Ejemplo n.º 1
0
 public function getMetrics($domain)
 {
     $pageCount = $this->fetchIndexedPagesCount($domain);
     $pageRank = $this->fetchPageRank($domain);
     $logo = SearchEngine::getInstance()->getLogoFromUrl('http://google.com');
     return array(new Metric('google-index', 'SEO_Google_IndexedPages', $pageCount, $logo, null, null, 'General_Pages'), new Metric('pagerank', 'Google PageRank', $pageRank, $logo, null, null, '/10'));
 }
Ejemplo n.º 2
0
 /**
  * Update the search engine definitions
  *
  * @see https://github.com/piwik/searchengine-and-social-list
  */
 public function updateSearchEngines()
 {
     $url = 'https://raw.githubusercontent.com/piwik/searchengine-and-social-list/master/SearchEngines.yml';
     $list = Http::sendHttpRequest($url, 30);
     $searchEngines = SearchEngine::getInstance()->loadYmlData($list);
     if (count($searchEngines) < 200) {
         return;
     }
     Option::set(SearchEngine::OPTION_STORAGE_NAME, base64_encode(serialize($searchEngines)));
 }
Ejemplo n.º 3
0
 public function getMetrics($domain)
 {
     try {
         $response = Http::sendHttpRequest(self::URL . urlencode($domain), $timeout = 10, @$_SERVER['HTTP_USER_AGENT']);
         $xml = @simplexml_load_string($response);
         $value = $xml ? NumberFormatter::getInstance()->formatNumber((int) $xml->SD->POPULARITY['TEXT']) : null;
     } catch (\Exception $e) {
         $this->logger->warning('Error while getting Alexa SEO stats: {message}', array('message' => $e->getMessage()));
         $value = null;
     }
     $logo = SearchEngine::getInstance()->getLogoFromUrl('http://alexa.com');
     $link = self::LINK . urlencode($domain);
     return array(new Metric('alexa', 'SEO_AlexaRank', $value, $logo, $link));
 }
Ejemplo n.º 4
0
Archivo: Bing.php Proyecto: piwik/piwik
 public function getMetrics($domain)
 {
     $url = self::URL . urlencode($domain);
     try {
         $response = str_replace('&nbsp;', ' ', Http::sendHttpRequest($url, $timeout = 10, @$_SERVER['HTTP_USER_AGENT']));
         if (preg_match('#([0-9,\\.]+) results#i', $response, $p)) {
             $pageCount = NumberFormatter::getInstance()->formatNumber((int) str_replace(array(',', '.'), '', $p[1]));
         } else {
             $pageCount = 0;
         }
     } catch (\Exception $e) {
         $this->logger->warning('Error while getting Bing SEO stats: {message}', array('message' => $e->getMessage()));
         $pageCount = null;
     }
     $logo = SearchEngine::getInstance()->getLogoFromUrl('http://bing.com');
     return array(new Metric('bing-index', 'SEO_Bing_IndexedPages', $pageCount, $logo, null, null, 'General_Pages'));
 }
 /**
  * @param DataTable $table
  */
 public function filter($table)
 {
     $idSubtable = $this->idSubtable ?: $table->getId();
     $subTableRow = $this->firstLevelSearchEnginesTable->getRowFromIdSubDataTable($idSubtable);
     if (!empty($subTableRow)) {
         $searchEngineUrl = $subTableRow->getMetadata('url');
         $table->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', function ($keyword, $url) {
             return SearchEngine::getInstance()->getBackLinkFromUrlAndKeyword($url, $keyword);
         }, array($searchEngineUrl)));
         $table->queueFilter(function (DataTable $table) {
             $row = $table->getRowFromId(DataTable::ID_SUMMARY_ROW);
             if ($row) {
                 $row->deleteMetadata('url');
             }
         });
     }
     $table->queueFilter('Piwik\\Plugins\\Referrers\\DataTable\\Filter\\KeywordNotDefined');
 }
Ejemplo n.º 6
0
 public function getMetrics($domain)
 {
     try {
         $response = Http::sendHttpRequest(self::URL . urlencode($domain), $timeout = 10, @$_SERVER['HTTP_USER_AGENT']);
         preg_match('#DMOZ Sites[^\\(]+\\([0-9]-[0-9]+ of ([0-9]+)\\)#', $response, $p);
         if (!empty($p[1])) {
             $value = NumberFormatter::getInstance()->formatNumber((int) $p[1]);
         } else {
             $value = 0;
         }
         // Add DMOZ only if > 0 entries found
         if ($value == 0) {
             return array();
         }
     } catch (\Exception $e) {
         $this->logger->warning('Error while getting Dmoz SEO stats: {message}', array('message' => $e->getMessage()));
         $value = null;
     }
     $logo = SearchEngine::getInstance()->getLogoFromUrl('http://dmoz.org');
     return array(new Metric('dmoz', 'SEO_Dmoz', $value, $logo));
 }
 /**
  * @param DataTable $table
  */
 public function filter($table)
 {
     $idSubtable = $this->idSubtable ?: $table->getId();
     $table->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', function ($url) {
         return SearchEngine::getInstance()->getUrlFromName($url);
     }));
     $table->queueFilter('MetadataCallbackAddMetadata', array('url', 'logo', function ($url) {
         return SearchEngine::getInstance()->getLogoFromUrl($url);
     }));
     // get the keyword and create the URL to the search result page
     $rootRow = $this->firstLevelKeywordTable->getRowFromIdSubDataTable($idSubtable);
     if ($rootRow) {
         $keyword = $rootRow->getColumn('label');
         $table->queueFilter('MetadataCallbackReplace', array('url', function ($url, $keyword) {
             return SearchEngine::getInstance()->getBackLinkFromUrlAndKeyword($url, $keyword);
         }, array($keyword)));
         $table->queueFilter(function (DataTable $table) {
             $row = $table->getRowFromId(DataTable::ID_SUMMARY_ROW);
             if ($row) {
                 $row->deleteMetadata('url');
             }
         });
     }
 }
