today.pl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 3 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, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('today.pl', 'Blog Module');
  18. our (%Action, $Now, @MyAdminCode, $UsePathInfo, $NamespaceCurrent);
  19. # New Action
  20. push(@MyAdminCode, \&TodayMenu);
  21. sub TodayMenu {
  22. my ($id, $menuref, $restref) = @_;
  23. push(@$menuref,
  24. ScriptLink('action=new',
  25. T('Create a new page for today'),
  26. 'today'));
  27. }
  28. $Action{new} = \&DoNew;
  29. sub DoNew {
  30. my $id = shift;
  31. # GetId() returns "SandWiki" for the following URL:
  32. # http://www.communitywiki.org/odd/SandWiki?action=new.
  33. if ($UsePathInfo and $NamespaceCurrent
  34. and $id eq $NamespaceCurrent
  35. and GetParam($NamespaceCurrent, 0) == 0
  36. and not GetParam('id', '')) {
  37. # Undo this unless we're getting
  38. # http://www.communitywiki.org/odd/SandWiki/SandWiki?action=new or
  39. # http://www.communitywiki.org/odd/SandWiki?action=new;id=SandWiki.
  40. $id = '';
  41. }
  42. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime($Now);
  43. my $today = sprintf("%d-%02d-%02d", $year + 1900, $mon + 1, $mday);
  44. $today .= sprintf("_%02dh%02d", $hour, $min) if GetParam('hour', 0);
  45. $today .= "_$id" if $id;
  46. return DoEdit($today);
  47. }