Exemplo n.º 1
0
function smarty_block_t($params, $text, &$smarty)
{
    $text = stripslashes($text);
    if (isset($params['escape'])) {
        $escape = $params['escape'];
        unset($params['escape']);
    }
    if (isset($params['plural'])) {
        $plural = $params['plural'];
        unset($params['plural']);
        if (isset($params['count'])) {
            $count = $params['count'];
            unset($params['count']);
        }
    }
    if (isset($count) && isset($plural)) {
        $text = CoreLoader::locale(CoreLoader::$system['language'])->ngettext($text, $plural, $count);
    } else {
        $text = CoreLoader::locale(CoreLoader::$system['language'])->gettext($text);
    }
    if (count($params)) {
        $text = strarg($text, $params);
    }
    if (!isset($escape) || $escape == 'html') {
        $text = nl2br(htmlspecialchars($text));
    } elseif (isset($escape) && ($escape == 'javascript' || $escape == 'js')) {
        $text = str_replace('\'', '\\\'', stripslashes($text));
    }
    return $text;
}
Exemplo n.º 2
0
/**
 * Smarty block function, provides gettext support for smarty.
 *
 * The block content is the text that should be translated.
 *
 * Any parameter that is sent to the function will be represented as %n in the translation text,
 * where n is 1 for the first parameter. The following parameters are reserved:
 *       - escape - sets escape mode:
 *           - 'html' for HTML escaping, this is the default.
 *           - 'js' for javascript escaping.
 *           - 'no'/'off'/0 - turns off escaping
 *       - plural - The plural version of the text (2nd parameter of ngettext())
 *       - count - The item count for plural mode (3rd parameter of ngettext())
 */
