Exemplo n.º 1
0
 /**
  * Scan content of source url for a trackback url
  *
  * @return str - trackback url
  *
  * Adapted from Pligg.com and SocialWebCMS.com
  */
 private function detectTrackback($h)
 {
     // Fetch the content of the original url...
     $url = $h->post->origUrl;
     $content = $url != 'http://' && $url != '' ? hotaru_http_request($url) : '';
     $trackback = '';
     if (preg_match('/trackback:ping="([^"]+)"/i', $content, $matches) || preg_match('/trackback:ping +rdf:resource="([^>]+)"/i', $content, $matches) || preg_match('/<trackback:ping>([^<>]+)/i', $content, $matches)) {
         $trackback = trim($matches[1]);
     } elseif (preg_match('/<a[^>]+rel="trackback"[^>]*>/i', $content, $matches)) {
         if (preg_match('/href="([^"]+)"/i', $matches[0], $matches2)) {
             $trackback = trim($matches2[1]);
         }
     } elseif (preg_match('/<a[^>]+href=[^>]+>trackback<\\/a>/i', $content, $matches)) {
         if (preg_match('/href="([^"]+)"/i', $matches[0], $matches2)) {
             $trackback = trim($matches2[1]);
         }
     } elseif (preg_match('/http:([^ ]+)trackback.php([^<|^ ]+)/i', $content, $matches)) {
         $trackback = trim($matches[1]);
     } elseif (preg_match('/trackback:ping="([^"]+)"/', $content, $matches)) {
         $trackback = trim($matches[1]);
     }
     return $trackback;
 }
Exemplo n.º 2
0
function hotaru_http_request($url)
{
    $response = "";
    if (substr($url, 0, 4) != 'http') {
        return 'The URL provided is missing the "http", can not continue with request';
    }
    $req = $url;
    $pos = strpos($req, '://');
    $protocol = strtolower(substr($req, 0, $pos));
    $req = substr($req, $pos + 3);
    $pos = strpos($req, '/');
    if ($pos === false) {
        $pos = strlen($req);
    }
    $host = substr($req, 0, $pos);
    if (strpos($host, ':') !== false) {
        list($host, $port) = explode(':', $host);
    } else {
        $port = $protocol == 'https' ? 443 : 80;
    }
    $uri = substr($req, $pos);
    if (empty($uri)) {
        $uri = '/';
    }
    $crlf = "\r\n";
    // generate request
    $req = 'GET ' . $uri . ' HTTP/1.0' . $crlf . 'Host: ' . $host . $crlf . $crlf;
    error_reporting(E_ERROR);
    // fetch
    $fp = fsockopen(($protocol == 'https' ? 'tls://' : '') . $host, $port, $errno, $errstr, 20);
    if (!$fp) {
        return "BADURL";
    }
    fwrite($fp, $req);
    while (is_resource($fp) && $fp && !feof($fp)) {
        $response .= fread($fp, 1024);
    }
    fclose($fp);
    // split header and body
    $pos = strpos($response, $crlf . $crlf);
    if ($pos === false) {
        return $response;
    }
    $header = substr($response, 0, $pos);
    $body = substr($response, $pos + 2 * strlen($crlf));
    // parse headers
    $headers = array();
    $lines = explode($crlf, $header);
    foreach ($lines as $line) {
        if (($pos = strpos($line, ':')) !== false) {
            $headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos + 1));
        }
    }
    // redirection?
    if (isset($headers['location'])) {
        return hotaru_http_request($headers['location']);
    }
    return $body;
}