weblog-2.pl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2004–2014 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software: you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation, either version 3 of the License, or (at your option) any later
  6. # version.
  7. #
  8. # This program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this program. If not, see <http://www.gnu.org/licenses/>.
  14. use strict;
  15. use v5.10;
  16. use Time::ParseDate;
  17. AddModuleDescription('weblog-2.pl', 'Complex Weblog Extension');
  18. our ($q, @MyInitVariables, @UserGotoBarPages);
  19. push(@MyInitVariables, \&WebLog2Init);
  20. sub WebLog2Init {
  21. my $id = GetId();
  22. my ($sec, $min, $hour, $mday, $mon, $year) = localtime; # CalcDay uses gmtime!
  23. my $today = sprintf('%4d-%02d-%02d', $year + 1900, $mon + 1, $mday);
  24. my ($current) = ($id =~ m|^(\d\d\d\d-\d\d-\d\d)|);
  25. if ($current and $current ne $today) {
  26. my $time = parsedate($current, GMT => 1);
  27. ($sec,$min,$hour,$mday,$mon,$year) = localtime($time - 60*60*24);
  28. my $previous = sprintf("%4d-%02d-%02d", $year + 1900, $mon + 1, $mday);
  29. ($sec,$min,$hour,$mday,$mon,$year) = localtime($time + 60*60*24);
  30. my $next = sprintf("%4d-%02d-%02d", $year + 1900, $mon + 1, $mday);
  31. push(@UserGotoBarPages,$next) unless grep(/^$next$/, @UserGotoBarPages);
  32. push(@UserGotoBarPages,$current) unless grep(/^$current$/, @UserGotoBarPages);
  33. push(@UserGotoBarPages,$previous) unless grep(/^$previous$/, @UserGotoBarPages);
  34. }
  35. }