Example #1
0
 /**
  *
  * 为 mobile 系统设置运行环境
  *
  * @return bool
  */
 private function doMobileAction()
 {
     global $f3;
     // 获取当前插件的根地址
     $currentThemeBasePath = dirname(__FILE__);
     // 通用的加载
     $this->doOtherAction();
     // mobile 目录加入到 auto load 的路径中,这样系统就能自动做 class 加载
     SystemHelper::addAutoloadPath($currentThemeBasePath . '/mobile/Code', true);
     // 设置路由,这样用户就能访问到我们的程序了
     $f3->config($currentThemeBasePath . '/mobile/route.cfg');
     $f3->config($currentThemeBasePath . '/mobile/route-rewrite.cfg');
     // 记录用户从什么来源到达网站的
     ReferHelper::addReferItem('HostRefer', new HostRefer());
     // 记录来源的 refer_host 和 refer_url
     // 注册 Asset 模块
     \Core\Asset\ManagerHelper::registerModule(MobileThemePlugin::pluginGetUniqueId(), $this->pluginGetVersion(), $currentThemeBasePath . '/mobile/Asset');
     // 发布必要的资源文件
     \Core\Asset\ManagerHelper::publishAsset(MobileThemePlugin::pluginGetUniqueId(), 'jquery-mobile');
     \Core\Asset\ManagerHelper::publishAsset(MobileThemePlugin::pluginGetUniqueId(), 'css');
     \Core\Asset\ManagerHelper::publishAsset(MobileThemePlugin::pluginGetUniqueId(), 'js');
     \Core\Asset\ManagerHelper::publishAsset(MobileThemePlugin::pluginGetUniqueId(), 'img');
     // 增加 smarty 模板搜索路径
     global $smarty;
     $smarty->addTemplateDir($currentThemeBasePath . '/mobile/Tpl/');
     // 加载 smarty 的扩展,里面有一些我们需要用到的函数
     require_once $currentThemeBasePath . '/mobile/Code/smarty_helper.php';
     // 注册 smarty 函数
     smarty_helper_register($smarty);
     global $f3;
     // 设置网站的 Base 路径,给 JavaScript 使用
     $smarty->assign("WEB_ROOT_HOST", $f3->get('sysConfig[webroot_schema_host]'));
     $smarty->assign("WEB_ROOT_BASE", $f3->get('BASE'));
     $smarty->assign("WEB_ROOT_BASE_RES", smarty_helper_function_get_asset_url(array('asset' => ''), null));
     $smarty->assign("IS_USER_AUTH", \Core\Helper\Utility\Auth::isAuthUser());
     // jQuery Mobile 根据当前页面的 URL 来决定是否缓存,我们对某些不希望缓存的页面在这里需要特殊处理,
     // 确保它的 url 是一直变化的
     $currentPageUrl = \Core\Helper\Utility\Route::getRequestURL();
     //  下面的操作页面不要缓存,因为每次可能都不一样,比如有验证码,或者有新订单
     if (false !== strpos($currentPageUrl, '/User/') || false !== strpos($currentPageUrl, '/My/') || false !== strpos($currentPageUrl, '/Cart/')) {
         $currentPageUrl = \Core\Helper\Utility\Route::addParam($currentPageUrl, array('_no_cache_page' => time()));
     }
     $smarty->assign("CURRENT_PAGE_URL", $currentPageUrl);
     return true;
 }
Example #2
0
 /**
  * 返回当前页面的 URL ,带查询参数,包括域名
  *
  * @return string 比如 http://www.aaa.com/User/Login?username=xxx&password=xxx
  *
  * */
 public static function getFullURL()
 {
     return Route::getDomain(true) . Route::getRequestURL();
 }
Example #3
0
/**
 * 生成分页栏,用法:{{bzf_paginator count=$totalCount pageNo=$pageNo pageSize=$pageSize }}
 */
