- libxml_use_internal_errors(true);
- $doc = new DOMDocument();
- $doc->loadHTML(mb_convert_encoding('<body>'.$page->html.'</body>', 'HTML-ENTITIES', 'UTF-8'));
- $xpath = new DOMXpath($doc);
-
- $bsElems = $xpath->query('body/div[@bs-embed-page]');
- if (is_null($bsElems)) return $page->html;
- foreach ($bsElems as $bsElem) {
- $pageId = intval($bsElem->getAttribute('bs-embed-page'));
- $embeddedPage = $this->getById('page', $pageId);
- if ($embeddedPage !== null) {
- $innerPage = $doc->createDocumentFragment();
- $innerPage->appendXML($embeddedPage->html);
- // Empty div then append in child content
- foreach ($bsElem->childNodes as $child) {
- $bsElem->removeChild($child);
- }
- $bsElem->appendChild($innerPage);
+ $content = $page->html;
+ $matches = [];
+ preg_match_all("/{{@\s?([0-9].*?)}}/", $content, $matches);
+ if (count($matches[0]) === 0) return $content;
+
+ foreach ($matches[1] as $index => $includeId) {
+ $splitInclude = explode('#', $includeId, 2);
+ $pageId = intval($splitInclude[0]);
+ if (is_nan($pageId)) continue;
+
+ $page = $this->getById('page', $pageId);
+ if ($page === null) {
+ $content = str_replace($matches[0][$index], '', $content);
+ continue;