/**
 * Fetches additional comment data from the page that sent the pingback
 * @access private
 * @param array comment array to be filled
 */
function fetchPingbackData(&$comment)
{
    global $serendipity;
    // Don't fetch remote page, if not explicitly allowed in serendipity_config_local.php:
    if (empty($serendipity['pingbackFetchPage'])) {
        return;
    }
    // If we don't have a comment or a commentors url, stop it.
    if (!isset($comment) || !is_array($comment) || !isset($comment['url'])) {
        return;
    }
    // Max amount of characters fetched from the page doing a pingback:
    $fetchPageMaxLength = 200;
    if (isset($serendipity['pingbackFetchPageMaxLength'])) {
        $fetchPageMaxLength = $serendipity['pingbackFetchPageMaxLength'];
    }
    require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
    $url = $comment['url'];
    if (function_exists('serendipity_request_start')) {
        serendipity_request_start();
    }
    // Request the page
    $req = new HTTP_Request($url, array('allowRedirects' => true, 'maxRedirects' => 5, 'timeout' => 20, 'readTimeout' => array(5, 0)));
    // code 200: OK, code 30x: REDIRECTION
    $responses = "/(200 OK)|(30[0-9] Found)/";
    // |(30[0-9] Moved)
    if (PEAR::isError($req->sendRequest()) || preg_match($responses, $req->getResponseCode())) {
        // nothing to do,
    } else {
        $fContent = $req->getResponseBody();
        // Get a title
        if (preg_match('@<head[^>]*>.*?<title[^>]*>(.*?)</title>.*?</head>@is', $fContent, $matches)) {
            $comment['title'] = serendipity_entity_decode(strip_tags($matches[1]), ENT_COMPAT, LANG_CHARSET);
        }
        // Try to get content from first <p> tag on:
        if (preg_match('@<p[^>]*>(.*?)</body>@is', $fContent, $matches)) {
            $body = $matches[1];
        }
        if (empty($body) && preg_match('@<body[^>]*>(.*?)</body>@is', $fContent, $matches)) {
            $body = $matches[1];
        }
        // Get a part of the article
        if (!empty($body)) {
            $body = trackback_body_strip($body);
            // truncate the text to 200 chars
            $arr = str_split($body, $fetchPageMaxLength);
            $body = $arr[0];
            $comment['comment'] = $body . '[..]';
        }
    }
    if (function_exists('serendipity_request_end')) {
        serendipity_request_end();
    }
}
/**
 * Fetches additional comment data from the page that sent the pingback
 * @access private
 * @param array comment array to be filled
 */
function fetchPingbackData(&$comment)
{
    global $serendipity;
    // Don't fetch remote page, if not explicitly allowed in serendipity_config_local.php:
    if (empty($serendipity['pingbackFetchPage'])) {
        return;
    }
    // If we don't have a comment or a commentors url, stop it.
    if (!isset($comment) || !is_array($comment) || !isset($comment['url'])) {
        return;
    }
    // Max amount of characters fetched from the page doing a pingback:
    $fetchPageMaxLength = 200;
    if (isset($serendipity['pingbackFetchPageMaxLength'])) {
        $fetchPageMaxLength = $serendipity['pingbackFetchPageMaxLength'];
    }
    require_once S9Y_PEAR_PATH . 'HTTP/Request2.php';
    $url = $comment['url'];
    if (function_exists('serendipity_request_start')) {
        serendipity_request_start();
    }
    // Request the page
    $options = array('follow_redirects' => true, 'max_redirects' => 5, 'timeout' => 20);
    if (version_compare(PHP_VERSION, '5.6.0', '<')) {
        // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1
        $options['ssl_verify_peer'] = false;
    }
    $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET, $options);
    // code 200: OK, code 30x: REDIRECTION
    $responses = "/(200)|(30[0-9])/";
    // |(30[0-9] Moved)
    try {
        $response = $req->send();
        if (preg_match($responses, $response->getStatus())) {
        }
        $fContent = $response->getBody();
        // Get a title
        if (preg_match('@<head[^>]*>.*?<title[^>]*>(.*?)</title>.*?</head>@is', $fContent, $matches)) {
            $comment['title'] = serendipity_entity_decode(strip_tags($matches[1]), ENT_COMPAT, LANG_CHARSET);
        }
        // Try to get content from first <p> tag on:
        if (preg_match('@<p[^>]*>(.*?)</body>@is', $fContent, $matches)) {
            $body = $matches[1];
        }
        if (empty($body) && preg_match('@<body[^>]*>(.*?)</body>@is', $fContent, $matches)) {
            $body = $matches[1];
        }
        // Get a part of the article
        if (!empty($body)) {
            $body = trackback_body_strip($body);
            // truncate the text to 200 chars
            $arr = str_split($body, $fetchPageMaxLength);
            $body = $arr[0];
            $comment['comment'] = $body . '[..]';
        }
    } catch (HTTP_Request2_Exception $e) {
    }
    if (function_exists('serendipity_request_end')) {
        serendipity_request_end();
    }
}