Add georss support to atomfeed.
[blosxom-plugins.git] / xtaran / xml_ping_generic
blob12e31fc0c4638ca25d32e03885fba9c2bb12932d
1 # -*- perl -*-
2 # Blosxom Plugin: xml_ping_generic
3 # Author(s): Axel Beckert <blosxom@deuxchevaux.org>, http://noone.org/blog
4 #            Bob Schumaker <cobblers@pobox.com>
5 #            Rael Dornfest <rael@oreilly.com> 
6 # Version: 0.01-2.0b4
7 # xml_ping_generic web page: http://noone.org/blog?-tags=Pinging
8 # xml_ping_generic download: http://noone.org/blosxom/xml_ping_generic
9 # Blosxom web page: http://www.blosxom.com/
10 # Documentation: See the bottom of this file or type: perldoc xml_ping_weblogs
12 package xml_ping_generic;
14 $VERSION = '0.01-2.0b4';
16 # --- Configurable variables -----
18 # What URL should this plugin ping?
19 require LWP::UserAgent;
20 use FileHandle;
21 use File::stat;
22 #use Data::Dumper;
24 # Keep track of the newest story's mtime
25 my $newest = 0;
27 my @urls_to_ping = 
28     qw(
30      http://rpc.technorati.com/rpc/ping
31      http://rpc.weblogs.com/RPC2
33        );
35 sub start {
38     return 1;
41 sub filter {
42     my($pkg, $files_ref) = @_;
44     my %mtimes = ();
45     foreach my $file (keys %$files_ref) {
46         $mtimes{$file} = stat($file)->mtime;
47     }
49     $newest_file = ( sort { $mtimes{$b} <=> $mtimes{$a} } keys %mtimes )[0];
50     $newest = $mtimes{$newest_file};
52     return 1;
55 sub end {
56     my $lockfile = "$blosxom::plugin_state_dir/.ping.lock";
57     my $outfile = "$blosxom::plugin_state_dir/.ping.output";
59     #print STDERR "lockfile=".(-e $lockfile)." preview=$preview::is_preview newest=".localtime($newest)." mtime=".localtime(stat($outfile)->mtime)." newest_file=$newest_file\n";
61     return 1 if (-e $lockfile or $preview::is_preview );
63     # If no timestamped touch-file or newest is newer than the touch-file...
64     if (!-e $outfile or $newest > stat($outfile)->mtime) {
66         open(LOCK, ">$lockfile");
67         close(LOCK);
69         # Okay, so we can't encode the values, we have to leave the
70         # slashes in and all.
72         my $blog_name = $blosxom::blog_title;
73         my $blog_url  = $blosxom::url;
74         
75         my $content = <<EOF;
76 <?xml version="1.0"?>
77 <methodCall>
78   <methodName>weblogUpdates.ping</methodName>
79   <params>
80      <param><value>$blog_name</value></param>
81      <param><value>$blog_url</value></param>
82   </params>
83 </methodCall>
84 EOF
85         # Touch the touchfile (creates if doesn't already exist)
86         open TOUCH, "> $blosxom::plugin_state_dir/.ping.output";
88         foreach my $url_to_ping (@urls_to_ping) {
89             $header = new HTTP::Headers;
90             (my $host = $urls_to_ping) =~ s!http://(.*?)/.*$!$1!;
91             $header->header( User_Agent => "blosxom/2.0-abe-dev xml_ping_weblogs/$VERSION",
92                              Host => $host,
93                              Content_Type => 'text/xml',
94                              Content_Length => length($content) );
95         
96             $request = HTTP::Request->new('POST', 
97                                           $url_to_ping,
98                                           $header,
99                                           $content);
100         
101             $ua = LWP::UserAgent->new;
102             $response = $ua->request($request);
104             #my $result = $response->{_content};
105             #$result =~ /Thanks for the ping/ or return 0;
107             my $result = $response->as_string;
108             my $reqas  = $request->as_string;
109             print TOUCH "$reqas\n$result\n";
110         }
111         close TOUCH;
112         unlink $lockfile;
114     }
115   
116     return 1;
119 sub encode {
120     my ($string) = @_;
121     
122     $string =~ s/([^-A-Za-z0-9_.!~*\'()])/sprintf('%%%02X', $1)/ge;
124     return $string;
129 __END__
131 =pod
133 =head1 NAME
135 Blosxom Plug-in: xml_ping_generic
137 =head1 SYNOPSIS
139 Purpose: Notifies one or more configurable pages via weblogs.com's XML
140 RPC API ping that your weblog has been updated upon encountering any
141 new story. By default it informs weblogs.com and technorati.com.
143 Maintains a touch-file ($blosxom::plugin_state_dir/.ping.output) to
144 which to compare the newest story's creation date. (In comparsion to
145 the original xml_ping_weblogs this point works fine with Rael's
146 entries_caching index module, too.) Fills the touch-file with the sent
147 HTTP and XML requests and responses of the latest ping.
149 =head1 VERSION
151 0.01-2.0b4
153 Second part of version number coincides with the version of Bob
154 Schumaker's xml_ping_weblogs plugin, it's based on.
156 =head1 AUTHOR
158 Axel Beckert <abe@deuxchevaux.org>
160 Based on the xml_ping_weblogs plugin by Bob Schumaker
161 <cobblers@pobox.com>, http://www.cobblers.net/blog/
163 =head1 SEE ALSO
165 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
167 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
169 =head1 BUGS
171 Address bug reports and comments to the Blosxom mailing list 
172 [http://www.yahoogroups.com/group/blosxom].
174 =head1 LICENSE
176 Blosxom and this Blosxom Plug-in
177 Copyright 2003, Rael Dornfest 
179 Permission is hereby granted, free of charge, to any person obtaining a
180 copy of this software and associated documentation files (the "Software"),
181 to deal in the Software without restriction, including without limitation
182 the rights to use, copy, modify, merge, publish, distribute, sublicense,
183 and/or sell copies of the Software, and to permit persons to whom the
184 Software is furnished to do so, subject to the following conditions:
186 The above copyright notice and this permission notice shall be included
187 in all copies or substantial portions of the Software.
189 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
190 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
191 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
192 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
193 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
194 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
195 OTHER DEALINGS IN THE SOFTWARE.