* @since 3.0 */ class JsFunctionTemplatePlugin implements IFunctionTemplatePlugin { /** * list of already included JavaScript files * @var string[] */ protected $includedFiles = []; /** * @inheritDoc */ public function execute($tagArgs, TemplateEngine $tplObj) { // needed arguments: application and lib/file if (empty($tagArgs['application'])) { throw new SystemException("missing 'application' argument in js tag"); } if (empty($tagArgs['file']) && empty($tagArgs['lib'])) { throw new SystemException("missing 'file' or 'lib' argument in js tag"); } $isJquery = false; if ( isset($tagArgs['lib']) && ($tagArgs['lib'] === 'jquery' || $tagArgs['lib'] === 'jquery-ui') && empty($tagArgs['file']) ) { $tagArgs['bundle'] = ''; $isJquery = true; } $src = WCF::getPath($tagArgs['application']) . (isset($tagArgs['acp']) && $tagArgs['acp'] === 'true' ? 'acp/' : '') . 'js/'; if (!empty($tagArgs['bundle']) && !ENABLE_DEBUG_MODE) { $src .= $tagArgs['bundle']; } elseif (!empty($tagArgs['lib'])) { if ($isJquery) { $src .= ENABLE_DEBUG_MODE ? '3rdParty/' . $tagArgs['lib'] : 'WCF.Combined'; } else { $src .= '3rdParty/' . $tagArgs['lib']; if (!empty($tagArgs['file'])) { $src .= '/' . $tagArgs['file']; } } } else { $src .= $tagArgs['file']; } if (isset($this->includedFiles[$src])) { return ''; } $this->includedFiles[$src] = true; if (!ENABLE_DEBUG_MODE) { if ( \defined('VISITOR_USE_TINY_BUILD') && VISITOR_USE_TINY_BUILD && !WCF::getUser()->userID && !empty($tagArgs['hasTiny']) ) { $src .= '.tiny'; } $src .= '.min'; } $src .= '.js?v=' . LAST_UPDATE_TIME; $relocate = !RequestHandler::getInstance()->isACPRequest() && (!isset($tagArgs['core']) || $tagArgs['core'] !== 'true'); $html = '' . "\n"; if (isset($tagArgs['encodeJs']) && $tagArgs['encodeJs'] === 'true') { $html = StringUtil::encodeJS($html); } return $html; } }