Пример #1
0
function postToBloggerApiBlog($host, $port, $xmlRpcPath, $username, $password, $title, $body, $authorName, $authorEmail, $draft, $proxyUsername = null, $proxyPassword = null)
{
    $postData = "<entry xmlns='http://www.w3.org/2005/Atom'>\n";
    $postData .= "\t<title type='text'>" . revealXml($title) . "</title>\n";
    if ($draft) {
        $postData .= "\t<app:control xmlns:app='http://purl.org/atom/app#'>\n";
        $postData .= "\t\t<app:draft>yes</app:draft>\n";
        $postData .= "\t</app:control>\n";
    }
    $postData .= "\t<content type='xhtml'>\n";
    $postData .= $body;
    //must be valid XML
    $postData .= "\t</content>\n";
    $postData .= "\t<author>\n";
    $postData .= "\t\t<name>" . revealXml($authorName) . "</name>\n";
    $postData .= "\t\t<email>" . revealXml($authorEmail) . "</email>\n";
    $postData .= "\t</author>\n";
    $postData .= "</entry>";
    $textArray['xmlrpc'] = $postData;
    //TODO: how to do submit this to the xmlrpc interface?
    return pullpage('POST', $host, $port, $xmlRpcPath, $username, $password, $proxyUsername, $proxyPassword, $textArray = null, $binaryArray = null, $debug = false, $timeOutInSeconds = null);
}
Пример #2
0
function followUrlRedirects($url, $maximumNumberOfOfRedirects = false)
{
    if ($maximumNumberOfOfRedirects === false) {
        $maximumNumberOfOfRedirects = 10;
    }
    $finalRedirectionUrl = false;
    $redirectPath = array();
    $numberOfRedirectsRemaining = $maximumNumberOfOfRedirects;
    $timeOutInSeconds = 5;
    while ($finalRedirectionUrl == false) {
        $previousUrl = $url;
        $wasRedirectedThisTime = false;
        $domainAndPort = getUrlDomainAndPortPart($url);
        $redirectPath[] = $url;
        $localPart = getUrlLocalPart($url);
        $result = pullpage('HEAD', $domainAndPort[0], $domainAndPort[1], $localPart, false, false, false, false, null, null, false, $timeOutInSeconds);
        if ($result === false) {
            return null;
        }
        $result = explode("\n", $result);
        foreach ($result as $line) {
            $headParts = explode(':', $line);
            if (count($headParts) > 1) {
                $subject = array_shift($headParts);
                $value = implode(':', $headParts);
                if (strtolower(trim($subject)) == "location") {
                    $url = trim($value);
                    if (!stringStartsWith($url, 'http://') && !stringStartsWith($url, 'https://')) {
                        $url = 'http://' . $domainAndPort[0] . $url;
                    }
                    //print "Was redirected to ".$url."<br />";
                    if ($previousUrl != $url) {
                        $wasRedirectedThisTime = true;
                    }
                }
            }
        }
        if ($wasRedirectedThisTime == false) {
            $finalRedirectionUrl = true;
        }
        if ($numberOfRedirectsRemaining <= 0) {
            webServiceError("&error-maximum-number-of-redirects-followed;", 500, array('redirectPaths' => implode("</li><li>", $redirectPath)));
        }
        $numberOfRedirectsRemaining--;
    }
    return $url;
}