/** * For each repeat instance create a copy of the repeatable node and merge * the instance's content areas. * * @param array $contentArea the content areas for the current level * @param Merger $merger object to do the merging */ public function merge($contentArea, Merger $merger = null) { if (is_null($contentArea)) { $contentArea = array(); } if ($this->edit && count($contentArea) == 0) { $contentArea = array(array()); } foreach ($contentArea as $i => $repeatInstance) { $this->node->parentNode->insertBefore(new DOMComment("Start of repeat instance {$i}"), $this->node); $copyNode = $this->node->cloneNode(true); $this->node->parentNode->insertBefore($copyNode, $this->node); $merger->mergeOneLevel($copyNode, $repeatInstance, $this->edit, $this->name, $i); if ($this->edit) { $this->addRepeatButtons($copyNode, $i, count($contentArea)); } $this->node->parentNode->insertBefore(new DOMComment("End of repeat instance {$i}"), $this->node); } $this->node->parentNode->removeChild($this->node); }
/** * If area is hidden and not editing then remove the area * Otherwise merge the content area. * * @param array $contentArea the content areas for the current level * @param Merger $merger object to do the merging */ public function merge($contentArea, Merger $merger = null) { if (is_null($contentArea)) { $contentArea = array(); } elseif (isset($contentArea[0])) { $contentArea = $contentArea[0]; } $isHidden = isset($contentArea['_hidden']) && $contentArea['_hidden']; if ($isHidden && !$this->edit) { $this->node->parentNode->removeChild($this->node); return; } $this->node->parentNode->insertBefore(new DOMComment("Start of hideable area {$this->name}"), $this->node); $merger->mergeOneLevel($this->node, $contentArea, !$isHidden && $this->edit, $this->name, 0); $this->node->parentNode->insertBefore(new DOMComment('End of hideable area'), $this->node->nextSibling); if ($this->edit) { $class = $isHidden ? 'hidden' : 'hideable'; $this->addClass($class); $this->addHideButton($isHidden); } }
/** * Merge the template with the content areas * The first level is processed here, further levels will be processed * recursively * Optionally inline css. * * @param array $contentAreas the content areas * @param bool $edit whether the merge should include edit buttons * * @return string the generated HTML */ public function merge(array $contentAreas, $edit = false) { if ($edit) { $this->addStyles(); } $merger = new Merger($this->xpath); $merger->mergeOneLevel($this->dom->documentElement, $contentAreas, $edit); $this->createToc(); $html = $this->saveAsHtml($this->removeAttributes($this->dom)); if (getConfig('contentareas_inline_css') && !$edit) { $factory = new CssInlinerFactory(); $inliner = $factory->createCssInliner(); $html = $inliner->inlineCss($html); } return $this->replaceEncodedBrackets($html); }