Ejemplo n.º 1
0
 /**
  * get text translation.
  * 
  * @param string $text text message.
  * @param string $domain text domain.
  * @return string return translated text.
  */
 function _t($text, $domain = 'messages')
 {
     if ($domain == null) {
         $domain = 'messages';
     }
     if (function_exists('_textdomain')) {
         _textdomain($domain);
     }
     if (function_exists('_gettext')) {
         return _gettext($text);
     } else {
         \System\Libraries\Log::write('language', 'warning', 'Unable to find _gettext function. Please check php-gettext component.');
         return $text;
     }
 }
Ejemplo n.º 2
0
 /**
  * get config routes file path.<br>
  * the routes are stored in db. use this class/method to generate them into file and get the file path that were generated.
  * 
  * @return string return path of routes file.
  */
 public function getRoutesFile()
 {
     $adapter = new Local($this->route_config_folder);
     $filesystem = new Filesystem($adapter);
     unset($adapter);
     if ($filesystem->has($this->route_db_file)) {
         $route_file_ts = $filesystem->getTimestamp($this->route_db_file);
         $day_old = (time() - $route_file_ts) / 60 / 60 / 24;
         if ($day_old > 30) {
             // older than 30 days, rebuild routes.
             $build_result = $this->buildRoutesFile();
         }
         unset($day_old, $filesystem, $route_file_ts);
         if (isset($build_result) && $build_result !== true) {
             \System\Libraries\Log::write('RoutesDb', 'notice', 'Could not generate the route from db from getRoutesFile method.');
         }
         return $this->route_config_folder . DS . $this->route_db_file;
     } elseif ($this->buildRoutesFile() === true) {
         // never build the routes before, build it.
         unset($filesystem);
         return $this->route_config_folder . DS . $this->route_db_file;
     } else {
         return null;
     }
 }
Ejemplo n.º 3
0
 /**
  * find where the theme or views location is and is it template file (in case of use template engine) or normal views php file.
  * this will be look by order:
  * 0. look for template file in public/themes
  * 1. look for views file in public/themes
  * 2. look for template file in public/themes for fallback theme
  * 3. look for views file in public/themes for fallback theme
  * 4. look for template file in module's/Theme
  * 5. look for views file in module's/Theme
  * 6. look for template file in system/Core/Theme
  * 7. look for views file in system/Core/Theme
  * 
  * @param string $views_file path of template or views file. without extension.
  * @param string $theme_dir path to theme directory. use relative path from index.php file.
  * @param string $theme_name the theme name
  * @param string $theme_name_fallback theme fallback name
  * @param string $module_name current module that is calling.
  * @param mixed $template_engine set to false if not use template engine. set to template class object if use template engine.
  * @return array
  */
 public function findThemeOrViewsLocation($views_file, $theme_dir, $theme_name, $theme_name_fallback, $module_name, $template_engine = false)
 {
     $output = [];
     if (is_object($template_engine) && method_exists($template_engine, 'getTemplateExtension')) {
         $ext = $template_engine->getTemplateExtension();
         $use_template = true;
     } else {
         $ext = '.php';
         $use_template = false;
     }
     // setup the order of theme location to search in.
     $theme_search_array = [];
     if ($use_template == true) {
         $theme_search_array[0]['theme_path'] = $theme_dir . '/' . $theme_name . '/Modules/' . $module_name;
         $theme_search_array[0]['theme_name'] = $theme_name;
         $theme_search_array[0]['theme_file'] = $views_file . $ext;
         $theme_search_array[0]['use_template'] = $use_template;
     }
     $theme_search_array[1]['theme_path'] = $theme_dir . '/' . $theme_name . '/Modules/' . $module_name;
     $theme_search_array[1]['theme_name'] = $theme_name;
     $theme_search_array[1]['theme_file'] = $views_file . '.php';
     $theme_search_array[1]['use_template'] = false;
     if ($use_template == true) {
         $theme_search_array[2]['theme_path'] = $theme_dir . '/' . $theme_name_fallback . '/Modules/' . $module_name;
         $theme_search_array[2]['theme_name'] = $theme_name_fallback;
         $theme_search_array[2]['theme_file'] = $views_file . $ext;
         $theme_search_array[2]['use_template'] = $use_template;
     }
     $theme_search_array[3]['theme_path'] = $theme_dir . '/' . $theme_name_fallback . '/Modules/' . $module_name;
     $theme_search_array[3]['theme_name'] = $theme_name_fallback;
     $theme_search_array[3]['theme_file'] = $views_file . '.php';
     $theme_search_array[3]['use_template'] = false;
     if ($use_template == true) {
         $theme_search_array[4]['theme_path'] = MODULE_PATH . DS . $module_name . DS . 'Theme';
         $theme_search_array[4]['theme_name'] = null;
         $theme_search_array[4]['theme_file'] = $views_file . $ext;
         $theme_search_array[4]['use_template'] = $use_template;
     }
     $theme_search_array[5]['theme_path'] = MODULE_PATH . DS . $module_name . DS . 'Theme';
     $theme_search_array[5]['theme_name'] = null;
     $theme_search_array[5]['theme_file'] = $views_file . '.php';
     $theme_search_array[5]['use_template'] = false;
     if (strpos($module_name, 'System/Core') !== false) {
         if ($use_template == true) {
             $theme_search_array[6]['theme_path'] = ROOT_PATH . DS . str_replace('System/Core', 'system/Core', $module_name) . DS . 'Theme';
             $theme_search_array[6]['theme_name'] = null;
             $theme_search_array[6]['theme_file'] = $views_file . $ext;
             $theme_search_array[6]['use_template'] = $use_template;
         }
         $theme_search_array[7]['theme_path'] = ROOT_PATH . DS . str_replace('System/Core', 'system/Core', $module_name) . DS . 'Theme';
         $theme_search_array[7]['theme_name'] = null;
         $theme_search_array[7]['theme_file'] = $views_file . '.php';
         $theme_search_array[7]['use_template'] = false;
     }
     // loop check in each location.
     foreach ($theme_search_array as $key => $item) {
         if (is_file($item['theme_path'] . '/' . $item['theme_file'])) {
             $output = $item;
             break;
         }
     }
     unset($item, $key, $theme_search_array);
     // for in case that developer did not create theme or views file. it is really not found!
     if (empty($output)) {
         $output['theme_path'] = MODULE_PATH . DS . $module_name . DS . 'Theme';
         $output['theme_file'] = $views_file . '.php';
         $output['use_template'] = false;
         \System\Libraries\Log::write('Theme', 'warning', 'The theme or views file could not be found.', $output);
     } else {
         \System\Libraries\Log::write('Theme', 'debug', 'The theme was found in this location data.', $output);
     }
     unset($ext, $use_template);
     return $output;
 }
