?
Path : /home/admin/public_html/old/administrator/components/com_coalawebtraffic/helpers/ |
Current File : /home/admin/public_html/old/administrator/components/com_coalawebtraffic/helpers/coalawebbot.php |
<?php /** * @package Joomla * @subpackage com_coalawebtraffic * @author Steven Palmer * @author url http://coalaweb.com * @author email support@coalaweb.com * @license GNU/GPL, see /files/en-GB.license.txt * @copyright Copyright (c) 2016 Steven Palmer All rights reserved. * * CoalaWeb Traffic is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ defined('_JEXEC') or die('Restricted access'); class CoalaWebBot { private $_agent = ''; private $_bot_name = ''; private $_version = ''; const BOT_UNKNOWN = 'Unknown'; const VERSION_UNKNOWN = 'Unknown'; const BOT_GOOGLEBOT = 'GoogleBot'; const BOT_SLURP = 'Yahoo! Slurp'; const BOT_MSNBOT = 'MSN Bot'; const BOT_BINGBOT = 'Bing Bot'; public function __construct($userAgent = "") { $this->reset(); if ($userAgent != "") { $this->setUserAgent($userAgent); } else { $this->determine(); } } /** * Reset all properties */ public function reset() { $this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; $this->_bot_name = self::BOT_UNKNOWN; $this->_version = self::VERSION_UNKNOWN; } /** * Check to see if the specific bot is valid * * @param string $botName * @return bool True if the bot is the specified bot */ function isBot($botName) { return (0 == strcasecmp($this->_bot_name, trim($botName))); } /** * The name of the bot. All return types are from the class contants * * @return string Name of the bot */ public function getBot() { return $this->_bot_name; } /** * Set the name of the bot * * @param string $bot string The name of the Bot * * @return void */ public function setBot($bot) { $this->_bot_name = $bot; } /** * The version of the Bot * * @return string Version of the bot (will only contain alpha-numeric characters and a period) */ public function getVersion() { return $this->_version; } /** * Set the version of the Bot * * @param string $version The version of the Bot * * @return void */ public function setVersion($version) { $this->_version = preg_replace('/[^0-9,.,a-z,A-Z-]/', '', $version); } /** * Get the user agent value in use to determine the Bot * * @return string The user agent from the HTTP header */ public function getUserAgent() { return $this->_agent; } /** * Set the user agent value (the construction will use the HTTP header value - this will overwrite it) * * @param string $agent_string The value for the User Agent */ public function setUserAgent($agent_string) { $this->reset(); $this->_agent = $agent_string; $this->determine(); } /** * Protected routine to calculate and determine what the bot is in use */ protected function determine() { $this->checkBots(); } /** * Protected routine to determine the bot type * * @return boolean True if the bot was detected otherwise false */ protected function checkBots() { return ( $this->checkBotGoogleBot() || $this->checkBotMSNBot() || $this->checkBotBingBot() || $this->checkBotSlurp() ); } /** * Determine if the bot is the GoogleBot or not (last updated 1.7) * * @return boolean True if the bot is the GoogletBot otherwise false */ protected function checkBotGoogleBot() { if (stripos($this->_agent, 'googlebot') !== false) { $aresult = explode('/', stristr($this->_agent, 'googlebot')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); $this->setVersion(str_replace(';', '', $aversion[0])); $this->_bot_name = self::BOT_GOOGLEBOT; return true; } } return false; } /** * Determine if the bot is the MSNBot or not (last updated 1.9) * * @return boolean True if the bot is the MSNBot otherwise false */ protected function checkBotMSNBot() { if (stripos($this->_agent, "msnbot") !== false) { $aresult = explode("/", stristr($this->_agent, "msnbot")); if (isset($aresult[1])) { $aversion = explode(" ", $aresult[1]); $this->setVersion(str_replace(";", "", $aversion[0])); $this->_bot_name = self::BOT_MSNBOT; return true; } } return false; } /** * Determine if the bot is the BingBot or not (last updated 1.9) * * @return boolean True if the bot is the BingBot otherwise false */ protected function checkBotBingBot() { if (stripos($this->_agent, "bingbot") !== false) { $aresult = explode("/", stristr($this->_agent, "bingbot")); if (isset($aresult[1])) { $aversion = explode(" ", $aresult[1]); $this->setVersion(str_replace(";", "", $aversion[0])); $this->_bot_name = self::BOT_BINGBOT; return true; } } return false; } /** * Determine if the bot is the Yahoo! Slurp Robot or not (last updated 1.7) * * @return boolean True if the bot is the Yahoo! Slurp Robot otherwise false */ protected function checkBotSlurp() { if (stripos($this->_agent, 'slurp') !== false) { $aresult = explode('/', stristr($this->_agent, 'Slurp')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); $this->setVersion($aversion[0]); $this->_bot_name = self::BOT_SLURP; return true; } } return false; } }