/** * 获取合并之后的 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; }
<?php // 加载 SupplierThemePlugin 插件加载文件,用于初始化插件同时返回一个插件的 instance 对象 use Theme\Supplier\SupplierThemePlugin; SupplierThemePlugin::instance()->setPluginDirAbsolutePath(dirname(__FILE__)); return SupplierThemePlugin::instance();
/** * * 为 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; }
public function doUpdate($currentVersion) { // 简单的把版本设置为 1.0.0 就算完成升级了 SupplierThemePlugin::saveOptionValue('version', $this->targetVersion); return true; }