3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2009, Control Yourself, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
22 function ping_broadcast_notice($notice) {
24 if (!$notice->is_local) {
28 # Array of servers, URL => type
29 $notify = common_config('ping', 'notify');
30 $profile = $notice->getProfile();
31 $tags = ping_notice_tags($notice);
33 foreach ($notify as $notify_url => $type) {
37 $req = xmlrpc_encode_request('weblogUpdates.ping',
38 array($profile->nickname, # site name
39 common_local_url('showstream',
40 array('nickname' => $profile->nickname)),
41 common_local_url('shownotice',
42 array('notice' => $notice->id)),
43 common_local_url('userrss',
44 array('nickname' => $profile->nickname)),
47 $context = stream_context_create(array('http' => array('method' => "POST",
49 "Content-Type: text/xml\r\n".
50 "User-Agent: Laconica/".LACONICA_VERSION."\r\n",
52 $file = file_get_contents($notify_url, false, $context);
54 if ($file === false || mb_strlen($file) == 0) {
55 common_log(LOG_WARNING,
56 "XML-RPC empty results for ping ($notify_url, $notice->id) ");
60 $response = xmlrpc_decode($file);
62 if (xmlrpc_is_fault($response)) {
63 common_log(LOG_WARNING,
64 "XML-RPC error for ping ($notify_url, $notice->id) ".
65 "$response[faultString] ($response[faultCode])");
68 "Ping success for $notify_url $notice->id");
74 $args = array('name' => $profile->nickname,
75 'url' => common_local_url('showstream',
76 array('nickname' => $profile->nickname)),
77 'changesURL' => common_local_url('userrss',
78 array('nickname' => $profile->nickname)));
80 $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
82 if ($type === 'get') {
83 $result = $fetcher->get($notify_url . '?' . http_build_query($args),
84 array('User-Agent: Laconica/'.LACONICA_VERSION));
86 $result = $fetcher->post($notify_url,
87 http_build_query($args),
88 array('User-Agent: Laconica/'.LACONICA_VERSION));
90 if ($result->status != '200') {
91 common_log(LOG_WARNING,
92 "Ping error for '$notify_url' ($notice->id): ".
96 "Ping success for '$notify_url' ($notice->id): ".
102 common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type);
109 function ping_notice_tags($notice) {
110 $tag = new Notice_tag();
111 $tag->notice_id = $notice->id;
114 while ($tag->fetch()) {
119 return implode('|', $tags);