function GetPR($url, $forceNoCache = false) { $total_exec_start = $this->microtimeFloat(); $result = array("", -1); if ($url . "" != "" && $url . "" != "http://") { $this->debugRes("url", $url); $this->cacheDir .= substr($this->cacheDir, -1) != "/" ? "/" : ""; // check for protocol $url_ = substr(strtolower($url), 0, 7) != "http://" ? "http://" . $url : $url; $host = $this->googleDomains[mt_rand(0, count($this->googleDomains) - 1)]; $target = "/search"; $querystring = sprintf("client=navclient-auto&ch=%s&features=Rank&q=%s", $this->CheckHash($this->HashURL($url_)), urlencode("info:" . $url_)); $contents = ""; $this->debugRes("host", $host); $this->debugRes("query_string", $querystring); $this->debugRes("user_agent", $this->userAgent); $query_exec_start = $this->microtimeFloat(); if ($forceNoCache == true) { $this->debugRes("force_no_cache", "true"); } elseif ($contents = $this->readCacheResult($url)) { $this->debugRes("read_from_cache", "true"); } else { $this->cacheExpired = true; } $contents = rsseoHelper::fopen("http://" . $host . $target . "?" . $querystring, 0); if ($this->cacheExpired == true) { $this->updateCacheResult($url, $contents); } $this->debugRes("query_exec_time", $this->microtimeFloat() - $query_exec_start); $result[0] = $contents; // Rank_1:1:0 = 0 // Rank_1:1:5 = 5 // Rank_1:1:9 = 9 // Rank_1:2:10 = 10 etc $p = explode(":", $contents); if (isset($p[2])) { $result[1] = $p[2]; } } if ($result[1] == -1) { $result[1] = 0; } $this->PageRank = (int) $result[1]; $this->debugRes("total_exec_time", $this->microtimeFloat() - $total_exec_start); $this->debugRes("result", $result); return $this->PageRank; }
function getContent($url) { return rsseoHelper::fopen($url); }
function checkPage($idPage) { $app =& JFactory::getApplication(); $rsseoConfig = $app->getuserState('rsseoConfig'); $db =& JFactory::getDBO(); JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_rsseo' . DS . 'tables'); $page =& JTable::getInstance('rsseo_pages', 'Table'); $page->load($idPage); $parser = rsseoHelper::file_get_html(JURI::root() . $page->PageURL, 0); $html = rsseoHelper::fopen(JURI::root() . $page->PageURL); $link = JURI::root() . $page->PageURL; $title = ''; $description = ''; $keywords = ''; $images = 0; $images_no_alt = 0; $images_no_hw = 0; $links = 0; preg_match('#<title>(.*?)<\\/title>#', $html, $match); preg_match_all('#<h([0-9+])(.*?)<\\/h([0-9+])>#is', $html, $matches); $title = @$match[1]; $headings = count($matches[0]); while ($parser->parse()) { if ($parser->iNodeName == 'a' && isset($parser->iNodeAttributes['href'])) { $links++; } if (strtolower($parser->iNodeName) == 'meta' && @$parser->iNodeAttributes['name'] == 'description') { $description = $parser->iNodeAttributes['content']; } if (strtolower($parser->iNodeName) == 'meta' && @$parser->iNodeAttributes['name'] == 'keywords') { $keywords = $parser->iNodeAttributes['content']; } if (empty($title) && strtolower($parser->iNodeName) == 'meta' && @$parser->iNodeAttributes['name'] == 'title') { $title = $parser->iNodeAttributes['content']; } if (strtolower($parser->iNodeName) == 'img') { $images++; } if (strtolower($parser->iNodeName) == 'img' && !isset($parser->iNodeAttributes['alt'])) { $images_no_alt++; } if (strtolower($parser->iNodeName) == 'img' && !isset($parser->iNodeAttributes['width']) && !isset($parser->iNodeAttributes['height'])) { $images_no_hw++; } } $valid_text = strtolower(strip_tags($html)); $density_keywords = $page->PageKeywordsDensity; if (!empty($density_keywords)) { $density_keywords = explode(',', $density_keywords); array_walk($density_keywords, array('rsseoHelper', 'lowercasearray')); $density_keywords = array_unique($density_keywords); $densityparams = array(); foreach ($density_keywords as $keyword) { if (empty($keyword)) { continue; } $densityparams[$keyword] = rsseoHelper::keywordDensity($valid_text, $keyword); } $registry = JRegistry::getInstance('density'); $registry->loadArray($densityparams); $page->densityparams = $registry->toString(); } else { $page->densityparams = ''; } $page->PageTitle = $title; $page->PageDescription = $description; $page->PageKeywords = $keywords; //build the params $params = array(); //check if url is sef friendly if (strpos($page->PageURL, ".php?") === FALSE) { $params['url_sef'] = 1; } else { $params['url_sef'] = 0; } //check if page title is unique $db->setQuery("SELECT COUNT(*) cnt FROM #__rsseo_pages WHERE PageTitle = '" . $db->getEscaped($page->PageTitle) . "' AND published = 1 "); $params['duplicate_title'] = $db->loadResult(); //check title length $params['title_length'] = strlen($page->PageTitle); //check if page meta description is unique $db->setQuery("SELECT COUNT(*) cnt FROM #__rsseo_pages WHERE PageDescription = '" . $db->getEscaped($page->PageDescription) . "' AND published = 1 "); $params['duplicate_desc'] = $db->loadResult(); //check description length $params['description_length'] = strlen($page->PageDescription); //check number of keywords $keyw = trim($keywords) != '' ? explode(',', $page->PageKeywords) : array(); $params['keywords'] = count($keyw); $params['headings'] = $headings; $params['images'] = $images; $params['images_wo_alt'] = $images_no_alt; $params['images_wo_hw'] = $images_no_hw; $params['links'] = $links; $reg = JRegistry::getInstance(''); $reg->loadArray($params); $page->params = $reg->toString(); //the raw html $page->_link = $link; //the page grade $grade = 0; $total = 0; if ($params['url_sef'] == 1 && $rsseoConfig['crawler.sef']) { $grade++; } if ($params['duplicate_title'] == 1 && $rsseoConfig['crawler.title.duplicate']) { $grade++; } if ($params['title_length'] >= 10 && $params['title_length'] <= 70 && $rsseoConfig['crawler.title.length']) { $grade++; } if ($params['duplicate_desc'] == 1 && $rsseoConfig['crawler.description.duplicate']) { $grade++; } if ($params['description_length'] >= 70 && $params['description_length'] <= 150 && $rsseoConfig['crawler.description.length']) { $grade++; } if ($params['keywords'] <= 10 && $rsseoConfig['crawler.keywords']) { $grade++; } if ($params['headings'] > 0 && $rsseoConfig['crawler.headings']) { $grade++; } if ($params['images'] <= 10 && $rsseoConfig['crawler.images']) { $grade++; } if ($params['images_wo_alt'] == 0 && $rsseoConfig['crawler.images.alt']) { $grade++; } if ($params['images_wo_hw'] == 0 && $rsseoConfig['crawler.images.hw']) { $grade++; } if ($params['links'] <= 100) { $grade++; } if ($rsseoConfig['crawler.sef']) { $total++; } if ($rsseoConfig['crawler.title.duplicate']) { $total++; } if ($rsseoConfig['crawler.title.length']) { $total++; } if ($rsseoConfig['crawler.description.duplicate']) { $total++; } if ($rsseoConfig['crawler.description.length']) { $total++; } if ($rsseoConfig['crawler.keywords']) { $total++; } if ($rsseoConfig['crawler.headings']) { $total++; } if ($rsseoConfig['crawler.images']) { $total++; } if ($rsseoConfig['crawler.images.alt']) { $total++; } if ($rsseoConfig['crawler.images.hw']) { $total++; } if ($rsseoConfig['crawler.intext.links']) { $total++; } $page->PageGrade = $grade * 100 / $total; return $page; }