PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/phpmyvisites_1_9/core/include/Request.class.php

https://bitbucket.org/pombredanne/spip-zone-treemap
PHP | 658 lines | 522 code | 97 blank | 39 comment | 60 complexity | 9cb10b9948a7354e91fc92f65addb828 MD5 | raw file
  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. // $Id: Request.class.php,v 1.61 2006/01/13 01:24:49 matthieu_ Exp $
  10. require_once INCLUDE_PATH . "/core/include/common.functions.php";
  11. class Request
  12. {
  13. var $site;
  14. var $date;
  15. var $period;
  16. var $mod;
  17. var $idToUse;// pages details, foolow up, etc.
  18. var $idDetails; // details for referers zoom
  19. var $methodName; // used for all data arrays
  20. var $offset; //offset for referers
  21. function Request()
  22. {
  23. $this->loadModuleName();
  24. $this->loadSiteId();
  25. $this->loadDate();
  26. $this->loadPeriod();
  27. $this->loadActionName();
  28. $this->loadIdDetails();
  29. $this->loadMethodName();
  30. $this->loadOffset();
  31. $this->loadCategoryAsked();
  32. $this->loadIdToUse();
  33. $this->loadAdminSite();
  34. $this->loadAdminNewsletter();
  35. $this->loadAdminUser();
  36. $this->loadAdminPartner();
  37. $this->loadContinentZoom();
  38. $pagesPercentLimit = 50;
  39. $keywordPercentLimit = $searchEnginePercentLimit = $sitePercentLimit =
  40. $partnerPercentLimit = $newsletterPercentLimit = 100;
  41. $defaultOrder = 'sum.desc';
  42. $nolimit = 0;
  43. $this->sorting_percent_limit_and_population_index = array(
  44. // parameter name => array( percent default limit value, all sums array index for this parameter, default sort)
  45. 'a_int_sort' => array( 100 , 'int', $defaultOrder),
  46. 'a_pag_sort' => array( $pagesPercentLimit, 'pag', $defaultOrder),
  47. 'a_entry_sort' => array( $pagesPercentLimit, 'entry','entry.desc'),
  48. 'a_exit_sort' => array( $pagesPercentLimit, 'exit', 'exit.desc'),
  49. 'a_singlepage_sort' => array( $pagesPercentLimit, 'singlepage', 'singlepage.desc'),
  50. 'a_sumtime_sort' => array( $pagesPercentLimit, 'sumtime', 'sumtime.desc'),
  51. 'a_keyword_sort' => array( $keywordPercentLimit, 'keyword', $defaultOrder),
  52. 'a_searchengine_sort' => array( $searchEnginePercentLimit, 'searchengine', $defaultOrder),
  53. 'a_site_sort' => array( $sitePercentLimit, 'site', $defaultOrder),
  54. 'a_partner_sort' => array( $partnerPercentLimit, 'partner', $defaultOrder),
  55. 'a_newsletter_sort' => array( $newsletterPercentLimit, 'newsletter', $defaultOrder),
  56. 'a_type_sort' => array( $nolimit, 'type', $defaultOrder), // referer type
  57. );
  58. // ==> see $this->arraySumInfo in DataModel
  59. foreach($this->sorting_percent_limit_and_population_index as $name => $info)
  60. {
  61. $this->loadArraySort($name, $info[2]);
  62. }
  63. // lang other => mod = otherlanguage
  64. if($this->getLang() === 'other')
  65. {
  66. $this->mod = 'other_language';
  67. }
  68. // if asked for mod=view_
  69. if( $this->mod == 'view_sites_summary'
  70. && $this->getSiteId() != -1)
  71. {
  72. $this->mod = 'view_visits';
  73. }
  74. // site 0 => mod = viewSitesSummary
  75. if($this->getSiteId() === -1)
  76. {
  77. $this->mod = 'view_sites_summary';
  78. $this->site = 1;
  79. $this->site_index = -1;
  80. }
  81. $this->crontabAllowed = false;
  82. }
  83. /**
  84. * Singleton
  85. */
  86. function &getInstance()
  87. {
  88. static $instance;
  89. if (!isset($instance)){
  90. $c = __CLASS__;
  91. $instance = new $c();
  92. }
  93. return $instance;
  94. }
  95. function isPhpmvLogModule()
  96. {
  97. return isset($GLOBALS['currentModuleIsLogModule']); // quick hack...
  98. return ereg( '/phpmyvisites.php', Request::getCurrentCompleteUrl() );
  99. }
  100. function setCrontabAllowed()
  101. {
  102. $this->crontabAllowed = true;
  103. }
  104. function isCrontabAllowed()
  105. {
  106. return $this->crontabAllowed;
  107. }
  108. function getErrorLogin()
  109. {
  110. return getRequestVar( 'error_login', 0, 'int');
  111. }
  112. function getConfirmedState()
  113. {
  114. return getRequestVar( 'confirmed', 0, 'int');
  115. }
  116. function getArrayInfoSort($allSumInfo)
  117. {
  118. foreach($this->sorting_percent_limit_and_population_index as $param => $info)
  119. {
  120. $sorted[$info[1]] = $this->getArraySort($param, $allSumInfo[$info[1]]);
  121. }
  122. return $sorted;
  123. }
  124. function getArraySort($name, $totalPopulation)
  125. {
  126. $sort = $this->$name;
  127. $sort = explode('.', $sort);
  128. $sorting_index = $sort[0];
  129. $sorting_order = $sort[1];
  130. $sorting_detail = isset($sort[2])?$sort[2]:'';
  131. $sorting_limit = isset($sort[3])?$sort[3]:$totalPopulation;
  132. //print("$name : total= $totalPopulation <br>");
  133. if(!isset($sort[4]))
  134. {
  135. $sorting_percent_limit = $this->sorting_percent_limit_and_population_index[$name][0];
  136. }
  137. else
  138. {
  139. $sorting_percent_limit = $sort[4];
  140. }
  141. $a = array(
  142. 0 => $sorting_index . "." . $sorting_order,
  143. 1 => $sorting_index,
  144. 2 => $sorting_order,
  145. 3 => $sorting_detail,
  146. 4 => $sorting_limit . "." . $sorting_percent_limit,
  147. 5 => $sorting_limit,
  148. 6 => $sorting_percent_limit,
  149. 7 => $totalPopulation . "." . $this->sorting_percent_limit_and_population_index[$name][0],
  150. 8 => $totalPopulation,
  151. 9 => $this->sorting_percent_limit_and_population_index[$name][0],
  152. );
  153. return $a;
  154. }
  155. function loadCategoryAsked()
  156. {
  157. $this->c_id_zoom = getRequestVar('c_id_zoom', '', 'string');
  158. }
  159. function getCategoryAsked()
  160. {
  161. return $this->c_id_zoom;
  162. }
  163. function moduleIsNotAStrangeModule()
  164. {
  165. if(@$_REQUEST['mod'] != 'view_pages_details'
  166. && @$_REQUEST['mod'] != 'view_visits_rss'
  167. && @$_REQUEST['mod'] != 'view_data_array'
  168. && @$_REQUEST['mod'] != 'view_graph')
  169. {
  170. return true;
  171. }
  172. return false;
  173. }
  174. function isCategoryZoom()
  175. {
  176. return empty($this->c_id_zoom)?
  177. false:
  178. true;
  179. }
  180. function getHostUrl()
  181. {
  182. return "http://".$_SERVER['HTTP_HOST'];
  183. }
  184. function getCurrentCompletePath()
  185. {
  186. $phpmv_url_chemin = '';
  187. if(isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] != "")
  188. {
  189. $phpmv_url_chemin = $_SERVER['PATH_INFO'];
  190. }
  191. else if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != "")
  192. {
  193. if($pos = strpos($_SERVER['REQUEST_URI'], "?"))
  194. {
  195. $phpmv_url_chemin = substr($_SERVER['REQUEST_URI'], 0, $pos);
  196. }
  197. else
  198. {
  199. $phpmv_url_chemin = $_SERVER['REQUEST_URI'];
  200. }
  201. }
  202. if(empty($phpmv_url_chemin))
  203. {
  204. $phpmv_url_chemin = $_SERVER['SCRIPT_NAME'];
  205. }
  206. $phpmv_url_chemin= Request::getHostUrl() . $phpmv_url_chemin;
  207. return substr($phpmv_url_chemin, 0, strrpos($phpmv_url_chemin, '/'));
  208. }
  209. function getPhpmvRoot()
  210. {
  211. $root = "http://" . $_SERVER['HTTP_HOST'] .
  212. rtrim(dirname($_SERVER['PHP_SELF']), '/\\') .
  213. "/";
  214. return $root;
  215. }
  216. function getCurrentCompleteUrl()
  217. {
  218. //print(Request::getCurrentCompletePath());
  219. //print("<br>");
  220. return Request::getCurrentCompletePath() . "/" . Request::getCurrentUrl();
  221. }
  222. function getCurrentUrl()
  223. {
  224. if(isset($_SERVER["SCRIPT_URL"]))
  225. {
  226. $toUse = $_SERVER["SCRIPT_URL"];
  227. }
  228. else
  229. {
  230. $toUse = $_SERVER["SCRIPT_NAME"];
  231. }
  232. $return = substr($toUse, 1 - strlen($toUse) + strrpos($toUse, "/"));
  233. if(isset($_SERVER["QUERY_STRING"])
  234. && !empty($_SERVER["QUERY_STRING"]))
  235. {
  236. $return .= "?".$_SERVER["QUERY_STRING"];
  237. }
  238. // not '//' in url
  239. if($return == '/')
  240. {
  241. $return = '';
  242. }
  243. else
  244. {
  245. // case servers that give path/page for return instead of page only! too bad
  246. if(ereg('/', $return))
  247. {
  248. $return = substr( $return, strrpos($return, "/")+1);
  249. }
  250. }
  251. //print($return);
  252. //exit;
  253. return $return;
  254. }
  255. /**
  256. *
  257. * @param string|array $a_paramExclude
  258. *
  259. * @return string
  260. */
  261. function getUrl($a_paramExclude = '')
  262. {
  263. if(!is_array($a_paramExclude))
  264. {
  265. $a_paramExclude = array ( $a_paramExclude);
  266. }
  267. // var_dump($a_paramExclude);
  268. // print"<br>\n";
  269. $param = array(
  270. 'site',
  271. 'date',
  272. 'period',
  273. 'mod',
  274. );
  275. // special case for pages details, we conserve the sort vars but not the mod vars
  276. if($a_paramExclude[0] == 'mod_sort_means_details')
  277. {
  278. $param[] = 'a_pag_sort';
  279. $param[] = 'a_entry_sort';
  280. $param[] = 'a_exit_sort';
  281. $param[] = 'a_sumtime_sort';
  282. $param[] = 'a_singlepage_sort';
  283. }
  284. // remove mod from url
  285. if($a_paramExclude[0] == 'mod_sort_means_details')
  286. {
  287. unset($param[array_search('mod', $param)]);
  288. }
  289. // add info relative to offset / details for ajax
  290. if($a_paramExclude[0] == 'offset' || $a_paramExclude[0] == 'a_int_sort')
  291. {
  292. $param[] = 'method_name';
  293. $param[] = 'id_details';
  294. }
  295. if($a_paramExclude[0] == 'offset')
  296. {
  297. $param[] = 'a_keyword_sort';
  298. $param[] = 'a_searchengine_sort';
  299. $param[] = 'a_site_sort';
  300. $param[] = 'a_partner_sort';
  301. $param[] = 'a_newsletter_sort';
  302. $param[] = 'a_int_sort';
  303. $param[] = 'a_type_sort';
  304. }
  305. $url = '?exec=phpmv&';//'index.php?';
  306. $arr = array();
  307. foreach($param as $value)
  308. {
  309. if(!in_array($value, $a_paramExclude)
  310. && isset($this->$value)
  311. && !empty($this->$value))
  312. {
  313. $arr[] = $value . '=' . $this->$value;
  314. }
  315. }
  316. $url .= implode('&amp;', $arr);
  317. // print "url = $url<br>\n";
  318. // return substr($url, 0, strlen($url) - 5);
  319. return $url;
  320. }
  321. function isInterest()
  322. {
  323. return (getRequestVar('a_int_sort', 'defaultvalue', 'string') !== 'defaultvalue');
  324. }
  325. function loadArraySort($name, $defaultSort)
  326. {
  327. $this->$name = getRequestVar($name, $defaultSort, 'string');
  328. }
  329. function loadActionName()
  330. {
  331. $this->action = getRequestVar('action', DEFAULT_ACTION, 'string');
  332. }
  333. function getModuleName()
  334. {
  335. return $this->mod;
  336. }
  337. function getModuleNameFromUrl()
  338. {
  339. return getRequestVar('mod', DEFAULT_MODULE, 'string');
  340. }
  341. function loadModuleName()
  342. {
  343. $this->mod = getRequestVar('mod', DEFAULT_MODULE, 'string');
  344. }
  345. function getActionName()
  346. {
  347. return $this->action;
  348. }
  349. function loadPeriod()
  350. {
  351. $p = getRequestVar('period', 1, 'int');
  352. if($p < 1 || $p > 4)
  353. {
  354. $p = 1;
  355. }
  356. $this->period = $p;
  357. }
  358. function getLang()
  359. {
  360. return getRequestVar('lang', 'unknown', 'string');
  361. }
  362. function getRssHash()
  363. {
  364. return getRequestVar('rss_hash', 'xxx', 'string');
  365. }
  366. function setDate( $s_date)
  367. {
  368. $this->date = $s_date;
  369. }
  370. function setModuleName( $s_module )
  371. {
  372. $this->mod = $s_module;
  373. }
  374. function loadDate()
  375. {
  376. $this->date = getRequestVar('date', getDateFromTimestamp(time()- (DEFAULT_DAY_TODAY ? 0 : 86400)), 'string');
  377. }
  378. function loadIdDetails()
  379. {
  380. $id = getRequestVar('id_details', false, 'int');
  381. if($id < 0) $id=false;
  382. $this->id_details = $id;
  383. }
  384. function getIdDetails()
  385. {
  386. return $this->id_details;
  387. }
  388. function loadMethodName()
  389. {
  390. $this->method_name = getRequestVar('method_name', '', 'string');
  391. }
  392. function getMethodName()
  393. {
  394. return $this->method_name;
  395. }
  396. function getOffset()
  397. {
  398. return $this->offset;
  399. }
  400. // for pages detail
  401. function loadOffset()
  402. {
  403. $this->offset = getRequestVar('offset', '0', 'int');
  404. }
  405. function loadAdminSite()
  406. {
  407. $this->adminSite = getRequestVar('adminsite', false, 'int');
  408. }
  409. function loadAdminNewsletter()
  410. {
  411. $this->adminNewsletter = getRequestVar('adminnewsletter', false, 'int');
  412. }
  413. function loadAdminUser()
  414. {
  415. $this->adminUser = getRequestVar('adminuser', false, 'string');
  416. }
  417. function loadAdminPartner()
  418. {
  419. $this->adminPartner = getRequestVar('adminpartner', false, 'int');
  420. }
  421. function getAdminSite()
  422. {
  423. return $this->adminSite;
  424. }
  425. function getAdminNewsletter()
  426. {
  427. return $this->adminNewsletter;
  428. }
  429. function getAdminUser()
  430. {
  431. return $this->adminUser;
  432. }
  433. function getAdminPartner()
  434. {
  435. return $this->adminPartner;
  436. }
  437. function getIdToUse()
  438. {
  439. return $this->idToUse;
  440. }
  441. // for pages detail
  442. function loadIdToUse()
  443. {
  444. $this->idToUse = getRequestVar('idtouse', 'sum', 'string');
  445. }
  446. function redirectToModule( $name )
  447. {
  448. //$url = Request::getPhpmvRoot() . "index.php?mod=".$name;
  449. $url = generer_url_ecrire('phpmv',"mod=".$name,true);
  450. if(Request::getCurrentCompleteUrl() != $url)
  451. {
  452. @header("Location: $url");
  453. echo "<a href='$url'>$url</a>";
  454. exit;
  455. }
  456. }
  457. function loadSiteId()
  458. {
  459. if($this->getModuleName() == 'list_logos')
  460. return true;
  461. $site = getRequestVar('site', Site::getFirstSiteAvailable(), 'int');
  462. $db =& Db::getInstance();
  463. if($db->isReady()
  464. && $db->areAllTablesInstalled()
  465. && !Request::isCurrentModuleAnInstallModule() )
  466. {
  467. // check site asked is ok
  468. if($site != -1)
  469. {
  470. $r = query("SELECT idsite
  471. FROM ".T_SITE);
  472. $idSite = array();
  473. while($l = mysql_fetch_assoc($r))
  474. {
  475. $idSite[] = $l['idsite'];
  476. }
  477. if(sizeof($idSite) == 0)
  478. {
  479. $GLOBALS['header_error_message_tpl'] = $GLOBALS['lang']['generique_aucune_site_bdd'];
  480. Request::redirectToModule( 'admin_site_general&action=add');
  481. $site = false;
  482. }
  483. elseif( !in_array( $site, $idSite) )
  484. {
  485. $site = 0;
  486. }
  487. }
  488. }
  489. $this->site = (int)$site;
  490. }
  491. function isCurrentModuleAnInstallModule()
  492. {
  493. return substr(Request::getModuleNameFromUrl(), 0, 8) === 'install_';
  494. }
  495. function isCurrentModuleAGraphModule()
  496. {
  497. return substr(Request::getModuleNameFromUrl(), 0, 10) === 'view_graph';
  498. }
  499. function getTablesClean()
  500. {
  501. return getRequestVar('clean', 0, 'int');
  502. }
  503. function getGraphType()
  504. {
  505. return getRequestVar('graph_type', null, 'int');
  506. }
  507. function getGraphData()
  508. {
  509. return getRequestVar('graph_data', null, 'string');
  510. }
  511. function getPeriod()
  512. {
  513. return $this->period;
  514. }
  515. function setSiteId($siteId)
  516. {
  517. $this->site = $siteId;
  518. }
  519. function getSiteId( $askedForExistingSite = true )
  520. {
  521. // case we asked for the real index asked, including site=-1 which means sites summary
  522. // so when asked for site for the SELECT HTML site generation
  523. if(!$askedForExistingSite
  524. && isset($this->site_index))
  525. {
  526. return $this->site_index;
  527. }
  528. return $this->site;
  529. }
  530. function getDate()
  531. {
  532. return $this->date;
  533. }
  534. function offsetDate($o_minDay)
  535. {
  536. $date = Archive::offsetDate(new Date($this->date), $o_minDay);
  537. $this->date = $date->get();
  538. }
  539. function getContinentZoom()
  540. {
  541. return $this->id_details_continent;
  542. }
  543. function loadContinentZoom()
  544. {
  545. $a_continent = array('eur', 'amn', 'ams', 'afr', 'oce', 'asi');
  546. $c = getRequestVar('id_details_continent', false, 'string');
  547. if( !in_array($c, $a_continent))
  548. {
  549. $this->id_details_continent = false;
  550. }
  551. else
  552. {
  553. $this->id_details_continent = $c;
  554. }
  555. }
  556. }
  557. ?>