Esempio n. 1
0
 public function doUpdate($currentVersion)
 {
     // 增加了新的设置选项
     MobileThemePlugin::saveOptionValue('goods_after_service', '这里是售后服务说明');
     // 设置新的版本
     MobileThemePlugin::saveOptionValue('version', $this->targetVersion);
     return true;
 }
Esempio n. 2
0
 public function get($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品id不能为空')->digits('商品id非法')->min(1, true, '商品id非法')->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 生成 smarty 的缓存 id
     $smartyCacheId = 'Goods|' . $goods_id . '|View';
     // 开启并设置 smarty 缓存时间
     enableSmartyCache(true, MobileThemePlugin::getOptionValue('smarty_cache_time_goods_view'));
     // 缓存页面
     if ($smarty->isCached('goods_view.tpl', $smartyCacheId)) {
         goto out_display;
     }
     // 查询商品信息
     $goodsBasicService = new GoodsBasicService();
     $goodsInfo = $goodsBasicService->loadGoodsById($goods_id);
     // 商品不存在,退出
     if ($goodsInfo->isEmpty() || !Utils::isTagExist(PluginHelper::SYSTEM_MOBILE, $goodsInfo['system_tag_list'])) {
         $this->addFlashMessage('商品 [' . $goods_id . '] 不存在');
         goto out_fail;
     }
     // 取商品推广信息设置
     $goodsPromote = $goodsBasicService->loadGoodsPromoteByGoodsId($goods_id);
     // 取商品图片集
     $goodsGalleryArray = GoodsGalleryCache::getGoodsGallery($goods_id);
     foreach ($goodsGalleryArray as &$galleryItem) {
         $galleryItem['img_url'] = RouteHelper::makeImageUrl($galleryItem['img_url']);
         $galleryItem['thumb_url'] = RouteHelper::makeImageUrl($galleryItem['thumb_url']);
     }
     unset($galleryItem);
     // 设置商品页面的 SEO 信息
     $smarty->assign('seo_title', $goodsInfo['seo_title'] . ',' . $f3->get('sysConfig[site_name]'));
     $smarty->assign('seo_description', $goodsInfo['seo_description']);
     $smarty->assign('seo_keywords', $goodsInfo['seo_keyword']);
     // 给模板赋值
     $smarty->assign('goodsInfo', $goodsInfo);
     $smarty->assign('goodsPromote', $goodsPromote);
     if (!Utils::isEmpty($goodsGalleryArray)) {
         $smarty->assign('goodsGalleryArray', $goodsGalleryArray);
     }
     // 设置商品规格
     if (!empty($goodsInfo['goods_spec'])) {
         $goodsSpecService = new GoodsSpecService();
         $goodsSpecService->initWithJson($goodsInfo['goods_spec']);
         $smarty->assign('goodsSpec', $goodsSpecService->getGoodsSpecDataArray());
     }
     out_display:
     $smarty->display('goods_view.tpl', $smartyCacheId);
     return;
     out_fail:
     // 失败从这里返回
     RouteHelper::reRoute($this, '/');
     // 返回首页
 }
Esempio n. 3
0
 public function doUpdate($currentVersion)
 {
     // 删除旧的设置,由于 JQuery Mobile 本身的特性,不适合用传统的统计代码来做统计
     MobileThemePlugin::removeOptionValue('statistics_code');
     // 新的统计设置选项
     // Google Analytics 的 UA 设置
     MobileThemePlugin::saveOptionValue('google_analytics_ua', '');
     // 设置新的版本
     MobileThemePlugin::saveOptionValue('version', $this->targetVersion);
     return true;
 }
