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>
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;
24 # Keep track of the newest story's mtime
30 http://rpc.technorati.com/rpc/ping
31 http://rpc.weblogs.com/RPC2
42 my($pkg, $files_ref) = @_;
45 foreach my $file (keys %$files_ref) {
46 $mtimes{$file} = stat($file)->mtime;
49 $newest_file = ( sort { $mtimes{$b} <=> $mtimes{$a} } keys %mtimes )[0];
50 $newest = $mtimes{$newest_file};
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");
69 # Okay, so we can't encode the values, we have to leave the
72 my $blog_name = $blosxom::blog_title;
73 my $blog_url = $blosxom::url;
78 <methodName>weblogUpdates.ping</methodName>
80 <param><value>$blog_name</value></param>
81 <param><value>$blog_url</value></param>
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",
93 Content_Type => 'text/xml',
94 Content_Length => length($content) );
96 $request = HTTP::Request->new('POST',
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";
122 $string =~ s/([^-A-Za-z0-9_.!~*\'()])/sprintf('%%%02X', $1)/ge;
135 Blosxom Plug-in: xml_ping_generic
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.
153 Second part of version number coincides with the version of Bob
154 Schumaker's xml_ping_weblogs plugin, it's based on.
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/
165 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
167 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
171 Address bug reports and comments to the Blosxom mailing list
172 [http://www.yahoogroups.com/group/blosxom].
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.