init()) { self::$integrated[$name] = ['class' => $instance]; } } } protected function addJsDef($jsk, $proc) { if (!isset(self::$integrated['jsdef'])) { self::$integrated['jsdef'] = []; self::$integrated['jsloc'] = []; } self::$integrated['jsdef'][$jsk] = ['proc' => $proc]; $locator = explode(':', $jsk); $cur = &self::$integrated['jsloc']; while ($key = array_shift($locator)) { if (!empty($locator)) { $cur[$key] = []; $cur = &$cur[$key]; } else { $cur[$key] = $jsk; } } } protected function addCacheableControllers($controllers) { LiteSpeedCacheConfig::getInstance()->addExtraPubControllers($controllers); } protected function registerEsiModule() { if ($this->esiConf && ($this->esiConf instanceof LiteSpeedCacheEsiModConf)) { LiteSpeedCacheConfig::getInstance()->registerEsiModule($this->esiConf); return true; } else { if (_LITESPEED_DEBUG_ >= LSLog::LEVEL_NOTICE) { LSLog::log(__FUNCTION__ . 'something wrong', LSLog::LEVEL_NOTICE); } return false; } } protected static function filterCurrentJSKeyVal($key, &$val, &$injected, &$log) { $def = &self::$integrated['jsdef']; if (!isset($def[$key])) { return false; } if (!isset($def[$key]['replace'])) { $proc = $def[$key]['proc']; $esiParam = ['pt' => LiteSpeedCacheEsiItem::ESI_JSDEF, 'm' => $proc::NAME, 'jsk' => $key, ]; $log .= $proc::NAME . ':' . $key . ' '; $item = new LiteSpeedCacheEsiItem($esiParam, $proc->esiConf); $id = $item->getId(); $injected[$id] = $item; // replacement, hardcoded $def[$key]['replace'] = '_LSCESIJS-' . $id . '-START__LSCESIEND_'; $def[$key]['value'] = json_encode($val); // original } $val = $def[$key]['replace']; return true; } private static function locateJSKey($key, &$js, &$loc, &$injected, &$log) { if (!isset($loc[$key])) { return null; } if (is_array($loc[$key]) && is_array($js)) { $loc = &$loc[$key]; foreach ($js as $key2 => &$js2) { self::locateJSKey($key2, $js2, $loc, $injected, $log); } } else { $curkey = $loc[$key]; self::filterCurrentJSKeyVal($curkey, $js, $injected, $log); } } public static function filterJSDef(&$jsDef) { if (!isset(self::$integrated['jsloc']) || !is_array($jsDef)) { return null; } $injected = []; $log = ''; foreach ($jsDef as $key => &$js) { $loc = &self::$integrated['jsloc']; self::locateJSKey($key, $js, $loc, $injected, $log); } if ($log && _LITESPEED_DEBUG_ >= LSLog::LEVEL_ESI_INCLUDE) { LSLog::log('filter JSDef = ' . $log, LSLog::LEVEL_ESI_INCLUDE); } return $injected; } public static function processJsDef($item) { $name = $item->getParam('m'); if (isset(self::$integrated[$name])) { $key = $item->getParam('jsk'); if (isset(self::$integrated['jsdef'][$key]['value'])) { $item->setContent(self::$integrated['jsdef'][$key]['value']); return; } $proc = self::$integrated[$name]['class']; if (method_exists($proc, 'jsKeyProcess')) { $item->setContent($proc->jsKeyProcess($key)); return; } } $item->setFailed(); } public static function processModField($item) { $name = $item->getParam('m'); if (isset(self::$integrated[$name])) { $proc = self::$integrated[$name]['class']; if (method_exists($proc, 'moduleFieldProcess')) { $content = $proc->moduleFieldProcess($item->getParam()); $item->setContent($content); return; } } $item->setFailed(); } protected function addPreDispatchAction($proc) { if (!isset(self::$integrated['predispatch'])) { self::$integrated['predispatch'] = []; } self::$integrated['predispatch'][] = $proc; } public static function preDispatchAction() { if (isset(self::$integrated['predispatch'])) { foreach (self::$integrated['predispatch'] as $proc) { $proc->actionPreDispatch(); } } } protected function addCheckPurgeControllerCustomHandler($controller_class, $proc) { $c = Tools::strtolower($controller_class); if (!isset(self::$integrated['checkpurgecontroller'])) { self::$integrated['checkpurgecontroller'] = []; } if (!isset(self::$integrated['checkpurgecontroller'][$c])) { self::$integrated['checkpurgecontroller'][$c] = [$proc]; } else { self::$integrated['checkpurgecontroller'][$c][] = $proc; } } /** * * @param type $controller_class * @param type $tags = ['pub' => [], 'priv' => []]; */ public static function checkPurgeController($lowercase_controller_class, &$tags) { if (isset(self::$integrated['checkpurgecontroller'][$lowercase_controller_class])) { foreach (self::$integrated['checkpurgecontroller'][$lowercase_controller_class] as $proc) { $proc->checkPurgeControllerCustomHandler($lowercase_controller_class, $tags); } } } protected function addInitCacheTagAction($proc) { if (!isset(self::$integrated['initCacheTag'])) { self::$integrated['initCacheTag'] = []; } self::$integrated['initCacheTag'][] = $proc; } public static function initCacheTagAction($params) { if (isset(self::$integrated['initCacheTag'])) { foreach (self::$integrated['initCacheTag'] as $proc) { $tag = $proc->initCacheTagsByController($params); if ($tag !== null) { return $tag; } } } } protected function isLoggedIn() { $context = Context::getContext(); return (($context->customer != null) && $context->customer->isLogged()); } abstract protected function init(); }