[ 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: functions.php 233 2007-07-06 15:24:03Z matthieu_ $ 11 12 13 function setIncludePath() 14 { 15 $path = array( 16 '.', 17 './', 18 './libs/', 19 '/usr/lib/php/', 20 @realpath(@dirname('__FILE__')), 21 'libs', 22 @get_include_path(), 23 ); 24 25 $patht = implode( PATH_SEPARATOR, $path); 26 27 if(!set_include_path( $patht )) 28 { 29 //print("The function 'set_include_path' must be allowed!"); 30 } 31 } 32 function setMemoryLimit() 33 { 34 $valueInit = getMemoryValue(); 35 if( ($valueInit === false 36 || $valueInit < MEMORY_LIMIT ) 37 && @ini_set('memory_limit', MEMORY_LIMIT.'M')) 38 { 39 return true; 40 } 41 return false; 42 } 43 44 function rmkdir($dirName, $rights=0777) 45 { 46 $dirs = explode('/', $dirName); 47 $dir=''; 48 foreach ($dirs as $part) { 49 $dir.=$part.'/'; 50 if (!is_dir($dir) && strlen($dir)>0) 51 mkdir($dir, $rights); 52 } 53 } 54 55 function rmrdir( $dir ) 56 { 57 if(is_dir($dir)) 58 { 59 $handle = @opendir($dir); 60 if($handle) 61 { 62 for(;(false !== ($readdir = @readdir($handle)));) 63 { 64 $path = $dir.'/'.$readdir; 65 if(is_dir($path)) 66 $output[$readdir] = rmrdir($path); 67 68 if(is_file($path)) 69 { 70 unlink($path); 71 } 72 } 73 closedir($handle); 74 } 75 } 76 } 77 78 function getMysqlVersion() 79 { 80 $r = query('SELECT version()'); 81 if($r) 82 { 83 $l = mysql_fetch_row($r); 84 return $l[0]; 85 } 86 return false; 87 } 88 89 function getMemoryValue() 90 { 91 if($memory = ini_get('memory_limit')) 92 { 93 return substr($memory, 0, strlen($memory) - 1); 94 } 95 return false; 96 } 97 function getSystemInformation( &$tpl ) 98 { 99 $infos = array(); 100 101 // directory to write 102 $infos['dirs'] = checkDirWritable( ); 103 104 // php version 105 $infos['php_version'] = phpversion(); 106 $infos['php_ok'] = version_compare( PHP_VERSION_NEEDED, $infos['php_version']) === -1; 107 108 $extensions = @get_loaded_extensions(); 109 110 // Gd version 111 if (in_array('gd', $extensions)) 112 { 113 $gdInfo = gd_info(); 114 115 $infos['gd_version'] = $gdInfo['GD Version']; 116 117 ereg ("([0-9]{1})", $gdInfo['GD Version'], $gdVersion); 118 ($gdVersion[0] >= 2) 119 ? $infos['gd_ok'] = true 120 : $infos['gd_ok'] = false; 121 122 // Freetype 123 ($gdInfo['FreeType Support'] === true && function_exists('imagettfbbox')) 124 ? $infos['freetype_ok'] = true 125 : $infos['freetype_ok'] = false; 126 } 127 128 // Mysql + version 129 if (in_array('mysql', $extensions)) 130 { 131 $infos['mysql_ok'] = true; 132 $infos['mysql_version'] = getMysqlVersion(); 133 } 134 135 // server version 136 $infos['server_version'] = addslashes($_SERVER['SERVER_SOFTWARE']); 137 138 // server os (linux) 139 $infos['server_os'] = @php_uname(); 140 141 // servert time 142 $infos['server_time'] = date('H:i:s'); 143 144 /* 145 //Tous ce qui est relatif a XML 146 if (in_array('xml', $extensions) 147 && function_exists('utf8_decode') 148 && function_exists('utf8_encode') ) 149 { 150 $infos['xml_ok'] = true; 151 } 152 */ 153 154 if(function_exists( 'set_time_limit')) 155 { 156 $infos['set_time_limit_ok'] = true; 157 } 158 159 if(function_exists( 'utf8_encode') && function_exists( 'utf8_decode')) 160 { 161 $infos['php_xml'] = true; 162 } 163 164 if(function_exists('mail')) 165 { 166 $infos['mail_ok'] = true; 167 } 168 169 //Registre global 170 $infos['register_globals'] = ini_get('register_globals') != 0; 171 172 if( $memoryValue = getMemoryValue() ) 173 { 174 $infos['memory'] = $memoryValue."M"; 175 if( $memoryValue < MEMORY_LIMIT) 176 { 177 $tpl->assign("memory_limit", 178 "PHP's memory_limit is ".$infos['memory'].". If this is too low, phpMyVisites may not work correctly on high traffic websites! Attempting to raise limit to ". MEMORY_LIMIT ."M..." 179 ); 180 if( setMemoryLimit() ) 181 { 182 $tpl->assign("memory_limit_ok", 183 "Memory set to ".MEMORY_LIMIT."M!"); 184 $infos['memory_ok'] = true; 185 } 186 else 187 { 188 189 $tpl->assign("memory_limit", 190 "Failed to set memory_limit to 20M. If phpMyVisites doesn't work correctly, try to raise this limit to at least 20M, look in the php.ini file or ask your server administrator." 191 ); 192 } 193 194 $infos['memory'] = @ini_get('memory_limit'); 195 } 196 else 197 { 198 $infos['memory_ok'] = true; 199 } 200 } 201 202 // server uptime from mysql uptime 203 $res = query('SHOW STATUS'); 204 if($res) 205 { 206 while ($row = mysql_fetch_array($res)) 207 { 208 $serverStatus[$row[0]] = $row[1]; 209 } 210 211 $infos['server_uptime'] = date("r",time() - $serverStatus['Uptime']); 212 } 213 214 return $infos; 215 } 216 217 function checkDirWritable() 218 { 219 $dir = array( 220 '/config', 221 '/datas', 222 '/datas/archives', 223 '/datas/cache_artichow', 224 '/datas/cache_lite', 225 '/datas/cache_smarty', 226 '/datas/tpl_compiled', 227 ); 228 229 $dirProb = array(); 230 231 foreach($dir as $name) 232 { 233 $u = INCLUDE_PATH . $name; 234 235 $dir2[$name] = false; 236 237 if(!is_writable($u)) 238 { 239 if(!is_dir($u) 240 && function_exists('mkdir') 241 ) 242 { 243 mkdir($u, 0755); 244 245 if($name == '/config') 246 { 247 saveFile( $u . "/.htaccess", "Deny from all"); 248 } 249 } 250 251 if(function_exists('chmod')) 252 { 253 chmod( $u, 0755); 254 } 255 } 256 257 if(is_writable($u)) 258 { 259 $dir2[$name] = true; 260 } 261 else 262 { 263 $dirProb[] = $name; 264 } 265 } 266 267 if(sizeof($dirProb) !== 0) 268 { 269 $strError = "<ul>"; 270 foreach($dirProb as $dir) 271 { 272 $strError .= "<li>$dir</li>"; 273 } 274 $strError .= "<li>Try to chmod the phpMyVisites root directory also</li></ul>"; 275 276 printf($GLOBALS['lang']['install_DirectoriesWriteError'], 277 "<font color=\"red\"><b>$strError</b></font>"); 278 exit; 279 } 280 281 282 return $dir2; 283 } 284 285 function getJavascriptCode( $i_site) 286 { 287 return nl2br( 288 str_replace(array('[b]', '[/b]'), 289 array('<b>', '</b>'), 290 str_replace( array('<', '>'), 291 array('<', '>'), 292 '<!-- phpmyvisites --> 293 <a href="http://www.phpmyvisites.us/" title="'. 294 addslashes( $GLOBALS['lang']['logo_description'] ).'" 295 onclick="window.open(this.href);return(false);"><script type="text/javascript"> 296 <!-- 297 var a_vars = Array(); 298 var pagename=\'\'; 299 300 var phpmyvisitesSite = [b]'.$i_site.'[/b]; 301 var phpmyvisitesURL = [b]"'.PHPMV_URL.'/phpmyvisites.php"[/b]; 302 //--> 303 </script> 304 <script language="javascript" src=[b]"'.PHPMV_URL.'/phpmyvisites.js"[/b] type="text/javascript"></script> 305 <object><noscript><p>'.addslashes( $GLOBALS['lang']['logo_description'] ).' 306 <img src=[b]"'.PHPMV_URL.'/phpmyvisites.php"[/b] alt="Statistics" style="border:0" /> 307 </p></noscript></object></a> 308 <!-- /phpmyvisites --> 309 '))); 310 } 311 312 313 function getDisplayLogosListing() 314 { 315 $toDisplay = "<h3>".$GLOBALS['lang']['install_popup_logo']."</h3>"; 316 $toDisplay .= "<form method=\"post\" action=\"#\"> 317 <table cellpadding=\"5\" align=\"center\" valign=\"center\" cellspacing=\"0\" border=\"0\">"; 318 319 $dir = DIR_IMG_LOGOS; 320 // on parcourt $dir et on stocke les noms dans le tableau $list_logos 321 if ($handle = opendir($dir)) 322 { 323 while (false !== ($file = readdir($handle))) 324 { 325 if ($file != "." && $file != ".." && !is_dir($file) && $file != "index.php" && @$file[strlen($file)-4] == '.' ) { 326 $list_logos[]=$file; 327 } 328 } 329 closedir($handle); 330 331 // logos à afficher en préférence, par ordre d'affichage 332 $list_logos_prio = array( 333 334 '37.png', 335 '40.png', 336 '41.png', 337 '50.png', 338 '49.png', 339 '48.png', 340 '47.png', 341 '46.png', 342 '45.gif', 343 '44.gif', 344 '51.png', 345 '28.png', 346 '4.png', 347 '5.png', 348 '6.png', 349 '7.png', 350 '3.png', 351 '8.png', 352 '9.png', 353 '32.png', 354 '43.png', 355 '1.png' 356 ); 357 358 // on recrée le tableau des logos $list_logos en prenant en comptes les logos prioritaires 359 $i=0; 360 foreach($list_logos as $key => $file) 361 { 362 $j=0; 363 $trouve=false; 364 while(!$trouve && $j != sizeof($list_logos_prio)) 365 { 366 if($list_logos_prio[$j] == $file) 367 { 368 $trouve = true; 369 $cle_prio = $j; 370 371 // inversion prio <-> autre 372 if( isset( $list_logos[$cle_prio] )) // due to bug in forum http://www.phpmyvisites.net/forums/index.php/t/2543/4/ 373 { 374 $list_logos[$key] = $list_logos[$cle_prio]; 375 $list_logos[$cle_prio] = $file; 376 } 377 } 378 $j++; 379 } 380 } 381 // logos par colonne 382 $logo_per_line = 3; 383 384 $i=0; 385 // on affiche le tableau avec $logo_per_line logos par ligne 386 foreach($list_logos as $key => $file) 387 { 388 $i++; 389 390 if(($i-1) % $logo_per_line == 0) $toDisplay .= "<tr>"; 391 $toDisplay .= "<td align=center>"; 392 $toDisplay .= 393 '<input type="image" onclick="window.opener.document.forms[\'form_phpmv\'].form_logo_no.value=\''.$file.'\';window.opener.document.images[\'logo_phpmv\'].src=\''.$dir.'/'.$file.'\';window.close();" 394 name="logo_num" value="'.$file.'" src="'.$dir.'/'.$file.'" />'; 395 $toDisplay .= "</td>"; 396 if($i % $logo_per_line == 0) $toDisplay .= "</tr>\n"; 397 } 398 } 399 400 $toDisplay .= " 401 </table> 402 </form> 403 </div> 404 </body> 405 </html> 406 "; 407 408 return $toDisplay; 409 } 410 /** 411 * QF rules 412 */ 413 function checkCorrectIp( $element, $value ) 414 { 415 return long2ip(ip2long($value)) === $value; 416 } 417 418 function compareField($element, $value, $arg) 419 { 420 $value2 = getRequestVar( $arg, '', 'string'); 421 if ($value === $value2) 422 { 423 return true; 424 } 425 else 426 { 427 return false; 428 } 429 } 430 function checkPasswordComplexity( $element, $value) 431 { 432 $isNumeric=false; 433 434 $l = strlen($value); 435 if( $l < 6) 436 { 437 return false; 438 } 439 440 for($i = 0; $i < $l ; $i++) 441 { 442 if(is_numeric($value[$i])) 443 $isNumeric=true; 444 } 445 446 if($isNumeric) 447 return true; 448 else 449 return false; 450 } 451 452 function checkChangePassword ($element, $value) { 453 if (!empty($value)) 454 { 455 return checkPasswordComplexity( $element, $value); 456 } 457 else 458 { 459 return true; 460 } 461 } 462 463 function checkOldCurrentPassword ($element, $value) { 464 $user =& User::getInstance(); 465 $currentInfo = User::getInfo( $user->getLogin() ); 466 // Verify if old password is ok 467 if (@$currentInfo['password'] !== md5($value)) { 468 return false; 469 } 470 else { 471 return true; 472 } 473 } 474 475 476 function checkCorrectUrl( $element, $value) 477 { 478 if($value[strlen($value)-1]=='/' || !ereg('^http[s]?://[A-Za-z0-9\/_.-]', $value)) 479 return false; 480 481 return true; 482 } 483 /** 484 * end QF rules 485 */ 486 487 function getTemplateArrayMonth($o_minDay, $o_request) 488 { 489 $dateAsked = new Date($o_request->getDate()); 490 $todayDate = getDateFromTimestamp(time()); 491 492 if($o_request->getPeriod() == DB_ARCHIVES_PERIOD_YEAR) 493 { 494 $minYear = $o_minDay->getYear(); 495 while($minYear <= date("Y")) 496 { 497 $return[$minYear."-07-14"] = $minYear++; // french 14 juillet ! :) 498 } 499 $selected = $dateAsked->getYear()."-07-14"; 500 } 501 else 502 { 503 $a_months = getDayOfMonthBetween($o_minDay->get(), $todayDate); 504 505 $selected = $todayDate; 506 foreach($a_months as $date) 507 { 508 $o_date = new Date($date); 509 510 if($o_date->getMonth() == $dateAsked->getMonth() 511 && $o_date->getYear() == $dateAsked->getYear()) 512 { 513 $selected = $date; 514 } 515 $return[$date] = getDateDisplay(5, $o_date); 516 } 517 } 518 519 return array( 520 $return, 521 $selected 522 ); 523 } 524 525 /** 526 * returns an array containing all day each of them belonging to a unique month, 527 * between the 2 dates 528 * 529 * @param string $s_date1 min 530 * @param string $s_date2 max 531 * 532 * @return array 533 */ 534 function getDayOfMonthBetween($s_date1, $s_date2) 535 { 536 $date1 = new Date($s_date1); 537 $date2 = new Date($s_date2); 538 539 $ts1 = $date1->getTimestamp(); 540 $ts2 = $date2->getTimestamp(); 541 542 while(date("m", $ts1) != date("m", $ts2) 543 || date("Y", $ts1) != date("Y", $ts2)) 544 { 545 $return[] = getDateFromTimestamp($ts1); 546 $ts1 = mktime(23, 59, 59, date("m", $ts1) + 1, 15, date("Y", $ts1)); 547 } 548 549 $return[] = getDateFromTimestamp($ts1); 550 551 return $return; 552 } 553 554 function getTemplateArrayCalendar($o_minDay, $s_date, $period) 555 { 556 // today 557 $today = new Date(getDateFromTimestamp(time())); 558 $tsToday = $today->getTimestamp(); 559 560 // date asked for statistics 561 $dateAsked = new Date($s_date); 562 563 // used for going througt the month 564 $date = new Date($s_date); 565 $month = $date->getMonth(); 566 $year = $date->getYear(); 567 $prefixDay = $year."-".$month."-"; 568 569 $date->setDate($prefixDay.'01'); 570 $week = $date->getWeek(); 571 $day = 1; 572 $ts = $date->getTimestamp(); 573 574 while($date->getMonth() == $month) 575 { 576 // day exists in stats, isn't it too old or in the future ? 577 if($date->getTimestamp() >= $o_minDay->getTimestamp() 578 && $date->getTimestamp() <= $tsToday) 579 { 580 $exists = 1; 581 } 582 else 583 { 584 $exists = 0; 585 } 586 587 // day selected for stats view ? 588 if( ($period == DB_ARCHIVES_PERIOD_DAY && $date->getDay() == $dateAsked->getDay()) 589 || ($period == DB_ARCHIVES_PERIOD_WEEK && $date->getWeek() == $dateAsked->getWeek()) 590 || ($period == DB_ARCHIVES_PERIOD_MONTH) 591 || ($period == DB_ARCHIVES_PERIOD_YEAR) 592 ) 593 { 594 $selected = 1; 595 } 596 else 597 { 598 $selected = 0; 599 } 600 601 $weekNo = $date->getWeek() - $week; 602 if ( defined('MONDAY_FIRST') && MONDAY_FIRST == 'no' && (date("w", $ts) == 0)) 603 { 604 $weekNo += 1; 605 } 606 607 $dayOfWeek = (int)(!defined('MONDAY_FIRST') || MONDAY_FIRST == 'yes' ? ((date("w", $ts) == 0) 608 ? 6 609 : date("w", $ts) - 1 610 ) 611 : date("w", $ts) 612 ); 613 $return[$weekNo][$dayOfWeek] = array( 614 'day' => (substr($date->getDay(),0,1) === '0') ? 615 substr($date->getDay(),1,2) : 616 $date->getDay(), 617 'date' => $date->get(), 618 'exists' => $exists, 619 'selected' => $selected 620 ); 621 622 $date->addDays(1); 623 624 //these 2 lines useless? to check 625 $ts=$date->getTimeStamp(); 626 $date->setTimestamp( $ts ); 627 628 } 629 630 foreach($return as $key => $r) 631 { 632 $row =& $return[$key]; 633 for($i = 0; $i < 7; $i++) 634 { 635 if(!isset($row[$i])) 636 { 637 $row[$i] = "-"; 638 } 639 } 640 ksort($row); 641 } 642 return $return; 643 644 } 645 646 /** 647 * dump a var and exit... 648 */ 649 function dump_exit($var, $dump = false) 650 { 651 echo '<pre>'; 652 if ($dump) 653 var_dump($var); 654 else 655 print_r($var); 656 echo "</pre>"; 657 exit; 658 } 659 660 function varToString(&$var) 661 { 662 ob_start(); 663 print("<pre>"); 664 var_export($var); 665 print("</pre>"); 666 $var_export = ob_get_contents(); 667 ob_clean(); 668 return $var_export; 669 } 670 671 function camelize($string) 672 { 673 $arrString = explode('_', $string); 674 $ret = ''; 675 foreach ($arrString as $terme) 676 $ret .= ucfirst($terme); 677 678 return $ret; 679 } 680 681 function getClassAndPathModule ($moduleName) { 682 $ret = array(); 683 if (($pos = strrpos($moduleName, ".")) !== false) { 684 $classModule = substr($moduleName, $pos+1); 685 $pathModule = str_replace(".", "/", substr($moduleName, 0, $pos+1)); 686 } 687 else { 688 $pathModule = ""; 689 $classModule = $moduleName; 690 } 691 $ret[0] = camelize($classModule); 692 $ret[1] = $pathModule; 693 694 return $ret; 695 } 696 697 function getFirstDayOfWeek($o_date) 698 { 699 return getDateFromTimestamp( 700 mktime( 701 0, 702 0, 703 0, 704 $o_date->getMonth(), 705 $o_date->getDay() - ($o_date->getWeekDayNumber() + 6 ) % 7, 706 $o_date->getYear() 707 ) 708 ); 709 } 710 711 function sortingDataInfo($a1,$a2) 712 { 713 @$elt1 = $a1[$GLOBALS['sorting_index']]; 714 @$elt2 = $a2[$GLOBALS['sorting_index']]; 715 716 if($GLOBALS['sorting_order'] === 'asc') 717 { 718 return ($elt1 < $elt2) ? -1 : 1; 719 } 720 else 721 { 722 return ($elt1 > $elt2) ? -1 : 1; 723 } 724 } 725 726 /** 727 * returns the literal date 728 * Ex : if period = DB_ARCHIVES_PERIOD_WEEK and $s_date = "2006-08-14" 729 * Returned string will be "Week August 14 To August 20 2006" 730 * 731 * @param int period 732 * @param string s_date 733 */ 734 function getLiteralDate($period, $s_date) 735 { 736 737 switch($period) 738 { 739 case DB_ARCHIVES_PERIOD_DAY: 740 return getDateDisplay(1, new Date($s_date)); 741 break; 742 743 case DB_ARCHIVES_PERIOD_WEEK: 744 745 case DB_ARCHIVES_PERIOD_WEEK: 746 $date = new Date($s_date); 747 $mon = getFirstDayOfWeek($date); 748 $sun = getDateFromTimestamp( mktime( 0, 0, 0, $date->getMonth(), $date->getDay() - ($date->getWeekDayNumber() + 6) % 7 + 6, $date->getYear())); 749 return getDateDisplay(3, new Date($mon), new Date($sun)); 750 751 break; 752 753 case DB_ARCHIVES_PERIOD_MONTH: 754 return getDateDisplay(4, new Date($s_date)); 755 break; 756 757 case DB_ARCHIVES_PERIOD_YEAR: 758 return getDateDisplay(11, new Date($s_date)); 759 break; 760 761 default: 762 trigger_error("Period unknown !", E_USER_ERROR); 763 break; 764 } 765 return; 766 } 767 768 /** 769 * 770 * @param int $type suffix of TDATE type found in language file, looks like "%monthshort% %yearshort%" 771 * @param object $date1 772 * @param object $date2 773 * 774 * @return string date formated 775 */ 776 function getDateDisplay($type, $date1, $date2 = null) 777 { 778 $return = $GLOBALS['lang']['tdate'.$type]; 779 780 $return = @str_replace('%daylong%', 781 $GLOBALS['lang']['jsemaine'][date("D", $date1->getTimestamp())], $return); 782 $return = @str_replace('%monthlong%', $GLOBALS['lang']['moistab'][$date1->getMonth()], $return); 783 784 $return = @str_replace('%dayshort%', $GLOBALS['lang']['jsemaine_graph'][date("D",$date1->getTimestamp())], $return); 785 $return = @str_replace('%monthshort%', $GLOBALS['lang']['moistab_graph'][$date1->getMonth()], $return); 786 $return = @str_replace('%yearshort%', substr($date1->getYear(), 2,2), $return); 787 788 $return = str_replace('%daynumeric%', $date1->getDay(), $return); 789 790 // when we display week label, the year is associated to the more recent date 791 if($type == 3) 792 { 793 $return = str_replace('%yearlong%', $date2->getYear(), $return); 794 } 795 else 796 { 797 $return = str_replace('%yearlong%', $date1->getYear(), $return); 798 } 799 800 if (isset($date2)) 801 { 802 $return = str_replace('%daynumeric2%', $date2->getDay(), $return); 803 $return = str_replace('%monthlong2%', $GLOBALS['lang']['moistab'][$date2->getMonth()], $return); 804 } 805 $return = str_replace('%monthnumeric%', $date1->getMonth(), $return); 806 807 return $return; 808 } 809 810 /** 811 * saves a configuration file, containing php readable variable value 812 * 813 * @param string $fileAdress 814 * @param all $variable 815 */ 816 function saveConfigFile($fileAdress, $variable, $name) 817 { 818 ob_start(); 819 print("\n\$".$name." = "); 820 var_export($variable); 821 print(";\n"); 822 $var_export = ob_get_contents(); 823 ob_clean(); 824 825 saveFile( $fileAdress, "<?php ".$var_export."?>"); 826 } 827 828 function saveFile( $fileAdress, $content ) 829 { 830 $file = @fopen($fileAdress, "w"); 831 if($file) 832 { 833 if(!fwrite($file, $content)) 834 { 835 print("Can't write file $fileAdress please chmod this file (create if it doesn't exist)."); 836 exit; 837 } 838 else 839 { 840 fclose($file); 841 } 842 } 843 } 844 function getCountImgHtml( $url, $name ) 845 { 846 return "<img src='http://www.phpmyvisites.net/count.php?version=".PHPMV_VERSION."&phpmv_url=".PHPMV_URL."&site_url=".$url."&site_name=".$name."&mail=".SU_EMAIL."'/>"; 847 } 848 849 /** 850 * Returns time elapsed in seconds since the beginning of the execution 851 */ 852 function getTimeElapsed() 853 { 854 $res = getMicrotime()-$GLOBALS['time_start']; 855 $res = substr($res, 0, 4); 856 return $res; 857 } 858 /** 859 * display time since the beginning of the script 860 */ 861 function printTime($detail = '', $force = false) 862 { 863 if(PRINT_TIME || !empty($force)) 864 { 865 //Message à passer en variable dans le template footer.tpl 866 $ch = ""; 867 if($detail == 'EOF') $ch .= ('<span style="color:white;size:2">'); 868 else $ch .= ("<br><b>$detail</b>"); 869 870 $ch .= (" Time : <b>".getTimeElapsed()."</b> sec"); 871 if($detail == 'EOF') $ch .= ('</span>'); 872 873 //$GLOBALS['PRINT_TIME_TO_SHOW'] = $ch; 874 print ch; 875 } 876 } 877 878 /** 879 * display number of queries since the beginning of the script 880 */ 881 function printQueryCount() 882 { 883 if(PRINT_QUERY_COUNT) 884 { 885 print("<br>Queries: <b>".$GLOBALS['query_count']."</b>"); 886 } 887 } 888 889 function getArrayOffsetLimit(&$a, $offset, $limit, $name='', $indexUsed = null, $allInfo=null) 890 { 891 //global $o_request; 892 $o_request =& Request::getInstance(); 893 894 $return = array(); 895 if(is_array($a)) 896 { 897 if($limit == -1) 898 { 899 $limit = sizeof($a); 900 } 901 902 $dataLimited = 0; 903 $dataLimitedPercent = 0; 904 905 if(!is_null($allInfo)) 906 { 907 if(substr($name, 0, 4) === 'int_') 908 { 909 if($name == 'int_keyword') 910 { 911 $name = 'a_keyword_sort'; 912 } 913 else if($name == 'int_search_engine') 914 { 915 $name = 'a_searchengine_sort'; 916 } 917 else if($name == 'int_site') 918 { 919 $name = 'a_site_sort'; 920 } 921 else if($name == 'int_partner') 922 { 923 $name = 'a_partner_sort'; 924 } 925 else if($name == 'int_newsletter') 926 { 927 $name = 'a_newsletter_sort'; 928 } 929 else 930 { 931 $name = 'a_int_sort'; 932 } 933 } 934 935 if( $name == 'a_int_sort' 936 || $name == 'a_pag_sort' 937 || $name == 'a_entry_sort' 938 || $name == 'a_exit_sort' 939 || $name == 'a_singlepage_sort' 940 || $name == 'a_sumtime_sort' 941 || $name == 'a_keyword_sort' 942 || $name == 'a_searchengine_sort' 943 || $name == 'a_site_sort' 944 || $name == 'a_partner_sort' 945 || $name == 'a_newsletter_sort' 946 947 ) 948 { 949 $sorted = $o_request->getArrayInfoSort($allInfo); 950 $sort = $sorted[$o_request->sorting_percent_limit_and_population_index[$name][1]]; 951 $GLOBALS['sorting_index'] = $sort[1]; 952 $GLOBALS['sorting_order'] = $sort[2]; 953 $dataLimited = $sort[5]; 954 $dataLimitedPercent = $sort[6]; 955 956 // printTime('before sort', true); 957 uasort($a, "sortingDataInfo"); 958 959 // printTime('after sort',true); 960 // case undefined (keyword because of very automatic fucking call) 961 if(is_null($indexUsed)) $indexUsed = 'sum'; 962 } 963 } 964 //print($indexUsed); 965 //printTime('after sort compute'); 966 $i = 0; 967 foreach($a as $key => $value) 968 { 969 //printDebug($value[$indexUsed] . ", "); 970 if( is_null($indexUsed) 971 || ($value[$indexUsed] > $dataLimitedPercent * $dataLimited / 100 / 100) 972 ) 973 { 974 //print("i:$i off:$offset lim:$limit <br>"); 975 if($i >= $offset + $limit) 976 { 977 continue; 978 } 979 if($i >= $offset) 980 { 981 $return[$key] = $value; 982 } 983 984 $i++; 985 } 986 } 987 } 988 return $return; 989 } 990 991 /** 992 * returns a formated time HH:MM:SS 993 * 994 * @param int $time timestamp second since midnight today 995 * 996 * @return string time at format HH:MM:SS 997 */ 998 function getTimeForDisplay($time) 999 { 1000 $h = floor($time / 3600); 1001 $m = floor(( $time % 3600 ) / 60); 1002 $s = $time - $h * 3600 - $m * 60; 1003 return $h.':'.$m.':'.$s; 1004 } 1005 1006 ?>
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 |
![]() |