[ Index ] |
PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10) |
[Summary view] [Print] [Text view]
1 <?php 2 /************************************************************************************* 3 Copyright notice 4 5 (c) 2002-2010 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 31 @ini_set( 'arg_separator.output' , '&' ); 32 33 // i18n charsets that might be accessible - in general used in MySQL 34 // but a few more as listed here http://www.w3.org/International/O-charset-list.html 35 $phpwcms['charsets'] = array( 36 'iso-2022-kr', 37 'iso-2022-jp', 38 'iso-8859-1', 39 'iso-8859-2', 40 'iso-8859-3', 41 'iso-8859-4', 42 'iso-8859-5', 43 'iso-8859-6', 44 'iso-8859-7', 45 'iso-8859-8', 46 'iso-8859-8-i', 47 'iso-8859-9', 48 'iso-8859-10', 49 'iso-8859-11', 50 'iso-8859-12', 51 'iso-8859-13', 52 'iso-8859-14', 53 'iso-8859-15', 54 'iso-10646-ucs-2', 55 'windows-874', 56 'windows-1250', 57 'windows-1251', 58 'windows-1252', 59 'windows-1253', 60 'windows-1254', 61 'windows-1255', 62 'windows-1256', 63 'windows-1257', 64 'windows-1258', 65 'koi8-r', 66 'big5', 67 'gb2312', 68 'us-ascii', 69 'utf-16', 70 'utf-8', 71 'utf-7', 72 'x-user-defined', 73 'euc-cn', 74 'euc-jp', 75 'euc-kr', 76 'euc-tw', 77 'ks_c_5601-1987', 78 'tis-620', 79 'shift_jis' 80 ); 81 82 define ('PHPWCMS_CHARSET', empty($phpwcms["charset"]) ? 'utf-8' : strtolower($phpwcms["charset"])); 83 84 /* seems to be problematic at the moment - so always use text/html 85 if (!empty($phpwcms['header_XML']) && $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1' && isset($_SERVER['HTTP_ACCEPT']) && preg_match('|application/xhtml\+xml(?!\s*;\s*q=0)|', $_SERVER['HTTP_ACCEPT'])) { 86 header('Content-Type: application/xhtml+xml; charset='.PHPWCMS_CHARSET); 87 header('Vary: Negotiate, Accept'); 88 $_use_content_type = 'application/xhtml+xml'; 89 } 90 */ 91 if(defined('CUSTOM_CONTENT_TYPE')) { 92 93 header(CUSTOM_CONTENT_TYPE); 94 95 } else { 96 97 header('Content-Type: text/html; charset='.PHPWCMS_CHARSET); 98 $_use_content_type = 'text/html'; 99 100 } 101 102 103 // define the real path of the phpwcms installation 104 // important to script that must know the real path to files or something else 105 106 $phpwcms['DOC_ROOT'] = rtrim( str_replace("\\", '/', $phpwcms['DOC_ROOT']), '/' ); 107 if( empty($phpwcms["root"]) ) { 108 $phpwcms["root"] = ''; 109 $phpwcms["host_root"] = ''; 110 } else { 111 $phpwcms["root"] = trim( $phpwcms["root"], '/' ); 112 $phpwcms["host_root"] = '/'.$phpwcms["root"]; 113 $phpwcms['DOC_ROOT'] .= '/' . $phpwcms["root"]; 114 $phpwcms["root"] .= '/'; 115 } 116 117 define ("PHPWCMS_ROOT", $phpwcms['DOC_ROOT']); 118 define ('PHPWCMS_FILES', $phpwcms["file_path"] . '/'); 119 define ('PHPWCMS_BASEPATH', '/' . $phpwcms["root"]); 120 define ('On', true); 121 define ('Off', false); 122 define ('PHPWCMS_USER_KEY', md5(getRemoteIP().$phpwcms['DOC_ROOT'].$phpwcms["db_pass"])); 123 define ('PHPWCMS_REWRITE_EXT', 'phtml'); 124 125 // Mime-Type definitions 126 require_once (PHPWCMS_ROOT.'/include/inc_lib/mimetype.inc.php'); 127 128 phpwcms_getUserAgent(); 129 define('BROWSER_NAME', $phpwcms['USER_AGENT']['agent']); 130 define('BROWSER_NUMBER', $phpwcms['USER_AGENT']['version']); 131 define('BROWSER_OS', $phpwcms['USER_AGENT']['platform']); 132 133 $phpwcms["file_path"] = '/'.$phpwcms["file_path"].'/' ; // "/phpwcms_filestorage/" 134 135 define ('TEMPLATE_PATH', $phpwcms["templates"].'/'); 136 $phpwcms["templates"] = '/'.$phpwcms["templates"].'/' ; // "/phpwcms_template/" 137 $phpwcms["content_path"] = $phpwcms["content_path"].'/' ; // "content/" 138 define ('CONTENT_PATH', $phpwcms["content_path"]); 139 $phpwcms["cimage_path"] = $phpwcms["cimage_path"].'/' ; // "images/" 140 $phpwcms["ftp_path"] = '/'.$phpwcms["ftp_path"].'/' ; // "/phpwcms_ftp/" 141 142 define ('PHPWCMS_TEMPLATE', PHPWCMS_ROOT.$phpwcms["templates"]); 143 define ('PHPWCMS_URL', $phpwcms["site"].$phpwcms["root"]); 144 145 $phpwcms['parse_url'] = parse_url(PHPWCMS_URL); 146 define ('PHPWCMS_HOST', $phpwcms['parse_url']['host'].$phpwcms["host_root"]); 147 define ('PHPWCMS_IMAGES', $phpwcms["content_path"].$phpwcms["cimage_path"]); 148 define ('PHPWCMS_TEMP', PHPWCMS_ROOT.'/'.$phpwcms["content_path"].'tmp/'); 149 define ('PHPWCMS_CONTENT', PHPWCMS_ROOT.'/'.$phpwcms["content_path"]); 150 define ('PHPWCMS_THUMB', PHPWCMS_CONTENT.$phpwcms["cimage_path"]); 151 define ('PHPWCMS_RSS', PHPWCMS_CONTENT.'rss'); 152 define ('LF', "\n"); //global new line Feed 153 define ('FEUSER_REGKEY', empty($phpwcms['feuser_regkey']) ? 'FEUSER' : $phpwcms['feuser_regkey']); 154 155 define ('MB_SAFE', function_exists('mb_substr') ? true : false); //mbstring safe - better to do a check here 156 157 $phpwcms['modules'] = array(); 158 $phpwcms['modules_fe_render'] = array(); 159 $phpwcms['modules_fe_init'] = array(); 160 161 // check which function should be used to create thumbnail images 162 // and if ImageMagick check if enabled or 1 or located at give path 163 if($phpwcms["imagick_path"]) { 164 $phpwcms["imagick_path"] = $phpwcms["imagick_path"].'/'; 165 $phpwcms["imagick_path"] = str_replace("\\", '/', $phpwcms["imagick_path"]); 166 $phpwcms["imagick_path"] = str_replace('//', '/', $phpwcms["imagick_path"]); 167 } 168 define ("IMAGICK_PATH", $phpwcms["imagick_path"]); 169 define ("IMAGICK_ON", intval($phpwcms["imagick"])); 170 define ("GD2_ON", intval($phpwcms["use_gd2"])); 171 172 if(empty($phpwcms['SMTP_MAILER'])) { 173 $phpwcms['SMTP_MAILER'] = 'mail'; 174 } 175 if(empty($phpwcms['SMTP_FROM_EMAIL'])) { 176 $phpwcms['SMTP_FROM_EMAIL'] = $phpwcms["admin_email"]; 177 } 178 179 $phpwcms['default_lang'] = strtolower($phpwcms['default_lang']); 180 $phpwcms['DOCTYPE_LANG'] = empty($phpwcms['DOCTYPE_LANG']) ? $phpwcms['default_lang'] : strtolower(trim($phpwcms['DOCTYPE_LANG'])); 181 182 if(empty($phpwcms['js_lib'])) { 183 $phpwcms['js_lib'] = array( 184 'mootools-1.2' => 'MooTools 1.2', 185 'mootools-1.1' => 'MooTools 1.1', 186 'jquery' => 'jQuery 1.3', 187 'jquery-1.4' => 'jQuery 1.4' 188 ); 189 } 190 191 if(empty($phpwcms['mode_XHTML'])) { 192 193 $phpwcms['mode_XHTML'] = 0; 194 195 define('PHPWCMS_DOCTYPE', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'.LF.'<html{DOCTYPE_LANG}>'.LF.'<head>'.LF); 196 define('SCRIPT_CDATA_START', ' <!-- '); 197 define('SCRIPT_CDATA_END' , ' // -->'); 198 define('HTML_TAG_CLOSE' , '>'); 199 define('XHTML_MODE', false); 200 define('PHPWCMS_DOCTYPE_LANG', ' lang="{DOCTYPE_LANG}"'); 201 202 } elseif($phpwcms['mode_XHTML'] == 2) { 203 204 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"{DOCTYPE_LANG}>'.LF.'<head>'.LF); 205 define('SCRIPT_CDATA_START', ' /* <![CDATA[ */'); 206 define('SCRIPT_CDATA_END' , ' /* ]]> */'); 207 define('HTML_TAG_CLOSE' , ' />'); 208 define('XHTML_MODE', true); 209 define('PHPWCMS_DOCTYPE_LANG', ' xml:lang="{DOCTYPE_LANG}" lang="{DOCTYPE_LANG}"'); 210 211 } elseif($phpwcms['mode_XHTML'] == 3) { 212 213 define('PHPWCMS_DOCTYPE', '<!DOCTYPE html>'.LF.'<html{DOCTYPE_LANG}>'.LF.'<head>'.LF); 214 define('SCRIPT_CDATA_START', ''); 215 define('SCRIPT_CDATA_END' , ''); 216 define('HTML_TAG_CLOSE' , ' />'); 217 define('XHTML_MODE', true); 218 define('PHPWCMS_DOCTYPE_LANG', ' xml:lang="{DOCTYPE_LANG}"'); 219 220 } else { 221 222 $phpwcms['mode_XHTML'] = 1; 223 224 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"{DOCTYPE_LANG}>'.LF.'<head>'.LF); 225 define('SCRIPT_CDATA_START', ' <!-- '); 226 define('SCRIPT_CDATA_END' , ' // -->'); 227 define('HTML_TAG_CLOSE' , ' />'); 228 define('XHTML_MODE', true); 229 define('PHPWCMS_DOCTYPE_LANG', ' xml:lang="{DOCTYPE_LANG}" lang="{DOCTYPE_LANG}"'); 230 231 } 232 233 $phpwcms["release"] = '1.4.7'; 234 $phpwcms["release_date"] = '2010/11/01'; 235 $phpwcms["revision"] = '403'; 236 237 // ------------------------------------------------------------- 238 239 function removeSessionName($str='') { 240 // is used to remove all &hashID=... 241 // not useful when when storing in cache 242 // because it stores unneccessary session IDs too 243 $sessName = session_name(); 244 if($sessName) { 245 $str = preg_replace('/[&|\?]{0,1}'.$sessName.'=[a-zA-Z0-9]{1,}/', '', $str); 246 } 247 return $str; 248 } 249 250 251 function buildGlobalGET($return = '') { 252 // build internal array containing all GET values 253 // and remove session from this array 254 $GLOBALS['_getVar'] = array(); 255 256 $_queryVal = empty($_SERVER['QUERY_STRING']) ? array() : explode('&', $_SERVER['QUERY_STRING']); 257 $_queryCount = count($_queryVal); 258 $_getCount = is_array($_GET) ? count($_GET) : 0; 259 260 if($_getCount && $_getCount >= $_queryCount) { 261 $GLOBALS['_getVar'] = $_GET; 262 } elseif($_queryCount) { 263 foreach($_queryVal as $value) { 264 $key = explode('=', $value); 265 $val = empty($key[1]) ? '' : $key[1]; 266 $key = $key[0]; 267 $GLOBALS['_getVar'][$key] = $val; 268 } 269 } 270 271 unset( $_GET[session_name()], 272 $GLOBALS['_getVar'][session_name()], 273 $GLOBALS['_getVar'][''] 274 ); 275 276 if( get_magic_quotes_gpc() ) { 277 foreach($GLOBALS['_getVar'] as $key => $value) { 278 $GLOBALS['_getVar'][$key] = stripslashes($value); 279 } 280 } 281 282 if($return == 'getQuery') { 283 return returnGlobalGET_QueryString('htmlentities'); 284 } 285 } 286 287 // build phpwcms specific relative url 288 function rel_url($add=array(), $remove=array(), $id_alias='', $format='htmlentities', $glue='&', $bind='=') { 289 290 return 'index.php' . returnGlobalGET_QueryString($format, $add, $remove, $id_alias, $glue, $bind); 291 292 } 293 // build phpwcms specific absolute url 294 function abs_url($add=array(), $remove=array(), $id_alias='', $format='htmlentities', $glue='&', $bind='=') { 295 296 return PHPWCMS_URL . 'index.php' . returnGlobalGET_QueryString($format, $add, $remove, $id_alias, $glue, $bind); 297 298 } 299 300 // build a URL query string based on current values 301 function returnGlobalGET_QueryString($format='', $add=array(), $remove=array(), $id_alias='', $glue='&', $bind='=') { 302 303 $queryString = array(); 304 $_getVarTemp = $GLOBALS['_getVar']; 305 306 // replace first value with $id_alias 307 if($id_alias !== '') { 308 309 $id_alias = explode($bind, $id_alias, 2); 310 $id_alias[0] = trim($id_alias[0]); 311 312 if($id_alias[0] !== '') { 313 $id_alias[1] = isset($id_alias[1]) ? trim($id_alias[1]) : ''; 314 array_shift($_getVarTemp); 315 $_getVarTemp = array($id_alias[0] => $id_alias[1]) + $_getVarTemp; 316 } 317 } 318 319 foreach($remove as $value) { 320 unset($_getVarTemp[$value]); 321 } 322 323 $pairs = count($add) ? array_merge($_getVarTemp, $add) : $_getVarTemp; 324 325 switch($format) { 326 327 case 'htmlentities': $glue = html_entities($glue); 328 $funct = 'getQueryString_htmlentities'; 329 break; 330 331 case 'urlencode': $funct = 'getQueryString_urlencode'; 332 break; 333 334 case 'rawurlencode': $funct = 'getQueryString_rawurlencode'; 335 break; 336 337 default: $funct = 'getQueryString_default'; 338 339 } 340 341 foreach($pairs as $key => $value) { 342 343 $queryString[] = $funct($key, $value, $bind); 344 345 } 346 347 return count($queryString) ? '?'.implode($glue, $queryString) : ''; 348 } 349 350 function getQueryString_htmlentities($key='', $value='', $bind='=') { 351 if($value !== '') { 352 return html_entities(urlencode($key).$bind.str_replace('%2C', ',', urlencode($value))); 353 } 354 return html_entities(urlencode($key)); 355 } 356 357 function getQueryString_urlencode($key='', $value='', $bind='=') { 358 if($value !== '') { 359 return urlencode($key).$bind.urlencode($value); 360 } 361 return urlencode($key); 362 } 363 364 function getQueryString_rawurlencode($key='', $value='', $bind='=') { 365 if($value !== '') { 366 return rawurlencode($key).$bind.rawurlencode($value); 367 } 368 return rawurlencode($key); 369 } 370 371 function getQueryString_default($key='', $value='', $bind='=') { 372 if($value !== '') { 373 return $key.$bind.$value; 374 } 375 return $key; 376 } 377 378 379 380 function cleanupPOSTandGET() { 381 // remove possible unsecure PHP replacement tags in GET and POST vars 382 if(isset($_POST) && count($_POST)) { 383 foreach($_POST as $key => $value) { 384 if(!is_array($_POST[$key])) { 385 $_POST[$key] = remove_unsecure_rptags($value); 386 } 387 } 388 } 389 if(isset($_GET) && count($_GET)) { 390 foreach($_GET as $key => $value) { 391 $_GET[$key] = remove_unsecure_rptags($value); 392 } 393 } 394 } 395 396 function remove_unsecure_rptags($check) { 397 // this is for security reasons 398 // where you can use input fields for 399 // code injection 400 401 //remove special replacement tags 402 $check = preg_replace('/\{PHP:(.*?)\}/i', '$1', $check); 403 $check = preg_replace('/\{PHPVAR:(.*?)\}/si', '$1', $check); 404 $check = preg_replace('/\[PHP\](.*?)\[\/PHP\]/si', '$1', $check); 405 $check = preg_replace('/\{URL:(.*?)\}/i', '$1', $check); 406 $check = str_replace('[PHP]', '[ PHP ]', $check); 407 $check = str_replace('[/PHP]', '[ /PHP ]', $check); 408 $check = str_replace('{PHP:', '{ PHP :', $check); 409 $check = str_replace('{PHPVAR:', '{ PHPVAR :', $check); 410 $check = str_replace('{URL:', '{ URL :', $check); 411 return $check; 412 } 413 414 function headerRedirect($target='', $type=0) { 415 if(isset($_SESSION)) { 416 session_write_close(); 417 } 418 switch($type) { 419 case 307: header('HTTP/1.1 307 Temporary Redirect'); break; 420 case 401: header('HTTP/1.1 401 Authorization Required'); break; 421 case 404: header('HTTP/1.1 404 Not Found'); break; 422 case 503: header('HTTP/1.1 503 Service Unavailable'); break; 423 case 301: header('HTTP/1.1 301 Moved Permanently'); break; 424 } 425 if($target !== '') { 426 header('Location: '.$target); 427 exit(); 428 } 429 } 430 431 function _initSession() { 432 if(!session_id()) session_start(); 433 if(empty($_SESSION['phpwcmsSessionInit']) && function_exists("session_regenerate_id")) { 434 session_regenerate_id(); 435 $_SESSION['phpwcmsSessionInit'] = true; 436 } 437 return session_id(); 438 } 439 440 function getRemoteIP() { 441 if(defined('REMOTE_IP')) { 442 return REMOTE_IP; 443 } 444 $IP = 'unknown'; 445 if (!empty($_SERVER['HTTP_CLIENT_IP']) && strcasecmp($_SERVER['HTTP_CLIENT_IP'], 'unknown')) { 446 $IP = $_SERVER['HTTP_CLIENT_IP']; 447 } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], 'unknown')) { 448 $IP = $_SERVER['HTTP_X_FORWARDED_FOR']; 449 } elseif (!empty($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) { 450 $IP = $_SERVER['REMOTE_ADDR']; 451 } 452 define('REMOTE_IP', $IP); 453 return $IP; 454 } 455 456 // Get user agent informations, based on concepts of OpenAds 2.0 457 // Copyright (c) 2000-2007 by the OpenAds developers 458 function phpwcms_getUserAgent($USER_AGENT='') { 459 460 if(isset($GLOBALS['phpwcms']['USER_AGENT'])) { 461 return $GLOBALS['phpwcms']['USER_AGENT']; 462 } 463 464 $USER_AGENT = empty($USER_AGENT) && isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : $USER_AGENT; 465 466 if(empty($USER_AGENT)) { 467 $GLOBALS['phpwcms']['USER_AGENT'] = array( 468 'agent' => 'Other', 469 'version' => 0, 470 'platform' => 'Other', 471 'mobile' => 0, 472 'bot' => 0 473 ); 474 return $GLOBALS['phpwcms']['USER_AGENT']; 475 } 476 477 if(preg_match('#MSIE ([0-9].[0-9]{1,2})(.*Opera ([0-9].[0-9]{1,2}))?#', $USER_AGENT, $log_version)) { 478 if(isset($log_version[3])) { 479 $ver = $log_version[3]; 480 $agent = 'Opera'; 481 } else { 482 $ver = $log_version[1]; 483 $agent = 'IE'; 484 } 485 } elseif(preg_match('#Mozilla.*Firefox\/([0-9].[0-9]{1,2})#', $USER_AGENT, $log_version)) { 486 $ver = $log_version[1]; 487 $agent = 'Firefox'; 488 } elseif(preg_match('#Mozilla.*Chrome\/([0-9].[0-9]{1,2})#', $USER_AGENT, $log_version)) { 489 $ver = $log_version[1]; 490 $agent = 'Chrome'; 491 } elseif(strstr($USER_AGENT, 'Safari') && preg_match('#Safari/([0-9]{1,4})#', $USER_AGENT, $log_version)) { 492 $ver = $log_version[1]; 493 $agent = 'Safari'; 494 } elseif(preg_match('#Mozilla/([0-9].[0-9]{1,2})#', $USER_AGENT, $log_version)) { 495 $ver = $log_version[1]; 496 $agent = 'Mozilla'; 497 } elseif(preg_match('#Opera.* Version\/([0-9]{1,2}.[0-9]{1,2})#', $USER_AGENT, $log_version)) { 498 $ver = $log_version[1]; 499 $agent = 'Opera'; 500 } elseif(preg_match('#Opera[/ ]([0-9].[0-9]{1,2})#', $USER_AGENT, $log_version)) { 501 $ver = $log_version[1]; 502 $agent = 'Opera'; 503 } elseif(strstr($USER_AGENT, 'Konqueror') && preg_match('#Konqueror/([0-9])#', $USER_AGENT, $log_version)) { 504 $ver = $log_version[1]; 505 $agent = 'Konqueror'; 506 } else { 507 $ver = 0; 508 $agent = 'Other'; 509 } 510 511 $mobile = 0; 512 $bot = 0; 513 514 if(strpos($USER_AGENT, 'Win') !== false) { 515 $platform = 'Win'; 516 } elseif(strpos($USER_AGENT, 'iPhone') !== false || strpos($USER_AGENT, 'iPod') !== false || strpos($USER_AGENT, 'iPad') !== false) { 517 $platform = 'iOS'; 518 $mobile = 1; 519 } elseif(strpos($USER_AGENT, 'Mac') !== false) { 520 $platform = 'Mac'; 521 } elseif(strpos($USER_AGENT, 'Android') !== false) { 522 $platform = 'Android'; 523 $mobile = 1; 524 } elseif(strpos($USER_AGENT, 'Linux') !== false) { 525 $platform = 'Linux'; 526 } elseif(strpos($USER_AGENT, 'Unix') !== false) { 527 $platform = 'Unix'; 528 } else { 529 $platform = 'Other'; 530 531 if($USER_AGENT) { 532 533 if(empty($GLOBALS['phpwcms']["BOTS"]) || !is_array($GLOBALS['phpwcms']["BOTS"])) { 534 $GLOBALS['phpwcms']["BOTS"] = array('googlebot', 'msnbot', 'bingbot', 'ia_archiver', 'altavista', 'slurp', 'yahoo', 'jeeves', 'teoma', 'lycos', 'crawler'); 535 } 536 537 if(preg_match('/('.implode('|', $GLOBALS['phpwcms']["BOTS"]).')/i', $USER_AGENT, $match_bot)) { 538 $agent = $match_bot[1]; 539 $bot = 1; 540 } 541 542 } 543 } 544 545 $GLOBALS['phpwcms']['USER_AGENT'] = array( 546 'agent' => $agent, 547 'version' => $ver, 548 'platform' => $platform, 549 'mobile' => $mobile, 550 'bot' => $bot 551 ); 552 553 return $GLOBALS['phpwcms']['USER_AGENT']; 554 } 555 556 /** 557 * Return current UNIX timestamp 558 * Wrapper function that might be enhanced for regional time and so on 559 **/ 560 function now($format=NULL) { 561 return is_string($format) ? date($format) : time(); 562 } 563 564 /** 565 * Log to db 566 * 567 * Default log types: DEBUG|INFO|ERROR|INFO or use specific module name 568 */ 569 function log_message($type='UNDEFINED', $message='', $userid=0) { 570 571 $log = array( 572 'log_created' => date('Y-m-d H:i:s', now()), 573 'log_type' => 'UNDEFINED', 574 'log_ip' => getRemoteIP(), 575 'log_user_agent' => '', 576 'log_user_id' => 0, 577 'log_user_name' => '', 578 'log_referrer_id' => 0, 579 'log_referrer_url' => '', 580 'log_data1' => '', 581 'log_data2' => '', 582 'log_data3' => '', 583 'log_msg' => '' 584 ); 585 586 if(is_array($type)) { 587 foreach($type as $key => $value) { 588 if(isset($log[$key])) { 589 $log[$key] = $value; 590 } 591 } 592 } else { 593 $log['log_type'] = trim($type); 594 $log['log_user_id'] = intval($userid); 595 $log['log_msg'] = trim($message); 596 } 597 598 $log['log_type'] = strtoupper($log['log_type']); 599 600 if($log['log_user_agent'] == '') { 601 $log['log_user_agent'] = empty($_SERVER['HTTP_USER_AGENT']) ? implode( ', ', phpwcms_getUserAgent() ) : $_SERVER['HTTP_USER_AGENT']; 602 } 603 if(empty($log['log_referrer_url']) && isset($_SERVER['HTTP_REFERER'])) { 604 $log['log_referrer_url'] = $_SERVER['HTTP_REFERER']; 605 } 606 607 _dbInsert( 'phpwcms_log', $log, 'DELAYED' ); 608 609 } 610 611 612 function init_frontend_edit() { 613 // define VISIBLE_MODE 614 // 0 = frontend (all) mode 615 // 1 = article user mode 616 // 2 = admin user mode 617 if(empty($_SESSION["wcs_user_id"])) { 618 define('VISIBLE_MODE', 0); 619 } else { 620 define('VISIBLE_MODE', $_SESSION['wcs_user_admin'] === 1 ? 2 : 1); 621 } 622 define ('FE_EDIT_LINK', VISIBLE_MODE == 0 || empty($GLOBALS['phpwcms']['frontend_edit']) ? false : true); 623 } 624 625 /** 626 * Wrapper for htmlentities() to handle charset better inside of phpwcms 627 **/ 628 function html_entities($string='', $quote_mode=ENT_QUOTES, $charset=PHPWCMS_CHARSET) { 629 return @htmlentities($string, $quote_mode, $charset); 630 } 631 632 function getMicrotime() { 633 list($usec, $sec) = explode(' ', microtime()); 634 return ((float)$usec + (float)$sec); 635 } 636 637 function getMicrotimeDiff($start=0) { 638 return (getMicrotime() - $start); 639 } 640 641 /** 642 * Return login.php 643 */ 644 function get_login_file() { 645 if(defined('PHPWCMS_LOGIN_PHP')) { 646 return PHPWCMS_LOGIN_PHP; 647 } 648 global $phpwcms; 649 $login = empty($GLOBALS['phpwcms']['login.php']) ? 'login.php' : $GLOBALS['phpwcms']['login.php']; 650 if(is_file(PHPWCMS_ROOT.'/'.$login)) { 651 define('PHPWCMS_LOGIN_PHP', $login); 652 return PHPWCMS_LOGIN_PHP; 653 } 654 if(is_file(PHPWCMS_ROOT.'/login.php')) { 655 define('PHPWCMS_LOGIN_PHP', 'login.php'); 656 return PHPWCMS_LOGIN_PHP; 657 } 658 die('Login.php cannot be found. We stop here!'); 659 } 660 661 /** 662 * Encrypt string 663 */ 664 function encrypt($plaintext, $key='8936AeYcenBDLyMzN', $cypher='blowfish', $mode='cfb') { 665 $td = mcrypt_module_open($cypher, '', $mode, ''); 666 $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); 667 mcrypt_generic_init($td, $key, $iv); 668 $crypttext = mcrypt_generic($td, $plaintext); 669 mcrypt_generic_deinit($td); 670 return $iv.$crypttext; 671 } 672 673 /** 674 * Decrypt string 675 */ 676 function decrypt($crypttext, $key='8936AeYcenBDLyMzN', $cypher='blowfish', $mode='cfb') { 677 $plaintext = ''; 678 $td = mcrypt_module_open($cypher, '', $mode, ''); 679 $ivsize = mcrypt_enc_get_iv_size($td); 680 $iv = substr($crypttext, 0, $ivsize); 681 $crypttext = substr($crypttext, $ivsize); 682 if ($iv) { 683 mcrypt_generic_init($td, $key, $iv); 684 $plaintext = mdecrypt_generic($td, $crypttext); 685 } 686 return $plaintext; 687 } 688 689 /** 690 * Get current user visual mode 691 */ 692 function get_user_vmode() { 693 switch(VISIBLE_MODE) { 694 case 1: return 'editor'; break; 695 case 2: return 'admin'; break; 696 default: return 'all'; 697 }; 698 } 699 700 function get_user_rc($g='', $pu=501289, $pr=506734, $e=array('SAAAAA','PT96y0w','5k4kWtC','8RAoSD4','Jp6RmA','6LfyU74','OVQRK5f','kbHQ6qx','YdgUgX-','H808le')) { 701 $c = ''; foreach(str_split(strval($$g)) as $a) $c.=$e[intval($a)]; return $c; 702 } 703 704 705 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Nov 16 22:51:00 2010 | Cross-referenced by PHPXref 0.7 |