[ Index ] |
|
Code source de phpMyVisites 2.3 |
1 <?php 2 /** 3 * ClickHeat : Fichier principal / Main file 4 * 5 * @author Yvan Taviaud - LabsMedia - www.labsmedia.com 6 * @since 27/10/2006 7 **/ 8 9 $__action = isset($_GET['action']) && $_GET['action'] !== '' ? $_GET['action'] : 'view'; 10 11 if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] !== '') 12 { 13 $realPath = &$_SERVER['REQUEST_URI']; 14 } 15 elseif (isset($_SERVER['SCRIPT_NAME']) && $_SERVER['SCRIPT_NAME'] !== '') 16 { 17 $realPath = &$_SERVER['SCRIPT_NAME']; 18 } 19 else 20 { 21 exit(LANG_UNKNOWN_DIR); 22 } 23 if (substr($realPath, -1) === '/') 24 { 25 header('Location: '.$realPath.'index.php'); 26 exit; 27 } 28 29 /** First of all, check if we are inside PhpMyVisites */ 30 $dirName = dirname($realPath); 31 if ($dirName === '/') 32 { 33 $dirName = ''; 34 } 35 if (defined('INCLUDE_PATH')) 36 { 37 define('CLICKHEAT_PATH', $dirName.'/plugins/clickheat/libs/'); 38 define('CLICKHEAT_INDEX_PATH', 'index.php?mod=clickheat.view_clickheat&'); 39 define('CLICKHEAT_ROOT', str_replace('\\', '/', dirname(__FILE__)).'/'); 40 define('CLICKHEAT_CONFIG', INCLUDE_PATH.'/config/clickheat.php'); 41 define('IS_PHPMV_MODULE', true); 42 } 43 else 44 { 45 define('CLICKHEAT_PATH', $dirName.'/'); 46 define('CLICKHEAT_INDEX_PATH', 'index.php?'); 47 define('CLICKHEAT_ROOT', str_replace('\\', '/', dirname(__FILE__)).'/'); 48 define('CLICKHEAT_CONFIG', CLICKHEAT_ROOT.'config/config.php'); 49 define('IS_PHPMV_MODULE', false); 50 } 51 52 /** Improve buffer usage and compression */ 53 if (function_exists('ob_start') && IS_PHPMV_MODULE === false) 54 { 55 if (function_exists('ob_gzhandler')) 56 { 57 @ob_start('ob_gzhandler'); 58 } 59 else 60 { 61 @ob_start(); 62 } 63 } 64 65 /** Loading language according to browser's Accept-Language or cookie «language» */ 66 if (isset($_GET['language'])) 67 { 68 $lang = $_GET['language']; 69 } 70 elseif (isset($_COOKIE['language'])) 71 { 72 $lang = $_COOKIE['language']; 73 } 74 elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) 75 { 76 $lang = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)); 77 } 78 if (!isset($lang) || !in_array($lang, array('fr', 'en', 'ru', 'uk'))) 79 { 80 $lang = 'en'; 81 } 82 if (!isset($_COOKIE['language']) || $_COOKIE['language'] !== $lang) 83 { 84 setcookie('language', $lang, time() + 365 * 86400, '/'); 85 } 86 define('CLICKHEAT_LANGUAGE', $lang); 87 unset($lang); 88 include CLICKHEAT_ROOT.'languages/'.CLICKHEAT_LANGUAGE.'.php'; 89 90 /** If there's no config file, run check script */ 91 if (!file_exists(CLICKHEAT_CONFIG)) 92 { 93 if ($__action !== 'check' && $__action !== 'config') 94 { 95 $__action = 'check'; 96 } 97 } 98 else 99 { 100 include CLICKHEAT_CONFIG; 101 102 /** Login check */ 103 if (IS_PHPMV_MODULE === true) 104 { 105 /** Call external check */ 106 $me = User::getInstance(); 107 define('CLICKHEAT_ADMIN', (bool) $me->hasSomeAdminRights()); 108 /** Viewer only, force it to 'view' action if not view|generate|png */ 109 if (CLICKHEAT_ADMIN === false && $__action !== 'generate' && $__action !== 'png' && $__action !== 'iframe' && $__action !== 'cleaner' && $__action !== 'logout') 110 { 111 $__action = 'view'; 112 } 113 } 114 elseif (isset($_COOKIE['clickheat'])) 115 { 116 if ($_COOKIE['clickheat'] === $clickheatConf['adminLogin'].'||'.$clickheatConf['adminPass']) 117 { 118 /** Everything is fine, admin logged */ 119 define('CLICKHEAT_ADMIN', true); 120 } 121 elseif ($_COOKIE['clickheat'] === $clickheatConf['viewerLogin'].'||'.$clickheatConf['viewerPass']) 122 { 123 /** Viewer logged, force it to 'view' action if not view|generate|png */ 124 if ($__action !== 'generate' && $__action !== 'png' && $__action !== 'iframe' && $__action !== 'cleaner' && $__action !== 'logout') 125 { 126 $__action = 'view'; 127 } 128 } 129 else 130 { 131 /** Not logged, send him to login form */ 132 $__action = 'logout'; 133 } 134 } 135 else 136 { 137 if (isset($_POST['login']) && isset($_POST['pass'])) 138 { 139 if ($_POST['login'] === $clickheatConf['adminLogin'] && md5($_POST['pass']) === $clickheatConf['adminPass']) 140 { 141 /** Set a session cookie */ 142 setcookie('clickheat', $clickheatConf['adminLogin'].'||'.$clickheatConf['adminPass'], 0, '/'); 143 /** Redirect to index.php */ 144 header('Content-Type: text/html'); 145 146 /** Upgrade needed ? */ 147 include CLICKHEAT_ROOT.'version.php'; 148 if (!isset($clickheatConf['version']) || $clickheatConf['version'] !== CLICKHEAT_VERSION) 149 { 150 header('Location: '.CLICKHEAT_INDEX_PATH.'action=config'); 151 } 152 else 153 { 154 header('Location: '.CLICKHEAT_INDEX_PATH.'action=view'); 155 } 156 exit; 157 } 158 elseif ($clickheatConf['viewerLogin'] !== '' && $_POST['login'] === $clickheatConf['viewerLogin'] && md5($_POST['pass']) === $clickheatConf['viewerPass']) 159 { 160 /** Set a session cookie */ 161 setcookie('clickheat', $clickheatConf['viewerLogin'].'||'.$clickheatConf['viewerPass'], 0, '/'); 162 /** Redirect to index.php */ 163 header('Content-Type: text/html'); 164 header('Location: '.CLICKHEAT_INDEX_PATH.'action=view'); 165 exit; 166 } 167 } 168 $__action = 'login'; 169 } 170 } 171 if (!defined('CLICKHEAT_ADMIN')) 172 { 173 define('CLICKHEAT_ADMIN', false); 174 } 175 176 /** Specific definitions */ 177 $__screenSizes = array(0 /** Must start with 0 */, 640, 800, 1024, 1280, 1440, 1600, 1800); 178 $__browsersList = array('all' => '', 'firefox' => 'Firefox', 'msie' => 'Internet Explorer', 'safari' => 'Safari', 'opera' => 'Opera', 'kmeleon' => 'K-meleon', 'unknown' => ''); 179 180 switch ($__action) 181 { 182 case 'check': 183 case 'config': 184 case 'view': 185 case 'login': 186 { 187 header('Content-Type: text/html; charset=utf-8'); 188 if ($__action !== 'view' || IS_PHPMV_MODULE === false) 189 { 190 include CLICKHEAT_ROOT.'header.php'; 191 include CLICKHEAT_ROOT.$__action.'.php'; 192 include CLICKHEAT_ROOT.'footer.php'; 193 } 194 else 195 { 196 include CLICKHEAT_ROOT.$__action.'.php'; 197 } 198 break; 199 } 200 case 'generate': 201 case 'layout': 202 case 'javascript': 203 case 'latest': 204 case 'cleaner': 205 { 206 header('Content-Type: text/html; charset=utf-8'); 207 include CLICKHEAT_ROOT.$__action.'.php'; 208 break; 209 } 210 case 'iframe': 211 { 212 $group = isset($_GET['group']) ? str_replace('/', '', $_GET['group']) : ''; 213 if (is_dir($clickheatConf['logPath'].$group)) 214 { 215 $webPage = array('/'); 216 if (file_exists($clickheatConf['logPath'].$group.'/url.txt')) 217 { 218 $f = @fopen($clickheatConf['logPath'].$group.'/url.txt', 'r'); 219 if ($f !== false) 220 { 221 $webPage = explode('>', trim(fgets($f, 1024))); 222 fclose($f); 223 } 224 } 225 echo $webPage[0]; 226 } 227 break; 228 } 229 case 'png': 230 { 231 $imagePath = $clickheatConf['cachePath'].(isset($_GET['file']) ? str_replace('/', '', $_GET['file']) : '**unknown**'); 232 233 header('Content-Type: image/png'); 234 if (file_exists($imagePath)) 235 { 236 readfile($imagePath); 237 } 238 else 239 { 240 readfile(CLICKHEAT_ROOT.'images/warning.png'); 241 } 242 break; 243 } 244 case 'layoutupdate': 245 { 246 $group = isset($_GET['group']) ? str_replace('/', '', $_GET['group']) : ''; 247 $url = isset($_GET['url']) ? $_GET['url'] : ''; 248 $left = isset($_GET['left']) ? (int) $_GET['left'] : 0; 249 $center = isset($_GET['center']) ? (int) $_GET['center'] : 0; 250 $right = isset($_GET['right']) ? (int) $_GET['right'] : 0; 251 252 if (!is_dir($clickheatConf['logPath'].$group) || $url === '') 253 { 254 exit('Error'); 255 } 256 257 $f = @fopen($clickheatConf['logPath'].$group.'/url.txt', 'w'); 258 fputs($f, $url.'>'.$left.'>'.$center.'>'.$right); 259 fclose($f); 260 261 echo 'OK'; 262 break; 263 } 264 case 'logout': 265 { 266 setcookie('clickheat', '', time() - 30 * 86400, '/'); 267 header('Location: index.php'); 268 exit; 269 break; 270 } 271 default: 272 { 273 header('HTTP/1.0 404 Not Found'); 274 exit('Error, page not found'); 275 break; 276 } 277 } 278 ?>
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 |
![]() |