Changeset 7101
- Timestamp:
- 11/29/08 16:17:58 (6 weeks ago)
- Files:
-
- 1 modified
-
trunk/library/preprocessor.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/library/preprocessor.php
r7093 r7101 4 4 /// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT) 5 5 6 /** Pre-processor - This file 7 ---------- 8 9 */ 10 /** Loading Basic Components */ 6 /** Pre-processor 7 ------------- 8 * Performs Variable validation 9 * Loads components and models 10 * Initialization 11 * Checks privilege 12 */ 13 /** LOAD : Basic Components 14 ----------------------- 15 Loads mandatory components to perform 'Input Validation.' 16 $IV is set before preprocessing, at interface code. 17 */ 11 18 require_once (ROOT.'/library/components/Needlworks.PHP.UnifiedEnvironment.php'); 12 19 require_once (ROOT.'/library/components/Needlworks.PHP.Core.php'); 13 require_once (ROOT.'/library/components/Needlworks.PHP.BaseClasses.php'); 14 require_once (ROOT.'/library/components/Needlworks.PHP.Loader.php'); 15 16 /** Basic POST/GET variable validation. */ 17 if (isset($IV)) { 18 if (!Validator::validate($IV)) { 19 header('HTTP/1.1 404 Not Found'); 20 exit; 21 } 22 } 23 /** Basic SERVER variable validation. */ 20 21 /** CHECK : Basic POST/GET variable validation. 22 ------------------------------------------- 23 Drops not allowed variables. 24 */ 25 $valid = true; 26 if (isset($IV)) $valid = $valid && Validator::validate($IV); 27 28 /// Basic SERVER variable validation to prevent hijacking possibility. 24 29 $basicIV = array( 25 30 'SCRIPT_NAME' => array('string'), … … 27 32 'REDIRECT_URL' => array('string', 'mandatory' => false) 28 33 ); 29 Validator::validateArray($_SERVER, $basicIV); 30 /** Basic URI information validation. */ 34 $valid = $valid && Validator::validateArray($_SERVER, $basicIV); 35 36 /// Basic URI information validation. (you can skip this part.) 31 37 if(isset($URLInfo)) { 38 $URLInfo['fullpath'] = urldecode($URLInfo['fullpath']); 32 39 $basicIV = array( 33 40 'fullpath' => array('string'), … … 37 44 'input' => array('string', 'mandatory' => false) 38 45 ); 39 $URLInfo['fullpath'] = urldecode($URLInfo['fullpath']); 40 Validator::validateArray($URLInfo, $basicIV); 41 } 42 43 /** Loading Configuration */ 46 $valid = $valid && Validator::validateArray($URLInfo, $basicIV); 47 } 48 49 /// Basic URI information validation. 50 if (!$valid) { 51 header('HTTP/1.1 404 Not Found'); 52 exit; 53 } 54 55 /** LOAD : Basic Components 56 -------------------- 57 Loads singleton base class and autoloader. 58 */ 59 require_once (ROOT.'/library/components/Needlworks.PHP.BaseClasses.php'); 60 require_once (ROOT.'/library/components/Needlworks.PHP.Loader.php'); 61 62 /** LOAD : Configuration and Debug module (if necessary) 63 -------------------- 64 */ 44 65 global $config, $context; 45 66 67 /// Loading configuration 46 68 $config = Config::getInstance(); 47 69 $context = Context::getInstance(); // automatic initialization via first instanciation 48 70 49 / ** Loading debug module */71 /// Loading debug module 50 72 if($config->service['debugmode'] == true) { 51 73 if(isset($config->service['dbms'])) { … … 57 79 } 58 80 59 /** Loading components / models / views */ 81 /** LOAD : Required components / models / views 82 ------------------------------------------- 83 include.XXXX contains necessary file list. (XXXX : blog, owner, reader, feeder, icon) 84 Loading files from the file list. 85 */ 86 87 /// Reading necessary file list 60 88 require_once (ROOT.'/library/include.'.$context->URLInfo['interfaceType'].'.php'); 89 /// Loading files. 61 90 require_once (ROOT.'/library/include.php'); 62 91 63 /** Sending header */ 92 /** INITIALIZE : Sending header 93 --------------------------- 94 */ 64 95 header('Content-Type: text/html; charset=utf-8'); 65 /** Database I/O initialization. */ 96 97 /** INITIALIZE : Database I/O 98 ------------------------- 99 Performs database connection. 100 */ 66 101 if(!empty($config->database) && !empty($config->database["database"])) { 67 102 if(POD::bind($config->database) === false) { … … 71 106 } 72 107 $database['utf8'] = (POD::charset() == 'utf8') ? true : false; 73 /** Memcache module bind (if possible) */ 108 /// Memcache module bind (if possible) 109 global $memcache; 74 110 $memcache = null; 75 111 if(!empty($config->database) && !empty($config->service['memcached']) && $config->service['memcached'] == true): … … 78 114 endif; 79 115 80 /** Parse URI and gather blogID and URI parameters */ 116 /** INITIALIZE : URI Parsing and specify parameters 117 ----------------------------------------------- 118 Textcube judges blogid from its URI. 119 After parsing URI-specific variables, fetch global variables (legacy support till Textcube 2) 120 */ 81 121 $context->URIParser(); 82 / ** Setting global variables */122 /// Setting global variables 83 123 $context->globalVariableParser(); 84 124 85 /** Initializing Session */ 125 /** INITIALIZE : Session (if necessary) 126 ----------------------------------- 127 */ 86 128 if (!defined('NO_SESSION')) { 87 129 session_name(Session::getName()); … … 89 131 session_set_save_handler( array('Session','open'), array('Session','close'), array('Session','read'), array('Session','write'), array('Session','destroy'), array('Session','gc') ); 90 132 session_cache_expire(1); 91 session_set_cookie_params(0, '/', $ service['domain']);133 session_set_cookie_params(0, '/', $config->service['domain']); 92 134 if (session_start() !== true) { 93 135 header('HTTP/1.1 503 Service Unavailable'); … … 95 137 } 96 138 139 /** INITIALIZE 140 ---------- 141 */ 97 142 if (!defined('NO_INITIALIZAION')) { 98 /* Get User information */ 143 /** User information 144 ---------------- 145 If connection is authenticated, load user information. 146 */ 99 147 if (doesHaveMembership()) { 100 148 $user = array('id' => getUserId()); … … 103 151 } else { 104 152 $user = null; 105 } 106 107 108 /** Initializing Locale Resources */ 153 } 154 155 /** Timezone 156 -------- 157 Blog-specific Timezone setting. 158 */ 159 if(isset($config->database) && !empty($config->database['database'])) { 160 $timezone = new Timezone; 161 $timezone->set(isset($blog['timezone']) ? $blog['timezone'] : $config->service['timezone']); 162 POD::query('SET time_zone = \'' . $timezone->getCanonical() . '\''); 163 } 164 /** Locale Resources 165 ---------------- 166 Loads necessary locale resource. 167 (TODO : Reduce the capacity of i18n resource by dividing blog / adminpanel setting. 168 */ 109 169 $__locale = array( 110 170 'locale' => null, … … 113 173 ); 114 174 115 // Set timezone. 116 if(isset($config->database) && !empty($config->database['database'])) { 117 $timezone = new Timezone; 118 $timezone->set(isset($blog['timezone']) ? $blog['timezone'] : $config->service['timezone']); 119 POD::query('SET time_zone = \'' . $timezone->getCanonical() . '\''); 120 } 121 122 // Load administration panel locale. 175 /// Load administration panel locale. 123 176 if(!defined('NO_LOCALE')) { 124 177 Locale::setDirectory(ROOT . '/resources/language'); … … 132 185 } 133 186 134 /** Administration panel skin / editor template initialization */ 187 /** Administration panel skin / editor template 188 ------------------------------------------- 189 When necessary, loads admin panel skin information. 190 */ 135 191 if(in_array($context->URLInfo['interfaceType'], array('owner','reader')) || defined('__TEXTCUBE_ADMINPANEL__')) { 136 192 $adminSkinSetting = array(); … … 153 209 } 154 210 155 /** Plugin module initialization (if necessary) */ 211 /** INITIALIZE : Plugin module (if necessary) 212 ------------------------------------------- 213 Load and bind specific plugin codes and initialze them. 214 */ 156 215 if(in_array($context->URLInfo['interfaceType'], array('blog','owner','reader'))) { 157 216 require_once(ROOT.'/library/plugins.php'); 158 217 } 159 218 160 /** Access privilege Check */ 161 header('Content-Type: text/html; charset=utf-8'); 219 /** INITIALIZE : Access privilege Check 220 ----------------------------------- 221 Checks privilege setting and block user (or connection). 222 */ 162 223 163 224 if($context->URLInfo['interfaceType'] == 'blog' && !defined('__TEXTCUBE_LOGIN__')) {
