[ 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/ -> Archive.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: Archive.functions.php 107 2006-10-02 09:40:54Z matthieu_ $

  11  
  12  
  13  
  14  /**

  15   * Sums values in the pages/groups/files two arrays of N dimensions that can be very different

  16   * 

  17   * @param array $a1

  18   * @param array $a2

  19   * 

  20   * @return array

  21   */
  22  function getPagGrpArrayMultiDimSum($a1, $a2)
  23  {
  24      if(!empty($a2) && is_array($a2))
  25      {
  26          foreach($a2 as $key=>$value)
  27          {
  28              if(!isset($a1[$key]))
  29              {
  30                  $a1[$key] = $value;
  31              }
  32              else
  33              {
  34                  if(substr($key, 0, 1) === 'c')
  35                  {
  36                      $a1[$key] = getPagGrpArrayMultiDimSum($value, $a1[$key]);
  37                  }
  38                  else
  39                  {
  40                      $a1[$key] =  sumArray($value, $a1[$key], true);
  41                  }
  42              }
  43          }
  44      }
  45      return $a1;
  46  }
  47  
  48  /**

  49   * Sum 2 arrays

  50   * 

  51   * @param array $a1

  52   * @param array $a2

  53   * 

  54   * @return array

  55   */
  56  function sumArray($a1, $a2, $specialCasePageExcludeSum = false)
  57  {
  58      return getArrayOneDimVeryVeryVerySpecialSum($a1, $a2, "sum", $specialCasePageExcludeSum);
  59  }
  60  
  61  /**

  62   * Performs a complete sum

  63   * 

  64   * @param int $a

  65   * @param int $b

  66   * 

  67   * @return int a+b

  68   */
  69  function sum($a, $b)
  70  {
  71      if(is_numeric($a) && is_numeric($b))
  72      {
  73          return $a + $b;
  74      }
  75      else
  76      {
  77          return $b;
  78      }
  79  }
  80  
  81  /**

  82   * Sums with a VeryVeryVery special arithmetic 

  83   * (!)

  84   * 

  85   * @param array $a1

  86   * @param array $a2

  87   * @param string VeryVeryVery special name of the VeryVeryVery special function to call for the sum

  88   * 

  89   * @return array The VeryVeryVery special array resulting from all the VeryVeryVery special process

  90   */
  91  function getArrayOneDimVeryVeryVerySpecialSum($a1, $a2, $veryVeryVerySpecialSumOperation, $specialCasePageExcludeSum = false)
  92  {
  93      if(!empty($a2) && is_array($a2))
  94      {
  95          foreach($a2 as $key=>$value)
  96          {
  97              if(
  98              $specialCasePageExcludeSum === false 
  99              ||
 100                  ($key != ARRAY_INDEX_IDPAGE
 101                  && $key != ARRAY_INDEX_IDCATEGORY)
 102              )
 103              {
 104                  if(!isset($a1[$key]))
 105                  {
 106                      $a1[$key] = $value;
 107                  }
 108                  else
 109                  {
 110                      $a1[$key] = call_user_func_array($veryVeryVerySpecialSumOperation, array($value, $a1[$key]));
 111                  }
 112              }
 113          }
 114      }
 115      return $a1;
 116  }
 117  
 118  function getNumberOfDaysBetween( $s_date1, $s_date2)
 119  {
 120      return sizeof(getDaysBetween($s_date1, $s_date2));
 121  }
 122  /**

 123   * returns an array containing the days between the 2 days

 124   * 

 125   * @param string $s_date1

 126   * @param string $s_date2

 127   * 

 128   * @return array 

 129   */
 130  function getDaysBetween($s_date1, $s_date2)
 131  {
 132      $date1 = new Date($s_date1);    
 133      $date2 = new Date($s_date2);
 134      
 135      $ts1 = $date1->getTimestamp();
 136      $ts2 = $date2->getTimestamp();
 137      
 138      //print("(".$date1->get()." > ".$date2->get().")");

 139  
 140      if($ts1 > $ts2)
 141      {        
 142          trigger_error("For the period statistic, Day 1 is AFTER Day 2 (".$date1->get()." > ".$date2->get()."). It's impossible, sorry.", E_USER_ERROR);
 143      }
 144      
 145      $return = array();
 146      while($ts1 <= $ts2)
 147      {
 148          $return[] = getDateFromTimestamp($ts1);
 149          
 150          $ts1 = mktime(23, 59, 59, date("m", $ts1), date("d", $ts1) + 1, date("Y", $ts1));
 151      }
 152      return $return;
 153  }
 154  
 155  
 156  /**

 157  * returns the value of a GET parameter $param in an URL query $urlQuery

 158  * 

 159  * @param string $urlQuery result of parse_url()['query'] and htmlentitied (& is &amp;)

 160  * @param string $param

 161  * 

 162  * @return string|bool param value (ex : keyword in google url) if found, false else

 163  */
 164  function getUrlParamValue($urlQuery, $param)
 165  {
 166      $refererQuery = '&amp;'.databaseEscape(trim(str_replace(array('%20'), ' ', '&amp;'.$urlQuery)));
 167      $word = '&amp;'.$param.'=';
 168      
 169  //    print($urlQuery." param=".$param);

 170      
 171      if( $off = strpos($refererQuery, $word))
 172      {
 173          $off += strlen($word); // &amp;q=

 174          $str = substr($refererQuery, $off);
 175          $len = strpos($str, '&amp;');
 176          if($len === false)
 177          {
 178              $len = strlen($str);
 179          }
 180          $toReturn = substr($refererQuery, $off, $len);
 181          return $toReturn;
 182      }
 183      else
 184      {
 185          return false;
 186      }
 187  }
 188  
 189  /**

 190   * Used in the sort function for N-dimensionnal arrays

 191   */
 192  function sortingAllPageInfo($a_id1,$a_id2)
 193  {
 194      @$elt1 = $a_id1[ARRAY_INDEX_LEVEL];
 195      @$elt2 = $a_id2[ARRAY_INDEX_LEVEL];
 196      return ($elt1 > $elt2) ? -1 : 1;
 197  }
 198  
 199  function sortingInterest($a_id1,$a_id2)
 200  {
 201      @$elt1 = $a_id1[0];
 202      @$elt2 = $a_id2[0];
 203      return ($elt1 > $elt2) ? -1 : 1;
 204  }
 205  
 206  function sortingPmv($a1,$a2)
 207  {
 208      @$elt1 = $a1['pmv_sum'];
 209      @$elt2 = $a2['pmv_sum'];
 210      return ($elt1 > $elt2) ? -1 : 1;
 211  }
 212  ?>


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