Ejemplo n.º 8
0
 /**
  * favicon exists but there's no corresponding search engine defined
  */
 public function testObsoleteSearchEngineIcons()
 {
     // Get list of search engines and first appearing URL
     $searchEngines = array();
     foreach (SearchEngine::getInstance()->getDefinitions() as $url => $searchEngine) {
         $name = parse_url('http://' . $url);
         if (!array_key_exists($name['host'], $searchEngines)) {
             $searchEngines[$name['host']] = true;
         }
     }
     // Get list of existing favicons
     $favicons = scandir(PIWIK_PATH_TEST_TO_ROOT . '/plugins/Referrers/images/searchEngines/');
     foreach ($favicons as $name) {
         if ($name[0] == '.' || strpos($name, 'xx.') === 0) {
             continue;
         }
         $host = substr($name, 0, -4);
         $this->assertTrue(array_key_exists($host, $searchEngines), $host);
     }
 }
Ejemplo n.º 9
0
 protected function detectCampaignKeywordFromReferrerUrl()
 {
     if (!empty($this->nameReferrerAnalyzed) && !empty($this->keywordReferrerAnalyzed)) {
         // keyword is already set, we skip
         return true;
     }
     // Set the Campaign keyword to the keyword found in the Referrer URL if any
     if (!empty($this->nameReferrerAnalyzed)) {
         $referrerUrlInfo = SearchEngineDetection::getInstance()->extractInformationFromUrl($this->referrerUrl);
         if (!empty($referrerUrlInfo['keywords'])) {
             $this->keywordReferrerAnalyzed = $referrerUrlInfo['keywords'];
         }
     }
     // Set the keyword, to the hostname found, in a Adsense Referrer URL '&url=' parameter
     if (empty($this->keywordReferrerAnalyzed) && !empty($this->referrerUrlParse['query']) && !empty($this->referrerHost) && (strpos($this->referrerHost, 'googleads') !== false || strpos($this->referrerHost, 'doubleclick') !== false)) {
         // This parameter sometimes is found & contains the page with the adsense ad bringing visitor to our site
         $value = $this->getParameterValueFromReferrerUrl('url');
         if (!empty($value)) {
             $parsedAdsenseReferrerUrl = parse_url($value);
             if (!empty($parsedAdsenseReferrerUrl['host'])) {
                 if (empty($this->nameReferrerAnalyzed)) {
                     $type = $this->getParameterValueFromReferrerUrl('ad_type');
                     $type = $type ? " ({$type})" : '';
                     $this->nameReferrerAnalyzed = self::LABEL_ADWORDS_NAME . $type;
                     $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_CAMPAIGN;
                 }
                 $this->keywordReferrerAnalyzed = self::LABEL_PREFIX_ADWORDS_KEYWORD . $parsedAdsenseReferrerUrl['host'];
             }
         }
     }
 }
Ejemplo n.º 10
0
 public function getSearchEngineIcon()
 {
     $searchEngineUrl = $this->getSearchEngineUrl();
     if (!is_null($searchEngineUrl)) {
         return SearchEngine::getInstance()->getLogoFromUrl($searchEngineUrl);
     }
     return null;
 }
Ejemplo n.º 11
0
 public function getSearchEngines($idSite, $period, $date, $segment = false, $expanded = false, $flat = false)
 {
     $dataTable = Archive::createDataTableFromArchive(Archiver::SEARCH_ENGINES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded, $flat);
     if ($flat) {
         $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'url', function ($url) {
             return SearchEngine::getInstance()->getUrlFromName($url);
         }));
         $dataTable->filter('MetadataCallbackAddMetadata', array('url', 'logo', function ($url) {
             return SearchEngine::getInstance()->getLogoFromUrl($url);
         }));
         $dataTable->filterSubtables('Piwik\\Plugins\\Referrers\\DataTable\\Filter\\KeywordsFromSearchEngineId', array($dataTable));
     } else {
         $dataTable->filter('AddSegmentByLabel', array('referrerName'));
         $dataTable->queueFilter('PrependSegment', array('referrerType==search;'));
         $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', function ($url) {
             return SearchEngine::getInstance()->getUrlFromName($url);
         }));
         $dataTable->queueFilter('MetadataCallbackAddMetadata', array('url', 'logo', function ($url) {
             return SearchEngine::getInstance()->getLogoFromUrl($url);
         }));
     }
     return $dataTable;
 }