Esempio n. 4
0
 public function doUpdate($currentVersion)
 {
     // 获得插件的配置 (config.php 里面的信息)
     $configArray = MobileThemePlugin::$instance->loadConfigFile();
     // 删除 smarty_cache_time_goods_category 设置
     MobileThemePlugin::removeOptionValue('smarty_cache_time_goods_category');
     // 添加一个新的设置
     MobileThemePlugin::saveOptionValue('smarty_cache_time_goods_search', $configArray['smarty_cache_time_goods_search']);
     // 升级版本信息
     MobileThemePlugin::saveOptionValue('version', $this->targetVersion);
     return true;
 }
Esempio n. 5
0
 public function get($f3)
 {
     global $smarty;
     // 生成 smarty 的缓存 id
     $smartyCacheId = 'Cache|Page';
     enableSmartyCache(true, MobileThemePlugin::getOptionValue('smarty_cache_time_cache_page'));
     // 缓存页面
     if ($smarty->isCached('cache_page.tpl', $smartyCacheId)) {
         goto out_display;
     }
     out_display:
     $smarty->display('cache_page.tpl', $smartyCacheId);
 }
Esempio n. 6
0
 public function beforeRoute($f3)
 {
     parent::beforeRoute($f3);
     //设置 SEO 信息
     global $smarty;
     $smarty->assign('seo_title', MobileThemePlugin::getOptionValue('seo_title'));
     $smarty->assign('seo_description', MobileThemePlugin::getOptionValue('seo_description'));
     $smarty->assign('seo_keywords', MobileThemePlugin::getOptionValue('seo_keywords'));
     // 设置页面显示用户名
     if (AuthHelper::isAuthUser()) {
         global $smarty;
         $authUser = AuthHelper::getAuthUser();
         $smarty->assign('USER_NAME_DISPLAY', $authUser['user_name']);
     }
     // 记录用户从什么来源到达网站的
     ReferHelper::setOrderRefer($f3);
     //设置 order_refer 信息
 }
Esempio n. 7
0
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_plugin_theme_configure');
     // 参数验证
     $validator = new Validator($f3->get('POST'));
     foreach ($this->optionKeyArray as $optionKey) {
         if (in_array($optionKey, $this->optionKeyNoFilterArray)) {
             $optionValue = $f3->get('POST[' . $optionKey . ']');
         } else {
             $optionValue = $validator->validate($optionKey);
         }
         MobileThemePlugin::saveOptionValue($optionKey, $optionValue);
     }
     // 清除所有缓存
     $cacheClear = new MobileClear();
     $cacheClear->clearAllCache();
     $this->addFlashMessage('保存设置成功');
     out_display:
     global $smarty;
     $smarty->display('theme_mobile_configure.tpl', 'post');
 }
