コード例 #1
0
ファイル: Filter.php プロジェクト: jaybill/Bolts
 function filter($url, array $params = null)
 {
     $this->_Bolts_plugin = Bolts_Plugin::getInstance();
     $out_url = $url;
     // LOCALIZATION
     if (Bolts_Registry::get('enable_localization') == '1') {
         if (stripos($url, "/") === 0) {
             // for virtual URLs
             $locale_code = $params['locale_code'];
             if (!is_null($locale_code)) {
                 // localize the URL by injecting the locale code at the root
                 if (Bolts_Translate::validateLocaleCode($locale_code)) {
                     $out_url = "/" . $locale_code . $url;
                 }
             }
         } else {
             // TODO - add other cases, such as absolute and relative URLs
         }
     }
     // SSL
     if (Bolts_Registry::get('enable_ssl') == '1') {
         $secure_urls = Bolts_Registry::get('secure_urls');
         if (!empty($secure_urls)) {
             $secure_urls = explode('|', $secure_urls);
             if (stripos($url, "/") === 0) {
                 // for virtual URLs
                 // $tmp_url = '/'.trim('/', $url); // get rid of the last slash
                 if (in_array($url, $secure_urls)) {
                     $out_url = str_replace('http://', 'https://', Bolts_Registry::get('site_url') . $out_url);
                 }
             } else {
                 // TODO - add other cases, such as absolute and relative URLs
             }
         }
     }
     // FORCE ABSOLUTE URL
     if (array_key_exists('absolute', $params) || in_array('absolute', $params)) {
         if (stripos($url, "/") === 0) {
             $out_url = Bolts_Registry::get('site_url') . $out_url;
         } else {
             $out_url = Bolts_Registry::get('site_url') . '/' . $out_url;
         }
     }
     $params = array('url' => $out_url);
     $params = $this->_Bolts_plugin->doFilter('url_post_filter', $params);
     // FILTER HOOK
     return $params['url'];
 }
コード例 #2
0
ファイル: block.url.php プロジェクト: jaybill/Bolts
function smarty_block_url($params, $content, $smarty, $repeat)
{
    $tpl_vars = $smarty->_tpl_vars;
    // only output on the closing tag
    if (!$repeat) {
        if (isset($content)) {
            $urlparams = array();
            $locale_code = $tpl_vars['locale_code'];
            $request_locale = $tpl_vars['request_locale'];
            if ($request_locale && $locale_code != $request_locale) {
                $urlparams['locale_code'] = strtolower($request_locale);
            } elseif (!is_null($locale_code) && Bolts_Translate::validateLocaleCode($locale_code)) {
                $urlparams['locale_code'] = strtolower($locale_code);
            }
            $url_filter = new Bolts_Url_Filter();
            return $url_filter->filter($content, $urlparams);
        }
    }
}
コード例 #3
0
ファイル: LocaleController.php プロジェクト: jaybill/Bolts
 function setcookieAction()
 {
     // TODO maybe? - prevent people from viewing this page if localization is not enabled
     $request = new Bolts_Request($this->getRequest());
     if ($request->has("code") && $request->code != "") {
         $locale_code = $request->code;
         $time = Bolts_Registry::get('locale_cache_lifetime');
         if (Bolts_Translate::validateLocaleCode($locale_code)) {
             setcookie("locale_code", $locale_code, time() + $time, "/");
             if ($request->has("return_url")) {
                 $url_filter = new Bolts_Url_Filter();
                 header("Location: " . $url_filter->filter($request->return_url, array('locale_code' => $locale_code)));
             } else {
                 header("Location: /" . $locale_code);
             }
         }
     } else {
         $this->_redirect("/bolts/locale/choose/");
     }
 }