Ejemplo n.º 1
0
<?php

/** Module view that outputs specified HTML fragments for inclusion using ESI.
 * @author FA
 * @since 2012-01-31 16:00
 * @copyright Copyright (C) 2012 NXC International
 * @license http://opensource.org/licenses/gpl-2.0.php GNU GPL v2
 * @package nxcESI
 */
$module = $Params['Module'];
$includeType = $Params['IncludeType'];
$http = eZHTTPTool::instance();
$keys = array();
$keysHeader = '';
foreach ($http->attribute('get') as $key => $value) {
    if (nxcESI::validateKeyName($key)) {
        if (is_string($value) || is_numeric($value)) {
            $keys[$key] = strval($value);
            $keysHeader .= ' ' . rawurlencode($key) . '=' . rawurlencode($value);
        }
    }
}
header('X-NXC-ESI-Keys:' . $keysHeader);
switch ($includeType) {
    case 'empty':
        eZExecution::cleanExit();
        break;
    case 'template':
    case 'template-in-pagelayout':
        if (!isset($keys['template']) || trim($keys['template']) == '') {
            eZDebug::writeError('Tried to include a template without specifying which.', 'nxc_esi/include/' . $includeType);
Ejemplo n.º 2
0
 /** Extract the cache keys, with values, from the function invocation.
  * @return array Associative array of key name to value.
  * @see process()
  */
 private function extractKeys($tpl, $functionParameters, $rootNamespace, $currentNamespace, $functionPlacement)
 {
     $keys = array();
     foreach ($functionParameters as $paramName => $paramValue) {
         if (!nxcESI::validateKeyName($paramName)) {
             $tpl->warning($this->ESIncludeName, 'Invalid key name: ' . $paramName, $functionPlacement);
         } else {
             $value = $tpl->elementValue($paramValue, $rootNamespace, $currentNamespace, $functionPlacement);
             if (is_null($value)) {
                 // Skip this key
             } elseif (is_bool($value)) {
                 $keys[$paramName] = $value ? 'true' : 'false';
             } elseif (is_string($value) || is_numeric($value)) {
                 $keys[$paramName] = strval($value);
             } else {
                 $tpl->warning($this->ESIncludeName, 'Invalid value for key ' . $paramName . ': ' . $value, $functionPlacement);
             }
         }
     }
     return $keys;
 }