dynlogo.pl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2004 Sebastian Blatt <sblatt@havens.de>
  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. # Makes the wiki logo depend on the current date.
  16. #
  17. # Example Usage: Put the following into your config file and modify as
  18. # needed:
  19. #
  20. # $DynLogoDirectory = '/mypic/dynlogo';
  21. # $DynLogoDefault = 'wiki.jpg';
  22. # %DynLogoMap = ('\d{4}-12-31' => 'party.jpg');
  23. # $LogoUrl = GetDynLogoUrl();
  24. #
  25. use strict;
  26. use v5.10;
  27. AddModuleDescription('dynlogo.pl', 'Dynamic Logo');
  28. our ($DynLogoDirectory, $DynLogoDefault, %DynLogoMap);
  29. # Directory to search for images.
  30. $DynLogoDirectory = '/pic/dynlogo';
  31. # Default logo in the $DynLogoDirectory.
  32. $DynLogoDefault = 'logo.png';
  33. # This maps a regular expression matching a date string of the form
  34. # "%Y-%m-%d" to a filename in the $DynLogoDirectory. Example usage:
  35. # %DynLogoMap = ('\d{4}-12-24'=>'logo-1224.jpg');
  36. %DynLogoMap = ();
  37. sub GetDynLogoUrl {
  38. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime(time);
  39. my $today = sprintf("%d-%02d-%02d", $year + 1900, $mon + 1, $mday);
  40. foreach my $k (keys(%DynLogoMap)) {
  41. if ($today=~m/$k/) {
  42. return $DynLogoDirectory."/".$DynLogoMap{$k};
  43. }
  44. }
  45. return "$DynLogoDirectory/$DynLogoDefault";
  46. }