[ Index ] |
PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12) |
[Summary view] [Print] [Text view]
1 <?php 2 /************************************************************************************* 3 Copyright notice 4 5 (c) 2002-2012 Oliver Georgi <oliver@phpwcms.de> // All rights reserved. 6 7 This script is part of PHPWCMS. The PHPWCMS web content management system is 8 free software; you can redistribute it and/or modify it under the terms of 9 the GNU General Public License as published by the Free Software Foundation; 10 either version 2 of the License, or (at your option) any later version. 11 12 The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html 13 A copy is found in the textfile GPL.txt and important notices to the license 14 from the author is found in LICENSE.txt distributed with these scripts. 15 16 This script is distributed in the hope that it will be useful, but WITHOUT ANY 17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 18 PARTICULAR PURPOSE. See the GNU General Public License for more details. 19 20 This copyright notice MUST APPEAR in all copies of the script! 21 *************************************************************************************/ 22 23 // ---------------------------------------------------------------- 24 // obligate check for phpwcms constants 25 if (!defined('PHPWCMS_INCLUDE_CHECK')) { 26 die("You Cannot Access This Script Directly, Have a Nice Day."); 27 } 28 // ---------------------------------------------------------------- 29 30 @ini_set( 'arg_separator.output' , '&' ); 31 32 if(!empty($phpwcms['php_timezone'])) { 33 @ini_set( 'date.timezone' , $phpwcms['php_timezone'] ); 34 } 35 36 // i18n charsets that might be accessible - in general used in MySQL 37 // but a few more as listed here http://www.w3.org/International/O-charset-list.html 38 $phpwcms['charsets'] = array( 39 'iso-2022-kr', 40 'iso-2022-jp', 41 'iso-8859-1', 42 'iso-8859-2', 43 'iso-8859-3', 44 'iso-8859-4', 45 'iso-8859-5', 46 'iso-8859-6', 47 'iso-8859-7', 48 'iso-8859-8', 49 'iso-8859-8-i', 50 'iso-8859-9', 51 'iso-8859-10', 52 'iso-8859-11', 53 'iso-8859-12', 54 'iso-8859-13', 55 'iso-8859-14', 56 'iso-8859-15', 57 'iso-10646-ucs-2', 58 'windows-874', 59 'windows-1250', 60 'windows-1251', 61 'windows-1252', 62 'windows-1253', 63 'windows-1254', 64 'windows-1255', 65 'windows-1256', 66 'windows-1257', 67 'windows-1258', 68 'koi8-r', 69 'big5', 70 'gb2312', 71 'us-ascii', 72 'utf-16', 73 'utf-8', 74 'utf-7', 75 'x-user-defined', 76 'euc-cn', 77 'euc-jp', 78 'euc-kr', 79 'euc-tw', 80 'ks_c_5601-1987', 81 'tis-620', 82 'shift_jis' 83 ); 84 85 define ('PHPWCMS_CHARSET', empty($phpwcms["charset"]) ? 'utf-8' : strtolower($phpwcms["charset"])); 86 87 if(defined('CUSTOM_CONTENT_TYPE')) { 88 89 header(CUSTOM_CONTENT_TYPE); 90 91 } else { 92 93 header('Content-Type: text/html; charset='.PHPWCMS_CHARSET); 94 $_use_content_type = 'text/html'; 95 96 } 97 98 99 // define the real path of the phpwcms installation 100 // important to script that must know the real path to files or something else 101 102 $phpwcms['DOC_ROOT'] = rtrim( str_replace("\\", '/', $phpwcms['DOC_ROOT']), '/' ); 103 if( empty($phpwcms["root"]) ) { 104 $phpwcms["root"] = ''; 105 $phpwcms["host_root"] = ''; 106 } else { 107 $phpwcms["root"] = trim( $phpwcms["root"], '/' ); 108 $phpwcms["host_root"] = '/'.$phpwcms["root"]; 109 $phpwcms['DOC_ROOT'] .= '/' . $phpwcms["root"]; 110 $phpwcms["root"] .= '/'; 111 } 112 113 define ("PHPWCMS_ROOT", $phpwcms['DOC_ROOT']); 114 define ('PHPWCMS_FILES', $phpwcms["file_path"] . '/'); 115 define ('PHPWCMS_BASEPATH', '/' . $phpwcms["root"]); 116 define ('On', true); 117 define ('Off', false); 118 define ('PHPWCMS_USER_KEY', md5(getRemoteIP().$phpwcms['DOC_ROOT'].$phpwcms["db_pass"])); 119 define ('PHPWCMS_REWRITE_EXT', isset($phpwcms['rewrite_ext']) ? $phpwcms['rewrite_ext'] : '.html'); 120 define ('IS_PHP5', version_compare(PHP_VERSION, '5.0.0', '>=')); 121 122 // Mime-Type definitions 123 require_once (PHPWCMS_ROOT.'/include/inc_lib/mimetype.inc.php'); 124 require_once (PHPWCMS_ROOT.'/include/inc_lib/revision/revision.php'); 125 126 phpwcms_getUserAgent(); 127 define('BROWSER_NAME', $phpwcms['USER_AGENT']['agent']); 128 define('BROWSER_NUMBER', $phpwcms['USER_AGENT']['version']); 129 define('BROWSER_OS', $phpwcms['USER_AGENT']['platform']); 130 define('BROWSER_MOBILE', $phpwcms['USER_AGENT']['mobile']); 131 132 $phpwcms["file_path"] = '/'.$phpwcms["file_path"].'/' ; // "/phpwcms_filestorage/" 133 134 define ('TEMPLATE_PATH', $phpwcms["templates"].'/'); 135 $phpwcms["templates"] = '/'.$phpwcms["templates"].'/' ; // "/phpwcms_template/" 136 $phpwcms["content_path"] = $phpwcms["content_path"].'/' ; // "content/" 137 define ('CONTENT_PATH', $phpwcms["content_path"]); 138 $phpwcms["cimage_path"] = $phpwcms["cimage_path"].'/' ; // "images/" 139 $phpwcms["ftp_path"] = '/'.$phpwcms["ftp_path"].'/' ; // "/phpwcms_ftp/" 140 141 define ('PHPWCMS_TEMPLATE', PHPWCMS_ROOT.$phpwcms["templates"]); 142 define ('PHPWCMS_URL', $phpwcms["site"].$phpwcms["root"]); 143 144 $phpwcms['parse_url'] = parse_url(PHPWCMS_URL); 145 define ('PHPWCMS_HOST', $phpwcms['parse_url']['host'].$phpwcms["host_root"]); 146 define ('PHPWCMS_IMAGES', $phpwcms["content_path"].$phpwcms["cimage_path"]); 147 define ('PHPWCMS_TEMP', PHPWCMS_ROOT.'/'.$phpwcms["content_path"].'tmp/'); 148 define ('PHPWCMS_CONTENT', PHPWCMS_ROOT.'/'.$phpwcms["content_path"]); 149 define ('PHPWCMS_THUMB', PHPWCMS_CONTENT.$phpwcms["cimage_path"]); 150 define ('PHPWCMS_RSS', PHPWCMS_CONTENT.'rss'); 151 define ('LF', "\n"); //global new line Feed 152 define ('FEUSER_REGKEY', empty($phpwcms['feuser_regkey']) ? 'FEUSER' : $phpwcms['feuser_regkey']); 153 154 if(function_exists('mb_substr')) { 155 define ('MB_SAFE', true); //mbstring safe - better to do a check here 156 } else { 157 define ('MB_SAFE', false); 158 159 function mb_substr(string $str, int $start, int $length, string $encoding) { 160 if(phpwcms_seems_utf8($str)) { 161 return utf8_encode(substr(utf8_decode($str), $start, $length)); 162 } else { 163 return substr($str, $start, $length); 164 } 165 } 166 function mb_strlen(string $str, string $encoding) { 167 return strlen(phpwcms_seems_utf8($str) ? utf8_decode($str) : $str); 168 } 169 } 170 171 $phpwcms['modules'] = array(); 172 $phpwcms['modules_fe_render'] = array(); 173 $phpwcms['modules_fe_init'] = array(); 174 175 // 2011-12-27 176 // Changed Image Manipulation class to CodeIgniter based class 177 // which supports GD, GD2, ImageMagick and NetPBM 178 if(isset($phpwcms['image_library'])) { 179 180 $phpwcms['image_library'] = strtolower($phpwcms['image_library']); 181 $phpwcms['library_path'] = empty($phpwcms['library_path']) ? '' : $phpwcms['library_path']; 182 183 if(!in_array($phpwcms['image_library'], array('gd2', 'imagemagick', 'netpbm', 'gd'))) { 184 $phpwcms['image_library'] = 'gd2'; 185 } 186 187 // Fallback to old setting 188 } else { 189 190 $phpwcms['image_library'] = empty($phpwcms["imagick"]) ? 'gd2' : 'imagemagick'; 191 $phpwcms['library_path'] = empty($phpwcms["imagick_path"]) ? '' : str_replace('//', '/', str_replace("\\", '/', $phpwcms["imagick_path"].'/') ); 192 193 unset($phpwcms["imagick_path"], $phpwcms["imagick"]); 194 195 } 196 197 if(empty($phpwcms['SMTP_MAILER'])) { 198 $phpwcms['SMTP_MAILER'] = 'mail'; 199 } 200 if(empty($phpwcms['SMTP_FROM_EMAIL'])) { 201 $phpwcms['SMTP_FROM_EMAIL'] = $phpwcms["admin_email"]; 202 } 203 204 $phpwcms['default_lang'] = strtolower($phpwcms['default_lang']); 205 $phpwcms['DOCTYPE_LANG'] = empty($phpwcms['DOCTYPE_LANG']) ? $phpwcms['default_lang'] : strtolower(trim($phpwcms['DOCTYPE_LANG'])); 206 207 if(empty($phpwcms['js_lib'])) { 208 $phpwcms['js_lib'] = array( 209 'mootools-1.4' => 'MooTools 1.4', 210 'mootools-1.4-compat' => 'MooTools 1.4 Compat', 211 'mootools-1.3' => 'MooTools 1.3', 212 'mootools-1.3-compat' => 'MooTools 1.3 Compat', 213 'mootools-1.2' => 'MooTools 1.2', 214 'mootools-1.1' => 'MooTools 1.1', 215 'jquery-1.7' => 'jQuery 1.7', 216 'jquery-1.6' => 'jQuery 1.6', 217 'jquery-1.5' => 'jQuery 1.5', 218 'jquery-1.4' => 'jQuery 1.4', 219 'jquery' => 'jQuery 1.3' 220 ); 221 } 222 223 if(empty($phpwcms['mode_XHTML'])) { 224 225 $phpwcms['mode_XHTML'] = 0; 226 227 define('PHPWCMS_DOCTYPE', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'.LF.'<html%s>'.LF.'<head>'.LF); 228 define('SCRIPT_CDATA_START', ' <!-- '); 229 define('SCRIPT_CDATA_END' , ' -->'); 230 define('HTML_TAG_CLOSE' , '>'); 231 define('XHTML_MODE', false); 232 define('PHPWCMS_DOCTYPE_LANG', ' lang="{DOCTYPE_LANG}"'); 233 234 } elseif($phpwcms['mode_XHTML'] == 2) { 235 236 define('PHPWCMS_DOCTYPE', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.LF.'<html xmlns="http://www.w3.org/1999/xhtml"%s>'.LF.'<head>'.LF); 237 define('SCRIPT_CDATA_START', ' /* <![CDATA[ */'); 238 define('SCRIPT_CDATA_END' , ' /* ]]> */'); 239 define('HTML_TAG_CLOSE' , ' />'); 240 define('XHTML_MODE', true); 241 define('PHPWCMS_DOCTYPE_LANG', ' xml:lang="{DOCTYPE_LANG}" lang="{DOCTYPE_LANG}"'); 242 243 } elseif($phpwcms['mode_XHTML'] == 3) { 244 245 define('PHPWCMS_DOCTYPE', '<!DOCTYPE html>'.LF.'<html%s>'.LF.'<head>'.LF); 246 define('SCRIPT_CDATA_START', ''); 247 define('SCRIPT_CDATA_END' , ''); 248 define('HTML_TAG_CLOSE' , ' />'); 249 define('XHTML_MODE', true); 250 define('PHPWCMS_DOCTYPE_LANG', ' lang="{DOCTYPE_LANG}"'); 251 252 } else { 253 254 $phpwcms['mode_XHTML'] = 1; 255 256 define('PHPWCMS_DOCTYPE', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'.LF.'<html xmlns="http://www.w3.org/1999/xhtml"%s>'.LF.'<head>'.LF); 257 define('SCRIPT_CDATA_START', ' <!-- '); 258 define('SCRIPT_CDATA_END' , ' -->'); 259 define('HTML_TAG_CLOSE' , ' />'); 260 define('XHTML_MODE', true); 261 define('PHPWCMS_DOCTYPE_LANG', ' xml:lang="{DOCTYPE_LANG}" lang="{DOCTYPE_LANG}"'); 262 263 } 264 265 // Todo: Later remove these 266 $phpwcms["release"] = PHPWCMS_VERSION; 267 $phpwcms["release_date"] = PHPWCMS_RELEASE_DATE; 268 $phpwcms["revision"] = PHPWCMS_REVISION; 269 270 // ------------------------------------------------------------- 271 272 function removeSessionName($str='') { 273 // is used to remove all &hashID=... 274 // not useful when when storing in cache 275 // because it stores unneccessary session IDs too 276 $sessName = session_name(); 277 if($sessName) { 278 $str = preg_replace('/[&|\?]{0,1}'.$sessName.'=[a-zA-Z0-9]{1,}/', '', $str); 279 } 280 return $str; 281 } 282 283 284 function buildGlobalGET($return = '') { 285 // build internal array containing all GET values 286 // and remove session from this array 287 $GLOBALS['_getVar'] = array(); 288 289 $_queryVal = empty($_SERVER['QUERY_STRING']) ? array() : explode('&', $_SERVER['QUERY_STRING']); 290 $_queryCount = count($_queryVal); 291 $_getCount = is_array($_GET) ? count($_GET) : 0; 292 293 if($_getCount && $_getCount >= $_queryCount) { 294 $GLOBALS['_getVar'] = $_GET; 295 } elseif($_queryCount) { 296 foreach($_queryVal as $value) { 297 $key = explode('=', $value); 298 $val = empty($key[1]) ? '' : $key[1]; 299 $key = $key[0]; 300 $GLOBALS['_getVar'][$key] = $val; 301 } 302 } 303 304 unset( $_GET[session_name()], 305 $GLOBALS['_getVar'][session_name()], 306 $GLOBALS['_getVar'][''] 307 ); 308 309 if( get_magic_quotes_gpc() ) { 310 foreach($GLOBALS['_getVar'] as $key => $value) { 311 $GLOBALS['_getVar'][$key] = stripslashes($value); 312 } 313 } 314 315 if($return == 'getQuery') { 316 return returnGlobalGET_QueryString('htmlentities'); 317 } 318 } 319 320 // build phpwcms specific relative url 321 function rel_url($add=array(), $remove=array(), $id_alias='', $format='htmlentities', $glue='&', $bind='=') { 322 323 return 'index.php' . returnGlobalGET_QueryString($format, $add, $remove, $id_alias, $glue, $bind); 324 325 } 326 // build phpwcms specific absolute url 327 function abs_url($add=array(), $remove=array(), $id_alias='', $format='htmlentities', $glue='&', $bind='=') { 328 329 return PHPWCMS_URL . 'index.php' . returnGlobalGET_QueryString($format, $add, $remove, $id_alias, $glue, $bind); 330 331 } 332 333 // build a URL query string based on current values 334 function returnGlobalGET_QueryString($format='', $add=array(), $remove=array(), $id_alias='', $glue='&', $bind='=') { 335 336 $queryString = array(); 337 $_getVarTemp = $GLOBALS['_getVar']; 338 339 // replace first value with $id_alias 340 if($id_alias !== '') { 341 342 $id_alias = explode($bind, $id_alias, 2); 343 $id_alias[0] = trim($id_alias[0]); 344 345 if($id_alias[0] !== '') { 346 $id_alias[1] = isset($id_alias[1]) ? trim($id_alias[1]) : ''; 347 array_shift($_getVarTemp); 348 $_getVarTemp = array($id_alias[0] => $id_alias[1]) + $_getVarTemp; 349 } 350 } 351 352 foreach($remove as $value) { 353 unset($_getVarTemp[$value]); 354 } 355 356 $pairs = count($add) ? array_merge($_getVarTemp, $add) : $_getVarTemp; 357 358 switch($format) { 359 360 case 'htmlentities': $glue = html_entities($glue); 361 $funct = 'getQueryString_htmlentities'; 362 break; 363 364 case 'urlencode': $funct = 'getQueryString_urlencode'; 365 break; 366 367 case 'rawurlencode': $funct = 'getQueryString_rawurlencode'; 368 break; 369 370 default: $funct = 'getQueryString_default'; 371 372 } 373 374 foreach($pairs as $key => $value) { 375 376 $queryString[] = $funct($key, $value, $bind); 377 378 } 379 380 return count($queryString) ? '?'.implode($glue, $queryString) : ''; 381 } 382 383 function getQueryString_htmlentities($key='', $value='', $bind='=') { 384 if($value !== '') { 385 return html_entities(urlencode($key).$bind.str_replace('%2C', ',', urlencode($value))); 386 } 387 return html_entities(urlencode($key)); 388 } 389 390 function getQueryString_urlencode($key='', $value='', $bind='=') { 391 if($value !== '') { 392 return urlencode($key).$bind.urlencode($value); 393 } 394 return urlencode($key); 395 } 396 397 function getQueryString_rawurlencode($key='', $value='', $bind='=') { 398 if($value !== '') { 399 return rawurlencode($key).$bind.rawurlencode($value); 400 } 401 return rawurlencode($key); 402 } 403 404 function getQueryString_default($key='', $value='', $bind='=') { 405 if($value !== '') { 406 return $key.$bind.$value; 407 } 408 return $key; 409 } 410 411 412 413 function cleanupPOSTandGET() { 414 // remove possible unsecure PHP replacement tags in GET and POST vars 415 if(isset($_POST) && count($_POST)) { 416 foreach($_POST as $key => $value) { 417 if(!is_array($_POST[$key])) { 418 $_POST[$key] = remove_unsecure_rptags($value); 419 } 420 } 421 } 422 if(isset($_GET) && count($_GET)) { 423 foreach($_GET as $key => $value) { 424 $_GET[$key] = remove_unsecure_rptags($value); 425 } 426 } 427 } 428 429 function remove_unsecure_rptags($check) { 430 // this is for security reasons 431 // where you can use input fields for 432 // code injection 433 434 //remove special replacement tags 435 $check = preg_replace('/\{PHP:(.*?)\}/i', '$1', $check); 436 $check = preg_replace('/\{PHPVAR:(.*?)\}/si', '$1', $check); 437 $check = preg_replace('/\[PHP\](.*?)\[\/PHP\]/si', '$1', $check); 438 $check = preg_replace('/\{URL:(.*?)\}/i', '$1', $check); 439 $check = str_replace('[PHP]', '[ PHP ]', $check); 440 $check = str_replace('[/PHP]', '[ /PHP ]', $check); 441 $check = str_replace('{PHP:', '{ PHP :', $check); 442 $check = str_replace('{PHPVAR:', '{ PHPVAR :', $check); 443 $check = str_replace('{URL:', '{ URL :', $check); 444 return $check; 445 } 446 447 function headerRedirect($target='', $type=0) { 448 if(isset($_SESSION)) { 449 session_write_close(); 450 } 451 switch($type) { 452 case 307: header('HTTP/1.1 307 Temporary Redirect'); break; 453 case 401: header('HTTP/1.1 401 Authorization Required'); break; 454 case 404: header('HTTP/1.1 404 Not Found'); break; 455 case 503: header('HTTP/1.1 503 Service Unavailable'); break; 456 case 301: header('HTTP/1.1 301 Moved Permanently'); break; 457 } 458 if($target !== '') { 459 header('Location: '.$target); 460 exit(); 461 } 462 } 463 464 function _initSession() { 465 if(!session_id()) session_start(); 466 if(empty($_SESSION['phpwcmsSessionInit']) && function_exists("session_regenerate_id")) { 467 session_regenerate_id(); 468 $_SESSION['phpwcmsSessionInit'] = true; 469 } 470 return session_id(); 471 } 472 473 function getRemoteIP() { 474 if(defined('REMOTE_IP')) { 475 return REMOTE_IP; 476 } 477 $IP = 'unknown'; 478 if (!empty($_SERVER['HTTP_CLIENT_IP']) && strcasecmp($_SERVER['HTTP_CLIENT_IP'], 'unknown')) { 479 $IP = $_SERVER['HTTP_CLIENT_IP']; 480 } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], 'unknown')) { 481 $IP = $_SERVER['HTTP_X_FORWARDED_FOR']; 482 } elseif (!empty($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) { 483 $IP = $_SERVER['REMOTE_ADDR']; 484 } 485 define('REMOTE_IP', $IP); 486 return $IP; 487 } 488 489 // Get user agent informations, based on concepts of OpenAds 2.0 (c) 2000-2007 by the OpenAds developers 490 function phpwcms_getUserAgent($USER_AGENT='') { 491 492 if(empty($USER_AGENT)) { 493 $USER_AGENT = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; 494 $index = 'USER_AGENT'; 495 } else { 496 $index = 'USER_AGENT_'.md5($USER_AGENT); 497 } 498 499 if(isset($GLOBALS['phpwcms'][$index])) { 500 return $GLOBALS['phpwcms'][$index]; 501 } 502 503 if(empty($USER_AGENT)) { 504 return $GLOBALS['phpwcms'][$index] = array( 505 'agent' => 'Other', 506 'version' => 0, 507 'platform' => 'Other', 508 'mobile' => 0, 509 'device' => 'Default', 510 'bot' => 0, 511 'engine' => 'Other' 512 ); 513 } 514 515 $mobile = 0; 516 $bot = 0; 517 $device = 'Other'; 518 $ver = 0; 519 $agent = 'Other'; 520 $platform = 'Other'; 521 $engine = 'Other'; 522 523 if(preg_match('#MSIE ([0-9]+)(.*Opera ([0-9]+))?#', $USER_AGENT, $log_version)) { 524 if(isset($log_version[3])) { 525 $ver = $log_version[3]; 526 $agent = 'Opera'; 527 $engine = 'Opera'; 528 } else { 529 $ver = $log_version[1]; 530 $agent = 'IE'; 531 $engine = 'IE'; 532 } 533 } elseif(preg_match('#Mozilla.*Firefox\/([0-9]+)#', $USER_AGENT, $log_version)) { 534 $ver = $log_version[1]; 535 $agent = 'Firefox'; 536 $engine = 'Gecko'; 537 } elseif(preg_match('#Mozilla.*Chrome\/([0-9]+)#', $USER_AGENT, $log_version)) { 538 $ver = $log_version[1]; 539 $agent = 'Chrome'; 540 $engine = 'WebKit'; 541 } elseif(strstr($USER_AGENT, 'Safari') && preg_match('#Safari/([0-9]+)#', $USER_AGENT, $log_version)) { 542 $ver = $log_version[1]; 543 $agent = 'Safari'; 544 $engine = 'WebKit'; 545 } elseif(preg_match('#Mozilla/([0-9]+)#', $USER_AGENT, $log_version)) { 546 $ver = $log_version[1]; 547 $agent = 'Mozilla'; 548 $engine = 'Gecko'; 549 } elseif(preg_match('#Opera.* Version\/([0-9]+)#', $USER_AGENT, $log_version)) { 550 $ver = $log_version[1]; 551 $agent = 'Opera'; 552 $engine = 'Opera'; 553 } elseif(preg_match('#Opera[/ ]([0-9]+)#', $USER_AGENT, $log_version)) { 554 $ver = $log_version[1]; 555 $agent = 'Opera'; 556 $engine = 'Opera'; 557 } elseif(strstr($USER_AGENT, 'Konqueror') && preg_match('#Konqueror/([0-9]+)#', $USER_AGENT, $log_version)) { 558 $ver = $log_version[1]; 559 $agent = 'Konqueror'; 560 $engine = 'KHTML'; 561 } 562 563 $USER_AGENT = strtolower($USER_AGENT); 564 565 if(strpos($USER_AGENT, 'windows phone os') !== false) { 566 $agent = 'IEMobile'; 567 $platform = 'WinPhone'; 568 $mobile = 1; 569 $device = 'Smartphone'; 570 } elseif(strpos($USER_AGENT, 'windows ce') !== false) { 571 $platform = 'WinCE'; 572 $mobile = 1; 573 $device = 'Smartphone'; 574 } elseif(strpos($USER_AGENT, 'win') !== false) { 575 $platform = 'Win'; 576 $device = 'Desktop'; 577 } elseif(strpos($USER_AGENT, 'iphone') !== false) { 578 $platform = 'iOS'; 579 $mobile = 1; 580 $device = 'Smartphone'; 581 } elseif(strpos($USER_AGENT, 'ipad') !== false) { 582 $platform = 'iOS'; 583 $mobile = 1; 584 $device = 'Tablet'; 585 } elseif(strpos($USER_AGENT, 'ipod') !== false) { 586 $platform = 'iOS'; 587 $mobile = 1; 588 $device = 'Smartphone'; 589 } elseif(strpos($USER_AGENT, 'mac') !== false) { 590 $platform = 'Mac'; 591 $device = 'Desktop'; 592 } elseif(strpos($USER_AGENT, 'googletv') !== false) { 593 $platform = 'GoogleTV'; 594 $mobile = 1; 595 $device = 'TV'; 596 $engine = 'WebKit'; 597 } elseif(preg_match('/android.*tablet/', $USER_AGENT)) { 598 $platform = 'Android'; 599 $mobile = 1; 600 $device = 'Tablet'; 601 $engine = 'Webkit'; 602 } elseif(preg_match('/android.*mobile/', $USER_AGENT)) { 603 $platform = 'Android'; 604 $mobile = 1; 605 $device = 'Smartphone'; 606 $engine = 'Webkit'; 607 } elseif(preg_match('/android(?!.*mobile)/', $USER_AGENT)) { 608 $platform = 'Android'; 609 $mobile = 1; 610 $device = 'Tablet'; 611 $engine = 'Webkit'; 612 } elseif(strpos($USER_AGENT, 'rim tablet') !== false) { 613 $platform = 'Blackberry'; 614 $mobile = 1; 615 $device = 'Tablet'; 616 $engine = 'Webkit'; 617 } elseif(strpos($USER_AGENT, 'blackberry') !== false) { 618 $platform = 'Blackberry'; 619 $mobile = 1; 620 $device = 'Smartphone'; 621 $engine = 'Webkit'; 622 } elseif(strpos($USER_AGENT, 'webos') !== false) { 623 $platform = 'WebOS'; 624 $mobile = 1; 625 $device = 'Smartphone'; 626 $engine = 'Webkit'; 627 } elseif(strpos($USER_AGENT, 'kindle') !== false) { 628 $platform = 'Android'; 629 $mobile = 1; 630 $device = 'Tablet'; 631 $engine = 'Webkit'; 632 } elseif(strpos($USER_AGENT, 'silk') !== false) { 633 $platform = 'Linux'; 634 $mobile = 1; 635 $device = 'Tablet'; 636 $engine = 'Webkit'; 637 } elseif(strpos($USER_AGENT, 'linux') !== false) { 638 $platform = 'Linux'; 639 } elseif(strpos($USER_AGENT, 'unix') !== false) { 640 $platform = 'Unix'; 641 } elseif(strpos($USER_AGENT, 'symbian') !== false) { 642 $platform = 'Symbian'; 643 $mobile = 1; 644 $device = 'Smartphone'; 645 } elseif($USER_AGENT) { 646 647 if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) { 648 $mobile = 1; 649 } 650 651 if(empty($GLOBALS['phpwcms']["BOTS"]) || !is_array($GLOBALS['phpwcms']["BOTS"])) { 652 $GLOBALS['phpwcms']["BOTS"] = array('googlebot', 'msnbot', 'bingbot', 'ia_archiver', 'altavista', 'slurp', 'yahoo', 'jeeves', 'teoma', 'lycos', 'crawler'); 653 } 654 655 if(preg_match('/('.implode('|', $GLOBALS['phpwcms']["BOTS"]).')/', $USER_AGENT, $match_bot)) { 656 $agent = $match_bot[1]; 657 $bot = 1; 658 $device = 'Bot'; 659 } 660 } 661 662 return $GLOBALS['phpwcms'][$index] = array( 663 'agent' => $agent, 664 'version' => intval($ver), 665 'platform' => $platform, 666 'mobile' => $mobile, 667 'device' => $device, 668 'bot' => $bot, 669 'engine' => $engine 670 ); 671 } 672 673 /** 674 * Return current UNIX timestamp 675 * Wrapper function that might be enhanced for regional time and so on 676 **/ 677 function now($format=NULL) { 678 return is_string($format) ? date($format) : time(); 679 } 680 681 /** 682 * Log to db 683 * 684 * Default log types: DEBUG|INFO|ERROR|INFO or use specific module name 685 */ 686 function log_message($type='UNDEFINED', $message='', $userid=0) { 687 688 $log = array( 689 'log_created' => date('Y-m-d H:i:s', now()), 690 'log_type' => 'UNDEFINED', 691 'log_ip' => getRemoteIP(), 692 'log_user_agent' => '', 693 'log_user_id' => 0, 694 'log_user_name' => '', 695 'log_referrer_id' => 0, 696 'log_referrer_url' => '', 697 'log_data1' => '', 698 'log_data2' => '', 699 'log_data3' => '', 700 'log_msg' => '' 701 ); 702 703 if(is_array($type)) { 704 foreach($type as $key => $value) { 705 if(isset($log[$key])) { 706 $log[$key] = $value; 707 } 708 } 709 } else { 710 $log['log_type'] = trim($type); 711 $log['log_user_id'] = intval($userid); 712 $log['log_msg'] = trim($message); 713 } 714 715 $log['log_type'] = strtoupper($log['log_type']); 716 717 if($log['log_user_agent'] == '') { 718 $log['log_user_agent'] = empty($_SERVER['HTTP_USER_AGENT']) ? implode( ', ', phpwcms_getUserAgent() ) : $_SERVER['HTTP_USER_AGENT']; 719 } 720 if(empty($log['log_referrer_url']) && isset($_SERVER['HTTP_REFERER'])) { 721 $log['log_referrer_url'] = $_SERVER['HTTP_REFERER']; 722 } 723 724 _dbInsert( 'phpwcms_log', $log, 'DELAYED' ); 725 726 } 727 728 729 function init_frontend_edit() { 730 // define VISIBLE_MODE 731 // 0 = frontend (all) mode 732 // 1 = article user mode 733 // 2 = admin user mode 734 if(empty($_SESSION["wcs_user_id"])) { 735 define('VISIBLE_MODE', 0); 736 } else { 737 define('VISIBLE_MODE', $_SESSION['wcs_user_admin'] === 1 ? 2 : 1); 738 } 739 define ('FE_EDIT_LINK', VISIBLE_MODE == 0 || empty($GLOBALS['phpwcms']['frontend_edit']) ? false : true); 740 } 741 742 /** 743 * Wrapper for htmlentities() to handle charset better inside of phpwcms 744 **/ 745 function html_entities($string='', $quote_mode=ENT_QUOTES, $charset=PHPWCMS_CHARSET) { 746 return @htmlentities($string, $quote_mode, $charset); 747 } 748 749 function getMicrotime() { 750 list($usec, $sec) = explode(' ', microtime()); 751 return ((float)$usec + (float)$sec); 752 } 753 754 function getMicrotimeDiff($start=0) { 755 return (getMicrotime() - $start); 756 } 757 758 /** 759 * Return login.php 760 */ 761 function get_login_file() { 762 if(defined('PHPWCMS_LOGIN_PHP')) { 763 return PHPWCMS_LOGIN_PHP; 764 } 765 global $phpwcms; 766 $login = empty($GLOBALS['phpwcms']['login.php']) ? 'login.php' : $GLOBALS['phpwcms']['login.php']; 767 if(is_file(PHPWCMS_ROOT.'/'.$login)) { 768 define('PHPWCMS_LOGIN_PHP', $login); 769 return PHPWCMS_LOGIN_PHP; 770 } 771 if(is_file(PHPWCMS_ROOT.'/login.php')) { 772 define('PHPWCMS_LOGIN_PHP', 'login.php'); 773 return PHPWCMS_LOGIN_PHP; 774 } 775 die('Login.php cannot be found. We stop here!'); 776 } 777 778 /** 779 * Encrypt string 780 */ 781 function encrypt($plaintext, $key='8936AeYcenBDLyMzN', $cypher='blowfish', $mode='cfb') { 782 $td = mcrypt_module_open($cypher, '', $mode, ''); 783 $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); 784 mcrypt_generic_init($td, $key, $iv); 785 $crypttext = mcrypt_generic($td, $plaintext); 786 mcrypt_generic_deinit($td); 787 return $iv.$crypttext; 788 } 789 790 /** 791 * Decrypt string 792 */ 793 function decrypt($crypttext, $key='8936AeYcenBDLyMzN', $cypher='blowfish', $mode='cfb') { 794 $plaintext = ''; 795 $td = mcrypt_module_open($cypher, '', $mode, ''); 796 $ivsize = mcrypt_enc_get_iv_size($td); 797 $iv = substr($crypttext, 0, $ivsize); 798 $crypttext = substr($crypttext, $ivsize); 799 if ($iv) { 800 mcrypt_generic_init($td, $key, $iv); 801 $plaintext = mdecrypt_generic($td, $crypttext); 802 } 803 return $plaintext; 804 } 805 806 /** 807 * Get current user visual mode 808 */ 809 function get_user_vmode() { 810 switch(VISIBLE_MODE) { 811 case 1: return 'editor'; break; 812 case 2: return 'admin'; break; 813 default: return 'all'; 814 }; 815 } 816 817 function get_user_rc($g='', $pu=501289, $pr=506734, $e=array('SAAAAA','PT96y0w','5k4kWtC','8RAoSD4','Jp6RmA','6LfyU74','OVQRK5f','kbHQ6qx','YdgUgX-','H808le')) { 818 $c = ''; foreach(str_split(strval($$g)) as $a) $c.=$e[intval($a)]; return $c; 819 } 820 821 822 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Jan 29 16:31:14 2012 | Cross-referenced by PHPXref 0.7.1 |