Пример #1
0
 function get_title()
 {
     $req = new WP_HTTP_Request($this->_url);
     $imdb = $req->DownloadToString();
     preg_match('/<meta property.+?og:title.+?content=[\'"](.+?)[\'"].+?\\/>/i', $imdb, $title_matches);
     $this->_title = $title_matches[1];
     if (empty($this->_title)) {
         return '<div id="message" class="error fade"><p><strong>Error while retrieving the title of the movie from imdb.</strong></p></div>';
     } else {
         return "";
     }
 }
 function DownloadToString()
 {
     $crlf = "\r\n";
     # generate request
     $req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf . 'Host: ' . $this->_host . $crlf . $crlf;
     # fetch
     $response = '';
     $this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
     fwrite($this->_fp, $req);
     while (is_resource($this->_fp) && $this->_fp && !feof($this->_fp)) {
         $response .= fread($this->_fp, 1024);
     }
     fclose($this->_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'])) {
         $http = new WP_HTTP_Request($headers['location']);
         return $http->DownloadToString($http);
     } else {
         return $body;
     }
 }