today.pl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the
  15. # Free Software Foundation, Inc.
  16. # 59 Temple Place, Suite 330
  17. # Boston, MA 02111-1307 USA
  18. use strict;
  19. use v5.10;
  20. AddModuleDescription('today.pl', 'Blog Module');
  21. our (%Action, $Now, @MyAdminCode, $UsePathInfo, $NamespaceCurrent);
  22. # New Action
  23. push(@MyAdminCode, \&TodayMenu);
  24. sub TodayMenu {
  25. my ($id, $menuref, $restref) = @_;
  26. push(@$menuref,
  27. ScriptLink('action=new',
  28. T('Create a new page for today'),
  29. 'today'));
  30. }
  31. $Action{new} = \&DoNew;
  32. sub DoNew {
  33. my $id = shift;
  34. # GetId() returns "SandWiki" for the following URL:
  35. # http://www.communitywiki.org/odd/SandWiki?action=new.
  36. if ($UsePathInfo and $NamespaceCurrent
  37. and $id eq $NamespaceCurrent
  38. and GetParam($NamespaceCurrent, 0) == 0
  39. and not GetParam('id', '')) {
  40. # Undo this unless we're getting
  41. # http://www.communitywiki.org/odd/SandWiki/SandWiki?action=new or
  42. # http://www.communitywiki.org/odd/SandWiki?action=new;id=SandWiki.
  43. $id = '';
  44. }
  45. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime($Now);
  46. my $today = sprintf("%d-%02d-%02d", $year + 1900, $mon + 1, $mday);
  47. $today .= sprintf("_%02dh%02d", $hour, $min) if GetParam('hour', 0);
  48. $today .= "_$id" if $id;
  49. return DoEdit($today);
  50. }