Fixed extraneous <updated>...</updated> tags for feed date/time in static rendering
[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 This plugin is now maintained by the Blosxom Sourceforge Team,
109 <blosxom-devel@lists.sourceforge.net>.
110
111 =head1 SEE ALSO
112
113 Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net/
114
115 Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/users/plugins.html
116
117 =head1 BUGS
118
119 None known; please send bug reports and feedback to the Blosxom
120 development mailing list <blosxom-devel@lists.sourceforge.net>.
121
122 =head1 LICENSE
123
124 Blosxom and this Blosxom Plug-in
125 Copyright 2003, Rael Dornfest 
126
127 Permission is hereby granted, free of charge, to any person obtaining a
128 copy of this software and associated documentation files (the "Software"),
129 to deal in the Software without restriction, including without limitation
130 the rights to use, copy, modify, merge, publish, distribute, sublicense,
131 and/or sell copies of the Software, and to permit persons to whom the
132 Software is furnished to do so, subject to the following conditions:
133
134 The above copyright notice and this permission notice shall be included
135 in all copies or substantial portions of the Software.
136
137 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
138 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
139 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
140 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
141 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
142 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
143 OTHER DEALINGS IN THE SOFTWARE.