Example #1
0
/**
 * System front end theme function
 * 
 * @author Vee W.
 * @license http://opensource.org/licenses/MIT
 * 
 */
function languageSwitchDropdown()
{
    $languages = \Config::get('locales');
    // no languages, language is empty, there is only just one language
    if (empty($languages) || !is_array($languages) || count($languages) <= 1) {
        return null;
    }
    ksort($languages);
    $current_lang = \Lang::get_lang();
    $output = "\n" . '<div class="dropdown">' . "\n";
    $output .= "\t" . '<button class="btn btn-default dropdown-toggle" type="button" id="language-switch-dropdown" data-toggle="dropdown">';
    $output .= $languages[$current_lang]['name'];
    $output .= '<span class="caret"></span>';
    $output .= '</button>' . "\n";
    if (is_array($languages) && !empty($languages) && count($languages) > 1) {
        $output .= '<ul class="dropdown-menu" role="menu" aria-labelledby="language-switch-dropdown">' . "\n";
        foreach ($languages as $language => $item) {
            if ($language != $current_lang) {
                $output .= "\t" . '<li>' . \Html::anchor(\Uri::createNL($language), $item['name']) . '</li>' . "\n";
            }
        }
        $output .= '</ul>' . "\n";
    }
    $output .= '</div>' . "\n";
    return $output;
}
Example #2
0
 public function before()
 {
     if (!\CMF\Auth::check(null, 'view', 'admin_site')) {
         \Response::redirect("/admin/login?next=" . \Uri::string(), 'location');
     }
     \Lang::$autosave = false;
     // Find the lang from the session, or from the user
     if ($this->lang_enabled = \Config::get('cmf.languages.enabled', false)) {
         $lang = \Session::get('cmf.admin.language');
         if ($lang === null) {
             $user = \CMF\Auth::current_user();
             $lang = $user->default_language;
         }
         if (!empty($lang) && strlen($lang) !== 0 && $lang !== null) {
             \CMF::setLang($lang);
         }
     }
     // Allows us to set the interface template via an integer
     $this->mode = \Input::param('_mode', 'default');
     $this->interface_template = \Config::get('cmf.admin.interface_templates.' . $this->mode);
     // A unique ID that can be passed through
     $this->cid = \Input::param('_cid', 'none');
     // Lang info
     $this->current_lang = \Lang::get_lang();
     $this->fallback_lang = \Lang::$fallback;
     $this->lang_lines = \Lang::$lines;
 }
Example #3
0
 /**
  * read template
  *
  * @author Vee Winch.
  * @param string $email_file email file.
  * @param string $template_path path to folder that store email file.
  * @return mixed
  */
 public static function readTemplate($email_file = '', $template_path = null)
 {
     if ($email_file == null) {
         return null;
     }
     if ($template_path == null) {
         $template_path = APPPATH . 'lang' . DS . \Lang::get_lang() . DS . 'email' . DS;
     }
     if (file_exists($template_path . $email_file)) {
         $site_name = \Model_Config::getval('site_name');
         $output = file_get_contents($template_path . $email_file);
         $output = str_replace("%site_name%", $site_name, $output);
         $output = str_replace("%site_url%", \Uri::base(), $output);
         $output = str_replace("%site_admin%", \Uri::create('admin'), $output);
         unset($site_name, $template_path);
         return $output;
     } else {
         return false;
     }
 }
Example #4
0
 /**
  * Gets a list of the active languages that have been configured
  */
 public static function languageUrls()
 {
     if (static::$languageUrls !== null) {
         return static::$languageUrls;
     }
     if (!static::$lang_enabled) {
         return static::$languageUrls = array(\Lang::get_lang());
     }
     $url = static::original_uri();
     if (empty($url)) {
         $url = '/';
     } else {
         $url = '/' . trim($url, '/');
     }
     try {
         $currentUrl = static::currentUrl();
         $languages = \DB::query("SELECT l.id, l.code, l.top_level_domain, u.url url, t.content url_translated FROM languages AS l LEFT JOIN urls AS u ON (u.id = " . (!empty($currentUrl) ? $currentUrl->id : '0') . ") LEFT JOIN ext_translations AS t ON (t.locale = l.code AND t.object_class = 'CMF\\\\Model\\\\URL' AND t.field = 'url' AND t.foreign_key = " . (!empty($currentUrl) ? $currentUrl->id : "0") . ") WHERE l.visible = 1 ORDER BY l.pos ASC")->execute()->as_array();
         foreach ($languages as &$language) {
             $language['url'] = static::link(!empty($language['url_translated']) ? $language['url_translated'] : $language['url'], $language['code']);
             unset($language['url_translated']);
         }
         return static::$languageUrls = $languages;
     } catch (\Exception $e) {
         return array(array('id' => 0, 'code' => \Lang::get_lang(), 'top_level_domain' => '', 'url' => $url));
     }
 }
Example #5
0
/**
 * language switch for admin page. display as select box.
 * 
 * @return string
 */
function languageSwitchAdminSelectBox()
{
    $languages = \Config::get('locales');
    ksort($languages);
    $current_lang = \Lang::get_lang();
    $output = "\n" . '<select name="admin_language" onchange="change_redirect($(this));" class="form-control chosen-select">' . "\n";
    if (is_array($languages) && !empty($languages)) {
        foreach ($languages as $language => $item) {
            $output .= "\t" . '<option value="' . \Uri::createNL($language . '/admin') . '"';
            if ($language == $current_lang) {
                $output .= ' selected="selected"';
            }
            $output .= '>' . $item['name'] . '</option>' . "\n";
        }
    } else {
        $output .= "\t" . '<option></option>' . "\n";
    }
    $output .= '</select>' . "\n";
    unset($current_lang, $languages);
    return $output;
}