Add a bunch of Rael plugins.
[matthijs/upstream/blosxom-plugins.git] / general / ping_weblogs_com
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
5
6 package ping_weblogs_com;
7
8 # --- Configurable variables -----
9
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);
12
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 = '';
18
19 # --------------------------------
20
21 use FileHandle;
22 use File::stat;
23
24 # Keep track of the newest story's mtime
25 my $newest = 0;
26
27 sub start {
28   $get_app or return 0;
29 print STDERR "here\n";
30   1;
31 }
32
33 sub filter {
34   my($pkg, $files_ref) = @_;
35
36   $newest = $files_ref->{( sort { $files_ref->{$b} <=> $files_ref->{$a} } keys %$files_ref )[0]};
37
38   1;
39 }
40
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 ) {
44
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();
54
55     $ping_success or return 0;
56
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   }  
64
65   return 1;
66 }  
67
68 sub encode {
69   my($string) = @_;
70
71   my %encodings;
72   for (0..255) {
73     $encodings{chr($_)} = sprintf("%%%02X", $_);
74   }
75
76   $string =~ s/([^A-Za-z0-9\-_.!~*'()])/$encodings{$1}/g;
77   return $string;
78 }
79
80 1;
81
82 __END__
83
84 =head1 NAME
85
86 Blosxom Plug-in: ping_weblogs_com
87
88 =head1 SYNOPSIS
89
90 Purpose: Notifies weblogs.com [http://www.weblogs.com] that your weblog
91 has been updated upon encountering any new story. 
92
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.
96
97 =head1 VERSION
98
99 2.0b3
100
101 Version number coincides with the version of Blosxom with which the 
102 current version was first bundled.
103
104 =head1 AUTHOR
105
106 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
107
108 =head1 SEE ALSO
109
110 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
111
112 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
113
114 =head1 BUGS
115
116 Address bug reports and comments to the Blosxom mailing list 
117 [http://www.yahoogroups.com/group/blosxom].
118
119 =head1 LICENSE
120
121 Blosxom and this Blosxom Plug-in
122 Copyright 2003, Rael Dornfest 
123
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:
130
131 The above copyright notice and this permission notice shall be included
132 in all copies or substantial portions of the Software.
133
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.