weblog-tracking.pl 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright (C) 2004 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. # Weblog Tracker Notification Extension
  16. use strict;
  17. use v5.10;
  18. our ($q, $UsePathInfo, $ScriptName, $SiteName);
  19. our (%NotifyJournalPage, @NotifyUrlPatterns);
  20. AddModuleDescription('weblog-tracking.pl', 'Update Weblog Tracker Extension');
  21. # Put this file in your modules directory.
  22. %NotifyJournalPage = ();
  23. @NotifyUrlPatterns = ();
  24. # NotifyJournalPage maps page names matching a certain pattern to
  25. # another page. In the example given below, \d stands for any number.
  26. # Thus any page name matching a date such as 2004-01-23 will map to
  27. # the Diary page. You can add more statements like these right here.
  28. $NotifyJournalPage{'\d\d\d\d-\d\d-\d\d'}='Diary';
  29. # NotifyUrlPatterns is a list of URLs to visit. They may contain three variables:
  30. # 1. $name is replaced by the name of the page.
  31. # 2. $url is replaced by the URL to the page.
  32. # 3. $rss is replaced by the RSS feed for your site.
  33. # You can push more of these statements onto the list.
  34. push (@NotifyUrlPatterns, 'http://ping.blo.gs/?name=$name&url=$url&rssUrl=$rss&direct=1');
  35. # You should not need to change anything below this point.
  36. *OldWeblogTrackingSave = \&Save;
  37. *Save = \&NewWeblogTrackingSave;
  38. sub NewWeblogTrackingSave {
  39. my ($id, $new, $summary, $minor, $upload) = @_;
  40. OldWeblogTrackingSave(@_);
  41. if (not $minor) {
  42. PingTracker($id);
  43. }
  44. }
  45. sub PingTracker {
  46. my $id = shift;
  47. foreach my $regexp (keys %NotifyJournalPage) {
  48. if ($id =~ m/$regexp/) {
  49. $id = $NotifyJournalPage{$regexp};
  50. last;
  51. }
  52. }
  53. if ($q->url(-base=>1) !~ m|^http://localhost|) {
  54. my $url;
  55. if ($UsePathInfo) {
  56. $url = $ScriptName . '/' . $id;
  57. } else {
  58. $url = $ScriptName . '?' . $id;
  59. }
  60. $url = UrlEncode($url);
  61. my $name = UrlEncode($SiteName . ': ' . $id);
  62. my $rss = UrlEncode($q->url . '?action=rss');
  63. require LWP::UserAgent;
  64. foreach my $uri (@NotifyUrlPatterns) {
  65. my $fork = fork();
  66. if (not ($fork > 0)) { # either we're the child or forking failed
  67. $uri =~ s/\$name/$name/g;
  68. $uri =~ s/\$url/$url/g;
  69. $uri =~ s/\$rss/$rss/g;
  70. my $ua = LWP::UserAgent->new;
  71. my $request = HTTP::Request->new('GET', $uri);
  72. $ua->request($request);
  73. exit if ($fork == 0); # exit when we're the child
  74. }
  75. }
  76. }
  77. }