예제 #1
0
 /**
 	Get custom (html/text) module translations
 		@private
 	**/
 private static function __translate(&$item, $section = 'custom', $skip_enable_checking = false)
 {
     if (empty($item)) {
         return false;
     }
     $params = json_decode($item->params);
     $serialized = $params !== null;
     if (!$serialized) {
         $params = new Parameter(@$item->params);
     }
     // get active lang
     $active_lang = I18N::getCurrentLanguage();
     if (!$skip_enable_checking) {
         $translation_opt = $serialized ? @$params->translation : @json_decode($params->get('translation'));
         // check enabled
         $lang_enabled = isset($translation_opt->{"{$active_lang}"}) ? $translation_opt->{$active_lang}->enabled : false;
         if ($lang_enabled && isset($translation_opt->{$active_lang})) {
             foreach (get_object_vars($translation_opt->{$active_lang}) as $k => $v) {
                 if (strpos($k, 'params__') !== false && isset($item->params)) {
                     $k = str_replace('params__', '', $k);
                     if ($serialized) {
                         $params->{$k} = $v;
                     } else {
                         $params->set($k, $v);
                     }
                 } else {
                     $item->{$k} = $v;
                 }
             }
             /**/
             $item->params = $serialized ? json_encode($params) : $params->toString();
         }
     } else {
         $lang_enabled = true;
     }
     if ($lang_enabled) {
         $lang_map = array();
         $active_lang = empty($active_lang) ? I18N::getDefaultLanguage() : $active_lang;
         // get translation map
         $map_data = I18N::getTranslationMapKeyValuePair(array('section' => 'default.modules.' . $section, 'id' => $item->id), 'lang_code');
         if (isset($map_data[$active_lang])) {
             $lang_map = $map_data[$active_lang];
         }
         if ($lang_map) {
             // translate
             foreach ($lang_map as $k => $v) {
                 if (isset($item->{$k}) && !empty($v)) {
                     $item->{$k} = $v;
                 }
             }
         }
     }
 }
예제 #2
0
파일: url.class.php 프로젝트: rudenyl/kcms
 /**
 	Routing implemention shorthand
 		@param $url string
 		@param $params string
 		@param $force_ssl boolean
 		@param $always_frontend boolean
 	**/
 public static function _($url, $params = null, $force_ssl = false, $always_frontend = null)
 {
     $__app = Factory::getApplication();
     $config = $__app->get('config');
     $url = str_replace('&', '&', $url);
     // set base URL
     $base_app_path = PATH_APPLICATIONS;
     $base_url_path = $config->baseURL;
     // always parse with frontend applications
     if ($always_frontend === true) {
         $admin_path = str_replace('/', DS, $config->admin_path);
         $base_app_path = str_replace($admin_path, '', PATH_APPLICATIONS);
         $base_url_path = str_replace($config->admin_path, '', $config->baseURL);
     }
     if ($config->SEFURL) {
         // Get current language
         $lang_code = I18N::getCurrentLanguage();
         // url prefix
         $lang_prefix = '';
         // Add language
         if ($lang_code && @$config->SEFURL_lang_prefix) {
             // add to route
             $lang_prefix = $lang_code . '/';
         }
         $segment = array();
         // create param link
         $params = empty($params) ? '' : ($params[0] != '#' ? '?' : '') . $params;
         // parse url
         $uri_vars = parse_url($url);
         // parse uri query
         parse_str(@$uri_vars['query'], $queries);
         if ($queries) {
             $segment = array_merge($segment, $queries);
             $required = array('app', 'view', 'task', 'id', 'menu_id', '_PN');
             foreach ($queries as $qk => $qv) {
                 if (in_array($qk, $required)) {
                     unset($queries[$qk]);
                 }
             }
             // attach to params
             if ($queries) {
                 $params .= (empty($params) ? '?' : '&') . http_build_query($queries);
             }
         }
         // build
         if (isset($segment['view'])) {
             $route = array();
             // save URL tag
             $save_url = false;
             // get SEF implementation per app
             if (isset($segment['app'])) {
                 $app = $segment['app'];
             } else {
                 $app = Request::getVar('app', 'default');
             }
             $appSEFName = 'App' . ucfirst($app) . 'SEF';
             $appSEFPath = $base_app_path . DS . $app . DS . 'sef.php';
             if (file_exists($appSEFPath) && is_file($appSEFPath)) {
                 require_once $appSEFPath;
                 $appSEFName = 'App' . ucfirst($app) . 'SEF';
                 $appSEFClass = new $appSEFName();
                 if (is_subclass_of($appSEFClass, 'SEF')) {
                     // check if can save url links
                     if (method_exists($appSEFClass, 'saveURL')) {
                         $save_url = $appSEFClass->saveURL();
                     }
                     $appSEFTask = 'BuildSEFRoute';
                     if (method_exists($appSEFClass, $appSEFTask)) {
                         // execute task
                         $route = $appSEFClass->{$appSEFTask}($segment, $save_url);
                     }
                 }
             }
             if (empty($route)) {
                 if (isset($segment['app'])) {
                     $route[] = $segment['app'];
                 }
                 $route[] = isset($segment['view']) ? $segment['view'] : 'default';
                 $route[] = isset($segment['task']) ? $segment['task'] : '';
                 if (isset($segment['id'])) {
                     if (strpos($segment['id'], ':') !== false) {
                         list($id, $alias) = explode(':', $segment['id']);
                         $route[] = $id;
                         $route[] = $alias;
                     } else {
                         $route[] = $segment['id'];
                     }
                 }
             }
             $route = implode('/', $route);
             $sef_url = $base_url_path . $route;
             // save redirection link
             if ($save_url) {
                 if (isset($uri_vars['path']) && $uri_vars['path'] == 'index.php') {
                     $url = $base_url_path . $url;
                 }
                 $old_url = str_replace($base_url_path, '', $url);
                 if (($saved_url = self::saveRedirection($old_url, $route)) !== false) {
                     $sef_url = $base_url_path . $lang_prefix . $saved_url;
                 }
             }
             $url = $sef_url . $params;
         } else {
             $url = $base_url_path . $lang_prefix;
             $url .= $params;
         }
     } else {
         // create param link
         $params = empty($params) ? '' : ($params[0] != '#' ? strpos($url, '?') !== false ? '&' : '?' : '') . $params;
         // add base URL
         if (strpos($url, 'http') === false) {
             $url = $base_url_path . $url;
         }
         $url .= $params;
     }
     // force ssl
     if ($force_ssl && !self::_isLocal()) {
         $uri = explode(':', $url);
         if (!empty($uri) && $uri[0] == 'http') {
             $url = str_replace('http://', 'https://', $url);
         }
     }
     return $url;
 }