function smarty_helper_function_paginator(array $paramArray, $smarty)
{
    $count = isset($paramArray['count']) ? $paramArray['count'] : 0;
    $pageNo = isset($paramArray['pageNo']) ? $paramArray['pageNo'] : 0;
    $pageSize = isset($paramArray['pageSize']) ? $paramArray['pageSize'] : 10;
    // 不需要分页
    if ($count <= 0 || $count < $pageSize) {
        return '';
    }
    // 修正 page 的值
    $pageNo = $pageNo * $pageSize < $count ? $pageNo : 0;
    $totalPage = ceil($count / $pageSize);
    // 只有一页,不需要分页
    if ($totalPage <= 1) {
        return '';
    }
    // 处理参数
    $currentUrl = RouteHelper::getRequestURL();
    // 首页
    $paginator = '<li><a href="' . RouteHelper::addParam($currentUrl, array('pageNo' => 0), true) . '">首页</a></li>';
    // 前后各输出 5 页
    $displayPageCount = 5;
    $pageStart = $pageNo - $displayPageCount > 0 ? $pageNo - $displayPageCount : 0;
    $pageEnd = $pageNo + $displayPageCount < $totalPage ? $pageNo + $displayPageCount : $totalPage - 1;
    for ($pageIndex = $pageStart; $pageIndex <= $pageEnd; $pageIndex++) {
        $link = '';
        if (0 == $pageIndex || $totalPage - 1 == $pageIndex) {
            $link = '<a href="' . RouteHelper::addParam($currentUrl, array('pageNo' => $pageIndex), true) . '">' . ($pageIndex + 1) . '</a>';
        } else {
            if ($pageStart == $pageIndex) {
                $link = '<a href="' . RouteHelper::addParam($currentUrl, array('pageNo' => $pageIndex), true) . '">&lt;&lt;</a>';
            } else {
                if ($pageEnd == $pageIndex) {
                    $link = '<a href="' . RouteHelper::addParam($currentUrl, array('pageNo' => $pageIndex), true) . '">&gt;&gt;</a>';
                } else {
                    $link = '<a href="' . RouteHelper::addParam($currentUrl, array('pageNo' => $pageIndex), true) . '">' . ($pageIndex + 1) . '</a>';
                }
            }
        }
        if ($pageNo == $pageIndex) {
            // 当前页,active
            $paginator .= '<li class="active">' . $link . '</li>';
        } else {
            $paginator .= '<li>' . $link . '</li>';
        }
    }
    // 末页
    $paginator .= '<li><a href="' . RouteHelper::addParam($currentUrl, array('pageNo' => $totalPage - 1), true) . '">末页</a></li>';
    return '<span>(总数:' . $count . '&nbsp;&nbsp;页数:' . ($pageNo + 1) . '/' . $totalPage . ')</span><ul>' . $paginator . '</ul>';
}
Example #4
0
/**
 * 生成分页栏,用法:{{bzf_paginator count=$totalCount pageNo=$pageNo pageSize=$pageSize }}
 */
function smarty_helper_function_paginator(array $paramArray, $smarty)
{
    $count = isset($paramArray['count']) ? $paramArray['count'] : 0;
    $pageNo = isset($paramArray['pageNo']) ? $paramArray['pageNo'] : 0;
    $pageSize = isset($paramArray['pageSize']) ? $paramArray['pageSize'] : 10;
    // 不需要分页
    if ($count <= 0 || $count < $pageSize) {
        return '';
    }
    // 修正 page 的值
    $pageNo = $pageNo * $pageSize < $count ? $pageNo : 0;
    $totalPage = ceil($count / $pageSize);
    // 只有一页,不需要分页
    if ($totalPage <= 1) {
        return '';
    }
    // 处理参数
    $currentUrl = RouteHelper::getRequestURL();
    // 去除已有的 page 和 size 参数
    $currentUrl = RouteHelper::removeParam($currentUrl, 'pageNo');
    $currentUrl = RouteHelper::removeParam($currentUrl, 'pageSize');
    // 上一页
    $pagePrevious = '<a data-role="button" class="ui-disabled" data-icon="arrow-l" data-iconpos="left" href="#" data-theme="b">上一页</a>';
    if ($pageNo > 0) {
        $pagePrevious = '<a data-role="button" data-icon="arrow-l" data-iconpos="left" href="' . RouteHelper::addParam($currentUrl, array('pageNo' => $pageNo - 1), true) . '"  data-theme="b" data-direction="reverse" data-transition="flow" >上一页</a>';
    }
    // 下一页
    $pageNext = '<a data-role="button" class="ui-disabled" data-icon="arrow-r" data-iconpos="right" href="#" data-theme="b">下一页</a>';
    if ($pageNo < $totalPage - 1) {
        $pageNext = '<a data-role="button" data-icon="arrow-r" data-iconpos="right" href="' . RouteHelper::addParam($currentUrl, array('pageNo' => $pageNo + 1), true) . '"  data-theme="b" data-transition="flow">下一页</a>';
    }
    return '<div class="ui-grid-a"><div class="ui-block-a">' . $pagePrevious . '</div><div class="ui-block-b">' . $pageNext . '</div></div>';
}