bludit/bl-kernel/page.class.php

70 lines
1.4 KiB
PHP
Raw Normal View History

2015-05-05 03:00:01 +02:00
<?php defined('BLUDIT') or die('Bludit CMS.');
2015-03-08 18:02:59 +01:00
2016-01-12 03:18:20 +01:00
class Page extends Content {
2015-05-05 03:00:01 +02:00
function __construct($key)
2015-08-24 00:07:14 +02:00
{
2015-06-30 05:23:29 +02:00
// Database Key
$this->setField('key', $key);
2015-03-08 18:02:59 +01:00
2016-01-12 03:18:20 +01:00
// Set filterType
$this->setField('filterType', 'page');
2015-06-28 01:28:22 +02:00
2016-01-12 03:18:20 +01:00
parent::__construct(PATH_PAGES.$key.DS);
2015-05-19 01:22:05 +02:00
}
// Returns the page position
2015-05-05 03:00:01 +02:00
public function position()
{
return $this->getField('position');
2015-03-08 18:02:59 +01:00
}
// Returns the page slug
2015-05-05 03:00:01 +02:00
public function slug()
2015-03-08 18:02:59 +01:00
{
2015-05-05 03:00:01 +02:00
$explode = explode('/', $this->getField('key'));
2016-01-12 03:18:20 +01:00
// Check if the page have a parent.
if(!empty($explode[1])) {
return $explode[1];
2015-06-22 02:47:07 +02:00
}
2016-01-12 03:18:20 +01:00
return $explode[0];
2015-03-08 18:02:59 +01:00
}
// Returns the parent key, if the page doesn't have a parent returns FALSE
2015-05-05 03:00:01 +02:00
public function parentKey()
2015-03-08 18:02:59 +01:00
{
2015-05-05 03:00:01 +02:00
$explode = explode('/', $this->getField('key'));
if(isset($explode[1])) {
return $explode[0];
}
2015-03-08 18:02:59 +01:00
return false;
}
// Returns the parent method output, if the page doesn't have a parent returns FALSE
2015-11-25 02:48:19 +01:00
public function parentMethod($method)
{
global $pages;
if( isset($pages[$this->parentKey()]) ) {
return $pages[$this->parentKey()]->{$method}();
}
return false;
}
2015-05-05 03:00:01 +02:00
public function children()
2015-03-08 18:02:59 +01:00
{
2015-05-05 03:00:01 +02:00
$tmp = array();
2015-09-15 01:07:15 +02:00
//$paths = glob(PATH_PAGES.$this->getField('key').DS.'*', GLOB_ONLYDIR);
$paths = Filesystem::listDirectories(PATH_PAGES.$this->getField('key').DS);
2015-05-05 03:00:01 +02:00
foreach($paths as $path) {
array_push($tmp, basename($path));
}
return $tmp;
2015-03-08 18:02:59 +01:00
}
2016-01-12 03:18:20 +01:00
}