Example #1
0
function theme_shop_smarty_helper_function_get_asset_url(array $paramArray, $smarty)
{
    if (!isset($paramArray['asset'])) {
        return '';
    }
    return ManagerHelper::getAssetUrl(ShopThemePlugin::pluginGetUniqueId(), $paramArray['asset']);
}
Example #2
0
 public function beforeRoute($f3)
 {
     parent::beforeRoute($f3);
     // 发布我们自己的资源
     ManagerHelper::publishAsset(ShopThemePlugin::pluginGetUniqueId(), 'css');
     ManagerHelper::publishAsset(ShopThemePlugin::pluginGetUniqueId(), 'js');
     ManagerHelper::publishAsset(ShopThemePlugin::pluginGetUniqueId(), 'img');
     // 插件注册 css, js
     ManagerHelper::registerCss(ManagerHelper::getAssetUrl(ShopThemePlugin::pluginGetUniqueId(), 'css/theme_shop.css'));
     ManagerHelper::registerCss(ManagerHelper::getAssetUrl(ShopThemePlugin::pluginGetUniqueId(), 'css/advblock.css'));
     ManagerHelper::registerJs(ManagerHelper::getAssetUrl(ShopThemePlugin::pluginGetUniqueId(), 'js/theme_shop.js'));
     // 注册自己使用的 smarty 函数
     theme_shop_smarty_register();
 }
Example #3
0
 private function initWebEnv($system)
 {
     global $f3;
     global $smarty;
     $systemUpperFirst = ucfirst($system);
     $saeStorage = new \SaeStorage();
     // -------------------- 1. 设置 data 路径 --------------------------------------
     // 当前网站的 webroot_schema_host
     if (!$f3->get('sysConfig[webroot_schema_host]')) {
         $f3->set('sysConfig[webroot_schema_host]', $f3->get('SCHEME') . '://' . $f3->get('HOST') . ('80' != $f3->get('PORT') ? ':' . $f3->get('PORT') : ''));
     }
     // 当前网站的 webroot_url_prefix
     if (!$f3->get('sysConfig[webroot_url_prefix]')) {
         $f3->set('sysConfig[webroot_url_prefix]', $f3->get('sysConfig[webroot_schema_host]') . $f3->get('BASE'));
     }
     //数据路径
     $f3->set('sysConfig[data_path_root]', $f3->get('sysConfig[sae_storage_data_path]'));
     $f3->set('sysConfig[data_url_prefix]', rtrim($saeStorage->getUrl($f3->get('sysConfig[sae_storage_data_domain]'), ''), '/'));
     //图片 image_url_prefix
     if (!$f3->get('sysConfig[image_url_prefix]')) {
         $f3->set('sysConfig[image_url_prefix]', $f3->get('sysConfig[data_url_prefix]'));
     }
     // -------------------- 2. 设置 runtime 路径 --------------------------------------
     // RunTime 路径
     $f3->set('sysConfig[runtime_path]', $f3->get('sysConfig[sae_runtime]'));
     define('RUNTIME_PATH', $f3->get('sysConfig[runtime_path]'));
     // 设置 Tmp 路径
     $f3->set('TEMP', RUNTIME_PATH . '/Temp/');
     // 设置 Log 路径
     $f3->set('LOGS', RUNTIME_PATH . '/Log/' . $systemUpperFirst . '/');
     //Sae 禁止 Cache 功能
     $f3->set('CACHE', false);
     // -------------------- 3. 设置 Smarty --------------------------------------
     //设置 smarty 工作目录
     $smarty->setCompileDir(RUNTIME_PATH . '/Smarty');
     $smarty->setCacheDir(RUNTIME_PATH . '/Smarty');
     $smarty->compile_locking = false;
     //smarty 在 SAE 下禁用缓存
     $f3->set('sysConfig[smarty_caching]', false);
     // smarty 会对生成的模板文件做一个 chmod 操作,这个操作会导致 Sae 报错
     $smarty->_file_perms = null;
     // -------------------- 4. 设置 Asset 管理 --------------------------------------
     // 关闭系统的 asset 合并功能
     $f3->set('sysConfig[enable_asset_merge]', false);
     // 我们使用 Sae 专用的 AssetManager
     SaeAssetManager::instance($system);
     \Core\Asset\ManagerHelper::setAssetManager(SaeAssetManager::instance());
 }
