| [ Index ] |
|
Code source de phpMyVisites 2.3 |
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: DataModel.class.php 215 2007-05-01 13:03:34Z matthieu_ $ 11 12 13 $GLOBALS['sorting_index'] = 'sum'; 14 $GLOBALS['sorting_order'] = 'desc'; 15 16 require_once INCLUDE_PATH."/core/include/Archive.class.php"; 17 require_once INCLUDE_PATH."/core/include/ArchiveEmpty.class.php"; 18 require_once INCLUDE_PATH."/core/include/ArchiveDay.class.php"; 19 require_once INCLUDE_PATH."/core/include/ArchivePeriod.class.php"; 20 require_once INCLUDE_PATH."/core/include/ArchiveWeek.class.php"; 21 require_once INCLUDE_PATH."/core/include/ArchiveMonth.class.php"; 22 require_once INCLUDE_PATH."/core/include/ArchiveYear.class.php"; 23 require_once INCLUDE_PATH . "/core/include/ArchiveTable.class.php"; 24 25 class DataModel 26 { 27 //object ArchiveX 28 var $archive; 29 30 var $langFile; 31 32 var $content; 33 34 var $objects; 35 36 var $infoSerialized; 37 38 var $idDetailsSaved; // store ID for compute nb of subelements for a data like search engines, keywords... 39 var $sizeDetailsSaved; 40 41 function DataModel( & $o_archive, & $o_request) 42 { 43 $this->archive = $o_archive; 44 45 $this->infoSerialized = $this->archive->getArchived(); 46 47 /* 48 print("<br>apres compresseion " . strlen($this->infoSerialized['vis_pag_grp'])); 49 print("avant compresseion " . strlen(uncompress($this->infoSerialized['vis_pag_grp'],1))); 50 print("<br>apres base 64 compresseion " . strlen(base64_encode($this->infoSerialized['vis_pag_grp']))); 51 */ 52 if(isset($this->infoSerialized['simple']) && $this->infoSerialized['simple'] == 1) 53 { 54 if(!isset($GLOBALS['header_message_tpl'])) $GLOBALS['header_message_tpl'] = ''; 55 56 if(!isset($GLOBALS['header_simple_message'])) 57 { 58 $GLOBALS['header_message_tpl'] .= "<br>This is a simple archiving. ONLY some statistics are available for this archive, because the period asked in the statistics is not finished yet. <br />You can turn 'Simple Archive' Off in the file /config.inc.php by setting CURRENT_XXXX_SIMPLE_ARCHIVE to false.<br/>"; 59 $GLOBALS['header_simple_message'] = true; 60 } 61 } 62 $this->request = $o_request; 63 64 $this->arraySumInfo = array( 65 'int' => $this->getContent('nb_vis'), 66 'pag' => $this->getContent('nb_pag'), 67 'exit' => $this->getContent('nb_vis'), 68 'entry' => $this->getContent('nb_vis'), 69 'sumtime' => $this->getContent('nb_pag'), 70 'singlepage' => $this->getContent('nb_vis'), 71 'keyword' => $this->getReferersNbSearchEngines(), 72 'searchengine' => $this->getReferersNbSearchEngines(), 73 'site' => $this->getReferersNbSites(), 74 'partner' => $this->getReferersNbPartners(), 75 'newsletter' => $this->getReferersNbNewsletters(), 76 'type' => $this->getReferersTypeDistinct() 77 ); 78 } 79 80 function getContent($name, $offset = 0, $nbElementsToDisplay = -1) 81 { 82 // case for example nb_uniq_vis_returning after rc2, prior version didn't have 83 if(!isset($this->infoSerialized[$name])) return 0; 84 85 $indexName = $name."-".$offset."-".$nbElementsToDisplay; 86 if(!isset($this->content[$indexName])) 87 { 88 //printDebug($this->infoSerialized); 89 //print("content : ".$this->infoSerialized[$name]); 90 if(!is_numeric($this->infoSerialized[$name]) 91 && $name!='date1' 92 && $name != 'date2' 93 && isset($this->arraySumInfo) 94 ) 95 { 96 $array = array(); 97 //printTime('before unserialize', true); 98 if(!is_null($this->infoSerialized[$name])) 99 { 100 if(isset($this->infoSerialized['compressed']) 101 && $this->infoSerialized['compressed'] == 1) 102 { 103 $array = unserialize(gzuncompress($this->infoSerialized[$name])); 104 } 105 else 106 { 107 $array = unserialize($this->infoSerialized[$name]); 108 } 109 110 if(substr($name, 0, 4) === 'int_') 111 { 112 $array = $this->getArrayInterestNamed($array); 113 } 114 } 115 116 // case subdetail, record number of subdetails for an element 117 if($name == 'vis_search_engine' 118 || $name == 'vis_keyword' 119 || $name == 'vis_site' 120 || $name == 'vis_partner') 121 { 122 if(is_array($array)) 123 { 124 foreach($array as $key => $infoA) 125 { 126 if($key == $this->idDetailsSaved[$name]) 127 { 128 $this->sizeDetailsSaved[$name] = sizeof($infoA)-1; 129 } 130 } 131 } 132 } 133 134 //printTime('before offset', true); 135 $this->content[$indexName] = getArrayOffsetLimit( 136 $array, 137 $offset, 138 $nbElementsToDisplay, 139 $name, 140 null, 141 $this->arraySumInfo 142 ); 143 } 144 else 145 { 146 $this->content[$indexName] = $this->infoSerialized[$name]; 147 } 148 } 149 return $this->content[$indexName]; 150 } 151 152 153 function getVisitsFrequencyNewReturningGraph() 154 { 155 $all = $this->getContent('vis_period'); 156 157 switch($this->archive->periodType) 158 { 159 160 case DB_ARCHIVES_PERIOD_WEEK: 161 $typeDateDisplay = 2; 162 $typeDateDisplayGraph = 8; 163 164 break; 165 166 case DB_ARCHIVES_PERIOD_MONTH: 167 $typeDateDisplay = 2; 168 $typeDateDisplayGraph = 8; 169 170 break; 171 172 case DB_ARCHIVES_PERIOD_YEAR: 173 $typeDateDisplay = 5; 174 $typeDateDisplayGraph = 10; 175 break; 176 } 177 178 $new = $returning = $axis = array(); 179 ksort($all); 180 foreach($all as $date => $info) 181 { 182 $new[] = $info[ARRAY_INDEX_NEW_COUNT]; 183 $returning[] = $info[ARRAY_INDEX_RETURNING_COUNT]; 184 switch($this->archive->periodType) 185 { 186 case DB_ARCHIVES_PERIOD_DAY: 187 $dateD = sprintf( $GLOBALS['lang']['generique_tempsheure'], $date) ; 188 break; 189 190 case DB_ARCHIVES_PERIOD_WEEK: 191 $dateD = getDateDisplay($typeDateDisplayGraph, new Date($date)); 192 break; 193 194 case DB_ARCHIVES_PERIOD_MONTH: 195 $dateDD = new Date($date); 196 $dateD = $dateDD->getDay(); 197 break; 198 199 case DB_ARCHIVES_PERIOD_YEAR: 200 $dateDD = new Date($date); 201 $dateD = $GLOBALS['lang']['moistab_graph'][$dateDD->getMonth()]; 202 203 break; 204 } 205 $axis[] = $dateD; 206 } 207 208 return array( 209 'data1' => array( 210 'data' => $new, 211 'legend' => $GLOBALS['lang']['frequence_nouvellesvisites'] 212 ), 213 'data2' => array( 214 'data' => $returning, 215 'legend' => $GLOBALS['lang']['frequence_visitesconnues'] 216 ), 217 'axis' => $axis, 218 'title' => $GLOBALS['lang']['frequence_nouveauxconnus'] 219 ); 220 } 221 222 function getVisitsFrequencyStatistics() 223 { 224 $ret = array(); 225 226 if($this->getContent('nb_vis') != 0) 227 { 228 $nbVisitNew = $this->getContent('nb_vis') - $this->getContent('nb_vis_returning'); 229 $nbPagNew = $this->getContent('nb_pag') - $this->getContent('nb_pag_returning'); 230 $totalTimeNew = $this->getContent('sum_vis_lth') - $this->getContent('sum_vis_lth_returning'); 231 $nbOnePagVis = $this->getContent('nb_vis_1pag') - $this->getContent('nb_vis_1pag_returning'); 232 233 $nb_vis = $this->getContent('nb_vis'); 234 $nb_uniq_vis = $this->getContent('nb_uniq_vis'); 235 $nb_pag = $this->getContent('nb_pag'); 236 $nb_vis_returning = $this->getContent('nb_vis_returning'); 237 $nb_uniq_vis_returning = $this->getContent('nb_uniq_vis_returning'); 238 $nb_pag_returning = $this->getContent('nb_pag_returning'); 239 $sum_vis_lth_returning = $this->getContent('sum_vis_lth_returning'); 240 $nb_vis_1pag_returning = $this->getContent('nb_vis_1pag_returning'); 241 242 243 $ret = array(); 244 $ret['nb_uniq_vis_returning'] = $nb_uniq_vis_returning; 245 $ret['nb_uniq_vis_new'] = $nb_uniq_vis - $nb_uniq_vis_returning; 246 $ret['returning_rate'] = 100 * $this->_secureDiv($nb_uniq_vis_returning , $nb_uniq_vis); 247 $ret['nb_vis_per_uniq_vis'] = $this->_secureDiv($nb_vis,$nb_uniq_vis); 248 $ret['nb_vis_returning_percent'] = 100 * $this->_secureDiv($nb_vis_returning , $nb_vis); 249 $ret['nb_vis_new_percent'] = 100 * $this->_secureDiv($nbVisitNew ,$nb_vis ); 250 251 $ret['nb_vis_returning'] = $nb_vis_returning; 252 $ret['nb_vis_new'] = $nbVisitNew; 253 $ret['nb_pag_returning'] = $nb_pag_returning; 254 $ret['nb_pag_new'] = $nbPagNew; 255 256 $ret['nb_pag_returning_percent'] = 100 * $this->_secureDiv($nb_pag_returning ,$nb_pag ); 257 $ret['nb_pag_new_percent'] = 100 * $this->_secureDiv($nbPagNew ,$nb_pag); 258 259 $ret['nb_pag_per_vis_returning'] = $this->_secureDiv($nb_pag_returning, $nb_vis_returning ); 260 $ret['time_per_vis_returning'] = $this->_secureDiv($sum_vis_lth_returning, $nb_vis_returning); 261 $ret['time_per_pag_returning'] = $this->_secureDiv($sum_vis_lth_returning, $nb_pag_returning); 262 $ret['one_page_rate_returning'] = 100 * $this->_secureDiv($nb_vis_1pag_returning,$nb_vis_returning); 263 264 $ret['nb_pag_per_vis_new'] = $this->_secureDiv($nbPagNew, $nbVisitNew); 265 $ret['one_page_rate_new'] = 100 * $this->_secureDiv($nbOnePagVis,$nbVisitNew); 266 $ret['time_per_vis_new'] = $this->_secureDiv($totalTimeNew, $nbVisitNew); 267 268 $ret['time_per_pag_new'] = $this->_secureDiv($totalTimeNew, $nbPagNew); 269 270 } 271 return $ret; 272 } 273 274 275 /** 276 * Visits 277 */ 278 279 function getVisitsStatistics() 280 { 281 $ret = array(); 282 283 if($this->getContent('nb_vis') != 0 284 && $this->getContent('nb_pag') != 0 ) 285 { 286 $nb_vis = $this->getContent('nb_vis'); 287 $nb_uniq_vis = $this->getContent('nb_uniq_vis'); 288 $nb_pag = $this->getContent('nb_pag'); 289 $nb_vis_1pag = $this->getContent('nb_vis_1pag'); 290 $sum_vis_lth = $this->getContent('sum_vis_lth'); 291 292 $nbPagPerVisSig = $this->_secureDiv($nb_pag - $nb_vis_1pag, $nb_vis - $nb_vis_1pag); 293 294 $ret['nb_vis'] = $nb_vis; 295 $ret['nb_uniq_vis'] = $nb_uniq_vis; 296 $ret['nb_pag'] = $nb_pag; 297 $ret['nb_pag_per_vis_sig'] = $nbPagPerVisSig; 298 $ret['nb_pag_per_vis'] = $this->_secureDiv($nb_pag, $nb_uniq_vis); 299 $ret['time_per_vis'] = $this->_secureDiv($sum_vis_lth, $nb_vis); 300 $ret['time_per_pag'] = $this->_secureDiv($sum_vis_lth, $nb_pag); 301 $ret['one_page_rate'] = 100 * $this->_secureDiv($nb_vis_1pag, $nb_vis); 302 303 304 // for period != day 305 if($this->getContent('period') != 1) 306 { 307 // number of days in the period 308 $nbDaysInPeriod = getNumberOfDaysBetween( $this->getContent("date1"), 309 $this->getContent("date2") 310 ); 311 312 // average visits per day in the period 313 $ret['average_visits_per_day'] = $this->_secureDiv($nb_vis, $nbDaysInPeriod); 314 } 315 } 316 return $ret; 317 } 318 319 function getSitesSignature() 320 { 321 $site = new Site(1); 322 $siteInfo = $site->getAllowedSites( 'view' ); 323 return (implode(array_keys($siteInfo),",")); 324 } 325 326 function getSites() 327 { 328 if(!isset($this->siteInfo)) 329 { 330 $site = new Site(1); 331 $siteInfo = $site->getAllowedSites( 'view' ); 332 $return=array(); 333 foreach($siteInfo as $id => $info) 334 { 335 $return[] = new Site( $id );// $info['idsite'] ); 336 } 337 //pegrint_r($return); 338 $this->siteInfo = $return; 339 } 340 else 341 { 342 $return = $this->siteInfo; 343 } 344 return $return; 345 } 346 347 function getSitesArchives() 348 { 349 $siteInfo = $this->getSites(); 350 foreach($siteInfo as $id => $o_site) 351 { 352 $id = $o_site->getId(); 353 $p = $this->getArchive($o_site, $this->archive->date->get(), $this->request->getPeriod() ); 354 $allArchive[] = new DataModel( $p , $this->request); 355 } 356 return $allArchive; 357 } 358 359 function getSitesSummaryStatisticsGraph() 360 { 361 $allSiteArchive = $this->getSites(); 362 363 $i = 1; 364 foreach($allSiteArchive as $id => $infoSite) 365 { 366 if($i < 4) 367 { 368 $allArchive = $this->getLastArchives( 15, 0, DATE_GRAPH, $infoSite); 369 370 $data = array(); 371 $axis = array(); 372 373 $allArchive = array_reverse($allArchive, true); 374 foreach($allArchive as $date => $o_archive) 375 { 376 $o_data = new DataModel($o_archive, $this->request); 377 $data[] = $o_data->getContent('nb_vis'); 378 $axis[] = $date; 379 } 380 381 $return['data'.$i++] = array( 382 'data' => $data, 383 'legend' => $infoSite->getName() 384 ); 385 } 386 } 387 388 $return['axis'] = $axis; 389 $return['title'] = $GLOBALS['lang']['visites_grapghrecap']; 390 return $return; 391 392 } 393 394 function getSitesSummaryStatistics() 395 { 396 $allSiteArchive = $this->getSitesArchives(); 397 398 foreach($allSiteArchive as $value) 399 { 400 $siteInfo = $value->archive->site->a_info; 401 402 $toSum['nb_vis'][] = $value->getContent('nb_vis'); 403 $toSum['nb_pag'][] = $value->getContent('nb_pag'); 404 $toSum['nb_uniq_vis'][] = $value->getContent('nb_uniq_vis'); 405 $toSum['sum_vis_lth'][] = $value->getContent('sum_vis_lth'); 406 $toSum['nb_vis_1pag'][] = $value->getContent('nb_vis_1pag'); 407 408 @$nbPagPerVisSig = $value->getContent('nb_pag') 409 / ($value->getContent('nb_vis') - $value->getContent('nb_vis_1pag')); 410 $return[] = array( 411 'id' => $value->archive->site->getId(), 412 'site_name' => $siteInfo['name'], 413 'nb_vis' => $value->getContent('nb_vis'), 414 'nb_uniq_vis' => $value->getContent('nb_uniq_vis'), 415 'nb_pag' => $value->getContent('nb_pag'), 416 'nb_pag_per_vis_sig'=> $nbPagPerVisSig, 417 'nb_pag_per_vis' => $this->_secureDiv($value->getContent('nb_pag') ,$value->getContent('nb_uniq_vis')), 418 'time_per_vis' => $this->_secureDiv($value->getContent('sum_vis_lth') ,$value->getContent('nb_vis')), 419 'time_per_pag' => $this->_secureDiv($value->getContent('sum_vis_lth') , $value->getContent('nb_pag')), 420 'one_page_rate' => 100 * $this->_secureDiv($value->getContent('nb_vis_1pag'), $value->getContent('nb_vis')) 421 ); 422 // print($value->getContent('sum_vis_lth')." ,".$value->getContent('nb_vis')."<br>"); 423 } 424 425 foreach($toSum as $id => $value) 426 { 427 $totalSum[$id] = array_sum($value); 428 } 429 430 $returnTotal = array( 431 'nb_vis' => $totalSum['nb_vis'], 432 'nb_pag' => $totalSum['nb_pag'], 433 'nb_pag_per_vis' => $this->_secureDiv($totalSum['nb_pag'] , $totalSum['nb_uniq_vis']) , 434 'time_per_vis' => $this->_secureDiv($totalSum['sum_vis_lth'] ,$totalSum['nb_vis']) , 435 'one_page_rate' => 100 * $this->_secureDiv($totalSum['nb_vis_1pag'] ,$totalSum['nb_vis'] ) 436 ); 437 438 $GLOBALS['sorting_index'] = 'nb_vis'; 439 uasort($return, "sortingDataInfo"); 440 //printdebug($return); 441 442 return array( 443 'sites_info' => $return, 444 'total' => $returnTotal 445 ); 446 } 447 448 function getVisitsPeriodSummaries($nbPeriodToDisplay = 8, $dateTextType = DATE_NORMAL) 449 { 450 $archives = $this->getLastArchives($nbPeriodToDisplay, 0, $dateTextType); 451 452 $visitsToday = $this->getContent('nb_vis'); 453 $pagesToday = $this->getContent('nb_pag'); 454 455 foreach($archives as $dateToDisplay => $archive) 456 { 457 $info = $archive->getArchived(); 458 $visitsPercent = $this->getDiffPercent($visitsToday, $info['nb_vis']); 459 $pagesPercent = $this->getDiffPercent($pagesToday, $info['nb_pag']); 460 461 $return[] = array( 462 'date' => $dateToDisplay, 463 'visits' => $info['nb_vis'], 464 'visits_percent'=> $visitsPercent, 465 'pages' => $info['nb_pag'], 466 'pages_percent' => $pagesPercent 467 ); 468 } 469 return array_reverse($return); 470 } 471 function getVisitsAllPeriodSummaryGraph() 472 { 473 if($this->archive->periodType === DB_ARCHIVES_PERIOD_YEAR) 474 { 475 $this->archive->periodType = DB_ARCHIVES_PERIOD_MONTH; 476 $periodNb = 18; 477 } 478 else 479 { 480 if($this->archive->periodType == DB_ARCHIVES_PERIOD_MONTH) 481 { 482 $periodNb = sizeof( getDayOfMonthBetween( $this->archive->date->get(), 483 $this->archive->date2->get())); 484 485 // case partial period, set entire month' days to see, even if they are zero 486 if($periodNb < 28) 487 { 488 $periodNb = 28; 489 } 490 } 491 else 492 { 493 $periodNb = 20; 494 } 495 496 // inverse for months and weeks because we take newer date 497 // but for days max date is date asked 498 if($this->archive->periodType == DB_ARCHIVES_PERIOD_MONTH 499 || $this->archive->periodType == DB_ARCHIVES_PERIOD_WEEK) 500 { 501 $this->archive->date = new Date($this->archive->date2->get()); 502 } 503 $this->archive->periodType = DB_ARCHIVES_PERIOD_DAY; 504 } 505 506 // inverse period date because month now goes 507 // until date2 which is newer (idem for year using months) 508 //print($this->archive->date->get());exit; 509 //$this->archive->date = new Date($this->archive->date2->get()); 510 //var_dump($this->archive->date); 511 return $this->getVisitsPeriodSummariesGraph( $periodNb , DATE_GRAPH_LONG_AXIS ); 512 } 513 514 function getVisitsPeriodSummariesGraph($nbPeriodToDisplay = 8, $longAxisBecauseAllPeriod = DATE_GRAPH) 515 { 516 $info = $this->getVisitsPeriodSummaries($nbPeriodToDisplay, $longAxisBecauseAllPeriod); 517 518 foreach($info as $info) 519 { 520 $visits[] = $info['visits']; 521 $pages[] = $info['pages']; 522 $axis[] = $info['date']; 523 } 524 return array( 525 'data1' => array( 526 'data' => $visits, 527 'legend' => $GLOBALS['lang']['visites_visites'] 528 ), 529 'data2' => array( 530 'data' => $pages, 531 'legend' => $GLOBALS['lang']['visites_pagesvues'] 532 ), 533 'axis' => $axis, 534 'title' => $GLOBALS['lang']['visites_recap'] 535 ); 536 } 537 function getVisitsTimeGraph( $name, $legend) 538 { 539 $data = $this->getContent($name); 540 for($i = 0; $i < 24; $i++) 541 { 542 if(!isset($data[$i])) 543 { 544 $data[$i] = 0; 545 } 546 } 547 ksort($data); 548 return array( 549 'data' => $data, 550 'axis' => array_keys($data), 551 'title' => $GLOBALS['lang'][$legend] 552 ); 553 } 554 function getVisitsServerTimeGraph() 555 { 556 return $this->getVisitsTimeGraph( 'vis_st', 'visites_graphheureserveurimg'); 557 } 558 function getVisitsLocalTimeGraph() 559 { 560 return $this->getVisitsTimeGraph( 'vis_lt', 'visites_graphheurelocalimg'); 561 } 562 563 function getVisitsTimeVisitsGraph() 564 { 565 $GLOBALS['timeGap'][0][1] = "30"; 566 $GLOBALS['timeGap'][1][0] = "30"; 567 $GLOBALS['timeGap'][1][1] = "60"; 568 $data = array_values($this->getContent('vis_lth')); 569 570 foreach($data as $id => $value) 571 { 572 $axis[] = sprintf( ($id == 0 || $id == 1) 573 ? $GLOBALS['lang']['visites_sec'] 574 : $GLOBALS['lang']['visites_min'] , 575 $GLOBALS['timeGap'][$id][0]. 576 "-". $GLOBALS['timeGap'][$id][1] ); 577 } 578 579 return array( 580 'data' => $data, 581 'axis' => $axis, 582 'title' => $GLOBALS['lang']['visites_graphtempsvisitesimg'] 583 ); 584 } 585 function getPagesByVisitGraph() 586 { 587 //$GLOBALS['timeGap'][0][1] = "30"; 588 //$GLOBALS['timeGap'][1][0] = "30"; 589 //$GLOBALS['timeGap'][1][1] = "60"; 590 $data = array_values($this->getContent('vis_nb_pag')); 591 592 $axis=array(); 593 foreach($data as $id => $value) 594 { 595 $axis[] = ($id == 0) 596 ? $GLOBALS['lang']['visites_unepage'] 597 : (($GLOBALS['pagesGap'][$id][0] != @$GLOBALS['pagesGap'][$id][1]) 598 ? sprintf( $GLOBALS['lang']['visites_pages'], 599 $GLOBALS['pagesGap'][$id][0]. 600 "-". @$GLOBALS['pagesGap'][$id][1] ) 601 : sprintf( $GLOBALS['lang']['visites_pages'], $GLOBALS['pagesGap'][$id][1] ) 602 ) 603 ; 604 } 605 606 return array( 607 'data' => $data, 608 'axis' => $axis, 609 'title' => $GLOBALS['lang']['pagesvues_graphnbvisitespageimg'] 610 ); 611 } 612 613 function getVisitsFrequencyVisitsByVisitor() 614 { 615 $data = $this->getContent('vis_nb_vis') ; 616 $maxLabel = 5; 617 $s = sizeof($data); 618 $maxEntries = $s > $maxLabel ? $maxLabel : $s; 619 620 for($i = 1; $i <= $maxEntries; $i++) 621 { 622 $axis[$i-1] = ($i==1) 623 ? $GLOBALS['lang']['frequence_visit'] 624 : sprintf($GLOBALS['lang']['frequence_visits'], $i); 625 if($i==$maxEntries) 626 { 627 $data2[$i-1] = array_sum( array_splice( $data, $maxEntries - 1 , $s) ); 628 $axis[$i-1] = '+' . $axis[ $i -1 ]; 629 } 630 else 631 { 632 $data2[$i-1] = @$data[$i]; 633 } 634 } 635 636 637 return array( 638 'data' => $data2, 639 'axis' => $axis, 640 'title' => $GLOBALS['lang']['frequence_vispervis'] 641 ); 642 } 643 644 function getSourceContinentCountriesDistinct( ) 645 { 646 return $this->sizeDetailsSaved['continentcountries']; 647 } 648 /** 649 * returns continent hits if no continent specified, or details of country per continent 650 */ 651 652 // -1 is default because of the need of all info for map of the world computing 653 function getSourceContinentCountries($cont='', $offset = 0, $nbElementsToDisplay = -1) 654 { 655 $sum = array( 656 $GLOBALS['lang']['eur'] => 0, 657 $GLOBALS['lang']['asi'] => 0, 658 $GLOBALS['lang']['ams'] => 0, 659 $GLOBALS['lang']['amn'] => 0, 660 $GLOBALS['lang']['afr'] => 0, 661 $GLOBALS['lang']['oce'] => 0, 662 $GLOBALS['lang']['domaines']['xx'] => 0 663 ); 664 665 // case continent global summary, we need all countries 666 667 $a = $this->getSourceCountries(0,-1); 668 669 $t = sizeof($a); 670 reset($a); 671 672 for($i = 0; $i < $t; $i++) 673 { 674 //print("i $i "); 675 676 $key = key($a); 677 678 //print("k : $key "); 679 680 $value =& $a[$key]; 681 $continent = $GLOBALS['countryList'][substr($value['img'], 0, strpos($value['img'], '.'))][0]; 682 683 $value['continent'] = $continent; 684 685 if($continent == 'unk') 686 { 687 $continentLang = $GLOBALS['lang']['domaines']['xx']; 688 } 689 else 690 { 691 $continentLang = $GLOBALS['lang'][$continent]; 692 } 693 694 if(!empty($cont)) 695 { 696 if($continent != $cont) 697 { 698 //print("conteinnt : $continent != $cont"); 699 unset($a[$key]); 700 } 701 else 702 { 703 next($a); 704 } 705 } 706 else 707 { 708 $sum[$continentLang] += $value['sum']; 709 next($a); 710 } 711 } 712 713 if(!empty($cont)) 714 { 715 $this->sizeDetailsSaved['continentcountries'] = sizeof($a); 716 $toReturn = getArrayOffsetLimit($a, $offset, $nbElementsToDisplay); 717 718 719 return $toReturn; 720 } 721 722 $this->sizeDetailsSaved['continentcountries'] = sizeof($sum); 723 arsort($sum); 724 $toReturn = $this->getContinentId( 725 $this->getArraySum($sum) 726 ); 727 728 // printDebug($toReturn); 729 return $toReturn; 730 } 731 732 function getContinentId($a) 733 { 734 $return = array(); 735 $continentReversed = @array_flip($GLOBALS['lang']); 736 737 foreach($a as $key => $value) 738 { 739 if(isset($continentReversed[$value['data']])) // case not "Unknown" 740 { 741 $value['continent'] = $continentReversed[$value['data']]; 742 $return[] = $value; 743 } 744 } 745 return $return; 746 } 747 748 function getFollowUpZoom($category='') 749 { 750 return $this->getPagesDetailsZoomAll($category, array('entry', 'exit', 'singlepage')); 751 } 752 753 function getPagesZoom($category='') 754 { 755 return $this->getPagesDetailsZoomAll($category, array('sum', 'sumtime')); 756 } 757 758 function getPagesDetailsZoomSorted($category, $idToUseForPagesInfoToCompute) 759 { 760 $return = $this->getPagesDetailsZoomAll($category, array($idToUseForPagesInfoToCompute)); 761 762 return $return; 763 } 764 765 function getPageGroupIdToName($return) 766 { 767 $type = array( 768 'page', 769 'category', 770 'file' 771 ); 772 foreach($return as $data) 773 { 774 $toLoad[$data['type']][] = $data['data']; 775 } 776 777 $s = sizeof($return); 778 reset($return); 779 for($i = 0; $i < $s ; $i ++) 780 { 781 782 $data =& $return[key($return)]; 783 784 if($data['type'] == 'page' || $data['type'] == 'category' || $data['type'] == 'file') 785 { 786 787 // TODO change name 788 $data['data'] = $this->objects[$data['type']]->getName($data['data']); 789 // For file it can be FILE, RSS or PODCAST ... 790 if ($data['type']=="file") { 791 $tagPrefix = getPrefixTag ($data['data']); 792 // If prefix == "" is old file so nothing to do 793 if ($tagPrefix != "") { 794 $data['data'] = substr($data['data'], strlen($tagPrefix)); 795 $data['type'] = strtolower(substr($tagPrefix, 0, strlen($tagPrefix)-1)); 796 } 797 } 798 } 799 800 next($return); 801 } 802 return $return; 803 } 804 805 function getPagesDetailsZoomAll($category, $a_infoAsked = array()) 806 { 807 printTime('begin zoom all'); 808 $info = $this->getPagesDetailsZoom($category); 809 810 if($info) 811 { 812 printTime('end of pages details2'); 813 814 if(in_array('sumtime', $a_infoAsked)) 815 { 816 $sortedEntry = $this->getPageGroupIdToName( 817 getArrayOffsetLimit($info[1], 818 0, 819 -1, 820 'a_sumtime_sort', 821 'sum', 822 $this->arraySumInfo) 823 ); 824 825 // var_dump($sortedEntry); 826 $return['sumtime'] = array( 827 $info[0], 828 $sortedEntry, 829 $info[2] 830 ); 831 } 832 printTime('after sumtime compute'); 833 if(in_array('singlepage', $a_infoAsked)) 834 { 835 $toto = getArrayOffsetLimit($info[1], 0, -1, 'a_singlepage_sort', 'singlepage', $this->arraySumInfo); 836 837 $sortedEntry = $this->getPageGroupIdToName($toto 838 839 ); 840 841 $return['singlepage'] = array( 842 $info[0], 843 $sortedEntry, 844 $info[2] 845 ); 846 847 // printdebug($info[1]); 848 } 849 printTime('after singlepage compute'); 850 if(in_array('entry', $a_infoAsked)) 851 { 852 $sortedEntry = $this->getPageGroupIdToName( 853 getArrayOffsetLimit($info[1], 0, -1, 'a_entry_sort', 'entry', $this->arraySumInfo) 854 ); 855 856 $return['entry'] = array( 857 $info[0], 858 $sortedEntry, 859 $info[2] 860 ); 861 } 862 863 printTime('after entry compute'); 864 if(in_array('exit', $a_infoAsked)) 865 { 866 //printDebug($sortedEntry);exit; 867 $sortedExit = $this->getPageGroupIdToName( 868 getArrayOffsetLimit($info[1], 0, -1, 'a_exit_sort', 'exit', $this->arraySumInfo) 869 ); 870 $return['exit'] = array( 871 $info[0], 872 $sortedExit, 873 $info[2] 874 ); 875 } 876 877 printTime('after exit compute'); 878 if(in_array('sum', $a_infoAsked)) 879 { 880 $toto = getArrayOffsetLimit($info[1], 0, -1, 'a_pag_sort', 'sum', $this->arraySumInfo); 881 $sortedHits = $this->getPageGroupIdToName( $toto); 882 $return['sum'] = array( 883 $info[0], 884 $sortedHits, 885 $info[2] 886 ); 887 } 888 889 printTime('end zoom all'); 890 return $return; 891 } 892 } 893 894 function getPagesDetailsZoom($categoryAsked = '') 895 { 896 $this->objects['category'] = new ArchiveTable('category'); 897 $this->objects['page'] = new ArchiveTable('page'); 898 $this->objects['file'] = new ArchiveTable('file'); 899 $this->objects['vars_name'] = new ArchiveTable('vars_name'); 900 $this->objects['vars_value'] = new ArchiveTable('vars_value'); 901 $nbVis = $this->getContent('nb_vis'); 902 // printDebug($all); exit; 903 904 if($this->archive->periodType === DB_ARCHIVES_PERIOD_DAY) 905 { 906 $nbLast = 15; 907 } 908 else 909 { 910 $nbLast = 3; 911 } 912 $archives = $this->getLastArchives($nbLast, 1, DATE_NORMAL); 913 914 printTime('beg 1 of pages details'); 915 $i=0; 916 917 // load "pure" pages array 918 foreach($archives as $dateToDisplay => $archive) 919 { 920 printTime('foreach'.++$i.' of pages details'); 921 $o_data = new DataModel( $archive , $this->request); 922 $displayInfo[] = $dateToDisplay; 923 printTime('before uz'.$i.' of pages details'); 924 925 if( STORE_PAG_ARRAY_IN_FILE ) 926 { 927 $file = INCLUDE_PATH . "/datas/archives/". $o_data->infoSerialized['idarchives'].".dat"; 928 if( !is_readable($file)) 929 { 930 saveConfigFile($file, unserialize($o_data->infoSerialized['vis_pag_grp']) , 'visPagGrp'); 931 } 932 933 if(is_readable($file)) 934 { 935 $visPagGrp=array(); 936 require_once $file; 937 $array = $visPagGrp; 938 } 939 } 940 else 941 { 942 $visPagGrp = array(); 943 if(!is_null($o_data->infoSerialized['vis_pag_grp'])) 944 { 945 $visPagGrp = $o_data->getContent('vis_pag_grp'); 946 } 947 } 948 //var_dump($visPagGrp);exit; 949 $a_all[] = $visPagGrp; 950 951 printTime('after uz'.$i.' of pages details'); 952 $headerInfo[] = array( 953 'nb_pag' => $o_data->getContent('nb_pag'), 954 'nb_uniq_pag' => $o_data->getContent('nb_uniq_pag'), 955 'nb_max_pag' => $o_data->getContent('nb_max_pag') 956 ); 957 //printDebug($headerInfo); 958 } 959 960 printTime('beg 2 of pages details'); 961 foreach($a_all as $j => $all) 962 { 963 if(empty($categoryAsked)) 964 { 965 $a_infosDay[$j] = $all; 966 $level = 0; 967 } 968 else 969 { 970 $categoryAsked = (string)$categoryAsked; 971 //print("Zoom cate '$categoryAsked' <br>"); 972 //print($categoryAsked[2]); 973 $detailsCategory = explode(">", $categoryAsked); 974 //printDebug($detailsCategory); 975 $level = sizeof($detailsCategory); 976 977 //print("level : $level <br>"); 978 979 $array = $this->getPagesDetailsZoomArrayLevel($all, $level, $detailsCategory); 980 981 $a_infosDay[$j] = $array; 982 } 983 } 984 printTime('mid of pages details'); 985 986 // list asked category 987 if($level != 0) $categoryAsked .= '>'; 988 // var_dump($categoryAsked); 989 // var_dump($a_infosDay[0]); 990 991 $return = array(); 992 if(is_array($a_infosDay[0])) 993 { 994 //var_dump($a_infosDay[0]); 995 foreach($a_infosDay[0] as $currentId => $info) 996 { 997 // page or file or category, but not total 998 if($currentId != 'p_pmv_sum' 999 && $currentId != 'f_pmv_sum' 1000 ) 1001 { 1002 $id = ''; 1003 $parentId = ''; 1004 $data =''; 1005 $sum = 0; 1006 $sumN1 = 0; 1007 $sumN2 = 0; 1008 $percentN1 = 0; 1009 $percentN2 = 0; 1010 $type = ''; 1011 $entry = 0; 1012 $sumtime = 0; 1013 $exit = 0; 1014 $singlepage = 0; 1015 $a_vars = array(); 1016 1017 // category 1018 if(substr($currentId, 0, 1) === 'c') 1019 { 1020 $type = 'category'; 1021 1022 $entry = @$info['p_pmv_sum'][ARRAY_INDEX_ENTRYPAGE]; 1023 $exit = @$info['p_pmv_sum'][ARRAY_INDEX_EXITPAGE]; 1024 $sum = @$info['p_pmv_sum'][ARRAY_INDEX_COUNT] 1025 + @$info['f_pmv_sum'][ARRAY_INDEX_COUNT]; 1026 $sumtime = @$info['p_pmv_sum'][ARRAY_INDEX_TIME_TOTAL]; 1027 $singlepage = @$info['p_pmv_sum'][ARRAY_INDEX_PAGES_VISIT_ONEPAGE]; 1028 1029 $allInfoInGroup = $this->getPagesDetailsZoomArrayLevel($a_infosDay[0], 1, array($currentId)); 1030 //var_dump($allInfoInGroup);exit; 1031 //$a_vars = $this->getVarIdToName($a_infosDay[0]['p_pmv_sum'][ARRAY_INDEX_VARS]); 1032 $a_vars = $this->getVarIdToName( @$allInfoInGroup['p_pmv_sum'][ARRAY_INDEX_VARS]); 1033 1034 //var_dump($a_vars); 1035 if(isset($a_infosDay[1][$currentId]['p_pmv_sum'][ARRAY_INDEX_COUNT])) 1036 { 1037 $sumN1 = $a_infosDay[1][$currentId]['p_pmv_sum'][ARRAY_INDEX_COUNT] 1038 + @$a_infosDay[1][$currentId]['f_pmv_sum'][ARRAY_INDEX_COUNT]; 1039 } 1040 1041 $percentN1 = $this->getDiffPercent($sum, $sumN1); 1042 1043 if(isset($a_infosDay[2][$currentId]['p_pmv_sum'][ARRAY_INDEX_COUNT])) 1044 { 1045 $sumN2 = $a_infosDay[2][$currentId]['p_pmv_sum'][ARRAY_INDEX_COUNT] 1046 + @$a_infosDay[2][$currentId]['f_pmv_sum'][ARRAY_INDEX_COUNT]; 1047 } 1048 $percentN2 = $this->getDiffPercent($sum, $sumN2); 1049 1050 $id = $categoryAsked . $currentId; 1051 if($level != 0) 1052 { 1053 $parentId = substr( 1054 $categoryAsked, 1055 0, 1056 strlen($categoryAsked) -1 1057 ); 1058 } 1059 else 1060 { 1061 $parentId = "root"; 1062 } 1063 $data = @$info[ARRAY_INDEX_IDCATEGORY]; 1064 1065 //if($data != -1) 1066 // $toLoad['category'][] = $data; 1067 1068 } 1069 // pages 1070 else if(substr($currentId, 0, 1) === 'p') 1071 { 1072 //print("pages = ".$currentId); 1073 $type = 'page'; 1074 $id = $currentId; 1075 1076 //printDebug($info); 1077 if(!isset($info[ARRAY_INDEX_COUNT])) 1078 { 1079 $info[ARRAY_INDEX_COUNT] = 0; 1080 } 1081 $sum = @$info[ARRAY_INDEX_COUNT]; 1082 $entry = @$info[ARRAY_INDEX_ENTRYPAGE]; 1083 $exit = @$info[ARRAY_INDEX_EXITPAGE]; 1084 $sumtime = @$info[ARRAY_INDEX_TIME_TOTAL]; 1085 $singlepage = @$info[ARRAY_INDEX_PAGES_VISIT_ONEPAGE]; 1086 1087 if(isset($info[ARRAY_INDEX_VARS])) 1088 $a_vars = $this->getVarIdToName($info[ARRAY_INDEX_VARS]); 1089 1090 // Period-1 1091 if(isset($a_infosDay[1][$currentId][ARRAY_INDEX_COUNT])) 1092 { 1093 $sumN1 = $a_infosDay[1][$currentId][ARRAY_INDEX_COUNT]; 1094 } 1095 $percentN1 = $this->getDiffPercent($sum, $sumN1); 1096 1097 // Period -2 1098 if(isset($a_infosDay[2][$currentId][ARRAY_INDEX_COUNT])) 1099 { 1100 $sumN2 = $a_infosDay[2][$currentId][ARRAY_INDEX_COUNT]; 1101 } 1102 $percentN2 = $this->getDiffPercent($sum, $sumN2); 1103 1104 // Name 1105 if(!isset($info[ARRAY_INDEX_IDPAGE])) 1106 { 1107 //print("Problem, please report this error message :"); 1108 //var_dump($info); 1109 $data = -1; 1110 } 1111 else 1112 { 1113 $data = $info[ARRAY_INDEX_IDPAGE]; 1114 } 1115 //print("$data : ".$sumtime . "<br>"); 1116 1117 1118 } 1119 // file 1120 else if(substr($currentId, 0, 1) === 'f') 1121 { 1122 $type = 'file'; 1123 $id = $currentId; 1124 $sum = $info[ARRAY_INDEX_COUNT]; 1125 1126 // Period-1 1127 //print("idfile=$currentId<br>"); 1128 if(isset($a_infosDay[1][$currentId][ARRAY_INDEX_COUNT])) 1129 { 1130 $sumN1 = $a_infosDay[1][$currentId][ARRAY_INDEX_COUNT]; 1131 } 1132 $percentN1 = $this->getDiffPercent($sum, $sumN1); 1133 1134 // Period -2 1135 if(isset($a_infosDay[2][$currentId][ARRAY_INDEX_COUNT])) 1136 { 1137 $sumN2 = $a_infosDay[2][$currentId][ARRAY_INDEX_COUNT]; 1138 } 1139 $percentN2 = $this->getDiffPercent($sum, $sumN2); 1140 1141 // Name 1142 $data = $info[ARRAY_INDEX_IDPAGE]; 1143 1144 } 1145 else 1146 { 1147 // this is related to the ARRAY_INDEX_IDCATEGORY 1148 //print("Whats that? Report it to phpmyvisites forums: "); 1149 //print($currentId); 1150 } 1151 1152 1153 if(!empty($data) 1154 && !empty($type) 1155 && $sum > 0 1156 ) 1157 { 1158 $return[] = array( 1159 'type' => $type, 1160 'sum' => $sum, 1161 'sumn1' => $sumN1, 1162 'sumn2' => $sumN2, 1163 'percentn1' => $percentN1, 1164 'percentn2' => $percentN2, 1165 'data' => $data, 1166 'id' => $id, 1167 'parentid' => $parentId, 1168 'entry' => $entry, 1169 'exit' => $exit, 1170 'sumtime' => $sumtime, 1171 'avgtime' => round($sumtime / $sum), 1172 'exitrate' => 100 * $exit / $sum, 1173 'singlepage' => $singlepage, 1174 'vars' => $a_vars 1175 ); 1176 } 1177 } 1178 } 1179 printTime('end of pages details'); 1180 $GLOBALS['sorting_index'] = 'sum'; 1181 1182 uasort($return, "sortingDataInfo"); 1183 return array( 1184 $displayInfo, 1185 $return, 1186 $headerInfo 1187 ); 1188 } 1189 1190 return false; 1191 1192 } 1193 1194 // returns from the whole array $all the $detailsCategory info for the level $level 1195 function getPagesDetailsZoomArrayLevel(&$all, $level, $a_detailsCategory) 1196 { 1197 $array = $all; 1198 // var_dump($array); 1199 for($i = 0; $i < $level ; $i++) 1200 { 1201 $arrayZoomed = array(); 1202 1203 // find category to detail 1204 if(is_array($array)) 1205 { 1206 foreach($array as $id => $info) 1207 { 1208 if($id == $a_detailsCategory[$i]) 1209 { 1210 $arrayZoomed = $info; 1211 break; 1212 } 1213 } 1214 $array = $arrayZoomed; 1215 } 1216 } 1217 return $array; 1218 } 1219 1220 // returns the variables array with nameId and valueId replaced by real name and value 1221 function getVarIdToName($a) 1222 { 1223 $a_vars=array(); 1224 if(is_array($a)) 1225 { 1226 // browse variables name => array( Narray => (count, value), ...) 1227 foreach($a as $vNameId => $a_vValuesId) 1228 { 1229 $varName = $this->objects['vars_name']->getName($vNameId); 1230 1231 // browse each of the Narray => (count, value) 1232 foreach($a_vValuesId as $a_idVarContent) 1233 { 1234 $a_vars[$varName][(string)$this->objects['vars_value']->getName($a_idVarContent[ARRAY_INDEX_VAR_VALUE])] = (int)$a_idVarContent[ARRAY_INDEX_VAR_COUNT] ; 1235 } 1236 } 1237 } 1238 return $a_vars; 1239 } 1240 1241 function getSourceContinentInterest() 1242 { 1243 return $this->getContent('int_continent'); 1244 } 1245 1246 function getSourceCountriesDistinct() 1247 { 1248 return $this->getDistinct('country'); 1249 } 1250 1251 function getSourceProvidersDistinct() 1252 { 1253 return $this->getDistinct('provider'); 1254 } 1255 1256 function getSourceCountriesGraph() 1257 { 1258 $all = $this->getSourceCountries(0, -1); 1259 1260 foreach($all as $id => $info) 1261 { 1262 if($id < 5) 1263 { 1264 $data[] = (int)$info['sum']; 1265 $axis[] = $info['data']; 1266 1267 } 1268 else 1269 { 1270 @$data[5] += $info['sum']; 1271 $axis[5] = $GLOBALS['lang']['generique_divers']; 1272 } 1273 } 1274 1275 1276 return array( 1277 'data' => $data, 1278 'axis' => $axis, 1279 'title' => $GLOBALS['lang']['provenance_pays'] 1280 ); 1281 } 1282 function getSourceCountries($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1283 { 1284 return $this->getCountriesImg( 1285 $this->getArraySum( 1286 $this->getContent('vis_country', $offset, $nbElementsToDisplay) 1287 ) 1288 ); 1289 } 1290 function getCountriesImg($a) 1291 { 1292 $return = array(); 1293 1294 if(is_array($a)) 1295 { 1296 foreach($a as $id => $value) 1297 { 1298 $value['img'] = $value['data'] . ".png"; 1299 1300 // flags not in the package ! 1301 if(!file_exists(DIR_IMG_COUNTRIES_FLAGS . "/". $value['img'])) 1302 $value['img'] = 'xx.png'; 1303 $value['data'] = $GLOBALS['lang']['domaines'][$value['data']]; 1304 $return[$id] = $value; 1305 } 1306 } 1307 return $return; 1308 } 1309 1310 function getSourceCountriesInterest($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1311 { 1312 return $this->getCountriesImg( 1313 $this->getContent('int_country', $offset, $nbElementsToDisplay) 1314 ); 1315 } 1316 1317 function getSourceProviders($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1318 { 1319 return $this->getProvidersNameAndUrl( 1320 $this->getArraySum( 1321 $this->getArrayIdToName( 1322 $this->getContent('vis_provider', $offset, $nbElementsToDisplay), 1323 'provider' 1324 ) 1325 ) 1326 ); 1327 } 1328 1329 1330 /** 1331 * Settings 1332 */ 1333 1334 function getSettingsConfig($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1335 { 1336 $return = $this->getArraySum( 1337 $this->getArrayIdToName($this->getContent('vis_config', $offset, $nbElementsToDisplay), 'config') 1338 ); 1339 foreach($return as $key => $value) 1340 { 1341 $value['data'] = $this->getConfigName($value['data']); 1342 $return[$key] = $value; 1343 } 1344 return $return; 1345 } 1346 1347 /* 1348 function getSettingsConfigInterest($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1349 { 1350 $a = $this->getArrayIdToName($this->getContent('int_config', $offset, $nbElementsToDisplay), 'config'); 1351 foreach($a as $key => $value) 1352 { 1353 $return[$this->getConfigName($key)] = $value; 1354 } 1355 return $this->getArrayInterestNamed($return); 1356 } 1357 */ 1358 function getSettingsOsDistinct() 1359 { 1360 return $this->getDistinct('os'); 1361 } 1362 1363 function getSettingsOs($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1364 { 1365 return $this->getOsNameAndImage( 1366 $this->getArraySum($this->getContent('vis_os', $offset, $nbElementsToDisplay) 1367 ) 1368 ); 1369 } 1370 1371 1372 function getSettingsOsInterest($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1373 { 1374 return $this->getOsNameAndImage( 1375 $this->getContent('int_os', $offset, $nbElementsToDisplay) 1376 ); 1377 } 1378 1379 function getSettingsBrowsersDistinct() 1380 { 1381 return $this->getDistinct('browser'); 1382 } 1383 1384 function getSettingsBrowsers($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1385 { 1386 return $this->getBrowsersNameAndImage( 1387 $this->getArraySum($this->getContent('vis_browser', $offset, $nbElementsToDisplay) 1388 ) 1389 ); 1390 } 1391 1392 function getSettingsBrowsersGraph() 1393 { 1394 $all = $this->getSettingsBrowsers(0, -1); 1395 1396 foreach($all as $id => $info) 1397 { 1398 if($id < 5) 1399 { 1400 $data[] = (int)$info['sum']; 1401 $axis[] = ucfirst($GLOBALS['browsers_graph'][substr($info['img'], 0, strpos($info['img'], '.'))]) 1402 . substr($info['data'], -strlen($info['data']) + strrpos($info['data'], ' ')); 1403 1404 } 1405 else 1406 { 1407 @$data[5] += $info['sum']; 1408 $axis[5] = $GLOBALS['lang']['generique_divers']; 1409 } 1410 } 1411 1412 1413 return array( 1414 'data' => $data, 1415 'axis' => $axis, 1416 'title' => $GLOBALS['lang']['configurations_navigateurs'] 1417 ); 1418 } 1419 1420 function getSettingsOsGraph() 1421 { 1422 $all = $this->getSettingsOs(0, -1); 1423 1424 foreach($all as $id => $info) 1425 { 1426 if($id < 5) 1427 { 1428 $data[] = (int)$info['sum']; 1429 $axis[] = ucfirst($GLOBALS['osNameToIdForGraph'][substr($info['img'], 0, strpos($info['img'], '.'))]); 1430 1431 } 1432 else 1433 { 1434 @$data[5] += $info['sum']; 1435 $axis[5] = $GLOBALS['lang']['generique_divers']; 1436 } 1437 } 1438 1439 1440 return array( 1441 'data' => $data, 1442 'axis' => $axis, 1443 'title' => $GLOBALS['lang']['configurations_os'] 1444 ); 1445 } 1446 1447 1448 function getSettingsBrowsersTypeGraph() 1449 { 1450 $all = $this->getSettingsBrowsersType(); 1451 1452 foreach($all as $id => $info) 1453 { 1454 $data[] = (int)$info['sum']; 1455 $axis[] = $info['data']; 1456 } 1457 1458 return array( 1459 'data' => $data, 1460 'axis' => $axis, 1461 'title' => $GLOBALS['lang']['configurations_navigateursbytype'] 1462 ); 1463 } 1464 function getSettingsPluginsGraph() 1465 { 1466 $all = $this->getSettingsPlugins(); 1467 1468 foreach($all as $id => $info) 1469 { 1470 $data[] = (int)$info['sum']; 1471 $axis[] = $info['data']; 1472 } 1473 1474 return array( 1475 'data' => $data, 1476 'axis' => $axis, 1477 'title' => $GLOBALS['lang']['configurations_plugins'] 1478 ); 1479 } 1480 1481 function getSettingsResolutionsGraph() 1482 { 1483 $all = $this->getSettingsResolutions(0, -1); 1484 1485 foreach($all as $id => $info) 1486 { 1487 if($id < 5) 1488 { 1489 $data[] = (int)$info['sum']; 1490 $axis[] = $info['data']; 1491 1492 } 1493 else 1494 { 1495 @$data[5] += $info['sum']; 1496 $axis[5] = $GLOBALS['lang']['generique_divers']; 1497 } 1498 } 1499 1500 1501 return array( 1502 'data' => $data, 1503 'axis' => $axis, 1504 'title' => $GLOBALS['lang']['configurations_resolutions'] 1505 ); 1506 } 1507 1508 function getSettingsBrowsersInterest($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1509 { 1510 return $this->getBrowsersNameAndImage( 1511 $this->getContent('int_browser', $offset, $nbElementsToDisplay) 1512 ); 1513 } 1514 1515 function getSettingsConfigDistinct() 1516 { 1517 return $this->getDistinct( 'config' ); 1518 } 1519 1520 function getSettingsBrowsersType() 1521 { 1522 $return = $this->getArraySum($this->getContent('vis_browser_type')); 1523 1524 1525 foreach($return as $key => $value) 1526 { 1527 $value['data'] = $GLOBALS['browsers_type_display'][$value['data']]; 1528 $return[$key] = $value; 1529 } 1530 return $return; 1531 } 1532 1533 function getSettingsResolutions($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1534 { 1535 return $this->getArraySum( 1536 $this->getArrayIdToName( 1537 $this->getContent('vis_resolution', $offset, $nbElementsToDisplay), 'resolution') 1538 ); 1539 } 1540 1541 function getSettingsResolutionsDistinct() 1542 { 1543 return $this->getDistinct( 'resolution' ); 1544 } 1545 1546 function getSettingsResolutionsInterest($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1547 { 1548 return $this->getArrayIdToName( 1549 $this->getContent('int_resolution', $offset, $nbElementsToDisplay) 1550 ,'resolution' 1551 ); 1552 } 1553 1554 function getSettingsNormalWidescreen() 1555 { 1556 $return = array(); 1557 $normal = $wide = $dual = 0; 1558 $a = $this->getSettingsResolutions(0, -1); 1559 foreach($a as $value) 1560 { 1561 $str = $value['data']; 1562 $operande = intval(substr($str, 0, strpos($str, 'x'))); 1563 $terme = intval(substr($str, strpos($str, 'x') + 1)); 1564 $ratio = $this->_secureDiv($operande, $terme); 1565 1566 if($ratio < 1.4) 1567 { 1568 $normal += $value['sum']; 1569 } 1570 else if($ratio < 2) 1571 { 1572 $wide += $value['sum']; 1573 } 1574 else 1575 { 1576 $dual += $value['sum']; 1577 } 1578 } 1579 1580 if($dual!=0) $return['dual'] = $dual; 1581 if($wide!=0) $return['wide'] = $wide; 1582 if($normal!=0) $return['normal'] = $normal; 1583 1584 arsort($return); 1585 return $this->getScreensNameAndImage( 1586 $this->getArraySum($return) 1587 ); 1588 } 1589 1590 function getSettingsNormalWidescreenDistinct() 1591 { 1592 return 3; 1593 } 1594 1595 1596 function getSettingsPlugins() 1597 { 1598 return $this->getPluginsNameAndImg( 1599 $this->getArraySum( 1600 $this->getContent('vis_plugin') 1601 ) 1602 ); 1603 } 1604 1605 1606 function getSettingsPluginsDistinct() 1607 { 1608 return $this->getDistinct( 'plugin' ); 1609 } 1610 1611 /** 1612 * Referers 1613 */ 1614 /* 1615 function getReferersGraphSummary() 1616 { 1617 }*/ 1618 1619 function getDistinct($name, $name2 = null) 1620 { 1621 if(isset($name2)) 1622 { 1623 switch($name) 1624 { 1625 case 'continent': 1626 $t = sizeof($this->getSourceContinentCountries( $name2, 0, -1)); 1627 break; 1628 } 1629 1630 } 1631 else 1632 { 1633 $t = sizeof($this->getContent('vis_'.$name)); 1634 } 1635 return $t; 1636 } 1637 1638 1639 /* 1640 * numbers 1641 */ 1642 function getReferersSearchEnginesDetailsDistinct( ) 1643 { 1644 return $this->sizeDetailsSaved['vis_search_engine']; 1645 } 1646 1647 function getReferersPartnersDetailsDistinct( ) 1648 { 1649 return $this->sizeDetailsSaved['vis_partner']; 1650 } 1651 function getReferersKeywordsDetailsDistinct( ) 1652 { 1653 return $this->sizeDetailsSaved['vis_keyword']; 1654 } 1655 function getReferersSitesDetailsDistinct( ) 1656 { 1657 return $this->sizeDetailsSaved['vis_site']; 1658 } 1659 function getReferersKeywordsDistinct( ) 1660 { 1661 return $this->getDistinct( 'keyword'); 1662 } 1663 function getReferersNewslettersDistinct() 1664 { 1665 return $this->getDistinct( 'newsletter'); 1666 } 1667 function getSettingsBrowsersTypeDistinct() 1668 { 1669 return 4; 1670 } 1671 function getReferersSearchEnginesDistinct( ) 1672 { 1673 return $this->getDistinct( 'search_engine'); 1674 } 1675 function getReferersPartnersDistinct() 1676 { 1677 return $this->getDistinct( 'partner'); 1678 } 1679 function getReferersSitesDistinct( ) 1680 { 1681 return $this->getDistinct( 'site'); 1682 } 1683 1684 function getReferersNbSearchEngines() 1685 { 1686 return $this->getContent('nb_search_engine'); 1687 } 1688 function getReferersNbSites() 1689 { 1690 return $this->getContent('nb_site'); 1691 } 1692 function getReferersNbDirect() 1693 { 1694 return $this->getContent('nb_direct'); 1695 } 1696 function getReferersNbPartners() 1697 { 1698 return $this->getContent('nb_partner'); 1699 } 1700 1701 function getReferersNbNewsletters() 1702 { 1703 return $this->getContent('nb_newsletter'); 1704 } 1705 1706 function getReferersSummaryGraph() 1707 { 1708 $data = array( 1709 $GLOBALS['lang']['affluents_moteursimg'] => $this->getReferersNbSearchEngines(), 1710 $GLOBALS['lang']['affluents_sitesimg'] => $this->getReferersNbSites(), 1711 $GLOBALS['lang']['affluents_newslettersimg'] => $this->getReferersNbNewsletters(), 1712 $GLOBALS['lang']['affluents_partenairesimg'] => $this->getReferersNbPartners(), 1713 $GLOBALS['lang']['affluents_directimg'] => $this->getReferersNbDirect(), 1714 ); 1715 1716 arsort($data); 1717 1718 foreach($data as $label => $value) 1719 { 1720 if($value != 0) 1721 { 1722 $return['data'][] = $value; 1723 $return['axis'][] = $label; 1724 } 1725 } 1726 $return['title'] = $GLOBALS['lang']['affluents_referrersimg']; 1727 1728 return $return; 1729 } 1730 /* 1731 * arrays 1732 */ 1733 function getReferersSearchEngines($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1734 { 1735 return $this->getSearchEnginesUrlAndImg( 1736 $this->getArrayPmvSum( 1737 $this->getArrayIdToName( 1738 $this->getContent('vis_search_engine', $offset, $nbElementsToDisplay) 1739 , 'search_engine'), 1740 $this->getReferersNbSearchEngines() 1741 ) 1742 // ) 1743 ) 1744 ; 1745 } 1746 1747 function getReferersSearchEnginesInterest($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1748 { 1749 return $this->getSearchEnginesUrlAndImg( 1750 $this->getArrayIdToName( 1751 $this->getContent('int_search_engine', 1752 $offset, 1753 $nbElementsToDisplay), 1754 'search_engine') 1755 ); 1756 } 1757 1758 1759 function getReferersSearchEnginesDetails($id, $offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1760 { 1761 $this->idDetailsSaved['vis_search_engine'] = $id; 1762 //printTime('before', true); 1763 $test = $this->getContent('vis_search_engine'); 1764 //printTime('after1', true); 1765 $return = $this->getArrayDetail( $test, $id, 1766 'keyword', 1767 $offset, 1768 $nbElementsToDisplay 1769 ); 1770 // printTime('after2', true); 1771 return $return; 1772 } 1773 1774 function getReferersKeywords($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1775 { 1776 return $this->getKeywordDecode( 1777 $this->getArrayPmvSum( 1778 $this->getArrayIdToName( 1779 $this->getContent('vis_keyword', $offset, $nbElementsToDisplay), 1780 'keyword'), 1781 $this->getReferersNbSearchEngines() 1782 ) 1783 ); 1784 } 1785 1786 function getReferersKeywordsInterest($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1787 { 1788 return $this->getKeywordDecode( 1789 $this->getArrayIdToName( 1790 $this->getContent('int_keyword', $offset, $nbElementsToDisplay), 'keyword') 1791 ); 1792 } 1793 1794 function getReferersKeywordsDetails($id, $offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1795 { 1796 1797 $this->idDetailsSaved['vis_keyword'] = $id; 1798 return $this->getSearchEnginesUrlAndImg( 1799 $this->getArrayDetail( 1800 $this->getContent('vis_keyword'), 1801 $id, 1802 'search_engine', 1803 $offset, 1804 $nbElementsToDisplay 1805 ) 1806 ); 1807 } 1808 1809 function getReferersSites($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1810 { 1811 return $this->getArrayPmvSum( 1812 $this->getArrayIdToName( 1813 $this->getContent('vis_site', $offset, $nbElementsToDisplay), 1814 'site'), 1815 $this->getReferersNbSites() 1816 ); 1817 } 1818 1819 function getReferersSitesInterest($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1820 { 1821 return $this->getArrayIdToName( 1822 $this->getContent('int_site', $offset, $nbElementsToDisplay), 'site'); 1823 } 1824 1825 function getReferersSitesDetails($id, $offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1826 { 1827 $this->idDetailsSaved['vis_site'] = $id; 1828 $a = $this->getArrayDetail( 1829 $this->getContent('vis_site'), 1830 $id, 1831 'site', 1832 $offset, 1833 $nbElementsToDisplay 1834 ); 1835 return $this->getSitesDetailsUrl( 1836 $a 1837 ); 1838 } 1839 function getSitesDetailsUrl( &$a ) 1840 { 1841 foreach($a as $key => $value) 1842 { 1843 $value['url'] = $value['data']; 1844 $a[$key] = $value; 1845 } 1846 return $a; 1847 } 1848 1849 1850 function getReferersPartners($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1851 { 1852 return $this->getArrayPmvSum( 1853 $this->getArrayIdToName($this->getContent('vis_partner', $offset, $nbElementsToDisplay), 1854 'partner_name'), 1855 $this->getReferersNbPartners() 1856 ); 1857 } 1858 function getReferersPartnersInterest($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1859 { 1860 return $this->getArrayIdToName( 1861 $this->getContent('int_partner', $offset, $nbElementsToDisplay), 1862 'partner_name'); 1863 } 1864 function getReferersPartnersDetails($id, $offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1865 { 1866 1867 $this->idDetailsSaved['vis_partner'] = $id; 1868 return $this->getSitesDetailsUrl( 1869 $this->getArrayDetail( 1870 $this->getContent('vis_partner'), 1871 $id, 1872 'partner_url', 1873 $offset, 1874 $nbElementsToDisplay 1875 ) 1876 ); 1877 } 1878 1879 function getReferersNewsletters($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1880 { 1881 $return = array(); 1882 $nlInfo = $this->getContent('vis_newsletter', $offset, $nbElementsToDisplay); 1883 $nlName = new ArchiveTable( 'newsletter' ); 1884 $totalNl = $this->getReferersNewslettersDistinct(); 1885 $totalNlHits = $this->getReferersNbNewsletters(); 1886 1887 if($totalNl != 0) 1888 { 1889 foreach($nlInfo as $key => $hits) 1890 { 1891 // compatibility < beta3 1892 if(is_array($hits)) $hits=1; 1893 $return[] = array( 1894 'data' => $nlName->getName( $key ), 1895 'sum' => $hits, 1896 'percent' => round(100 * $hits / $totalNlHits,3) 1897 ); 1898 } 1899 } 1900 return $return; 1901 } 1902 1903 1904 function getReferersNewslettersInterest($offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1905 { 1906 return $this->getArrayIdToName( 1907 $this->getContent('int_newsletter', $offset, $nbElementsToDisplay), 'newsletter'); 1908 } 1909 1910 function getReferersTypeDistinct() 1911 { 1912 return 7;//sizeof($this->getReferersTypeInterest()); 1913 } 1914 1915 function getReferersTypeInterest() 1916 { 1917 $a = $this->getContent('int_referer_type'); 1918 //var_dump($a);exit; 1919 $return2 = array(); 1920 $convert = array( 1921 REF_TYPE_SEARCH_ENGINE => 'affluents_moteurs', 1922 REF_TYPE_SITE =>'affluents_sitesinternet', 1923 REF_TYPE_PARTNER =>'affluents_partenaires', 1924 REF_TYPE_NEWSLETTER =>'affluents_newsletters', 1925 REF_TYPE_DIRECT_ENTRY =>'affluents_entreedirecte' 1926 ); 1927 foreach($a as $key => $value) 1928 { 1929 if(sizeof($value) != 0) 1930 { 1931 $value['data'] = $GLOBALS['lang'][$convert[$key]]; 1932 $return2[] = $value; 1933 } 1934 } 1935 return $return2; 1936 } 1937 1938 function addPercent( $nb, $total) 1939 { 1940 $calc = 100 * $this->_secureDiv($nb, $total); 1941 return "<strong> $nb </strong> <small>(". round($calc) . "%)</small>"; 1942 } 1943 1944 function getReferersNumbers() 1945 { 1946 $ret = array(); 1947 1948 if($this->getContent('nb_vis') != 0) 1949 { 1950 $a = array( 1951 'visits' => $this->getContent('nb_vis'), 1952 'searchengines' => $this->getReferersNbSearchEngines(), 1953 'keywords' => $this->getReferersKeywordsDistinct(), 1954 'sites' => $this->getReferersNbSites(), 1955 'distinctsites' => $this->getReferersSitesDistinct(), 1956 'partners' => $this->getReferersNbPartners(), 1957 'newsletters' => $this->getReferersNbNewsletters(), 1958 'direct' => $this->getReferersNbDirect(), 1959 1960 ); 1961 1962 foreach($a as $key => $value) 1963 { 1964 if($key != 'distinctsites' && $key != 'keywords') 1965 { 1966 $a2[$key] = $this->addPercent( $value, $this->getContent('nb_vis')); 1967 } 1968 } 1969 1970 $ret = array_merge($a, $a2); 1971 } 1972 return $ret; 1973 } 1974 /* 1975 * Process functions 1976 */ 1977 function getArrayDetail($a, $id, $table, $offset = 0, $nbElementsToDisplay = NB_ELEMENTS_TO_DISPLAY) 1978 { 1979 $return = array(); 1980 foreach($a as $key => $value) 1981 { 1982 if($key == $id) 1983 { 1984 // printTime('1', true); 1985 $sum = $value['pmv_sum']; 1986 unset($value['pmv_sum']); 1987 $a2 = $this->getArrayIdToName( 1988 getArrayOffsetLimit($value, $offset, $nbElementsToDisplay), 1989 $table 1990 ); 1991 // printDebug($a2); 1992 1993 // printTime('2', true); 1994 foreach($a2 as $name => $hits) 1995 { 1996 if($table === 'keyword') 1997 { 1998 $name = urldecode($name); 1999 } 2000 $return[] = array( 2001 'data' => $name, 2002 'sum' => $hits, 2003 'percent' => 100 * $this->_secureDiv($hits, $sum) 2004 ); 2005 } 2006 // printTime('3', true); 2007 break; 2008 } 2009 } 2010 // printTime('4', true); 2011 //printDebug($return); 2012 usort($return, "sortingDataInfo"); 2013 // printTime('5', true); 2014 return $return; 2015 } 2016 function getArrayIdToName($a, $table) 2017 { 2018 $return = array(); 2019 if(is_array($a) && sizeof($a) != 0) 2020 { 2021 if(!isset($this->objects[$table])) 2022 { 2023 $this->objects[$table] = new ArchiveTable($table); 2024 } 2025 $this->objects[$table]->loadName(array_keys($a)); 2026 2027 foreach($a as $id => $value) 2028 { 2029 // case when all table with details for each key 2030 if(is_array($value)) 2031 { 2032 $value['id'] = $id; 2033 } 2034 // else we only have hits number, don't do anything 2035 $name = $this->objects[$table]->getName($id); 2036 2037 //printDebug("id ".$id); 2038 //printDebug("name ".$name); 2039 //printDebug("value ".$value); 2040 2041 // héhé... :-D 2042 if(is_array($value)) 2043 { 2044 $value['data'] = $name; 2045 } 2046 $return[$name] = $value; 2047 } 2048 } 2049 return $return; 2050 } 2051 2052 function getArraySum($a, $max = 0) 2053 { 2054 if($max === 0) 2055 { 2056 $max = $this->getContent('nb_vis'); 2057 } 2058 2059 $return = array(); 2060 2061 if($max == 0) return $return; 2062 2063 foreach($a as $key => $value) 2064 { 2065 if($value != 0) 2066 { 2067 $return[] = array( 2068 'sum' =>$value, 2069 'percent' => 100 * $this->_secureDiv($value, $max), 2070 'data' => $key 2071 ); 2072 } 2073 } 2074 2075 return $return; 2076 } 2077 2078 function getArrayPmvSum($a, $max = 0) 2079 { 2080 if($max === 0) 2081 { 2082 $max = $this->getContent('nb_vis'); 2083 } 2084 $return = array(); 2085 foreach($a as $key => $value) 2086 { 2087 $return[] = array( 2088 'sum' =>$value['pmv_sum'], 2089 'percent' => 100 * $this->_secureDiv($value['pmv_sum'] , $max), 2090 'data' => $key, 2091 'id' => $value['id'] 2092 ); 2093 } 2094 // print("sort here<br>"); 2095 2096 $GLOBALS['sorting_index'] = 'sum'; 2097 $GLOBALS['sorting_order'] = 'desc'; 2098 usort($return, "sortingDataInfo"); 2099 2100 return $return; 2101 } 2102 2103 2104 function getInterestValues($s, $sumpage, $onepage, $sumtime, $data) 2105 { 2106 // pages per visit 2107 $pv = $this->_secureDiv($sumpage ,$s); 2108 2109 // pages per significativ visit 2110 if($s != $onepage) 2111 { 2112 $psv = $this->_secureDiv(($sumpage - $onepage) , ($s - $onepage)); 2113 } 2114 else 2115 { 2116 $psv = 0; 2117 } 2118 // 1 page visit rate 2119 $opr = $this->_secureDiv($onepage ,$s); 2120 // time spent per visit 2121 $vl = round( $this->_secureDiv($sumtime , $s )); 2122 /* 2123 printDebug("<br>hits $s<br>"); 2124 printDebug("pages per visit $pv<br>" ); 2125 printDebug("pages per significativ visit $psv<br>" ); 2126 printDebug("1 page visit rate $opr<br>" ); 2127 printDebug("time spent per visit $vl<br>" ); 2128 */ 2129 return array( 2130 'sum' => $s, 2131 'page_per_visit' => $pv, 2132 'page_per_visit_significant' => $psv, 2133 'one_page_rate' => $opr * 100, 2134 'time_per_visit' => strftime("%H:%M:%S", $vl+82800), 2135 'data' => $data 2136 ); 2137 } 2138 2139 function getArrayInterestNamed($a) 2140 { 2141 $return = array(); 2142 2143 if(is_array($a)) 2144 { 2145 foreach($a as $key => $value) 2146 { 2147 if(is_array($value) && sizeof($value) == 4) 2148 { 2149 $return[$key] = $this->getInterestValues( 2150 $value[0], 2151 $value[1], 2152 $value[2], 2153 $value[3], 2154 $key 2155 ); 2156 } 2157 } 2158 } 2159 return $return; 2160 } 2161 2162 function getKeywordDecode($return) 2163 { 2164 $return2 = array(); 2165 foreach($return as $value) 2166 { 2167 $value['data'] = urldecode($value['data']); 2168 $return2[] = $value; 2169 } 2170 return $return2; 2171 } 2172 2173 function getBrowserName($str) 2174 { 2175 return ucwords( 2176 $GLOBALS['browsers_reverse'][ 2177 substr($str, 0, strpos($str, ';')) 2178 ]); 2179 } 2180 2181 function getBrowserVersion($str) 2182 { 2183 return substr($str, strpos($str, ';') + 1); 2184 } 2185 2186 function getConfigName($str) 2187 { 2188 $os = substr($str, 0, strpos($str, ';')); 2189 2190 $browser = substr(substr($str, strlen($os)+1), 0, 2191 strrpos(substr($str, strlen($os)+1), ';')); 2192 2193 $resolution = substr($str, strrpos($str, ';') + 1); 2194 $str = $GLOBALS['osIdToName'][$os]; 2195 $str .= " / "; 2196 $str .= ucwords($GLOBALS['browsers_reverse'][$browser]); 2197 $str .= " / "; 2198 $str .= $resolution; 2199 return $str; 2200 } 2201 2202 function getProvidersNameAndUrl($return) 2203 { 2204 foreach($return as $key => $value) 2205 { 2206 if($value['data'] === 'Ip') 2207 { 2208 $value['url'] = "http://www.phpmyvisites.us/"; 2209 $value['data'] = "Ip"; 2210 } 2211 else 2212 { 2213 $value['url'] = "http://www.".$value['data']."/"; 2214 $value['data'] = ucfirst(substr($value['data'], 0, strpos($value['data'], '.'))); 2215 } 2216 $return[$key] = $value; 2217 } 2218 return $return; 2219 } 2220 2221 2222 function getPluginsNameAndImg($return) 2223 { 2224 $v_keyJs = ""; 2225 foreach($return as $key => $value) 2226 { 2227 if (ucwords($value['data']) == "Javascript") { 2228 $v_keyJs = $key; 2229 // Conflict with java image jav.png 2230 $value['img'] = "jsc.png"; 2231 } 2232 else { 2233 $value['img'] = substr($value['data'], 0, 3) . ".png"; 2234 } 2235 $value['data'] = ucwords($value['data']); 2236 $return[$key] = $value; 2237 } 2238 // TODO To delete when javascript test is ok 2239 2240 if($v_keyJs != "") { 2241 unset($return[$v_keyJs]); 2242 $return = array_values($return); 2243 } 2244 2245 return $return; 2246 } 2247 function getOsNameAndImage($return) 2248 { 2249 foreach($return as $key => $value) 2250 { 2251 $value['img'] = $value['data'] . ".png"; 2252 $value['data'] = $GLOBALS['osIdToName'][$value['data']]; 2253 $return[$key] = $value; 2254 } 2255 return $return; 2256 } 2257 2258 function getSearchEnginesUrlAndImg($return) 2259 { 2260 foreach($GLOBALS['searchEngines'] as $url => $value) 2261 { 2262 $searchEnginesReversed[$value[0]] = $url; 2263 } 2264 2265 $return2 = array(); 2266 foreach($return as $value) 2267 { 2268 $value['url'] = @$searchEnginesReversed[$value['data']]; 2269 2270 $img = $value['url']; 2271 $imgUrlP = DIR_IMG_SEARCH_ENGINES . "/" . $img . ".png"; 2272 2273 $value['img'] = is_file( $imgUrlP ) 2274 ? $img . ".png" 2275 : 'xx.gif'; 2276 2277 $value['url'] = 'http://' . $value['url']; 2278 2279 $return2[] = $value; 2280 } 2281 return $return2; 2282 } 2283 2284 function getBrowsersNameAndImage($return) 2285 { 2286 foreach($return as $key => $value) 2287 { 2288 $prefix = substr($value['data'], 0, strpos($value['data'], ';')); 2289 if($prefix != 'unk') 2290 { 2291 $value['img'] = $prefix. ".png"; 2292 } 2293 else 2294 { 2295 $value['img'] = 'unk.gif'; 2296 } 2297 $value['data'] = $this->getBrowserName($value['data']) ." ".$this->getBrowserVersion($value['data']); 2298 $return[$key] = $value; 2299 } 2300 return $return; 2301 } 2302 2303 function getScreensNameAndImage($return) 2304 { 2305 foreach($return as $key => $value) 2306 { 2307 $value['img'] = $value['data'] . ".png"; 2308 switch($value['data']) 2309 { 2310 case 'dual': 2311 $txt = $GLOBALS['lang']['configurations_double']; 2312 break; 2313 case 'wide': 2314 $txt = $GLOBALS['lang']['configurations_large']; 2315 break; 2316 case 'normal': 2317 $txt = $GLOBALS['lang']['configurations_normal']; 2318 break; 2319 } 2320 $value['data'] = $txt; 2321 $return[$key] = $value; 2322 } 2323 return $return; 2324 } 2325 // nb1 = base 2326 // nb2 / nb1 ? 2327 function getDiffPercent($nb1, $nb2) 2328 { 2329 if($nb2 == 0) 2330 { 2331 return "+ 1000%"; 2332 } 2333 if($nb2 <= $nb1) 2334 { 2335 $percent = ($nb1/$nb2) * 100 - 100; 2336 $percent>PERCENT_MAX?$percent=PERCENT_MAX:''; 2337 2338 $str = "+"; 2339 } 2340 else 2341 { 2342 $percent = (( $nb2 - $nb1) / $nb2) * 100; 2343 $percent>PERCENT_MAX?$percent=PERCENT_MAX:''; 2344 2345 $str = "-"; 2346 } 2347 return $str . " " .round($percent)."%"; 2348 } 2349 2350 function getLastArchives($n, $boolOnlyGetPeriodNMinus=0, $dateTextType = DATE_NORMAL, $o_site = false) 2351 { 2352 //var_dump($this->archive->date->get()); 2353 2354 $date = new Date( $this->archive->date->get() ); 2355 //var_dump($date->get()); 2356 if($o_site) 2357 { 2358 $o_siteToUse = $o_site; 2359 } 2360 else 2361 { 2362 $o_siteToUse = $this->archive->site; 2363 } 2364 2365 $toArchive = array(); 2366 switch($this->archive->periodType) 2367 { 2368 case DB_ARCHIVES_PERIOD_DAY: 2369 $ts = $date->getTimestamp() + 86400; 2370 while(sizeof($toArchive) < $n) 2371 { 2372 $toArchive[] = getDateFromTimestamp( $ts -= 86400); 2373 } 2374 $typeDateDisplay = 2; 2375 $typeDateDisplayGraph = 8; 2376 $typeDateDisplayGraphLongAxis = 13; 2377 2378 // only take N - x, only for page views comparisons 2379 if($boolOnlyGetPeriodNMinus===1) 2380 { 2381 $date0 = $toArchive[0]; 2382 $date1 = $toArchive[7]; 2383 $date2 = $toArchive[14]; 2384 unset($toArchive); 2385 $toArchive[] = $date0; 2386 $toArchive[] = $date1; 2387 $toArchive[] = $date2; 2388 $typeDateDisplay = 7; 2389 //print("date1 $date1 date2 $date2 "); 2390 } 2391 break; 2392 2393 case DB_ARCHIVES_PERIOD_WEEK: 2394 $ts = $date->getTimestamp(); 2395 $ts += 86400*7; 2396 while(sizeof($toArchive) < $n) 2397 { 2398 $toArchive[] = getDateFromTimestamp( $ts-=86400*7); 2399 } 2400 $typeDateDisplay = 6; 2401 $typeDateDisplayGraph = 6; 2402 $typeDateDisplayGraphLongAxis = 13; 2403 2404 break; 2405 2406 case DB_ARCHIVES_PERIOD_MONTH: 2407 $s_date1 = getDateFromTimestamp( 2408 mktime(23, 59, 59, 2409 $date->getMonth() - $n % 12, 2410 15, 2411 $date->getYear() - floor($n/12)) 2412 ); 2413 $s_date2 = $date->get(); 2414 2415 $toArchive = array_reverse(getDayOfMonthBetween($s_date1, $s_date2)); 2416 2417 $typeDateDisplay = 5; 2418 $typeDateDisplayGraph = 10; 2419 $typeDateDisplayGraphLongAxis = 10; 2420 2421 break; 2422 2423 case DB_ARCHIVES_PERIOD_YEAR: 2424 for($i = 0; $i < $n; $i++) 2425 { 2426 $a = $date->getYear()-$i; 2427 $toArchive[] = $a."-01-01"; 2428 } 2429 2430 $typeDateDisplay = 11; 2431 $typeDateDisplayGraph = 12; 2432 break; 2433 } 2434 2435 //var_dump($this->archive->date->get()); 2436 2437 $return = array(); 2438 foreach($toArchive as $dateToArchive) 2439 { 2440 //print("boucle :"); 2441 2442 // if day, and IF current date asked is today, then take current archive 2443 if( 2444 $dateToArchive == $this->archive->date->get() 2445 && $this->archive->periodType === DB_ARCHIVES_PERIOD_DAY 2446 && $o_siteToUse->getId() === $this->archive->site->getId() 2447 ) 2448 { 2449 $a = $this->archive; // erreur possible ici ? 2450 } 2451 else 2452 { 2453 $a = $this->getArchive( $o_siteToUse, 2454 $dateToArchive, 2455 $this->archive->periodType 2456 ); 2457 } 2458 2459 if($dateTextType == DATE_GRAPH) 2460 { 2461 $dateToDisplay = getDateDisplay($typeDateDisplayGraph, new Date($dateToArchive)); 2462 2463 $dateComputed = getDateDisplay($typeDateDisplayGraph, $a->date); 2464 } 2465 else if($dateTextType == DATE_NORMAL) 2466 { 2467 $dateToDisplay = getDateDisplay($typeDateDisplay, new Date($dateToArchive)); 2468 $dateComputed = getDateDisplay($typeDateDisplay, $a->date); 2469 } 2470 else if($dateTextType == DATE_GRAPH_LONG_AXIS) 2471 { 2472 $dateToDisplay = getDateDisplay($typeDateDisplayGraphLongAxis, new Date($dateToArchive)); 2473 $dateComputed = getDateDisplay($typeDateDisplayGraphLongAxis, $a->date); 2474 } 2475 2476 if($this->archive->periodType === DB_ARCHIVES_PERIOD_WEEK) 2477 { 2478 $firstDayOfWeek = new Date(getFirstDayOfWeek(new Date($dateToArchive))); 2479 $minDay = $o_siteToUse->getMinDay(); 2480 if($firstDayOfWeek->getTimestamp() >= $minDay->getTimestamp()) 2481 { 2482 $dateToDisplay = getDateDisplay($typeDateDisplay, 2483 $firstDayOfWeek 2484 ); 2485 } 2486 } 2487 2488 if($dateComputed == $dateToDisplay) 2489 { 2490 // print("$dateToDisplay is correctly computed ($dateComputed)<br>"); 2491 $return[$dateComputed] = $a; 2492 2493 } 2494 else 2495 { 2496 // print("$dateToDisplay is not correctly computed ($dateComputed) ==> empty archive<br>"); 2497 $return[$dateToDisplay] = 2498 $this->getEmptyArchive( $o_siteToUse, 2499 $dateToArchive, 2500 $this->archive->periodType 2501 ); 2502 } 2503 } 2504 //print("\n\n");exit; 2505 return $return; 2506 } 2507 2508 function getVisitsSummaryRss() 2509 { 2510 2511 2512 return array( 2513 'site' => ''); 2514 } 2515 2516 function getArchive($site, $s_date, $type) 2517 { 2518 switch($type) 2519 { 2520 case DB_ARCHIVES_PERIOD_DAY: 2521 $p = new ArchiveDay($site, $s_date); 2522 break; 2523 2524 case DB_ARCHIVES_PERIOD_MONTH: 2525 $p = new ArchiveMonth($site, $s_date); 2526 break; 2527 2528 case DB_ARCHIVES_PERIOD_WEEK: 2529 $p = new ArchiveWeek($site, $s_date); 2530 break; 2531 2532 case DB_ARCHIVES_PERIOD_YEAR: 2533 $p = new ArchiveYear($site, $s_date); 2534 break; 2535 } 2536 return $p; 2537 } 2538 2539 function getEmptyArchive($site, $s_date, $type) 2540 { 2541 return new ArchiveEmpty($site, $s_date, $type); 2542 } 2543 2544 function _secureDiv($operande, $terme) 2545 { 2546 if ( is_numeric($operande) && is_numeric($terme) && intval($terme) != 0) 2547 { 2548 return $operande / $terme; 2549 } 2550 return 0; 2551 } 2552 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 14:10:01 2007 | par Balluche grâce à PHPXref 0.7 |
|