Changeset 2257

Show
Ignore:
Timestamp:
11/26/10 15:59:51 (18 months ago)
Author:
petsagouris
Message:

[Branch 1.5] Improved the class structure. (way of work)
Made methods private.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/1.5/libs/Initialize.php

    r2239 r2257  
    2424 * @link      http://www.hotarucms.org/ 
    2525 */ 
    26 class Initialize { 
     26class Initialize 
     27{ 
    2728 
    2829        public $db;  // database object 
    2930        public $cage;   // Inspekt object 
    30         public $isDebug = false; // show db queries and page loading time 
     31        public $isDebug = FALSE; // show db queries and page loading time 
    3132 
    3233        /** 
    3334         * Initialize Hotaru with the essentials 
     35         *  
     36         * @return Initialize 
    3437         */ 
    3538        public function __construct(Hotaru $h) 
    3639        { 
    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. 
    3971                if (!isset($_SESSION['HotaruCMS'])) { 
    4072                        session_start(); 
    4173                        $_SESSION['HotaruCMS'] = time(); 
    4274                } 
    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; 
    6275        } 
    6376 
    6477        /** 
    6578         * Error reporting 
    66          */ 
    67         public function errorReporting() 
     79         * 
     80         * @return null 
     81         */ 
     82        private function errorReporting() 
    6883        { 
    6984                // display errors 
     
    90105        /** 
    91106         * Table Constants 
    92          */ 
    93         public function setTableConstants() 
     107         * 
     108         * @return null 
     109         */ 
     110        private function setTableConstants() 
    94111        { 
    95112                // define database tables 
     
    124141        } 
    125142 
    126  
    127143        /** 
    128144         * Set the timezone 
    129          */ 
    130         public function setDefaultTimezone() 
     145         * 
     146         * @return null 
     147         */ 
     148        private function setDefaultTimezone() 
    131149        { 
    132150                // set timezone 
     
    138156        /** 
    139157         * Include necessary files 
    140          */ 
    141         public function getFiles() 
     158         * 
     159         * @return null 
     160         */ 
     161        private function getFiles() 
    142162        { 
    143163                require_once(FUNCTIONS.'funcs.strings.php'); 
     
    151171         * Initialize Database 
    152172         * 
    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'"); 
    161179        } 
    162180 
     
    164182         * Initialize Inspekt 
    165183         * 
    166          * @return object 
    167          */ 
    168         public function initInspektCage() 
    169         { 
    170                 $cage = Inspekt::makeSuperCage(); 
     184         * @return null 
     185         */ 
     186        private function initInspektCage() 
     187        { 
     188                $this->cage = Inspekt::makeSuperCage(); 
    171189 
    172190                // 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'); 
    184200        } 
    185201 
    186202        /** 
    187203         * 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() 
    193208        { 
    194209                $sql = "SELECT settings_name, settings_value FROM ".TABLE_SETTINGS; 
     
    196211 
    197212                if (!$settings) { 
    198                         return FALSE; 
     213                        return NULL; 
    199214                } 
    200215 
     
    207222 
    208223                if (!defined('THEME_URL')) { 
    209                         define('THEME_URL', SITEURL.'content/themes/'.THEME); 
     224                        define('THEME_URL', BASEURL.'content/themes/'.THEME); 
    210225                } 
    211226 
    212227                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        } 
    219231 
    220232        /** 
    221233         * 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        } 
    244247 
    245248        /** 
     
    247250         * 
    248251         * 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() 
    251256        { 
    252257                // Setup database cache 
    253258                $this->db->cache_timeout = DB_CACHE_DURATION; // Note: this is hours 
    254259                $this->db->cache_dir = CACHE.'db_cache'; 
    255                 return $this->db->use_disk_cache = (bool) (DB_CACHE == "true"); 
    256         } 
    257  
    258         /** 
    259          * Debug timer 
    260          * 
    261          * @ return bool 
    262          */ 
    263         public function checkDebug() 
    264         { 
    265                 // Start timer if debugging 
     260                $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 
    266271                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 
    271277                timer_start(); 
    272278                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() 
    283288        { 
    284289                $file = CACHE.'css_js_cache/JavascriptConstants.js'; 
    285290                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; 
    287293                } 
    288294                return FALSE;