示例#1
0
文件: ping.php 项目: Br3nda/StatusNet
function ping_broadcast_notice($notice)
{
    if ($notice->is_local != Notice::LOCAL_PUBLIC && $notice->is_local != Notice::LOCAL_NONPUBLIC) {
        return true;
    }
    # Array of servers, URL => type
    $notify = common_config('ping', 'notify');
    $profile = $notice->getProfile();
    $tags = ping_notice_tags($notice);
    foreach ($notify as $notify_url => $type) {
        switch ($type) {
            case 'xmlrpc':
            case 'extended':
                $req = xmlrpc_encode_request('weblogUpdates.ping', array($profile->nickname, common_local_url('showstream', array('nickname' => $profile->nickname)), common_local_url('shownotice', array('notice' => $notice->id)), common_local_url('userrss', array('nickname' => $profile->nickname)), $tags));
                $request = HTTPClient::start();
                $request->setConfig('connect_timeout', common_config('ping', 'timeout'));
                $request->setConfig('timeout', common_config('ping', 'timeout'));
                try {
                    $httpResponse = $request->post($notify_url, array('Content-Type: text/xml'), $req);
                } catch (Exception $e) {
                    common_log(LOG_ERR, "Exception pinging {$notify_url}: " . $e->getMessage());
                    continue;
                }
                if (!$httpResponse || mb_strlen($httpResponse->getBody()) == 0) {
                    common_log(LOG_WARNING, "XML-RPC empty results for ping ({$notify_url}, {$notice->id}) ");
                    continue;
                }
                $response = xmlrpc_decode($httpResponse->getBody());
                if (is_array($response) && xmlrpc_is_fault($response)) {
                    common_log(LOG_WARNING, "XML-RPC error for ping ({$notify_url}, {$notice->id}) " . "{$response['faultString']} ({$response['faultCode']})");
                } else {
                    common_log(LOG_INFO, "Ping success for {$notify_url} {$notice->id}");
                }
                break;
            case 'get':
            case 'post':
                $args = array('name' => $profile->nickname, 'url' => common_local_url('showstream', array('nickname' => $profile->nickname)), 'changesURL' => common_local_url('userrss', array('nickname' => $profile->nickname)));
                $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
                if ($type === 'get') {
                    $result = $fetcher->get($notify_url . '?' . http_build_query($args), array('User-Agent: StatusNet/' . STATUSNET_VERSION));
                } else {
                    $result = $fetcher->post($notify_url, http_build_query($args), array('User-Agent: StatusNet/' . STATUSNET_VERSION));
                }
                if ($result->status != '200') {
                    common_log(LOG_WARNING, "Ping error for '{$notify_url}' ({$notice->id}): " . "{$result->body}");
                } else {
                    common_log(LOG_INFO, "Ping success for '{$notify_url}' ({$notice->id}): " . "'{$result->body}'");
                }
                break;
            default:
                common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type);
        }
    }
    return true;
}
示例#2
0
文件: ping.php 项目: Br3nda/laconica
function ping_broadcast_notice($notice)
{
    if (!$notice->is_local) {
        return true;
    }
    # Array of servers, URL => type
    $notify = common_config('ping', 'notify');
    $profile = $notice->getProfile();
    $tags = ping_notice_tags($notice);
    foreach ($notify as $notify_url => $type) {
        switch ($type) {
            case 'xmlrpc':
            case 'extended':
                $req = xmlrpc_encode_request('weblogUpdates.ping', array($profile->nickname, common_local_url('showstream', array('nickname' => $profile->nickname)), common_local_url('shownotice', array('notice' => $notice->id)), common_local_url('userrss', array('nickname' => $profile->nickname)), $tags));
                $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml\r\n" . "User-Agent: Laconica/" . LACONICA_VERSION . "\r\n", 'content' => $req)));
                $file = file_get_contents($notify_url, false, $context);
                if ($file === false || mb_strlen($file) == 0) {
                    common_log(LOG_WARNING, "XML-RPC empty results for ping ({$notify_url}, {$notice->id}) ");
                    continue;
                }
                $response = xmlrpc_decode($file);
                if (xmlrpc_is_fault($response)) {
                    common_log(LOG_WARNING, "XML-RPC error for ping ({$notify_url}, {$notice->id}) " . "{$response['faultString']} ({$response['faultCode']})");
                } else {
                    common_log(LOG_INFO, "Ping success for {$notify_url} {$notice->id}");
                }
                break;
            case 'get':
            case 'post':
                $args = array('name' => $profile->nickname, 'url' => common_local_url('showstream', array('nickname' => $profile->nickname)), 'changesURL' => common_local_url('userrss', array('nickname' => $profile->nickname)));
                $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
                if ($type === 'get') {
                    $result = $fetcher->get($notify_url . '?' . http_build_query($args), array('User-Agent: Laconica/' . LACONICA_VERSION));
                } else {
                    $result = $fetcher->post($notify_url, http_build_query($args), array('User-Agent: Laconica/' . LACONICA_VERSION));
                }
                if ($result->status != '200') {
                    common_log(LOG_WARNING, "Ping error for '{$notify_url}' ({$notice->id}): " . "{$result->body}");
                } else {
                    common_log(LOG_INFO, "Ping success for '{$notify_url}' ({$notice->id}): " . "'{$result->body}'");
                }
                break;
            default:
                common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type);
        }
    }
    return true;
}