Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Load layouts from /layouts #9

Merged
merged 6 commits into from
Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/site/components/com_pages/model/entity/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function _initialize(KObjectConfig $config)
'process' => array(
'plugins' => true
),
'layout' => 'default'
'layout' => ''
),
));

Expand Down
9 changes: 4 additions & 5 deletions code/site/components/com_pages/template/locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ public function find(array $info)
{
$path = ltrim(str_replace(parse_url($info['url'], PHP_URL_SCHEME).'://', '', $info['url']), '/');

$file = pathinfo($path, PATHINFO_FILENAME);
$format = pathinfo($path, PATHINFO_EXTENSION);
$path = ltrim(pathinfo($path, PATHINFO_DIRNAME), '.');
$file = pathinfo($path, PATHINFO_FILENAME);
$path = ltrim(pathinfo($path, PATHINFO_DIRNAME), '.');

//Prepend the base path
if($path) {
Expand All @@ -56,9 +55,9 @@ public function find(array $info)
}

if($this->realPath($path.'/'.$file)) {
$pattern = $path.'/'.$file.'/index.'.$format.'*';
$pattern = $path.'/'.$file.'/index.'.'*';
} else {
$pattern = $path.'/'.$file.'.'.$format.'*';
$pattern = $path.'/'.$file.'.*';
}

//Try to find the file
Expand Down
44 changes: 39 additions & 5 deletions code/site/components/com_pages/view/page/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @link https://github.com/joomlatools/joomlatools-framework-pages for the canonical source repository
*/

class ComPagesViewPageHtml extends ComKoowaViewHtml
class ComPagesViewPageHtml extends ComKoowaViewPageHtml
{
public function __construct(KObjectConfig $config)
{
Expand All @@ -25,34 +25,68 @@ protected function _initialize(KObjectConfig $config)
parent::_initialize($config);
}

protected function _fetchData(KViewContext $context)
{
parent::_fetchData($context);

//Find the layout
if($layout = $context->data->page->layout)
{
$path = 'page://layouts/'.$layout;

if (!$this->getObject('template.locator.factory')->locate($path)) {
throw new RuntimeException(sprintf("Layout '%s' cannot be found", $layout));
}
}
else $path = 'com://site/pages.page.default.html';

$context->layout = $path;
}

protected function _actionRender(KViewContext $context)
{
$data = KObjectConfig::unbox($context->data);

//Render the template
$this->_content = $this->getTemplate()
->loadFile($context->layout)
->setParameters($context->parameters)
->render($data);

return KViewAbstract::_actionRender($context);
}

protected function _processPlugins(KViewContextInterface $context)
{
$page = $context->data->page;

if($page->process->plugins)
{
$content = $context->result;
$content = new stdClass;
$content->text = $context->result;

$params = (object)$page->getProperties();

//Trigger onContentBeforeDisplay
$results = array();
$results[] = $this->getTemplate()->createHelper('event')->trigger(array(
'name' => 'onContentBeforeDisplay',
'import_group' => 'content',
'attributes' => array('com_pages.page', &$content, (object)$page->getProperties())
'attributes' => array('com_pages.page', &$content, &$params)
));

//Trigger onContentPrepare
$results[] = $this->getTemplate()->createHelper('event')->trigger(array(
'name' => 'onContentPrepare',
'import_group' => 'content',
'attributes' => array('com_pages.page', &$content, (object)$page->getProperties())
'attributes' => array('com_pages.page', &$content, &$params)
));

//Trigger onContentAfterDisplay
$results[] = $this->getTemplate()->createHelper('event')->trigger(array(
'name' => 'onContentAfterDisplay',
'import_group' => 'content',
'attributes' => array('com_pages.page', &$content, (object)$page->getProperties())
'attributes' => array('com_pages.page', &$content, &$params)
));

$context->result = trim(implode("\n", $results));;
Expand Down