Skip to content

Commit

Permalink
Version update to 2.1.0: Initial commit of new child class SEOstats_S…
Browse files Browse the repository at this point in the history
…EMRush.
  • Loading branch information
Stephan Schmitz committed May 12, 2012
1 parent 52789f0 commit 34252ee
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 4 deletions.
10 changes: 6 additions & 4 deletions CHANGELOG
@@ -1,10 +1,12 @@
======================================================================
CHANGELOG
----------------------------------------------------------------------
v2.1.0 12.05.2012 * New child class SEOstats_SEMRush
* New public method SEOstats::SEMRush (ln 456)
v2.0.9 30.01.2011 * New Checksum API for Pagerank requests.
* New built-in method for GPR Awesome Hash.
* Updated Pagespeed Service URL's.
* New license.
* New built-in method for GPR Awesome Hash.
* Updated Pagespeed Service URL's.
* New license.
v2.0.8.2 06.09.2011 * removed child class SEOstats_Majesticseo
v2.0.8 04.08.2011 * implemented contributed child class:
added child class SEOstats_Bing
Expand All @@ -20,7 +22,7 @@
* fixed method Seomoz_Linkdetails_Array
* fixed method Alexa_Avg_Load_Time
* improved method googleArray by changing
from regular expressions to xpath
from regular expressions to xpath
v2.0.6 18.05.2011 * added method Google_Performance_Analysis
* added method Google_Pagespeed_Score
* fixed method googleArray
Expand Down
21 changes: 21 additions & 0 deletions examples/example-8.php
@@ -0,0 +1,21 @@
<?php ini_set('max_execution_time', 180);

include '../src/class.seostats.php';
try
{
$url = new SEOstats($_GET['url']);

$report = $url->SEMRush("de");

print "<pre>";
print_r($report);
print "</pre>";
}
catch (SEOstatsException $e)
{
/**
* Error handling (print it, log it, leave it.. whatever you want.)
*/
die($e->getMessage());
}
?>
104 changes: 104 additions & 0 deletions src/seostats.semrush.php
@@ -0,0 +1,104 @@
<?php
/**
* PHP class SEOstats
*
* @class SEOstats_SEMRush
* @package class.seostats
* @link https://github.com/eyecatchup/SEOstats/
* @updated 2012/05/12
* @author Stephan Schmitz <eyecatchup@gmail.com>
* @copyright 2010-present, Stephan Schmitz
* @license GNU General Public License (GPL)
*
* @filename ./seostats.semrush.php
* @desc Child class of SEOstats, extending the main class
* by methods for http://www.semrush.com
*
* @changelog
* date author method: change(s)
* 2012/05/12 Stephan Schmitz initial commit
*/

class SEOstats_SEMRush extends SEOstats {

/**
* Returns the SEMRush main report data.
* (Only main report is public available.)
*
* @access public
* @param host string Domain name only, eg. "ebay.com" (/wo quotes).
* @param db string Optional: The database to use. Valid values are:
* au, br, ca, de, es, fr, it, ru, uk, us, us.bing (us is default)
* @return array Returns an array containing the main report data.
* @link http://www.semrush.com/api.html
*/
public static function semrushMainReport($host, $db="us")
{
$domain_name = $host;
$dbs = array(
"au", # Google.com.au (Australia)
"br", # Google.com.br (Brazil)
"ca", # Google.ca (Canada)
"de", # Google.de (Germany)
"es", # Google.es (Spain)
"fr", # Google.fr (France)
"it", # Google.it (Italy)
"ru", # Google.ru (Russia)
"uk", # Google.co.uk (United Kingdom)
"us", # Google.com (United States)
"us.bing" # Bing.com
);
if(!in_array($db,$dbs)) {
$err_msg = "Invalid database. Choose one of: " . substr( implode(", ", $dbs), 0, -2);
throw new SEOstatsException($err_msg);
exit(0);
}
else {
// API request url
$api_uri = "http://$db.api.semrush.com/" .
"?action=report" .
"&type=domain_rank" .
"&key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" .
"&export=api" .
"&export_columns=Dn,Rk,Or,Ot,Oc,Ad,At,Ac" .
"&domain=" . $domain_name;
// Send the request
$str = SEOstats::cURL($api_uri);

// We want the 2nd line of the result string.
// RegExp matches line breaks on Windows, Mac and Linux.
$tmp = @preg_split('/$\R?^/m', $str);

if(!array($tmp) || sizeof($tmp) == 0) {
return "No data available for $domain_name.";
}
else {
$names = explode(";", $tmp[0]);
$values = explode(";", $tmp[1]);
$keys = array("Dn","Rk","Or","Ot","Oc","Ad","At","Ac");
$descrs = array(
"The requested site name.",
"Rating of sites by the number of visitors coming from the first 20 search results.",
"Number of Keywords this site has in the TOP20 organic results.",
"Estimated number of visitors coming from the first 20 search results (per month).",
"Estimated cost of purchasing the same number of visitors through Ads.",
"Number of Keywords this site has in the TOP20 Ads results.",
"Estimated number of visitors coming from Ads (per month).",
"Estimated expenses the site has for advertising in Ads (per month)."
);
$ret = array();
for($i=0;$i<=7;$i++) {
$ret[] = array(
"name" => $names[$i],
"value" => $values[$i],
"semrush_key" => $keys[$i],
"description" => $descrs[$i]
);
}
return $ret;
}
}
}

}
?>

0 comments on commit 34252ee

Please sign in to comment.