[ 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/ -> Request.class.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: Request.class.php 212 2007-04-09 18:38:48Z cmil $

  11  require_once  INCLUDE_PATH . "/core/include/common.functions.php";
  12  
  13  class Request
  14  {
  15      var $site;
  16      var $date;
  17      var $period;
  18      var $mod;
  19      
  20      
  21      var $idToUse;// pages details, foolow up, etc.

  22      
  23      var $idDetails; // details for referers zoom

  24      var $methodName; // used for all data arrays

  25      var $offset; //offset for referers

  26      
  27  	function Request()
  28      {
  29          $this->loadModuleName();
  30          $this->loadSiteId();
  31          
  32          $this->loadDate();
  33          $this->loadPeriod();
  34          $this->loadActionName();
  35          
  36          $this->loadIdDetails();
  37          $this->loadMethodName();
  38          
  39          $this->loadOffset();
  40          
  41          
  42          $this->loadCategoryAsked();
  43          $this->loadIdToUse();
  44          
  45          $this->loadAdminSite();
  46          $this->loadAdminNewsletter();
  47          $this->loadAdminUser();
  48          $this->loadAdminPartner();
  49          
  50          $this->loadContinentZoom();
  51          
  52          $pagesPercentLimit = 50;
  53          $keywordPercentLimit = $searchEnginePercentLimit = $sitePercentLimit =  
  54                                          $partnerPercentLimit =  $newsletterPercentLimit = 100;
  55          $defaultOrder = 'sum.desc';
  56          $nolimit = 0;
  57          $this->sorting_percent_limit_and_population_index = array(
  58              // parameter name => array( percent default limit value, all sums array index for this parameter, default sort)

  59              'a_int_sort'         => array( 100 ,                 'int',     $defaultOrder),
  60              'a_pag_sort'         => array( $pagesPercentLimit,     'pag',    $defaultOrder),
  61              'a_entry_sort'         => array( $pagesPercentLimit,     'entry','entry.desc'),
  62              'a_exit_sort'        => array( $pagesPercentLimit,     'exit',    'exit.desc'),
  63              'a_singlepage_sort'    => array( $pagesPercentLimit,     'singlepage',    'singlepage.desc'),
  64              'a_sumtime_sort'    => array( $pagesPercentLimit,     'sumtime',    'sumtime.desc'),
  65              'a_keyword_sort'     => array( $keywordPercentLimit, 'keyword',    $defaultOrder),
  66              'a_searchengine_sort' => array( $searchEnginePercentLimit, 'searchengine', $defaultOrder),
  67              'a_site_sort'         => array( $sitePercentLimit, 'site', $defaultOrder),
  68              'a_partner_sort'     => array( $partnerPercentLimit, 'partner', $defaultOrder),
  69              'a_newsletter_sort' => array( $newsletterPercentLimit, 'newsletter', $defaultOrder),
  70              'a_type_sort'         => array( $nolimit, 'type', $defaultOrder), // referer type
  71          );
  72          // ==> see $this->arraySumInfo in DataModel

  73          
  74          foreach($this->sorting_percent_limit_and_population_index as $name => $info)
  75          {
  76              $this->loadArraySort($name, $info[2]);
  77          }
  78                  
  79          // lang other => mod = otherlanguage

  80          if($this->getLang() === 'other')
  81          {
  82              $this->mod = 'other_language';
  83          }
  84          
  85          // if asked for mod=view_

  86          if(    $this->mod == 'view_sites_summary' 
  87              && $this->getSiteId() != -1)
  88          {
  89              $this->mod = 'view_visits';
  90          }
  91          
  92          if($this->getSiteId() === -1 
  93              && Request::isCurrentModuleAViewModule()
  94              && $this->mod != 'view_pdf'
  95              && $this->mod != 'view_pdf_v2'
  96              && $this->mod != 'view_rss' 
  97              )
  98          {
  99              $this->mod = 'view_sites_summary';
 100              $this->site = 1;
 101              $this->site_index = -1;
 102          } 
 103          elseif($this->getSiteId() === -1) 
 104          {
 105              $this->site = 1;
 106              $this->site_index = -1;
 107          }
 108          $this->crontabAllowed = false;
 109      }
 110      
 111      /**

 112       * Singleton

 113       */
 114      function &getInstance()
 115      {
 116          static $instance;
 117          if (!isset($instance)){
 118              $c = __CLASS__;
 119              $instance = new $c();
 120          }
 121          return $instance;
 122          
 123      }
 124      
 125  	function isPhpmvLogModule()
 126      {
 127          // quick hack...

 128          return isset($GLOBALS['currentModuleIsLogModule']) && $GLOBALS['currentModuleIsLogModule']; 
 129      }
 130  	function setCrontabAllowed()
 131      {
 132          $this->crontabAllowed = true;
 133      }
 134  	function isCrontabAllowed()
 135      {
 136          return $this->crontabAllowed;
 137      }
 138      function getErrorLogin()
 139      {
 140          return getRequestVar( 'error_login', 0, 'int');
 141      }
 142  	function getConfirmedState()
 143      {
 144          return getRequestVar( 'confirmed', 0, 'int');
 145      }
 146      
 147  	function getArrayInfoSort($allSumInfo)
 148      {
 149          foreach($this->sorting_percent_limit_and_population_index as $param => $info)
 150          {
 151              $sorted[$info[1]] = $this->getArraySort($param, $allSumInfo[$info[1]]);
 152          }
 153          return $sorted;
 154      }
 155      
 156  	function getArraySort($name, $totalPopulation)
 157      {
 158          $sort = $this->$name;
 159          
 160          $sort = explode('.', $sort);
 161          $sorting_index = $sort[0];
 162          $sorting_order = $sort[1];
 163          $sorting_detail = isset($sort[2])?$sort[2]:'';
 164          $sorting_limit = isset($sort[3]) ? $sort[3] : (ALL_POPULATION ? 0 : $totalPopulation);
 165          
 166          //print("$name : total= $totalPopulation <br>");

 167          if(!isset($sort[4]))
 168          {
 169              $sorting_percent_limit = (ALL_POPULATION ? 0 : $this->sorting_percent_limit_and_population_index[$name][0]);
 170          }
 171          else
 172          {
 173              $sorting_percent_limit = $sort[4];
 174          }
 175  
 176          
 177          $a = array(
 178              0 => $sorting_index . "." . $sorting_order,
 179              1 => $sorting_index,
 180              2 => $sorting_order,
 181              3 => $sorting_detail,
 182              4 => $sorting_limit . "." . $sorting_percent_limit,
 183              5 => $sorting_limit,
 184              6 => $sorting_percent_limit,
 185              7 => $totalPopulation . "." . $this->sorting_percent_limit_and_population_index[$name][0],
 186              8 => $totalPopulation,
 187              9 => $this->sorting_percent_limit_and_population_index[$name][0],
 188              
 189              );
 190  
 191          return $a;
 192      }
 193      
 194  	function loadCategoryAsked()
 195      {
 196          $this->c_id_zoom = getRequestVar('c_id_zoom', '', 'string');
 197      }
 198  	function getCategoryAsked()
 199      {
 200          return $this->c_id_zoom;
 201      }
 202      
 203  	function moduleIsNotAStrangeModule()
 204      {
 205          if(@$_REQUEST['mod'] != 'view_pages_details'
 206              && @$_REQUEST['mod'] != 'view_visits_rss'
 207              && @$_REQUEST['mod'] != 'view_data_array'
 208              && @$_REQUEST['mod'] != 'view_graph')
 209          {
 210              return true;
 211          }
 212          
 213          return false;
 214      }
 215      
 216  	function isCategoryZoom()
 217      {
 218          return empty($this->c_id_zoom)?
 219                      false:
 220                      true;
 221      }
 222      
 223  	function getHostUrl()
 224      {
 225          return (SECURE_SERVER_HTTPS?"https":"http")."://".$_SERVER['HTTP_HOST'];
 226      }
 227      
 228  	function getScriptName()
 229      {
 230          $phpmv_url_chemin = '';
 231          if(isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO'])) 
 232          { 
 233              $phpmv_url_chemin = $_SERVER['PATH_INFO'];
 234          } 
 235          else if(isset($_SERVER['REQUEST_URI']) && !empty($_SERVER['REQUEST_URI']) ) 
 236          {
 237              if( ($pos = strpos($_SERVER['REQUEST_URI'], "?")) !== false ) 
 238              {
 239                  $phpmv_url_chemin = substr($_SERVER['REQUEST_URI'], 0, $pos);
 240              } 
 241              else 
 242              {
 243                  $phpmv_url_chemin = $_SERVER['REQUEST_URI'];
 244              }
 245          } 
 246          
 247          if(empty($phpmv_url_chemin))
 248          {
 249              $phpmv_url_chemin = $_SERVER['SCRIPT_NAME'];
 250          }
 251          return $phpmv_url_chemin;
 252      }
 253      
 254  	function getCurrentCompletePath()
 255      {
 256          
 257          $phpmv_url_chemin= Request::getHostUrl() . Request::getScriptName();
 258          return substr($phpmv_url_chemin, 0, strrpos($phpmv_url_chemin, '/'));
 259      }
 260      
 261  	function getPhpmvRoot()
 262      {
 263          if (SECURE_SERVER_HTTPS)
 264          {
 265              $root = "https://";
 266          }
 267          else
 268          {
 269              $root = "http://";
 270          }
 271          $root .= $_SERVER['HTTP_HOST'] .
 272                                          rtrim(dirname($_SERVER['PHP_SELF']), '/\\') .
 273                                          "/";
 274          return $root;
 275      }
 276      
 277  	function getCurrentCompleteUrl()
 278      {
 279          return Request::getCurrentCompletePath() . "/" . Request::getCurrentUrl();
 280      }
 281      
 282  	function getCurrentUrl()
 283      {
 284          $toUse = Request::getScriptName();
 285          $return = substr($toUse, 1 -  strlen($toUse) + strrpos($toUse, "/"));
 286          
 287          if(isset($_SERVER['QUERY_STRING'])
 288              && !empty($_SERVER['QUERY_STRING']))
 289          {
 290              $return .= "?".$_SERVER['QUERY_STRING'];
 291          }
 292          
 293          // not '//' in url

 294          if($return == '/')
 295          {
 296              $return = '';
 297          }
 298          else
 299          {
 300              // case servers that give path/page for return instead of page only! too bad

 301              if(ereg('/', $return))
 302              {
 303                  $return = substr( $return, strrpos($return, "/")+1);
 304              }
 305          }
 306          //print($return);

 307          //exit;

 308          return $return;
 309      }
 310      /**

 311       * 

 312       * @param string|array $a_paramExclude

 313       * 

 314       * @return string

 315       */
 316  	function getUrl($a_paramExclude = '')
 317      {
 318          // $v_param = $a_paramExclude;

 319          if(!is_array($a_paramExclude))
 320          {
 321              $a_paramExclude = array ( $a_paramExclude);
 322          }
 323          
 324          // var_dump($a_paramExclude);

 325          // print"<br>\n";

 326          
 327          $param = array(
 328              'site',
 329              'date',
 330              'period',
 331              'mod',
 332              'action'
 333              );
 334          
 335          // special case for pages details, we conserve the sort vars but not the mod vars

 336          if($a_paramExclude[0] == 'mod_sort_means_details')
 337          {
 338              $param[] = 'a_pag_sort';
 339              $param[] = 'a_entry_sort';
 340              $param[] = 'a_exit_sort';
 341              $param[] = 'a_sumtime_sort';
 342              $param[] = 'a_singlepage_sort';
 343          }
 344          
 345          
 346          // remove mod from url

 347          if($a_paramExclude[0] == 'mod_sort_means_details')
 348          {
 349              unset($param[array_search('mod', $param)]);
 350          }
 351          
 352          // add info relative to offset / details for ajax

 353          if($a_paramExclude[0] == 'offset' || $a_paramExclude[0] == 'a_int_sort')
 354          {
 355              $param[] = 'method_name';
 356              $param[] = 'id_details';
 357          }
 358          
 359          if($a_paramExclude[0] == 'offset')
 360          {
 361              $param[] = 'a_keyword_sort';
 362              $param[] = 'a_searchengine_sort';
 363              $param[] = 'a_site_sort'; 
 364              $param[] = 'a_partner_sort';
 365              $param[] = 'a_newsletter_sort';
 366              $param[] = 'a_int_sort';
 367              $param[] = 'a_type_sort';
 368          }
 369          $url = 'index.php?';
 370  
 371          $arr = array();
 372          foreach($param as $value)
 373          {
 374              if(!in_array($value, $a_paramExclude) 
 375                  && isset($this->$value)
 376                  && !empty($this->$value))
 377              {
 378                  if (($value == 'site') && (isset($this->site_index)))
 379                  {
 380                      $arr[] = 'site=' . $this->site_index;
 381                  }
 382                  else
 383                  {
 384                      $arr[] = $value . '=' . $this->$value;
 385                  }
 386              }
 387          }
 388          $url .= implode('&amp;', $arr);
 389          
 390          // print "$v_param => url = $url<br>\n";

 391  
 392          // return substr($url, 0, strlen($url) - 5);

 393          return $url;
 394      }
 395      
 396  	function isInterest()
 397      {
 398          return (getRequestVar('a_int_sort', 'defaultvalue', 'string') !== 'defaultvalue');
 399      }
 400      
 401  	function loadArraySort($name, $defaultSort)
 402      {
 403          $this->$name = getRequestVar($name, $defaultSort, 'string');
 404      }
 405          
 406  	function loadActionName()
 407      {
 408          $this->action = getRequestVar('action', DEFAULT_ACTION, 'string');
 409      }
 410      
 411  	function getModuleName()
 412      {
 413          return $this->mod;
 414      }
 415      
 416  	function getModuleNameFromUrl()
 417      {
 418          return getRequestVar('mod', DEFAULT_MODULE, 'string');
 419      }
 420      
 421  	function loadModuleName()
 422      {
 423          $this->mod = getRequestVar('mod', DEFAULT_MODULE, 'string');
 424      }
 425      
 426  	function getActionName()
 427      {
 428          return $this->action;
 429      }    
 430  
 431  	function loadPeriod()
 432      {
 433          $p = getRequestVar('period', 1, 'int');
 434          
 435          if($p < 1 || $p > 4)
 436          {
 437              $p = 1;
 438          }
 439          $this->period = $p;
 440      }
 441      
 442  	function getLang()
 443      {
 444          return  getRequestVar('lang', 'unknown', 'string');
 445          
 446      }
 447      
 448  	function getRssHash()
 449      {
 450          return  getRequestVar('rss_hash', 'xxx', 'string');
 451      }
 452      
 453  	function setDate( $s_date)
 454      {
 455          $this->date = $s_date;
 456      }
 457      
 458  	function setModuleName( $s_module )
 459      {
 460          $this->mod = $s_module;
 461      }
 462      
 463  	function loadDate()
 464      {
 465          $this->date = getRequestVar('date', getDateFromTimestamp(time()- (DEFAULT_DAY_TODAY ? 0 : 86400)), 'string');
 466      }
 467      
 468  	function loadIdDetails()
 469      {
 470          $id = getRequestVar('id_details', false, 'int');
 471          if($id < 0) $id=false;
 472          $this->id_details = $id;
 473      }
 474      
 475  	function getIdDetails()
 476      {
 477          return $this->id_details;
 478      }
 479      
 480  	function loadMethodName()
 481      {
 482          $this->method_name = getRequestVar('method_name', '', 'string');
 483      }
 484      
 485  	function getMethodName()
 486      {
 487          return $this->method_name;
 488      }
 489      
 490  	function getOffset()
 491      {
 492          return $this->offset;
 493      }
 494      
 495      // for pages detail

 496  	function loadOffset()
 497      {
 498          $this->offset = getRequestVar('offset', '0', 'int');
 499      }
 500      
 501  	function loadAdminSite()
 502      {
 503          $this->adminSite = getRequestVar('adminsite', false, 'int');
 504      }
 505      
 506  	function loadAdminNewsletter()
 507      {
 508          $this->adminNewsletter = getRequestVar('adminnewsletter', false, 'int');
 509      }
 510  	function loadAdminUser()
 511      {
 512          $this->adminUser = getRequestVar('adminuser', false, 'string');
 513      }
 514      
 515  	function loadAdminPartner()
 516      {
 517          $this->adminPartner = getRequestVar('adminpartner', false, 'int');
 518      }
 519      
 520  	function getAdminSite()
 521      {
 522          return $this->adminSite;
 523      }
 524      
 525  	function getAdminNewsletter()
 526      {
 527          return $this->adminNewsletter;
 528      }
 529  	function getAdminUser()
 530      {
 531          return $this->adminUser;
 532      }
 533  	function getAdminPartner()
 534      {
 535          return $this->adminPartner;
 536      }
 537      
 538  	function getIdToUse()
 539      {
 540          return $this->idToUse;
 541      }
 542      
 543      // for pages detail

 544  	function loadIdToUse()
 545      {
 546          $this->idToUse = getRequestVar('idtouse', 'sum', 'string');
 547      }
 548      
 549  	function redirectToModule( $name )
 550      {
 551          $url = Request::getPhpmvRoot() . "index.php?mod=".$name;
 552                  
 553          if(Request::getCurrentCompleteUrl() != $url)
 554          {
 555              header("Location: $url");
 556              exit;
 557          }
 558      }
 559      
 560  	function loadSiteId()
 561      {
 562          if($this->getModuleName() == 'list_logos')
 563              return true;
 564              
 565          $site = getRequestVar('site', Site::getFirstSiteAvailable(), 'int');
 566          
 567          $db =& Db::getInstance();
 568          
 569          if($db->isReady()
 570              && $db->areAllTablesInstalled()
 571              && !Request::isCurrentModuleAnInstallModule() )
 572          {
 573              // check site asked is ok

 574              if($site != -1)
 575              {
 576                  $r = query("SELECT idsite 
 577                          FROM ".T_SITE);
 578                  
 579                  $idSite = array();        
 580                  while($l = mysql_fetch_assoc($r))
 581                  {
 582                      $idSite[] = $l['idsite'];
 583                  }
 584                  
 585                  if(sizeof($idSite) == 0)
 586                  {
 587                      $GLOBALS['header_error_message_tpl'] = $GLOBALS['lang']['generique_aucune_site_bdd'];
 588                      Request::redirectToModule( 'admin_site_general&action=add');
 589                      
 590                      $site = false;
 591                  }
 592                  elseif( !in_array( $site, $idSite) )
 593                  {
 594                      $site = 0;
 595                  }
 596              }
 597          }
 598          
 599          $this->site = (int)$site;
 600      }
 601      
 602  	function isCurrentModuleAnInstallModule()
 603      {
 604          return substr(Request::getModuleNameFromUrl(), 0, 8) === 'install_';
 605      }
 606  	function isCurrentModuleAGraphModule()
 607      {
 608          return substr(Request::getModuleNameFromUrl(), 0, 10) === 'view_graph';
 609      }
 610      
 611  	function isCurrentModuleAViewModule()
 612      {
 613          return substr(Request::getModuleNameFromUrl(), 0, 4) === 'view';
 614      }
 615      
 616  	function getTablesClean()
 617      {
 618          return getRequestVar('clean', 0, 'int');
 619      }
 620      
 621  	function getGraphType()
 622      {
 623          return getRequestVar('graph_type', null, 'int');
 624      }
 625  	function getGraphData()
 626      {
 627          return getRequestVar('graph_data', null, 'string');
 628      }
 629      
 630  	function getPeriod()
 631      {
 632          return $this->period;
 633      }
 634  	function setSiteId($siteId)
 635      {
 636          $this->site = $siteId;
 637      }
 638  	function getSiteId( $askedForExistingSite = true )
 639      {
 640          // case we asked for the real index asked, including site=-1 which means sites summary

 641          // so when asked for site for the SELECT HTML site generation

 642          if(!$askedForExistingSite 
 643              && isset($this->site_index))
 644          {
 645              return $this->site_index;
 646          }
 647          return $this->site;
 648      }    
 649              
 650  	function getDate()
 651      {
 652          return $this->date;
 653      }
 654      
 655  	function offsetDate($o_minDay)
 656      {
 657          $date = Archive::offsetDate(new Date($this->date), $o_minDay);
 658          $this->date = $date->get();
 659      }
 660      
 661  	function getContinentZoom()
 662      {
 663          return $this->id_details_continent;
 664      }
 665      
 666  	function loadContinentZoom()
 667      {
 668          $a_continent = array('eur', 'amn', 'ams', 'afr', 'oce', 'asi');
 669          $c = getRequestVar('id_details_continent', false, 'string');
 670          
 671          if( !in_array($c, $a_continent))
 672          {
 673              $this->id_details_continent = false;
 674          }
 675          else
 676          {
 677              $this->id_details_continent = $c;
 678          }
 679      }
 680  }
 681  ?>


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