Example #4
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 #5
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\Supplier\SupplierThemePlugin::pluginGetUniqueId(), $relativeAssetPath) . '"></script>' . "\n";
        }
    } else {
        // 合并文件
        $outputStr = '<script type="text/javascript" src="' . \Core\Asset\ManagerHelper::getMergedAssetJsUrl(\Theme\Supplier\SupplierThemePlugin::pluginGetUniqueId(), $fileRelativeNameArray) . '"></script>';
    }
    return $outputStr;
}
Example #6
0
 private function initWebEnv($system)
 {
     global $f3;
     global $smarty;
     // 预先加载一些模块,提高后面的加载效率
     require_once PROTECTED_PATH . '/Core/Asset/SimpleManager.php';
     $systemUpperFirst = ucfirst($system);
     $sysPath = '';
     $sysDir = '';
     switch ($system) {
         case PluginHelper::SYSTEM_SHOP:
             $sysPath = SHOP_PATH;
             $sysDir = SHOP_DIR;
             break;
         case PluginHelper::SYSTEM_AIMEIDAREN:
             $sysPath = AIMEIDAREN_PATH;
             $sysDir = AIMEIDAREN_DIR;
             break;
         case PluginHelper::SYSTEM_GROUPON:
             $sysPath = GROUPON_PATH;
             $sysDir = GROUPON_DIR;
             break;
         case PluginHelper::SYSTEM_MOBILE:
             $sysPath = MOBILE_PATH;
             $sysDir = MOBILE_DIR;
             break;
         case PluginHelper::SYSTEM_MANAGE:
             $sysPath = MANAGE_PATH;
             $sysDir = MANAGE_DIR;
             break;
         case PluginHelper::SYSTEM_SUPPLIER:
             $sysPath = SUPPLIER_PATH;
             $sysDir = SUPPLIER_DIR;
             break;
         case PluginHelper::SYSTEM_INSTALL:
             $sysPath = INSTALL_PATH;
             $sysDir = INSTALL_DIR;
             // install use tmp directory for cache
             $f3->set('sysConfig[cache]', 'folder=' . sys_get_temp_dir());
             break;
         default:
             throw new \InvalidArgumentException('can not init for system [' . $system . ']');
     }
     // -------------------- 1. 设置 data 路径 --------------------------------------
     // 当前网站的 webroot_schema_host
     if (!$f3->get('sysConfig[webroot_schema_host]')) {
         $f3->set('sysConfig[webroot_schema_host]', $f3->get('SCHEME') . '://' . $f3->get('HOST') . ('80' != $f3->get('PORT') ? ':' . $f3->get('PORT') : ''));
     }
     // 当前网站的 webroot_url_prefix
     if (!$f3->get('sysConfig[webroot_url_prefix]')) {
         $f3->set('sysConfig[webroot_url_prefix]', $f3->get('sysConfig[webroot_schema_host]') . $f3->get('BASE'));
     }
     // 没有自己的目录,比如把 shop 放在根目录了
     if (empty($sysDir)) {
         //数据路径
         if (!$f3->get('sysConfig[data_path_root]')) {
             $f3->set('sysConfig[data_path_root]', realpath($sysPath . '/data'));
         }
         //数据 url prefix
         if (!$f3->get('sysConfig[data_url_prefix]')) {
             $f3->set('sysConfig[data_url_prefix]', $f3->get('sysConfig[webroot_url_prefix]') . '/data');
         }
     } else {
         //数据路径
         if (!$f3->get('sysConfig[data_path_root]')) {
             $f3->set('sysConfig[data_path_root]', realpath($sysPath . '/../data'));
         }
         //数据 url prefix
         if (!$f3->get('sysConfig[data_url_prefix]')) {
             $f3->set('sysConfig[data_url_prefix]', str_replace('/' . $sysDir, '/data', $f3->get('sysConfig[webroot_url_prefix]')));
         }
     }
     //图片 image_url_prefix
     if (!$f3->get('sysConfig[image_url_prefix]')) {
         $f3->set('sysConfig[image_url_prefix]', $f3->get('sysConfig[data_url_prefix]'));
     }
     // -------------------- 2. 设置 runtime 路径 --------------------------------------
     // RunTime 路径
     if (!$f3->get('sysConfig[runtime_path]')) {
         $f3->set('sysConfig[runtime_path]', realpath(PROTECTED_PATH . '/Runtime'));
     }
     define('RUNTIME_PATH', $f3->get('sysConfig[runtime_path]'));
     // 设置 Tmp 路径
     $f3->set('TEMP', RUNTIME_PATH . '/Temp/');
     // 设置 Log 路径
     $f3->set('LOGS', RUNTIME_PATH . '/Log/' . $systemUpperFirst . '/');
     //开启 Cache 功能
     if ($f3->get('sysConfig[cache]')) {
         $f3->set('CACHE', $f3->get('sysConfig[cache]'));
     } else {
         // 让 F3 自动选择使用最优的 Cache 方案,最差的情况会使用 TEMP/cache 目录文件做缓存
         $f3->set('CACHE', 'true');
     }
     // -------------------- 3. 设置 Smarty --------------------------------------
     // 初始化 smarty 模板引擎
     $smarty->debugging = $f3->get('sysConfig[smarty_debug]');
     $smarty->force_compile = $f3->get('sysConfig[smarty_force_compile]');
     $smarty->use_sub_dirs = $f3->get('sysConfig[smarty_use_sub_dirs]');
     //设置 smarty 工作目录
     $smarty->setCompileDir(RUNTIME_PATH . '/Smarty/' . $systemUpperFirst . '/Compile');
     $smarty->setCacheDir(RUNTIME_PATH . '/Smarty/' . $systemUpperFirst . '/Cache');
     // -------------------- 4. 设置 Asset 管理 --------------------------------------
     // asset 路径,用于发布 css, js , 图片 等
     if (!$f3->get('sysConfig[asset_path_root]')) {
         $f3->set('sysConfig[asset_path_root]', realpath($sysPath . '/asset'));
     }
     if (!$f3->get('sysConfig[asset_path_url_prefix]')) {
         $f3->set('sysConfig[asset_path_url_prefix]', $f3->get('sysConfig[webroot_url_prefix]') . '/asset');
     }
     \Core\Asset\SimpleManager::instance($f3->get('sysConfig[asset_path_url_prefix]'), $f3->get('sysConfig[asset_path_root]'));
     // 开启 asset 智能重新发布功能
     \Core\Asset\SimpleManager::instance()->enableSmartPublish($f3->get('sysConfig[enable_asset_smart_publish]'));
     // asset 文件 url 开启 hash,文件名采用 时间戳.文件名 的方式
     \Core\Asset\SimpleManager::instance()->enableFileHashUrl($f3->get('sysConfig[enable_asset_hash_url]'), $f3->get('sysConfig[enable_asset_hash_name]'));
     \Core\Asset\ManagerHelper::setAssetManager(\Core\Asset\SimpleManager::instance());
 }
