addPreDispatchAction($this); $this->addCacheableControllers($this->getPubControllers()); $this->addInitCacheTagAction($this); return true; } protected function getPubControllers() { return [ 'pk_amphomeModuleFrontController' => LiteSpeedCacheConfig::TAG_HOME, // controller name - tag linked to it 'pk_ampproductController' => '', 'pk_ampproductModuleFrontController' => '', 'pk_ampcategoryModuleFrontController' => '', 'pk_ampcmsModuleFrontController' => '', 'pk_ampmanufacturerModuleFrontController' => '', 'pk_ampsupplierModuleFrontController' => '', 'pk_ampsearchModuleFrontController' => LiteSpeedCacheConfig::TAG_SEARCH, 'pk_ampbestsalesModuleFrontController' => LiteSpeedCacheConfig::TAG_SEARCH, 'pk_ampnewProductsModuleFrontController' => LiteSpeedCacheConfig::TAG_SEARCH, 'pk_amppricesdropModuleFrontController' => LiteSpeedCacheConfig::TAG_SEARCH, 'pk_ampsitemapModuleFrontController' => LiteSpeedCacheConfig::TAG_SITEMAP, 'pk_ampstoresModuleFrontController' => LiteSpeedCacheConfig::TAG_STORES, 'pk_amp404ModuleFrontController' => LiteSpeedCacheConfig::TAG_404, ]; } protected function actionPreDispatch() { $mtb = ''; $context = Context::getContext(); $mtb .= $context->isMobile() ? '1' : '0'; $mtb .= $context->isTablet() ? '1' : '0'; //$isbot = Module::getInstanceByName(self::NAME)->is_bot(); $isbot = $this->is_bot(); $mtb .= $isbot ? '1' : '0'; if (_LITESPEED_DEBUG_ >= LSLog::LEVEL_ENVCOOKIE_DETAIL) { LSLog::log(__FUNCTION__ . 'LscPkAmp setAmpVary=' . $mtb, LSLog::LEVEL_ENVCOOKIE_DETAIL); } LiteSpeedCacheVaryCookie::setAmpVary($mtb); } /* Please make sure this function is exactly same as Pk_Amp->is_bot(). * If mismatch, it will cache wrong copy */ public function is_bot() { $bots = array( 'Googlebot', 'Baiduspider', 'ia_archiver', 'R6_FeedFetcher', 'NetcraftSurveyAgent', 'Sogou web spider', 'bingbot', 'Yahoo! Slurp', 'facebookexternalhit', 'PrintfulBot', 'msnbot', 'Twitterbot', 'UnwindFetchor', 'urlresolver', 'Butterfly', 'TweetmemeBot'); foreach($bots as $b){ if( stripos( $_SERVER['HTTP_USER_AGENT'], $b ) !== false ) return true; } return false; } protected function initCacheTagsByController($params) { $controller = $params['controller']; $pagename = $controller->getPageName(); if (strpos($pagename, 'module-pk_amp-') === false) { return null; } $pagename = substr($pagename, 14); switch ($pagename) { case 'category': $id = Tools::getValue('id_category'); if ($id) { return Conf::TAG_PREFIX_CATEGORY . $id; } break; case 'manufacturer': $id = Tools::getValue('id_manufacturer'); if ($id) { return Conf::TAG_PREFIX_MANUFACTURER . $id; } break; case 'supplier': $id = Tools::getValue('id_supplier'); if ($id) { $tag = Conf::TAG_PREFIX_SUPPLIER . $id; } break; case 'cms': $id = Tools::getValue('id_cms'); if ($id) { return Conf::TAG_PREFIX_CMS . $id; } break; } return null; } } LscPkAmp::register();