bludit/bl-kernel/page.class.php

71 lines
1.4 KiB
PHP
Raw Normal View History

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