From 4c677c92e46c69dcf419d9be6416b865c6c905cf Mon Sep 17 00:00:00 2001 From: Toni Haryanto Date: Tue, 30 Dec 2014 04:58:57 +0700 Subject: [PATCH 1/2] create SITE_FOLDER const --- index.php | 1 + system/application/config/pusaka.php | 25 ++++++++++++++++++- system/application/config/template.php | 2 +- system/application/core/Admin_Controller.php | 8 +++--- system/application/core/MY_Controller.php | 24 ++++++++++-------- .../application/helpers/template_helper.php | 4 +-- system/application/hooks/MyHookClass.php | 6 ++--- system/application/libraries/Template.php | 2 +- system/modules/cms/controllers/cms.php | 8 +++--- system/modules/panel/controllers/auth.php | 2 +- system/modules/panel/controllers/export.php | 8 +++--- system/modules/panel/controllers/media.php | 2 +- system/modules/panel/controllers/settings.php | 2 +- system/modules/panel/controllers/users.php | 2 +- 14 files changed, 61 insertions(+), 35 deletions(-) diff --git a/index.php b/index.php index 510c591..53163c6 100644 --- a/index.php +++ b/index.php @@ -243,6 +243,7 @@ define('VIEWPATH', $view_folder); + define('SITE_FOLDER', 'sites/'); // load Composer libraries include_once './system/vendor/autoload.php'; diff --git a/system/application/config/pusaka.php b/system/application/config/pusaka.php index 2b2c825..b9c75b8 100644 --- a/system/application/config/pusaka.php +++ b/system/application/config/pusaka.php @@ -22,4 +22,27 @@ | Default to false. | */ -$config['subsite_domain'] = false; \ No newline at end of file +$config['subsite_domain'] = false; + +/* +|-------------------------------------------------------------------------- +| post term +|-------------------------------------------------------------------------- +| +| what term you want to use to represent post slug +| +*/ +$config['post_term'] = 'blog'; + +/* +|-------------------------------------------------------------------------- +| content folders +|-------------------------------------------------------------------------- +| +| content folders path relatives to each site folder +| +*/ +$config['page_folder'] = 'content/pages/'; +$config['post_folder'] = 'content/posts/'; +$config['label_folder'] = 'content/labels/'; +$config['nav_folder'] = 'content/navs/'; diff --git a/system/application/config/template.php b/system/application/config/template.php index ac9c340..97f88a5 100644 --- a/system/application/config/template.php +++ b/system/application/config/template.php @@ -86,7 +86,7 @@ $config['theme_locations'] = array( 'system/themes/', - 'sites/'.SITE_SLUG.'/themes/' + SITE_FOLDER.SITE_SLUG.'/themes/' ); /* diff --git a/system/application/core/Admin_Controller.php b/system/application/core/Admin_Controller.php index 0c5f0ce..6126241 100644 --- a/system/application/core/Admin_Controller.php +++ b/system/application/core/Admin_Controller.php @@ -9,8 +9,8 @@ public function __construct() // set theme $this->template->set_theme($this->config->item('admin_theme')); - if(file_exists('sites/'.SITE_SLUG.'/users/admin.json')){ - $admin = json_decode(file_get_contents('sites/'.SITE_SLUG.'/users/admin.json'), true); + if(file_exists(SITE_FOLDER.SITE_SLUG.'/users/admin.json')){ + $admin = json_decode(file_get_contents(SITE_FOLDER.SITE_SLUG.'/users/admin.json'), true); if(isset($admin['password']) && $admin['password'] == 'password') $this->template->set('warning', 'Change your default admin password to secure one in Users settings page first.'); } @@ -25,8 +25,8 @@ function logged_in(){ } protected function _force_login($username){ - if(file_exists('sites/'.SITE_SLUG.'/users/'.$username.'.json')){ - $data = json_decode(file_get_contents('sites/'.SITE_SLUG.'/users/'.$username.'.json'), true); + if(file_exists(SITE_FOLDER.SITE_SLUG.'/users/'.$username.'.json')){ + $data = json_decode(file_get_contents(SITE_FOLDER.SITE_SLUG.'/users/'.$username.'.json'), true); $this->session->set_userdata(SITE_SLUG.'_username', $data['username']); $this->session->set_userdata(SITE_SLUG.'_role', $data['role']); diff --git a/system/application/core/MY_Controller.php b/system/application/core/MY_Controller.php index 6fe0225..9dad134 100644 --- a/system/application/core/MY_Controller.php +++ b/system/application/core/MY_Controller.php @@ -15,26 +15,27 @@ public function __construct() parent::__construct(); $this->output->enable_profiler(false); + // Set timezone date_default_timezone_set('Asia/Jakarta'); - $sitepath = 'sites/'.SITE_SLUG.'/'; + define('SITE_PATH', SITE_FOLDER.SITE_SLUG.'/'); // check if main config file exist - if(!file_exists(($sitepath.'config/site.json'))){ + if(!file_exists((SITE_PATH.'config/site.json'))){ show_error('site.json config file for your site is not found. Please create it first.'); } - if(!file_exists(($sitepath.'config/system.json'))){ + if(!file_exists((SITE_PATH.'config/system.json'))){ show_error('system.json config file for your site is not found. Please create it first.'); } // get all config file - $config_file = array_filter(scandir($sitepath.'config'), function($user){ + $config_file = array_filter(scandir(SITE_PATH.'config'), function($user){ return (strpos($user, '.json')); }); foreach ($config_file as $confile) { - $config = json_decode(file_get_contents($sitepath.'config/'.$confile), true); + $config = json_decode(file_get_contents(SITE_PATH.'config/'.$confile), true); foreach ($config as $key => $value) { $this->config->set_item($key, $value); $this->data[$key] = $value; @@ -47,15 +48,16 @@ public function __construct() $this->config->set_item('page_title', $this->config->item('site_name')); - if(! defined('PAGE_FOLDER')) define('PAGE_FOLDER', $sitepath.'content/pages/'); - if(! defined('POST_FOLDER')) define('POST_FOLDER', $sitepath.'content/posts/'); - if(! defined('LABEL_FOLDER')) define('LABEL_FOLDER', $sitepath.'content/labels/'); - if(! defined('NAV_FOLDER')) define('NAV_FOLDER', $sitepath.'content/navs/'); - if(! defined('SITE_PATH')) define('SITE_PATH', $sitepath); - if(! defined('POST_TERM')) define('POST_TERM', $this->config->item('post_term')?$this->config->item('post_term'):'blog'); + if(! defined('PAGE_FOLDER')) define('PAGE_FOLDER', SITE_PATH.$this->config->item('page_folder')); + if(! defined('POST_FOLDER')) define('POST_FOLDER', SITE_PATH.$this->config->item('post_folder')); + if(! defined('LABEL_FOLDER')) define('LABEL_FOLDER', SITE_PATH.$this->config->item('label_folder')); + if(! defined('NAV_FOLDER')) define('NAV_FOLDER', SITE_PATH.$this->config->item('nav_folder')); + + if(! defined('POST_TERM')) define('POST_TERM', $this->config->item('post_term')); if(! defined('PLUGIN_FOLDER')) define('PLUGIN_FOLDER', 'system/plugins/'); + // support compatibility with php < 5.3 if(! defined('JSON_PRETTY_PRINT')) define('JSON_PRETTY_PRINT', 128); } diff --git a/system/application/helpers/template_helper.php b/system/application/helpers/template_helper.php index 87b3623..00b3f9f 100644 --- a/system/application/helpers/template_helper.php +++ b/system/application/helpers/template_helper.php @@ -95,7 +95,7 @@ function get_theme_url($url = '') { if ( ! function_exists('get_content_image')) { function get_image_content($file = false, $attr = '') { - $url = base_url().'sites/'.SITE_SLUG.'/content/files/'.$file; + $url = base_url().SITE_FOLDER.SITE_SLUG.'/content/files/'.$file; return ''; } @@ -104,7 +104,7 @@ function get_image_content($file = false, $attr = '') { if ( ! function_exists('get_content_file')) { function get_content_file($file = false) { - $url = base_url().'sites/'.SITE_SLUG.'/content/files/'.$file; + $url = base_url().SITE_FOLDER.SITE_SLUG.'/content/files/'.$file; return $url; } diff --git a/system/application/hooks/MyHookClass.php b/system/application/hooks/MyHookClass.php index 28fcc45..d684040 100644 --- a/system/application/hooks/MyHookClass.php +++ b/system/application/hooks/MyHookClass.php @@ -14,7 +14,7 @@ function multisite() $segments = explode('/', $uri); if(isset($segments[1]) && !empty($segments[1])) { - if(is_dir('sites/'.$segments[1])) + if(is_dir(SITE_FOLDER.$segments[1])) define('SITE_SLUG', $segments[1]); else show_error('Site not found'); @@ -25,8 +25,8 @@ function multisite() // then it is a online server with real domain else { - if(file_exists('sites/_domain/'.$domain.'.conf')) - define('SITE_SLUG', trim(@file_get_contents('sites/_domain/'.$domain.'.conf'))); + if(file_exists(SITE_FOLDER.'_domain/'.$domain.'.conf')) + define('SITE_SLUG', trim(@file_get_contents(SITE_FOLDER.'_domain/'.$domain.'.conf'))); else show_error('Site not configured yet'); } diff --git a/system/application/libraries/Template.php b/system/application/libraries/Template.php index fb46757..13705db 100755 --- a/system/application/libraries/Template.php +++ b/system/application/libraries/Template.php @@ -106,7 +106,7 @@ function initialize($config = array()) if ($this->_theme_locations === array()) { // Let's use this obvious default - $this->_theme_locations = array('sites/themes/'); + $this->_theme_locations = array(SITE_FOLDER.'themes/'); } // No asset locations set in config? diff --git a/system/modules/cms/controllers/cms.php b/system/modules/cms/controllers/cms.php index 8ba01dd..fe3be3b 100755 --- a/system/modules/cms/controllers/cms.php +++ b/system/modules/cms/controllers/cms.php @@ -158,14 +158,14 @@ function update_domain($site = null) { if(!$site) show_error('which site domain must be update?'); - if(file_exists('sites/'.$site.'/CNAME')){ - $domain = @file_get_contents('sites/'.$site.'/CNAME'); - if(write_file('sites/_domain/'.$domain.'.conf', $site)){ + if(file_exists(SITE_FOLDER.$site.'/CNAME')){ + $domain = @file_get_contents(SITE_FOLDER.$site.'/CNAME'); + if(write_file(SITE_FOLDER.'_domain/'.$domain.'.conf', $site)){ header("Content-Type:text/plain"); echo "Domain setting for site $site updated."; } else - show_error('Writing domain configuration file failed. /sites/_domain/ folder must be writable.'); + show_error('Writing domain configuration file failed. '.SITE_FOLDER.'_domain/ folder must be writable.'); } else show_error('CNAME file not found'); } diff --git a/system/modules/panel/controllers/auth.php b/system/modules/panel/controllers/auth.php index 1549518..dbd3b5b 100644 --- a/system/modules/panel/controllers/auth.php +++ b/system/modules/panel/controllers/auth.php @@ -19,7 +19,7 @@ class Auth extends Admin_Controller { function __construct(){ parent::__construct(); - $this->users_path = 'sites/'.SITE_SLUG.'/users/'; + $this->users_path = SITE_FOLDER.SITE_SLUG.'/users/'; } function index() diff --git a/system/modules/panel/controllers/export.php b/system/modules/panel/controllers/export.php index 7079031..d3447d8 100644 --- a/system/modules/panel/controllers/export.php +++ b/system/modules/panel/controllers/export.php @@ -9,7 +9,7 @@ function __construct(){ $this->export_location = ($this->config->item('export_location')) ? $this->config->item('export_location') - : 'sites/'.SITE_SLUG.'/html_output'; + : SITE_FOLDER.SITE_SLUG.'/html_output'; } function index() @@ -62,10 +62,10 @@ function copy_files() ? $this->input->post('location') : $this->export_location; - if(!file_exists($this->export_location.'/sites/'.SITE_SLUG.'/content/')) - mkdir($this->export_location.'/sites/'.SITE_SLUG.'/content/', 0777, true); + if(!file_exists($this->export_location.'/'.SITE_FOLDER.SITE_SLUG.'/content/')) + mkdir($this->export_location.'/'.SITE_FOLDER.SITE_SLUG.'/content/', 0777, true); - recurse_copy('sites/'.SITE_SLUG.'/content/files', $this->export_location.'/sites/'.SITE_SLUG.'/content/files'); + recurse_copy(SITE_FOLDER.SITE_SLUG.'/content/files', $this->export_location.'/'.SITE_FOLDER.SITE_SLUG.'/content/files'); echo '{"status":"success", "message":"Files content copied."}'; } diff --git a/system/modules/panel/controllers/media.php b/system/modules/panel/controllers/media.php index 7d0d19e..e5ac7ba 100755 --- a/system/modules/panel/controllers/media.php +++ b/system/modules/panel/controllers/media.php @@ -23,7 +23,7 @@ function __construct(){ if(! $this->logged_in()) redirect('panel/login'); - $this->files_path = 'sites/'. SITE_SLUG .'/content/files'; + $this->files_path = SITE_FOLDER. SITE_SLUG .'/content/files'; if(!is_readable($this->files_path) || !is_writable($this->files_path)) show_error('Set folder '.$this->files_path.' and its contents readable and writable first.'); diff --git a/system/modules/panel/controllers/settings.php b/system/modules/panel/controllers/settings.php index 249366a..c3feef0 100755 --- a/system/modules/panel/controllers/settings.php +++ b/system/modules/panel/controllers/settings.php @@ -23,7 +23,7 @@ function __construct(){ if(! $this->logged_in()) redirect('panel/login'); - $this->config_path = 'sites/'.SITE_SLUG.'/config/'; + $this->config_path = SITE_FOLDER.SITE_SLUG.'/config/'; if(!is_readable($this->config_path) || !is_writable($this->config_path)) show_error('Set folder '.$this->config_path.' and its contents readable and writable first.'); diff --git a/system/modules/panel/controllers/users.php b/system/modules/panel/controllers/users.php index 7bb183f..29f4758 100755 --- a/system/modules/panel/controllers/users.php +++ b/system/modules/panel/controllers/users.php @@ -41,7 +41,7 @@ function __construct(){ if(! $this->logged_in()) redirect('panel/login'); - $this->users_path = 'sites/'. SITE_SLUG .'/users/'; + $this->users_path = SITE_FOLDER. SITE_SLUG .'/users/'; if(!is_readable($this->users_path) || !is_writable($this->users_path)) show_error('Set folder '.$this->users_path.' and its contents readable and writable first.'); From 8889a4e936be236848ed972a086cb1baf0eb9702 Mon Sep 17 00:00:00 2001 From: Toni Haryanto Date: Tue, 30 Dec 2014 04:59:20 +0700 Subject: [PATCH 2/2] init sites module --- system/modules/sites/config/sites.php | 0 system/modules/sites/controllers/sites.php | 0 system/modules/sites/views/index.php | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 system/modules/sites/config/sites.php create mode 100644 system/modules/sites/controllers/sites.php create mode 100644 system/modules/sites/views/index.php diff --git a/system/modules/sites/config/sites.php b/system/modules/sites/config/sites.php new file mode 100644 index 0000000..e69de29 diff --git a/system/modules/sites/controllers/sites.php b/system/modules/sites/controllers/sites.php new file mode 100644 index 0000000..e69de29 diff --git a/system/modules/sites/views/index.php b/system/modules/sites/views/index.php new file mode 100644 index 0000000..e69de29