public function __construct() { parent::__construct(); // PHP 5.3 ask for timezone, and throw a warning whenever it is not available // so, just give this one :) $timezone = @date_default_timezone_get(); if (!isset($timezone) || $timezone == '') { $timezone = @ini_get('date.timezone'); } if (!isset($timezone) || $timezone == '') { $timezone = 'UTC'; } date_default_timezone_set($timezone); // load helpers and libraries $this->load->helper('url'); $this->load->helper('html'); $this->load->helper('form'); $this->load->helper('string'); $this->load->library('user_agent'); $this->load->driver('session'); $this->load->helper('cms_helper'); $this->load->library('form_validation'); $this->load->database(); // accessing file is faster than accessing database // but I think accessing variable is faster than both of them if (self::$__cms_model_properties == NULL || defined('CMS_OVERRIDDEN_SUBSITE') && !defined('CMS_RESET_OVERRIDDEN_SUBSITE')) { self::$__cms_model_properties = array(); } $default_properties = array('session' => array(), 'language_dictionary' => array(), 'config' => array(), 'module_name' => array(), 'module_path' => array(), 'module_version' => array(), 'navigation' => array(), 'quicklink' => array(), 'widget' => array(), 'super_admin' => NULL, 'properties' => array(), 'is_config_cached' => FALSE, 'is_module_name_cached' => FALSE, 'is_module_path_cached' => FALSE, 'is_module_version_cached' => FALSE, 'is_user_last_active_extended' => FALSE, 'is_navigation_cached' => FALSE, 'is_quicklink_cached' => FALSE, 'is_widget_cached' => FALSE, 'is_language_dictionary_cached' => FALSE); foreach ($default_properties as $key => $val) { if (!array_key_exists($key, self::$__cms_model_properties)) { self::$__cms_model_properties[$key] = $val; } } if (self::$__cms_model_properties['super_admin'] === NULL) { $query = $this->db->select('user_name, real_name')->from(cms_table_name('main_user'))->where('user_id', 1)->get(); $super_admin = $query->row(); self::$__cms_model_properties['super_admin'] = $super_admin; } // kcfinder include APPPATH . 'config/main/cms_config.php'; if (array_key_exists('__cms_chipper', $config)) { $chipper = $config['__cms_chipper']; } else { $chipper = 'Love Song Storm Gravity Tonight End of Sorrow Rosier'; } $default_cookie = array('__cms_base_url' => base_url(), '__cms_subsite' => CMS_SUBSITE, '__cms_user_id' => $this->cms_user_id()); foreach ($default_cookie as $key => $val) { if (!array_key_exists(cms_encode($key, $chipper), $_COOKIE)) { setcookie(cms_encode($key, $chipper), cms_encode($val, $chipper)); } } // extend user last active status $this->__cms_extend_user_last_active($this->cms_user_id()); }
function get_decoded_cookie($key, $chipper) { $key = cms_encode($key, $chipper); if (!array_key_exists($key, $_COOKIE)) { $key = urldecode($key); } if (array_key_exists($key, $_COOKIE)) { return cms_decode($_COOKIE[$key], $chipper); } return NULL; }
public function index() { $this->theme = $this->cms_get_config('site_theme'); // third party authentication setting $third_party_variables = array('auth_enable_facebook', 'auth_facebook_app_id', 'auth_facebook_app_secret', 'auth_enable_twitter', 'auth_twitter_app_key', 'auth_twitter_app_secret', 'auth_enable_google', 'auth_google_app_id', 'auth_google_app_secret', 'auth_enable_yahoo', 'auth_yahoo_app_id', 'auth_yahoo_app_secret', 'auth_enable_linkedin', 'auth_linkedin_app_key', 'auth_linkedin_app_secret', 'auth_enable_myspace', 'auth_myspace_app_key', 'auth_myspace_app_secret', 'auth_enable_foursquare', 'auth_foursquare_app_id', 'auth_foursquare_app_secret', 'auth_enable_windows_live', 'auth_windows_live_app_id', 'auth_windows_live_app_secret', 'auth_enable_open_id', 'auth_enable_aol'); if (CMS_SUBSITE == '') { $hybridauth_config_file = APPPATH . '/config/main/hybridauthlib.php'; } else { $hybridauth_config_file = APPPATH . '/config/site-' . CMS_SUBSITE . '/hybridauthlib.php'; } // save the uploaded files if (isset($_FILES['site_logo'])) { try { $site_logo = $_FILES['site_logo']; if (isset($site_logo['tmp_name']) && $site_logo['tmp_name'] != '' && getimagesize($site_logo['tmp_name']) !== FALSE) { $file_name = FCPATH . 'assets/nocms/images/custom_logo/' . CMS_SUBSITE . $site_logo['name']; move_uploaded_file($site_logo['tmp_name'], $file_name); $this->cms_resize_image($file_name, 800, 125); $this->cms_set_config('site_logo', '{{ base_url }}assets/nocms/images/custom_logo/' . CMS_SUBSITE . $site_logo['name']); } } catch (Exception $e) { // do nothing } } if (isset($_FILES['site_favicon'])) { try { $site_favicon = $_FILES['site_favicon']; if (isset($site_favicon['tmp_name']) && $site_favicon['tmp_name'] != '' && getimagesize($site_favicon['tmp_name']) !== FALSE) { $file_name = FCPATH . 'assets/nocms/images/custom_favicon/' . CMS_SUBSITE . $site_favicon['name']; move_uploaded_file($site_favicon['tmp_name'], $file_name); $this->cms_resize_image($file_name, 64, 64); $this->cms_set_config('site_favicon', '{{ base_url }}assets/nocms/images/custom_favicon/' . CMS_SUBSITE . $site_favicon['name']); } } catch (Exception $e) { // do nothing } } if ($this->input->post('remove_background_image') == 1) { $this->cms_set_config('site_background_image', ''); } else { if (isset($_FILES['site_background_image'])) { try { $site_background_image = $_FILES['site_background_image']; if (isset($site_background_image['tmp_name']) && $site_background_image['tmp_name'] != '' && getimagesize($site_background_image['tmp_name']) !== FALSE) { $file_name = FCPATH . 'assets/nocms/images/custom_background/' . CMS_SUBSITE . $site_background_image['name']; move_uploaded_file($site_background_image['tmp_name'], $file_name); $this->cms_set_config('site_background_image', '{{ base_url }}assets/nocms/images/custom_background/' . CMS_SUBSITE . $site_background_image['name']); } } catch (Exception $e) { // do nothing } } } if (count($_POST) > 0) { // save the section widgets $this->update_static_content('section_custom_style', $this->input->post('section_custom_style')); $this->update_static_content('section_custom_script', $this->input->post('section_custom_script')); $this->update_static_content('section_top_fix', $this->input->post('section_top_fix')); $this->update_static_content('section_banner', $this->input->post('section_banner')); $this->update_static_content('section_left', $this->input->post('section_left')); $this->update_static_content('section_right', $this->input->post('section_right')); $this->update_static_content('section_bottom', $this->input->post('section_bottom')); $this->update_static_content('navigation_right_partial', $this->input->post('navigation_right_partial')); // save configurations $configuration_list = array('site_name', 'site_layout', 'site_slogan', 'site_footer', 'site_language', 'site_background_color', 'site_background_position', 'site_background_size', 'site_background_repeat', 'site_background_origin', 'site_background_clip', 'site_background_attachment', 'site_background_blur', 'site_text_color', 'site_show_benchmark', 'cms_signup_activation', 'cms_email_protocol', 'cms_email_reply_address', 'cms_email_reply_name', 'cms_email_forgot_subject', 'cms_email_forgot_message', 'cms_email_signup_subject', 'cms_email_signup_message', 'cms_email_useragent', 'cms_email_mailpath', 'cms_email_smtp_host', 'cms_email_smtp_user', 'cms_email_smtp_pass', 'cms_email_smtp_port', 'cms_email_smtp_timeout', 'cms_google_analytic_property_id', 'cms_internet_connectivity', 'cms_subsite_configs', 'cms_subsite_modules'); // only for non-subsite if (CMS_SUBSITE == '' && $this->cms_is_module_active('gofrendi.noCMS.multisite')) { $configuration_list[] = 'cms_add_subsite_on_register'; $configuration_list[] = 'cms_subsite_use_subdomain'; $configuration_list[] = 'cms_subsite_home_content'; $configuration_list[] = 'cms_subsite_configs'; $configuration_list[] = 'cms_subsite_modules'; } foreach ($configuration_list as $configuration) { $value = $this->input->post($configuration); if ($configuration == 'cms_email_smtp_pass') { if ($value == '[PASSWORD SET]') { continue; } $value = cms_encode($value); } // Don't update configuration if there is no change if ($this->cms_get_config($configuration, TRUE) == $value) { continue; } $this->cms_set_config($configuration, $value); } // save language $this->cms_language($this->input->post('site_language')); // save default_controller $this->cms_set_default_controller($this->input->post('default_controller')); // save third party authentication $str = file_get_contents($hybridauth_config_file); foreach ($third_party_variables as $var) { $value = $this->input->post($var); // for auth_enable type, just put a boolean value, else add quotes if (substr($var, 0, 11) == 'auth_enable') { $value = $value == 0 ? 'FALSE' : 'TRUE'; } else { $value = "'" . addslashes($value) . "'"; } $pattern = '/(\\$' . $var . ' *= *)(.*?)(;)/si'; $replacement = '${1}' . $value . '${3}'; $str = preg_replace($pattern, $replacement, $str); } @chmod($hybridauth_config_file, 0777); file_put_contents($hybridauth_config_file, $str); @chmod($hybridauth_config_file, 0755); } // widgets $query = $this->db->select('widget_id, widget_name, static_content')->from(cms_table_name('main_widget'))->get(); $widget_list = $query->result_array(); $normal_widget_list = array(); $section_widget_list = array(); foreach ($widget_list as $widget) { if (substr($widget['widget_name'], 0, 8) == 'section_' || $widget['widget_name'] == 'navigation_right_partial') { $section_widget_list[$widget['widget_name']] = $widget; } else { $normal_widget_list[] = $widget; } } // languages $language_list = $this->cms_language_list(); // config $query = $this->db->select('config_name, value')->from(cms_table_name('main_config'))->get(); $config_list = array(); foreach ($query->result_array() as $row) { $value = $row['value']; if ($row['config_name'] == 'cms_email_smtp_pass') { //$value = cms_decode($value); if ($value != '') { $value = '[PASSWORD SET]'; } } $config_list[$row['config_name']] = $value; } // layout $layout_list = array(); $site_theme = $config_list['site_theme']; $this->load->helper('directory'); $files = directory_map('themes/' . $site_theme . '/views/layouts/', 1); sort($files); foreach ($files as $file) { if (is_dir('themes/' . $site_theme . '/views/layouts/' . $file)) { continue; } $file = str_ireplace('.php', '', $file); if ($file == $config_list['site_layout']) { continue; } $layout_list[] = $file; } // get third_party_configurations include $hybridauth_config_file; $third_party_config = array(); foreach ($third_party_variables as $var) { eval('$third_party_config["' . $var . '"] = $' . $var . ';'); } // update route if ($this->cms_is_module_active('gofrendi.noCMS.multisite')) { $module_path = $this->cms_module_path('gofrendi.noCMS.multisite'); if (strtoupper($this->cms_get_config('cms_add_subsite_on_register')) == 'TRUE') { $this->cms_add_route('main/register', $module_path . '/multisite/register'); } else { $this->cms_remove_route('main/register'); } } $default_controller = $this->cms_get_default_controller(); // send to the view $data['normal_widget_list'] = $normal_widget_list; $data['section_widget_list'] = $section_widget_list; $data['language_list'] = $language_list; $data['config_list'] = $config_list; $data['layout_list'] = $layout_list; $data['current_language'] = $this->cms_get_config('site_language', True); $data['default_controller'] = $default_controller; $data['multisite_active'] = $this->cms_is_module_active('gofrendi.noCMS.multisite'); $data['third_party_config'] = $third_party_config; $data['changed'] = count($_POST) > 0; $this->view('setting_index', $data, 'main_setting'); }