function theme_shop_smarty_helper_function_get_asset_url(array $paramArray, $smarty) { if (!isset($paramArray['asset'])) { return ''; } return ManagerHelper::getAssetUrl(ShopThemePlugin::pluginGetUniqueId(), $paramArray['asset']); }
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(); }
/** * 获取合并之后的 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\Shop\ShopThemePlugin::pluginGetUniqueId(), $relativeAssetPath) . '"></script>' . "\n"; } } else { // 合并文件 $outputStr = '<script type="text/javascript" src="' . \Core\Asset\ManagerHelper::getMergedAssetJsUrl(\Theme\Shop\ShopThemePlugin::pluginGetUniqueId(), $fileRelativeNameArray) . '"></script>'; } return $outputStr; }
/** * * 为 shop 系统设置运行环境 * * @return bool */ private function doShopAction() { global $f3; global $smarty; // 获取当前插件的根地址 $currentThemeBasePath = dirname(__FILE__); // 通用的加载 $this->doOtherAction(); // shop Code 目录加入到 auto load 的路径中,这样系统就能自动做 class 加载 SystemHelper::addAutoloadPath($currentThemeBasePath . '/shop/Code', true); // 设置路由,这样用户就能访问到我们的程序了 $f3->config($currentThemeBasePath . '/shop/route.cfg'); $f3->config($currentThemeBasePath . '/shop/route-rewrite.cfg'); ReferHelper::addReferItem('HostRefer', new HostRefer()); // 记录来源的 refer_host 和 refer_url // 注册 Asset 模块 \Core\Asset\ManagerHelper::registerModule(ShopThemePlugin::pluginGetUniqueId(), $this->pluginGetVersion(), $currentThemeBasePath . '/shop/Asset'); // 发布必要的资源文件 \Core\Asset\ManagerHelper::publishAsset(ShopThemePlugin::pluginGetUniqueId(), 'bootstrap-custom'); \Core\Asset\ManagerHelper::publishAsset(ShopThemePlugin::pluginGetUniqueId(), 'css'); \Core\Asset\ManagerHelper::publishAsset(ShopThemePlugin::pluginGetUniqueId(), 'js'); \Core\Asset\ManagerHelper::publishAsset(ShopThemePlugin::pluginGetUniqueId(), 'img'); // 增加 smarty 模板搜索路径 $smarty->addTemplateDir($currentThemeBasePath . '/shop/Tpl/'); // 加载 smarty 的扩展,里面有一些我们需要用到的函数 require_once $currentThemeBasePath . '/shop/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; }