* @license PHP License * @package WB * @subpackage content */ /** * Load base class */ WBClass::load('WBContent'); /** * Content component: Page Maker * * Create and edit page's config stored in database * * @version 0.1.0 * @package WB * @subpackage content */ class WBContent_PageMaker extends WBContent { /** * my parameter list * @var array */ protected $config = array( 'action' => 'overview', 'requiredgroup' => 'pagemaker' ); /** * config loader * @var WBConfig_Loader_ConfigTable */ private $loader = null; /** * constructor * * */ public function __construct() { parent::__construct(); $this->loader = WBClass::create('WBConfig_Loader_ConfigTable'); } /** * run * * run component * * @todo become user-aware for blog categories * @return array parameter list */ public function run() { // group required if (!$this->isUserInGroup($this->config['requiredgroup'])) { $this->config['action'] = 'anonymous'; return $this->config; } return $this->config; } /** * receive output * * fetch output of this content component * * @return string */ public function getString() { switch ($this->config['action']) { case 'anonymous': $this->loadTemplates('anon'); break; case 'site'; $values = $this->loadXml('site'); return $this->processForm('site', $values); break; case 'content': $values = $this->loadXml('site/content'); return $this->processForm('content', $values); break; case 'page': $path = trim($this->req->get('path', ''), '/ '); if ($path == '__new') { $values = array(); $loader = WBClass::create('WBConfig_Loader_File'); $loader->load('pagemaker/template', $values['xml'], $expire); $this->tmpl->addGlobalVar('page_path', $path); return $this->processForm('page', $values); } $path = str_replace('*', '__default', $path); if (empty($path)) { $path = '__index'; } $values = $this->loadXml('site/page/' . $path); if ('__index' == $path) { $path = ''; } else { $path = str_replace('__default', '*', $path); } $this->tmpl->addGlobalVar('page_path', $path); return $this->processForm('page', $values); break; case 'overview': default: $this->loadTemplates('overview'); break; } $this->tmpl->addGlobalVars($this->config); return $this->tmpl->getParsedTemplate('snippet'); } /** * Site validation complete * * Save site config * * @param patForms $form * @param array $values */ protected function onSiteValid($form, $values) { $xml = trim($values['xml']) . "\n"; $this->loader->save('site', $xml); return true; } /** * Content validation complete * * Save default content in site config * * @param patForms $form * @param array $values */ protected function onContentValid($form, $values) { $this->saveXml('site/content', $values); return true; } /** * page validation complete * * Save page config * * @param patForms $form * @param array $values */ protected function onPageValid($form, $values) { $path = $this->req->get('path', ''); if ('__new' == $path) { $path = $values['page']; } if (empty($path)) { $path = '__index'; } else { $path = str_replace('*', '__default', $path); } $this->saveXml('site/page/' . $path, $values); return true; } /** * load and prepare XML config * * @param string $config * @return array */ private function loadXml($config) { $values = array(); $expire = array(); $this->loader->load($config, $values['xml'], $expire); $regex = '/\{([A-Z_]+)\}/'; $repl = '[[$1]]'; $values['xml'] = preg_replace($regex, $repl, $values['xml']); return $values; } /** * store XML config * * @param string $config * @param array $values */ private function saveXml($config, $values) { $xml = trim($values['xml']) . "\n"; $regex = '/\[\[([A-Z_]+)\]\]/'; $repl = '{$1}'; $values['xml'] = preg_replace($regex, $repl, $xml); $this->loader->save($config, $xml); } /** * Fetch list of form elements * * Load form element definition using parent class and add project ids * * @param string name of the xml- and template-filename * @return array $elements */ protected function getFormElementList($name) { $list = parent::getFormElementList($name); if ('page' == $name) { $path = trim($this->req->get('path', ''), '/ '); if ('__new' != $path) { unset($list['page']); } } return $list; } /** * location of form config * * Return sub directory where form element definitions are located * * @return string folder */ protected function getFormConfigDir() { return 'pagemaker/form'; } } ?>