function smarty_block_t($params, $text, &$smarty)
{
    $text = stripslashes($text);
    // set escape mode
    if (isset($params['escape'])) {
        $escape = $params['escape'];
        unset($params['escape']);
    }
    // set plural version
    if (isset($params['plural'])) {
        $plural = $params['plural'];
        unset($params['plural']);
        // set count
        if (isset($params['count'])) {
            $count = $params['count'];
            unset($params['count']);
        }
    }
    // use plural if required parameters are set
    if (isset($count) && isset($plural)) {
        $text = CoreLoader::locale(CoreLoader::$system['language'])->ngettext($text, $plural, $count);
    } else {
        // use normal
        $text = CoreLoader::locale(CoreLoader::$system['language'])->gettext($text);
    }
    // run strarg if there are parameters
    if (count($params)) {
        $text = strarg($text, $params);
    }
    if (!isset($escape) || $escape == 'html') {
        // html escape, default
        $text = nl2br(htmlspecialchars($text));
    } elseif (isset($escape) && ($escape == 'javascript' || $escape == 'js')) {
        // javascript escape
        $text = str_replace('\'', '\\\'', stripslashes($text));
    }
    return $text;
}
Exemplo n.º 3
0
 /**
  * 分页函数
  * @param type $total 一共多少记录
  * @param type $page  当前是第几页
  * @param type $pagesize 每页多少
  * @param type $url    url是什么,url里面的{page}会被替换成页码
  * @param array $order 分页条的组成,是一个数组,可以按着1-6的序号,选择分页条组成部分和每个部分的顺序
  * @param int $a_count   分页条中a页码链接的总数量,不包含当前页的a标签,默认10个。
  * @return type  String
  * echo CoreLoader::instance()->page(100,3,10,'?article/list/{page}',array(3,4,5,1,2,6));
  */
 public static function page($total, $page, $pagesize, $url, $order = array(1, 2, 3, 4, 5, 6), $a_count = 10)
 {
     $a_num = $a_count;
     $locale = CoreLoader::locale(CoreLoader::$system['language']);
     $first = $locale->gettext('首页');
     $last = $locale->gettext('尾页');
     $pre = $locale->gettext('上页');
     $next = $locale->gettext('下页');
     $a_num = $a_num % 2 == 0 ? $a_num + 1 : $a_num;
     $pages = ceil($total / $pagesize);
     $curpage = intval($page) ? intval($page) : 1;
     $curpage = $curpage > $pages || $curpage <= 0 ? 1 : $curpage;
     #当前页超范围置为1
     $body = '<span class="page_body">';
     $prefix = '';
     $suffix = '';
     $start = $curpage - ($a_num - 1) / 2;
     #开始页
     $end = $curpage + ($a_num - 1) / 2;
     #结束页
     $start = $start <= 0 ? 1 : $start;
     #开始页超范围修正
     $end = $end > $pages ? $pages : $end;
     #结束页超范围修正
     if ($pages >= $a_num) {
         #总页数大于显示页数
         if ($curpage <= ($a_num - 1) / 2) {
             $end = $a_num;
         }
         //当前页在左半边补右边
         if ($end - $curpage <= ($a_num - 1) / 2) {
             $start -= floor($a_num / 2) - ($end - $curpage);
         }
         //当前页在右半边补左边
     }
     for ($i = $start; $i <= $end; $i++) {
         if ($i == $curpage) {
             $body .= '<a class="page_cur_page" href="javascript:void(0);"><b>' . $i . '</b></a>';
         } else {
             $body .= '<a href="' . str_replace('{page}', $i, $url) . '">' . $i . '</a>';
         }
     }
     $body .= '</span>';
     $prefix = $curpage == 1 ? '' : '<span class="page_bar_prefix"><a href="' . str_replace('{page}', 1, $url) . '">' . $first . '</a><a href="' . str_replace('{page}', $curpage - 1, $url) . '">' . $pre . '</a></span>';
     $suffix = $curpage == $pages ? '' : '<span class="page_bar_suffix"><a href="' . str_replace('{page}', $curpage + 1, $url) . '">' . $next . '</a><a href="' . str_replace('{page}', $pages, $url) . '">' . $last . '</a></span>';
     $info = '<span class="page_cur">' . sprintf($locale->gettext('第%d/%d页'), $curpage, $pages) . '</span>';
     $inputId = 'PAGES' . time() . rand(0, 9999);
     $go = '<span class="page_input_num"><input onkeyup="if(event.keyCode==13){var num=this.value;if(!/^\\d+$/.test(num)||num<=0||num>' . $pages . '){alert(\'' . $locale->gettext('请输入正确页码!') . '\');return;};location=\'' . addslashes($url) . '\'.replace(/\\{page\\}/,this.value);}" type="number" min="1" value="' . $page . '" id="' . $inputId . '" /></span><span class="page_btn_go" onclick="var num=document.getElementById(\'' . $inputId . '\').value;if(!/^\\d+$/.test(num)||num<=0||num>' . $pages . '){alert(\'' . $locale->gettext('请输入正确页码!') . '\');return;};location=\'' . addslashes($url) . '\'.replace(/\\{page\\}/,num);" style="cursor:pointer">' . $locale->gettext('转到') . '</span>';
     $total = '<span class="page_total">' . sprintf($locale->gettext('共%d条'), $total) . '</span>';
     $pagination = array($total, $info, $prefix, $body, $suffix, $go);
     $output = array();
     if (is_null($order)) {
         $order = array(1, 2, 3, 4, 5, 6);
     }
     foreach ($order as $key) {
         if (isset($pagination[$key - 1])) {
             $output[] = $pagination[$key - 1];
         }
     }
     return $pages > 1 ? implode('', $output) : '';
 }
