示例#1
0
function ewiki_pingback_rpc($source_url, $target_url)
{
    global $ewiki_config;
    #-- does the target URL refer to a known WikiPage ?
    $id = ewiki_url2id($target_url);
    if (!$id) {
        xmlrpc_send_response(xmlrpc_error(0x21, "Could not determine PageName for the given target URL."));
    }
    if (!($data = ewiki_db::GET($id))) {
        xmlrpc_send_response(xmlrpc_error(0x20, "The given target page does not exist."));
    }
    #-- check if the caller really has a link as he claims
    ini_set("user_agent", $ewiki_config["ua"]);
    if (strpos($source_url, "http://") === 0 && ($test = ewiki_http_asis($source_url, 96256))) {
        $test = strtolower($test);
        $test_url = strtolower($target_url);
        if (!strpos($test, $test_url) and !strpos($test, htmlentities($test_url))) {
            return xmlrpc_error(0x11, "Sorry, but couldn't find a link to '{$target_url}' on your given '{$source_url}' page.");
        }
    } else {
        return xmlrpc_error(0x10, "Your given source URL does not exist, could not be retrieved.");
    }
    #-- reject other frivolous links
    if (preg_match('#^http://[^/]+/?$#', $source_url)) {
        return xmlrpc_error(0x11, "Rejected '{$source_url}' as frivolous.");
    }
    #-- check write permissions
    if (EWIKI_DB_F_TEXT != $data["flags"] & EWIKI_DB_F_TYPE or $data["flags"] & EWIKI_DB_F_READONLY) {
        return xmlrpc_error(0x31, "Sorry, but this page is write-protected or not a system page.");
    }
    #-- already on page
    if (strpos($data["content"], $source_url)) {
        return xmlrpc_error(0x30, "The given link does already exist on this page.");
    }
    #-- other go-away cases
    if (function_exists("ewiki_banned_url") && ewiki_banned_url($source_url) || function_exists("ewiki_blocked_url") && ewiki_blocked_url($source_url)) {
        return xmlrpc_error(0x100, "Your link is unwanted here (registered on BlockedLinks or BannedLinks).");
    }
    #-- else update page
    $data["content"] = rtrim($data["content"]) . "\n* {$source_url} (PingBack)\n";
    ewiki_db::UPDATE($data);
    $data["version"]++;
    $ok = ewiki_db::WRITE($data);
    #-- fin response
    if ($ok) {
        return "Link to '{$source_url}' was added to page '{$id}'.";
    } else {
        return xmlrpc_error(0x101, "Seems like a database/writing error occoured.");
    }
}
 function send()
 {
     $error = xmlrpc_compact_value(array("faultCode" => $no, "faultString" => $str));
     $resp = array("methodResponse" => array("fault" => $error));
     xmlrpc_send_response($resp);
 }