/** * Using CURL get page source. * * @param string $url Link to get content * * @return string */ protected static function curlResponse($url) { $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13", CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYPEER => false); $ch = curl_init($url); curl_setopt_array($ch, $options); $contents = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch); $header = curl_getinfo($ch); curl_close($ch); if ($err > 0) { exit('cUrl error number: ' . $err); } $response = new stdClass(); $response->contents = $contents; $response->redirect_url = $header['redirect_url']; if ($response->redirect_url != self::$_renderUrl and trim($response->redirect_url) != '') { $old_uri = new JURI(self::$_renderUrl); $redirect_uri = new JURI($response->redirect_url); if ($old_uri->hasVar('tp') and !$redirect_uri->hasVar('tp')) { $redirect_uri->setVar('tp', 1); } if ($old_uri->hasVar('jsntpl_position') and !$redirect_uri->hasVar('jsntpl_position')) { $redirect_uri->setVar('jsntpl_position', 1); } if ($old_uri->hasVar('secret_key') and !$redirect_uri->hasVar('secret_key')) { $config = JFactory::getConfig(); $secret = $config->get('secret'); $redirect_uri->setVar('secret_key', md5($secret)); } if ($old_uri->hasVar('Itemid') and !$redirect_uri->hasVar('Itemid')) { $redirect_uri->setVar('Itemid', $old_uri->getVar('Itemid')); } // Save redirect url self::$_renderUrl = $redirect_uri->toString(); $response = self::curlResponse(self::$_renderUrl); } return $response; }