예제 #1
0
파일: crawler.php 프로젝트: 01J/bealtine
 function _parseLinks($url, &$found)
 {
     // Get response, follow 5 redirections
     $redirs = 0;
     do {
         $redirect = false;
         $response = SEFTools::PostRequest($url, null, null, 'get', null);
         if ($response === false) {
             // Error
             return;
         }
         if ($redirs < 5 && $response->code >= 300 && $response->code < 400) {
             // Parse redirect URL
             $pos = stripos($response->header, 'location:');
             if ($pos !== false) {
                 $pos += 9;
                 // Skip header name
                 $pos2 = strpos($response->header, "\r", $pos);
                 $url = substr($response->header, $pos, $pos2 - $pos);
                 $url = trim($url);
                 $redirect = true;
                 $redirs++;
             }
         }
     } while ($redirect);
     // Check code
     if ($response->code == 200) {
         // Parse URLs
         $matches = array();
         if (preg_match_all('#<a\\s[^>]*href=["\']([^"\']+)#i', $response->content, $matches) > 0) {
             // Loop through found URLs
             foreach ($matches[1] as $link) {
                 $link = str_replace(JURI::root(), '', $link);
                 if (strpos($link, '://') !== false) {
                     // Absolute external link, skip
                     continue;
                 }
                 // Internal link
                 $link = JURI::root() . ltrim(html_entity_decode(urldecode($link)), '/');
                 if (!in_array($link, $found)) {
                     $found[] = $link;
                 }
             }
         }
     }
 }
예제 #2
0
 function _getPackageFromServer($extension)
 {
     // Make sure that zlib is loaded so that the package can be unpacked
     if (!extension_loaded('zlib')) {
         JError::raiseWarning(100, JText::_('WARNINSTALLZLIB'));
         return false;
     }
     // build the appropriate paths
     $sefConfig =& SEFConfig::getConfig();
     $config =& JFactory::getConfig();
     if (empty($extension)) {
         $tmp_dest = $config->getValue('config.tmp_path') . DS . 'joomsef.zip';
     } else {
         $tmp_dest = $config->getValue('config.tmp_path') . DS . $extension . '.zip';
     }
     // Validate the upgrade on server
     $data = array();
     $data['username'] = $sefConfig->artioUserName;
     $data['password'] = $sefConfig->artioPassword;
     if (empty($extension)) {
         $data['download_id'] = $sefConfig->artioDownloadId;
         $data['file'] = 'com_joomsef';
     } else {
         $params =& SEFTools::getExtParams($extension);
         $data['download_id'] = $params->get('downloadId', '');
         $data['file'] = 'ext_joomsef3_' . substr($extension, 4);
     }
     $uri = parse_url(JURI::root());
     $url = $uri['host'] . $uri['path'];
     $url = trim($url, '/');
     $data['site'] = $url;
     $data['ip'] = $_SERVER['SERVER_ADDR'];
     $lang =& JFactory::getLanguage();
     $data['lang'] = $lang->getTag();
     $data['cat'] = 'joomsef3';
     // Get the server response
     $response = SEFTools::PostRequest($sefConfig->serverAutoUpgrade, JURI::root(), $data);
     // Check the response
     if ($response === false || $response->code != 200) {
         JError::raiseWarning(100, JText::_('Connection to server could not be established.'));
         return false;
     }
     // Response OK, check what we got
     if (strpos($response->header, 'Content-Type: application/zip') === false) {
         JError::raiseWarning(100, $response->content);
         return false;
     }
     // Seems we got the ZIP installation package, let's save it to disk
     if (!JFile::write($tmp_dest, $response->content)) {
         JError::raiseWarning(100, JText::_('Unable to save installation file in temp directory.'));
         return false;
     }
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest);
     // Delete the package file
     JFile::delete($tmp_dest);
     return $package;
 }
예제 #3
0
 function getPageSpeed($url)
 {
     require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'classes' . DS . 'config.php';
     $url = str_replace("/administrator", "", JFactory::getURI()->base()) . $url;
     $config = SEFConfig::getConfig();
     $ndata = new stdClass();
     if (strlen($config->google_apikey) == 0) {
         return false;
     }
     $google_url = 'https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=' . urlencode($url) . '&key=' . $config->google_apikey;
     if (function_exists('curl_init')) {
         $c = curl_init($google_url);
         curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($c, CURLOPT_ENCODING, "utf-8");
         $data = curl_exec($c);
         curl_close($c);
     } else {
         // Try to use our own method
         $data = SEFTools::PostRequest($google_url, null, null, 'get');
         if ($data !== false) {
             $data = $data->content;
         }
     }
     if ($data === false) {
         // Could not connect
         return false;
     }
     $data = json_decode($data);
     $ndata = new stdClass();
     if (isset($data->error)) {
         $ndata->message = $data->error->errors[0]->message;
         return $ndata;
     }
     @($ndata->pageStats = $data->pageStats);
     @($ndata->score = $data->score);
     $reg = new JRegistry();
     $reg->loadObject($ndata);
     return $reg->toString("ini");
 }
