Exemplo n.º 1
0
 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;
 }