Ejemplo n.º 4
0
 /**
  * check and get language locale uri.<br>
  * check that the input language locale uri is correctly or enabled or not. if not then return the default language locale uri.
  * 
  * @param string $language_locale_uri language locale uri. for example: th, en-US, en-UK, ...
  * @return string return the correctly language locale uri or default language locale uri.
  */
 public function getLanguageUri($language_locale_uri)
 {
     $lang_config_file = $this->getConfigFile();
     if ($lang_config_file != null && is_file($lang_config_file)) {
         $languages_config = (include $lang_config_file);
     }
     unset($lang_config_file);
     if (is_array($languages_config) && array_key_exists('languages', $languages_config)) {
         // found languages in config array key.
         if (is_array($languages_config['languages'])) {
             if (array_key_exists($language_locale_uri, $languages_config['languages'])) {
                 // the input language locale uri were matched the languages.
                 unset($languages_config);
                 return $language_locale_uri;
             } else {
                 // the input language locale uri does not match in any languages.
                 foreach ($languages_config['languages'] as $key => $item) {
                     if (is_array($item) && array_key_exists('language_default', $item) && $item['language_default'] === true) {
                         // found the default language, use this one.
                         unset($item, $languages_config);
                         return $key;
                     }
                 }
                 // endforeach;
                 unset($item, $key);
             }
         }
     }
     if (is_array($languages_config) && array_key_exists('language_fallback', $languages_config)) {
         // not found languages in config array key but found language_fallback in config array key.
         \System\Libraries\Log::write('LanguagesDb', 'warning', 'Unable to get languages configuration values.');
         unset($languages_config);
         return key($languages_config['language_fallback']);
     } else {
         // not found anything.
         \System\Libraries\Log::write('LanguagesDb', 'error', 'Unable to get languages and language_fallback configuration values.');
         unset($languages_config);
         die('Unable to get languages configuration values.');
     }
 }
Ejemplo n.º 5
0
 /**
  * re-connect to db.
  * 
  * @param array $db_config array config for override the default configuration.
  */
 public function reconnect(array $db_config = [])
 {
     \System\Libraries\Log::write('db_connection', 'debug', 'Re-connecting to db with this configurations.', $db_config);
     $this->close();
     $this->connect($db_config);
 }
Ejemplo n.º 6
0
 /**
  * set config name (key) and value. warning! this will not write to the config file.
  * 
  * @param string $file config file name only, no extension.
  * @param string $config_key config name.
  * @param mixed $config_value config value.
  */
 public function set($file, $config_key, $config_value)
 {
     $this->isLoaded($file);
     if (is_array($this->loaded_file) && array_key_exists($file, $this->loaded_file)) {
         if (is_array($this->loaded_file[$file])) {
             $this->loaded_file[$file][$config_key] = $config_value;
         } else {
             \System\Libraries\Log::write('config library', 'warning', 'Config file that were load is not an array.', ['config_file' => $this->trace_loaded_files, 'content' => $this->loaded_file[$file]]);
         }
     } else {
         \System\Libraries\Log::write('config library', 'warning', 'Config file could not be loaded.', ['config_file' => $this->trace_loaded_files]);
     }
 }