PyukiWiki CVS Commit
pyuki****@lists*****
2012年 3月 21日 (水) 17:26:19 JST
Index: PyukiWiki-Devel/lib/ping.inc.pl diff -u PyukiWiki-Devel/lib/ping.inc.pl:1.36 PyukiWiki-Devel/lib/ping.inc.pl:1.37 --- PyukiWiki-Devel/lib/ping.inc.pl:1.36 Wed Mar 21 06:47:02 2012 +++ PyukiWiki-Devel/lib/ping.inc.pl Wed Mar 21 17:26:19 2012 @@ -1,6 +1,6 @@ ###################################################################### # ping.inc.pl - This is PyukiWiki, yet another Wiki clone. -# $Id: ping.inc.pl,v 1.36 2012/03/20 21:47:02 papu Exp $ +# $Id: ping.inc.pl,v 1.37 2012/03/21 08:26:19 papu Exp $ # # "PyukiWiki" ver 0.2.0-p3-dev2 $$ # Author: Nanami http://nanakochi.daiba.cx/ @@ -22,20 +22,26 @@ $ping::titleformat="__mypage__ - __wikititle__"; +use Nana::HTTP; + if(!defined($ping::serverlist)) { $ping::serverlist=<<EOM; -http://api.my.yahoo.co.jp/RPC2 -http://blogsearch.google.co.jp/ping/RPC2 -http://rpc.reader.livedoor.com/ping -http://blog.goo.ne.jp/XMLRPC -http://ping.fc2.com -http://ping.rss.drecom.jp/ -http://ping.dendou.jp/ -http://ping.freeblogranking.com/xmlrpc/ +XMLRPC|http://blogsearch.google.com/ping/RPC2 +NANA|http://api.my.yahoo.co.jp/RPC2 +XMLRPC|http://rpc.reader.livedoor.com/ping +XMLRPC|http://blog.goo.ne.jp/XMLRPC +XMLRPC|http://ping.fc2.com +XMLRPC|http://ping.rss.drecom.jp/ +XMLRPC|http://ping.dendou.jp/ +XMLRPC|http://ping.freeblogranking.com/xmlrpc/ +XMLRPC|http://rpc.pingomatic.com/ +XMLRPC|http://rpc.weblogs.com/rpc2 +XMLRPC|http://ping.myblog.jp +XMLRPC|http://www.blogpeople.net/servlet/weblogUpdates EOM $ping::serverlist.=<<EOM if($::rss_lines > 0); -http://api.my.yahoo.co.jp/rss/ping?u=__RSSURIENC__ +NANA|http://api.my.yahoo.co.jp/rss/ping?u=__RSSURIENC__ EOM } @@ -56,32 +62,45 @@ %ping::sentserver; use strict; -my $lastmod_org; + +$ping::sendtimepage=":ping"; sub plugin_ping_init { &exec_explugin_sub("lang"); &exec_explugin_sub("urlhack"); &exec_explugin_sub("autometarobot"); - $lastmod_org = $::database{"__update__" . $::form{mypage}} - if(&is_exist_page($::form{mypage})); - return ('init'=>1 , 'func'=>'do_write', 'do_write'=>\&do_write - , 'last_func'=>'&send_ping_main;'); + , 'last_func'=>'&send_ping_main;'); } sub send_ping_rpc { -# This code is use # comment -# http://isnot.jp/?p=XML-RPC%A1%F8%B9%B9%BF%B7Ping%A4%CE%C1%F7%BF%AE #comment my($rpcurl,$name,$url,$rssurl)=@_; $rpcurl=~s/\/$//g; return if($ping::sentserver{$rpcurl} ne ''); $ping::sentserver{$rpcurl}=$rpcurl; - &load_module("XMLRPC::Lite"); - &load_module("Nana::HTTP"); + + my $type="XMLRPC"; + if($rpcurl=~/\|/) { + ($type, $rpcurl)=split(/\|/,$rpcurl); + } + + if(lc $type eq "xmlrpc") { + &load_module("XMLRPC::Lite"); + return &send_ping_xmlrpc($rpcurl, $name, $url, $rssurl); + } else { + &load_module("Nana::HTTP"); + return &send_ping_nanahttp($rpcurl, $name, $url, $rssurl); + } +} + +sub send_ping_xmlrpc($rpcurl, $name, $url, $rssurl) { +# This code is use # comment +# http://isnot.jp/?p=XML-RPC%A1%F8%B9%B9%BF%B7Ping%A4%CE%C1%F7%BF%AE #comment + my($rpcurl,$name,$url,$rssurl)=@_; my $result; eval { @@ -113,13 +132,66 @@ } } my $test=lc $result; - if($test=~/thank/ && $test=~/ping/ + if( $test=~/thank/ && $test=~/ping/ + || $test=~/forwarded/ && $test=~/services/ + || $test=~/<boolean>0<\/boolean>/ + || $test=~/<value><boolean>0<\/boolean><\/value>/ + || $test=~/<boolean>0<\/value>/ + || $test=~/OK/ || $test=~/successfully/ && $test=~/refresh/ && $test=~/requested/) { return (0,$result); } return (1,$result); } +sub send_ping_nanahttp { + my($rpcurl,$name,$url,$rssurl)=@_; + + $rpcurl =~ m!(http:)?(//)?([^:/]*)?(:([0-9]+)?)?(/.*)?!; + my $host = ($3 ne "") ? $3 : "localhost"; + my $port = ($5 ne "") ? $5 : 80; + my $path = ($6 ne "") ? $6 : "/"; + + my $pingmsg=<<EOM; +<?xml version="1.0" encoding='UTF-8'?> +<methodCall> +<methodName>weblogUpdates.ping</methodName> +<params> +<param> +<value>$name</value> +</param> +<param> +<value>$url</value> +</param> +</params> +</methodCall> +EOM + + + my $pingbody=&code_convert(\$pingmsg, 'utf8', $::defaultcode); + + my $length = length($pingbody); + my $header=<<EOM; + +Content-Type: text/xml; charset=utf-8 +Content-Length: $length +Referer: $url +EOM + my $http=new Nana::HTTP('module'=>"ping");#, 'header'=>$header); + my ($result, $stream) = $http->post($rpcurl, , $pingbody); + my $test=lc $stream; + if( $test=~/thank/ && $test=~/ping/ + || $test=~/forwarded/ && $test=~/services/ + || $test=~/<boolean>0<\/boolean>/ + || $test=~/<value><boolean>0<\/boolean><\/value>/ + || $test=~/<boolean>0<\/value>/ + || $test=~/OK/ + || $test=~/successfully/ && $test=~/refresh/ && $test=~/requested/) { + return (0,$stream); + } + return (1,$stream); +} + sub send_ping_main { my($page)=$ping::pagesave; return if($page eq ''); @@ -142,10 +214,11 @@ $val{wikititle}=$::wiki_title; my $title=&replace($ping::titleformat,%val); $val{TITLE}=&code_convert(\$title,'utf8',$::defaultcode); -# $val{TITLE}=$title; - $val{URL}=$::bxasehref; + $val{TITLE}=$title; + $val{URL}=$::basehref; my($stat,$result)=&send_ping_rpc($server, $val{TITLE}, $val{URL}, $val{RSSURI}); + if($stat eq 0) { $results.="Sent $server\n"; } else { @@ -162,21 +235,34 @@ sub send_ping { my($page)=@_; return if(!&is_exist_page($page)); - my $lastmod = $::database{"__update__" . $page}; - if(time < $lastmod_org + $ping::wait) { + my $lastmod=$::database{$ping::sendtimepage}; + if($lastmod=~/(\d+)/) { + $lastmod=$1+0; + } else { + $lastmod=0; + } + + if(time < $lastmod + $ping::wait) { my $msg=<<EOM; Ping waiting @{[&date($::lastmod_format, $lastmod + $ping::wait)]} EOM - &load_module("Nana::Mail"); Nana::Mail::toadmin("ping", $page, $msg); return; } + + my $time=time; + my $newlastmod=<<EOM; +#freeze +// Do not edit. using ping sending check +$time +EOM + $::database{$ping::sendtimepage}=$newlastmod; + if(&load_module("XMLRPC::Lite")) { $ping::pagesave=$page; } else { &load_module("Nana::Mail"); Nana::Mail::toadmin("ping", $page, "Can't send ping. please install XMLRPC::Lite (in SOAP::Lite)"); - } }