16 include_once (
'Class.Log.php');
17 include_once (
'Class.Action.php');
18 include_once (
'Class.Application.php');
72 private $escapeBracket =
"__BRACKET-OPEN__";
73 private $noGoZoneMapping =
"__NO-GO-ZONE__";
74 private $goZoneMapping =
"[ZONE ";
117 $this->LOG =
new Log(
"",
"Layout");
118 if (($template ==
"[OUT]") && ($caneva !=
"")) $this->
template = sprintf(_(
"Template [%s] not found") , $caneva);
119 else $this->
template = $template;
121 $this->generation =
"";
122 $this->noGoZoneMapping = uniqid($this->noGoZoneMapping);
123 $this->escapeBracket = uniqid($this->escapeBracket);
127 if ((!file_exists(
$file)) && (
$file[0] !=
'/')) {
131 if (file_exists(
$file)) {
133 $this->
template = file_get_contents(
$file);
168 $this->corresp[
"$p_nom_block"][
"[$p_nom_modele]"] = ($p_nom == NULL ? $p_nom_modele :
"$p_nom");
178 if (is_array(
$data)) {
179 foreach (
$data as & $aRow) {
180 if (is_array($aRow)) {
181 foreach ($aRow as & $aData) {
182 $aData = str_replace(
"[", $this->escapeBracket, htmlspecialchars($aData, ENT_QUOTES));
197 $this->data[
"$p_nom_block"] =
$data;
199 if (is_array(
$data)) {
201 $elem = current(
$data);
202 if (isset($elem) && is_array($elem)) {
203 foreach ($elem as $k => $v) {
204 if (!isset($this->corresp[
"$p_nom_block"][
"[$k]"])) {
220 if (isset($this->data[
"$p_nom_block"]))
return $this->data[
"$p_nom_block"];
226 if ($this->strip ==
'Y') {
228 $block = str_replace(
"\\\"",
"\"", $block);
233 if (isset($this->data) && isset($this->data[
"$name"]) && is_array($this->data[
"$name"])) {
234 foreach ($this->data[
"$name"] as $k => $v) {
236 if (!is_array($this->corresp[
"$name"]))
return sprintf(_(
"SetBlock:error [%s]") , $name);
237 foreach ($this->corresp[
"$name"] as $k2 => $v2) {
238 $vv2 = (isset($v[$v2])) ? $v[$v2] :
'';
239 if ((!is_object($vv2)) && (!is_array($vv2))) {
240 $loc = str_replace($k2, str_replace($this->goZoneMapping, $this->noGoZoneMapping, $vv2) , $loc);
247 $this->rif = $oriRif;
255 $out = preg_replace_callback(
'/(?m)\[BLOCK\s*([^\]]*)\](.*?)\[ENDBLOCK\s*\\1\]/s',
function ($matches)
257 return $this->
SetBlock($matches[1], $matches[2]);
262 protected function TestIf($name, $block, $not =
false)
265 if (array_key_exists($name, $this->rif) || isset($this->rkey[$name])) {
266 $n = (array_key_exists($name, $this->rif)) ? $this->rif[$name] : $this->rkey[$name];
268 if ($this->strip ==
'Y') {
269 $block = str_replace(
"\\\"",
"\"", $block);
276 if ($this->strip ==
'Y') $block = str_replace(
"\\\"",
"\"", $block);
278 if ($not)
$out =
"[IFNOT $name]" . $block .
"[ENDIF $name]";
279 else $out =
"[IF $name]" . $block .
"[ENDIF $name]";
286 $out = preg_replace_callback(
'/\[IF(NOT)?\s+([^\]]*)\](.*?)\[ENDIF\s+\\2\]/smu',
function ($matches)
288 return $this->
TestIf($matches[2], $matches[3], $matches[1]);
295 $out = preg_replace_callback(
'/\[ZONE\s+([^:]*):([^\]]*)\]/',
function ($matches)
297 return $this->
execute($matches[1], $matches[2]);
304 if (isset($this->rkey)) {
305 $out = str_replace($this->pkey, $this->rkey,
$out);
316 if ($enc ==
"utf-8") {
317 $this->encoding = $enc;
325 $limit =
getParam(
'CORE_LAYOUT_EXECUTE_RECURSION_LIMIT', 0);
326 if (is_numeric($limit) && $limit > 0) {
328 if ($loop[
'count'] >= $limit) {
333 if ($this->action ==
"")
return (
"Layout not used in a core environment");
337 $actionargn = str_replace(
":",
"--", $actionargn);
338 $acturl = parse_url($actionargn);
342 $OLD_ZONE_ARGS = $ZONE_ARGS;
343 if (isset($acturl[
"query"])) {
344 $acturl[
"query"] = str_replace(
"--",
":", $acturl[
"query"]);
345 $zargs = explode(
"&", $acturl[
"query"]);
346 foreach ($zargs as $v) {
347 if (preg_match(
"/([^=]*)=(.*)/", $v, $regs)) {
349 $ZONE_ARGS[$regs[1]] = urldecode($regs[2]);
354 if (
$appname != $this->action->parent->name) {
358 $appl = & $this->action->parent;
361 if ((
$actionname != $this->action->name) || ($OLD_ZONE_ARGS != $ZONE_ARGS)) {
371 $res = $act->CompleteSet(
$appl);
374 $res = $act->execute();
377 $jsRefs = $act->parent->getJsRef();
378 foreach ($jsRefs as $jsRefe) {
379 $this->action->parent->addJsRef($jsRefe);
381 $cssRefs = $act->parent->getCssRef();
382 foreach ($cssRefs as $cssRefe) {
383 $this->action->parent->addCssRef($cssRefe);
386 $ZONE_ARGS = $OLD_ZONE_ARGS;
390 return (
"Fatal loop : $actionname is called in $actionname");
400 public function set($tag, $val)
402 $this->pkey[$tag] =
"[$tag]";
403 $this->rkey[$tag] = $val;
405 public function rSet($tag, $val)
407 $this->
set($tag, $val);
409 public function xSet($tag, $val)
418 public function eSet($tag, $val)
420 $val = str_replace($this->goZoneMapping, $this->noGoZoneMapping, $val);
421 $this->
set($tag, str_replace(
"[", $this->escapeBracket, htmlspecialchars($val, ENT_QUOTES)));
432 if (isset($this->rkey[$tag]))
return $this->rkey[$tag];
438 if (!$this->action)
return;
439 $out = preg_replace_callback(
'/\[IMG:([^\|\]]+)\|([0-9]+)\]/',
function ($matches)
442 return $action->parent->getImageLink($matches[1],
true, $matches[2]);
446 $out = preg_replace_callback(
'/\[IMG:([^\]\|]+)\]/',
function ($matches)
449 return $action->parent->getImageLink($matches[1]);
453 $out = preg_replace_callback(
'/\[IMGF:([^\]]*)\]/',
function ($matches)
456 return $action->parent->GetFilteredImageUrl($matches[1]);
463 $out = preg_replace_callback(
'/\[TEXT(\([^\)]*\))?:([^\]]*)\]/',
function ($matches)
466 if (
$s ==
"")
return $s;
470 return ___(
$s, trim($matches[1],
'()'));
478 if (
$s ==
"")
return $s;
485 $list[] = $this->action->GetParam(
"CORE_JSURL") .
"/logmsg.js?wv=" . $this->action->GetParam(
"WVERSION");
486 if (!empty($this->action->parent))
$list = array_merge(
$list, $this->action->parent->GetJsRef());
490 foreach (
$list as $k => $v) {
491 $js.=
"\n" . sprintf(
'<script type="text/javascript" language="JavaScript" src="%s"></script>', $v);
504 if (empty($this->action->parent))
return $out;
507 $list = $this->action->parent->GetJsCode();
508 foreach (
$list as $k => $v) {
514 $list = $this->action->parent->GetLogMsg();
516 $out.=
"var logmsg=new Array();\n";
517 foreach (
$list as $k => $v) {
518 if (($v[0] ==
'{'))
$out.=
"logmsg[$k]=$v;\n";
519 else $out.=
"logmsg[$k]=" . json_encode($v) .
";\n";
522 $out.=
"if ('displayLogMsg' in window) displayLogMsg(logmsg);\n";
523 $this->action->parent->ClearLogMsg();
525 $list = $this->action->parent->GetWarningMsg();
526 if (count(
$list) > 0) {
527 $out.=
"displayWarningMsg(" . json_encode(implode(
"\n---------\n", array_unique(
$list)) , JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP) .
");\n";
529 $this->action->parent->ClearWarningMsg();
533 $actcode = $actarg = array();
534 $this->action->getActionDone($actcode, $actarg);
535 if (count($actcode) > 0) {
536 $out.=
"var actcode=new Array();\n";
537 $out.=
"var actarg=new Array();\n";
538 foreach ($actcode as $k => $v) {
539 $out.= sprintf(
"actcode[%d]=%s;\n", $k, json_encode($v, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP));
540 $out.= sprintf(
"actarg[%d]=%s;\n", $k, json_encode($actarg[$k], JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP));
542 $out.=
"sendActionNotification(actcode,actarg);\n";
543 $this->action->clearActionDone();
551 $out = preg_replace_callback(
'/\[JS:REF\]/',
function ()
557 $out = preg_replace_callback(
'/\[JS:CODE\]/',
function ()
563 $out = preg_replace_callback(
'/\[JS:CODENLOG\]/',
function ()
573 if (empty($this->action->parent))
return "";
574 if ($oldCompatibility) {
575 $cssLink = $this->action->parent->getCssLink(
"css/dcp/system.css",
true);
576 $css.=
"<link rel=\"stylesheet\" type=\"text/css\" href=\"$cssLink\">\n";
578 $list = $this->action->parent->GetCssRef();
579 foreach (
$list as $k => $v) {
580 $css.=
"<link rel=\"stylesheet\" type=\"text/css\" href=\"$v\">\n";
587 if (empty($this->action->parent))
return "";
588 $list = $this->action->parent->GetCssCode();
591 foreach (
$list as $v) {
598 $out = preg_replace_callback(
'/\[CSS:REF\]/',
function ()
603 $out = preg_replace_callback(
'/\[CSS:CUSTOMREF\]/',
function ()
609 $out = preg_replace_callback(
'/\[CSS:CODE\]/',
function ()
622 if ($this->noparse)
return $this->template;
624 $out = $this->template;
644 $out = str_replace(array(
645 $this->noGoZoneMapping,
648 $this->goZoneMapping,
660 if (is_object($this->action) && (!empty($this->action->parent))) {
661 $keys = $pval = array();
662 $list = $this->action->parent->GetAllParam();
664 foreach (
$list as $k => $v) {
665 $this->rif[$k] = !empty($v);
667 } elseif ($this->zoneLevel === 0) {
668 foreach (
$list as $k => $v) {
669 if ($v === null) $v =
'';
670 elseif (!is_scalar($v)) $v =
"notScalar";
676 $out = str_replace($keys, $pval,
$out);
692 $bt = debug_backtrace(
false);
693 $btCount = count($bt);
694 for ($i = $btCount - 2; $i >= 0; $i--) {
696 $bClass = isset($bt[$i][
'class']) ? $bt[$i][
'class'] :
'';
697 $bFunction = isset($bt[$i][
'function']) ? $bt[$i][
'function'] :
'';
698 if (
$class == $bClass && $function == $bFunction) {
699 $delta = $curDepth - $prevDepth;
700 $prevDepth = $curDepth;
719 include_once (
'WHAT/Lib.Prefix.php');
722 $http_reason =
"Recursion Count Error";
723 header(sprintf(
"HTTP/1.1 %s %s", $http_code, $http_reason));
725 print "<html><head>\n";
726 print "<title>" . htmlspecialchars($http_reason) .
"</title>\n";
727 print "</head></body>\n";
729 print "<h1>" . sprintf(
"%s %s", htmlspecialchars($http_code) , htmlspecialchars($http_reason)) .
"</h1>\n";
731 $message = sprintf(
"Infinite recursive loop in %s::%s() (call count = '%s')",
$class, $function, $count);
733 error_log(sprintf(
"%s::%s Error: %s",
$class, $function,
$message));
735 print "</body></html>\n";
Layout is a template generator.
eSetBlockData($p_nom_block, $data=NULL)
parseApplicationParameters(&$out, $addIf)
getRecursionCount($class, $function)
if(!function_exists('pgettext')) ___($message, $context="")
GenCssRef($oldCompatibility=true)
xml_entity_encode_all($s)
printRecursionCountError($class, $function, $count)
__construct($caneva="", $action=null, $template="[OUT]")
getParam($name, $def="")
must be in core or global type
setBlockData($p_nom_block, $data=NULL)
GenJsCode($showlog, $onlylog=false)
setBlockCorresp($p_nom_block, $p_nom_modele, $p_nom=NULL)
execute($appname, $actionargn)
getBlockData($p_nom_block)
TestIf($name, $block, $not=false)