$clicksHeatmap->maxScreen = $maxScreen; $clicksHeatmap->layout = $layout; $clicksHeatmap->memory = $clickheatConf['memory'] * 1048576; $clicksHeatmap->step = $clickheatConf['step']; $clicksHeatmap->dot = $clickheatConf['dot']; $clicksHeatmap->palette = $clickheatConf['palette']; $clicksHeatmap->heatmap = $heatmap; $clicksHeatmap->path = $clickheatConf['cachePath']; $clicksHeatmap->cache = $clickheatConf['cachePath']; $clicksHeatmap->file = $imagePath . '-%d.png'; /** Add files */ for ($day = 0; $day < $days; $day++) { $currentDate = date('Y-m-d', mktime(0, 0, 0, date('m', $dateStamp), date('d', $dateStamp) + $day, date('Y', $dateStamp))); $clicksHeatmap->addFile($clickheatConf['logPath'] . $group . '/' . $currentDate . '.log'); } $result = $clicksHeatmap->generate($width); if ($result === false) { errorGenerate($clicksHeatmap->error); } $html = ''; for ($i = 0; $i < $result['count']; $i++) { $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 />'; } echo $html; /** Save the HTML code to speed up following queries (only over two minutes) */ $f = fopen($htmlPath, 'w'); fputs($f, $html); fclose($f); /** * Retourne une erreur / Returns an error *
/** * Generate image */ private function generate($vars) { /** * Class files */ include dirname(__FILE__) . '/classes/Heatmap.class.php'; include dirname(__FILE__) . '/classes/HeatmapFromClicks.class.php'; /** * Screen size */ $screen = isset($vars['screen']) ? (int) $vars['screen'] : 0; $minScreen = 0; if ($screen < 0) { $width = abs($screen); $maxScreen = 3000; } else { $maxScreen = $screen; if (!in_array($screen, $this->screenSizes) || $screen === 0) { $this->error(_t('Non-standard screen size') . ": {$screen}"); } $psize = 0; foreach ($this->screenSizes as $size) { if ($size === $screen) { $minScreen = $psize; break; } $psize = $size; } $width = $screen - 25; } /** * Time and memory limits */ $memory = Options::get('clickheat__memory'); @set_time_limit(120); @ini_set('memory_limit', $memory . 'M'); /** * Selected Group */ $group = isset($vars['group']) ? $vars['group'] : false; if ($group === false || !is_dir($this->logs . "/" . $group)) { return $this->error(_t('Unknown group')); } /** * Show clicks or heatmap */ $heatmap = isset($vars['heatmap']) && $vars['heatmap'] == 1; /** * Date and days */ $time = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time(); $dateStamp = isset($vars['date']) ? strtotime($vars['date']) : $time; $range = isset($vars['range']) && in_array($vars['range'], array('d', 'w', 'm')) ? $vars['range'] : 'd'; $date = date('Y-m-d', $dateStamp); switch ($range) { case 'd': $days = 1; $delay = date('dmy', $dateStamp) !== date('dmy') ? 86400 : 120; break; case 'w': $days = 7; $delay = date('Wy', $dateStamp) !== date('Wy') ? 86400 : 120; break; case 'm': $days = date('t', $dateStamp); $delay = date('my', $dateStamp) !== date('my') ? 86400 : 120; break; } $imagePath = $group . '-' . $date . '-' . $range . '-' . $screen . '-' . '-' . ($heatmap ? 'heat' : 'click'); $htmlPath = $this->cache . "/" . $imagePath . '.html'; /** * If images are already created, * just stop script here if these have less * than 120 seconds (today's log) or 86400 seconds (old logs) */ if (file_exists($htmlPath) && filemtime($htmlPath) > $time - $delay) { readfile($htmlPath); exit; } /** * Call the Heatmap class */ $clicksHeatmap = new HeatmapFromClicks(); $clicksHeatmap->minScreen = $minScreen; $clicksHeatmap->maxScreen = $maxScreen; $clicksHeatmap->memory = $memory * 1048576; $clicksHeatmap->step = Options::get('clickheat__step'); $clicksHeatmap->dot = Options::get('clickheat__dot_size'); $clicksHeatmap->palette = Options::get('clickheat__palette'); $clicksHeatmap->rainbow = Options::get('clickheat__rainbow'); $clicksHeatmap->heatmap = $heatmap; $clicksHeatmap->path = $this->cache; $clicksHeatmap->cache = $this->cache; $clicksHeatmap->file = $imagePath . '-%d.png'; /** * Add files */ for ($day = 0; $day < $days; $day++) { $currentDate = date('Y-m-d', mktime(0, 0, 0, date('m', $dateStamp), date('d', $dateStamp) + $day, date('Y', $dateStamp))); $clicksHeatmap->addFile($this->logs . "/{$group}/{$currentDate}.log"); } if (($result = $clicksHeatmap->generate($width)) === false) { return $this->error($clicksHeatmap->error); } $html = ''; for ($i = 0; $i < $result['count']; $i++) { $html .= '<img src="' . URL::get('ajax', array('context' => 'clickheat', 'action' => 'png', 'file' => $result['filenames'][$i], 'rand' => $time)) . '" width="' . $result['width'] . '" height="' . $result['height'] . '" alt="" id="heatmap-' . $i . '" /><br />'; } /** * Save the HTML code to speed up following queries (only over two minutes) */ $f = fopen($htmlPath, 'w'); fputs($f, $html); fclose($f); return $html; }