diff --git a/LICENSE b/LICENSE index 387b1a5e..fc7510b0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,8 +1,8 @@ -The MIT License (http://eyecatchup.mit-license.org/) -Copyright © 2012 Stephan Schmitz, https://github.com/eyecatchup - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - +The MIT License (http://eyecatchup.mit-license.org/) +Copyright © 2012 Stephan Schmitz, https://github.com/eyecatchup + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/SEOstats/Common/AutoLoader.php b/SEOstats/Common/AutoLoader.php new file mode 100644 index 00000000..6a278a28 --- /dev/null +++ b/SEOstats/Common/AutoLoader.php @@ -0,0 +1,82 @@ + + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/02/03 + */ +class AutoLoader +{ + /** + * @var string The namespace prefix for this instance. + */ + protected $namespace = ''; + + /** + * @var string The filesystem prefix to use for this instance + */ + protected $path = ''; + + /** + * Build the instance of the autoloader + * + * @param string $namespace The prefixed namespace this instance will load + * @param string $path The filesystem path to the root of the namespace + */ + public function __construct($namespace, $path) + { + $this->namespace = ltrim($namespace, '\\'); + $this->path = rtrim($path, '/\\') . DIRECTORY_SEPARATOR; + } + + /** + * Try to load a class + * + * @param string $class The class name to load + * + * @return boolean If the loading was successful + */ + public function load($class) + { + $class = ltrim($class, '\\'); + + if (strpos($class, $this->namespace) === 0) { + $nsparts = explode('\\', $class); + $class = array_pop($nsparts); + $nsparts[] = ''; + $path = $this->path . implode(DIRECTORY_SEPARATOR, $nsparts); + $path .= str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; + + if (file_exists($path)) { + require $path; + return true; + } + } + return false; + } + + /** + * Register the autoloader to PHP + * + * @return boolean The status of the registration + */ + public function register() + { + return spl_autoload_register(array($this, 'load')); + } + + /** + * Unregister the autoloader to PHP + * + * @return boolean The status of the unregistration + */ + public function unregister() + { + return spl_autoload_unregister(array($this, 'load')); + } +} diff --git a/SEOstats/Common/SEOstatsException.php b/SEOstats/Common/SEOstatsException.php new file mode 100644 index 00000000..161431d2 --- /dev/null +++ b/SEOstats/Common/SEOstatsException.php @@ -0,0 +1,16 @@ + + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/02/03 + */ + +class SEOstatsException extends \Exception +{ +} diff --git a/SEOstats/Config/ApiKeys.php b/SEOstats/Config/ApiKeys.php new file mode 100644 index 00000000..e7bc277a --- /dev/null +++ b/SEOstats/Config/ApiKeys.php @@ -0,0 +1,26 @@ + + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/08/14 + */ + +/** + * Client API keys + * @package SEOstats + */ +interface ApiKeys +{ + // To acquire an API key, visit Google's APIs Console here: + // https://code.google.com/apis/console + // In the Services pane, activate the "PageSpeed Insights API" (not the service!). + // Next, go to the API Access pane. The API key is near the bottom of that pane, + // in the section titled "Simple API Access.". + const GOOGLE_SIMPLE_API_ACCESS_KEY = ''; +} diff --git a/src/interfaces/default-settings.php b/SEOstats/Config/DefaultSettings.php similarity index 67% rename from src/interfaces/default-settings.php rename to SEOstats/Config/DefaultSettings.php index ce7fb13e..b2d6075e 100644 --- a/src/interfaces/default-settings.php +++ b/SEOstats/Config/DefaultSettings.php @@ -1,13 +1,24 @@ - + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/02/03 */ -interface default_settings +/** + * Default client settings + * @package SEOstats + */ +interface DefaultSettings { + const DEFAULT_RETURN_NO_DATA = 'n.a.'; + const GOOGLE_TLD = 'com'; // Note: Google search results, doesn't matter which tld you request, vary depending on @@ -24,13 +35,10 @@ interface default_settings const HTTP_HEADER_ACCEPT_LANGUAGE = 'en-us;q=0.8,en;q=0.3'; // For curl instances: Whether to allow Google to store cookies, or not. - const ALLOW_GOOGLE_COOKIES = '0'; + const ALLOW_GOOGLE_COOKIES = 0; - // Choose the local SEMRush database to use. + // Choose the local SEMRush database to use. const SEMRUSH_DB = 'de'; const EXPORT_DIR = 'data/'; } - -/* End of file default-settings.php */ -/* Location: ./src/interfaces/default-settings.php */ \ No newline at end of file diff --git a/SEOstats/Config/Package.php b/SEOstats/Config/Package.php new file mode 100644 index 00000000..63ff8e7d --- /dev/null +++ b/SEOstats/Config/Package.php @@ -0,0 +1,25 @@ + + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/02/03 + */ + +/** + * SEOstats package info + * @package SEOstats + */ +interface Package +{ + const VERSION_CODE = '2.5.2-dev'; + const LICENSE_TYPE = 'MIT Licence'; + const LICENSE_URL = 'http://eyecatchup.mit-license.org/'; + const AUTHOR_NAME = 'Stephan Schmitz'; + const AUTHOR_MAIL = 'eyecatchup@gmail.com'; +} diff --git a/src/interfaces/services.php b/SEOstats/Config/Services.php similarity index 82% rename from src/interfaces/services.php rename to SEOstats/Config/Services.php index 38898fa2..6a86ca15 100644 --- a/src/interfaces/services.php +++ b/SEOstats/Config/Services.php @@ -1,13 +1,21 @@ - - * @updated 2013/01/29 + * @package SEOstats + * @author Stephan Schmitz + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/08/14 */ -interface services +/** + * SEOstats provider list and service URLs + * @package SEOstats + */ +interface Services { const PROVIDER = '["alexa","google","ose","semrush","seomoz","sistrix","social","yahoo"]'; @@ -26,8 +34,8 @@ interface services // Url to get Google search total counts from const GOOGLE_APISEARCH_URL = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=%s&q=%s'; - // Url to get the Pagespeed analysis from - const GOOGLE_PAGESPEED_URL = 'https://developers.google.com/_apps/pagespeed/run_pagespeed?url=%s&format=json'; + // Url to the Page Speed Insights API + const GOOGLE_PAGESPEED_URL = 'https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=%s&key=%s'; // Url to get the Plus One count from const GOOGLE_PLUSONE_URL = 'https://plusone.google.com/u/0/_/+1/fastbutton?count=true&url=%s'; @@ -63,6 +71,3 @@ interface services // Url to get share count via VKontakte from const VKONTAKTE_INFO_URL = 'http://vk.com/share.php?act=count&index=1&url=%s'; } - -/* End of file services.php */ -/* Location: ./src/interfaces/services.php */ \ No newline at end of file diff --git a/src/helper/seostats.httprequest.php b/SEOstats/Helper/HttpRequest.php similarity index 69% rename from src/helper/seostats.httprequest.php rename to SEOstats/Helper/HttpRequest.php index 4351211c..0f8ba3d4 100644 --- a/src/helper/seostats.httprequest.php +++ b/SEOstats/Helper/HttpRequest.php @@ -1,13 +1,17 @@ - - * @updated 2012/06/15 + * @package SEOstats + * @author Stephan Schmitz + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/05/12 */ -class HttpRequest extends SEOstats +class HttpRequest { /** * HTTP GET/POST request with curl. @@ -20,18 +24,21 @@ class HttpRequest extends SEOstats */ public static function sendRequest($url, $postData = false, $postJson = false) { + $ua = sprintf('SEOstats %s https://github.com/eyecatchup/SEOstats', + \SEOstats\SEOstats::BUILD_NO); + $ch = curl_init($url); curl_setopt_array($ch, array( - CURLOPT_USERAGENT => sprintf('SEOstats %s https://github.com/eyecatchup/SEOstats', SEOstats::BUILD_NO), + CURLOPT_USERAGENT => $ua, CURLOPT_RETURNTRANSFER => 1, CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_MAXREDIRS => 2, - CURLOPT_SSL_VERIFYPEER => 0 + CURLOPT_SSL_VERIFYPEER => 0, )); - if (false != $postData) { - if (false != $postJson) { + if (false !== $postData) { + if (false !== $postJson) { curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json')); $data = json_encode($postData); @@ -46,10 +53,7 @@ public static function sendRequest($url, $postData = false, $postJson = false) $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); - if($httpCode == 200) { - return $response; - } - else { return $httpCode; } + return (200 == (int)$httpCode) ? $response : false; } /** @@ -62,37 +66,43 @@ public static function sendRequest($url, $postData = false, $postJson = false) */ public static function getHttpCode($url) { + $ua = sprintf('SEOstats %s https://github.com/eyecatchup/SEOstats', + \SEOstats\SEOstats::BUILD_NO); + $ch = curl_init($url); curl_setopt_array($ch, array( - CURLOPT_USERAGENT => sprintf('SEOstats %s https://github.com/eyecatchup/SEOstats', SEOstats::BUILD_NO), + CURLOPT_USERAGENT => $ua, CURLOPT_RETURNTRANSFER => 1, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_MAXREDIRS => 2, CURLOPT_SSL_VERIFYPEER => 0, - CURLOPT_NOBODY => 1 + CURLOPT_NOBODY => 1, )); curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); - return (int) $httpCode; + return (int)$httpCode; } public function getFile($url, $file) { + $ua = sprintf('SEOstats %s https://github.com/eyecatchup/SEOstats', + \SEOstats\SEOstats::BUILD_NO); + $fp = fopen("$file", 'w'); $ch = curl_init($url); curl_setopt_array($ch, array( - CURLOPT_USERAGENT => sprintf('SEOstats %s https://github.com/eyecatchup/SEOstats', SEOstats::BUILD_NO), + CURLOPT_USERAGENT => $ua, CURLOPT_RETURNTRANSFER => 1, CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_MAXREDIRS => 2, CURLOPT_SSL_VERIFYPEER => 0, - CURLOPT_FILE => $fp + CURLOPT_FILE => $fp, )); curl_exec($ch); @@ -100,9 +110,6 @@ public function getFile($url, $file) fclose($fp); clearstatcache(); - return (bool) FALSE !== stat($file); + return (bool)(false !== stat($file)); } } - -/* End of file seostats.httprequest.php */ -/* Location: ./src/helper/seostats.httprequest.php */ \ No newline at end of file diff --git a/SEOstats/Helper/Json.php b/SEOstats/Helper/Json.php new file mode 100644 index 00000000..cda64673 --- /dev/null +++ b/SEOstats/Helper/Json.php @@ -0,0 +1,64 @@ + + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/02/03 + */ + +class Json +{ + /** + * Decodes a JSON string into appropriate variable. + * + * @param string $str JSON-formatted string + * @param boolean $accos When true, returned objects will be converted into associative arrays. + * @return mixed number, boolean, string, array, or object corresponding to given JSON input string. + * Note that decode() always returns strings in ASCII or UTF-8 format! + */ + public static function decode($str, $assoc = false) + { + if (!function_exists('json_decode')) { + $j = self::getJsonService(); + return $j->decode($str); + } + else { + return $assoc ? json_decode($str, true) : json_decode($str); + } + } + + /** + * Encodes an arbitrary variable into JSON format. + * + * @param mixed $var any number, boolean, string, array, or object to be encoded. + * if var is a string, note that encode() always expects it + * to be in ASCII or UTF-8 format! + * @return mixed JSON string representation of input var or an error if a problem occurs + */ + public static function encode($var) + { + if (!function_exists('json_encode')) { + $j = self::getJsonService(); + return $j->encode($var); + } + else { + return json_encode($var); + } + } + + /** + * Return a new object of Services_JSON class. + * Used if native PHP JSON extension is not available. + */ + private static function getJsonService() + { + require_once SEOSTATSPATH . 'Services\3rdparty\JSON.php'; + return new \Services_JSON(); + } + +} diff --git a/src/helper/seostats.urlhelper.php b/SEOstats/Helper/Url.php similarity index 55% rename from src/helper/seostats.urlhelper.php rename to SEOstats/Helper/Url.php index 4fc7a14d..34a361dc 100644 --- a/src/helper/seostats.urlhelper.php +++ b/SEOstats/Helper/Url.php @@ -1,15 +1,19 @@ - - * @updated 2012/06/06 + * @package SEOstats + * @author Stephan Schmitz + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/02/03 */ -class UrlHelper extends SEOstats +class Url { - public static function getHost($url) + public static function parseHost($url) { $url = @parse_url('http://' . preg_replace('#^https?://#', '', $url)); return (isset($url['host']) && !empty($url['host'])) ? $url['host'] : false; @@ -22,23 +26,17 @@ public static function getHost($url) * @param string $url String, containing the initialized object URL. * @return string Returns string, containing the validation result. */ - private function isRfc($url) + public static function isRfc($url) { - if(isset($url) && 1 < strlen($url)) - { - $host = self::getHost($url); - $scheme = parse_url($url, PHP_URL_SCHEME); - if (false !== $host && in_array(strtolower($scheme), array('http','https'))) - { + if(isset($url) && 1 < strlen($url)) { + $host = self::parseHost($url); + $scheme = strtolower(parse_url($url, PHP_URL_SCHEME)); + if (false !== $host && ($scheme == 'http' || $scheme == 'https')) { $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}))?)'; - return (bool) preg_match($pattern, $url); } } return false; } } - -/* End of file seostats.urlhelper.php */ -/* Location: ./src/helper/seostats.urlhelper.php */ \ No newline at end of file diff --git a/SEOstats/SEOstats.php b/SEOstats/SEOstats.php new file mode 100644 index 00000000..978e9038 --- /dev/null +++ b/SEOstats/SEOstats.php @@ -0,0 +1,211 @@ + + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org + * @version CVS: $Id: SEOstats.php, v2.5.2 Rev 31 2013/08/14 13:57:17 ssc Exp $ + * @link https://github.com/eyecatchup/SEOstats/ + * ================================================================================ + * LICENSE: Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software'), + * to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * ================================================================================ + */ + +/** + * Check required PHP settings. + */ +if (!function_exists('curl_init')) { + throw new E('SEOstats requires the PHP CURL extension.'); + exit(); +} + +if (1 == ini_get('safe_mode') || 'on' === strtolower(ini_get('safe_mode'))) { + throw new E('Because some SEOstats functions require the CURLOPT_FOLLOWLOCATION flag, ' . + 'you must not run PHP in safe mode! (This flag can not be set in safe mode.)'); + exit(); +} + +/** + * Starting point for the SEOstats library. Example Usage: + * + * + * ... + * $url = 'http://www.domain.tld'; + * + * // Get the Google Toolbar PageRank value. + * $result = \SEOstats\Services\Google::getPageRank($url); + * + * // Get the first 100 results for a Google search for 'query string'. + * $result = \SEOstats\Services\Google::getSerps('query string'); + * + * // Get the first 500 results for a Google search for 'query string'. + * $result = \SEOstats\Services\Google::getSerps('query string', 500); + * + * // Check the first 500 results for a Google search for 'query string' for + * // occurrences of the given domain name and return an array of matching + * // URL's and their position within the serps. + * $result = \SEOstats\Services\Google::getSerps('query string', 500, $url); + * ... + * + * + */ +class SEOstats +{ + const BUILD_NO = Config\Package::VERSION_CODE; + + protected static $_url, + $_host, + $_lastHtml, + $_lastLoadedUrl + = false; + + public function __construct($url = false) + { + if (false !== $url) { + self::setUrl($url); + } + } + + public function Alexa() + { + return new Service\Alexa; + } + + public function Google() + { + return new Service\Google; + } + + public function OpenSiteExplorer() + { + return new Service\OpenSiteExplorer; + } + + public function SEMRush() + { + return new Service\SemRush; + } + + public function Sistrix() + { + return new Service\Sistrix; + } + + public function Social() + { + return new Service\Social; + } + + public static function getHost() + { + return self::$_host; + } + + public static function getLastLoadedHtml() + { + return self::$_lastHtml; + } + + public static function getLastLoadedUrl() + { + return self::$_lastLoadedUrl; + } + + /** + * Ensure the URL is set, return default otherwise + * @return string + */ + public static function getUrl($url = false) + { + $url = false !== $url ? $url : self::$_url; + return $url; + } + + public function setUrl($url) + { + if (false !== Helper\Url::isRfc($url)) { + self::$_url = $url; + self::$_host = Helper\Url::parseHost($url); + } + else { + throw new E('Invalid URL!'); + exit(); + } + return true; + } + + /** + * @return DOMDocument + */ + protected static function _getDOMDocument($html) { + $doc = new \DOMDocument; + @$doc->loadHtml($html); + return $doc; + } + + /** + * @return DOMXPath + */ + protected static function _getDOMXPath($doc) { + $xpath = new \DOMXPath($doc); + return $xpath; + } + + /** + * @return HTML string + */ + protected static function _getPage($url) { + $url = self::getUrl($url); + if (self::getLastLoadedUrl() == $url) { + return self::getLastLoadedHtml(); + } + + $html = Helper\HttpRequest::sendRequest($url); + if ($html) { + self::$_lastLoadedUrl = $url; + self::_setHtml($html); + return $html; + } + else { + self::noDataDefaultValue(); + } + } + + protected static function _setHtml($str) + { + self::$_lastHtml = $str; + } + + protected static function noDataDefaultValue() + { + return Config\DefaultSettings::DEFAULT_RETURN_NO_DATA; + } +} diff --git a/src/3rdparty/GTB_PageRank.php b/SEOstats/Services/3rdparty/GTB_PageRank.php similarity index 100% rename from src/3rdparty/GTB_PageRank.php rename to SEOstats/Services/3rdparty/GTB_PageRank.php diff --git a/src/3rdparty/JSON.php b/SEOstats/Services/3rdparty/JSON.php similarity index 100% rename from src/3rdparty/JSON.php rename to SEOstats/Services/3rdparty/JSON.php diff --git a/SEOstats/Services/Alexa.php b/SEOstats/Services/Alexa.php new file mode 100644 index 00000000..3f30b466 --- /dev/null +++ b/SEOstats/Services/Alexa.php @@ -0,0 +1,169 @@ + + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/08/14 + */ + +use SEOstats\SEOstats as SEOstats; +use SEOstats\Config as Config; +use SEOstats\Helper as Helper; + +class Alexa extends SEOstats +{ + /** + * Used for cache + * @var DOMXPath + */ + protected static $_xpath = false; + + /** + * The global rank is compute as an average over three months + * + * @return int + */ + public static function getGlobalRank($url = false) + { + return self::getQuarterRank($url); + } + + /** + * Get the average rank over the week + * @return int + */ + public static function getWeekRank($url = false) + { + $xpath = self::_getXPath($url); + $nodes = @$xpath->query("//*[@id='rank']/table/tr[2]/td[1]"); + + return !$nodes->item(0) ? parent::noDataDefaultValue() : + self::retInt( strip_tags($nodes->item(0)->nodeValue) ); + } + + /** + * Get the average rank over the week + * @return int + */ + public static function getMonthRank($url = false) + { + $xpath = self::_getXPath($url); + $nodes = @$xpath->query("//*[@id='rank']/table/tr[3]/td[1]"); + + return !$nodes->item(0) ? parent::noDataDefaultValue() : + self::retInt( strip_tags($nodes->item(0)->nodeValue) ); + } + + + public static function getQuarterRank($url = false) { + $xpath = self::_getXPath($url); + $nodes = @$xpath->query("//*[@id='siteStats']/tbody/tr[1]/td[1]/div"); + + return !$nodes->item(0) ? parent::noDataDefaultValue() : + self::retInt( strip_tags($nodes->item(0)->nodeValue) ); + } + + public static function getCountryRank($url = false) + { + $xpath = self::_getXPath($url); + $nodes = @$xpath->query("//*[@id='siteStats']/tbody/tr[1]/td[2]/div"); + + if ($nodes->item(0)) { + $rank = self::retInt(strip_tags($nodes->item(0)->nodeValue)); + if ($nodes->item(1) && 0 != $rank) { + $cntry = @explode("\n", $nodes->item(1)->nodeValue, 3); + return array( + 'rank' => $rank, + 'country' => $cntry[1] + ); + } + } + + return parent::noDataDefaultValue(); + } + + public static function getBacklinkCount($url = false) + { + $xpath = self::_getXPath($url); + $nodes = @$xpath->query("//*[@id='siteStats']/tbody/tr[1]/td[3]/div[1]/a"); + + return !$nodes->item(0) ? parent::noDataDefaultValue() : + self::retInt($nodes->item(0)->nodeValue); + } + + public static function getPageLoadTime($url = false) + { + $xpath = self::_getXPath($url); + $nodes = @$xpath->query( "//*[@id='trafficstats_div']/div[4]/div[1]/p" ); + + return !$nodes->item(0) ? parent::noDataDefaultValue() : + strip_tags($nodes->item(0)->nodeValue); + } + + /** + * @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 static function getTrafficGraph($type = 1, $url = false, $w = 660, $h = 330, $period = 1, $html = true) + { + $url = self::getUrl($url); + $domain = Helper\Url::parseHost($url); + + 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; + } + + $imgUrl = sprintf(Config\Services::ALEXA_GRAPH_URL, $gtype, $w, $h, $period, $domain); + $imgTag = 'Alexa Statistics Graph for %s'; + + return !$html ? $imgUrl : sprintf($imgTag, $imgUrl, $w, $h, $domain); + } + + /** + * @return DOMXPath + */ + private static function _getXPath($url) { + $url = parent::getUrl($url); + if (parent::getLastLoadedUrl() == $url && self::$_xpath) { + return self::$_xpath; + } + + $html = self::_getAlexaPage($url); + $doc = parent::_getDOMDocument($html); + $xpath = parent::_getDOMXPath($doc); + + self::$_xpath = $xpath; + + return $xpath; + } + + private static function _getAlexaPage($url) + { + $domain = Helper\Url::parseHost($url); + $dataUrl = sprintf(Config\Services::ALEXA_SITEINFO_URL, $domain); + $html = parent::_getPage($dataUrl); + return $html; + } + + private static function retInt($str) + { + $strim = trim(str_replace(',', '', $str)); + $intStr = 0 < strlen($strim) ? $strim : '0'; + return intval($intStr); + } +} diff --git a/src/modules/seostats.google.php b/SEOstats/Services/Google.php similarity index 66% rename from src/modules/seostats.google.php rename to SEOstats/Services/Google.php index 850ed523..2168dac7 100644 --- a/src/modules/seostats.google.php +++ b/SEOstats/Services/Google.php @@ -1,13 +1,22 @@ - - * @updated 2012/06/07 + * @package SEOstats + * @author Stephan Schmitz + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/08/14 */ -class SEOstats_Google extends SEOstats implements services, default_settings +use SEOstats\Common\SEOstatsException as E; +use SEOstats\SEOstats as SEOstats; +use SEOstats\Config as Config; +use SEOstats\Helper as Helper; + +class Google extends SEOstats { /** * Gets the Google Pagerank @@ -15,12 +24,10 @@ class SEOstats_Google extends SEOstats implements services, default_settings * @param string $url String, containing the query URL. * @return integer Returns the Google PageRank. */ - public function getPageRank($url = false) + public static function getPageRank($url = false) { - require_once(SEOSTATSPATH . '3rdparty/GTB_PageRank.php'); - - $url = false != $url ? $url : self::getUrl(); - $gtb = new GTB_PageRank($url); + require_once SEOSTATSPATH . 'Services\3rdparty\GTB_PageRank.php'; + $gtb = new \GTB_PageRank(parent::getUrl($url)); return $gtb->getPageRank(); } @@ -31,10 +38,10 @@ public function getPageRank($url = false) * @param string $url String, containing the query URL. * @return integer Returns the total site-search result count. */ - public function getSiteindexTotal($url = false) + public static function getSiteindexTotal($url = false) { - $url = false != $url ? $url : self::getUrl(); - $query = urlencode("site:$url"); + $url = parent::getUrl($url); + $query = urlencode("site:{$url}"); return self::getSearchResultsTotal($query); } @@ -45,10 +52,10 @@ public function getSiteindexTotal($url = false) * @param string $url String, containing the query URL. * @return integer Returns the total link-search result count. */ - public function getBacklinksTotal($url = false) + public static function getBacklinksTotal($url = false) { - $url = false != $url ? $url : self::getUrl(); - $query = urlencode("link:$url"); + $url = parent::getUrl($url); + $query = urlencode("link:{$url}"); return self::getSearchResultsTotal($query); } @@ -60,42 +67,43 @@ public function getBacklinksTotal($url = false) * @param string $url String, containing the query URL. * @return integer Returns the total search result count. */ - public function getSearchResultsTotal($url = false) + public static function getSearchResultsTotal($url = false) { - $url = false != $url ? $url : self::getUrl(); - $url = sprintf(services::GOOGLE_APISEARCH_URL, 1, $url); + $url = parent::getUrl($url); + $url = sprintf(Config\Services::GOOGLE_APISEARCH_URL, 1, $url); - $ret = HttpRequest::sendRequest($url); + $ret = parent::_getPage($url); - $obj = json_decode($ret); - return ! isset($obj->responseData->cursor->estimatedResultCount) - ? '0' + $obj = Helper\Json::decode($ret); + return !isset($obj->responseData->cursor->estimatedResultCount) + ? parent::noDataDefaultValue() : intval($obj->responseData->cursor->estimatedResultCount); } - /** - * Returns total amount of results for any Google search, - * requesting the deprecated Websearch API. - * - * @param string $url String, containing the query URL. - * @return integer Returns a total count. - */ - public function getPagespeedAnalysis($url = false) + public static function getPagespeedAnalysis($url = false) { - $url = false != $url ? $url : self::getUrl(); - $url = sprintf(services::GOOGLE_PAGESPEED_URL, $url); + if ('' == Config\ApiKeys::GOOGLE_SIMPLE_API_ACCESS_KEY) { + throw new E('In order to use the PageSpeed API, you must obtain + and set an API key first (see SEOstats\Config\ApiKeys.php).'); + exit(0); + } + + $url = parent::getUrl($url); + $url = sprintf(Config\Services::GOOGLE_PAGESPEED_URL, + $url, Config\ApiKeys::GOOGLE_SIMPLE_API_ACCESS_KEY); - $ret = HttpRequest::sendRequest($url); + $ret = parent::_getPage($url); - return json_decode($ret); + return Helper\Json::decode($ret); } - public function getPagespeedScore($url = false) + public static function getPagespeedScore($url = false) { - $url = false != $url ? $url : self::getUrl(); + $url = parent::getUrl($url); $ret = self::getPagespeedAnalysis($url); - return intval($ret->results->score); + return !$ret->score ? parent::noDataDefaultValue() : + intval($ret->score); } /** @@ -105,7 +113,7 @@ public function getPagespeedScore($url = false) * @param string $tld String, containing the desired Google top level domain. * @return array Returns array, containing the keys 'URL', 'Title' and 'Description'. */ - public function getSerps($query, $maxResults=100, $domain=false) + public static function getSerps($query, $maxResults=100, $domain=false) { $q = rawurlencode($query); $maxResults = ($maxResults/10)-1; @@ -118,8 +126,8 @@ public function getSerps($query, $maxResults=100, $domain=false) $curledSerp = utf8_decode( self::gCurl($nextSerp, $ref) ); - if (preg_match("#answer=86640#i", $curledSerp)) { - print('Please read: http://www.google.com/support/websearch/bin/answer.py?&answer=86640&hl=en'); + if (preg_match("#answer[=|/]86640#i", $curledSerp)) { + print('Please read: https://support.google.com/websearch/answer/86640'); exit(); } else { @@ -133,7 +141,7 @@ public function getSerps($query, $maxResults=100, $domain=false) $c++; $resCnt = ($start * 10) + $c; if (FALSE !== $domain) { - if (preg_match("#^$domain#i", $match[1])) { + if (preg_match("#^{$domain}#i", $match[1])) { $result[] = array( 'position' => $resCnt, 'url' => $match[1], @@ -170,9 +178,9 @@ public function getSerps($query, $maxResults=100, $domain=false) return $result; } - private function gCurl($path, $ref, $useCookie = default_settings::ALLOW_GOOGLE_COOKIES) + private static function gCurl($path, $ref, $useCookie = Config\DefaultSettings::ALLOW_GOOGLE_COOKIES) { - $url = sprintf('https://www.google.%s/', default_settings::GOOGLE_TLD); + $url = sprintf('https://www.google.%s/', Config\DefaultSettings::GOOGLE_TLD); $referer = $ref == '' ? $url : $ref; $url .= $path; @@ -182,13 +190,13 @@ private function gCurl($path, $ref, $useCookie = default_settings::ALLOW_GOOGLE_ } $header = array( - 'Host: www.google.' . default_settings::GOOGLE_TLD, + 'Host: www.google.' . Config\DefaultSettings::GOOGLE_TLD, 'Connection: keep-alive', 'Cache-Control: max-age=0', 'User-Agent: ' . $ua, 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Referer: ' . $referer, - 'Accept-Language: ' . default_settings::HTTP_HEADER_ACCEPT_LANGUAGE, + 'Accept-Language: ' . Config\DefaultSettings::HTTP_HEADER_ACCEPT_LANGUAGE, 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7' ); @@ -199,8 +207,8 @@ private function gCurl($path, $ref, $useCookie = default_settings::ALLOW_GOOGLE_ curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_USERAGENT, $ua); if ($useCookie == 1) { - curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt'); - curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookie.txt'); + curl_setopt($ch, CURLOPT_COOKIEJAR, __DIR__ . '/cookie.txt'); + curl_setopt($ch, CURLOPT_COOKIEFILE, __DIR__ . '/cookie.txt'); } curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); $result = curl_exec($ch); @@ -209,6 +217,3 @@ private function gCurl($path, $ref, $useCookie = default_settings::ALLOW_GOOGLE_ return ($info['http_code']!=200) ? false : $result; } } - -/* End of file seostats.google.php */ -/* Location: ./src/modules/seostats.google.php */ \ No newline at end of file diff --git a/SEOstats/Services/OpenSiteExplorer.php b/SEOstats/Services/OpenSiteExplorer.php new file mode 100644 index 00000000..1666b79b --- /dev/null +++ b/SEOstats/Services/OpenSiteExplorer.php @@ -0,0 +1,40 @@ + + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/08/14 + */ + +use SEOstats\SEOstats as SEOstats; +use SEOstats\Config as Config; + +class OpenSiteExplorer extends SEOstats +{ + public static function getPageMetrics($url = false) + { + $url = parent::getUrl($url); + $dataUrl = sprintf(Config\Services::OPENSITEEXPLORER_URL, 'links', '1', $url); + + $html = parent::_getPage($dataUrl); + $doc = parent::_getDOMDocument($html); + $data = @$doc->getElementsByTagName('td'); + + if ($data->item(0)) { + return array( + 'domainAuthority' => trim(strip_tags($data->item(0)->textContent)), + 'pageAuthority' => trim(strip_tags($data->item(1)->textContent)), + 'linkingRootDomains' => trim(strip_tags($data->item(2)->textContent)), + 'totalInboundLinks' => trim(strip_tags($data->item(3)->textContent)) + ); + } + else { + return parent::noDataDefaultValue(); + } + } +} diff --git a/src/modules/seostats.semrush.php b/SEOstats/Services/SemRush.php similarity index 63% rename from src/modules/seostats.semrush.php rename to SEOstats/Services/SemRush.php index 9537452f..4ba87927 100644 --- a/src/modules/seostats.semrush.php +++ b/SEOstats/Services/SemRush.php @@ -1,15 +1,24 @@ - - * @updated 2012/06/16 + * @package SEOstats + * @author Stephan Schmitz + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/08/14 */ -class SEOstats_SEMRush extends SEOstats +use SEOstats\Common\SEOstatsException as E; +use SEOstats\SEOstats as SEOstats; +use SEOstats\Config as Config; +use SEOstats\Helper as Helper; + +class SEMRush extends SEOstats { - public function getDBs() + public static function getDBs() { return array( "au", # Google.com.au (Australia) @@ -26,7 +35,7 @@ public function getDBs() ); } - public function getParams() + public static function getParams() { return array( "DomainReports" => array( @@ -69,63 +78,59 @@ public function getParams() * @return array Returns an array containing the main report data. * @link http://www.semrush.com/api.html */ - public function getDomainRank($url = false, $db = false) + public static function getDomainRank($url = false, $db = false) { - $db = false != $db ? $db : default_settings::SEMRUSH_DB; + $db = false !== $db ? $db : Config\DefaultSettings::SEMRUSH_DB; $dataUrl = self::getBackendUrl($url, $db, 'domain_rank'); - - $data = self::getApiData($dataUrl); + $data = self::getApiData($dataUrl); if (!is_array($data)) { - $data = self::getApiData( str_replace('.backend.', '.api.', $dataUrl) ); + $data = self::getApiData(str_replace('.backend.', '.api.', $dataUrl)); if (!is_array($data)) { - return false; + return parent::noDataDefaultValue(); } } return $data['rank']['data'][0]; } - public function getDomainRankHistory($url = false, $db = false) + public static function getDomainRankHistory($url = false, $db = false) { - $db = false != $db ? $db : default_settings::SEMRUSH_DB; + $db = false !== $db ? $db : Config\DefaultSettings::SEMRUSH_DB; $dataUrl = self::getBackendUrl($url, $db, 'domain_rank_history'); - - $data = self::getApiData($dataUrl); + $data = self::getApiData($dataUrl); if (!is_array($data)) { - $data = self::getApiData( str_replace('.backend.', '.api.', $dataUrl) ); + $data = self::getApiData(str_replace('.backend.', '.api.', $dataUrl)); if (!is_array($data)) { - return false; + return parent::noDataDefaultValue(); } } return $data['rank_history']; } - public function getOrganicKeywords($url = false, $db = false) + public static function getOrganicKeywords($url = false, $db = false) { - $db = false != $db ? $db : default_settings::SEMRUSH_DB; + $db = false !== $db ? $db : Config\DefaultSettings::SEMRUSH_DB; $dataUrl = self::getWidgetUrl($url, $db, 'organic'); + $data = self::getApiData($dataUrl); - $data = self::getApiData($dataUrl); - - return ! is_array($data) ? false : $data['organic']; + return !is_array($data) ? parent::noDataDefaultValue() : $data['organic']; } - public function getCompetitors($url = false, $db = false) + public static function getCompetitors($url = false, $db = false) { - $db = false != $db ? $db : default_settings::SEMRUSH_DB; + $db = false !== $db ? $db : Config\DefaultSettings::SEMRUSH_DB; $dataUrl = self::getWidgetUrl($url, $db, 'organic_organic'); + $data = self::getApiData($dataUrl); - $data = self::getApiData($dataUrl); - - return ! is_array($data) ? false : $data['organic_organic']; + return !is_array($data) ? parent::noDataDefaultValue() : $data['organic_organic']; } - public function getDomainGraph($reportType = 1, $url = false, $db = false, $w = 400, $h = 300, $lc = 'e43011', $dc = 'e43011', $lang = 'en', $html = true) + public static function getDomainGraph($reportType = 1, $url = false, $db = false, $w = 400, $h = 300, $lc = 'e43011', $dc = 'e43011', $lang = 'en', $html = true) { - $db = false != $db ? $db : default_settings::SEMRUSH_DB; - $url = false != $url ? $url : self::getUrl(); - $domain = UrlHelper::getHost($url); + $db = false !== $db ? $db : Config\DefaultSettings::SEMRUSH_DB; + $url = self::getUrl($url); + $domain = Helper\Url::parseHost($url); $database = self::checkDatabase($db); if (false == $domain) { @@ -147,7 +152,8 @@ public function getDomainGraph($reportType = 1, $url = false, $db = false, $w = self::exc('You must specify a valid language code.'); } else { - $imgUrl = sprintf(services::SEMRUSH_GRAPH_URL, $domain, $database, $reportType, $w, $h, $lc, $dc, $lang); + $imgUrl = sprintf(Config\Services::SEMRUSH_GRAPH_URL, + $domain, $database, $reportType, $w, $h, $lc, $dc, $lang); if (true != $html) { return $imgUrl; } else { @@ -157,56 +163,58 @@ public function getDomainGraph($reportType = 1, $url = false, $db = false, $w = } } - private function getApiData($url) + private static function getApiData($url) { - $jsonData = HttpRequest::sendRequest($url); - return json_decode($jsonData, true); + $json = parent::_getPage($url); + return Helper\Json::decode($json, true); } - private function getBackendUrl($url, $db, $reportType) + private static function getBackendUrl($url, $db, $reportType) { - $url = false != $url ? $url : self::getUrl(); - $domain = UrlHelper::getHost($url); + $url = parent::getUrl($url); + $domain = Helper\Url::parseHost($url); $database = self::checkDatabase($db); if (false === $domain) { - self::exc('Invalid domain name.'); } + self::exc('Invalid domain name.'); + } else if (false === $database) { - self::exc('db'); } + self::exc('db'); + } else { - $backendUrl = services::SEMRUSH_BE_URL; + $backendUrl = Config\Services::SEMRUSH_BE_URL; return sprintf($backendUrl, $database, $reportType, $domain); } } - private function getWidgetUrl($url, $db, $reportType) + private static function getWidgetUrl($url, $db, $reportType) { - $url = false != $url ? $url : self::getUrl(); - $domain = UrlHelper::getHost($url); + $url = parent::getUrl($url); + $domain = Helper\Url::parseHost($url); $database = self::checkDatabase($db); if (false === $domain) { - self::exc('Invalid domain name.'); } + self::exc('Invalid domain name.'); + } else if (false === $database) { - self::exc('db'); } + self::exc('db'); + } else { - $widgetUrl = services::SEMRUSH_WIDGET_URL; + $widgetUrl = Config\Services::SEMRUSH_WIDGET_URL; return sprintf($widgetUrl, $reportType, $database, $domain); } } - private function checkDatabase($db) + private static function checkDatabase($db) { - return ! in_array($db, self::getDBs()) ? false : $db; + return !in_array($db, self::getDBs()) ? false : $db; } - private function exc($err) + private static function exc($err) { - $e = ($err == 'db') ? "Invalid database. Choose one of: " . substr( implode(", ", self::getDBs()), 0, -2) : $err; - throw new SEOstatsException($e); + $e = ($err == 'db') ? "Invalid database. Choose one of: " . + substr( implode(", ", self::getDBs()), 0, -2) : $err; + throw new E($e); exit(0); } } - -/* End of file seostats.semrush.php */ -/* Location: ./src/modules/seostats.semrush.php */ \ No newline at end of file diff --git a/SEOstats/Services/Sistrix.php b/SEOstats/Services/Sistrix.php new file mode 100644 index 00000000..43d0bcf7 --- /dev/null +++ b/SEOstats/Services/Sistrix.php @@ -0,0 +1,39 @@ + + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/08/14 + */ + +use SEOstats\SEOstats as SEOstats; +use SEOstats\Config as Config; +use SEOstats\Helper as Helper; + +class Sistrix extends SEOstats +{ + /** + * Returns the Sistrix visibility index + * + * @access public + * @param url string The URL to check. + * @return integer Returns the Sistrix visibility index. + * @link http://www.sistrix.com/blog/870-sistrix-visibilityindex.html + */ + public static function getVisibilityIndex($url = false) + { + $url = parent::getUrl($url); + $domain = Helper\Url::parseHost($url); + $dataUrl = sprintf(Config\Services::SISTRIX_VI_URL, urlencode($domain)); + + $html = parent::_getPage($dataUrl); + @preg_match_all('#

(.*?)<\/h3>#si', $html, $matches); + + return isset($matches[1][0]) ? $matches[1][0] : parent::noDataDefaultValue(); + } +} diff --git a/SEOstats/Services/Social.php b/SEOstats/Services/Social.php new file mode 100644 index 00000000..c176fa57 --- /dev/null +++ b/SEOstats/Services/Social.php @@ -0,0 +1,209 @@ + + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/08/14 + */ + +use SEOstats\SEOstats as SEOstats; +use SEOstats\Config as Config; +use SEOstats\Helper as Helper; + +class Social extends SEOstats +{ + /** + * Returns the total count of Google+ Plus Ones + * + * @access public + * @param url string The URL to check. + * @return integer Returns the total count of Plus Ones for a URL. + */ + public static function getGoogleShares($url = false) + { + $url = parent::getUrl($url); + $dataUrl = sprintf(Config\Services::GOOGLE_PLUSONE_URL, urlencode($url)); + $html = parent::_getPage($dataUrl); + @preg_match_all('#c: (.*?)\.0#si', $html, $matches); + + return isset($matches[1][0]) ? intval($matches[1][0]) : parent::noDataDefaultValue(); + } + + /** + * Returns Facebook Sharing data + * + * @access public + * @link http://developers.facebook.com/docs/reference/fql/link_stat/ + * @param url string The URL to check. + * @return array Returns an array of total counts for 1. all Facebook interactions, + * 2. FB shares, 3. FB likes, 4. FB comments and 5. outgoing clicks for a URL. + */ + public static function getFacebookShares($url = false) + { + $url = parent::getUrl($url); + $fql = sprintf('SELECT total_count, share_count, like_count, comment_count, commentsbox_count, click_count FROM link_stat WHERE url="%s"', $url); + $dataUrl = sprintf(Config\Services::FB_LINKSTATS_URL, rawurlencode($fql)); + + $jsonData = parent::_getPage($dataUrl); + $phpArray = Helper\Json::decode($jsonData, true); + + return isset($phpArray[0]) ? $phpArray[0] : parent::noDataDefaultValue(); + } + + /** + * Returns the total count of Twitter mentions + * + * @access public + * @param url string The URL to check. + * @return integer Returns the total count of Twitter mentions for a URL. + * @link https://dev.twitter.com/discussions/5653#comment-11514 + */ + public static function getTwitterShares($url = false) + { + $url = parent::getUrl($url); + $dataUrl = sprintf(Config\Services::TWEETCOUNT_URL, urlencode($url)); + + $jsonData = parent::_getPage($dataUrl); + $phpArray = Helper\Json::decode($jsonData, true); + + return isset($phpArray['count']) ? intval($phpArray['count']) : parent::noDataDefaultValue(); + } + + /** + * Returns the total count of URL shares via Delicious + * + * @access public + * @param url string The URL to check. + * @return integer Returns the total count of URL shares. + */ + public static function getDeliciousShares($url = false) + { + $url = parent::getUrl($url); + $dataUrl = sprintf(Config\Services::DELICIOUS_INFO_URL, urlencode($url)); + + $jsonData = parent::_getPage($dataUrl); + $phpArray = Helper\Json::decode($jsonData, true); + + return isset($phpArray[0]['total_posts']) ? intval($phpArray[0]['total_posts']) : parent::noDataDefaultValue(); + } + + /** + * Returns the Top10 tags from Delicious + * + * @access public + * @param url string The URL to check. + * @return array Returns the top ten delicious tags for a URL (if exist; else an empty array). + */ + public static function getDeliciousTopTags($url = false) + { + $url = parent::getUrl($url); + $dataUrl = sprintf(Config\Services::DELICIOUS_INFO_URL, urlencode($url)); + + $jsonData = parent::_getPage($dataUrl); + $phpArray = Helper\Json::decode($jsonData, true); + + $ret = array(); + if (isset($phpArray[0]['top_tags']) && 0 < sizeof($phpArray[0]['top_tags'])) { + foreach($phpArray[0]['top_tags'] as $k => $v) { + $ret[] = $k; + } + } + return $ret; + } + + /** + * Returns the total count of URL shares via Digg + * + * @access public + * @param url string The URL to check. + * @return integer Returns the total count of URL shares. + */ + public static function getDiggShares($url = false) + { + $url = parent::getUrl($url); + $dataUrl = sprintf(Config\Services::DIGG_INFO_URL, urlencode($url)); + + $jsonData = parent::_getPage($dataUrl); + $phpArray = Helper\Json::decode(substr($jsonData, 2, -2), true); + + return isset($phpArray['diggs']) ? intval($phpArray['diggs']) : parent::noDataDefaultValue(); + } + + /** + * Returns the total count of URL shares via LinkedIn + * + * @access public + * @param url string The URL to check. + * @return integer Returns the total count of URL shares. + */ + public static function getLinkedInShares($url = false) + { + $url = parent::getUrl($url); + $dataUrl = sprintf(Config\Services::LINKEDIN_INFO_URL, urlencode($url)); + + $jsonData = parent::_getPage($dataUrl); + $phpArray = Helper\Json::decode(substr($jsonData, 2, -2), true); + + return isset($phpArray['count']) ? intval($phpArray['count']) : parent::noDataDefaultValue(); + } + + /** + * Returns the total count of URL shares via Pinterest + * + * @access public + * @param url string The URL to check. + * @return integer Returns the total count of URL shares. + */ + public static function getPinterestShares($url = false) + { + $url = parent::getUrl($url); + $dataUrl = sprintf(Config\Services::PINTEREST_INFO_URL, urlencode($url)); + + $jsonData = parent::_getPage($dataUrl); + $phpArray = Helper\Json::decode(substr($jsonData, 2, -1), true); + + return isset($phpArray['count']) ? intval($phpArray['count']) : parent::noDataDefaultValue(); + } + + /** + * Returns the total count of URL shares via StumpleUpon + * + * @access public + * @param url string The URL to check. + * @return integer Returns the total count of URL shares. + */ + public static function getStumbleUponShares($url = false) + { + $url = parent::getUrl($url); + $dataUrl = sprintf(Config\Services::STUMBLEUPON_INFO_URL, urlencode($url)); + + $jsonData = parent::_getPage($dataUrl); + $phpArray = Helper\Json::decode($jsonData, true); + + return isset($phpArray['result']['in_index']) && true == $phpArray['result']['in_index'] + ? intval($phpArray['result']['views']) : parent::noDataDefaultValue(); + } + + /** + * Returns the total count of URL shares via VKontakte + * + * @access public + * @param url string The URL to check. + * @return integer Returns the total count of URL shares. + */ + public static function getVKontakteShares($url = false) + { + $url = parent::getUrl($url); + $dataUrl = sprintf(Config\Services::VKONTAKTE_INFO_URL, urlencode($url)); + + $htmlData = parent::_getPage($dataUrl); + @preg_match_all('#^VK\.Share\.count\(1, (\d+)\);$#si', $htmlData, $matches); + + return isset($matches[1][0]) ? intval($matches[1][0]) : parent::noDataDefaultValue(); + } +} diff --git a/SEOstats/bootstrap.php b/SEOstats/bootstrap.php new file mode 100644 index 00000000..b1aebb70 --- /dev/null +++ b/SEOstats/bootstrap.php @@ -0,0 +1,44 @@ + + * @copyright Copyright (c) 2010 - present Stephan Schmitz + * @license http://eyecatchup.mit-license.org/ MIT License + * @updated 2013/08/14 + */ + +if (!ini_get('date.timezone') && function_exists('date_default_timezone_set')) { + date_default_timezone_set('UTC'); +} + +/* + *--------------------------------------------------------------- + * SEOSTATS BASE PATH + *--------------------------------------------------------------- + * For increased reliability, resolve os-specific system path. + */ + +$base_path = __DIR__; +if (realpath( $base_path ) !== false) { + $base_path = realpath($base_path).'/'; +} +$base_path = rtrim($base_path, '/').'/'; +$base_path = str_replace('\\', '/', $base_path); + +define('SEOSTATSPATH', $base_path); + +/* + *--------------------------------------------------------------- + * Register autoloader + *--------------------------------------------------------------- + */ + +require_once SEOSTATSPATH . '/Common/AutoLoader.php'; + +$autoloader = new \SEOstats\Common\AutoLoader(__NAMESPACE__, dirname(__DIR__)); + +$autoloader->register(); diff --git a/composer.json b/composer.json index 1a6acdd5..1066eb48 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "description": "SEOstats is a powerful open source PHP library to request a bunch of SEO relevant metrics for any website.", "keywords": ["SEO","Pagerank","Backlinks","Google","SEOmoz","SEMRush","Bing","Alexa"], "homepage": "http://github.com/eyecatchup/SEOstats", - "version": "2.5.1", + "version": "2.5.2-dev", "license": "MIT", "authors": [ { diff --git a/demo/index.php b/demo/index.php deleted file mode 100644 index b6fce42d..00000000 --- a/demo/index.php +++ /dev/null @@ -1,199 +0,0 @@ - - - - - - Alexa(); - ?> - - - - - - - - - - - - - - - - getCountryRank(); ?> - - - - - - - - - - - - - Google(); - ?> - - - - - - - - - - - - - - - - - - - - - OpenSiteExplorer()->getPageMetrics(); - ?> - - - - - - - - - - - - - - - - - - - - - SEMRush()->getDomainRank(); - ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Sistrix(); - ?> - - - - - - - - - Social(); - ?> - - - - - - - - getFacebookShares(); ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Alexa
Global Domain-RankgetGlobalRank(); ?>
Week Domain-RankgetWeekRank(); ?>
Month Domain-RankgetMonthRank(); ?>
Country-specific Domain-Rank (Rank in )
Total amount of incoming linksgetBacklinkCount(); ?>
Average Pageload TimegetPageLoadTime(); ?>
Google
Toolbar PageRankgetPageRank(); ?>
Total amount of pages in Websearch-IndexgetSiteindexTotal(); ?>
Total amount of incoming linksgetBacklinksTotal(); ?>
PageSpeed total scoregetPagespeedScore(); ?>/100
OpenSiteExplorer (by SEOmoz)
SEOmoz Page-Authority
SEOmoz Domain-Authority
Total amount of incoming links
Total amount of inlinking domains
SEMRush
SEMRush Domain-Rank
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
Estimated number of competitors in organic search
Estimated number of potential ad/traffic buyers
Sistrix
Visibility-IndexgetVisibilityIndex(); ?>
Social Visibility
Total amount of Google +1s for the URLgetGoogleShares(); ?>
Total amount of Facebook Likes
Total amount of Facebook Shares
Total amount of backlinks from Facebook Comments
Total amount of backlinks from TweetsgetTwitterShares(); ?>
Total amount of backlinks from DeliciousgetDeliciousShares(); ?>
Total amount of backlinks from DigggetDiggShares(); ?>
Total amount of backlinks from LinkedIngetLinkedInShares(); ?>
Total amount of backlinks from PinterestgetPinterestShares(); ?>
Total amount of backlinks from StumbleUpongetStumbleUponShares(); ?>
Total amount of backlinks from VKontaktegetVKontakteShares(); ?>
-getMessage()); -} diff --git a/example/index.php b/example/index.php new file mode 100644 index 00000000..6dd218e2 --- /dev/null +++ b/example/index.php @@ -0,0 +1,62 @@ +setUrl($uri)) { + #$alexa = $seostats->Alexa(); + #$google = $seostats->Google(); + #$opensiteexplorer = $seostats->OpenSiteExplorer(); + #$semrush = $seostats->SEMRush(); + #print '
';
+		#print_r($seostats->Google()->getSerps('SEOstats'));
+		#print $alexa->getPageLoadTime();
+		#print $alexa->getPageLoadTime();
+		#print $google->getSearchResultsTotal('test');
+		#print $google->getSearchResultsTotal('test');
+		#print_r($semrush->getDomainRank());
+		#print_r($semrush->getDomainRankHistory());
+		#print_r($semrush->getCompetitors());
+		#print_r($opensiteexplorer->getPageMetrics());
+		#print '
'; + #print $semrush->getDomainGraph(); + #print $semrush->getDomainGraph(2); + #print $semrush->getDomainGraph(3); + #print $semrush->getDomainGraph(4); + #print $semrush->getDomainGraph(5); + + #print_r(SEOstats\Google::getPagespeedAnalysis()); + #print SEOstats\Google::getPagespeedScore(); + + #/* + print "= Alexa Metrics: \n"; + print " Page Load Time: " . SEOstats\Alexa::getPageLoadTime() . "\n"; + print "= Google Metrics: \n"; + print " Page-Rank: " . SEOstats\Google::getPageRank() . "\n"; + print " Total Indexed Pages: " . SEOstats\Google::getSiteindexTotal() . "\n"; + print "= Sistrix Metrics: \n"; + print " Visibility-Index: " . SEOstats\Sistrix::getVisibilityIndex() . "\n"; + print "= Open-Site-Explorer Metrics: \n"; + $ose = SEOstats\OpenSiteExplorer::getPageMetrics(); + print " Domain-Authority: " . $ose['domainAuthority'] . "\n"; + print " Page-Authority: " . $ose['pageAuthority'] . "\n"; + print " Linking Root Domains: " . $ose['linkingRootDomains'] . "\n"; + print " Total Inbound Links: " . $ose['totalInboundLinks']; + #*/ + } +} +catch (\Exception $e) { + echo 'Caught SEOstatsException: ' . $e->getMessage(); +} \ No newline at end of file diff --git a/src/helper/seostats.exception.php b/src/helper/seostats.exception.php deleted file mode 100644 index d0f53a58..00000000 --- a/src/helper/seostats.exception.php +++ /dev/null @@ -1,22 +0,0 @@ - - * @updated 2012/05/13 - */ - -class SEOstatsException extends Exception {} - -if (!function_exists('curl_init')) -{ - throw new SEOstatsException('SEOstats requires the PHP CURL extension.'); -} -if (!function_exists('json_decode')) -{ - throw new SEOstatsException('SEOstats requires the PHP JSON extension.'); -} - -/* End of file seostats.exception.php */ -/* Location: ./src/helper/seostats.exception.php */ \ No newline at end of file diff --git a/src/interfaces/api-keys.php b/src/interfaces/api-keys.php deleted file mode 100644 index 4296fe8d..00000000 --- a/src/interfaces/api-keys.php +++ /dev/null @@ -1,16 +0,0 @@ - - * @updated 2013/01/29 - */ - -interface api_keys -{ - //const VENDOR_APP_ID = 'FCB316D398F094C53B8C7AA8DA24B2D58AB520F8'; -} - -/* End of file api-keys.php */ -/* Location: ./src/interfaces/api-keys.php */ \ No newline at end of file diff --git a/src/interfaces/package.php b/src/interfaces/package.php deleted file mode 100644 index b34caee0..00000000 --- a/src/interfaces/package.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @updated 2013/01/29 - */ - -interface package -{ - const VERSION_CODE = '2.5.1'; - const LICENSE_TYPE = 'MIT Licence'; - const LICENSE_URL = 'http://eyecatchup.mit-license.org/'; - const AUTHOR_NAME = 'Stephan Schmitz'; - const AUTHOR_MAIL = 'eyecatchup@gmail.com'; -} - -/* End of file package.php */ -/* Location: ./src/interfaces/package.php */ \ No newline at end of file diff --git a/src/modules/seostats.alexa.php b/src/modules/seostats.alexa.php deleted file mode 100644 index 8d823847..00000000 --- a/src/modules/seostats.alexa.php +++ /dev/null @@ -1,188 +0,0 @@ - - * @updated 2013/01/18 - */ - -class SEOstats_Alexa extends SEOstats implements services -{ - /** - * Used for cache - * @var DOMXPath - */ - private $_xpath = NULL; - - /** - * Used for cache - * @var DOMXPath - */ - private $_lastLoadedUrl = NULL; - - /** - * The global rank is compute as an average over three months - * - * @return int - */ - public function getGlobalRank($url = false) - { - return $this->getQuarterRank($url); - } - - /** - * Get the average rank over the week - * @return int - */ - public function getWeekRank($url = false) - { - $xpath = $this->_getXPath($url); - $nodes = @$xpath->query("//*[@id='rank']/table/tr[2]/td[1]"); - - return self::retInt( strip_tags($nodes->item(0)->nodeValue) ); - } - - /** - * Get the average rank over the week - * @return int - */ - public function getMonthRank($url = false) - { - $xpath = $this->_getXPath($url); - $nodes = @$xpath->query("//*[@id='rank']/table/tr[3]/td[1]"); - - return self::retInt( strip_tags($nodes->item(0)->nodeValue) ); - } - - - public function getQuarterRank($url = false) { - $xpath = $this->_getXPath($url); - $nodes = @$xpath->query("//*[@id='siteStats']/tbody/tr[1]/td[1]/div"); - - return self::retInt( strip_tags($nodes->item(0)->nodeValue) ); - } - - public function getCountryRank($url = false) - { - $xpath = $this->_getXPath($url); - $nodes = @$xpath->query("//*[@id='siteStats']/tbody/tr[1]/td[2]/div"); - - $rank = self::retInt( strip_tags($nodes->item(0)->nodeValue) ); - if (0 != $rank) { - $cntry = @explode("\n", $nodes->item(1)->nodeValue, 3); - return array( - 'rank' => $rank, - 'country' => $cntry[1] - ); - } else { - return 'No data available.'; - } - } - - public function getBacklinkCount($url = false) - { - $xpath = $this->_getXPath($url); - $nodes = @$xpath->query("//*[@id='siteStats']/tbody/tr[1]/td[3]/div[1]/a"); - - return self::retInt($nodes->item(0)->nodeValue); - } - - public function getPageLoadTime($url = false) - { - $xpath = $this->_getXPath($url); - $nodes = @$xpath->query( "//*[@id='trafficstats_div']/div[4]/div[1]/p" ); - - return strip_tags($nodes->item(0)->nodeValue); - } - - /** - * @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 getTrafficGraph($type = 1, $url = false, $w = 660, $h = 330, $period = 1, $html = true) - { - $url = false != $url ? $url : self::getUrl(); - $domain = UrlHelper::getHost($url); - - 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; - } - - $imgUrl = sprintf(services::ALEXA_GRAPH_URL, $gtype, $w, $h, $period, $domain); - - if (true != $html) { - return $imgUrl; - } - else { - $imgTag = 'Alexa Statistics Graph for %s'; - return sprintf($imgTag, $imgUrl, $w, $h, $domain); - } - } - - /** - * @return DOMXPath - */ - private function _getXPath($url) { - $url = $this->_getUrl($url); - if ($this->_lastLoadedUrl == $url) { - return $this->_xpath; - } - $html = $this->_getAlexaPage($url); - $doc = $this->_getDOMDocument($html); - $xpath = new DOMXPath($doc); - $this->_lastLoadedUrl = $url; - $this->_xpath = $xpath; - - return $xpath; - } - - /** - * @return DOMDocument - */ - private function _getDOMDocument($html) { - $doc = new DOMDocument(); - @$doc->loadHtml($html); - return $doc; - } - - private function _getAlexaPage($url) - { - $domain = UrlHelper::getHost($url); - - $dataUrl = sprintf(services::ALEXA_SITEINFO_URL, $domain); - - return HttpRequest::sendRequest($dataUrl); - } - - /** - * Ensure the URL is set, return default otherwise - * @return string - */ - private function _getUrl($url) { - $url = false != $url ? $url : self::getUrl(); - return $url; - } - - private function retInt($str) - { - $strim = trim(str_replace(',', '', $str)); - $intStr = 0 < strlen($strim) ? $strim : '0'; - - return intval($intStr); - } -} - -/* End of file seostats.alexa.php */ -/* Location: ./src/modules/seostats.alexa.php */ \ No newline at end of file diff --git a/src/modules/seostats.opensiteexplorer.php b/src/modules/seostats.opensiteexplorer.php deleted file mode 100644 index 97676b25..00000000 --- a/src/modules/seostats.opensiteexplorer.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @updated 2013/01/29 - */ - -class SEOstats_OpenSiteExplorer extends SEOstats implements services -{ - public function getPageMetrics($url = false) - { - $url = false != $url ? $url : self::getUrl(); - $dataUrl = sprintf(services::OPENSITEEXPLORER_URL, 'links', '1', $url); - - $html = HttpRequest::sendRequest($dataUrl); - - $doc = new DOMDocument(); - @$doc->loadHtml($html); - - $data = $doc->getElementsByTagName('td'); - - return array( - 'domainAuthority' => trim(strip_tags($data->item(0)->textContent)), - 'pageAuthority' => trim(strip_tags($data->item(1)->textContent)), - 'linkingRootDomains' => trim(strip_tags($data->item(2)->textContent)), - 'totalInboundLinks' => trim(strip_tags($data->item(3)->textContent)) - ); - } -} - -/* End of file seostats.opensiteexplorer.php */ -/* Location: ./src/modules/seostats.opensiteexplorer.php */ \ No newline at end of file diff --git a/src/modules/seostats.sistrix.php b/src/modules/seostats.sistrix.php deleted file mode 100644 index cfb17578..00000000 --- a/src/modules/seostats.sistrix.php +++ /dev/null @@ -1,41 +0,0 @@ - - * @updated 2012/06/15 - */ - -class SEOstats_Sistrix extends SEOstats implements services -{ - /** - * Returns the Sistrix visibility index - * - * @access public - * @param url string The URL to check. - * @return integer Returns the Sistrix visibility index. - * @link http://www.sistrix.com/blog/870-sistrix-visibilityindex.html - */ - public function getVisibilityIndex($url = false) - { - $url = false != $url ? $url : self::getUrl(); - $domain = UrlHelper::getHost($url); - $dataUrl = sprintf(services::SISTRIX_VI_URL, urlencode($domain)); - - $html = HttpRequest::sendRequest($dataUrl); - - preg_match_all('#

(.*?)<\/h3>#si', $html, $matches); - - return isset($matches[1][0]) ? $matches[1][0] : intval('0'); - } - - public function OpenLinkGraph() - { - require_once(SEOSTATSPATH . 'modules/seostats.sistrix.openlinkgraph.php'); - return new SEOstats_OpenLinkGraph(); - } -} - -/* End of file seostats.sistrix.php */ -/* Location: ./src/modules/seostats.sistrix.php */ \ No newline at end of file diff --git a/src/modules/seostats.social.php b/src/modules/seostats.social.php deleted file mode 100644 index 0208ffe6..00000000 --- a/src/modules/seostats.social.php +++ /dev/null @@ -1,205 +0,0 @@ - - * @updated 2012/06/15 - */ - -class SEOstats_Social extends SEOstats implements services -{ - /** - * Returns the total count of Google+ Plus Ones - * - * @access public - * @param url string The URL to check. - * @return integer Returns the total count of Plus Ones for a URL. - */ - public function getGoogleShares($url = false) - { - $url = false != $url ? $url : self::getUrl(); - $dataUrl = sprintf(services::GOOGLE_PLUSONE_URL, urlencode($url)); - - $html = HttpRequest::sendRequest($dataUrl); - preg_match_all('#c: (.*?)\.0#si', $html, $matches); - - return isset($matches[1][0]) ? intval($matches[1][0]) : intval('0'); - } - - /** - * Returns Facebook Sharing data - * - * @access public - * @link http://developers.facebook.com/docs/reference/fql/link_stat/ - * @param url string The URL to check. - * @return array Returns an array of total counts for 1. all Facebook interactions, - * 2. FB shares, 3. FB likes, 4. FB comments and 5. outgoing clicks for a URL. - */ - public function getFacebookShares($url = false) - { - $url = false != $url ? $url : self::getUrl(); - $fql = sprintf('SELECT total_count, share_count, like_count, comment_count, commentsbox_count, click_count FROM link_stat WHERE url="%s"', $url); - $dataUrl = sprintf(services::FB_LINKSTATS_URL, rawurlencode($fql)); - - $jsonData = HttpRequest::sendRequest($dataUrl); - $phpArray = json_decode($jsonData, true); - - return isset($phpArray[0]) ? $phpArray[0] : intval('0'); - } - - /** - * Returns the total count of Twitter mentions - * - * @access public - * @param url string The URL to check. - * @return integer Returns the total count of Twitter mentions for a URL. - * @link https://dev.twitter.com/discussions/5653#comment-11514 - */ - public function getTwitterShares($url = false) - { - $url = false != $url ? $url : self::getUrl(); - $dataUrl = sprintf(services::TWEETCOUNT_URL, urlencode($url)); - - $jsonData = HttpRequest::sendRequest($dataUrl); - $phpArray = json_decode($jsonData, true); - - return isset($phpArray['count']) ? intval($phpArray['count']) : intval('0'); - } - - /** - * Returns the total count of URL shares via Delicious - * - * @access public - * @param url string The URL to check. - * @return integer Returns the total count of URL shares. - */ - public function getDeliciousShares($url = false) - { - $url = false != $url ? $url : self::getUrl(); - $dataUrl = sprintf(services::DELICIOUS_INFO_URL, urlencode($url)); - - $jsonData = HttpRequest::sendRequest($dataUrl); - $phpArray = json_decode($jsonData, true); - - return isset($phpArray[0]['total_posts']) ? intval($phpArray[0]['total_posts']) : intval('0'); - } - - /** - * Returns the Top10 tags from Delicious - * - * @access public - * @param url string The URL to check. - * @return array Returns the top ten delicious tags for a URL (if exist; else an empty array). - */ - public function getDeliciousTopTags($url = false) - { - $url = false != $url ? $url : self::getUrl(); - $dataUrl = sprintf(services::DELICIOUS_INFO_URL, urlencode($url)); - - $jsonData = HttpRequest::sendRequest($dataUrl); - $phpArray = json_decode($jsonData, true); - - $ret = array(); - if (isset($phpArray[0]['top_tags']) && 0 < sizeof($phpArray[0]['top_tags'])) { - foreach($phpArray[0]['top_tags'] as $k => $v) { - $ret[] = $k; - } - } - return $ret; - } - - /** - * Returns the total count of URL shares via Digg - * - * @access public - * @param url string The URL to check. - * @return integer Returns the total count of URL shares. - */ - public function getDiggShares($url = false) - { - $url = false != $url ? $url : self::getUrl(); - $dataUrl = sprintf(services::DIGG_INFO_URL, urlencode($url)); - - $jsonData = HttpRequest::sendRequest($dataUrl); - $phpArray = json_decode(substr($jsonData, 2, -2), true); - - return isset($phpArray['diggs']) ? intval($phpArray['diggs']) : intval('0'); - } - - /** - * Returns the total count of URL shares via LinkedIn - * - * @access public - * @param url string The URL to check. - * @return integer Returns the total count of URL shares. - */ - public function getLinkedInShares($url = false) - { - $url = false != $url ? $url : self::getUrl(); - $dataUrl = sprintf(services::LINKEDIN_INFO_URL, urlencode($url)); - - $jsonData = HttpRequest::sendRequest($dataUrl); - $phpArray = json_decode(substr($jsonData, 2, -2), true); - - return isset($phpArray['count']) ? intval($phpArray['count']) : intval('0'); - } - - /** - * Returns the total count of URL shares via Pinterest - * - * @access public - * @param url string The URL to check. - * @return integer Returns the total count of URL shares. - */ - public function getPinterestShares($url = false) - { - $url = false != $url ? $url : self::getUrl(); - $dataUrl = sprintf(services::PINTEREST_INFO_URL, urlencode($url)); - - $jsonData = HttpRequest::sendRequest($dataUrl); - $phpArray = json_decode(substr($jsonData, 2, -1), true); - - return isset($phpArray['count']) ? intval($phpArray['count']) : intval('0'); - } - - /** - * Returns the total count of URL shares via StumpleUpon - * - * @access public - * @param url string The URL to check. - * @return integer Returns the total count of URL shares. - */ - public function getStumbleUponShares($url = false) - { - $url = false != $url ? $url : self::getUrl(); - $dataUrl = sprintf(services::STUMBLEUPON_INFO_URL, urlencode($url)); - - $jsonData = HttpRequest::sendRequest($dataUrl); - $phpArray = json_decode($jsonData, true); - - return isset($phpArray['result']['in_index']) && true == $phpArray['result']['in_index'] - ? intval($phpArray['result']['views']) : intval('0'); - } - - /** - * Returns the total count of URL shares via VKontakte - * - * @access public - * @param url string The URL to check. - * @return integer Returns the total count of URL shares. - */ - public function getVKontakteShares($url = false) - { - $url = false != $url ? $url : self::getUrl(); - $dataUrl = sprintf(services::VKONTAKTE_INFO_URL, urlencode($url)); - - $htmlData = HttpRequest::sendRequest($dataUrl); - preg_match_all('#^VK\.Share\.count\(1, (\d+)\);$#si', $htmlData, $matches); - - return isset($matches[1][0]) ? intval($matches[1][0]) : intval('0'); - } -} - -/* End of file seostats.social.php */ -/* Location: ./src/modules/seostats.social.php */ \ No newline at end of file diff --git a/src/seostats.php b/src/seostats.php deleted file mode 100644 index 5c2841dc..00000000 --- a/src/seostats.php +++ /dev/null @@ -1,160 +0,0 @@ - - * @link https://github.com/eyecatchup/SEOstats/ - * ================================================================================ - * LICENSE: Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the "Software'), - * to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * ================================================================================ - */ - -/* - *--------------------------------------------------------------- - * SEOSTATS BASE PATH - *--------------------------------------------------------------- - * For increased reliability, resolve os-specific system path. - */ - -$base_path = __DIR__; -if (realpath( $base_path ) !== false) { - $base_path = realpath($base_path).'/'; -} -$base_path = rtrim($base_path, '/').'/'; -$base_path = str_replace('\\', '/', $base_path); - -define('SEOSTATSPATH', $base_path); - -/* - *--------------------------------------------------------------- - * SEOSTATS INTERFACES - *--------------------------------------------------------------- - */ -// Doesn't follow typical include path conventions, but is more convenient for users. -require SEOSTATSPATH . 'interfaces/default-settings.php'; -require SEOSTATSPATH . 'interfaces/services.php'; -require SEOSTATSPATH . 'interfaces/api-keys.php'; -require SEOSTATSPATH . 'interfaces/package.php'; - -/* - *--------------------------------------------------------------- - * SEOSTATS CORE CLASS - *--------------------------------------------------------------- - */ - -/** - * Starting point for the SEOstats class library. Represents a URL resource and has - * methods for pinging, adding, deleting, committing, optimizing and searching. - * - * Example Usage: - * - * ... - * $url = new SEOstats(); - * $url->setUrl('http://www.domain.tld'); //or explicitly new SEOstats('http://www.domain.tld') - * - * $url->Google()->getPageRank(); //returns the Google Toolbar PageRank value - - * $url->Google()->getSerps('query string'); //returns the first 100 results for a Google search for 'query string' - * $url->Google()->getSerps('query string', 500); //returns the first 500 results for a Google search for 'query string' - * - * //checks the first 500 results for a Google search for 'query string' for occurrences of the given domain name - * //and returns an array of matching URL's and their position within serps. - * $url->Google()->getSerps('query string', 500, 'http://www.domain.tld'); - * - * ... - * - * - */ -class SEOstats implements default_settings, services, api_keys, package -{ - const BUILD_NO = package::VERSION_CODE; - - protected static $_url; - - public function __construct($url = false) - { - if (false !== $url) { - self::setUrl($url); - } - } - - public function getUrl() - { - return self::$_url; - } - - public function setUrl($url) - { - self::$_url = $url; - } - - public function Alexa() - { - require_once SEOSTATSPATH . 'modules/seostats.alexa.php'; - return new SEOstats_Alexa(); - } - - public function Google() - { - require_once SEOSTATSPATH . 'modules/seostats.google.php'; - return new SEOstats_Google(); - } - - public function OpenSiteExplorer() - { - require_once SEOSTATSPATH . 'modules/seostats.opensiteexplorer.php'; - return new SEOstats_OpenSiteExplorer(); - } - - public function SEMRush() - { - require_once SEOSTATSPATH . 'modules/seostats.semrush.php'; - return new SEOstats_SEMRush(); - } - - public function Sistrix() - { - require_once SEOSTATSPATH . 'modules/seostats.sistrix.php'; - return new SEOstats_Sistrix(); - } - - public function Social() - { - require_once SEOSTATSPATH . 'modules/seostats.social.php'; - return new SEOstats_Social(); - } -} - -// URL-String Helper Class -require SEOSTATSPATH . 'helper/seostats.urlhelper.php'; -// HTTP Request Helper Class -require SEOSTATSPATH . 'helper/seostats.httprequest.php'; -// SEOstats Exception Class -require SEOSTATSPATH . 'helper/seostats.exception.php'; - -/* End of file seostats.php */ -/* Location: ./src/seostats.php */ \ No newline at end of file