Example #7
0
 /**
  *
  * 为 supplier 系统设置运行环境
  *
  * @return bool
  */
 private function doSupplierAction()
 {
     global $f3;
     global $smarty;
     // 获取当前插件的根地址
     $currentThemeBasePath = dirname(__FILE__);
     // supplier 目录加入到 auto load 的路径中,这样系统就能自动做 class 加载
     SystemHelper::addAutoloadPath($currentThemeBasePath . '/supplier/Code', true);
     // 设置路由,这样用户就能访问到我们的程序了
     $f3->config($currentThemeBasePath . '/supplier/route.cfg');
     // 注册 Asset 模块
     \Core\Asset\ManagerHelper::registerModule(SupplierThemePlugin::pluginGetUniqueId(), $this->pluginGetVersion(), $currentThemeBasePath . '/supplier/Asset');
     // 发布必要的资源文件
     \Core\Asset\ManagerHelper::publishAsset(SupplierThemePlugin::pluginGetUniqueId(), 'bootstrap-custom');
     \Core\Asset\ManagerHelper::publishAsset(SupplierThemePlugin::pluginGetUniqueId(), 'css');
     \Core\Asset\ManagerHelper::publishAsset(SupplierThemePlugin::pluginGetUniqueId(), 'img');
     \Core\Asset\ManagerHelper::publishAsset(SupplierThemePlugin::pluginGetUniqueId(), 'js');
     // 增加 smarty 模板搜索路径
     $smarty->addTemplateDir($currentThemeBasePath . '/supplier/Tpl/');
     // 加载 smarty 的扩展,里面有一些我们需要用到的函数
     require_once $currentThemeBasePath . '/supplier/Code/smarty_helper.php';
     // 注册 smarty 函数
     smarty_helper_register($smarty);
     // 设置网站的 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));
     return true;
 }
Example #8
0
/**
 * dump 出所有插件注册的 js 文件
 *
 * @param array $paramArray
 * @param       $smarty
 */
function smarty_helper_function_dump_register_js(array $paramArray, $smarty)
{
    $jsArray = \Core\Asset\ManagerHelper::getRegisterJsArray();
    if (empty($jsArray)) {
        return '';
    }
    $jsHtml = '';
    foreach ($jsArray as $jsItem) {
        $jsHtml .= '<script type="text/javascript" src="' . $jsItem . '"></script>';
    }
    return $jsHtml;
}