yiyunet 發表於 2013-11-22 09:24
- k* ?3 d+ e1 k3 {1 d3 G" z不會用pubhubsubbub。有實踐的來點介紹吧 - function http_post($url, $post_string) {, {- h* \9 t) \% m: H' K8 o# O
- $options = array(CURLOPT_URL => $url,
7 p+ D# M, e# y5 ~0 m; ^. a7 ?& e - CURLOPT_POST => true,2 s6 ?. C' H7 i
- CURLOPT_POSTFIELDS => $post_string,
5 l3 F2 R p7 _2 z4 {5 Q7 N& q - CURLOPT_RETURNTRANSFER => true,& J; t# `" l; E: x0 ?* _: ~+ r
- CURLOPT_RETURNTRANSFER => true,/ Q; c! n9 r& T H
- CURLOPT_USERAGENT => "PubSubHubbub-Publisher-PHP/1.0");! [! Y# { v& R; C- F$ C
- $ch = curl_init();
; ~( @* j% g7 g+ V! f - curl_setopt_array($ch, $options);
0 V& ^ w5 ^% ]$ a! v% C& h1 z - $response = curl_exec($ch);3 y$ I5 }4 b8 I* U D
- $info = curl_getinfo($ch);
; k5 e! g: d/ Q+ ^* V( J - curl_close($ch);
6 u5 i6 u8 C2 L% z5 P) Q* n% h - // all good
4 F3 |, [8 o4 i, n, H1 S$ q - if ($info['http_code'] == 204)& _# m" w2 `3 a
- return true;3 o6 W+ w4 G2 _
- return false;5 w$ t, X$ {3 x5 }. N6 n' \7 l$ [' p# [
- }0 G3 w( x3 g' F
- function Publisher($topic_url){
9 D) D+ C" S: n! I) |+ W- x% [& G - $hub_urls=array('http://pubsubhubbub.appspot.com/','http://pubsubhubbub.superfeedr.com/','http://superfeedr.com/hubbub');
) J! `" [6 y/ b7 S - $post_string = "hub.mode=publish";, N: m; A8 i% M, I6 }9 a0 _
- $post_string .= "&hub.url=".urlencode($topic_url);# Y" q: z. F0 G, k2 T" x7 L( ^( @9 k. D
- foreach ($hub_urls as $hub_url) {
- z3 F+ ?$ k8 j, ?8 v& K - http_post($hub_url,$post_string);/ ?: {% s% o$ \
- }
' w2 {4 z5 n6 v8 O7 A- ]2 k - }
複製代碼 以前從wp插件中扣的代碼,3個pub源7 W& e3 w5 W# r. x: _' A
+ C% M3 u* H/ M
: y; ^5 Q6 v+ N8 v
|