Changeset 1908


Ignore:
Timestamp:
06/07/10 04:52:20 (3 years ago)
Author:
shibuya246
Message:

[Branch 1.4] multi-site check on initialize. checks siteid=1's settings table for presence of MULTI_SITE constant. If not found do nothing. if false do nothing. If true, check which site to show.

File:
1 edited

Legend:

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

    r1816 r1908  
    5353                $this->getCurrentSiteID(); 
    5454                $this->errorReporting(); 
    55                  
     55 
    5656                $this->readSettings(); 
    5757                $this->setUpDatabaseCache(); 
     
    153153        public function getCurrentSiteID() 
    154154        { 
    155 //              if isActive($result) { 
    156 //                  $url =  $this->cage->server->getRaw('HTTP_HOST');   // wanted to use sanitizeTags 
    157 //                  $sql = "SELECT site_id, site_adminuser_id FROM " . TABLE_SITE . " WHERE site_url = %s"; 
    158 //                  $settings = $this->db->get_row($this->db->prepare($sql, $url)); 
    159 //                  var_dump( $settings); 
    160 // 
    161 //                  if ($settings) { 
    162 //                      $siteid = $settings->site_id; 
    163 //                  } else { 
    164 //                      $siteid = 1; 
    165 //                  } 
    166 //              } else { 
     155                // read settings for default siteid=1 first to check whether MULTISITE is TRUE 
     156                $sql = "SELECT settings_value FROM " . TABLE_SETTINGS . " WHERE settings_name = %s AND settings_siteid = %d"; 
     157                $multi_site = $this->db->get_var($this->db->prepare($sql, 'MULTI_SITE', 1)); 
     158 
     159                if ($multi_site == 'true') {             
     160                    $url =  $this->cage->server->getRaw('HTTP_HOST');   // wanted to use sanitizeTags 
     161                    $sql = "SELECT site_id, site_adminuser_id FROM " . TABLE_SITE . " WHERE site_url = %s"; 
     162                    $settings = $this->db->get_row($this->db->prepare($sql, $url));               
     163 
     164                    if ($settings) { 
     165                        $siteid = $settings->site_id; 
     166                        $siteurl = "http://" . $url; 
     167                    } else { 
     168                        $siteid = 1; 
     169                        $siteurl = BASEURL; 
     170                    } 
     171 
     172                } else { 
    167173                    $siteid = 1; 
    168 //              } 
    169                 if (!defined('SITEID')) { 
    170                     define('SITEID', $siteid); 
    171                     if (!defined('CACHE')) { define("CACHE", BASE . "cache/" . $siteid . "/"); } 
     174                    $siteurl = BASEURL; 
     175                } 
     176 
     177                if (!defined('SITEID')) { define('SITEID', $siteid); } 
     178                if (!defined('SITEURL')) { define("SITEURL", $siteurl . "/"); } 
     179                 
     180                if (!defined('CACHE')) { 
     181 
     182                    define("CACHE", BASE . "cache/" . $siteid . "/"); 
    172183 
    173184                    $dirs = array('', 'debug_logs/' , 'db_cache/', 'css_js_cache/', 'html_cache/', 'rss_cache/', 'lang_cache/');  // first array item is needed to create the SITEID base folder 
     
    178189                        } 
    179190                    } 
     191                     
    180192                } 
    181193 
     
    256268        /** 
    257269         * Returns all site settings 
    258          * @param int $multisite - site id 
    259          * 
    260          * @return bool 
    261          */ 
    262         public function readSettings($multisite = 0) 
    263         {  
    264                 if (!$multisite) {  
    265                         $sql = "SELECT settings_name, settings_value FROM " . TABLE_SETTINGS; 
    266                         $settings = $this->db->get_results($this->db->prepare($sql)); 
    267                 } else { 
    268                         $sql = "SELECT settings_name, settings_value FROM " . TABLE_SETTINGS . " WHERE settings_siteid = %d"; 
    269                         $settings = $this->db->get_results($this->db->prepare($sql, $multisite)); 
    270                 } 
    271                  
    272                 if(!$settings) { return false; } 
    273                  
     270         * @param <int> $siteid 
     271         *  
     272         * @return <bool> 
     273         */ 
     274        public function readSettings() { 
     275            $sql = "SELECT settings_name, settings_value FROM " . TABLE_SETTINGS . " WHERE settings_siteid = %d"; 
     276            $settings = $this->db->get_results($this->db->prepare($sql, SITEID)); 
     277 
     278            if(!$settings) { return false; } 
     279 
    274280                // Make Hotaru settings global constants 
    275281                foreach ($settings as $setting) 
    276282                { 
    277                         if (!defined($setting->settings_name)) {  
     283                        if (!defined($setting->settings_name)) { 
    278284                                define($setting->settings_name, $setting->settings_value); 
    279285                        } 
    280286                } 
    281                                  
     287 
    282288                return true; 
    283289        } 
Note: See TracChangeset for help on using the changeset viewer.