referrer-rss.pl 3.0 KB

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