예제 #4
0
 function getPageSpeed($url)
 {
     require_once JPATH_COMPONENT_ADMINISTRATOR . '/classes/config.php';
     $url = rtrim(JURI::root(), '/') . '/' . ltrim($url, '/');
     $config = SEFConfig::getConfig();
     $ndata = new stdClass();
     if (strlen($config->google_apikey) == 0) {
         return false;
     }
     $google_url = 'https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=' . urlencode($url) . '&key=' . $config->google_apikey;
     // Use CURL if available
     if (function_exists('curl_init')) {
         $certFile = realpath(dirname(__FILE__) . '/../cacert.pem');
         $c = curl_init($google_url);
         curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($c, CURLOPT_ENCODING, "utf-8");
         curl_setopt($c, CURLOPT_CAINFO, $certFile);
         $data = curl_exec($c);
         curl_close($c);
     } else {
         // Try to use our own method
         $data = SEFTools::PostRequest($google_url, null, null, 'get');
         if ($data !== false) {
             $data = $data->content;
         }
     }
     if ($data === false) {
         // Could not connect
         return false;
     }
     $data = json_decode($data);
     $ndata = new stdClass();
     if (isset($data->error)) {
         $ndata->message = $data->error->errors[0]->message;
         return $ndata;
     }
     @($ndata->pageStats = $data->pageStats);
     @($ndata->score = $data->score);
     $reg = new JRegistry();
     $reg->loadObject($ndata);
     return $reg->toString("ini");
 }
예제 #5
0
 function _getPackageFromServer()
 {
     $extension = trim(JRequest::getString('extension'));
     // Make sure we have an extension selected
     if (empty($extension)) {
         JError::raiseWarning(100, JText::_('COM_SEF_NO_EXTENSION_SELECTED'));
         return false;
     }
     // Make sure that zlib is loaded so that the package can be unpacked
     if (!extension_loaded('zlib')) {
         JError::raiseWarning(100, JText::_('COM_SEF_WARNINSTALLZLIB'));
         return false;
     }
     // build the appropriate paths
     $sefConfig =& SEFConfig::getConfig();
     $config =& JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path') . '/' . $extension . '.zip';
     // Validate the upgrade on server
     $data = array();
     $data['username'] = $sefConfig->artioUserName;
     $data['password'] = $sefConfig->artioPassword;
     $params =& SEFTools::getExtParams($extension);
     $data['download_id'] = $params->get('downloadId', '');
     $data['file'] = 'ext_joomsef4_' . substr($extension, 4);
     $uri = parse_url(JURI::root());
     $url = $uri['host'] . $uri['path'];
     $url = trim($url, '/');
     $data['site'] = $url;
     $data['ip'] = $_SERVER['SERVER_ADDR'];
     $lang =& JFactory::getLanguage();
     $data['lang'] = $lang->getTag();
     $data['cat'] = 'joomsef4';
     // Get the server response
     $response = SEFTools::PostRequest($sefConfig->serverAutoUpgrade, JURI::root(), $data);
     // Check the response
     if ($response === false || $response->code != 200) {
         JError::raiseWarning(100, JText::_('COM_SEF_ERROR_SERVER_CONNECTION'));
         return false;
     }
     // Response OK, check what we got
     if (strpos($response->header, 'Content-Type: application/zip') === false) {
         JError::raiseWarning(100, $response->content);
         return false;
     }
     // Seems we got the ZIP installation package, let's save it to disk
     if (!JFile::write($tmp_dest, $response->content)) {
         JError::raiseWarning(100, JText::_('COM_SEF_ERROR_TEMP_DIRECTORY'));
         return false;
     }
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest);
     // Delete the package file
     JFile::delete($tmp_dest);
     return $package;
 }
 function getData($metrics, $dimensions = "", $sort = "", $max_results = "50")
 {
     $google_url = $this->_feed . "data";
     $headers = array();
     $headers[] = "GData-Version: 2";
     $headers[] = "Authorization: GoogleLogin auth=\"" . $this->_info["Auth"] . "\"";
     $url_params = array();
     $url_params["ids"] = "ga:" . JRequest::getInt('account_id', $this->_default_id);
     $url_params["start-date"] = JRequest::getString('start_date', JFactory::getDate(JFactory::getDate()->toUnix() - 60 * 60 * 24 * 7)->toFormat("%Y-%m-%d"));
     $url_params["end-date"] = JRequest::getString('end_date', JFactory::getDate()->toFormat("%Y-%m-%d"));
     $url_params["prettyprint"] = "true";
     $url_params["metrics"] = $metrics;
     $url_params["dimensions"] = $dimensions;
     $url_params["sort"] = $sort;
     $url_params["max-results"] = $max_results;
     $google_url .= "?" . http_build_query($url_params);
     if (function_exists('curl_init')) {
         // Use CURL
         $c = curl_init($google_url);
         curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
         $data = curl_exec($c);
         curl_close($c);
     } else {
         // Try to use OpenSSL
         $response = SEFTools::PostRequest($google_url, null, null, 'get', null, $headers);
         if ($response === false) {
             return array();
         }
         $data = $response->content;
     }
     if (!$data) {
         return array();
     }
     $xml = new DomDocument("1.0");
     if ($xml->loadXML($data) === false) {
         return array();
     }
     return $this->_processData($xml->getElementsByTagName('entry'));
 }