referrer-rss.pl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. # TODO referers and refeRrers
  16. use strict;
  17. use v5.10;
  18. AddModuleDescription('referrer-rss.pl', 'Comments on Automatic Link Back');
  19. our (%Action, $LastUpdate, $ScriptName, $RssStyleSheet, $RssImageUrl, $SiteName, $SiteDescription, %Referers);
  20. $Action{"refer-rss"} = \&DoRefererRss;
  21. sub DoRefererRss {
  22. my $url = QuoteHtml($ScriptName);
  23. my $date = TimeToRFC822($LastUpdate);
  24. my $limit = GetParam("rsslimit", 15); # Only take the first 15 entries
  25. my $count = 0;
  26. print GetHttpHeader('application/xml');
  27. print qq{<?xml version="1.0" encoding="utf-8"?>};
  28. if ($RssStyleSheet =~ /\.(xslt?|xml)$/) {
  29. print qq{<?xml-stylesheet type="text/xml" href="$RssStyleSheet" ?>};
  30. } elsif ($RssStyleSheet) {
  31. print qq{<?xml-stylesheet type="text/css" href="$RssStyleSheet" ?>};
  32. }
  33. print qq{<rss version="2.0">
  34. <channel>
  35. <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  36. };
  37. print "<title>" . QuoteHtml($SiteName) . " " . T("Referrers") . "</title>\n";
  38. print "<link>$url?action=refer</link>\n";
  39. print "<description>" . QuoteHtml($SiteDescription) . "</description>\n";
  40. print "<pubDate>" . $date. "</pubDate>\n";
  41. print "<lastBuildDate>" . $date . "</lastBuildDate>\n";
  42. print "<generator>Oddmuse</generator>\n";
  43. if ($RssImageUrl) {
  44. print "<image>\n";
  45. print "<url>" . $RssImageUrl . "</url>\n";
  46. print "<title>" . QuoteHtml($SiteName) . "</title>\n";
  47. print "<link>" . $url . "</link>\n";
  48. print "</image>\n";
  49. }
  50. my %when = ();
  51. my %where = ();
  52. for my $id (AllPagesList()) {
  53. ReadReferers($id);
  54. # $Referers{url} = time for each $id
  55. foreach my $url (keys %Referers) {
  56. # $where{$url} = HomePage, AlexSchroeder, What_Is_A_Wiki
  57. push(@{$where{$url}}, $id);
  58. # $when{$url} = last time
  59. $when{$url} = $Referers{$url}
  60. if $when{$url} < $Referers{$url};
  61. }
  62. }
  63. foreach my $url (sort { $when{$b} <=> $when{$a} } keys %when) {
  64. print "\n<item>\n";
  65. print "<title>" . QuoteHtml($url) . "</title>\n";
  66. print "<link>" . QuoteHtml($url) . "</link>\n";
  67. print "<description>" . join(", ", map {
  68. QuoteHtml(GetPageLink($_));
  69. } @{$where{$url}}) . ", " . CalcDay($when{$url}) . " " . CalcTime($when{$url}) . "</description>\n";
  70. print "<pubDate>" . $date . "</pubDate>\n";
  71. print "</item>\n";
  72. }
  73. print "</channel>\n</rss>\n";
  74. }