Example #1
0
 /**
  * Constructor
  *
  */
 public function __construct()
 {
     parent::__construct();
     $module_uri = $this->uri->segment(1);
     // Set Module's config
     $module_config = Modules()->get_module_config_from_uri($module_uri);
     foreach ($module_config as $item => $value) {
         $this->config->set_item($item, $value);
     }
     if (!empty($module_config)) {
         // Languages
         $online_lang_codes = array();
         foreach (Settings::get_online_languages() as $language) {
             $online_lang_codes[] = $language['lang'];
         }
         // If the lang code detected by the Router is not in the DB languages, set it to the DB default one
         if (!in_array(config_item('detected_lang_code'), $online_lang_codes)) {
             Settings::set('current_lang', Settings::get_lang('default'));
             $this->config->set_item('detected_lang_code', Settings::get_lang('default'));
         } else {
             // Store the current lang code (found by Router) to Settings
             Settings::set('current_lang', config_item('detected_lang_code'));
         }
         // Set the current theme
         Theme::set_theme(Settings::get('theme'));
         // Load Theme Events library
         if (is_file($file = FCPATH . Theme::get_theme_path() . 'libraries/theme_events.php')) {
             Event::load_event_library($file);
         }
         // Static translations
         $lang_files = array();
         $lang_folder = APPPATH . 'language/' . Settings::get_lang();
         // Core languages files : Including except "admin_lang.php"
         if (is_dir($lang_folder)) {
             $lang_files = glob($lang_folder . '/*_lang.php', GLOB_BRACE);
             foreach ($lang_files as $key => $lang_file) {
                 if ($lang_file == $lang_folder . '/admin_lang.php') {
                     unset($lang_files[$key]);
                 }
             }
         }
         // Check if theme lang folder exist
         $theme_lang_folder = FCPATH . Theme::get_theme_path() . 'language/' . Settings::get_lang() . '/';
         if (file_exists($theme_lang_folder)) {
             // Theme static translations
             $lf = glob($theme_lang_folder . '*_lang.php');
             foreach ($lf as $key => $tlf) {
                 if (basename($tlf) === 'theme_lang.php') {
                     unset($lf[$key]);
                     array_unshift($lf, $tlf);
                     break;
                 }
             }
             if (!empty($lf)) {
                 $lang_files = array_merge($lf, (array) $lang_files);
             }
         }
         // Module translation files
         $lang_file = MODPATH . $module_config['folder'] . '/language/' . Settings::get_lang('current') . '/' . $module_config['key'] . '_lang.php';
         if (is_file($lang_file)) {
             array_push($lang_files, $lang_file);
         }
         // Load all lang files
         if (!empty($lang_files)) {
             foreach ($lang_files as $l) {
                 if (is_file($l) && '.' . end(explode('.', $l)) == EXT) {
                     include $l;
                     if (!empty($lang)) {
                         foreach ($lang as $key => $translation) {
                             // If the term doesn't exists
                             if (!isset($this->lang->language[$key]) or $this->lang->language[$key] == '') {
                                 $this->lang->language[$key] = $translation;
                             } else {
                                 // Only replace by default (theme vs. module) if the translation is empty
                                 if (empty($this->lang->language[$key])) {
                                     $this->lang->language[$key] = $translation;
                                 }
                             }
                         }
                         unset($lang);
                     }
                 }
             }
         }
     }
 }