[ Index ] |
|
Code source de XOOPS 2.0.17.1 |
1 <?php 2 // $Id: common.php 1023 2007-09-08 02:55:26Z phppp $ 3 // ------------------------------------------------------------------------ // 4 // XOOPS - PHP Content Management System // 5 // Copyright (c) 2000 XOOPS.org // 6 // <http://www.xoops.org/> // 7 // ------------------------------------------------------------------------ // 8 // This program is free software; you can redistribute it and/or modify // 9 // it under the terms of the GNU General Public License as published by // 10 // the Free Software Foundation; either version 2 of the License, or // 11 // (at your option) any later version. // 12 // // 13 // You may not change or alter any portion of this comment or credits // 14 // of supporting developers from this source code or any supporting // 15 // source code which is considered copyrighted (c) material of the // 16 // original comment or credit authors. // 17 // // 18 // This program is distributed in the hope that it will be useful, // 19 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 21 // GNU General Public License for more details. // 22 // // 23 // You should have received a copy of the GNU General Public License // 24 // along with this program; if not, write to the Free Software // 25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // 26 // ------------------------------------------------------------------------ // 27 28 defined("XOOPS_MAINFILE_INCLUDED") or die(); 29 30 set_magic_quotes_runtime(0); 31 32 /** 33 * Extremely reduced kernel class 34 * This class should not really be defined in this file, but it wasn't worth including an entire 35 * file for those two functions. 36 * Few notes: 37 * - modules should use this class methods to generate physical paths/URIs (the ones which do not conform 38 * will perform badly when true URL rewriting is implemented) 39 */ 40 class xos_kernel_Xoops2 { 41 var $paths = array( 42 'www' => array(), 'modules' => array(), 'themes' => array(), 43 ); 44 function xos_kernel_Xoops2() { 45 $this->paths['www'] = array( XOOPS_ROOT_PATH, XOOPS_URL ); 46 $this->paths['modules'] = array( XOOPS_ROOT_PATH . '/modules', XOOPS_URL . '/modules' ); 47 $this->paths['themes'] = array( XOOPS_ROOT_PATH . '/themes', XOOPS_URL . '/themes' ); 48 } 49 /** 50 * Convert a XOOPS path to a physical one 51 */ 52 function path( $url, $virtual = false ) { 53 $path = ''; 54 @list( $root, $path ) = explode( '/', $url, 2 ); 55 if ( !isset( $this->paths[$root] ) ) { 56 list( $root, $path ) = array( 'www', $url ); 57 } 58 if ( !$virtual ) { // Returns a physical path 59 return $this->paths[$root][0] . '/' . $path; 60 } 61 return !isset( $this->paths[$root][1] ) ? '' : ( $this->paths[$root][1] . '/' . $path ); 62 } 63 /** 64 * Convert a XOOPS path to an URL 65 */ 66 function url( $url ) { 67 return ( false !== strpos( $url, '://' ) ? $url : $this->path( $url, true ) ); 68 } 69 /** 70 * Build an URL with the specified request params 71 */ 72 function buildUrl( $url, $params = array() ) { 73 if ( $url == '.' ) { 74 $url = $_SERVER['REQUEST_URI']; 75 } 76 $split = explode( '?', $url ); 77 if ( count($split) > 1 ) { 78 list( $url, $query ) = $split; 79 parse_str( $query, $query ); 80 $params = array_merge( $query, $params ); 81 } 82 if ( !empty( $params ) ) { 83 foreach ( $params as $k => $v ) { 84 $params[$k] = $k . '=' . rawurlencode($v); 85 } 86 $url .= '?' . implode( '&', $params ); 87 } 88 return $url; 89 } 90 91 92 93 94 } 95 global $xoops; 96 $xoops =& new xos_kernel_Xoops2(); 97 98 // Instantiate security object 99 require_once XOOPS_ROOT_PATH."/class/xoopssecurity.php"; 100 global $xoopsSecurity; 101 $xoopsSecurity = new XoopsSecurity(); 102 //Check super globals 103 $xoopsSecurity->checkSuperglobals(); 104 105 // ############## Activate error handler / logger class ############## 106 global $xoopsLogger, $xoopsErrorHandler; 107 108 include_once XOOPS_ROOT_PATH . '/class/logger.php'; 109 $xoopsLogger =& XoopsLogger::instance(); 110 $xoopsErrorHandler =& $xoopsLogger; 111 $xoopsLogger->startTime(); 112 $xoopsLogger->startTime( 'XOOPS Boot' ); 113 114 115 define("XOOPS_SIDEBLOCK_LEFT",0); 116 define("XOOPS_SIDEBLOCK_RIGHT",1); 117 define("XOOPS_SIDEBLOCK_BOTH",2); 118 define("XOOPS_CENTERBLOCK_LEFT",3); 119 define("XOOPS_CENTERBLOCK_RIGHT",4); 120 define("XOOPS_CENTERBLOCK_CENTER",5); 121 define("XOOPS_CENTERBLOCK_ALL",6); 122 define("XOOPS_CENTERBLOCK_BOTTOMLEFT",7); 123 define("XOOPS_CENTERBLOCK_BOTTOMRIGHT",8); 124 define("XOOPS_CENTERBLOCK_BOTTOM",9); 125 define("XOOPS_BLOCK_INVISIBLE",0); 126 define("XOOPS_BLOCK_VISIBLE",1); 127 define("XOOPS_MATCH_START",0); 128 define("XOOPS_MATCH_END",1); 129 define("XOOPS_MATCH_EQUAL",2); 130 define("XOOPS_MATCH_CONTAIN",3); 131 define("SMARTY_DIR", XOOPS_ROOT_PATH."/class/smarty/"); 132 define("XOOPS_CACHE_PATH", XOOPS_ROOT_PATH."/cache"); 133 define("XOOPS_UPLOAD_PATH", XOOPS_ROOT_PATH."/uploads"); 134 define("XOOPS_THEME_PATH", XOOPS_ROOT_PATH."/themes"); 135 define("XOOPS_COMPILE_PATH", XOOPS_ROOT_PATH."/templates_c"); 136 define("XOOPS_THEME_URL", XOOPS_URL."/themes"); 137 define("XOOPS_UPLOAD_URL", XOOPS_URL."/uploads"); 138 139 if (!defined('XOOPS_XMLRPC')) { 140 define('XOOPS_DB_CHKREF', 1); 141 } else { 142 define('XOOPS_DB_CHKREF', 0); 143 } 144 145 // ############## Include common functions file ############## 146 include_once XOOPS_ROOT_PATH.'/include/functions.php'; 147 148 // #################### Connect to DB ################## 149 require_once XOOPS_ROOT_PATH.'/class/database/databasefactory.php'; 150 if ($_SERVER['REQUEST_METHOD'] != 'POST' || !$xoopsSecurity->checkReferer(XOOPS_DB_CHKREF)) { 151 define('XOOPS_DB_PROXY', 1); 152 } 153 $xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection(); 154 155 // ################# Include required files ############## 156 require_once XOOPS_ROOT_PATH.'/kernel/object.php'; 157 require_once XOOPS_ROOT_PATH.'/class/criteria.php'; 158 159 // #################### Include text sanitizer ################## 160 include_once XOOPS_ROOT_PATH."/class/module.textsanitizer.php"; 161 162 // ################# Load Config Settings ############## 163 $config_handler =& xoops_gethandler('config'); 164 $xoopsConfig =& $config_handler->getConfigsByCat(XOOPS_CONF); 165 166 // Disable gzip compression if PHP is run under CLI mode 167 // To be refactored 168 if (empty($_SERVER['SERVER_NAME']) || substr(PHP_SAPI, 0, 3) == 'cli') { 169 $xoopsConfig['gzip_compression'] = 0; 170 } 171 if ( $xoopsConfig['gzip_compression'] == 1 && extension_loaded( 'zlib' ) && !ini_get( 'zlib.output_compression' ) ) { 172 if ( @ini_get( 'zlib.output_compression_level' ) < 0 ) { 173 ini_set( 'zlib.output_compression_level', 6 ); 174 } 175 ob_start( 'ob_gzhandler' ); 176 } 177 178 // #################### Error reporting settings ################## 179 if ( $xoopsConfig['debug_mode'] == 1 || $xoopsConfig['debug_mode'] == 2 ) { 180 error_reporting(E_ALL); 181 $xoopsLogger->enableRendering(); 182 $xoopsLogger->usePopup = ( $xoopsConfig['debug_mode'] == 2 ); 183 } else { 184 error_reporting(0); 185 $xoopsLogger->activated = false; 186 } 187 $xoopsSecurity->checkBadips(); 188 189 // ################# Include version info file ############## 190 include_once XOOPS_ROOT_PATH."/include/version.php"; 191 192 // for older versions...will be DEPRECATED! 193 $xoopsConfig['xoops_url'] = XOOPS_URL; 194 $xoopsConfig['root_path'] = XOOPS_ROOT_PATH."/"; 195 196 197 // #################### Include site-wide lang file ################## 198 if ( file_exists(XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/global.php") ) { 199 include_once XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/global.php"; 200 } else { 201 include_once XOOPS_ROOT_PATH."/language/english/global.php"; 202 } 203 204 // ################ Include page-specific lang file ################ 205 if (isset($xoopsOption['pagetype']) && false === strpos($xoopsOption['pagetype'], '.')) { 206 if ( file_exists(XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/".$xoopsOption['pagetype'].".php") ) { 207 include_once XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/".$xoopsOption['pagetype'].".php"; 208 } else { 209 include_once XOOPS_ROOT_PATH."/language/english/".$xoopsOption['pagetype'].".php"; 210 } 211 } 212 $xoopsOption = array(); 213 214 if ( !defined("XOOPS_USE_MULTIBYTES") ) { 215 define("XOOPS_USE_MULTIBYTES",0); 216 } 217 218 /**#@+ 219 * Host abstraction layer 220 */ 221 if ( !isset($_SERVER['PATH_TRANSLATED']) && isset($_SERVER['SCRIPT_FILENAME']) ) { 222 $_SERVER['PATH_TRANSLATED'] =& $_SERVER['SCRIPT_FILENAME']; // For Apache CGI 223 } elseif ( isset($_SERVER['PATH_TRANSLATED']) && !isset($_SERVER['SCRIPT_FILENAME']) ) { 224 $_SERVER['SCRIPT_FILENAME'] =& $_SERVER['PATH_TRANSLATED']; // For IIS/2K now I think :-( 225 } 226 227 if ( empty( $_SERVER[ 'REQUEST_URI' ] ) ) { // Not defined by IIS 228 // Under some configs, IIS makes SCRIPT_NAME point to php.exe :-( 229 if ( !( $_SERVER[ 'REQUEST_URI' ] = @$_SERVER['PHP_SELF'] ) ) { 230 $_SERVER[ 'REQUEST_URI' ] = $_SERVER['SCRIPT_NAME']; 231 } 232 if ( isset( $_SERVER[ 'QUERY_STRING' ] ) ) { 233 $_SERVER[ 'REQUEST_URI' ] .= '?' . $_SERVER[ 'QUERY_STRING' ]; 234 } 235 } 236 $xoopsRequestUri = $_SERVER[ 'REQUEST_URI' ]; // Deprecated (use the corrected $_SERVER variable now) 237 /**#@-*/ 238 239 // ############## Login a user with a valid session ############## 240 $xoopsUser = ''; 241 $xoopsUserIsAdmin = false; 242 $member_handler =& xoops_gethandler('member'); 243 global $sess_handler; 244 $sess_handler =& xoops_gethandler('session'); 245 if ($xoopsConfig['use_ssl'] && isset($_POST[$xoopsConfig['sslpost_name']]) && $_POST[$xoopsConfig['sslpost_name']] != '') { 246 session_id($_POST[$xoopsConfig['sslpost_name']]); 247 } elseif ($xoopsConfig['use_mysession'] && $xoopsConfig['session_name'] != '') { 248 if (isset($_COOKIE[$xoopsConfig['session_name']])) { 249 session_id($_COOKIE[$xoopsConfig['session_name']]); 250 } 251 if (function_exists('session_cache_expire')) { 252 session_cache_expire($xoopsConfig['session_expire']); 253 } 254 @ini_set('session.gc_maxlifetime', $xoopsConfig['session_expire'] * 60); 255 } 256 session_set_save_handler(array(&$sess_handler, 'open'), array(&$sess_handler, 'close'), array(&$sess_handler, 'read'), array(&$sess_handler, 'write'), array(&$sess_handler, 'destroy'), array(&$sess_handler, 'gc')); 257 session_start(); 258 259 // Remove expired session for xoopsUserId 260 if ( $xoopsConfig['use_mysession'] && $xoopsConfig['session_name'] != '' && !isset($_COOKIE[$xoopsConfig['session_name']]) && !empty($_SESSION['xoopsUserId']) ) { 261 unset( $_SESSION['xoopsUserId'] ); 262 } 263 264 if (!empty($_SESSION['xoopsUserId'])) { 265 $xoopsUser =& $member_handler->getUser($_SESSION['xoopsUserId']); 266 if (!is_object($xoopsUser)) { 267 $xoopsUser = ''; 268 $_SESSION = array(); 269 session_destroy(); 270 } else { 271 $GLOBALS["sess_handler"]->update_cookie(); 272 $xoopsUser->setGroups($_SESSION['xoopsUserGroups']); 273 $xoopsUserIsAdmin = $xoopsUser->isAdmin(); 274 } 275 } 276 if (!empty($_POST['xoops_theme_select']) && in_array($_POST['xoops_theme_select'], $xoopsConfig['theme_set_allowed'])) { 277 $xoopsConfig['theme_set'] = $_POST['xoops_theme_select']; 278 $_SESSION['xoopsUserTheme'] = $_POST['xoops_theme_select']; 279 } elseif (!empty($_SESSION['xoopsUserTheme']) && in_array($_SESSION['xoopsUserTheme'], $xoopsConfig['theme_set_allowed'])) { 280 $xoopsConfig['theme_set'] = $_SESSION['xoopsUserTheme']; 281 } 282 283 if ($xoopsConfig['closesite'] == 1) { 284 include XOOPS_ROOT_PATH . "/include/site-closed.php"; 285 } 286 287 if (file_exists('./xoops_version.php')) { 288 $url_arr = explode( '/', strstr( $_SERVER['PHP_SELF'],'/modules/') ); 289 $module_handler =& xoops_gethandler('module'); 290 $xoopsModule =& $module_handler->getByDirname($url_arr[2]); 291 unset($url_arr); 292 if (!$xoopsModule || !$xoopsModule->getVar('isactive')) { 293 include_once XOOPS_ROOT_PATH."/header.php"; 294 echo "<h4>"._MODULENOEXIST."</h4>"; 295 include_once XOOPS_ROOT_PATH."/footer.php"; 296 exit(); 297 } 298 $moduleperm_handler =& xoops_gethandler('groupperm'); 299 if ($xoopsUser) { 300 if (!$moduleperm_handler->checkRight('module_read', $xoopsModule->getVar('mid'), $xoopsUser->getGroups())) { 301 redirect_header(XOOPS_URL."/user.php",1,_NOPERM, false); 302 exit(); 303 } 304 $xoopsUserIsAdmin = $xoopsUser->isAdmin($xoopsModule->getVar('mid')); 305 } else { 306 if (!$moduleperm_handler->checkRight('module_read', $xoopsModule->getVar('mid'), XOOPS_GROUP_ANONYMOUS)) { 307 redirect_header(XOOPS_URL."/user.php",1,_NOPERM); 308 exit(); 309 } 310 } 311 if ( file_exists(XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar('dirname')."/language/".$xoopsConfig['language']."/main.php") ) { 312 include_once XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar('dirname')."/language/".$xoopsConfig['language']."/main.php"; 313 } else { 314 if ( file_exists(XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar('dirname')."/language/english/main.php") ) { 315 include_once XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar('dirname')."/language/english/main.php"; 316 } 317 } 318 if ($xoopsModule->getVar('hasconfig') == 1 || $xoopsModule->getVar('hascomments') == 1 || $xoopsModule->getVar( 'hasnotification' ) == 1) { 319 $xoopsModuleConfig =& $config_handler->getConfigsByCat(0, $xoopsModule->getVar('mid')); 320 } 321 } elseif($xoopsUser) { 322 $xoopsUserIsAdmin = $xoopsUser->isAdmin(1); 323 } 324 $xoopsLogger->stopTime( 'XOOPS Boot' ); 325 $xoopsLogger->startTime( 'Module init' ); 326 327 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Nov 25 11:44:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |