mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-23 10:41:16 +08:00
Started page transclusion system
This commit is contained in:
parent
d8c5f72258
commit
e4e3b25c22
|
@ -156,15 +156,19 @@ class PageController extends Controller
|
|||
return redirect($page->getUrl());
|
||||
}
|
||||
|
||||
|
||||
$this->checkOwnablePermission('page-view', $page);
|
||||
|
||||
$pageContent = $this->entityRepo->renderPage($page);
|
||||
$sidebarTree = $this->entityRepo->getBookChildren($page->book);
|
||||
$pageNav = $this->entityRepo->getPageNav($page);
|
||||
|
||||
Views::add($page);
|
||||
$this->setPageTitle($page->getShortName());
|
||||
return view('pages/show', ['page' => $page, 'book' => $page->book,
|
||||
'current' => $page, 'sidebarTree' => $sidebarTree, 'pageNav' => $pageNav]);
|
||||
return view('pages/show', [
|
||||
'page' => $page,'book' => $page->book,
|
||||
'current' => $page, 'sidebarTree' => $sidebarTree,
|
||||
'pageNav' => $pageNav, 'pageContent' => $pageContent]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,6 +13,7 @@ use Carbon\Carbon;
|
|||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class EntityRepo
|
||||
{
|
||||
|
@ -796,6 +797,44 @@ class EntityRepo
|
|||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the page for viewing, Parsing and performing features such as page transclusion.
|
||||
* @param Page $page
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function renderPage(Page $page)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
$body = $doc->getElementsByTagName('body')->item(0);
|
||||
$html = '';
|
||||
foreach ($body->childNodes as $node) {
|
||||
$html .= $doc->saveHTML($node);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new draft page instance.
|
||||
* @param Book $book
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
@if (isset($diff) && $diff)
|
||||
{!! $diff !!}
|
||||
@else
|
||||
{!! $page->html !!}
|
||||
{!! isset($pageContent) ? $pageContent : $page->html !!}
|
||||
@endif
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user