Exemplo n.º 4
0
 public function __construct()
 {
     parent::__construct();
     $this->router_info = CoreRouter::info();
     // ====================================
     // 确定语言
     // ====================================
     $cookie_lifetime = 7 * 86400;
     if (!empty($_GET['lang']) && preg_match('/^[a-z\\-]+$/', $_GET['lang'])) {
         if ($this->validLanguage($_GET['lang'])) {
             CoreLoader::setCookie('lang', $_GET['lang'], $cookie_lifetime);
             CoreLoader::$system['language'] = $_GET['lang'];
         } else {
             CoreLoader::setCookie('lang', CoreLoader::$system['default_language'], $cookie_lifetime);
             CoreLoader::$system['language'] = CoreLoader::$system['default_language'];
         }
     } else {
         $cookieLang = CoreInput::cookie('lang');
         if (empty($cookieLang) || !preg_match('/^[a-z\\-]+$/', $cookieLang) || !$this->validLanguage($cookieLang)) {
             // if user doesn't specify any language, check his/her browser language
             // check if the visitor language is supported
             // $this->language(true) to return the country code such as en-US zh-CN zh-TW
             $countryCode = true;
             $langcode = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
             $langcode = !empty($langcode) ? explode(';', $langcode) : $langcode;
             $langcode = !empty($langcode[0]) ? explode(',', $langcode[0]) : $langcode;
             if (!$countryCode) {
                 $langcode = !empty($langcode[0]) ? explode('-', $langcode[0]) : $langcode;
             }
             $lang = $langcode[0];
             $lang = strtolower($lang);
             if (preg_match('/^[a-z\\-]+$/', $lang) && $this->validLanguage($lang)) {
                 CoreLoader::setCookie('lang', $lang, $cookie_lifetime);
                 CoreLoader::$system['language'] = $lang;
             } else {
                 CoreLoader::setCookie('lang', CoreLoader::$system['default_language'], $cookie_lifetime);
                 CoreLoader::$system['language'] = CoreLoader::$system['default_language'];
             }
         } else {
             CoreLoader::$system['language'] = $cookieLang;
         }
     }
     #echo CoreLoader::$system['language'];
     $locale = CoreLoader::locale(CoreLoader::$system['language']);
     $langEncoding = explode('.', $locale->getLocale());
     $localeDataFile = CoreLoader::$system['language_folder'] . '/' . $langEncoding[0] . '/locale.php';
     if (file_exists($localeDataFile)) {
         CoreLocale::$LANG = (include $localeDataFile);
     }
     // ====================================
     // 初始化Smarty模板引擎
     // ====================================
     include_once FRAMEWORK_CORE_PATH . '/Smarty/Smarty.class.php';
     $smarty = new Smarty();
     $view_dir = self::$system['view_folder'];
     $cache_dir = self::$system['table_cache_folder'] . '/smarty';
     // $smarty->force_compile = true;
     $smarty->error_reporting = 9;
     //E_ALL;
     $smarty->debugging = false;
     $smarty->caching = false;
     //$smarty->use_sub_dirs = true;
     $smarty->cache_lifetime = 120;
     $smarty->left_delimiter = '<{';
     $smarty->right_delimiter = '}>';
     $smarty->allow_php_templates = true;
     $smarty->setTemplateDir($view_dir);
     $smarty->setCompileDir($cache_dir . '/templates_c/');
     $smarty->setConfigDir($cache_dir . '/configs/');
     $smarty->setCacheDir($cache_dir . '/cache/');
     $smarty->registered_cache_resources = array('phpFastCache', 'memcache');
     //$smarty->caching_type = 'phpFastCache'; //TODO: 缓存无效
     $smarty->caching_type = 'file';
     switch (phpFastCache::$storage) {
         case 'memcache':
         case 'apc':
             $smarty->caching_type = phpFastCache::$storage;
             break;
         default:
             if (function_exists('apc_cache_info')) {
                 $smarty->caching_type = 'apc';
             }
             break;
     }
     $smarty->default_resource_type = 'file';
     //模板保存方式
     // ====================================
     // 设置全局变量
     // ====================================
     $smarty->assignGlobal('TITLE', '');
     $smarty->assignGlobal('KEYWORDS', '');
     $smarty->assignGlobal('DESCRIPTION', '');
     // ====================================
     // 注册自定义函数
     // ====================================
     //$smarty->registerPlugin('function', 'burl', 'build_url');
     //<{burl param=value}> ===> function build_url(...){...}
     //$smarty->registerPlugin('modifier', 'astatus', 'audit_status');
     //<{$var|astatus}> ===> function audit_status(...){...}
     $smarty->registerPlugin('modifier', 'url', 'Fn::url');
     $this->view =& $smarty;
 }