[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/plugins/clickheat/libs/ -> click.php (source)

   1  <?php
   2  /**
   3   * ClickHeat : Enregistrement d'un clic suivi / Logging of a tracked click
   4   * 
   5   * @author Yvan Taviaud - LabsMedia - www.labsmedia.com
   6   * @since 27/10/2006
   7  **/
   8  
   9  /** First of all, check if we are inside PhpMyVisites */
  10  if (defined('INCLUDE_PATH'))
  11  {
  12      define('CLICKHEAT_ROOT', INCLUDE_PATH.'/libs/clickheat/');
  13      define('IS_PHPMV_MODULE', true);
  14      define('CLICKHEAT_CONFIG', INCLUDE_PATH.'/config/clickheat.php');
  15  }
  16  else
  17  {
  18      define('CLICKHEAT_ROOT', './');
  19      define('IS_PHPMV_MODULE', false);
  20      define('CLICKHEAT_CONFIG', CLICKHEAT_ROOT.'config/config.php');
  21  }
  22  
  23  /** Include config file */
  24  include CLICKHEAT_CONFIG;
  25  
  26  /** Check parameters */
  27  if (!isset($clickheatConf) || !isset($_GET['x']) || !isset($_GET['y']) || !isset($_GET['w']) || !isset($_GET['g']) || !isset($_GET['s']) || !isset($_GET['b']) || !isset($_GET['c']))
  28  {
  29      exit('Parameters or config error');
  30  }
  31  
  32  /** Check referers */
  33  if (is_array($clickheatConf['referers']))
  34  {
  35      if (!isset($_SERVER['HTTP_REFERER']))
  36      {
  37          exit('No domain in referer');
  38      }
  39      $referer = parse_url($_SERVER['HTTP_REFERER']);
  40      if (!in_array($referer['host'], $clickheatConf['referers']))
  41      {
  42          exit('Forbidden domain ('.$referer['host'].')');
  43      }
  44  }
  45  
  46  /** Check if group, site and browser are letters-only */
  47  $site = substr(preg_replace('/[^a-z_0-9\-]+/', '.', strtolower($_GET['s'])), 0, 50);
  48  $group = substr(preg_replace('/[^a-z_0-9\-]+/', '.', strtolower($_GET['g'])), 0, 50);
  49  if ($group === '')
  50  {
  51      exit('No group specified (clickHeatGroup empty)');
  52  }
  53  /** Check group */
  54  if (is_array($clickheatConf['groups']))
  55  {
  56      if (!in_array($group, $clickheatConf['groups']))
  57      {
  58          exit('Forbidden group ('.$group.')');
  59      }
  60  }
  61  $browser = preg_replace('/[^a-z]+/', '', strtolower($_GET['b']));
  62  if ($browser === '')
  63  {
  64      exit('Browser empty');
  65  }
  66  $final = ltrim($site.','.$group, ',');
  67  /** Limit file size */
  68  if ($clickheatConf['filesize'] !== 0)
  69  {
  70      if (file_exists($clickheatConf['logPath'].$final.'/'.date('Y-m-d').'.log') && filesize($clickheatConf['logPath'].$final.'/'.date('Y-m-d').'.log') > $clickheatConf['filesize'])
  71      {
  72          exit('Filesize reached limit');
  73      }
  74  }
  75  /** Logging the click */
  76  $f = fopen($clickheatConf['logPath'].$final.'/'.date('Y-m-d').'.log', 'a');
  77  if ($f === false)
  78  {
  79      /** Can't open the log, let's try to create the directory */
  80      if (!is_dir(rtrim($clickheatConf['logPath'], '/')))
  81      {
  82          if (!mkdir(rtrim($clickheatConf['logPath'], '/')))
  83          {
  84              exit('Cannot create log directory: '.$clickheatConf['logPath']);
  85          }
  86      }
  87      if (!is_dir($clickheatConf['logPath'].$final))
  88      {
  89          if (!mkdir($clickheatConf['logPath'].$final))
  90          {
  91              exit('Cannot create log directory: '.$clickheatConf['logPath'].$final);
  92          }
  93          if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] !== '')
  94          {
  95              $f = fopen($clickheatConf['logPath'].$final.'/url.txt', 'w');
  96              fputs($f, str_replace('debugclickheat', '', $_SERVER['HTTP_REFERER']).'>0>0>0');
  97              fclose($f);
  98          }
  99      }
 100      $f = fopen($clickheatConf['logPath'].$final.'/'.date('Y-m-d').'.log', 'a');
 101  }
 102  if ($f !== false)
 103  {
 104      if (isset($_COOKIE['clickheat-admin']))
 105      {
 106          echo 'OK, but click not logged as you selected it in the admin panel ("Log my clicks/Enregistrer mes clics")';
 107      }
 108      else
 109      {
 110          echo 'OK';
 111          fputs($f, ((int) $_GET['x']).'|'.((int) $_GET['y']).'|'.((int) $_GET['w']).'|'.$browser.'|'.((int) $_GET['c'])."\n");
 112      }
 113      fclose($f);
 114  }
 115  else
 116  {
 117      echo 'KO, file not writable';
 118  }
 119  ?>


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics