yiyunet 發表於 2013-11-22 09:24
* }1 F1 y1 ?9 y0 E不會用pubhubsubbub。有實踐的來點介紹吧 - function http_post($url, $post_string) {+ n" k( N) E, m6 x
- $options = array(CURLOPT_URL => $url,
* c* D4 w) R& G5 b% Y2 R4 h5 V8 f - CURLOPT_POST => true,& v9 F- K5 ]) a- @! `7 c0 I0 S& s
- CURLOPT_POSTFIELDS => $post_string,
% l' @# }8 z7 }0 D, L& x: A) Q - CURLOPT_RETURNTRANSFER => true,) V1 ~- x( }7 I+ e T+ T# p
- CURLOPT_RETURNTRANSFER => true,9 y. ]" a* }/ \
- CURLOPT_USERAGENT => "PubSubHubbub-Publisher-PHP/1.0");+ m2 H5 M2 V$ T% T1 g3 A) R
- $ch = curl_init();
6 t6 Z/ e1 m j! S! W) o - curl_setopt_array($ch, $options);4 @2 p5 |5 l! Y" M3 v, s8 A
- $response = curl_exec($ch);' u, Q! S0 l1 C0 L5 D) g) H
- $info = curl_getinfo($ch);' Q8 b! n8 M u
- curl_close($ch);( b& ^% A+ A2 d0 J1 l( g
- // all good
, P/ P, N, x# r8 R - if ($info['http_code'] == 204)
9 i3 J7 I$ ^1 b* {: W: F( e @ - return true;
& a. H+ [6 D+ b* e2 ] - return false;
/ u- N' v0 W" D8 l7 {1 S - }% H2 I4 y; b0 d9 Z% t
- function Publisher($topic_url){" b) \1 ^* \0 w' f' }
- $hub_urls=array('http://pubsubhubbub.appspot.com/','http://pubsubhubbub.superfeedr.com/','http://superfeedr.com/hubbub');
% j1 W6 U T0 P! Q6 ~' s( C - $post_string = "hub.mode=publish";
2 ~& {1 Y& i: } - $post_string .= "&hub.url=".urlencode($topic_url);
# r7 f3 i+ o( w - foreach ($hub_urls as $hub_url) {3 }4 i- c9 g: B+ h1 |
- http_post($hub_url,$post_string);0 q/ a M, b+ g' p3 p+ A& w
- }4 D8 D6 V. M+ ^, J+ U% b& X; O" h
- }
複製代碼 以前從wp插件中扣的代碼,3個pub源. n. r% Q W" c& L( W% J) o
5 A1 K; ^, Q6 R/ o& V) Q2 w7 y% w2 ]* H8 p" T9 ]4 H
|