Advertisement
Guest User

hook_boot

a guest
Aug 5th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Implements hook_help.
  4.  *
  5.  * Displays help and module information.
  6.  *
  7.  * @param path
  8.  *   Which path of the site we're using to display help
  9.  * @param arg
  10.  *   Array that holds the current path as returned from arg() function
  11.  */
  12. function site_visitors_help($path, $arg) {
  13.     switch ($path) {
  14.     case "admin/help#site_visitors":
  15.         return '<p>' . t("Displays links to nodes created on this date") . '</p>';
  16.         break;
  17.     }
  18. }
  19.  
  20. /**
  21.  * Implements hook_init().
  22.  */
  23. function site_visitor_boot() {
  24.     site_visitors_insert();
  25. }
  26.  
  27. /**
  28.  * Custom visitor function.
  29.  *
  30.  * Insert IP Address, URL to the database
  31.  *
  32.  * @return
  33.  *   A result set of the targeted posts.
  34.  */
  35. function site_visitors_insert(){
  36.     $tracker = array(
  37.         'database' => 'c1tracker',
  38.         'username' => 'c1tracker',
  39.         'password' => 'NdA8A5SXcz7s',
  40.         'host' => 'localhost',
  41.         'driver' => 'mysql',
  42.     );
  43.  
  44.     Database::addConnectionInfo('tracker', 'default', $tracker);
  45.     db_set_active('tracker');
  46.  
  47.     //This should be put above html tag in html.tpl.php
  48.     /*
  49.     <?php
  50.     $time = microtime();
  51.     $time = explode(' ', $time);
  52.     $time = $time[1] + $time[0];
  53.     $start = $time;
  54.     ?>
  55.     */
  56.  
  57.     //This code requires the code above to compute the start time. This will compute the total page load.
  58.     $time = microtime();
  59.     $time = explode(' ', $time);
  60.     $time = $time[1] + $time[0];
  61.     $finish = $time;
  62.     $total_time = round(($finish - $start), 4);
  63.     $t = $total_time;
  64.     //$url = $_GET['url'];
  65.     $url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  66.     $current_ip = $_SERVER['REMOTE_ADDR'];
  67.     $user_agent = $_SERVER['HTTP_USER_AGENT'];
  68.     $date = date("Y-m-d");
  69.     $time =  date("h:i:s");
  70.  
  71.     function is_bot()
  72.     {
  73.         $botlist = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
  74.         "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
  75.         "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
  76.         "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
  77.         "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
  78.         "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
  79.         "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
  80.         "Butterfly","Twitturls","Me.dium","Twiceler");
  81.        
  82.         foreach($botlist as $bot)
  83.         {
  84.             if(strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
  85.             return true;
  86.         }
  87.     return false;
  88.     }
  89.  
  90.     if (is_bot())
  91.         $isbot = 1;
  92.     else
  93.         $isbot = 0;
  94.  
  95.     db_insert('ap_visits')
  96.         ->fields(array(
  97.             'id' => NULL,
  98.             'length' => $t,
  99.             'url' => $url,
  100.             'current_ip' => $current_ip,
  101.             'user_agent' => $user_agent,
  102.             'date_start' => date("Y-m-d H:i:s"),
  103.             'is_bot' => $isbot,
  104.             'is_logout' => 0
  105.         ))
  106.         ->execute();
  107.      
  108.     db_set_active();
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement