/** * Retrieves a remote url using CURL making absolute links relative * @param string $urlToLoad * @return string HTML */ static function loadUrl($urlToLoad) { // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $urlToLoad); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //set up proxy if specified if (isset(MediabirdConfig::$proxy_address) && strlen(MediabirdConfig::$proxy_address) > 0) { curl_setopt($ch, CURLOPT_PROXY, MediabirdConfig::$proxy_address . ":" . MediabirdConfig::$proxy_port); } //execute $html = curl_exec($ch); //check for error if ($html === false) { return null; } // grab URL and pass it to the browser $finalUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // grab content type and pass it to the browser $type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); if (isset($type)) { header('Content-Type: ' . $type); } //parse the url $path = parse_url($finalUrl); //remove last bit of path if (isset($path['path'])) { $li = strrpos($path['path'], "/"); if ($li > -1) { $path['path'] = substr($path['path'], 0, $li + 1); } } //forget about query and fragment unset($path['query']); unset($path['fragment']); //construct base url self::$baseUrl = self::__glueUrl($path); //construct the root url unset($path['path']); self::$rootUrl = self::__glueUrl($path); //correct relative URIs $html = self::makeLinksAbsolute($html); // close cURL resource, and free up system resources curl_close($ch); //echo modified HTML return $html; }