/** Get an include tag for the given base URL and parameters. * * This performs the processing common to both types of includes. * @param string $url The base of the URL that should be included. * @param array $keys An associative array of GET parameters to add to the * URL before including it. * @return string The generated esi:include tag for the given URL. */ private function getIncludeTag($url, $params) { if ($this->sendDoESIHeader) { header(self::DO_ESI_HEADER); } nxcESIEAS::setUseESI(true); foreach ($params as $key => $value) { $url .= '&' . rawurlencode($key) . '=' . rawurlencode($value); } eZURI::transformURI($url); $include = '<esi:include src="' . $url; if ($this->continueOnError) { $include .= '" onerror="continue'; } $include .= '"/>'; return $include; }
/** Get the list of identified surrogates and their capabilities. * * This is based on the Surrogate-Capability header, but only includes the * surrogates that followed the specification, ignoring any others. * @return array The array of identified surrogates. Each element of this * array is an associative array with the keys 'device-token' and * 'capabilities', where 'capabilities' is an array of capability tokens * for that device. */ private static function getSurrogates() { if (is_array(self::$surrogates)) { return self::$surrogates; } self::$surrogates = array(); $header = self::getSurrogateCapabilityHeader(); if (is_string($header) && $header != '') { $token = '[^\\0-\\037\\0177()<>@,;:\\"\\/[\\]?={} \\t]+'; $matches = array(); if (preg_match_all('/(?:^|,)\\s*(' . $token . ')="([^"]*)"\\s*(?=,|$)/', $header, $matches, PREG_SET_ORDER) > 0) { foreach ($matches as $match) { self::$surrogates[] = array('device-token' => $match[1], 'capabilities' => explode(' ', $match[2])); } } } return self::$surrogates; }
/** Get the text content to make the edge include the given method call. * @see nxcESI::getIncludeForMethodCall() */ public function getIncludeForMethodCall($methodInfo, $keys) { // Save the current EAS instance to restore it afterwards, so that the // called method can use nxcESIEAS without affecting the header for the // current response, which is for the full page. $easInstance = nxcESIEAS::restoreInstance(null); if ($methodInfo['static']) { $call = array($methodInfo['class'], $methodInfo['method']); } else { $class = $methodInfo['class']; $call = array(new $class(), $methodInfo['method']); } $content = call_user_func($call, $keys); if (!is_string($content)) { $content = ''; } nxcESIEAS::restoreInstance($easInstance); return $content; }
/** Handle the processing of the es-cache template function. * @see process() */ private function processESCacheFunction($tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace) { if (isset($functionParameters['ttl'])) { $ttl = $tpl->elementValue($functionParameters['ttl'], $rootNamespace, $currentNamespace, $functionPlacement); $parts = array(); if (!preg_match('/^(\\d+\\.?\\d*|\\.\\d+)\\s*([a-z]?)$/', $ttl, $parts)) { $tpl->warning($this->ESCacheName, 'Invalid TTL: ' . $ttl, $functionPlacement); } else { $ttl = $parts[1]; // NOTE: This switch uses fall-through on purpose. switch ($parts[2]) { case 'w': $ttl *= 7; // weeks // weeks case 'd': $ttl *= 24; // days // days case 'h': $ttl *= 60; // hours // hours case 'm': $ttl *= 60; // minutes // minutes case '': // Empty unit is defaulted to seconds. // Empty unit is defaulted to seconds. case 's': // $ttl *= 1; // seconds break; default: $tpl->warning($this->ESCacheName, 'Unknown unit on TTL, assuming seconds: ' . $parts[2], $functionPlacement); break; } // Ensure we have an integer number of seconds. $ttl = round($ttl); nxcESIEAS::setMaxAge($ttl); } } if (isset($functionParameters['no-store'])) { $noStore = $tpl->elementValue($functionParameters['no-store'], $rootNamespace, $currentNamespace, $functionPlacement); if (!is_bool($noStore)) { $tpl->warning($this->ESCacheName, 'Non-boolean value given to no-store', $functionPlacement); } else { nxcESIEAS::setNoStore($noStore); } } if (isset($functionParameters['no-store-remote'])) { $noStore = $tpl->elementValue($functionParameters['no-store-remote'], $rootNamespace, $currentNamespace, $functionPlacement); if (!is_bool($noStore)) { $tpl->warning($this->ESCacheName, 'Non-boolean value given to no-store-remote', $functionPlacement); } else { nxcESIEAS::setNoStoreRemote($noStore); } } return true; }