daux.io/libs/Format/HTML/ContentPage.php

101 lines
3.3 KiB
PHP
Raw Normal View History

<?php namespace Todaymade\Daux\Format\HTML;
use Todaymade\Daux\Tree\Root;
class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
{
private $language;
private $homepage;
private function isHomepage()
2015-04-23 00:32:30 +02:00
{
if (array_key_exists('auto_landing', $this->params['html']) && !$this->params['html']['auto_landing']) {
return false;
}
if ($this->file->getParent()->getIndexPage() != $this->file) {
return false;
}
if ($this->params['multilanguage']) {
return ($this->file->getParent()->getParent() instanceof Root);
}
2015-04-26 18:24:22 +02:00
return ($this->file->getParent() instanceof Root);
}
private function initialize()
{
$this->homepage = $this->isHomepage();
$this->language = '';
if ($this->params['multilanguage'] && count($this->file->getParents())) {
2015-07-18 21:23:02 +02:00
$language_dir = $this->file->getParents()[0];
$this->language = $language_dir->getName();
}
}
2015-07-18 21:23:02 +02:00
/**
* @param \Todaymade\Daux\Tree\Directory[] $parents
* @param bool $multilanguage
* @return array
*/
2015-04-27 11:57:44 +02:00
private function getBreadcrumbTrail($parents, $multilanguage)
2015-04-23 00:32:30 +02:00
{
if ($multilanguage && !empty($parents)) {
$parents = array_splice($parents, 1);
}
$breadcrumb_trail = array();
if (!empty($parents)) {
foreach ($parents as $node) {
2015-07-21 09:51:55 +02:00
$page = $node->getIndexPage() ?: $node->getFirstPage();
$breadcrumb_trail[$node->getTitle()] = $page ? $page->getUrl() : '';
}
}
return $breadcrumb_trail;
}
protected function generatePage()
2015-04-23 00:32:30 +02:00
{
$this->initialize();
$params = $this->params;
2015-04-23 00:32:30 +02:00
$entry_page = [];
if ($this->homepage) {
2015-04-23 00:32:30 +02:00
if ($params['multilanguage']) {
foreach ($params['languages'] as $key => $name) {
2015-04-23 10:24:50 +02:00
$entry_page[$name] = $params['base_page'] . $params['entry_page'][$key]->getUrl();
2015-04-23 00:32:30 +02:00
}
} else {
2015-04-26 18:24:22 +02:00
$entry_page['View Documentation'] = $params['base_page'] . $params['entry_page']->getUrl();
2015-04-23 00:32:30 +02:00
}
}
2015-04-27 11:57:44 +02:00
$page = [
'entry_page' => $entry_page,
'homepage' => $this->homepage,
'title' => $this->file->getTitle(),
'filename' => $this->file->getName(),
'language' => $this->language,
'path' => $this->file->getPath(),
'modified_time' => filemtime($this->file->getPath()),
'markdown' => $this->content,
'request' => $params['request'],
'content' => $this->getPureContent(),
'breadcrumbs' => $params['html']['breadcrumbs'],
'prev' => $this->file->getPrevious(),
'next' => $this->file->getNext(),
2015-04-27 11:57:44 +02:00
];
if ($page['breadcrumbs']) {
$page['breadcrumb_trail'] = $this->getBreadcrumbTrail($this->file->getParents(), $params['multilanguage']);
2015-07-19 16:36:34 +02:00
$page['breadcrumb_separator'] = $params['html']['breadcrumb_separator'];
}
2015-04-23 00:32:30 +02:00
2015-08-02 15:42:23 +02:00
$context = ['page' => $page, 'params' => $params];
2015-04-23 10:24:50 +02:00
$template = new Template($params['templates'], $params['theme']['templates']);
2015-08-02 15:42:23 +02:00
return $template->render($this->homepage ? 'theme::home' : 'theme::content', $context);
}
}