2015-05-18 14:26:29 +02:00
|
|
|
<?php namespace Todaymade\Daux\Format\HTML;
|
2015-04-21 17:11:43 +02:00
|
|
|
|
2015-07-18 23:50:47 +02:00
|
|
|
use Todaymade\Daux\Tree\Root;
|
|
|
|
|
2015-07-28 17:25:03 +02:00
|
|
|
class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
2015-04-21 17:11:43 +02:00
|
|
|
{
|
|
|
|
private $language;
|
|
|
|
private $homepage;
|
|
|
|
|
2016-01-07 21:18:18 +01:00
|
|
|
private function isHomepage()
|
2015-04-23 00:32:30 +02:00
|
|
|
{
|
2017-01-10 10:28:58 +01:00
|
|
|
// If the current page isn't the index, no chance it is the landing page
|
2016-01-07 21:18:18 +01:00
|
|
|
if ($this->file->getParent()->getIndexPage() != $this->file) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-10 10:28:58 +01:00
|
|
|
// If the direct parent is root, this is the homage
|
2016-07-27 21:32:51 +02:00
|
|
|
return $this->file->getParent() instanceof Root;
|
2016-01-07 21:18:18 +01:00
|
|
|
}
|
|
|
|
|
2017-05-16 23:17:06 +02:00
|
|
|
private function isLanding() {
|
|
|
|
// If we don't have the auto_landing parameter, we don't want any homepage
|
|
|
|
if (array_key_exists('auto_landing', $this->params['html']) && !$this->params['html']['auto_landing']) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->homepage;
|
|
|
|
}
|
|
|
|
|
2016-01-07 21:18:18 +01:00
|
|
|
private function initialize()
|
|
|
|
{
|
|
|
|
$this->homepage = $this->isHomepage();
|
|
|
|
|
2015-04-21 17:11:43 +02:00
|
|
|
$this->language = '';
|
2016-07-27 23:27:51 +02:00
|
|
|
if ($this->params->isMultilanguage() && count($this->file->getParents())) {
|
2015-07-18 21:23:02 +02:00
|
|
|
$language_dir = $this->file->getParents()[0];
|
|
|
|
$this->language = $language_dir->getName();
|
2015-04-21 17:11:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2016-07-27 21:32:51 +02:00
|
|
|
$breadcrumb_trail = [];
|
2015-04-21 17:11:43 +02:00
|
|
|
if (!empty($parents)) {
|
|
|
|
foreach ($parents as $node) {
|
2015-07-21 09:51:55 +02:00
|
|
|
$page = $node->getIndexPage() ?: $node->getFirstPage();
|
2018-06-05 23:02:01 +02:00
|
|
|
$breadcrumb_trail[] = ['title' => $node->getTitle(), 'url' => $page ? $page->getUrl() : ''];
|
2015-04-21 17:11:43 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-27 21:32:51 +02:00
|
|
|
|
2015-04-21 17:11:43 +02:00
|
|
|
return $breadcrumb_trail;
|
|
|
|
}
|
|
|
|
|
2015-05-18 14:26:29 +02:00
|
|
|
protected function generatePage()
|
2015-04-23 00:32:30 +02:00
|
|
|
{
|
2015-05-18 14:26:29 +02:00
|
|
|
$this->initialize();
|
2015-04-21 17:11:43 +02:00
|
|
|
$params = $this->params;
|
2015-04-22 18:24:10 +02:00
|
|
|
|
2015-04-23 00:32:30 +02:00
|
|
|
$entry_page = [];
|
2015-07-18 23:50:47 +02:00
|
|
|
if ($this->homepage) {
|
2016-07-27 23:27:51 +02:00
|
|
|
if ($params->isMultilanguage()) {
|
2015-04-23 00:32:30 +02:00
|
|
|
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 {
|
2017-10-19 22:18:46 +02:00
|
|
|
$entry_page['__VIEW_DOCUMENTATION__'] = $params['base_page'] . $params['entry_page']->getUrl();
|
2015-04-23 00:32:30 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-21 17:11:43 +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(),
|
2016-08-17 00:18:34 +02:00
|
|
|
'relative_path' => $this->file->getRelativePath(),
|
2015-04-27 11:57:44 +02:00
|
|
|
'modified_time' => filemtime($this->file->getPath()),
|
|
|
|
'markdown' => $this->content,
|
|
|
|
'request' => $params['request'],
|
2016-03-13 21:51:15 +01:00
|
|
|
'content' => $this->getPureContent(),
|
2015-10-28 00:18:29 +01:00
|
|
|
'breadcrumbs' => $params['html']['breadcrumbs'],
|
|
|
|
'prev' => $this->file->getPrevious(),
|
|
|
|
'next' => $this->file->getNext(),
|
2017-11-07 22:39:34 +01:00
|
|
|
'attributes' => $this->file->getAttribute()
|
2015-04-27 11:57:44 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
if ($page['breadcrumbs']) {
|
2016-07-27 23:27:51 +02:00
|
|
|
$page['breadcrumb_trail'] = $this->getBreadcrumbTrail($this->file->getParents(), $params->isMultilanguage());
|
2015-07-19 16:36:34 +02:00
|
|
|
$page['breadcrumb_separator'] = $params['html']['breadcrumb_separator'];
|
2017-05-16 23:17:06 +02:00
|
|
|
|
|
|
|
if ($this->homepage) {
|
2018-06-05 23:02:01 +02:00
|
|
|
$page['breadcrumb_trail'] = [['title' => $this->file->getTitle(), 'url' => '']];
|
2017-05-16 23:17:06 +02:00
|
|
|
}
|
2015-04-21 17:11:43 +02:00
|
|
|
}
|
2015-04-23 00:32:30 +02:00
|
|
|
|
2015-08-02 15:42:23 +02:00
|
|
|
$context = ['page' => $page, 'params' => $params];
|
|
|
|
|
2017-12-11 21:14:18 +01:00
|
|
|
return $this->templateRenderer->render($this->isLanding() ? 'theme::home' : 'theme::content', $context);
|
2015-04-21 17:11:43 +02:00
|
|
|
}
|
|
|
|
}
|