function launch() { global $configArray; global $interface; //Grab the tracking data $recordId = $_REQUEST['id']; $ipAddress = $_SERVER['REMOTE_ADDR']; $field856Index = isset($_REQUEST['index']) ? $_REQUEST['index'] : null; // Setup Search Engine Connection $class = $configArray['Index']['engine']; $url = $configArray['Index']['url']; $this->db = new $class($url); // Process MARC Data require_once ROOT_DIR . '/sys/MarcLoader.php'; $marcRecord = MarcLoader::loadMarcRecordByILSId($recordId); if ($marcRecord) { $this->marcRecord = $marcRecord; } else { PEAR_Singleton::raiseError(new PEAR_Error("Failed to load the MAC record for this title.")); } /** @var File_MARC_Data_Field[] $linkFields */ $linkFields = $marcRecord->getFields('856'); if ($linkFields) { $cur856Index = 0; foreach ($linkFields as $marcField) { $cur856Index++; if ($cur856Index == $field856Index) { //Get the link if ($marcField->getSubfield('u')) { $link = $marcField->getSubfield('u')->getData(); $externalLink = $link; } } } } $linkParts = parse_url($externalLink); //Insert into the purchaseLinkTracking table require_once ROOT_DIR . '/sys/BotChecker.php'; if (!BotChecker::isRequestFromBot()) { require_once ROOT_DIR . '/sys/ExternalLinkTracking.php'; $externalLinkTracking = new ExternalLinkTracking(); $externalLinkTracking->ipAddress = $ipAddress; $externalLinkTracking->recordId = $recordId; $externalLinkTracking->linkUrl = $externalLink; $externalLinkTracking->linkHost = $linkParts['host']; $result = $externalLinkTracking->insert(); } //redirects them to the link they clicked if ($externalLink != "") { header("Location:" . $externalLink); } else { PEAR_Singleton::raiseError(new PEAR_Error("Failed to load link for this record.")); } }
function __construct($ipAddress, $startTime) { global $configArray; if (!isset($configArray)) { die("You must load configuration before creating a tracker"); } global $interface; if (!isset($interface)) { die("You must setup the interface before creating a tracker"); } //Make sure that we don't track visits from bots if (BotChecker::isRequestFromBot() == true) { //$logger->log("Disabling logging because the request is from a bot", PEAR_LOG_DEBUG); $this->trackingDisabled = true; $this->finished = true; return; } //Check to see if analytics is enabled if (isset($configArray['System']['enableAnalytics']) && $configArray['System']['enableAnalytics'] == false) { $this->trackingDisabled = true; return; } //Check to see if we are in maintenance mode if (isset($configArray['System']['available']) && $configArray['System']['available'] == false) { $this->trackingDisabled = true; return; } $session = new Analytics_Session(); //disable error handler since the tables may not be installed yet. disableErrorHandler(); $sessionId = session_id(); $session->session_id = $sessionId; if ($session->find(true)) { $this->session = $session; if ($this->session->ip != $ipAddress) { $this->session->ip = $ipAddress; $this->doGeoIP(); } } else { $this->session = $session; $this->session->sessionStartTime = $startTime; $this->session->lastRequestTime = $startTime; $this->session->ip = $ipAddress; $this->doGeoIP(); $this->session->insert(); } $this->pageView = new Analytics_PageView(); $this->pageView->sessionId = $this->session->id; $this->pageView->pageStartTime = $startTime; $this->pageView->fullUrl = $_SERVER['REQUEST_URI']; enableErrorHandler(); }
function launch() { global $configArray; global $interface; $libraryName = $configArray['Site']['title']; //Grab the tracking data $store = urldecode(strip_tags($_GET['store'])); $recordId = $_REQUEST['id']; $ipAddress = $_SERVER['REMOTE_ADDR']; // Retrieve Full Marc Record $eContentRecord = new EContentRecord(); $eContentRecord->id = $recordId; if (!$eContentRecord->find(true)) { PEAR_Singleton::raiseError(new PEAR_Error('Record Does Not Exist')); } $title = str_replace("/", "", $eContentRecord->title); if ($eContentRecord->purchaseUrl == null) { switch ($store) { case "Tattered Cover": $purchaseLinkUrl = "http://www.tatteredcover.com/search/apachesolr_search/" . urlencode($title) . "?source=" . urlencode($libraryName); break; case "Barnes and Noble": $purchaseLinkUrl = "http://www.barnesandnoble.com/s/?title=" . urlencode($title) . "&source=" . urlencode($libraryName); break; case "Amazon": $purchaseLinkUrl = "http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=" . urlencode($title) . "&source=" . urlencode($libraryName); break; } } else { // Process MARC Data $purchaseLinkUrl = $eContentRecord->purchaseUrl; } //Do not track purchases from Bots require_once ROOT_DIR . '/sys/BotChecker.php'; if (!BotChecker::isRequestFromBot()) { require_once ROOT_DIR . '/sys/PurchaseLinkTracking.php'; $tracking = new PurchaseLinkTracking(); $tracking->ipAddress = $ipAddress; $tracking->recordId = 'econtentRecord' . $recordId; $tracking->store = $store; $insertResult = $tracking->insert(); } //redirects them to the link they clicked if ($purchaseLinkUrl != "") { header("Location:" . $purchaseLinkUrl); } else { PEAR_Singleton::raiseError(new PEAR_Error("Failed to load link for this title.")); } }
/** * * Determines if the current request appears to be from a bot */ public static function isRequestFromBot() { if (BotChecker::$isBot == null) { global $logger; global $timer; global $memCache; global $configArray; $userAgent = $_SERVER['HTTP_USER_AGENT']; $isBot = $memCache->get("bot_by_user_agent_" . $userAgent); if ($isBot === FALSE) { global $serverName; if (file_exists('../../sites/' . $serverName . '/conf/bots.ini')) { $fhnd = fopen('../../sites/' . $serverName . '/conf/bots.ini', 'r'); } elseif (file_exists('../../sites/default/conf/bots.ini')) { $fhnd = fopen('../../sites/default/conf/bots.ini', 'r'); } else { $logger->log("Did not find bots.ini file, cannot detect bots", PEAR_LOG_ERR); return false; } $isBot = false; while (($curAgent = fgets($fhnd, 4096)) !== false) { //Remove line separators $curAgent = str_replace("\r", '', $curAgent); $curAgent = str_replace("\n", '', $curAgent); if (strcasecmp($userAgent, $curAgent) == 0) { $isBot = true; break; } } fclose($fhnd); $memCache->set("bot_by_user_agent_" . $userAgent, $isBot ? 'TRUE' : 'FALSE', 0, $configArray['Caching']['bot_by_user_agent']); if ($isBot) { $logger->log("{$userAgent} is a bot", PEAR_LOG_DEBUG); } else { $logger->log("{$userAgent} is not a bot", PEAR_LOG_DEBUG); } BotChecker::$isBot = $isBot; } else { //$logger->log("Got bot info from memcache $isBot", PEAR_LOG_DEBUG); BotChecker::$isBot = $isBot === 'TRUE'; } $timer->logTime("Checking isRequestFromBot"); } return BotChecker::$isBot; }
function launch() { global $configArray; global $interface; //Grab the tracking data $recordId = $_REQUEST['id']; $ipAddress = $_SERVER['REMOTE_ADDR']; $itemId = $_REQUEST['itemId']; // Retrieve Full Marc Record $eContentRecord = new EContentRecord(); $eContentRecord->id = $recordId; if (!$eContentRecord->find(true)) { PEAR_Singleton::raiseError(new PEAR_Error('Record Does Not Exist')); } $eContentItem = new EContentItem(); $eContentItem->id = $itemId; if (!$eContentItem->find(true)) { PEAR_Singleton::raiseError(new PEAR_Error('Item Does Not Exist')); } $linkUrl = $eContentItem->link; $linkParts = parse_url($linkUrl); $title = str_replace("/", "", $eContentRecord->title); //Insert into the externalLinkTracking table require_once ROOT_DIR . '/sys/BotChecker.php'; if (!BotChecker::isRequestFromBot()) { require_once ROOT_DIR . '/sys/ExternalLinkTracking.php'; $externalLinkTracking = new ExternalLinkTracking(); $externalLinkTracking->ipAddress = $ipAddress; $externalLinkTracking->recordId = "econtentRecord" . $recordId; $externalLinkTracking->linkUrl = $linkUrl; $externalLinkTracking->linkHost = $linkParts['host']; $result = $externalLinkTracking->insert(); } //redirects them to the link they clicked if ($linkUrl != "") { header("Location:" . $linkUrl); } else { PEAR_Singleton::raiseError(new PEAR_Error("Failed to load link for this title.")); } }
function launch() { global $configArray; global $interface; //Grab the tracking data $store = urldecode(strip_tags($_GET['store'])); $recordId = $_REQUEST['id']; $ipAddress = $_SERVER['REMOTE_ADDR']; $field856Index = isset($_REQUEST['index']) ? $_REQUEST['index'] : null; $libraryName = $configArray['Site']['title']; // Setup Search Engine Connection $class = $configArray['Index']['engine']; $url = $configArray['Index']['url']; $this->db = new $class($url); if ($configArray['System']['debugSolr']) { $this->db->debug = true; } // Retrieve Full Marc Record if (!($record = $this->db->getRecord($recordId))) { PEAR_Singleton::raiseError(new PEAR_Error('Record Does Not Exist')); } $this->record = $record; $interface->assign('record', $record); $titleTerm = $record["title"]; $title = str_replace(":", " ", $titleTerm); $authorTerm = $record["auth_author"]; $author = str_replace("/", "", $authorTerm); if ($field856Index == null) { // Find the store in the database require_once ROOT_DIR . '/Drivers/marmot_inc/BookStore.php'; $storeDbObj = new BookStore(); $storeDbObj->storeName = $store; $storeDbObj->find(); if ($storeDbObj->N > 0) { $storeDbObj->fetch(); $purchaseLinkUrl = self::getPurchaseLinkForTitle($storeDbObj->link, $title, $author, $libraryName); } } else { // Process MARC Data require_once ROOT_DIR . '/sys/MarcLoader.php'; $marcRecord = MarcLoader::loadMarcRecordFromRecord($record); if ($marcRecord) { $this->marcRecord = $marcRecord; } else { PEAR_Singleton::raiseError(new PEAR_Error("Failed to load the MAC record for this title.")); } $linkFields = $marcRecord->getFields('856'); if ($linkFields) { $cur856Index = 0; foreach ($linkFields as $marcField) { $cur856Index++; if ($cur856Index == $field856Index) { //Get the link if ($marcField->getSubfield('u')) { $link = $marcField->getSubfield('u')->getData(); $purchaseLinkUrl = $link; } } } } } //Do not track purchases from Bots require_once ROOT_DIR . '/sys/BotChecker.php'; if (!BotChecker::isRequestFromBot()) { require_once ROOT_DIR . '/sys/PurchaseLinkTracking.php'; $tracking = new PurchaseLinkTracking(); $tracking->ipAddress = $ipAddress; $tracking->recordId = $recordId; $tracking->store = $store; $insertResult = $tracking->insert(); } //redirects them to the link they clicked if ($purchaseLinkUrl != "") { header("Location:" . $purchaseLinkUrl); } else { PEAR_Singleton::raiseError(new PEAR_Error("Failed to load the store information for this title.")); } }