Exemplo n.º 1
0
 /**
  * @return array
  * @access public
  */
 function post()
 {
     $referer = $this->container['referer_orig'];
     if ($this->container['first_request'] && !empty($referer)) {
         if (!($ignoreRules = @file(POT_CONFIG_PATH . 'search_engines.ignore.ini'))) {
             return phpOpenTracker::handleError(sprintf('Cannot open "%s".', POT_CONFIG_PATH . 'search_engines.ignore.ini'), E_USER_ERROR);
         }
         if (!($matchRules = @file(POT_CONFIG_PATH . 'search_engines.match.ini'))) {
             return phpOpenTracker::handleError(sprintf('Cannot open "%s".', POT_CONFIG_PATH . 'search_engines.match.ini'), E_USER_ERROR);
         }
         $ignore = false;
         foreach ($ignoreRules as $ignoreRule) {
             if (preg_match(trim($ignoreRule), $referer)) {
                 $ignore = true;
                 break;
             }
         }
         if (!$ignore) {
             foreach ($matchRules as $matchRule) {
                 if (preg_match(trim($matchRule), $referer, $tmp)) {
                     $keywords = $tmp[1];
                 }
             }
             $searchEngineName = phpOpenTracker_Parser::match($referer, phpOpenTracker_Parser::readRules(POT_CONFIG_PATH . 'search_engines.group.ini'));
         }
         if (isset($keywords) && isset($searchEngineName) && $searchEngineName != $referer) {
             $this->db->query(sprintf("INSERT INTO %s\n                         (accesslog_id,\n                          search_engine, keywords)\n                  VALUES ('%d',\n                          '%s', '%s')", $this->config['plugins']['search_engines']['table'], $this->container['accesslog_id'], $this->db->prepareString($searchEngineName), $this->db->prepareString($keywords)));
             $this->container['referer'] = '';
             $this->container['referer_orig'] = '';
             $this->container['referer_id'] = 0;
         }
     }
     return array();
 }
Exemplo n.º 2
0
 /**
  * Parses a given string for Operating System and
  * User Agent information.
  *
  * @param  string $string
  * @return array
  * @access public
  * @static
  */
 function userAgent($string)
 {
     if (preg_match('#\\((.*?)\\)#', $string, $tmp)) {
         $elements = explode(';', $tmp[1]);
         $elements[] = $string;
     } else {
         $elements = array($string);
     }
     if ($elements[0] != 'compatible') {
         $elements[] = substr($string, 0, strpos($string, '('));
     }
     $result['operating_system'] = phpOpenTracker_Parser::match($elements, phpOpenTracker_Parser::readRules(POT_CONFIG_PATH . 'operating_systems.ini'));
     $result['user_agent'] = phpOpenTracker_Parser::match($elements, phpOpenTracker_Parser::readRules(POT_CONFIG_PATH . 'user_agents.ini'));
     return $result;
 }
