| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | class Piwik_ClickHeat_Controller extends Piwik_Controller |
|---|
| 13 | { |
|---|
| 14 | |
|---|
| 15 | static $conf = array(); |
|---|
| 16 | |
|---|
| 17 | function init() |
|---|
| 18 | { |
|---|
| 19 | $__languages = array('bg', 'cz', 'de', 'en', 'es', 'fr', 'hu', 'id', 'it', 'ja', 'nl', 'pl', 'pt', 'ro', 'ru', 'sr', 'tr', 'uk', 'zh'); |
|---|
| 20 | |
|---|
| 21 | if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] !== '') |
|---|
| 22 | { |
|---|
| 23 | $realPath = &$_SERVER['REQUEST_URI']; |
|---|
| 24 | } |
|---|
| 25 | elseif (isset($_SERVER['SCRIPT_NAME']) && $_SERVER['SCRIPT_NAME'] !== '') |
|---|
| 26 | { |
|---|
| 27 | $realPath = &$_SERVER['SCRIPT_NAME']; |
|---|
| 28 | } |
|---|
| 29 | else |
|---|
| 30 | { |
|---|
| 31 | exit(LANG_UNKNOWN_DIR); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | $dirName = dirname($realPath); |
|---|
| 36 | if ($dirName === '/') |
|---|
| 37 | { |
|---|
| 38 | $dirName = ''; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | define('CLICKHEAT_PATH', $dirName.'/plugins/ClickHeat/libs/'); |
|---|
| 42 | define('CLICKHEAT_INDEX_PATH', 'index.php?module=ClickHeat&'); |
|---|
| 43 | define('CLICKHEAT_ROOT', PIWIK_INCLUDE_PATH.'/plugins/ClickHeat/libs/'); |
|---|
| 44 | define('CLICKHEAT_CONFIG', PIWIK_INCLUDE_PATH.'/config/clickheat.php'); |
|---|
| 45 | define('IS_PIWIK_MODULE', true); |
|---|
| 46 | |
|---|
| 47 | if (Zend_Registry::get('access')->isSuperUser()) |
|---|
| 48 | { |
|---|
| 49 | define('CLICKHEAT_ADMIN', true); |
|---|
| 50 | } |
|---|
| 51 | else |
|---|
| 52 | { |
|---|
| 53 | define('CLICKHEAT_ADMIN', false); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | define('CLICKHEAT_LANGUAGE', Piwik_Translate::getInstance()->getLanguageToLoad()); |
|---|
| 57 | include (CLICKHEAT_CONFIG); |
|---|
| 58 | self::$conf = $clickheatConf; |
|---|
| 59 | |
|---|
| 60 | $GLOBALS['clickheatConf'] = &self::$conf; |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | self::$conf['__screenSizes'] = array(0 , 640, 800, 1024, 1280, 1440, 1600, 1800); |
|---|
| 64 | self::$conf['__browsersList'] = array('all' => '', 'firefox' => 'Firefox', 'msie' => 'Internet Explorer', 'safari' => 'Safari', 'opera' => 'Opera', 'kmeleon' => 'K-meleon', 'unknown' => ''); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | function view() |
|---|
| 71 | { |
|---|
| 72 | $this->init(); |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | $groups = array(); |
|---|
| 76 | $d = dir(self::$conf['logPath']); |
|---|
| 77 | while (($dir = $d->read()) !== false) |
|---|
| 78 | { |
|---|
| 79 | if ($dir[0] === '.' || !is_dir($d->path.$dir)) continue; |
|---|
| 80 | $pos = strpos($dir, ','); |
|---|
| 81 | if ($pos !== false) |
|---|
| 82 | { |
|---|
| 83 | $site = substr($dir, 0, $pos); |
|---|
| 84 | } |
|---|
| 85 | else |
|---|
| 86 | { |
|---|
| 87 | $site = ''; |
|---|
| 88 | } |
|---|
| 89 | if (!isset($groups[$site])) |
|---|
| 90 | { |
|---|
| 91 | $groups[$site] = array(); |
|---|
| 92 | } |
|---|
| 93 | $groups[$site][] = '<option value="'.$dir.'">'.($pos === false ? $dir : substr($dir, $pos + 1)).'</option>'; |
|---|
| 94 | } |
|---|
| 95 | $d->close(); |
|---|
| 96 | |
|---|
| 97 | ksort($groups); |
|---|
| 98 | $__selectGroups = ''; |
|---|
| 99 | foreach ($groups as $key => $options) |
|---|
| 100 | { |
|---|
| 101 | sort($options); |
|---|
| 102 | if ($key !== '') |
|---|
| 103 | { |
|---|
| 104 | $piwikSite = new Piwik_Site($key); |
|---|
| 105 | $__selectGroups .= '<optgroup label="'.htmlentities($piwikSite->getName()).'">'; |
|---|
| 106 | } |
|---|
| 107 | $__selectGroups .= implode("\n", $options); |
|---|
| 108 | if ($key !== '') |
|---|
| 109 | { |
|---|
| 110 | $__selectGroups .= '</optgroup>'; |
|---|
| 111 | } |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | $__selectScreens = ''; |
|---|
| 115 | for ($i = 0; $i < count(self::$conf['__screenSizes']); $i++) |
|---|
| 116 | { |
|---|
| 117 | $__selectScreens .= '<option value="'.self::$conf['__screenSizes'][$i].'">'.(self::$conf['__screenSizes'][$i] === 0 ? Piwik_Translate('LANG_ALL') : self::$conf['__screenSizes'][$i].'px').'</option>'; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | $__selectBrowsers = ''; |
|---|
| 122 | foreach (self::$conf['__browsersList'] as $label => $name) |
|---|
| 123 | { |
|---|
| 124 | $__selectBrowsers .= '<option value="'.$label.'">'.($label === 'all' ? Piwik_Translate('LANG_ALL') : ($label === 'unknown' ? Piwik_Translate('LANG_UNKNOWN') : $name)).'</option>'; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | $date = isset($_GET['date']) ? strtotime($_GET['date']) : (self::$conf['yesterday'] === true ? mktime(0, 0, 0, date('m'), date('d') - 1, date('Y')) : false); |
|---|
| 129 | if ($date === false) |
|---|
| 130 | { |
|---|
| 131 | $date = time(); |
|---|
| 132 | } |
|---|
| 133 | $__day = (int) date('d', $date); |
|---|
| 134 | $__month = (int) date('m', $date); |
|---|
| 135 | $__year = (int) date('Y', $date); |
|---|
| 136 | |
|---|
| 137 | $view = new Piwik_View('ClickHeat/templates/view.tpl'); |
|---|
| 138 | |
|---|
| 139 | $view->assign('clickheat_host', 'http://'.$_SERVER['SERVER_NAME']); |
|---|
| 140 | $view->assign('clickheat_path', CLICKHEAT_PATH); |
|---|
| 141 | $view->assign('clickheat_index', CLICKHEAT_INDEX_PATH); |
|---|
| 142 | $view->assign('clickheat_group', Piwik_Translate('LANG_GROUP')); |
|---|
| 143 | $view->assign('clickheat_groups', $__selectGroups); |
|---|
| 144 | $view->assign('clickheat_browser', Piwik_Translate('LANG_BROWSER')); |
|---|
| 145 | $view->assign('clickheat_browsers', $__selectBrowsers); |
|---|
| 146 | $view->assign('clickheat_screen', Piwik_Translate('LANG_SCREENSIZE')); |
|---|
| 147 | $view->assign('clickheat_screens', $__selectScreens); |
|---|
| 148 | $view->assign('clickheat_heatmap', Piwik_Translate('LANG_HEATMAP')); |
|---|
| 149 | $view->assign('clickheat_loading', str_replace('\'', '\\\'', Piwik_Translate('LANG_ERROR_LOADING'))); |
|---|
| 150 | $view->assign('clickheat_cleaner', str_replace('\'', '\\\'', Piwik_Translate('LANG_CLEANER_RUNNING'))); |
|---|
| 151 | $view->assign('clickheat_admincookie', str_replace('\'', '\\\'', Piwik_Translate('LANG_JAVASCRIPT_ADMIN_COOKIE'))); |
|---|
| 152 | $view->assign('clickheat_alpha', self::$conf['alpha']); |
|---|
| 153 | $view->assign('clickheat_iframes', self::$conf['hideIframes'] === true ? 'true' : 'false'); |
|---|
| 154 | $view->assign('clickheat_flashes', self::$conf['hideFlashes'] === true ? 'true' : 'false'); |
|---|
| 155 | $view->assign('clickheat_force_heatmap', self::$conf['heatmap'] === true ? ' checked="checked"' : ''); |
|---|
| 156 | $view->assign('clickheat_jsokay', '<a href="#" onclick="showJsCode(); return false;">'.str_replace('\'', '\\\'', Piwik_Translate('LANG_ERROR_JAVASCRIPT')).'</a>'); |
|---|
| 157 | $view->assign('clickheat_day', $__day); |
|---|
| 158 | $view->assign('clickheat_month', $__month); |
|---|
| 159 | $view->assign('clickheat_year', $__year); |
|---|
| 160 | $range = isset($_GET['period']) ? $_GET['period'][0] : 'd'; |
|---|
| 161 | if (!in_array($range, array('d', 'm', 'w'))) |
|---|
| 162 | { |
|---|
| 163 | $range = 'd'; |
|---|
| 164 | } |
|---|
| 165 | $view->assign('clickheat_range', $range); |
|---|
| 166 | $view->assign('clickheat_menu', '<a href="#" onclick="adminCookie(); return false;">'.Piwik_Translate('LANG_LOG_MY_CLICKS').'</a><br /><a href="#" onclick="showJsCode(); return false;">Javascript</a>'); |
|---|
| 167 | |
|---|
| 168 | echo $view->render(); |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | function iframe() |
|---|
| 172 | { |
|---|
| 173 | $this->init(); |
|---|
| 174 | $group = isset($_GET['group']) ? str_replace('/', '', $_GET['group']) : ''; |
|---|
| 175 | if (is_dir(self::$conf['logPath'].$group)) |
|---|
| 176 | { |
|---|
| 177 | $webPage = array('/'); |
|---|
| 178 | if (file_exists(self::$conf['logPath'].$group.'/url.txt')) |
|---|
| 179 | { |
|---|
| 180 | $f = @fopen(self::$conf['logPath'].$group.'/url.txt', 'r'); |
|---|
| 181 | if ($f !== false) |
|---|
| 182 | { |
|---|
| 183 | $webPage = explode('>', trim(fgets($f, 1024))); |
|---|
| 184 | fclose($f); |
|---|
| 185 | } |
|---|
| 186 | } |
|---|
| 187 | echo $webPage[0]; |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | function javascript() |
|---|
| 192 | { |
|---|
| 193 | $this->init(); |
|---|
| 194 | include (CLICKHEAT_ROOT.'javascript.php'); |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | function layout() |
|---|
| 198 | { |
|---|
| 199 | $this->init(); |
|---|
| 200 | include (CLICKHEAT_ROOT.'layout.php'); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | function generate() |
|---|
| 204 | { |
|---|
| 205 | $this->init(); |
|---|
| 206 | include (CLICKHEAT_ROOT.'generate.php'); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | function png() |
|---|
| 210 | { |
|---|
| 211 | $this->init(); |
|---|
| 212 | $imagePath = self::$conf['cachePath'].(isset($_GET['file']) ? str_replace('/', '', $_GET['file']) : '**unknown**'); |
|---|
| 213 | |
|---|
| 214 | header('Content-Type: image/png'); |
|---|
| 215 | if (file_exists($imagePath)) |
|---|
| 216 | { |
|---|
| 217 | readfile($imagePath); |
|---|
| 218 | } |
|---|
| 219 | else |
|---|
| 220 | { |
|---|
| 221 | readfile(CLICKHEAT_ROOT.'images/warning.png'); |
|---|
| 222 | } |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | function layoutupdate() |
|---|
| 226 | { |
|---|
| 227 | $this->init(); |
|---|
| 228 | |
|---|
| 229 | $group = isset($_GET['group']) ? str_replace('/', '', $_GET['group']) : ''; |
|---|
| 230 | $url = isset($_GET['url']) ? $_GET['url'] : ''; |
|---|
| 231 | if (strpos($url, 'http') !== 0) |
|---|
| 232 | { |
|---|
| 233 | $url = 'http://'.$_SERVER['SERVER_NAME'].'/'.ltrim($url, '/'); |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | $url = parse_url(str_replace(array('<', '>'), array('', ''), $url)); |
|---|
| 237 | $left = isset($_GET['left']) ? (int) $_GET['left'] : 0; |
|---|
| 238 | $center = isset($_GET['center']) ? (int) $_GET['center'] : 0; |
|---|
| 239 | $right = isset($_GET['right']) ? (int) $_GET['right'] : 0; |
|---|
| 240 | |
|---|
| 241 | if (!is_dir(self::$conf['logPath'].$group) || !isset($url['host']) || !isset($url['path'])) |
|---|
| 242 | { |
|---|
| 243 | exit('Error'); |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | if ($url['scheme'] !== 'http' && $url['scheme'] !== 'https') |
|---|
| 247 | { |
|---|
| 248 | $url['scheme'] = 'http'; |
|---|
| 249 | } |
|---|
| 250 | if (isset($url['query'])) |
|---|
| 251 | { |
|---|
| 252 | $url = $url['scheme'].'://'.$url['host'].$url['path'].'?'.$url['query']; |
|---|
| 253 | } |
|---|
| 254 | else |
|---|
| 255 | { |
|---|
| 256 | $url = $url['scheme'].'://'.$url['host'].$url['path']; |
|---|
| 257 | } |
|---|
| 258 | $f = fopen(self::$conf['logPath'].$group.'/url.txt', 'w'); |
|---|
| 259 | fputs($f, $url.'>'.$left.'>'.$center.'>'.$right); |
|---|
| 260 | fclose($f); |
|---|
| 261 | |
|---|
| 262 | exit('OK'); |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | function cleaner() |
|---|
| 266 | { |
|---|
| 267 | $this->init(); |
|---|
| 268 | include (CLICKHEAT_ROOT.'cleaner.php'); |
|---|
| 269 | } |
|---|
| 270 | } |
|---|
| 271 | ?> |
|---|