]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/inline.pm
* Support pinging services such as Technorati using XML-RPC to notify them
[git.ikiwiki.info.git] / IkiWiki / Plugin / inline.pm
index a11e5a52bbb916dcef8a30396c6fedb5f8b74d88..6bcd59a9fa90ad16c7896de2e2cf61843cf7804f 100644 (file)
@@ -9,12 +9,19 @@ use IkiWiki;
 sub import { #{{{
        IkiWiki::hook(type => "preprocess", id => "inline", 
                call => \&IkiWiki::preprocess_inline);
+       # Hook to change to do pinging since it's called late.
+       # This ensures each page only pings once and prevents slow
+       # pings interrupting page builds.
+       IkiWiki::hook(type => "change", id => "inline", 
+               call => \&IkiWiki::pingurl);
 } # }}}
 
 # Back to ikiwiki namespace for the rest, this code is very much
 # internal to ikiwiki even though it's separated into a plugin.
 package IkiWiki;
-       
+
+my %toping;
+
 sub preprocess_inline (@) { #{{{
        my %params=@_;
 
@@ -59,10 +66,10 @@ sub preprocess_inline (@) { #{{{
        foreach my $page (blog_list($params{pages}, $params{show})) {
                next if $page eq $params{page};
                push @pages, $page;
-               $template->param(pagelink => htmllink($params{page}, $page));
+               $template->param(pagelink => htmllink($params{page}, $params{page}, $page));
                $template->param(content => get_inline_content($params{page}, $page))
                        if $params{archive} eq "no";
-               $template->param(ctime => scalar(gmtime($pagectime{$page})));
+               $template->param(ctime => displaytime($pagectime{$page}));
                $ret.=$template->output;
        }
        
@@ -72,6 +79,7 @@ sub preprocess_inline (@) { #{{{
        if ($config{rss}) {
                writefile(rsspage($params{page}), $config{destdir},
                        genrss($params{page}, @pages));
+               $toping{$params{page}}=1;
        }
        
        return $ret;
@@ -100,7 +108,7 @@ sub get_inline_content ($$) { #{{{
        my $file=$pagesources{$page};
        my $type=pagetype($file);
        if ($type ne 'unknown') {
-               return htmlize($type, linkify($parentpage, readfile(srcfile($file))));
+               return htmlize($type, preprocess($page, linkify($page, $parentpage, readfile(srcfile($file))), 1));
        }
        else {
                return "";
@@ -121,8 +129,8 @@ sub absolute_urls ($$) { #{{{
 
        $url=~s/[^\/]+$//;
        
-       $content=~s/<a\s+href="(?!http:\/\/)([^"]+)"/<a href="$url$1"/ig;
-       $content=~s/<img\s+src="(?!http:\/\/)([^"]+)"/<img src="$url$1"/ig;
+       $content=~s/<a\s+href="(?![^:]+:\/\/)([^"]+)"/<a href="$url$1"/ig;
+       $content=~s/<img\s+src="(?![^:]+:\/\/)([^"]+)"/<img src="$url$1"/ig;
        return $content;
 } #}}}
 
@@ -160,4 +168,32 @@ sub genrss ($@) { #{{{
        return $template->output;
 } #}}}
 
+sub pingurl (@) { #{{{
+       return unless $config{pingurl} && %toping;
+
+       eval q{require RPC::XML::Client};
+       if ($@) {
+               debug("RPC::XML::Client not found, not pinging");
+       }
+
+       foreach my $page (keys %toping) {
+               my $title=pagetitle(basename($page));
+               my $url="$config{url}/".htmlpage($page);
+               foreach my $pingurl (@{$config{pingurl}}) {
+                       my $client = RPC::XML::Client->new($pingurl);
+                       my $req = RPC::XML::request->new('weblogUpdates.ping',
+                               $title, $url);
+                       debug("Pinging $pingurl for $page");
+                       my $res = $client->send_request($req);
+                       if (! ref $res) {
+                               debug("Did not receive response to ping");
+                       }
+                       my $r=$res->value;
+                       if (! exists $r->{flerror} || $r->{flerror}) {
+                               debug("Ping rejected: ".$r->{message});
+                       }
+               }
+       }
+} #}}}
+
 1