- Timestamp:
- 11/26/10 15:59:51 (18 months ago)
- Files:
-
- 1 modified
-
branches/1.5/libs/Initialize.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.5/libs/Initialize.php
r2239 r2257 24 24 * @link http://www.hotarucms.org/ 25 25 */ 26 class Initialize { 26 class Initialize 27 { 27 28 28 29 public $db; // database object 29 30 public $cage; // Inspekt object 30 public $isDebug = false; // show db queries and page loading time31 public $isDebug = FALSE; // show db queries and page loading time 31 32 32 33 /** 33 34 * Initialize Hotaru with the essentials 35 * 36 * @return Initialize 34 37 */ 35 38 public function __construct(Hotaru $h) 36 39 { 37 38 // session to be used by CSRF, etc. 40 // Start the session 41 $this->initSession(); 42 43 // The order here is important! 44 $this->setDefaultTimezone(); 45 $this->setTableConstants(); 46 47 $this->MakeCacheFolders(); 48 $this->getFiles(); 49 $this->initInspektCage(); 50 $this->initDatabase(); 51 52 $this->errorReporting(); 53 54 $this->readSettings(); 55 $this->setUpDatabaseCache(); 56 $this->checkDebug(); 57 58 $this->setUpJsConstants(); 59 60 return $this; 61 } 62 63 /** 64 * Initialize the current session 65 * 66 * @return null 67 */ 68 private function initSession() 69 { 70 // Session to be used by CSRF, etc. 39 71 if (!isset($_SESSION['HotaruCMS'])) { 40 72 session_start(); 41 73 $_SESSION['HotaruCMS'] = time(); 42 74 } 43 44 // The order here is important!45 $this->setDefaultTimezone();46 $this->setTableConstants();47 48 $this->MakeCacheFolders();49 $this->getFiles();50 $this->cage = $this->initInspektCage();51 $this->db = $this->initDatabase();52 53 $this->errorReporting();54 55 $this->readSettings();56 $this->setUpDatabaseCache();57 $this->isDebug = $this->checkDebug();58 59 $this->setUpJsConstants();60 61 return $this;62 75 } 63 76 64 77 /** 65 78 * Error reporting 66 */ 67 public function errorReporting() 79 * 80 * @return null 81 */ 82 private function errorReporting() 68 83 { 69 84 // display errors … … 90 105 /** 91 106 * Table Constants 92 */ 93 public function setTableConstants() 107 * 108 * @return null 109 */ 110 private function setTableConstants() 94 111 { 95 112 // define database tables … … 124 141 } 125 142 126 127 143 /** 128 144 * Set the timezone 129 */ 130 public function setDefaultTimezone() 145 * 146 * @return null 147 */ 148 private function setDefaultTimezone() 131 149 { 132 150 // set timezone … … 138 156 /** 139 157 * Include necessary files 140 */ 141 public function getFiles() 158 * 159 * @return null 160 */ 161 private function getFiles() 142 162 { 143 163 require_once(FUNCTIONS.'funcs.strings.php'); … … 151 171 * Initialize Database 152 172 * 153 * @return object 154 */ 155 public function initDatabase() 156 { 157 $ezSQL = new Database(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); 158 $ezSQL->query("SET NAMES 'utf8'"); 159 160 return $ezSQL; 173 * @return null 174 */ 175 private function initDatabase() 176 { 177 $this->db = new Database(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); 178 $this->db->query("SET NAMES 'utf8'"); 161 179 } 162 180 … … 164 182 * Initialize Inspekt 165 183 * 166 * @return object167 */ 168 p ublicfunction initInspektCage()169 { 170 $ cage = Inspekt::makeSuperCage();184 * @return null 185 */ 186 private function initInspektCage() 187 { 188 $this->cage = Inspekt::makeSuperCage(); 171 189 172 190 // Add Hotaru custom methods 173 $cage->addAccessor('testAlnumLines'); 174 $cage->addAccessor('testPage'); 175 $cage->addAccessor('testUsername'); 176 $cage->addAccessor('testPassword'); 177 $cage->addAccessor('getFriendlyUrl'); 178 $cage->addAccessor('sanitizeAll'); 179 $cage->addAccessor('sanitizeTags'); 180 $cage->addAccessor('sanitizeEnts'); 181 $cage->addAccessor('getHtmLawed'); 182 183 return $cage; 191 $this->cage->addAccessor('testAlnumLines'); 192 $this->cage->addAccessor('testPage'); 193 $this->cage->addAccessor('testUsername'); 194 $this->cage->addAccessor('testPassword'); 195 $this->cage->addAccessor('getFriendlyUrl'); 196 $this->cage->addAccessor('sanitizeAll'); 197 $this->cage->addAccessor('sanitizeTags'); 198 $this->cage->addAccessor('sanitizeEnts'); 199 $this->cage->addAccessor('getHtmLawed'); 184 200 } 185 201 186 202 /** 187 203 * Returns all site settings 188 * @param <int> $siteid 189 * 190 * @return <bool> 191 */ 192 public function readSettings() 204 * 205 * @return null 206 */ 207 private function readSettings() 193 208 { 194 209 $sql = "SELECT settings_name, settings_value FROM ".TABLE_SETTINGS; … … 196 211 197 212 if (!$settings) { 198 return FALSE;213 return NULL; 199 214 } 200 215 … … 207 222 208 223 if (!defined('THEME_URL')) { 209 define('THEME_URL', SITEURL.'content/themes/'.THEME);224 define('THEME_URL', BASEURL.'content/themes/'.THEME); 210 225 } 211 226 212 227 if (!defined('ADMIN_THEME_URL')) { 213 define('ADMIN_THEME_URL', SITEURL.'content/admin_themes/'.ADMIN_THEME); 214 } 215 216 return TRUE; 217 } 218 228 define('ADMIN_THEME_URL', BASEURL.'content/admin_themes/'.ADMIN_THEME); 229 } 230 } 219 231 220 232 /** 221 233 * Make cache folders if they don't already exist 222 */ 223 public function MakeCacheFolders() 224 { 225 // create a debug_logs folder if one doesn't exist. 226 if (!is_dir(CACHE . 'debug_logs')) { mkdir(CACHE . 'debug_logs'); } 227 228 // create a db_cache folder if one doesn't exist. 229 if (!is_dir(CACHE . 'db_cache')) { mkdir(CACHE . 'db_cache'); } 230 231 // create a css_js_cache folder if one doesn't exist. 232 if (!is_dir(CACHE . 'css_js_cache')) { mkdir(CACHE . 'css_js_cache'); } 233 234 // create a lang_cache folder if one doesn't exist. 235 if (!is_dir(CACHE . 'lang_cache')) { mkdir(CACHE . 'lang_cache'); } 236 237 // create an rss_cache folder if one doesn't exist. 238 if (!is_dir(CACHE . 'rss_cache')) { mkdir(CACHE . 'rss_cache'); } 239 240 // create an html_cache folder if one doesn't exist. 241 if (!is_dir(CACHE . 'html_cache')) { mkdir(CACHE . 'html_cache'); } 242 } 243 234 * 235 * @return null 236 */ 237 private function MakeCacheFolders() 238 { 239 // Create the debug logs and database, css/js, lang, rss, html cache 240 // directories if they dont exist. 241 foreach (array('debug_logs', 'db_cache', 'css_js_cache', 'lang_cache', 'rss_cache', 'html_cache') as $dir) { 242 if (!is_dir(CACHE.$dir)) { 243 mkdir(CACHE.$dir); 244 } 245 } 246 } 244 247 245 248 /** … … 247 250 * 248 251 * Note: Queries are still only cached following $this->db->cache_queries = true; 249 */ 250 public function setUpDatabaseCache() 252 * 253 * @return null 254 */ 255 private function setUpDatabaseCache() 251 256 { 252 257 // Setup database cache 253 258 $this->db->cache_timeout = DB_CACHE_DURATION; // Note: this is hours 254 259 $this->db->cache_dir = CACHE.'db_cache'; 255 return$this->db->use_disk_cache = (bool) (DB_CACHE == "true");256 } 257 258 /** 259 * Debug timer260 * 261 * @ return bool262 */ 263 p ublicfunction checkDebug()264 { 265 // S tart timer ifdebugging260 $this->db->use_disk_cache = (bool) (DB_CACHE == "true"); 261 } 262 263 /** 264 * Debug and timer 265 * 266 * @ return null 267 */ 268 private function checkDebug() 269 { 270 // Show errors if we are debugging 266 271 if (DEBUG == 'false') { 267 ini_set('display_errors', 0); // hide errors 268 return FALSE; 269 } 270 272 ini_set('display_errors', 0); 273 $this->isDebug = FALSE; 274 } 275 276 // Start timer if we are debugging 271 277 timer_start(); 272 278 ini_set('display_errors', 1); // show errors 273 274 return TRUE; 275 } 276 277 /** 278 * Get JQuery Globals 279 * 280 * 281 */ 282 public function setUpJsConstants() 279 $this->isDebug = TRUE; 280 } 281 282 /** 283 * Get JQuery Globals in a file. 284 * 285 * @return null 286 */ 287 private function setUpJsConstants() 283 288 { 284 289 $file = CACHE.'css_js_cache/JavascriptConstants.js'; 285 290 if (!file_exists($file)) { 286 file_put_contents($file, "var BASE='".BASE."', BASEURL='".SITEURL."', SITEURL='".SITEURL."', ADMIN_THEME='".ADMIN_THEME."', THEME='".THEME."', THEME_URL='".THEME_URL."', ADMIN_THEME_URL='".ADMIN_THEME_URL."';"); 291 file_put_contents($file, "var BASE='".BASE."', BASEURL='".BASEURL."', SITEURL='".SITEURL."', ADMIN_THEME='".ADMIN_THEME."', THEME='".THEME."', THEME_URL='".THEME_URL."', ADMIN_THEME_URL='".ADMIN_THEME_URL."';"); 292 return TRUE; 287 293 } 288 294 return FALSE;