conf = $conf; if (!$this->conf->isPrivate($param)) { // make diff esi url if a block under vary condition, can be either public or private $param['pub'] = 1; } $this->sdata = [ 'id' => json_encode($param), 'param' => $param, 'url' => '', 'inc' => false, 'inlStart' => false, 'shared' => null, 'tag' => implode(',', $conf->getTags()), // use default conf tags, cannot use this, not ready yet ]; $this->cdata = [ 'inlStart' => false, ]; } public function getInfoLog($simple = false) { $params = implode('|', $this->sdata['param']); if ($simple) { return $params; } else { return $this->sdata['id'] . ': ' . $params . ' ' . $this->err; } } public static function newFromSavedData($sdata) { $conf = LiteSpeedCacheConfig::getInstance()->getEsiModuleConf($sdata['param']['m']); if ($conf == null) { return null; } $item = new self($sdata['param'], $conf); $item->sdata = $sdata; $item->cdata['inlStart'] = $sdata['inlStart']; return $item; } public function getSavedData() { return $this->sdata; } public function getId() { return $this->sdata['id']; } public function getInclude() { return $this->sdata['inc']; } public function getInline() { return $this->esiInline; } public function setIncludeInlineTag($esiInclude, $inlineStart, $url, $ttl) { $this->cdata['inlStart'] = $inlineStart; if ($ttl > 0) { $this->sdata['inlStart'] = $inlineStart; } $this->sdata['inc'] = $esiInclude; $this->sdata['url'] = $url; } public function getConf() { return $this->conf; } /** * comma delimited string */ public function getTagString($prefix) { $tags = $this->getTags(); $s = ''; foreach ($tags as $tag) { if (strpos($tag, 'public:') !== false) { $s .= 'public:' . $prefix . substr($tag, 7) . ','; } else { $s .= $prefix . $tag . ','; } } return rtrim($s, ','); } public function getTags() { return $this->conf->getTags($this->sdata['param']); } public function getTTL() { return $this->conf->getTTL($this->sdata['param']); } public function isPrivate() { return $this->conf->isPrivate($this->sdata['param']); } public function onlyCacheEmtpy() { return $this->conf->onlyCacheEmtpy($this->sdata['param']); } public function ignoreEmptyContent() { return $this->conf->ignoreEmptyContent($this->sdata['param']); } public function asVar() { return $this->conf->asVar($this->sdata['param']); } public function noItemCache() { return $this->conf->getNoItemCache($this->sdata['param']); } public function getParam($key = '') { if ($key == '') { return $this->sdata['param']; } elseif (!isset($this->sdata['param'][$key])) { return null; } else { return $this->sdata['param'][$key]; } } public function getContent() { return $this->content; } public function setContent($content) { $this->content = trim($content); if ($this->sdata['inlStart'] == false || $this->onlyCacheEmtpy()) { // can vary, always regenerate if ($this->content === '' && $this->ignoreEmptyContent()) { $this->sdata['inc'] = ''; return; } LSHelper::genEsiElements($this); } $this->esiInline = $this->cdata['inlStart'] . $this->content . ''; } public function setFailed($err = '') { $this->content = self::RES_FAILED; $this->err = $err; } public function preRenderWidget() { $p = $this->sdata['param']; unset($p['pt']); unset($p['m']); unset($p['h']); foreach ($p as $k => $v) { $_GET[$k] = $v; // restore extra GET param } } public static function decodeEsiUrl() { $err = $pd = $param = $conf = null; if (($pd = Tools::getValue('pd')) == null) { $err = 'missing pd'; } elseif (($param = json_decode($pd, true)) == null) { $err = 'invalid format in pd'; } elseif (!isset($param['pt'])) { $err = 'missing pt'; } elseif (!isset($param['m'])) { $err = 'missing m'; } elseif (($conf = LiteSpeedCacheConfig::getInstance()->getEsiModuleConf($param['m'])) == null) { $err = $param['m'] . ' is not found'; } else { switch ($param['pt']) { case self::ESI_TOKEN: case self::ESI_ENV: break; case self::ESI_JSDEF: if (!isset($param['jsk'])) { $err = 'missing jsk'; } break; case self::ESI_RENDERWIDGET: if (!isset($param['h'])) { $err = 'missing h'; } break; case self::ESI_CALLHOOK: if (!isset($param['mt'])) { $err = 'missing mt'; } break; case self::ESI_SMARTYFIELD: if (!isset($param['f']) || $param['f'] == '') { $err = 'missing f'; } elseif ($param['f'] == 'widget_block' && !isset($param['t'])) { $err = 'missing t'; } break; default: $err = 'pt invalid ' . $param['pt']; } } if ($err) { return $err . ' : ' . $pd; } return new self($param, $conf); } }