[ Index ] |
|
Code source de phpMyVisites 2.3 |
1 <?php 2 /** 3 * ClickHeat : réponse à l'appel Ajax / Reply to the Ajax call 4 * 5 * @author Yvan Taviaud - LabsMedia - www.labsmedia.com 6 * @since 27/10/2006 7 **/ 8 9 /** Direct call forbidden */ 10 if (!defined('CLICKHEAT_LANGUAGE')) 11 { 12 exit; 13 } 14 15 /** Main class */ 16 include CLICKHEAT_ROOT.'classes/Heatmap.class.php'; 17 include CLICKHEAT_ROOT.'classes/HeatmapFromClicks.class.php'; 18 19 /** Screen size */ 20 $screen = isset($_GET['screen']) ? (int) $_GET['screen'] : 0; 21 $minScreen = 0; 22 if ($screen < 0) 23 { 24 $width = abs($screen); 25 $maxScreen = 3000; 26 } 27 else 28 { 29 $maxScreen = $screen; 30 if (!in_array($screen, $__screenSizes) || $screen === 0) 31 { 32 errorGenerate(LANG_ERROR_SCREEN); 33 } 34 for ($i = 1; $i < count($__screenSizes); $i++) 35 { 36 if ($__screenSizes[$i] === $screen) 37 { 38 $minScreen = $__screenSizes[$i - 1]; 39 break; 40 } 41 } 42 $width = $screen - 25; 43 } 44 45 /** Browser */ 46 $browser = isset($_GET['browser']) ? $_GET['browser'] : ''; 47 if (!isset($__browsersList[$browser])) 48 { 49 $browser = 'all'; 50 } 51 52 /** Time and memory limits */ 53 @set_time_limit(120); 54 @ini_set('memory_limit', $clickheatConf['memory'].'M'); 55 56 /** Selected Group */ 57 $group = isset($_GET['group']) ? str_replace('/', '', $_GET['group']) : '****dead_directory****'; 58 if (!is_dir($clickheatConf['logPath'].$group)) 59 { 60 errorGenerate(LANG_ERROR_GROUP); 61 } 62 63 /** Show clicks or heatmap */ 64 $heatmap = isset($_GET['heatmap']) && $_GET['heatmap'] === '1'; 65 66 /** Date and days */ 67 $time = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time(); 68 $dateStamp = isset($_GET['date']) ? strtotime($_GET['date']) : $time; 69 $range = isset($_GET['range']) && in_array($_GET['range'], array('d', 'w', 'm')) ? $_GET['range'] : 'd'; 70 $date = date('Y-m-d', $dateStamp); 71 switch ($range) 72 { 73 case 'd': 74 { 75 $days = 1; 76 $delay = date('dmy', $dateStamp) !== date('dmy') ? 86400 : 120; 77 break; 78 } 79 case 'w': 80 { 81 $days = 7; 82 $delay = date('Wy', $dateStamp) !== date('Wy') ? 86400 : 120; 83 break; 84 } 85 case 'm': 86 { 87 $days = date('t', $dateStamp); 88 $delay = date('my', $dateStamp) !== date('my') ? 86400 : 120; 89 break; 90 } 91 } 92 93 $imagePath = $group.'-'.$date.'-'.$range.'-'.$screen.'-'.$browser.'-'.($heatmap === true ? 'heat' : 'click'); 94 $htmlPath = $clickheatConf['cachePath'].$imagePath.'.html'; 95 96 /** If images are already created, just stop script here if these have less than 120 seconds (today's log) or 86400 seconds (old logs) */ 97 if (file_exists($htmlPath) && filemtime($htmlPath) > $time - $delay) 98 { 99 readfile($htmlPath); 100 exit; 101 } 102 103 /** Get some data for the current group (centered and/or fixed layout) */ 104 if (file_exists($clickheatConf['logPath'].$group.'/url.txt')) 105 { 106 $f = fopen($clickheatConf['logPath'].$group.'/url.txt', 'r'); 107 $layout = trim(fgets($f, 1024)); 108 fclose($f); 109 } 110 else 111 { 112 $layout = ''; 113 } 114 $layout = explode('>', $layout); 115 if (count($layout) !== 4) 116 { 117 $layout = array('', 0, 0, 0); 118 } 119 120 /** Call the Heatmap class */ 121 $clicksHeatmap = new HeatmapFromClicks(); 122 $clicksHeatmap->browser = $browser; 123 $clicksHeatmap->minScreen = $minScreen; 124 $clicksHeatmap->maxScreen = $maxScreen; 125 $clicksHeatmap->layout = $layout; 126 $clicksHeatmap->memory = $clickheatConf['memory'] * 1048576; 127 $clicksHeatmap->step = $clickheatConf['step']; 128 $clicksHeatmap->dot = $clickheatConf['dot']; 129 $clicksHeatmap->palette = $clickheatConf['palette']; 130 $clicksHeatmap->heatmap = $heatmap; 131 $clicksHeatmap->path = $clickheatConf['cachePath']; 132 $clicksHeatmap->cache = $clickheatConf['cachePath']; 133 $clicksHeatmap->file = $imagePath.'-%d.png'; 134 /** Add files */ 135 for ($day = 0; $day < $days; $day++) 136 { 137 $currentDate = date('Y-m-d', mktime(0, 0, 0, date('m', $dateStamp), date('d', $dateStamp) + $day, date('Y', $dateStamp))); 138 $clicksHeatmap->addFile($clickheatConf['logPath'].$group.'/'.$currentDate.'.log'); 139 } 140 141 $result = $clicksHeatmap->generate($width); 142 if ($result === false) 143 { 144 errorGenerate($clicksHeatmap->error); 145 } 146 $html = ''; 147 for ($i = 0; $i < $result['count']; $i++) 148 { 149 $html .= '<img src="'.CLICKHEAT_INDEX_PATH.'action=png&file='.$result['filenames'][$i].'&rand='.$time.'" width="'.$result['width'].'" height="'.$result['height'].'" alt="" id="heatmap-'.$i.'" /><br />'; 150 } 151 echo $html; 152 153 /** Save the HTML code to speed up following queries (only over two minutes) */ 154 $f = fopen($htmlPath, 'w'); 155 fputs($f, $html); 156 fclose($f); 157 158 /** 159 * Retourne une erreur / Returns an error 160 * 161 * @param string $error 162 **/ 163 function errorGenerate($error) 164 { 165 echo ' <div style="line-height:20px;"><span class="error">'.$error.'</span></div>'; 166 exit; 167 } 168 ?>
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 |
![]() |