sabifoo.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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('sabifoo.pl', 'Sabifoo');
  21. our (%IndexHash, @MyInitVariables);
  22. our ($SummaryDefaultLength);
  23. push(@MyInitVariables, \&SabiFooInit);
  24. sub SabiFooInit {
  25. my $text = UnquoteHtml(GetParam('sabifoo_message', ''));
  26. if ($text) {
  27. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime();
  28. my $today = sprintf("%02d-%02d-%02d", $year + 1900, $mon + 1, $mday);
  29. my $title = '';
  30. if ($text =~ m/^\s*==\s*(.*?)\s*==\s*(.*)/) {
  31. $title = $1;
  32. $text = $2;
  33. }
  34. # base summary on the text added this time only, without title
  35. my $summary = $text;
  36. if (length($summary) > $SummaryDefaultLength) {
  37. $summary = substr($summary, 0, $SummaryDefaultLength);
  38. $summary =~ s/\s*\S*$/ . . ./;
  39. }
  40. # append to existing page!
  41. $title = FreeToNormal($today . ' ' . $title);
  42. if ($IndexHash{$title}) {
  43. $text = GetPageContent($title) . "\n\n" . $text;
  44. }
  45. my $username = GetParam('sabifoo_author');
  46. $username =~ s/@.*//;
  47. SetParam('title', $title);
  48. SetParam('text', $text);
  49. SetParam('username', $username);
  50. SetParam('summary', 'x' . $summary);
  51. }
  52. }