'.LF.''.LF.''.LF); define('SCRIPT_CDATA_START', ' '); define('HTML_TAG_CLOSE' , '>'); define('XHTML_MODE', false); define('PHPWCMS_DOCTYPE_LANG', ' lang="{DOCTYPE_LANG}"'); } elseif($phpwcms['mode_XHTML'] == 2) { define('PHPWCMS_DOCTYPE', ''.LF.''.LF.''.LF); define('SCRIPT_CDATA_START', ' /* */'); define('HTML_TAG_CLOSE' , ' />'); define('XHTML_MODE', true); define('PHPWCMS_DOCTYPE_LANG', ' xml:lang="{DOCTYPE_LANG}" lang="{DOCTYPE_LANG}"'); } else { $phpwcms['mode_XHTML'] = 1; define('PHPWCMS_DOCTYPE', ''.LF.''.LF.''.LF); define('SCRIPT_CDATA_START', ' '); define('HTML_TAG_CLOSE' , ' />'); define('XHTML_MODE', true); define('PHPWCMS_DOCTYPE_LANG', ' xml:lang="{DOCTYPE_LANG}" lang="{DOCTYPE_LANG}"'); } $phpwcms["release"] = '1.4.3'; $phpwcms["release_date"] = '2009/11/23'; $phpwcms["revision"] = '380'; // load permissions class require(PHPWCMS_ROOT.'/include/inc_lib/permissions.class.php'); // init permissions $_PERMIT = new Permissions(); // ------------------------------------------------------------- function removeSessionName($str='') { // is used to remove all &hashID=... // not useful when when storing in cache // because it stores unneccessary session IDs too $sessName = session_name(); if($sessName) { $str = preg_replace('/[&|\?]{0,1}'.$sessName.'=[a-zA-Z0-9]{1,}/', '', $str); } return $str; } function buildGlobalGET($return = '') { // build internal array containing all GET values // and remove session from this array $GLOBALS['_getVar'] = array(); $_queryVal = empty($_SERVER['QUERY_STRING']) ? array() : explode('&', $_SERVER['QUERY_STRING']); $_queryCount = count($_queryVal); $_getCount = is_array($_GET) ? count($_GET) : 0; if($_getCount && $_getCount >= $_queryCount) { $GLOBALS['_getVar'] = $_GET; } elseif($_queryCount) { foreach($_queryVal as $value) { $key = explode('=', $value); $val = empty($key[1]) ? '' : $key[1]; $key = $key[0]; $GLOBALS['_getVar'][$key] = $val; } } unset( $_GET[session_name()], $GLOBALS['_getVar'][session_name()], $GLOBALS['_getVar'][''] ); if( get_magic_quotes_gpc() ) { foreach($GLOBALS['_getVar'] as $key => $value) { $GLOBALS['_getVar'][$key] = stripslashes($value); } } if($return == 'getQuery') { return returnGlobalGET_QueryString('htmlentities'); } } // build phpwcms specific relative url function rel_url($add=array(), $remove=array(), $id_alias='', $format='htmlentities', $glue='&', $bind='=') { return 'index.php' . returnGlobalGET_QueryString($format, $add, $remove, $id_alias, $glue, $bind); } // build phpwcms specific absolute url function abs_url($add=array(), $remove=array(), $id_alias='', $format='htmlentities', $glue='&', $bind='=') { return PHPWCMS_URL . 'index.php' . returnGlobalGET_QueryString($format, $add, $remove, $id_alias, $glue, $bind); } // build a URL query string based on current values function returnGlobalGET_QueryString($format='', $add=array(), $remove=array(), $id_alias='', $glue='&', $bind='=') { $queryString = array(); $_getVarTemp = $GLOBALS['_getVar']; // replace first value with $id_alias if($id_alias !== '') { $id_alias = explode($bind, $id_alias, 2); $id_alias[0] = trim($id_alias[0]); if($id_alias[0] !== '') { $id_alias[1] = isset($id_alias[1]) ? trim($id_alias[1]) : ''; array_shift($_getVarTemp); $_getVarTemp = array($id_alias[0] => $id_alias[1]) + $_getVarTemp; } } foreach($remove as $value) { unset($_getVarTemp[$value]); } $pairs = count($add) ? array_merge($_getVarTemp, $add) : $_getVarTemp; switch($format) { case 'htmlentities': $glue = html_entities($glue); $funct = 'getQueryString_htmlentities'; break; case 'urlencode': $funct = 'getQueryString_urlencode'; break; case 'rawurlencode': $funct = 'getQueryString_rawurlencode'; break; default: $funct = 'getQueryString_default'; } foreach($pairs as $key => $value) { $queryString[] = $funct($key, $value, $bind); } return count($queryString) ? '?'.implode($glue, $queryString) : ''; } function getQueryString_htmlentities($key='', $value='', $bind='=') { if($value !== '') { return html_entities(urlencode($key).$bind.str_replace('%2C', ',', urlencode($value))); } return html_entities(urlencode($key)); } function getQueryString_urlencode($key='', $value='', $bind='=') { if($value !== '') { return urlencode($key).$bind.urlencode($value); } return urlencode($key); } function getQueryString_rawurlencode($key='', $value='', $bind='=') { if($value !== '') { return rawurlencode($key).$bind.rawurlencode($value); } return rawurlencode($key); } function getQueryString_default($key='', $value='', $bind='=') { if($value !== '') { return $key.$bind.$value; } return $key; } function cleanupPOSTandGET() { // remove possible unsecure PHP replacement tags in GET and POST vars if(isset($_POST) && count($_POST)) { foreach($_POST as $key => $value) { if(!is_array($_POST[$key])) { $_POST[$key] = remove_unsecure_rptags($value); } } } if(isset($_GET) && count($_GET)) { foreach($_GET as $key => $value) { $_GET[$key] = remove_unsecure_rptags($value); } } } function remove_unsecure_rptags($check) { // this is for security reasons // where you can use input fields for // code injection //remove special replacement tags $check = preg_replace('/\{PHP:(.*?)\}/i', '$1', $check); $check = preg_replace('/\{PHPVAR:(.*?)\}/si', '$1', $check); $check = preg_replace('/\[PHP\](.*?)\[\/PHP\]/si', '$1', $check); $check = preg_replace('/\{URL:(.*?)\}/i', '$1', $check); $check = str_replace('[PHP]', '[ PHP ]', $check); $check = str_replace('[/PHP]', '[ /PHP ]', $check); $check = str_replace('{PHP:', '{ PHP :', $check); $check = str_replace('{PHPVAR:', '{ PHPVAR :', $check); $check = str_replace('{URL:', '{ URL :', $check); return $check; } function headerRedirect($target='', $type=0) { if(isset($_SESSION)) { session_write_close(); } switch($type) { case 307: header('HTTP/1.1 307 Temporary Redirect'); break; case 401: header('HTTP/1.1 401 Authorization Required'); break; case 404: header('HTTP/1.1 404 Not Found'); break; case 503: header('HTTP/1.1 503 Service Unavailable'); break; case 301: header('HTTP/1.1 301 Moved Permanently'); break; } if($target !== '') { header('Location: '.$target); exit(); } } function _initSession() { if(!session_id()) session_start(); if(empty($_SESSION['phpwcmsSessionInit']) && function_exists("session_regenerate_id")) { session_regenerate_id(); $_SESSION['phpwcmsSessionInit'] = true; } return session_id(); } function getRemoteIP() { if(defined('REMOTE_IP')) { return REMOTE_IP; } $IP = 'unknown'; if (!empty($_SERVER['HTTP_CLIENT_IP']) && strcasecmp($_SERVER['HTTP_CLIENT_IP'], 'unknown')) { $IP = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], 'unknown')) { $IP = $_SERVER['HTTP_X_FORWARDED_FOR']; } elseif (!empty($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) { $IP = $_SERVER['REMOTE_ADDR']; } define('REMOTE_IP', $IP); return $IP; } /************************************************************************/ /* Openads 2.0 */ /* =========== */ /* */ /* Copyright (c) 2000-2007 by the Openads developers */ /* For more information visit: http://www.openads.org */ /* */ /* This program is free software. You can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License. */ /************************************************************************/ function phpwcms_getUserAgent($USER_AGENT='') { if(isset($GLOBALS['phpwcms']['USER_AGENT'])) { return $GLOBALS['phpwcms']['USER_AGENT']; } $USER_AGENT = empty($USER_AGENT) && isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : $USER_AGENT; if(empty($USER_AGENT)) { $GLOBALS['phpwcms']['USER_AGENT'] = array( 'agent' => 'Other', 'version' => 0, 'platform' => 'Other' ); return $GLOBALS['phpwcms']['USER_AGENT']; } if(preg_match('#MSIE ([0-9].[0-9]{1,2})(.*Opera ([0-9].[0-9]{1,2}))?#', $USER_AGENT, $log_version)) { if(isset($log_version[3])) { $ver = $log_version[3]; $agent = 'Opera'; } else { $ver = $log_version[1]; $agent = 'IE'; } } elseif (preg_match('#Opera[/ ]([0-9].[0-9]{1,2})#', $USER_AGENT, $log_version)) { $ver = $log_version[1]; $agent = 'Opera'; } elseif (strstr($USER_AGENT, 'Safari') && preg_match('#Safari/([0-9]{1,3})#', $USER_AGENT, $log_version)) { $ver = $log_version[1]; $agent = 'Safari'; } elseif (strstr($USER_AGENT, 'Konqueror') && preg_match('#Konqueror/([0-9])#', $USER_AGENT, $log_version)) { $ver = $log_version[1]; $agent = 'Konqueror'; } elseif (preg_match('#Mozilla/([0-9].[0-9]{1,2})#', $USER_AGENT, $log_version)) { $ver = $log_version[1]; $agent = 'Mozilla'; } else { $ver = 0; $agent = 'Other'; } if (strstr($USER_AGENT, 'Win')) { $platform = 'Win'; } elseif (strstr($USER_AGENT, 'Mac')) { $platform = 'Mac'; } elseif (strstr($USER_AGENT, 'Linux')) { $platform = 'Linux'; } elseif (strstr($USER_AGENT, 'Unix')) { $platform = 'Unix'; } else { $platform = 'Other'; } $GLOBALS['phpwcms']['USER_AGENT'] = array( 'agent' => $agent, 'version' => $ver, 'platform' => $platform ); return $GLOBALS['phpwcms']['USER_AGENT']; } /** * Return current UNIX timestamp * Wrapper function that might be enhanced for regional time and so on **/ function now($format=NULL) { return is_string($format) ? date($format) : time(); } /** * Log to db * * Default log types: DEBUG|INFO|ERROR|INFO or use specific module name */ function log_message($type='UNDEFINED', $message='', $userid=0) { $log = array( 'log_created' => date('Y-m-d H:i:s', now()), 'log_type' => 'UNDEFINED', 'log_ip' => getRemoteIP(), 'log_user_agent' => '', 'log_user_id' => 0, 'log_user_name' => '', 'log_referrer_id' => 0, 'log_referrer_url' => '', 'log_data1' => '', 'log_data2' => '', 'log_data3' => '', 'log_msg' => '' ); if(is_array($type)) { $user = array_intersect( $log, $type ); } else { $user = array( 'log_type' => trim($type), 'log_user_id' => intval($userid), 'log_msg' => trim($message) ); } $log = array_merge( $log, $user ); $log['log_type'] = strtoupper($log['log_type']); if($log['log_user_agent'] == '') { $log['log_user_agent'] = empty($_SERVER['HTTP_USER_AGENT']) ? implode( ', ', phpwcms_getUserAgent() ) : $_SERVER['HTTP_USER_AGENT']; } if(empty($log['log_referrer_url']) && isset($_SERVER['HTTP_REFERER'])) { $log['log_referrer_url'] = $_SERVER['HTTP_REFERER']; } _dbInsert( 'phpwcms_log', $log, 'DELAYED' ); } function init_frontend_edit() { // define VISIBLE_MODE // 0 = frontend (all) mode // 1 = article user mode // 2 = admin user mode if(empty($_SESSION["wcs_user_id"])) { define('VISIBLE_MODE', 0); } else { define('VISIBLE_MODE', $_SESSION['wcs_user_admin'] === 1 ? 2 : 1); } define ('FE_EDIT_LINK', VISIBLE_MODE == 0 || empty($GLOBALS['phpwcms']['frontend_edit']) ? false : true); } /** * Wrapper for htmlentities() to handle charset better inside of phpwcms **/ function html_entities($string='', $quote_mode=ENT_QUOTES, $charset=PHPWCMS_CHARSET) { return @htmlentities($string, $quote_mode, $charset); } function getMicrotime() { list($usec, $sec) = explode(' ', microtime()); return ((float)$usec + (float)$sec); } function getMicrotimeDiff($start=0) { return (getMicrotime() - $start); } /** * Return login.php */ function get_login_file() { if(defined('PHPWCMS_LOGIN_PHP')) { return PHPWCMS_LOGIN_PHP; } global $phpwcms; $login = empty($GLOBALS['phpwcms']['login.php']) ? 'login.php' : $GLOBALS['phpwcms']['login.php']; if(is_file(PHPWCMS_ROOT.'/'.$login)) { define('PHPWCMS_LOGIN_PHP', $login); return PHPWCMS_LOGIN_PHP; } if(is_file(PHPWCMS_ROOT.'/login.php')) { define('PHPWCMS_LOGIN_PHP', 'login.php'); return PHPWCMS_LOGIN_PHP; } die('Login.php cannot be found. We stop here!'); } ?>