| [ Index ] |
|
Code source de phpMyVisites 2.3 |
1 <?php 2 /** 3 * ClickHeat : Classe de génération des cartes depuis un fichier de coordonnées X,Y / Maps generation class from a X,Y coords file 4 * 5 * Cette classe est VOLONTAIREMENT écrite pour PHP 4 6 * This class is VOLUNTARILY written for PHP 4 7 * 8 * Utilisation : jettez un oeil au répertoire /examples/ 9 * Usage: have a look into /examples/ directory 10 * 11 * @author Yvan Taviaud - LabsMedia - www.labsmedia.com 12 * @since 19/05/2007 13 **/ 14 15 class HeatmapFromFile extends Heatmap 16 { 17 /** @var array $files Fichiers de suivi à étudier / Logfiles to use */ 18 var $files = array(); 19 /** @var string $regular Expression régulière pour lire les enregistrements du fichier / Regular expression to read file entries */ 20 var $regular = '/^(\d+),(\d+)$/m'; 21 22 /** 23 * Add a file to parse and check existence 24 * 25 * @param string $file 26 */ 27 function addFile($file) 28 { 29 if (file_exists($file)) 30 { 31 $this->files[] = $file; 32 } 33 } 34 35 /** 36 * Do some tasks before drawing (database connection...) 37 **/ 38 function startDrawing() 39 { 40 return true; 41 } 42 43 /** 44 * Find pixels coords and draw these on the current image 45 * 46 * @param integer $image Number of the image (to be used with $this->height) 47 * @return boolean Success 48 **/ 49 function drawPixels($image) 50 { 51 if (count($this->files) === 0) 52 { 53 return $this->raiseError('No files to be used'); 54 } 55 for ($file = 0; $file < count($this->files); $file++) 56 { 57 /** Read clicks in the log file */ 58 $f = @fopen($this->files[$file], 'r'); 59 if ($f === false) 60 { 61 return $this->raiseError('Can\'t open file: '.$this->files[$file]); 62 } 63 64 $buffer = ''; 65 $count = 0; 66 while (true) 67 { 68 $buffer .= fgets($f, 1024); 69 /** Grouping by 1000 clicks */ 70 if (feof($f) === false && $count++ !== 1000) 71 { 72 continue; 73 } 74 /** Do a regular match (faster and easier for large volume of data) */ 75 preg_match_all($this->regular, $buffer, $clicks); 76 $buffer = ''; 77 78 for ($i = 0, $max = count($clicks[1]); $i < $max; $i++) 79 { 80 $x = (int) $clicks[1][$i]; 81 $y = (int) ($clicks[2][$i] - $image * $this->height); 82 if ($x < 0 || $x >= $this->width) 83 { 84 continue; 85 } 86 if ($y >= 0 && $y < $this->height) 87 { 88 /** Apply a calculus for the step, with increases the speed of rendering : step = 3, then pixel is drawn at x = 2 (center of a 3x3 square) */ 89 $x -= $x % $this->step - $this->startStep; 90 $y -= $y % $this->step - $this->startStep; 91 /** Add 1 to the current color of this pixel (color which represents the sum of clicks on this pixel) */ 92 $color = imagecolorat($this->image, $x, $y) + 1; 93 imagesetpixel($this->image, $x, $y, $color); 94 $this->maxClicks = max($this->maxClicks, $color); 95 } 96 if ($image === 0) 97 { 98 /** Looking for the maximum height of click */ 99 $this->maxY = max($y, $this->maxY); 100 } 101 } 102 unset($clicks); 103 104 if ($count !== 1001) 105 { 106 break; 107 } 108 $count = 0; 109 } 110 fclose($f); 111 } 112 return true; 113 } 114 115 /** 116 * Do some cleaning or ending tasks (close database, reset array...) 117 **/ 118 function finishDrawing() 119 { 120 $this->files = array(); 121 return true; 122 } 123 } 124 ?>
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 |
|