From 34252ee54ef7302858c45c06958fe5875d952261 Mon Sep 17 00:00:00 2001 From: Stephan Schmitz Date: Sat, 12 May 2012 19:59:29 +0200 Subject: [PATCH] Version update to 2.1.0: Initial commit of new child class SEOstats_SEMRush. --- CHANGELOG | 10 ++-- examples/example-8.php | 21 ++++++++ src/seostats.semrush.php | 104 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 examples/example-8.php create mode 100644 src/seostats.semrush.php diff --git a/CHANGELOG b/CHANGELOG index c11648c9..81ae7cb1 100644 --- a/CHANGELOG +++ b/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 @@ -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 diff --git a/examples/example-8.php b/examples/example-8.php new file mode 100644 index 00000000..e44c1c2a --- /dev/null +++ b/examples/example-8.php @@ -0,0 +1,21 @@ +SEMRush("de"); + + print "
";
+	print_r($report);
+	print "
"; +} +catch (SEOstatsException $e) +{ + /** + * Error handling (print it, log it, leave it.. whatever you want.) + */ + die($e->getMessage()); +} +?> \ No newline at end of file diff --git a/src/seostats.semrush.php b/src/seostats.semrush.php new file mode 100644 index 00000000..1804a872 --- /dev/null +++ b/src/seostats.semrush.php @@ -0,0 +1,104 @@ + + * @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; + } + } + } + +} +?>