Esempio n. 8
0
 public function get($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits('pageNo 参数非法')->min(0, true, 'pageNo 参数非法')->validate('pageNo');
     // 搜索参数数组
     $searchFormQuery = array();
     $searchFormQuery['category_id'] = $validator->digits('分类id非法')->min(1, true, '分类id非法')->filter('ValidatorIntValue')->validate('category_id');
     $searchFormQuery['suppliers_id'] = $validator->digits('供货商id非法')->min(1, true, '供货商id非法')->filter('ValidatorIntValue')->validate('suppliers_id');
     $searchFormQuery['goods_name'] = $validator->validate('goods_name');
     // 价格区间查询
     $shopPriceMin = $validator->filter('ValidatorFloatValue')->validate('shop_price_min');
     $shopPriceMax = $validator->filter('ValidatorFloatValue')->validate('shop_price_max');
     $searchFormQuery['shop_price'] = array($shopPriceMin, $shopPriceMax);
     // 排序
     $orderBy = $validator->oneOf(array('', 'total_buy_number', 'shop_price', 'add_time'))->validate('orderBy');
     $orderDir = $validator->oneOf(array('', 'asc', 'desc'))->validate('orderDir');
     $orderByParam = array();
     if (!empty($orderBy)) {
         $orderByParam = array(array($orderBy, $orderDir));
     }
     //增加一些我们的缺省排序
     $orderByParam[] = array('sort_order', 'desc');
     $orderByParam[] = array('goods_id', 'desc');
     // 参数验证
     if (!$this->validate($validator) || empty($searchFormQuery)) {
         goto out_fail;
     }
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = 10;
     // 每页固定显示 10 个商品
     // 生成 smarty 的缓存 id
     $smartyCacheId = 'Goods|Search|' . md5(json_encode($searchFormQuery) . json_encode($orderByParam) . '_' . $pageNo . '_' . $pageSize);
     // 开启并设置 smarty 缓存时间
     enableSmartyCache(true, MobileThemePlugin::getOptionValue('smarty_cache_time_goods_search'));
     if ($smarty->isCached('goods_search.tpl', $smartyCacheId)) {
         goto out_display;
     }
     // 合并查询参数
     $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray);
     $totalCount = SearchHelper::count(SearchHelper::Module_Goods, $searchParamArray);
     if ($totalCount <= 0) {
         goto out_display;
         // 没有商品,直接显示
     }
     // 页号可能是用户乱输入的,我们需要检查
     if ($pageNo * $pageSize >= $totalCount) {
         goto out_fail;
         // 返回首页
     }
     $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, $this->searchFieldSelector, $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize);
     if (empty($goodsArray)) {
         goto out_display;
     }
     // 取得 商品ID 列表
     $goodsIdArray = array();
     foreach ($goodsArray as $goodsItem) {
         $goodsIdArray[] = $goodsItem['goods_id'];
     }
     // 取得商品的图片
     $goodsGalleryService = new GoodsGalleryService();
     $goodsGalleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsIdArray($goodsIdArray);
     $currentGoodsId = -1;
     $goodsThumbImageArray = array();
     $goodsImageArray = array();
     foreach ($goodsGalleryArray as $goodsGalleryItem) {
         if ($currentGoodsId == $goodsGalleryItem['goods_id']) {
             continue;
             //每个商品我们只需要一张图片,跳过其它的图片
         }
         $currentGoodsId = $goodsGalleryItem['goods_id'];
         // 新的商品 id
         $goodsThumbImageArray[$currentGoodsId] = RouteHelper::makeImageUrl($goodsGalleryItem['thumb_url']);
         $goodsImageArray[$currentGoodsId] = RouteHelper::makeImageUrl($goodsGalleryItem['img_url']);
     }
     // 赋值给模板
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('goodsArray', $goodsArray);
     $smarty->assign('goodsThumbImageArray', $goodsThumbImageArray);
     $smarty->assign('goodsImageArray', $goodsImageArray);
     out_display:
     $smarty->display('goods_search.tpl', $smartyCacheId);
     return;
     out_fail:
     // 失败从这里返回
     RouteHelper::reRoute($this, '/');
     // 返回首页
 }
Esempio n. 9
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;
 }
Esempio n. 10
0
 public function doUpdate($currentVersion)
 {
     // 简单的把版本设置为 1.0.0 就算完成升级了
     MobileThemePlugin::saveOptionValue('version', $this->targetVersion);
     return true;
 }
