[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/include/ -> Logs.functions.php (source)

   1  <?php
   2  /* 

   3   * phpMyVisites : website statistics and audience measurements

   4   * Copyright (C) 2002 - 2006

   5   * http://www.phpmyvisites.net/ 

   6   * phpMyVisites is free software (license GNU/GPL)

   7   * Authors : phpMyVisites team

   8  */
   9  
  10  // $Id: Logs.functions.php 218 2007-06-02 07:15:48Z cmil $

  11  
  12  function isPrefixTag ($pageName) {
  13      $tabTag = split(",", PREFIX_ALL_TAG);
  14      $ret = false;
  15      foreach ($tabTag as $info) {
  16          if (substr($pageName, 0, strlen($info)) === $info) {
  17              $ret = true;
  18              break;
  19          }
  20      }
  21      return $ret;
  22  }
  23  
  24  function getPrefixTag ($pageName) {
  25      $tabTag = split(",", PREFIX_ALL_TAG);
  26      $ret = "";
  27      foreach ($tabTag as $info) {
  28          if (substr($pageName, 0, strlen($info)) === $info) {
  29              $ret = $info;
  30              break;
  31          }
  32      }
  33      return $ret;
  34  }
  35  
  36  function deletePrefixTag ($pageName) {
  37      $tabTag = split(",", PREFIX_ALL_TAG);
  38      $ret = $pageName;
  39      foreach ($tabTag as $info) {
  40          if (substr($pageName, 0, strlen($info)) === $info) {
  41              $ret = substr($pageName, strlen($info));
  42              break;
  43          }
  44      }
  45      return $ret;
  46      
  47  }
  48  
  49  function setCookieFromPear ($aPearCookie) {
  50      $v_secure = false;
  51      if (($aPearCookie['secure'] != null) && ($aPearCookie['secure'] == "true")) {
  52          $v_secure = true;
  53      }
  54      setcookie ($aPearCookie['name'], $aPearCookie['value'], strtotime($aPearCookie['expires']),
  55              $aPearCookie['path'], $aPearCookie['domain'], $v_secure);
  56  }
  57  
  58  function redirectToUrlIfNecessary()
  59  {
  60      $pageCompleteName = stripslashesPmv($_GET['pagename']);
  61      if ((isset($_GET['url'])) && ($_GET['url'] != "")) {
  62          $pageUrl = stripslashesPmv($_GET['url']);
  63      }
  64      else {
  65          $pageUrl = null;
  66      }
  67  
  68  //    if(substr($pageCompleteName, 0, 5) == PREFIX_FILES)

  69      if(isPrefixTag ($pageCompleteName))
  70      {
  71          if(DEBUG)
  72          {
  73              printDebug("=====================<br>Header() to file to download<br>=====================");
  74          }
  75          else
  76          {
  77              if ($pageUrl != null) {
  78                  if (defined(PMV_REWRITE_MODE) && (PMV_REWRITE_MODE == 'PEAR_REQUEST'))
  79                  {
  80                       // Debut version PEAR

  81                       setIncludePath();
  82                      require_once  INCLUDE_PATH."/libs/Request/Request.php";
  83                       
  84                       $a = &new HTTP_Request(str_replace("&amp;","&",$pageUrl));
  85                      $a->sendRequest();
  86      
  87                       foreach ($a->getResponseHeader() as $key => $value) {
  88                           if ($key != "transfer-encoding") { // IE does not support this parameter
  89                              header ($key.": ".$value);
  90                           }
  91                      }
  92                      $cookies = $a->getResponseCookies();
  93                      if($cookies)
  94                      {
  95                           foreach ($cookies as $value) 
  96                           {
  97                               setCookieFromPear($value);
  98                          }
  99                      }
 100                      print $a->getResponseBody();
 101                       exit;
 102                       // Fin version PEAR

 103                  }
 104                  else
 105                  {
 106                      header('Location:' . str_replace("&amp;","&",$pageUrl), false, 302);
 107                      exit;
 108                  }
 109              }
 110              else {
 111                  trigger_error("Error : There is no url to redirect", E_USER_ERROR);
 112              }
 113              exit;
 114          }
 115      }
 116  }
 117  
 118  /**

 119  * returns the hostname of the $ip

 120  * 

 121  * @param string $ip

 122  * 

 123  * @return string hostname

 124  */
 125  function getHost($ip)
 126  {
 127      return trim(strtolower(@gethostbyaddr($ip)));
 128  }
 129  
 130  
 131  /**

 132  * returns an ip which can be resolved, if possible

 133  * 

 134  * @return string ip 

 135  */
 136  function getIp() 
 137  {
 138      if(isset($_SERVER['HTTP_CLIENT_IP']) 
 139          && ($ip = getFirstIpFromList($_SERVER['HTTP_CLIENT_IP']))
 140          && strpos($ip, "unknown")===false 
 141          && getHost($ip) != $ip)
 142      {
 143          return $ip;
 144      }
 145      elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) 
 146          && $ip = getFirstIpFromList($_SERVER['HTTP_X_FORWARDED_FOR'])
 147          && isset($ip) && !empty($ip)
 148          && strpos($ip, "unknown")===false 
 149          && getHost($ip) != $ip)
 150      {
 151          return $ip;
 152      }
 153      elseif( isset($_SERVER['HTTP_CLIENT_IP'])
 154          && strlen( getFirstIpFromList($_SERVER['HTTP_CLIENT_IP']) ) != 0 )
 155      {
 156          return getFirstIpFromList($_SERVER['HTTP_CLIENT_IP']);
 157      }
 158      else if( isset($_SERVER['HTTP_X_FORWARDED_FOR']) 
 159          && strlen (getFirstIpFromList($_SERVER['HTTP_X_FORWARDED_FOR'])) != 0)
 160      {
 161          return getFirstIpFromList($_SERVER['HTTP_X_FORWARDED_FOR']);
 162      }
 163      else
 164      {
 165          return getFirstIpFromList($_SERVER['REMOTE_ADDR']);
 166      }
 167  }
 168  
 169  /**

 170  * returns first element of a comma separated list

 171  * 

 172  * @param string $ip

 173  * 

 174  * @return string first element before ','

 175  */
 176  function getFirstIpFromList($ip)
 177  {
 178      $p = strpos($ip, ',');
 179      if($p!==false)
 180      {
 181          return secureVar(substr($ip, 0, $p));
 182      }
 183      else
 184      {
 185          return secureVar($ip);
 186      }
 187  }
 188  
 189  /**

 190  * get the visitor os

 191  * 

 192  * @param string $userAgent

 193  * @param array $osList

 194  * 

 195  * @return string 

 196  */
 197  function getOs($userAgent)
 198  {
 199      for (@reset($GLOBALS['osNameToId']), $ok = false; 
 200          (list($key, $value) = @each($GLOBALS['osNameToId'])) && !$ok;)
 201      {
 202          if ($ok = ereg($key, $userAgent))
 203          {
 204              return $value;
 205          }
 206      }
 207      return 'UNK';
 208  }
 209  
 210  /**

 211  * returns continent of $country 

 212  * 

 213  * @param string $country isocode

 214  * @param array $coutryList

 215  * 

 216  * @return string continent (3 letters)

 217  */
 218  function getContinent($country)
 219  {
 220      if(isset($GLOBALS['countryList'][$country][0]))
 221      {
 222          return $GLOBALS['countryList'][$country][0];
 223      }
 224      else
 225      {
 226          return "unk";
 227      }
 228  }
 229  
 230  /**

 231  * get visitor country with both information : Hostname and BrowserLang

 232  * 

 233  * @param string $host

 234  * @param string $lang browser lang

 235  * 

 236  * @return string 

 237  */
 238  function getCountry($host, $lang)
 239  {
 240      if(isset($GLOBALS['ispCountryList'][$host]))
 241      {
 242          return $GLOBALS['ispCountryList'][$host];
 243      }
 244  
 245      // look for an existing domain

 246      $domain = substr($host, strrpos($host, '.') + 1);
 247      
 248      // if domain doesn't exist

 249      if(strlen($domain) != 2)
 250      {
 251          // look for the the last but one extension Ex : "ca" in ".ca.com"

 252          $host = substr($host, 0, strrpos($host, '.') );
 253          $domain = substr($host, strrpos($host, '.'));
 254      }
 255      
 256      if(isset($GLOBALS['countryList'][$domain][0]))
 257      {
 258          return $domain;
 259      }
 260      else
 261      {
 262          // try with the browser langage code

 263          
 264          // replace cs language (Serbia Montenegro country code) with czech country code

 265          $lang = str_replace('cs', 'cz', $lang);
 266          
 267          // replace sv language (El Salvador country code) with sweden country code

 268          $lang = str_replace('sv', 'se', $lang); 
 269          
 270          // replace fa language (Unknown country code) with Iran country code

 271          $lang = str_replace('fa', 'ir', $lang);
 272          
 273          // replace ja language (Unknown country code) with japan country code

 274          $lang = str_replace('ja', 'jp', $lang);
 275          
 276          // replace ko language (Unknown country code) with corée country code

 277          $lang = str_replace('ko', 'kr', $lang); 
 278          
 279          // replace he language (Unknown country code) with Israel country code

 280          $lang = str_replace('he', 'il', $lang);                  
 281                 
 282          // replace da language (Unknown country code) with Danemark country code

 283          $lang = str_replace('da', 'dk', $lang);            
 284                  
 285          
 286          // Ex: "fr"

 287          if(strlen($lang) == 2)
 288          {
 289              if(isset($GLOBALS['countryList'][$lang][0]))
 290              {
 291                  return $lang;
 292              }
 293          }
 294  
 295          // when comma

 296          $offcomma = strpos($lang, ',');
 297      
 298          if($offcomma == 2)
 299          {
 300              // in 'fr,en-us', keep first two chars

 301              $domain = substr($lang, 0, 2);
 302              if(isset($GLOBALS['countryList'][$domain][0]))
 303              {
 304                  return $domain;
 305              }
 306  
 307              // catch the second language Ex: "fr" in "en,fr"

 308              $domain = substr($lang, 3, 2);
 309              if(isset($GLOBALS['countryList'][$domain][0]))
 310              {
 311                  return $domain;
 312              }
 313          }
 314  
 315          // detect second code Ex: "be" in "fr-be"

 316          $off = strpos($lang, '-');
 317          if($off!==false)
 318          {
 319              $domain = substr($lang, $off+1, 2);
 320              
 321              if(isset($GLOBALS['countryList'][$domain][0]))
 322              {
 323                  return $domain;
 324              }
 325          }
 326          
 327          // catch the second language Ex: "fr" in "en;q=1.0,fr;q=0.9"

 328          if(preg_match("/^en;q=[01]\.[0-9],(?P<domain>[a-z]{2});/", $lang, $parts))
 329          {
 330              $domain = $parts['domain'];
 331  
 332              if(isset($GLOBALS['countryList'][$domain][0]))
 333              {
 334                  return $domain;
 335              }
 336          }
 337  
 338      }
 339      
 340      // unfortunately... unknown !

 341      return "xx";
 342  }
 343  
 344  /**

 345  * returns valid phpmv hostname extension (site.co.jp in fvae.VARG.ceaga.site.co.jp)

 346  * from the complete hostname

 347  * 

 348  * @param string $hostname

 349  * 

 350  * @return string

 351  */
 352  function getHostnameExt($hostname)
 353  {
 354      $extToExclude = array(
 355          'com', 'net', 'org', 'co'
 356      );
 357      
 358      $off = strrpos($hostname, '.');
 359      $ext = substr($hostname, $off);
 360  
 361      if(empty($off) || is_numeric($ext) || strlen($hostname) < 5)
 362      {
 363          return 'Ip';
 364      }
 365      else
 366      {
 367          $e = explode('.', $hostname);
 368          $s = sizeof($e);
 369          
 370          // if extension not correct

 371          if(isset($e[$s-2]) && in_array($e[$s-2], $extToExclude))
 372          {
 373              return $e[$s-3].".".$e[$s-2].".".$e[$s-1];
 374          }
 375          else
 376          {
 377              return $e[$s-2].".".$e[$s-1];
 378          }
 379      }
 380  }
 381  
 382  /**

 383  * get visitor browser 

 384  * 

 385  * @param string $userAgent

 386  */
 387  function getBrowserInfo($userAgent)
 388  {
 389      $browser = '';
 390      
 391      $info = array(
 392      'shortName' => 'unk',
 393      'longName' => '',
 394      'major_number' => '',
 395      'minor_number' => '',
 396      'version' => ''
 397      );
 398      
 399      foreach($GLOBALS['browsers'] as $key => $value) 
 400      {
 401          if(!empty($browser)) $browser .= "|";
 402          $browser .= $key;
 403      }
 404      
 405      $results = array();
 406      
 407      // added fix for Mozilla Suite detection

 408      if ((preg_match_all("/(mozilla)[\/\sa-z;.0-9-(]+rv:([0-9]+)([.0-9a-z]+)\) gecko\/[0-9]{8}$/i", $userAgent, $results)) 
 409      ||    (preg_match_all("/($browser)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results))
 410          )
 411       {
 412          $count = count($results[0])-1;
 413          
 414          // browser code

 415          $info['shortName'] = $GLOBALS['browsers'][strtolower($results[1][$count])];
 416          $info['longName'] = $GLOBALS['browsers'][strtolower($results[1][$count])];
 417          
 418          // majeur version number (7 in mozilla 1.7

 419          $info['major_number'] = $results[2][$count];
 420          
 421          // is an minor version number ? If not, 0

 422          $match = array();
 423          
 424          preg_match('/([.\0-9]+)?([\.a-z0-9]+)?/i', $results[3][$count], $match);
 425          
 426          if(isset($match[1])) 
 427          {
 428              // find minor version number (7 in mozilla 1.7, 9 in firefox 0.9.3)

 429              $info['minor_number'] = substr($match[1], 0, 2);
 430          } 
 431          else 
 432          {
 433              $info['minor_number'] = '.0';
 434          }
 435          
 436          $info['version'] = $info['major_number'] . $info['minor_number'];
 437      }    
 438      return $info;    
 439  }
 440  
 441  
 442  /**

 443  * records in the DB a category, and recursively records its parent if not saved before

 444  * 

 445  * @param string $categoryName complete name of the category to record. Ex : "g1>g2>g3" which parent is "g1>g2"

 446  * 

 447  * @return int idparent of the category saved

 448  */
 449  function recordDbCategory($categoryName)
 450  {
 451      //print("<br>$categoryName</br>");

 452      $level = substr_count($categoryName, CATEGORY_DELIMITER) + 1;
 453      printDebug("in category $categoryName := level : $level <br>".CATEGORY_DELIMITER);
 454      
 455      // "g3"

 456      $off = strrpos($categoryName, CATEGORY_DELIMITER);
 457      
 458      // adjust offset, if no '>' detected, we must begin at offset 0. 

 459      // If '>' detected, begin at offset+1

 460      ($off===false) ? $off=0 : $off+=1;
 461      
 462      $pageCategory = substr($categoryName, $off );
 463      // print("pageCategory : $pageCategory <br>");                                                                                      

 464      
 465      // "g1>g2"

 466      $parentName = substr($categoryName, 0,  strrpos($categoryName, CATEGORY_DELIMITER) );
 467      $parentLevel = $level - 1 ;
 468      
 469      // print("parentName : $parentName <br>");

 470      
 471      if($parentName === '')
 472      {
 473          $idParent = 0;
 474      }
 475      else
 476      {
 477          // try to select idParent category

 478          $r = query("SELECT idcategory
 479          FROM ".T_CATEGORY."
 480          WHERE complete_name = '$parentName'
 481          AND level = '$parentLevel'
 482          LIMIT 1");
 483          
 484          if(mysql_num_rows($r)>0)
 485          {
 486              $r = mysql_fetch_assoc($r);
 487              $idParent = $r['idcategory'];
 488          }
 489          else if($level == 1)
 490          {
 491              // save a new row with category info

 492              $r = query("INSERT INTO ".T_CATEGORY." 
 493                          (complete_name, name, level, idparent)
 494                          VALUES ('$categoryName', '$pageCategory', '1', '0')
 495                      ");
 496              
 497              return mysql_insert_id();        
 498          }
 499          else 
 500          {
 501              // saves the parent category name

 502              $idParent = recordDbCategory($parentName);
 503          }
 504      }    
 505      // save a new row with category info and idparent

 506      $r = query("INSERT INTO ".T_CATEGORY." 
 507                  (complete_name, name, level, idparent)
 508                  VALUES ('$categoryName', '$pageCategory', '$level', '$idParent')
 509          ");
 510      
 511      return mysql_insert_id();
 512  }
 513  
 514  /**

 515  * records the table 'page' if necessary and

 516  * create links to the page URL, links to the page category

 517  * 

 518  * @param string $pageName 

 519  * @param string $pageUrl complete page Url

 520  * @param string $pageCategory "g1>g2>g3>g4". No category is string '' and has idCategory = 0

 521  * 

 522  * @return array (idpage of the page saved, idpageurl of the url of the page saved)

 523  */
 524  function recordDbPage($pageName, $pageUrl, $pageCategory, $b_savePageUrlBecauseEntry)
 525  {
 526      if(strcmp($pageCategory,'')===0 || empty($pageCategory) || $pageCategory == '')
 527      {
 528          $categoryId = 0;
 529      }
 530      else
 531      {
 532          // select the category

 533          $r = query("SELECT idcategory
 534          FROM ".T_CATEGORY."
 535          WHERE complete_name = '$pageCategory'
 536          LIMIT 1
 537          ");
 538          
 539          if(mysql_num_rows($r)==0)
 540          {
 541              // save category

 542              $categoryId = recordDbCategory($pageCategory);
 543          }
 544          else
 545          {
 546              // category id

 547              $r = mysql_fetch_assoc($r);
 548              $categoryId = $r['idcategory'];
 549          }
 550      }
 551      // try to select page

 552      $r = query("SELECT idpage
 553                  FROM ".T_PAGE."
 554                  WHERE idcategory = '$categoryId'
 555                  AND name = '$pageName'
 556                  LIMIT 1
 557              ");
 558      
 559      if(mysql_num_rows($r)==0)
 560      {
 561          // saves page name & idcategory

 562          $r = query("INSERT INTO ".T_PAGE." 
 563                      (idcategory, name)
 564                      VALUES ('$categoryId', '$pageName')
 565                      ");
 566          $idPage = mysql_insert_id();
 567      }
 568      else
 569      {
 570          $r = mysql_fetch_assoc($r);
 571          $idPage = $r['idpage'];
 572      }
 573      
 574      $idPageUrl = 0;
 575      // if this is the first page view of the visitor, we save its url, because we could find some partners/newsletter parameter in it

 576      if($b_savePageUrlBecauseEntry)
 577      {
 578          $idPageUrl = recordDbPageUrl($pageUrl, $idPage);
 579      }    
 580      return array($idPage, $idPageUrl);
 581  }
 582  
 583  /**

 584  * saves in the DB the pageUrl of the page $idPage, if necessary

 585  * 

 586  * @param string $pageUrl

 587  * @param int $idPage

 588  * 

 589  * @return bool

 590  */
 591  function recordDbPageUrl($pageUrl, $idPage)
 592  {
 593      $r = query("SELECT idpage_url as id
 594                  FROM ".T_PAGE_MD5URL."
 595                  WHERE idpage = '$idPage'
 596                  AND md5url = '".md5($pageUrl)."'
 597                  LIMIT 1
 598      ");
 599      
 600      if(mysql_num_rows($r)==0)
 601      {
 602      /*    // search for the whole URL if already exists

 603              $r2 = query("SELECT idpage_url as id

 604                  FROM ".T_PAGE_URL."

 605                  WHERE url = '$pageUrl'

 606                  LIMIT 1

 607          ");

 608          if(mysql_num_rows($r2)==0)

 609          {

 610          */    
 611          // saves text URL

 612          $r3 = query("INSERT INTO ".T_PAGE_URL." (url)
 613                      VALUES ('$pageUrl')");
 614          $idInserted = mysql_insert_id();
 615          
 616          /*}

 617          else

 618          {

 619              $l= mysql_fetch_assoc($r2);

 620              $idInserted = $l['id'];

 621          }

 622          */
 623          
 624          // saves URL and links to table 'page'

 625          $r = query("INSERT INTO ".T_PAGE_MD5URL." (idpage, md5url, idpage_url)
 626                      VALUES ('$idPage', '".md5($pageUrl)."', '$idInserted')
 627                      ");
 628          return $idInserted;
 629      }
 630      
 631      $l = mysql_fetch_assoc($r);
 632      return $l['id'];
 633  }
 634  
 635  /**

 636  * saves a variable value & name if not saved before

 637  * and create the link in table 'link_vpv' 

 638  * 

 639  * @param string $varName

 640  * @param string|int $varValue

 641  * @param int $idLink_vp

 642  * 

 643  * @return bool

 644  */
 645  function recordDbVars($varName, $varValue, $idLink_vp)
 646  {
 647      // detect type of the variable, which determines where to store the value :

 648      // because there are 2 fields : int_value for int values and varchar_value for string values

 649      if(is_numeric($varValue))
 650      {
 651          $field = 'int_value';
 652          $field2 = 'varchar_value';
 653      }
 654      else
 655      {
 656          $field = 'varchar_value';
 657          $field2 = 'int_value';
 658      }
 659      
 660      // try to select vars id

 661      $r = query("SELECT idvars
 662                  FROM ".T_VARS."
 663                  WHERE name = '$varName'
 664                  AND $field = '$varValue'
 665                  LIMIT 1
 666      ");
 667      
 668      if(mysql_num_rows($r)==0)
 669      {
 670          // create var name + value

 671          $r = query("INSERT INTO ".T_VARS." (name, $field)
 672                      VALUES ('$varName', '$varValue')
 673                      ");
 674          $idVars = mysql_insert_id();
 675          
 676      }
 677      else
 678      {
 679          $r = mysql_fetch_assoc($r);
 680          $idVars = $r['idvars'];
 681      }
 682      
 683      $r = query("INSERT INTO ".T_LINK_VPV." (idlink_vp, idvars)" .
 684      " VALUES ('$idLink_vp', '$idVars')");
 685      
 686      return true;
 687  }
 688  
 689  /**

 690  * update the table link_vp

 691  * 

 692  * create the field if necessary with idvisit, idpage, ...

 693  * or update it if previously saved

 694  * 

 695  * @param int $idVisit

 696  * @param int $idPage

 697  * @param int $idPageRef

 698  * @param int $totalTime

 699  * 

 700  * @return int $idLink_vp

 701  */
 702  function recordDbLink_vp($idVisit, $idPage, $idPageRef, $totalTime) 
 703  {
 704      $r = query("INSERT INTO ".T_LINK_VP." (idvisit, idpage, idpage_ref, total_time_page_ref)" .
 705      " VALUES ('$idVisit', '$idPage', '$idPageRef', '$totalTime')");
 706      $idLink_vp = mysql_insert_id();
 707      
 708      return $idLink_vp;    
 709  }
 710  
 711  /**

 712  * saves all info concerning page & variables 

 713  * 

 714  * @param int $idVisit

 715  * @param int $idPage

 716  * @param int $idPageRef idpageref or 0 if page referer not found

 717  * @param int $timeDiffRef

 718  * @param array $a_vars contains variables names and values array( 'name' => 'value', ...)

 719  * 

 720  * @return array contains $idLink_vp created and $idPage used (and maybe created if page was not recorded before)

 721  */
 722  function recordDbInfoPage($idVisit, $idPage, $idPageRef, $timeDiffRef, $a_vars)
 723  {
 724      $idLink_vp = recordDbLink_vp($idVisit, $idPage, $idPageRef, $timeDiffRef);
 725      
 726      printDebug("===> Page info saved (idPage = ".$idPage.", idLink_vp = ".$idLink_vp.") <br>");
 727      
 728      // if there are variables to record

 729      if(is_array($a_vars))
 730      {
 731          foreach ($a_vars as $name => $value) 
 732          {
 733              if( strlen( $value ) < MAX_LENGTH_JAVASCRIPT_A_VARS_ARRAY )
 734              {
 735                  recordDbVars($name, $value, $idLink_vp);
 736              }
 737          }
 738      }
 739      
 740      return $idLink_vp;
 741  }
 742  
 743  /**

 744  * load image of phpmyvisites logo and calls performance log and footer display

 745  * 

 746  * @param string $logo name of the logo '1.png'

 747  * @param int $idSite

 748  * 

 749  * @return exit

 750  */
 751  function loadImage($logo='pixel.gif', $idSite)
 752  {
 753      if(empty($logo)) $logo = 'pixel.gif';
 754      
 755      $img = INCLUDE_PATH."/images/logos/".$logo;
 756      if(file_exists($img) && !DEBUG)
 757      {
 758          header("Content-type: image/".substr($logo, -3, 3));
 759          readfile($img);
 760          exit();
 761      }
 762      else
 763      {
 764          printDebug("<hr><b>IMAGE_HERE</b><hr>");
 765      }
 766      return;
 767  }
 768  
 769  /**

 770  * exit the script of the ip is recorded as an ip to exclude

 771  * or if the ip is in any range of ip to exclude for this site

 772  * 

 773  * @param int $ip2long ip2long version of ip

 774  * @param string $logo logo name '1.png' necessary if we exit the script

 775  * @param int $idSite

 776  * 

 777  * @return true or calls loadImage() and exit

 778  */
 779  function exitIfIpExcluded($ip2long, $logo, &$o_site)
 780  {
 781      printDebug("ip:".$ip2long);
 782      
 783      // look into the cookie for $a_ipToIgnore

 784      $a_ipToIgnore = $o_site->getIpArray();
 785      
 786      if(isset($a_ipToIgnore) 
 787      && sizeof($a_ipToIgnore) >= 1)
 788      {
 789          $i = 0;
 790          // is the ip excludable ?

 791          while($i < sizeof($a_ipToIgnore))
 792          {
 793              $ip1 = $a_ipToIgnore[$i][0];
 794              $ip2 = $a_ipToIgnore[$i][1];
 795  
 796              if($ip2long >= $ip1 && $ip2long <= $ip2
 797                  || $ip2long == $ip1
 798                  || $ip2long == $ip2 )
 799              {
 800                  printDebug("<b>=> Ip is excluded, exit</b><br>");
 801                  redirectToUrlIfNecessary();
 802                  loadImage($logo, $o_site->getId());
 803              }    
 804              $i++;
 805          }
 806      }
 807      
 808      printDebug("<b>=> Ip is not excluded</b><br>");
 809      return true;
 810  }
 811  
 812  /**

 813  * process urls removing params in siteInfo following information contained in $siteInfo

 814  * 

 815  * @param string $url url, even imcomplete

 816  * @param array $siteInfo array('params_choice' => 'all|except|only|none', 'params_exlude' => 'p1;p2', params_include_only => 'p1;p2' )

 817  * 

 818  * @return string url processed

 819  */
 820  function processParams($url, $siteInfo)
 821  {
 822      $parseUrl = parse_url($url);
 823      
 824      $a_varsToExclude = explode(';', $siteInfo['params_names']);
 825      $a_varsToInclude = explode(';', $siteInfo['params_names']);
 826      $choice = $siteInfo['params_choice'];
 827  
 828      // add PHPSESSID

 829      $a_toExclude[] = 'PHPSESSID';
 830      $a_toExclude[] = 'phpsessid';
 831      $a_toExclude[] = ''; // exclude empty var "&=&toto..."

 832      
 833      // always include these Id

 834      $a_toInclude = array();
 835      $a_toInclude[] = PARAM_URL_PARTNER;
 836      $a_toInclude[] = PARAM_URL_NEWSLETTER;
 837      
 838      $a_varsToExclude = array_merge( $a_varsToExclude, $a_toExclude);
 839      
 840      //if($choice == 'none')

 841      //{

 842      //    $toReturn = isset($parseUrl['path'])?$parseUrl['path']:'';

 843      //}

 844      //else 

 845      
 846      // if there is a query we keep only the accepted parameters in that query

 847      if(isset($parseUrl['query']))
 848      {
 849          $queryEx = explode('&amp;', $parseUrl['query']);
 850          $return = $parseUrl['path'] . '?';
 851  
 852          foreach($queryEx as $value)
 853          {
 854              $varAndValue = explode('=', $value);
 855          
 856              // include only parameters

 857              if( sizeof($varAndValue) == 2
 858                  && 
 859                  (
 860                      // keep only some parameters

 861                      ($choice == 'only' && in_array($varAndValue[0], $a_varsToInclude))
 862                      ||
 863                      // keep all except some parameters

 864                      ($choice == 'except' && !in_array($varAndValue[0], $a_varsToExclude))
 865                      ||
 866                      // keep all parameters, except those that are always excluded (phpsessid, etc.)

 867                      ($choice == 'all' && !in_array($varAndValue[0], $a_toExclude))
 868                      ||
 869                      // keep always some parameters (partner parameter, newsletter parameter)

 870                      in_array( $varAndValue[0], $a_toInclude)
 871                  )
 872              )
 873              {
 874                  $return .= $varAndValue[0].'='.$varAndValue[1].'&amp;';
 875                  
 876              }
 877          }
 878          
 879          // remove the last &amp;

 880          if(substr($return, strlen($return)-5) == '&amp;')
 881          {
 882              $toReturn = substr($return, 0, strlen($return)-5);
 883          }
 884          // or the finishing '?'

 885          else if(substr($return, strlen($return)-1) == '?')
 886          {
 887              $toReturn = substr($return, 0, strlen($return)-1);
 888          }
 889      }
 890      else
 891      {
 892          $toReturn = $url;
 893      }
 894      
 895      return $toReturn;
 896  }
 897  
 898  function displayPageWhenEmptyGet()
 899  {
 900      // random lang

 901      $lang =& Lang::getInstance();
 902      $lang->setRandomLang();
 903          
 904      print("<html>
 905              <head>
 906                  <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />
 907                  <meta name=\"description\" content=\"".$GLOBALS['lang']['head_description']."\" />
 908                  <meta name=\"keywords\" content=\"".$GLOBALS['lang']['head_keywords']."\" />
 909                  <meta name=\"copyright\" content=\"phpMyVisites\" />
 910                  <title>".$GLOBALS['lang']['head_titre']." = Websites statistics for ".Request::getHostUrl()."</title>
 911              </head>
 912              <body>");
 913      print("\n<h1>".$GLOBALS['lang']['logo_description']."</h1>");
 914      print("
 915              <p>Whatever you need, free counter, web counter ? Try <a href='http://www.phpmyvisites.us/'>Web site statistics</a> ! It's FREE :-)</p>
 916              <p>".$GLOBALS['lang']['contacts_merci3']."</p>
 917              <p>".$GLOBALS['lang']['contacts_trad1']."</p>
 918              <p>".$GLOBALS['lang']['contacts_merci2']."</p>
 919              <p>".str_replace("Matthieu Aubry", "<a href='http://giik.net/'>Matthieu</a> Aubry (<a href='http://giik.net/blog/'>blog</a>)",$GLOBALS['lang']['contacts_auteur'])."</p>
 920              
 921              
 922              <p>Statistics consist of seven parts : 
 923              ".$GLOBALS['lang']['menu_visites'].", 
 924              ".$GLOBALS['lang']['menu_pagesvues'].", 
 925              ".$GLOBALS['lang']['menu_suivi'].",
 926              ".$GLOBALS['lang']['menu_provenance'].",
 927              ".$GLOBALS['lang']['menu_configurations'].", 
 928              ".$GLOBALS['lang']['menu_affluents'].", 
 929              ".$GLOBALS['lang']['menu_bilansites'].", 
 930               available for the period 
 931              ".$GLOBALS['lang']['menu_jour'].", 
 932              ".$GLOBALS['lang']['menu_semaine'].",  
 933              ".$GLOBALS['lang']['menu_mois'].", 
 934              ".$GLOBALS['lang']['menu_annee']."
 935              </p>
 936              
 937              <p>phpMyVisites can for example gives these informations : 
 938              ".$GLOBALS['lang']['visites_statistiques'].", 
 939              ".$GLOBALS['lang']['visites_visites'].", 
 940              ".$GLOBALS['lang']['visites_uniques'].",  
 941              ".$GLOBALS['lang']['visites_pagesvues'].",  
 942              ".$GLOBALS['lang']['visites_pagesvisiteurs'].",  
 943              ".$GLOBALS['lang']['visites_pagesvisites'].", 
 944              ".$GLOBALS['lang']['visites_pagesvisitessign'].", 
 945              ".$GLOBALS['lang']['visites_tempsmoyen'].", 
 946              ".$GLOBALS['lang']['visites_tempsmoyenpv'].", 
 947              ".$GLOBALS['lang']['visites_tauxvisite'].",
 948              ".$GLOBALS['lang']['visites_average_visits_per_day']."
 949              </p>
 950              
 951              
 952              <p>phpMyVisites has a powerful administration tool. For example you can :</p>
 953              <ul>
 954              <li> ".$GLOBALS['lang']['admin_cookienavigateur']."</li>
 955              <li>".$GLOBALS['lang']['admin_ip_ranges']."</li>
 956              <li>".$GLOBALS['lang']['admin_get_a1']." / ".$GLOBALS['lang']['admin_get_a2']." / ".$GLOBALS['lang']['admin_get_a3']." / ".$GLOBALS['lang']['admin_get_a4']."</li>
 957              <li>".$GLOBALS['lang']['admin_nl_add']." / ".$GLOBALS['lang']['admin_partner_add']." / ".$GLOBALS['lang']['admin_site_add']." </li>
 958              <li>".$GLOBALS['lang']['admin_send_mail']." / ".$GLOBALS['lang']['admin_rss_feed']."</li>
 959              <li>".$GLOBALS['lang']['admin_server_info']."</li>
 960              </ul>
 961              ");
 962              
 963      print("\n<p>(Text in ".$GLOBALS['lang']['lang_libelle_en']." provided by ".$GLOBALS['lang']['auteur_nom'] .")
 964              <p>Thanks to ".Request::getHostUrl().", they have chosen phpMyVisites for their web analytics</p>");
 965      print("\n<p>".$GLOBALS['lang']['lang_libelle_en']."</p>
 966              <p><a href='http://www.phpmyvisites.us/'>".$GLOBALS['lang']['head_description'] ."</a></p>
 967               ");
 968      
 969      //displayLang();

 970      print("\n<h2>Is phpmyvisites THE solution?</h2>");
 971      print("\n <p>Free software is good for you!</p> <a href='http://www.phpmyvisites.us/'>Web Analytics</a></p>");
 972      
 973      //displayLang();

 974      print("\n<h2>Statistics demo</h2>
 975              <p>See statistics (if they are not protected by phpMyVisites administrator) for <a href=\"".Request::getHostUrl()."\">". Request::getHostUrl()."</a> ; you can also try <a href='http://www.phpmyvisites.us'>Internet Statistics</a></p>");
 976      
 977      //displayLang();

 978      
 979      print("<p>[ Today's date is ".date('r')." ]</p>
 980              </body>
 981             </html>");
 982  }
 983  
 984  function displayLang()
 985  {
 986      $keys = array_keys($GLOBALS['lang']);
 987      $stop = rand( 3, 20);
 988      $skeys = sizeof($keys);
 989      for ($i = 0; $i < $stop ; $i++)
 990      {
 991          $str = @$GLOBALS['lang'][$keys[rand(1,$skeys-1)]];
 992          if(is_string($str) && !ereg('%', $str)) print($str);
 993          print("\n<br>");        
 994      }
 995  }
 996  
 997  ?>


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