Add a bunch of Rael plugins.
[blosxom-plugins.git] / general / ping_weblogs_com
blob4cadb933d3b2e4d2a71841c0cfd03a4b6c1fa2d7
1 # Blosxom Plugin: ping_weblogs_com
2 # Author(s): Rael Dornfest <rael@oreilly.com> 
3 # Version: 2.0b4
4 # Documentation: See the bottom of this file or type: perldoc ping_weblogs_com
6 package ping_weblogs_com;
8 # --- Configurable variables -----
10 # What URL should this plugin ping?
11 my $ping_url = "http://newhome.weblogs.com/pingSiteForm?name=" . encode($blosxom::blog_title) . "&url=" . encode($blosxom::url);
13 # What external program should this plugin use to ping Weblogs.com?
14 # 'lynx -source'
15 # 'wget --quiet -U "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" -O -';
16 # 'curl -m 30 -s'
17 my $get_app = '';
19 # --------------------------------
21 use FileHandle;
22 use File::stat;
24 # Keep track of the newest story's mtime
25 my $newest = 0;
27 sub start {
28   $get_app or return 0;
29 print STDERR "here\n";
30   1;
33 sub filter {
34   my($pkg, $files_ref) = @_;
36   $newest = $files_ref->{( sort { $files_ref->{$b} <=> $files_ref->{$a} } keys %$files_ref )[0]};
38   1;
41 sub end {
42   # If no timestamped touch-file or newest is newer than the touch-file...
43   if ( !-e "$blosxom::plugin_state_dir/.ping_weblogs_com.output" or $newest > stat("$blosxom::plugin_state_dir/.ping_weblogs_com.output")->mtime ) {
45     my $response = '';
46     my $ping_success = 0;
47     my $fh = new FileHandle;
48     $fh->open(qq{$get_app "$ping_url" |});
49     while (<$fh>) {
50       $response .= $_;
51       $_ =~ /Thanks for the ping/ and $ping_success++, last;
52     }
53     $fh->close();
55     $ping_success or return 0;
57     # Touch the touchfile (creates if doesn't already exist)
58     open TOUCH, "> $blosxom::plugin_state_dir/.ping_weblogs_com.output";
59     print TOUCH $response;
60     close TOUCH;
61   
62     return 1;
63   }  
65   return 1;
66 }  
68 sub encode {
69   my($string) = @_;
71   my %encodings;
72   for (0..255) {
73     $encodings{chr($_)} = sprintf("%%%02X", $_);
74   }
76   $string =~ s/([^A-Za-z0-9\-_.!~*'()])/$encodings{$1}/g;
77   return $string;
82 __END__
84 =head1 NAME
86 Blosxom Plug-in: ping_weblogs_com
88 =head1 SYNOPSIS
90 Purpose: Notifies weblogs.com [http://www.weblogs.com] that your weblog
91 has been updated upon encountering any new story. 
93 Maintains a touch-file ($blosxom::plugin_state_dir/.ping_weblogs_com.output)
94 to which to compare the newest story's creation date.  Fills the
95 touch-file with the HTML results of the latest ping.
97 =head1 VERSION
99 2.0b3
101 Version number coincides with the version of Blosxom with which the 
102 current version was first bundled.
104 =head1 AUTHOR
106 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
108 =head1 SEE ALSO
110 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
112 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
114 =head1 BUGS
116 Address bug reports and comments to the Blosxom mailing list 
117 [http://www.yahoogroups.com/group/blosxom].
119 =head1 LICENSE
121 Blosxom and this Blosxom Plug-in
122 Copyright 2003, Rael Dornfest 
124 Permission is hereby granted, free of charge, to any person obtaining a
125 copy of this software and associated documentation files (the "Software"),
126 to deal in the Software without restriction, including without limitation
127 the rights to use, copy, modify, merge, publish, distribute, sublicense,
128 and/or sell copies of the Software, and to permit persons to whom the
129 Software is furnished to do so, subject to the following conditions:
131 The above copyright notice and this permission notice shall be included
132 in all copies or substantial portions of the Software.
134 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
135 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
136 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
137 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
138 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
139 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
140 OTHER DEALINGS IN THE SOFTWARE.