Exemplo n.º 3
0
 /**
  * Returns a reference to phpOpenTracker's session container.
  *
  * The first call to this method during a request triggers, if
  * $parameters['init'] is not set to false, the generation of
  * the session container array.
  *
  * @param  optional array $parameters
  * @return array
  * @access public
  * @static
  */
 function &singleton($parameters = array())
 {
     static $isInitialized;
     $init = isset($parameters['init']) ? $parameters['init'] : false;
     $initAPI = isset($parameters['initAPI']) ? $parameters['initAPI'] : false;
     $initNoSetup = isset($parameters['initNoSetup']) ? $parameters['initNoSetup'] : false;
     $isInitialized = isset($isInitialized) ? $isInitialized : false;
     if ($initAPI) {
         $init = true;
         $isInitialized = false;
     } else {
         if ($initNoSetup) {
             $init = true;
         }
     }
     if ($isInitialized && !$init) {
         return $_SESSION['_phpOpenTracker_Container'];
     }
     if ($init && !$initAPI) {
         session_register('_phpOpenTracker_Container');
         $container =& $_SESSION['_phpOpenTracker_Container'];
     }
     if ($init && !$isInitialized && !$initNoSetup) {
         $config =& phpOpenTracker_Config::singleton(true);
         $db =& phpOpenTracker_DB::singleton();
         $parameters['client_id'] = isset($parameters['client_id']) ? $parameters['client_id'] : 1;
         $container['first_request'] = isset($container['first_request']) ? false : true;
         if ($container['first_request']) {
             $client_id_switched = false;
         } else {
             if ($container['client_id'] != $parameters['client_id']) {
                 $container['first_request'] = true;
                 $client_id_switched = true;
             }
         }
         $container['client_id'] = $parameters['client_id'];
         if ($container['first_request']) {
             if (function_exists('posix_getpid')) {
                 $container['accesslog_id'] = crc32(microtime() . posix_getpid());
             } else {
                 $container['accesslog_id'] = crc32(microtime() . session_id());
             }
             if (!$client_id_switched) {
                 if (!isset($parameters['host']) && !isset($parameters['ip_address'])) {
                     if (isset($_SERVER['REMOTE_ADDR'])) {
                         $container['ip_address'] = $_SERVER['REMOTE_ADDR'];
                         if (isset($_SERVER['REMOTE_HOST'])) {
                             $container['host_orig'] = $_SERVER['REMOTE_HOST'];
                         } else {
                             if ($config['resolve_hostname']) {
                                 $container['host_orig'] = gethostbyaddr($container['ip_address']);
                             } else {
                                 $container['host_orig'] = $container['ip_address'];
                             }
                         }
                     } else {
                         $container['host_orig'] = '';
                         $container['ip_address'] = '';
                     }
                 } else {
                     $container['host_orig'] = isset($parameters['host']) ? $parameters['host'] : '';
                     $container['ip_address'] = isset($parameters['ip_address']) ? $parameters['ip_address'] : '';
                 }
                 $container['host'] = $container['host_orig'];
                 if ($config['group_hostnames']) {
                     $container['host'] = phpOpenTracker_Parser::hostname($container['host']);
                 }
                 if (isset($parameters['user_agent'])) {
                     $container['user_agent_orig'] = $parameters['user_agent'];
                 } else {
                     $container['user_agent_orig'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
                 }
                 if ($config['group_user_agents']) {
                     $container = array_merge($container, phpOpenTracker_Parser::userAgent($container['user_agent_orig']));
                 } else {
                     $container['operating_system'] = 'Not identified';
                     $container['user_agent'] = $container['user_agent_orig'];
                 }
                 $container['host_id'] = $db->storeIntoDataTable($config['hostnames_table'], $container['host']);
                 $container['operating_system_id'] = $db->storeIntoDataTable($config['operating_systems_table'], $container['operating_system']);
                 $container['user_agent_id'] = $db->storeIntoDataTable($config['user_agents_table'], $container['user_agent']);
             }
             if (isset($parameters['referer'])) {
                 $container['referer_orig'] = $parameters['referer'];
             } else {
                 $container['referer_orig'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
             }
             $container['referer_orig'] = urldecode($container['referer_orig']);
             if ($config['clean_referer_string']) {
                 $container['referer'] = preg_replace('/(\\?.*)/', '', $container['referer_orig']);
             } else {
                 $container['referer'] = $container['referer_orig'];
             }
             if (!empty($container['referer'])) {
                 $container['referer'] = str_replace('http://', '', $container['referer']);
             }
             $container['referer_id'] = $db->storeIntoDataTable($config['referers_table'], $container['referer']);
         } else {
             $container['last_document'] = $container['document'];
         }
         $container['document_url'] = isset($parameters['document_url']) ? $parameters['document_url'] : urldecode($_SERVER[$config['document_env_var']]);
         if ($config['clean_query_string']) {
             $container['document_url'] = preg_replace('/(\\?.*)/', '', $container['document_url']);
         } else {
             $filters = array_merge($config['get_parameter_filter'], array(session_name()));
             foreach ($filters as $filter) {
                 $container['document_url'] = preg_replace('#\\?' . $filter . '=.*$|&' . $filter . '=.*$|' . $filter . '=.*&#msiU', '', $container['document_url']);
             }
         }
         $container['document'] = isset($parameters['document']) ? $parameters['document'] : $container['document_url'];
         $container['document_id'] = $db->storeIntoDataTable($config['documents_table'], $container['document'], $container['document_url']);
         $container['timestamp'] = isset($parameters['timestamp']) ? $parameters['timestamp'] : time();
         $isInitialized = true;
     }
     return $container;
 }