
seostats
PHP Class SEOstats
Important Update
The project page moved to GitHub! To download the latest version, please visit https://github.com/eyecatchup/SEOstats
The documentation will stay for whatever reason, but no longer be updated.
Issue must be reported to GitHub, too.
Best regards,
Stephan.
Project Description
SEOstats is a powerful open source PHP class to get a lot of SEO relevant data such as detailed backlink analyses,
keyword and traffic statistics, website trends, page authority, the Google Pagerank, the Alexa Trafficrank and much more.
Therefore SEOstats gathers data from Google, Yahoo, Bing, Majesticseo, SEOmoz, Alexa, Facebook and Twitter. SEOstats offers over 50 different methods to request SEO relevant data for websites.
Table of Contents
Demo
Two live demos are available at:
- http://demos.bexton.net/seostats/index.php
- http://demos.bexton.net/seostats/demo.html
There is also an iframe based Facebook App Version of the demo, that can be used as a custom tab to your Facebook profile page.
Therefore use the "Add to my page" link on the apps' profile page (2nd link).
- http://apps.facebook.com/seo-check/
- http://www.facebook.com/apps/application.php?id=181872768521082&sk=app_181872768521082
Feature Requests
New feature requests can be placed at: http://bexton.net/php-class-seostats/
Back-to-Back Credit
The usage of SEOstats is completely free.
But as a little back-to-back credit, i appreciate when you give me a backlink to my business site from any of your projects.
You will find pre-formed backlinks at http://www.nahklick.de/backlinks/'>http://www.nahklick.de/backlinks/
Thank you!
Download
Direct link to the latest version: https://github.com/eyecatchup/SEOstats/zipball/master'>https://github.com/eyecatchup/SEOstats/zipball/master
How To Use
Example Code
<?php include '../src/class.seostats.php';
try
{
$url = new SEOstats($_GET['url']);
$url->print_array('Google','json');
}
catch (SEOstatsException $e)
{
die($e->getMessage());
}
?>
More example files are included within the download archive!
NOTE: The Pagerank Checksum API URL was going to be changed anyway with the next release. As the old URL stopped working (for any reason i don't have the time to determine now), you can use the new URL, that will be implemented with the next version's release as standard anyway. Therefore you have to change the line:
const PAGERANK_CHECKSUM_API_URI = 'http://217.150.244.124/prch/?url=';
to
const PAGERANK_CHECKSUM_API_URI = 'http://pagerank.bexton.net/?url=';
in the second line of the main class (file:class.seostats.php
)
Public Methods (Feature List)
Google Methods
Method @returnGoogle()
Returns an array, containing all results of all Google methods.
Google_Page_Rank()
Returns the Google PageRank.
Google_Siteindex_Total()
Returns the total amount of results for a Google 'site:'-search on the object URL.
Google_Siteindex_Total_API()
new Same like Google_Siteindex_Total, but requesting data from the Websearch API.
Google_Siteindex_Array()
Returns an array, containing the keys 'URL', 'Title' and 'Description' (foreach 'site:'-search result).
Google_Backlinks_Total()
Returns the total amount of results for a Google 'link:'-search on the object URL.
Google_Backlinks_Total_API()
new Same like Google_Backlinks_Total, but requesting data from the Websearch API.
Google_Backlinks_Array()
Returns an array, containing the keys 'URL', 'Title' and 'Description' (foreach 'link:'-search result).
Google_Mentions_Total()
Returns the total amount of results for an exact match Google search on the object URL.
Google_Mentions_Array()
Returns an array, containing the keys 'URL', 'Title' and 'Description' (foreach exact match result).
Google_Performance_Analysis()
Returns an array, containing a bunch of technical details about the object URL.
Google_Pagespeed_Score()
Returns an integer (between 0 - 100).
Yahoo Methods
Method @returnYahoo()
Returns an array, containing all results of all Yahoo methods.
Yahoo_Siteindex_Total()
Returns the total amount of results for a Yahoo 'site:'-search on the object URL.
Yahoo_Siteindex_Array()
Returns an array, containing the keys 'URL', 'Title' and 'Description' (foreach 'site:'-search result).
Yahoo_Backlinks_Total()
Returns the total amount of results for a Yahoo 'link:'-search on the object URL.
Yahoo_Backlinks_Array()
Returns an array, containing the keys 'URL', 'Title' and 'Description' (foreach 'link:'-search result).
Majesticseo Methods
Method @returnMajesticseo()
Returns an array, containing all results of all Majesticseo methods.
Majesticseo_Siteindex_Total()
Returns the total amount of indexed pages, listed at Majesticseo.
Majesticseo_Backlinks_Total()
Returns the total amount of backlinks, listed at Majesticseo.
Majesticseo_Backlinking_Domains_Total()
Returns the total amount of backlinking domains, listed at Majesticseo.
Majesticseo_Backlinking_IPs_Total()
Returns the total amount of backlinking IP's, listed at Majesticseo.
Majesticseo_Backlinking_CSubnets_Total()
Returns the total amount of backlinking Class C subnets, listed at Majesticseo.
Seomoz Methods
Method @returnSeomoz()
Returns an array, containing all results of all Seomoz methods.
Seomoz_Domainauthority_Array()
Returns an array, containing the keys 'URL Authority', 'URL mozRank', 'Domain Authority' and 'Domain mozRank'.
Seomoz_Linkdetails_Array()
Returns an array, containing backlink details by Seomoz.
Alexa Methods
Method @returnAlexa()
Returns an array, containing all results of all Alexa methods.
Alexa_Global_Rank_Array()
Returns an array, containing the Alexa Global Rank stats (7d, 1m, 3m).
Alexa_Country_Rank()
Returns an integer - The (best) local Alexa rank.
Alexa_Rank_By_County()
Returns an array, containing local Alexa ranks for multiple countries.
Alexa_Visits_By_County()
Returns an array, containing local visits stats, sorted by country.
Alexa_Pageviews()
Returns an array, containing pageview stats (7d, 1m, 3m).
Alexa_Pageviews_Per_User()
Returns an array, containing pageviews per user stats (7d, 1m, 3m).
Alexa_Reach()
Returns an array, containing reach stats (7d, 1m, 3m).
Alexa_Bounce_Rate()
Returns an array, containing bounce rate stats (7d, 1m, 3m).
Alexa_Time_On_Site()
Returns an array, containing time on site stats (7d, 1m, 3m).
Alexa_Search_Visits()
Returns an array, containing search visit stats (7d, 1m, 3m).
Alexa_Search_Visits_Keywords()
Returns an array, containing the keywords, refered to the object URL.
Alexa_Search_Visits_Changes()
Returns an array, containing changes in the keywords, refered to the object URL.
Alexa_Avg_Load_Time()
Returns a string - the average load time of the object URL.
Alexa_Graph($type='1',$width='660',$height='330',$period='1')
Returns a string, containing the HTML code of an image, showing Alexa Statistics as Graph.@param integer $type Specifies the graph type. Valid values are 1 to 6. (see below)
1 = Daily traffic rank trend
2 = Daily pageviews (percent)
3 = Daily pageviews per user
4 = Time on site (minutes)
5 = Bounce rate (percent)
6 = Search visits (percent)
@param integer $width Specifies the graph width (in px).
@param integer $height Specifies the graph height (in px).
@param integer $period Specifies the displayed time period. Valid values are 1 to 12.
Facebook Methods
Method @returnFacebook()
Returns an array, containing all results of all Facebook methods.
Facebook_Mentions_Total()
Returns an array, containing the total amount of mentions ofthe object URL at Facebook.
Facebook_Mentions_Array()
Returns an array, containing the keys 'URL', 'Title' and 'Description' (foreach Facebook mention).
Twitter Methods
Method @returnTwitter()
Returns an array, containing all results of all Twitter methods.
Twitter_Mentions_Total()
Returns an array, containing the total amount of mentions of the object URL at Twitter.
Twitter_Mentions_Array()
Returns an array, containing the keys 'URL', 'Title' and 'Description' (foreach Twitter mention).
Other Methods
Method @returnAll_Totals()
Returns an array, containing all results of all methods, but without Linkdetail-Arrays.
Everything()
Returns an array, containing all results of all methods.
print_array($method,$format)
Prints an array within <pre>
tags.@param $method Name of a SEOstats method.
@param $format This optional parameter can be set to 'json' to receive a json encoded array.
Optional Configurations
You can adjust some relevant (as i think;)) constants in the http://code.google.com/p/seostats/#class.seostats.config.php'>class.seostats.config.php file. Note: All changes are optional!
SEOstats PHP Class
class.seostats.php
<?php
/**
* PHP Class SEOstats
*
* PHP class to request a bunch of SEO data, such as Backlinkdetails,
* Traffic Statistics, Pageauthority and much more.
*
* ---
* @package class.seostats.2.0.7
* @updated 2011/06/11
* @author Stephan Schmitz <eyecatchup@gmail.com>
* @copyright 2010-present, Stephan Schmitz
* @license GNU General Public License (GPL)
* @link http://www.gnu.org/copyleft/gpl.html
* @link http://code.google.com/p/seostats/
*
* ---
* Copyright (c) 2010-present, Stephan Schmitz
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Neither the name of the Author nor the name of the Product
* may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
include_once('class.seostats.config.php');
include_once('modules.php');
class SEOstats
{
const BUILD_NO = '2.0.7';
const PAGERANK_CHECKSUM_API_URI = 'http://217.150.244.124/prch/?url=';
/**
* Object URL
*
* @access public
* @var string
*/
public $url;
/**
* Constructor
*
* Checks for valid URL syntax and server response.
*
* @access public
* @param string $url String, containing the initialized
* object URL.
*/
public function __construct($url)
{
$this->url = $url;
$url_validation = $this->valid_url($this->url);
if($url_validation == 'valid')
{
$valid_response_codes = array('200','301','302');
$curl_result = $this->get_status_code($this->url);
if(in_array($curl_result,$valid_response_codes))
{
$this->host = parse_url($this->url, PHP_URL_HOST);
$this->protocol = parse_url($this->url, PHP_URL_SCHEME);
}
elseif($curl_result == '0')
{
$e = 'Invalid URL > '.$this->url.' returned no response for a
HTTP HEAD request, at all. It seems like the Domain does
not exist.';
throw new SEOstatsException($e);
}
else
{
throw new SEOstatsException('Invalid Request > '.$this->url.
' returned a '.$curl_result.' status code.');
}
}
else
{
throw new SEOstatsException($url_validation);
}
}
/**
* HTTP GET request with curl.
*
* @access private
* @param string $url String, containing the URL to
* curl.
* @return string Returns string, containing the
* curl result.
*/
public static function cURL($url)
{
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_USERAGENT,
'SEOstats '. SEOstats::BUILD_NO .' code.google.com/p/seostats/');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_MAXREDIRS,2);
if(strtolower(parse_url($url, PHP_URL_SCHEME)) == 'https')
{
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,1);
}
$str = curl_exec($ch);
curl_close($ch);
return $str;
}
/**
* HTTP HEAD request with curl.
*
* @access private
* @param string $url String, containing the
* initialized object URL.
* @return intval Returns a HTTP status code.
*/
private function get_status_code($url)
{
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_USERAGENT,
'SEOstats '. SEOstats::BUILD_NO .' code.google.com/p/seostats/');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_NOBODY,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
$str = curl_exec($ch);
$int = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
return intval($int);
}
/**
* Validates the initialized object URL syntax.
*
* @access private
* @param string $url String, containing the initialized object URL.
* @return string Returns string, containing the validation result.
*/
private function valid_url($url)
{
$allowed_schemes = array('http','https');
$host = parse_url($url, PHP_URL_HOST);
$scheme = parse_url($url, PHP_URL_SCHEME);
if(!isset($url) || empty($url) || $url = '')
{
$e = 'Invalid Object > Requires an URL.';
}
else
{
if(!in_array(strtolower($scheme),$allowed_schemes))
{
$e = 'Invalid URL > SEOstats supports soley RFC compliant URL\'s with HTTP(/S) protocol.';
}
elseif(empty($host) || $host == '')
{
$e = 'Invalid URL > Hostname undefined (or invalid URL syntax).';
}
else
{
/**
* Regex pattern found in and copied from the Nutch source
* @url {http://nutch.apache.org/}
*
* Fyi: For the following reason, i decided to stay with preg_match.
*
* Testing 10k URL's, returned an average execution time (in seconds, per URL) of:
* if(!preg_match($pattern,$this->url))
* 0.000104904174805
* if(!filter_var($this->url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED))
* 0.000140905380249
*/
$pattern = '([A-Za-z][A-Za-z0-9+.-]{1,120}:[A-Za-z0-9/](([A-Za-z0-9$_.+!*,;/?:@&~=-])';
$pattern .= '|%[A-Fa-f0-9]{2}){1,333}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*,;/?:@&~=%-]{0,1000}))?)';
if(!preg_match($pattern,$this->url))
{
$e = 'Invalid URL > Invalid URL syntax.';
}
else
{
$e = 'valid';
}
}
}
return $e;
}
/**
* Just a 'quicker' way to print an array of a method's result.
*
* @param string $method String, containing a method name.
* @param string $output Optional Parameter. If set to json, output will be a json encoded array.
* @access public
* @return string Prints an array within <pre> tags.
*/
public function print_array($method,$output='')
{
$array = ($output != 'json') ? $this->$method() : json_encode($this->$method());
print '<pre>';
print_r ($array);
print '</pre>';
}
/**
* @access public
* @return integer Returns the Google PageRank.
*/
public function Google_Page_Rank()
{
return SEOstats_Google::Google_PR($this->host);
}
/**
* @access public
* @return integer Returns the total amount of results for a Google 'site:'-search on the object URL.
*/
public function Google_Siteindex_Total()
{
$q = urlencode('site:'.$this->host);
return SEOstats_Google::googleTotal($q);
}
/**
* @access public
* @return integer Returns the total amount of results for a Google 'site:'-search on the object URL.
*/
public function Google_Siteindex_Total_API()
{
$q = urlencode('site:'.$this->host);
return SEOstats_Google::googleTotal2($q);
}
/**
* Limited to 1000 results, due to Google.
*
* @access public
* @return array Returns array, containing foreach 'site:'-search result the keys 'URL', 'Title' and 'Description'.
*/
public function Google_Siteindex_Array()
{
$q = urlencode('site:'.$this->host);
return SEOstats_Google::googleArray($q);
}
/**
* @access public
* @return integer Returns the total amount of results for a Google 'link:'-search on the object URL.
*/
public function Google_Backlinks_Total()
{
$q = urlencode('link:'.$this->host);
return SEOstats_Google::googleTotal($q);
}
/**
* @access public
* @return integer Returns the total amount of results for a Google 'link:'-search on the object URL.
*/
public function Google_Backlinks_Total_API()
{
$q = urlencode('link:'.$this->host);
return SEOstats_Google::googleTotal2($q);
}
/**
* Limited to 1000 results, due to Google.
*
* @access public
* @return array Returns array, containing foreach 'link:'-search result the keys 'URL', 'Title' and 'Description'.
*/
public function Google_Backlinks_Array()
{
$q = urlencode('link:'.$this->host);
return SEOstats_Google::googleArray($q);
}
/**
* @access public
* @return integer Returns the total amount of results for an exact match Google search on the object URL.
*/
public function Google_Mentions_Total()
{
$q = urlencode('"'.$this->host.'" -site:'.$this->host.'');
return SEOstats_Google::googleTotal($q);
}
/**
* Limited to 1000 results, due to Google.
*
* @access public
* @return array Returns array, containing foreach exact match search result the keys 'URL', 'Title' and 'Description'.
*/
public function Google_Mentions_Array()
{
$q = urlencode('"'.$this->host.'" -site:'.$this->host.'');
return SEOstats_Google::googleArray($q);
}
/**
* Returns Onsite Optimization Tips (for better page performance) by Google.
*
* @access public
* @return array Returns array, containing the page analysis results.
*/
public function Google_Performance_Analysis()
{
return SEOstats_Google::performanceAnalysis($this->host);
}
/**
* Returns the Google Pagespeed Score.
* Score is between 0 (worst) and 100 (best).
*
* @access public
* @returun integer Returns a number between 0 - 100.
*/
public function Google_Pagespeed_Score()
{
return SEOstats_Google::pagespeedScore($this->host);
}
/**
* @access public
* @return integer Returns the total amount of pages for the domain, indexed at Yahoo!.
*/
public function Yahoo_Siteindex_Total()
{
return SEOstats_Yahoo::yahooSiteindexTotal($this->host);
}
/**
* Limited to 100 results.
*
* @access public
* @return integer Returns array, containing the keys 'Title', 'URL' and 'Click URL'.
*/
public function Yahoo_Siteindex_Array()
{
return SEOstats_Yahoo::yahooSiteindexArray($this->host);
}
/**
* @access public
* @return integer Returns the total amount of backlinks to the domain, listed at Yahoo!.
*/
public function Yahoo_Backlinks_Total()
{
return SEOstats_Yahoo::yahooBacklinksTotal($this->host);
}
/**
* Limited to 100 results.
*
* @access public
* @return integer Returns array, containing the keys 'URL' and 'Anchortext'.
*/
public function Yahoo_Backlinks_Array()
{
return SEOstats_Yahoo::yahooBacklinksArray($this->host);
}
/**
* @access public
* @return integer Returns the total amount of indexed pages for the object URL, listed at Majesticseo.
*/
public function Majesticseo_Siteindex_Total()
{
return SEOstats_Majesticseo::report($this->url, 6);
}
/**
* @access public
* @return integer Returns the total amount of backlinks, listed at Majesticseo.
*/
public function Majesticseo_Backlinks_Total()
{
return SEOstats_Majesticseo::report($this->url, 3);
}
/**
* @access public
* @return integer Returns the total amount of backlinking domains, listed at Majesticseo.
*/
public function Majesticseo_Backlinking_Domains_Total()
{
return SEOstats_Majesticseo::report($this->url, 1);
}
/**
* @access public
* @return integer Returns the total amount of backlinking IP's, listed at Majesticseo.
*/
public function Majesticseo_Backlinking_IPs_Total()
{
return SEOstats_Majesticseo::report($this->url, 4);
}
/**
* @access public
* @return integer Returns the total amount of backlinking Class C subnets.
*/
public function Majesticseo_Backlinking_CSubnets_Total()
{
return SEOstats_Majesticseo::report($this->url, 5);
}
/**
* @access public
* @return array Returns array, containing the keys 'URL Authority', 'URL mozRank', 'Domain Authority' and 'Domain mozRank'.
*/
public function Seomoz_Domainauthority_Array()
{
return SEOstats_Seomoz::Seomoz_Authority($this->host);
}
/**
* Limited to 25 links per source domain, due to using a free API key.
*
* @access public
* @link http://apiwiki.seomoz.org/w/page/27002419/Glossary Response Format, Term Conventions
* @return array Returns multi-array, containing backlink details.
*/
public function Seomoz_Linkdetails_Array()
{
return SEOstats_Seomoz::Seomoz_Links($this->host);
}
/**
* @access public
* @return integer Returns the Alexa Global Rank.
*/
public function Alexa_Global_Rank_Array()
{
return SEOstats_Alexa::extractSingle('div','id','rank','0',$this->host,true);
}
/**
* @access public
* @return integer Returns the Alexa Country Rank.
*/
public function Alexa_Country_Rank()
{
return SEOstats_Alexa::extractSingle('div','class','data','1',$this->host,false);
}
/**
* @access public
* @return array Returns multi-array, containing data from Alexa about the total pageviews.
*/
public function Alexa_Pageviews()
{
return SEOstats_Alexa::extractSingle('div','id','pageviews','0',$this->host,true);
}
/**
* @access public
* @return array Returns multi-array, containing data from Alexa about pageviews per user.
*/
public function Alexa_Pageviews_Per_User()
{
return SEOstats_Alexa::extractSingle('div','id','pageviews_per_user','0',$this->host,true);
}
/**
* @access public
* @return array Returns multi-array, containing data from Alexa about the reach.
*/
public function Alexa_Reach()
{
return SEOstats_Alexa::extractSingle('div','id','reach','0',$this->host,true);
}
/**
* @access public
* @return array Returns multi-array, containing data from Alexa about the bounce rate.
*/
public function Alexa_Bounce_Rate()
{
return SEOstats_Alexa::extractSingle('div','id','bounce','0',$this->host,true);
}
/**
* @access public
* @return array Returns multi-array, containing data from Alexa about the avg time, users stay on the site.
*/
public function Alexa_Time_On_Site()
{
return SEOstats_Alexa::extractSingle('div','id','time_on_site','0',$this->host,true);
}
/**
* @access public
* @return array Returns multi-array, containing data from Alexa about visitors from searches.
*/
public function Alexa_Search_Visits()
{
return SEOstats_Alexa::extractSingle('div','id','search','0',$this->host,true);
}
/**
* @access public
* @return array Returns multi-array, containing the Visits by Country.
*/
public function Alexa_Visits_By_Country()
{
return SEOstats_Alexa::Alexa_VBC($this->url);
}
/**
* @access public
* @return array Returns multi-array, containing the Alexa Rank, sorted by Country.
*/
public function Alexa_Rank_By_Country()
{
return SEOstats_Alexa::Alexa_RBC($this->url);
}
/**
* @access public
* @return array Returns multi-array, containing data from Alexa about keywords from search visits.
*/
public function Alexa_Search_Visits_Keywords()
{
return SEOstats_Alexa::Alexa_SV_Keywords($this->url);
}
/**
* @access public
* @return array Returns multi-array, containing data from Alexa about changes of incoming search terms.
*/
public function Alexa_Search_Visits_Changes()
{
return SEOstats_Alexa::Alexa_SV_Changes($this->url);
}
/**
* @access public
* @return string Returns string, containing the average load time of the URL from Alexa.
*/
public function Alexa_Avg_Load_Time()
{
return SEOstats_Alexa::Alexa_Load_Time($this->url);
}
/**
* @access public
* @param integer $type Specifies the graph type. Valid values are 1 to 6.
* @param integer $width Specifies the graph width (in px).
* @param integer $height Specifies the graph height (in px).
* @param integer $period Specifies the displayed time period. Valid values are 1 to 12.
* @return string Returns a string, containing the HTML code of an image, showing Alexa Statistics as Graph.
*/
public function Alexa_Graph($type='1',$width='660',$height='330',$period='1')
{
switch($type)
{
case 1: $gtype = 't'; break;
case 2: $gtype = 'p'; break;
case 3: $gtype = 'u'; break;
case 4: $gtype = 's'; break;
case 5: $gtype = 'b'; break;
case 6: $gtype = 'q'; break;
default:break;
}
$graph = '<img src="http://traffic.alexa.com/graph?&o=f&c=1&y='.$gtype.'&b=ffffff&n=666666';
$graph .= '&w='.$width.'&h='.$height.'&r='.$period.'m&u='.$this->url;
$graph .= '" width="'.$width.'" height="'.$height.'" alt="Alexa Statistics Graph for '.$this->url.'" />';
return $graph;
}
/**
* @access public
* @return integer Returns the total amount of Facebook pages mention the URL.
*/
public function Facebook_Mentions_Total()
{
$q = urlencode('site:facebook.com "'.$this->host.'"');
return SEOstats_Google::googleTotal($q);
}
/**
* Limited to 1000 results.
*
* @access public
* @return array Returns array, containing detailed results about Facebook pages mention the URL.
*/
public function Facebook_Mentions_Array()
{
$q = urlencode('site:facebook.com "'.$this->host.'"');
return SEOstats_Google::googleArray($q);
}
/**
* @access public
* @return integer Returns the total amount of Twitter pages mention the URL.
*/
public function Twitter_Mentions_Total()
{
$q = urlencode('site:twitter.com "'.$this->host.'"');
return SEOstats_Google::googleTotal($q);
}
/**
* Limited to 1000 results.
*
* @access public
* @return array Returns array, containing detailed results about Twitter pages mention the URL.
*/
public function Twitter_Mentions_Array()
{
$q = urlencode('site:twitter.com "'.$this->host.'"');
return SEOstats_Google::googleArray($q);
}
/**
* @access public
* @return array Returns multi-array, containing all Google data.
*/
public function Google()
{
$all = array(
'GOOGLE' => array(
'Google_Page_Rank' => $this->Google_Page_Rank(),
'Google_Siteindex_Total' => $this->Google_Siteindex_Total(),
'Google_Siteindex_Array' => $this->Google_Siteindex_Array(),
'Google_Backlinks_Total' => $this->Google_Backlinks_Total(),
'Google_Backlinks_Array' => $this->Google_Backlinks_Array(),
'Google_Mentions_Total' => $this->Google_Mentions_Total(),
'Google_Mentions_Array' => $this->Google_Mentions_Array()
)
);
return array('OBJECT' => $this->url, 'DATA' => $all);
}
/**
* @access public
* @return array Returns multi-array, containing all Yahoo! data.
*/
public function Yahoo()
{
$all = array(
'YAHOO' => array(
'Yahoo_Siteindex_Total' => $this->Yahoo_Siteindex_Total(),
'Yahoo_Siteindex_Array' => $this->Yahoo_Siteindex_Array(),
'Yahoo_Backlinks_Total' => $this->Yahoo_Backlinks_Total(),
'Yahoo_Backlinks_Array' => $this->Yahoo_Backlinks_Array()
)
);
return array('OBJECT' => $this->url, 'DATA' => $all);
}
/**
* @access public
* @return array Returns multi-array, containing all Majesticseo data.
*/
public function Majesticseo()
{
$all = array(
'MAJESTICSEO' => array(
'Majesticseo_Siteindex_Total' => $this->Majesticseo_Siteindex_Total(),
'Majesticseo_Backlinks_Total' => $this->Majesticseo_Backlinks_Total(),
'Majesticseo_Backlinking_Domains_Total' => $this->Majesticseo_Backlinking_Domains_Total(),
'Majesticseo_Backlinking_IPs_Total' => $this->Majesticseo_Backlinking_IPs_Total(),
'Majesticseo_Backlinking_CSubnets_Total'=> $this->Majesticseo_Backlinking_CSubnets_Total()
)
);
return array('OBJECT' => $this->url, 'DATA' => $all);
}
/**
* @access public
* @return array Returns multi-array, containing all SEOmoz data.
*/
public function Seomoz()
{
$all = array(
'SEOMOZ' => array(
'Seomoz_Domainauthority_Array' => $this->Seomoz_Domainauthority_Array(),
'Seomoz_Linkdetails_Array' => $this->Seomoz_Linkdetails_Array()
)
);
return array('OBJECT' => $this->url, 'DATA' => $all);
}
/**
* @access public
* @return array Returns multi-array, containing all Alexa data.
*/
public function Alexa()
{
$all = array(
'ALEXA' => array(
'Alexa_Global_Rank_Array' => $this->Alexa_Global_Rank_Array(),
'Alexa_Country_Rank' => $this->Alexa_Country_Rank(),
'Alexa_Rank_By_Country' => $this->Alexa_Rank_By_Country(),
'Alexa_Visits_By_Country' => $this->Alexa_Visits_By_Country(),
'Alexa_Pageviews' => $this->Alexa_Pageviews(),
'Alexa_Pageviews_Per_User' => $this->Alexa_Pageviews_Per_User(),
'Alexa_Reach' => $this->Alexa_Reach(),
'Alexa_Bounce_Rate' => $this->Alexa_Bounce_Rate(),
'Alexa_Time_On_Site' => $this->Alexa_Time_On_Site(),
'Alexa_Search_Visits' => $this->Alexa_Search_Visits(),
'Alexa_Search_Visits_Keywords' => $this->Alexa_Search_Visits_Keywords(),
'Alexa_Search_Visits_Changes' => $this->Alexa_Search_Visits_Changes(),
'Alexa_Avg_Load_Time' => $this->Alexa_Avg_Load_Time()
)
);
return array('OBJECT' => $this->url, 'DATA' => $all);
}
/**
* @access public
* @return array Returns multi-array, containing all Facebook data.
*/
public function Facebook()
{
$all = array(
'FACEBOOK' => array(
'Facebook_Mentions_Total' => $this->Facebook_Mentions_Total(),
'Facebook_Mentions_Array' => $this->Facebook_Mentions_Array()
)
);
return array('OBJECT' => $this->url, 'DATA' => $all);
}
/**
* @access public
* @return array Returns multi-array, containing all Twitter data.
*/
public function Twitter()
{
$all = array(
'TWITTER' => array(
'Twitter_Mentions_Total' => $this->Twitter_Mentions_Total(),
'Twitter_Mentions_Array' => $this->Twitter_Mentions_Array()
)
);
return array('OBJECT' => $this->url, 'DATA' => $all);
}
/**
* Method processing might take a few more seconds!
*
* @access public
* @return array Returns multi-array, containing all data but without Linkdetails.
*/
public function All_Totals()
{
$all = array(
'GOOGLE' => array(
'Google_Page_Rank' => $this->Google_Page_Rank(),
'Google_Siteindex_Total' => $this->Google_Siteindex_Total(),
'Google_Backlinks_Total' => $this->Google_Backlinks_Total(),
'Google_Mentions_Total' => $this->Google_Mentions_Total()
),
'YAHOO' => array(
'Yahoo_Siteindex_Total' => $this->Yahoo_Siteindex_Total(),
'Yahoo_Backlinks_Total' => $this->Yahoo_Backlinks_Total()
),
'MAJESTICSEO' => array(
'Majesticseo_Siteindex_Total' => $this->Majesticseo_Siteindex_Total(),
'Majesticseo_Backlinks_Total' => $this->Majesticseo_Backlinks_Total(),
'Majesticseo_Backlinking_Domains_Total' => $this->Majesticseo_Backlinking_Domains_Total(),
'Majesticseo_Backlinking_IPs_Total' => $this->Majesticseo_Backlinking_IPs_Total(),
'Majesticseo_Backlinking_CSubnets_Total'=> $this->Majesticseo_Backlinking_CSubnets_Total()
),
'SEOMOZ' => array(
'Seomoz_Domainauthority_Array' => $this->Seomoz_Domainauthority_Array()
),
'ALEXA' => array(
'Alexa_Global_Rank_Array' => $this->Alexa_Global_Rank_Array(),
'Alexa_Country_Rank' => $this->Alexa_Country_Rank(),
'Alexa_Rank_By_Country' => $this->Alexa_Rank_By_Country(),
'Alexa_Visits_By_Country' => $this->Alexa_Visits_By_Country(),
'Alexa_Pageviews' => $this->Alexa_Pageviews(),
'Alexa_Pageviews_Per_User' => $this->Alexa_Pageviews_Per_User(),
'Alexa_Reach' => $this->Alexa_Reach(),
'Alexa_Bounce_Rate' => $this->Alexa_Bounce_Rate(),
'Alexa_Time_On_Site' => $this->Alexa_Time_On_Site(),
'Alexa_Search_Visits' => $this->Alexa_Search_Visits(),
'Alexa_Search_Visits_Keywords' => $this->Alexa_Search_Visits_Keywords(),
'Alexa_Search_Visits_Changes' => $this->Alexa_Search_Visits_Changes(),
'Alexa_Avg_Load_Time' => $this->Alexa_Avg_Load_Time()
),
'FACEBOOK' => array(
'Facebook_Mentions_Total' => $this->Facebook_Mentions_Total()
),
'TWITTER' => array(
'Twitter_Mentions_Total' => $this->Twitter_Mentions_Total()
)
);
return array('OBJECT' => $this->url, 'DATA' => $all);
}
/**
* Method processing might take a few more seconds!
*
* @access public
* @return array Returns multi-array, containing all data.
*/
public function Everything()
{
$google = $this->Google();
$yahoo = $this->Yahoo();
$majestics = $this->Majesticseo();
$seomoz = $this->Seomoz();
$alexa = $this->Alexa();
$facebook = $this->Facebook();
$twitter = $this->Twitter();
$all = array($google['DATA'],
$yahoo['DATA'],
$majestics['DATA'],
$seomoz['DATA'],
$alexa['DATA'],
$facebook['DATA'],
$twitter['DATA']
);
return array('OBJECT' => $this->url, 'DATA' => $all);
}
}
?>
seostats.google.php
<?php
/**
* PHP class SEOstats
*
* @class SEOstats_Google
* @package class.seostats
* @updated 2011/06/11
* @author Stephan Schmitz <eyecatchup@gmail.com>
* @copyright 2010-present, Stephan Schmitz
* @license GNU General Public License (GPL)
*/
class SEOstats_Google extends SEOstats {
/**
* Returns total amount of results for any Google search,
* requesting the deprecated Websearch API.
*
* @access private
* @param string $query String, containing the search query.
* @param string $tld String, containing the desired Google top level domain.
* @return integer Returns a total count.
*/
public static function googleTotal2($query)
{
$url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=1&q='.$query;
$str = SEOstats::cURL($url);
$data= json_decode($str);
return intval($data->responseData->cursor->estimatedResultCount);
}
/**
* Returns total amount of results for any Google search.
*
* @access private
* @param string $query String, containing the search query.
* @param string $tld String, containing the desired Google top level domain.
* @return integer Returns a total count.
*/
public static function googleTotal($query)
{
$url = 'http://www.google.'. GOOGLE_TLD .'/custom?num=1&q='.$query;
$str = SEOstats::cURL($url);
preg_match_all('#<b>(.*?)</b>#',$str,$matches);
$result = (!empty($matches[1][2])) ? $matches[1][2] : '0';
return $result;
}
/**
* Returns array, containing detailed results for any Google search.
*
* @access private
* @param string $query String, containing the search query.
* @param string $tld String, containing the desired Google top level domain.
* @return array Returns array, containing the keys 'URL', 'Title' and 'Description'.
*/
public static function googleArray($query)
{
$result = array ();
$pages = 1;
$delay = 0;
for($start=0;$start<$pages;$start++)
{
$url = 'http://www.google.'. GOOGLE_TLD .'/custom?q='.$query.'&filter=0'.
'&num=100'.(($start == 0) ? '' : '&start='.$start.'00');
$str = SEOstats::cURL($url);
if (preg_match("#answer=86640#i", $str))
{
$e = 'Please read: http://www.google.com/support/websearch/' .
'bin/answer.py?&answer=86640&hl=en';
throw new SEOstatsException($e);
}
else
{
$html = new DOMDocument();
@$html->loadHtml( $str );
$xpath = new DOMXPath( $html );
$links = $xpath->query( "//div[@class='g']//a" );
$descs = $xpath->query( "//td[@class='j']//div[@class='std']" );
$i = 0;
foreach ( $links as $link )
{
if(!preg_match('#cache#si',$link->textContent) &&
!preg_match('#similar#si',$link->textContent))
{
$result []= array(
'url' => $link->getAttribute('href'),
'title' => utf8_decode($link->textContent),
'descr' => utf8_decode($descs->item($i)->textContent)
);
$i++;
}
}
if ( preg_match('#<div id="nn"><\/div>#i', $str) ||
preg_match('#<div id=nn><\/div>#i', $str))
{
$pages += 1;
$delay += 200000;
usleep($delay);
}
else
{
$pages -= 1;
}
}
}
return $result;
}
public static function performanceAnalysis($uri)
{
$url = 'http://pagespeed.googlelabs.com/run_pagespeed?url='.$uri.'&format=json';
$str = SEOstats::cURL($url);
return json_decode($str);
}
public static function pageSpeedScore($uri)
{
$url = 'http://pagespeed.googlelabs.com/run_pagespeed?url='.$uri.'&format=json';
$str = SEOstats::cURL($url);
$data = json_decode($str);
return intval($data->results->score);
}
/**
* Gets the 'GPR_awesomeHash' of the object URL.
*
* @access private
* @param string $url String, containing the URL to hash.
* @return string Returns hash.
*/
public static function genhash ($url)
{
$hash = 'Mining PageRank is AGAINST GOOGLE\'S TERMS OF SERVICE. Yes, I\'m talking to you, scammer.';
$c = 16909125;
$length = strlen($url);
$hashpieces = str_split($hash);
$urlpieces = str_split($url);
for ($d = 0; $d < $length; $d++)
{
$c = $c ^ (ord($hashpieces[$d]) ^ ord($urlpieces[$d]));
$c = self::zerofill($c, 23) | $c << 9;
}
return '8' . self::hexencode($c);
}
/**
* @return integer
*/
public static function zerofill($a,$b)
{
$z = hexdec(80000000);
if ($z & $a)
{
$a = ($a>>1);
$a &= (~$z);
$a |= 0x40000000;
$a = ($a>>($b-1));
}
else
{
$a = ($a>>$b);
}
return $a;
}
/**
* @return string
*/
public static function hexencode($str)
{
$out = self::hex8(self::zerofill($str, 24));
$out .= self::hex8(self::zerofill($str, 16) & 255);
$out .= self::hex8(self::zerofill($str, 8 ) & 255);
$out .= self::hex8($str & 255);
return $out;
}
/**
* @return integer
*/
public static function hex8 ($str)
{
$str = dechex($str);
(strlen($str) == 1 ? $str = '0' . $str: null);
return $str;
}
/**
* Gets the Google Pagerank
*
* @access private
* @return integer Returns the Google PageRank.
*/
public static function Google_PR($host)
{
$domain = 'http://'.$host;
if(USE_PAGERANK_CHECKSUM_API == true)
{
$str = SEOstats::cURL( SEOstats::PAGERANK_CHECKSUM_API_URI . $domain );
$data = json_decode($str);
$checksum = $data->CH;
}
else
{
$checksum = self::genhash($domain);
}
$googleurl = 'http://toolbarqueries.google.com/search?features=Rank&sourceid=navclient-ff&client=navclient-auto-ff';
$googleurl .= '&googleip=O;66.249.81.104;104&ch='.$checksum.'&q=info:'.urlencode($domain);
$out = SEOstats::cURL($googleurl);
$pagerank = trim(substr($out, 9));
if (!preg_match('/^[0-9]/',$pagerank))
{
$pagerank = 'Failed to generate a valid hash for PR check.';
}
return $pagerank;
}
}
?>
seostats.yahoo.php
<?php
/**
* PHP class SEOstats
*
* @class SEOstats_Yahoo
* @package class.seostats
* @updated 2011/04/29
* @author Stephan Schmitz <eyecatchup@gmail.com>
* @copyright 2010-present, Stephan Schmitz
* @license GNU General Public License (GPL)
*/
class SEOstats_Yahoo extends SEOstats {
/**
* Returns the total amount of pages for a Domain indexed at Yahoo!
*
* @access private
* @link http://developer.yahoo.com/search/siteexplorer/ Get your own application ID here
* @return integer Returns the total amount of pages for a Domain indexed at Yahoo!
*/
public static function yahooSiteindexTotal($uri)
{
$url = 'http://search.yahooapis.com/SiteExplorerService/V1/pageData?appid=';
$url .= YAHOO_APP_ID;
$url .= '&results=1&output=json&query=http://'.urlencode($uri);
$str = SEOstats::cURL($url);
$data = json_decode($str);
return $data->ResultSet->totalResultsAvailable;
}
/**
* Returns array, containing details about the pages indexed at Yahoo!
*
* @access private
* @link http://developer.yahoo.com/search/siteexplorer/ Get your own application ID here
* @return array Returns array, containing details about the pages indexed at Yahoo!
*/
public static function yahooSiteindexArray($uri)
{
$url = 'http://search.yahooapis.com/SiteExplorerService/V1/pageData?appid=';
$url .= YAHOO_APP_ID;
$url .= '&results=100&output=json&query=http://'.urlencode($uri);
$str = SEOstats::cURL($url);
$data = json_decode($str);
$result = array();
for($i=0;$i<sizeof($data->ResultSet->Result);$i++)
{
$result[] = array( 'Title' => utf8_decode($data->ResultSet->Result[$i]->Title),
'URL' => $data->ResultSet->Result[$i]->Url,
'Click URL' => $data->ResultSet->Result[$i]->ClickUrl);
}
return $result;
}
/**
* Returns the total amount of Backlinks indexed at Yahoo!
*
* @access private
* @link http://developer.yahoo.com/search/siteexplorer/ Get your own application ID here
* @return integer Returns the total amount of backlinks indexed at Yahoo!
*/
public static function yahooBacklinksTotal($uri)
{
$url = 'http://search.yahooapis.com/SiteExplorerService/V1/inlinkData?appid=';
$url .= YAHOO_APP_ID;
$url .= '&results=1&output=json&query=http://'.urlencode($uri);
$str = SEOstats::cURL($url);
$data = json_decode($str);
return $data->ResultSet->totalResultsAvailable;
}
/**
* Returns an array containing details about the backlinks indexed at Yahoo!
*
* @access private
* @link http://developer.yahoo.com/search/siteexplorer/ Get your own application ID here
* @return array Returns an array containing details about the backlinks indexed at Yahoo!
*/
public static function yahooBacklinksArray($uri)
{
$url = 'http://search.yahooapis.com/SiteExplorerService/V1/inlinkData?appid=';
$url .= YAHOO_APP_ID;
$url .= '&results=100&output=json&query=http://'.urlencode($uri);
$str = SEOstats::cURL($url);
$data = json_decode($str);
$result = array();
for($i=0;$i<sizeof($data->ResultSet->Result);$i++)
{
$result[] = array('URL' => $data->ResultSet->Result[$i]->Url,
'Anchortext' => utf8_decode($data->ResultSet->Result[$i]->Title));
}
return $result;
}
}
?>
seostats.majesticseo.php
<?php
/**
* PHP class SEOstats
*
* @class SEOstats_Majesticseo
* @package class.seostats
* @updated 2011/06/11
* @author Stephan Schmitz <eyecatchup@gmail.com>
* @copyright 2010-present, Stephan Schmitz
* @license GNU General Public License (GPL)
*/
class SEOstats_Majesticseo extends SEOstats {
/**
* Helper. Gets the Majesticseo's free report webpage.
*
* @access private
* @return string String, containing the curl result of the the Majesticseo webpage.
*/
public static function report($uri, $i)
{
$tmp = SEOstats::cURL( 'http://www.majesticseo.com/reports/site-explorer/summary/'.
str_replace('http://', '', $uri) );
$dom = new DOMDocument();
@$dom->loadHTML($tmp);
$xpath = new DOMXPath($dom);
$p = $xpath->query("//table//tr//td//p");
if($i==1 || $i==3)
{
$r = trim($p->item($i)->textContent);
}
else
{
switch($i)
{
case 4: $regex = ' Referring IP addresses'; break;
case 5: $regex = ' are Class C subnets'; break;
case 6: $regex = ' Indexed URLs'; break;
default:break;
}
foreach ( $p as $paragraph )
{
if(preg_match('#'.$regex.'#i',$paragraph->textContent))
{
$r = str_replace($regex,'',$paragraph->textContent);
}
}
}
return ($r != '') ? $r : intval('0');
}
}
?>
seostats.seomoz.php
<?php
/**
* PHP class SEOstats
*
* @class SEOstats_Seomoz
* @package class.seostats
* @updated 2011/06/11
* @author Stephan Schmitz <eyecatchup@gmail.com>
* @copyright 2010-present, Stephan Schmitz
* @license GNU General Public License (GPL)
*/
class SEOstats_Seomoz extends SEOstats {
/**
* Gets domain and URL authority from SEOmoz.
*
* @access private
* @link http://www.seomoz.org/api The SEOmoz API
* @return array Returns array, containing authority data.
*/
public static function Seomoz_Authority($uri)
{
// external helper class
include_once ('ext/SeoMoz/Authenticator.php');
$authenticator = new Authenticator();
$url = urlencode($uri);
$tmp = SEOstats::cURL('http://lsapi.seomoz.com/linkscape/url-metrics/'.$url.'?'.$authenticator->getAuthenticationStr());
$data = json_decode($tmp);
$result = array('URL Authority' => $data->upa,
'URL mozRank' => $data->umrp,
'Domain Authority' => $data->pda,
'Domain mozRank' => $data->fmrp
);
return $result;
}
/**
* Gets Backlinkdetails from SEOmoz.
* Limited to 25 links per source domain, due to using a free API key.
*
* @access private
* @link http://www.seomoz.org/api The SEOmoz API
* @return array Returns array, containing linkdetails.
*/
public static function Seomoz_Links($uri)
{
// external helper classes
include_once('ext/SeoMoz/Authenticator.php');
include_once('ext/SeoMoz/LinksService.php');
include_once('ext/SeoMoz/LinksConstants.php');
$authenticator = new Authenticator();
$linksService = new LinksService($authenticator);
$result = $linksService->getLinks($uri, LINKS_SCOPE_PAGE_TO_PAGE, null, LINKS_SORT_DOMAIN_AUTHORITY, LINKS_COL_URL, 0 , 25);
return (!empty($result)) ? $result : 'No data available.';
}
}
?>
seostats.alexa.php
<?php
/**
* PHP class SEOstats
*
* @class SEOstats_Alexa
* @package class.seostats
* @updated 2011/06/11
* @author Stephan Schmitz <eyecatchup@gmail.com>
* @copyright 2010-present, Stephan Schmitz
* @license GNU General Public License (GPL)
*/
class SEOstats_Alexa extends SEOstats {
/**
* Helper. Get the Alexa's free report webpage.
*
* @access private
* @return string String, containing the curl result of the the Alexa webpage.
*/
private static function _alexa($uri)
{
$tmp = SEOstats::cURL('http://www.alexa.com/siteinfo/'.$uri);
return $tmp;
}
/**
* Extracts a String off of HTML input.
*
* @access private
*
* @param string $tag String, containing the html tag to select
* @param string $attr String, containing the attribute used on the WHERE condition
* @param string $value String, containing the value used on the WHERE condition
* @param string $site Input string
* @param integer $id Defines the position of the key, to be returned from the preg_match_all array.
*
* @return string/integer Returns an integer or a string.
*/
public static function extractSingle($tag,$attr,$value,$id,$uri,$alextract)
{
// external helper class
include_once("ext/htmlsql.class.php");
$wsql = new htmlsql();
$wsql->connect('string', SEOstats_Alexa::_alexa($uri));
$wsql->query('SELECT * FROM '.$tag.' WHERE $'.$attr.' == "'.$value.'"');
$row = $wsql->fetch_array();
if($alextract == true)
{
return SEOstats_Alexa::alextract($row[$id]['text']);
}
elseif($alextract == false)
{
return trim(strip_tags($row[$id]['text']));
}
elseif($alextract == 'none')
{
return $row[$id]['text'];
}
}
/**
* Extracts an Array off of HTML input.
*
* @access private
*
* @param string $tag String, containing the html tag to select
* @param string $attr String, containing the attribute used on the WHERE condition
* @param string $value String, containing the value used on the WHERE condition
* @param string $site Input string
*
* @return array Returns an array of results.
*/
public static function extractMulti($tag,$attr,$value,$uri)
{
// external helper classs
include_once("ext/htmlsql.class.php");
$wsql = new htmlsql();
$wsql->connect('string', SEOstats_Alexa::_alexa($uri));
$wsql->query('SELECT * FROM '.$tag.' WHERE $'.$attr.' == "'.$value.'"');
$results = array ();
foreach($wsql->fetch_array() as $row)
{
$results[] = $row['text'];
}
return $results;
}
/**
* Gets data off of curled Alexa webpages.
*
* @access private
* @param string $str String, containing the html source code of Alexa's free result webpage.
* @return array Returns an array of Alexa results.
*/
public static function alextract($str)
{
$tmpArr = explode('</td>',$str);
$replace = array("\r", "\r\n", "\n", "7 day", "Yesterday", "1 month", "3 month");
$value1 = trim(str_replace($replace,'',strip_tags($tmpArr[3])));
if ($value1 == '-' || $value1 == '' || empty($value1))
{
$value1 = 'No Data available.';
$change1 = '';
}
else
{
$change1 = trim(strip_tags($tmpArr[4]));
}
$value3 = trim(str_replace($replace,'',strip_tags($tmpArr[6])));
if ($value3 == '-' || $value3 == '' || empty($value3))
{
$value3 = 'No Data available.';
$change3 = '';
}
else
{
$change3 = trim(strip_tags($tmpArr[7]));
}
$month1 = array('value' => $value1, 'change' => $change1);
$month3 = array('value' => $value3, 'change' => $change3);
$result = array('1 Month' => $month1,'3 Months' => $month3);
return $result;
}
/**
* @access public
* @return array Returns multi-array, containing the Visits by Country.
*/
public static function Alexa_VBC($uri)
{
$str = SEOstats_Alexa::_alexa($uri);
preg_match_all('#<img class="dynamic-icon" src="/images/flags/(.*?).png" alt="(.*?)"/>(.*?)</a>#',$str,$country);
preg_match_all('#<p class="tc1" style="width:30%; text-align:right;">(.*?)</p>#',$str,$percent);
$result = array();
$countries = array();
foreach($country[3] as $tmp)
{
$x = trim(str_replace(' ','',$tmp));
if(!in_array($x,$countries))
{
$countries[] = $x;
}
}
for($i=0;$i < sizeof($countries);$i++)
{
$result[] = array('Country' => trim($countries[$i]), 'Percent of Traffic' => $percent[1][$i]);
}
return $result;
}
/**
* @access public
* @return array Returns multi-array, containing the Alexa Rank, sorted by Country.
*/
public static function Alexa_RBC($uri)
{
$str = SEOstats_Alexa::_alexa($uri);
preg_match_all('# (.*?)</a>#',$str,$country);
preg_match_all('#<p class="tc1" style="width:40%; text-align:right;">(.*?)</p>#',$str,$rank);
$result = array();
for($i=0;$i < sizeof($country);$i++)
{
$result[] = array('Country' => trim($country[1][$i]), 'Rank' => trim($rank[1][$i]));
}
return $result;
}
/**
* @access public
* @return array Returns multi-array, containing data from Alexa about keywords from search visits.
*/
public static function Alexa_SV_Keywords($uri)
{
$tmp = SEOstats_Alexa::extractSingle('div','id','top-keywords-from-search','0',$uri,'none');
$tmp = explode('style="color:#253759;">', $tmp);
$tmp = explode('<tr>', $tmp[2]);
$result = array();
for ($i=1;$i<sizeof($tmp);$i++)
{
$temp = explode('</td>',$tmp[$i]);
$result[] = array(
'Keyword' => utf8_decode(trim(strip_tags($temp[1]))),
'Percent of Search Traffic' => trim(strip_tags($temp[2])));
}
return $result;
}
/**
* @access public
* @return array Returns multi-array, containing data from Alexa about changes of incoming search terms.
*/
public static function Alexa_SV_Changes($uri)
{
$tmp = SEOstats_Alexa::extractMulti('table','class','dataTable',$uri);
$tmp_incr = explode('<tr>', $tmp[9]);
$tmp_decl = explode('<tr>', $tmp[11]);
for ($i=1;$i<sizeof($tmp_incr);$i++)
{
$temp_incr = explode('</td>',$tmp_incr[$i]);
$result_incr[] = array(
'Keyword' => utf8_decode(trim(strip_tags($temp_incr[1]))),
'Change in Percent' => trim(strip_tags($temp_incr[2])));
}
for ($i=1;$i<sizeof($tmp_decl);$i++)
{
$temp_decl = explode('</td>',$tmp_decl[$i]);
$result_decl[] = array(
'Keyword' => utf8_decode(trim(strip_tags($temp_decl[1]))),
'Change in Percent' => trim(strip_tags($temp_decl[2])));
}
if(empty($result_incr)) { $result_incr = 'No Data available.'; }
if(empty($result_decl)) { $result_decl = 'No Data available.'; }
$result = array('Increase' => $result_incr, 'Decline' => $result_decl);
return $result;
}
/**
* @access public
* @return string Returns string, containing the average load time of the URL from Alexa.
*/
public static function Alexa_Load_Time($uri)
{
$str = SEOstats_Alexa::_alexa($uri);
$html = new DOMDocument();
@$html->loadHtml( $str );
$xpath = new DOMXPath( $html );
$p = $xpath->query( "//div[@class='speedAd']//div//p" );
foreach($p as $match)
{
if(preg_match('/Seconds/si',$match->textContent))
{
return trim(strip_tags($match->textContent));
exit();
}
}
return 'No data available.';
}
}
?>
seostats.exception.php
<?php
/**
* PHP class SEOstats
*
* @package class.seostats
* @updated 2011/04/29
* @author Stephan Schmitz <eyecatchup@gmail.com>
* @copyright 2010-present, Stephan Schmitz
* @license GNU General Public License (GPL)
*
* EXCEPTION
*/
class SEOstatsException extends Exception {}
if (!function_exists('curl_init'))
{
throw new SEOstatsException('SEOstats needs the PHP CURL extension.');
}
if (!function_exists('json_decode'))
{
throw new SEOstatsException('SEOstats needs the PHP JSON extension.');
}
?>
class.seostats.config.php
<?php
/**
* PHP class SEOstats
*
* @package class.seostats
* @updated 2011/04/29
* @author Stephan Schmitz <eyecatchup@gmail.com>
* @copyright 2010-present, Stephan Schmitz
* @license GNU General Public License (GPL)
*
* GLOBALS
*/
define('GOOGLE_TLD',
'com');
define('USE_PAGERANK_CHECKSUM_API',
false);
/**
* Optional changes.
*/
define('YAHOO_APP_ID',
'oVFwwjnV34GEEZTLB3K_WW1YC9_VysYbCYQ4szoXTAHZscrDvMazUpFR7TR0wchmlA--');
define('SEOMOZ_ACCESS_ID',
'member-881a55bcfb');
define('SEOMOZ_SECRET_KEY',
'7145d56a1279285be92e6e4875bba8ee');
?>
modules.php
<?php
/**
* PHP class SEOstats
*
* @package class.seostats
* @updated 2011/04/29
* @author Stephan Schmitz <eyecatchup@gmail.com>
* @copyright 2010-present, Stephan Schmitz
* @license GNU General Public License (GPL)
*
* SEOstats modules
*/
include_once('seostats.google.php');
include_once('seostats.yahoo.php');
include_once('seostats.majesticseo.php');
include_once('seostats.seomoz.php');
include_once('seostats.alexa.php');
include_once('seostats.exception.php');
?>
Changelog
/*
======================================================================
CHANGELOG
----------------------------------------------------------------------
v2.0.7 11.06.2011 * added method Google_Siteindex_Total_API
* added method Google_Backlinks_Total_API
* fixed Majesticseo methods
* fixed method Seomoz_Linkdetails_Array
* fixed method Alexa_Avg_Load_Time
* improved method googleArray by changing
from regular expressions to xpath
v2.0.6 18.05.2011 * added method Google_Performance_Analysis
* added method Google_Pagespeed_Score
* fixed method googleArray
* fixed typo in method print_array
v2.0.5 29.04.2011 * fixed method googleArray
* improved regex pattern for URL validation
v2.0.4 13.04.2011 * fixed method Google_Backlinks_Array
* improved method googleArray
* no more need of external helper classes
* added a delay when scraping more than 100 results at once
* removed the Google Pagerank API
* added a Pagerank Checksum API
v2.0.3 13.03.2011 * fixed all Majesticseo methods
* added method Majesticseo_Backlinking_CSubnets_Total
v2.0.2 18.02.2011 * added method Alexa_Visits_By_Country
v2.0.1 18.02.2011 * added method Alexa_Rank_By_Country
* added method Alexa_Avg_Load_Time
v2.0 17.02.2011 * Major code clean up
* improved existing methods
* added new Yahoo methods
* added new SEOmoz methods
* added new Facebook methods
* added new Twitter methods
* added optional Pagerank API
* added optional json output method
* removed GUI example
v1.2.3 18.12.2010 * fixed method PageRank
v1.2.2 17.12.2010 * improved method AlexaGlobalRank
* pure numeric result
* no more html in output
* improved method AlexaCountryRank
* pure numeric result
* no more html in output
* improved Alexa Stats and Trend methods
* no more html wrapped output
* returns results as array
v1.2.1 09.12.2010 * fixed method GoogleLinks
v1.2 01.12.2010 * added new Google methods
* GoogleIndexDetails
* GoogleLinkDetails
* GoogleMentions
* Introduced global var $google_tld
* used in all google methods
* if not defined = com
* enhanced method GoogleIndex
* No longer requires an API Key
* enhanced method GoogleLinks
* No longer requires an API Key
v1.1 29.10.2010 * added Yahoo methods
* YahooLinks
* YahooLinkDetails
v1.0.3 19.10.2010 * fixed method AlexaCountryRank
v1.0.2 19.10.2010 * added method PageRank
v1.0.1 19.10.2010 * added method cURL
----------------------------------------------------------------------
======================================================================
*/
Roadmap
v2.1 June 2011
- New methods to gather detailed user demographics.
- New methods to gather data from several bookmarking Services
- More detailed methods for social media data
Google Pagerank API Info
Due to heavy misuse (coming from the Harvard University Network), i needed to shut down the Google Pagerank API.
The soley purpose of the "API" was to give all users the same chance to request the Pagerank for a site - eventhough they can not generate a valid checksum for the PR request on their own machines.
Thus i changed the $use_pagerank_api
parameter of the class to $use_pr_checksum_api
with the release of v2.0.4. So you can use the new "API" to get the checksum, but the actual request to the google servers need to be done by yourself.
Project Information
- License: GNU GPL v2
- 65 stars
- hg-based source control
Labels:
Bing
SEO
Traffic
Keywords
Backlinks
Authority
Alexa
Yahoo
SEOmoz
Majesticseo
Pagerank
Analytics
Statistics
Trends