Esempio n. 11
0
 public function get($f3)
 {
     global $smarty;
     // 生成 smarty 的缓存 id
     $smartyCacheId = 'Mobile|Index';
     // 开启并设置 smarty 缓存时间
     enableSmartyCache(true, MobileThemePlugin::getOptionValue('smarty_cache_time_goods_index'));
     // 缓存页面
     if ($smarty->isCached('mobile_index.tpl', $smartyCacheId)) {
         goto out_display;
     }
     $categoryLevel = 3;
     // 取得分类下面 3 层的商品
     $categoryGoodsSzie = 4;
     // 每个分类下面取 4 个商品
     // 取得分类列表
     $categoryService = new CategoryService();
     $categoryArray = $categoryService->fetchCategoryArray(0);
     //取得分类
     // 取得商品列表
     $categoryGoodsArray = array();
     $goodsIdArray = array();
     foreach ($categoryArray as $category) {
         // 分类下面 3 层子分类, 取 4 个商品
         $goodsArray = $categoryService->fetchGoodsArray($category['meta_id'], $categoryLevel, PluginHelper::SYSTEM_MOBILE, 0, $categoryGoodsSzie);
         if (!empty($goodsArray)) {
             $categoryGoodsArray[$category['meta_id']] = $goodsArray;
             foreach ($goodsArray as $goodsItem) {
                 $goodsIdArray[] = $goodsItem['goods_id'];
             }
         }
     }
     // 网站完全没有商品? 不缓存
     if (empty($goodsIdArray)) {
         goto out_display;
     }
     // 取得商品的图片
     $goodsGalleryService = new GoodsGalleryService();
     $goodsGalleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsIdArray($goodsIdArray);
     $currentGoodsId = -1;
     $goodsThumbImageArray = array();
     $goodsImageArray = array();
     foreach ($goodsGalleryArray as $goodsGalleryItem) {
         if ($currentGoodsId == $goodsGalleryItem['goods_id']) {
             continue;
             //每个商品我们只需要一张图片,跳过其它的图片
         }
         $currentGoodsId = $goodsGalleryItem['goods_id'];
         // 新的商品 id
         $goodsThumbImageArray[$currentGoodsId] = RouteHelper::makeImageUrl($goodsGalleryItem['thumb_url']);
         $goodsImageArray[$currentGoodsId] = RouteHelper::makeImageUrl($goodsGalleryItem['img_url']);
     }
     // 赋值给模板
     $smarty->assign('categoryArray', $categoryArray);
     $smarty->assign('categoryGoodsArray', $categoryGoodsArray);
     $smarty->assign('goodsThumbImageArray', $goodsThumbImageArray);
     $smarty->assign('goodsImageArray', $goodsImageArray);
     out_display:
     $smarty->assign('seo_title', $smarty->getTemplateVars('seo_title') . ',' . $f3->get('HOST'));
     $smarty->display('mobile_index.tpl', $smartyCacheId);
 }
Esempio n. 12
0
<?php

// 加载 MobileThemePlugin  插件加载文件,用于初始化插件同时返回一个插件的 instance 对象
use Theme\Mobile\MobileThemePlugin;
MobileThemePlugin::instance()->setPluginDirAbsolutePath(dirname(__FILE__));
return MobileThemePlugin::instance();
Esempio n. 13
0
/**
 * 获取合并之后的 JS 文件
 *
 * @param array $paramArray
 * @param       $smarty
 *
 * @return string
 */
function smarty_helper_function_dump_merged_asset_js_url(array $paramArray, $smarty)
{
    if (!isset($paramArray['asset'])) {
        return '';
    }
    global $f3;
    $merge = $f3->get('sysConfig[enable_asset_merge]');
    if (isset($paramArray['merge'])) {
        $merge = $paramArray['merge'];
    }
    $fileRelativeNameArray = explode(',', preg_replace('![\\r\\n\\s\\t]+!', '', $paramArray['asset']));
    if (empty($fileRelativeNameArray)) {
        return '';
    }
    $outputStr = '';
    if (!$merge) {
        foreach ($fileRelativeNameArray as $relativeAssetPath) {
            $outputStr .= '<script type="text/javascript" src="' . \Core\Asset\ManagerHelper::getAssetUrl(\Theme\Mobile\MobileThemePlugin::pluginGetUniqueId(), $relativeAssetPath) . '"></script>' . "\n";
        }
    } else {
        // 合并文件
        $outputStr = '<script type="text/javascript" src="' . \Core\Asset\ManagerHelper::getMergedAssetJsUrl(\Theme\Mobile\MobileThemePlugin::pluginGetUniqueId(), $fileRelativeNameArray) . '"></script>';
    }
    return $outputStr;
}