<?php
namespace Moto\Website; use Moto; use Moto\Application\Pages\PagesTable; class PageType { protected $_type = 'page'; protected $_section = ''; protected $_params = null; protected static $_cache = array(); public function __construct($type) { $this->_type = $type; $parts = explode('.', $type, 2); $this->_section = $parts[0]; $this->_params = Moto\Website\Settings::get('content_section_' . $this->_section); } public function getParam($name, $default = null) { if (null === $this->_params) { return $default; } return (isset($this->_params->$name) ? $this->_params->$name : $default); } public function getParams() { return $this->_params; } public function getMainPageId() { return $this->getParam('page_id', 0); } public function isPage() { return ($this->_type == 'page'); } public function isTemplate() { return !!(preg_match('/^(tpl|template)\./', $this->_type)); } public function isPost() { return !!(preg_match('/^[a-z\-\_0-9]+\.(post)$/', $this->_type)); } public function isIndexPage() { return !!(preg_match('/\.(index)$/', $this->_type)); } public static function get($type) { if (!array_key_exists($type, static::$_cache)) { static::$_cache[$type] = new self($type); } return static::$_cache[$type]; } }