* @package WB * @subpackage content */ /** * Load base class */ WBClass::load('WBContent' , 'WBContent_LandingPage'); /** * Content component: LandingPage * * @version 0.3.1 * @package WB * @subpackage content */ class WBContent_LandingPage_Display extends WBContent_LandingPage { /** * My Parameter List * @var array */ protected $config = array( 'tmpl' => 'blank', 'urlpath' => '' ); /** * Current Page * @var array */ protected $page = array(); /** * Event Data * @var array */ protected $eData = array(); /** * Event Name * @var array */ protected $eName = 'visit'; /** * @var WBDatesource_Table */ private $table; /** * HTTP Return Status * @var int */ private $statusCode = 200; /** * whether to use template engine or not * @var bool */ protected $withFormTmpl = true; /** * automatically parse template and return HTML * @var bool */ protected $parseFormTmpl = false; /** * Template's name - allow sub-classes to override this value * @var string */ protected $formTmplName = 'contactFormSnippet'; /** * 2nd constructor * * Called after configuration was done */ protected function init() { parent::init(); $this->statusCode = 200; $this->table = WBClass::create('WBDatasource_Table'); } /** * run * * run component * * @see sendAndExit() * @return array parameter list */ public function run() { if (empty($this->config['urlpath'])) { $this->statusCode = 404; $this->loadTemplates('default/404'); return $this->config; } if (!$this->loadPage4URLPath($this->config['urlpath'])) { $this->statusCode = 404; $this->loadTemplates('default/404'); return $this->config; } $this->loadTemplates($this->page['template']); if (!empty($this->page['title'])) { $this->bubbles['title'] = $this->page['title']; } if (!empty($this->page['keywords'])) { $this->bubbles['keywords'] = trim($this->page['keywords']); } if (!empty($this->page['brief'])) { $this->bubbles['description'] = substr(trim(str_replace("\n", ' ', strip_tags($this->page['brief']))), 0, 200); } $this->tmpl->addGlobalVars($this->page); if (0 < $this->page['withcontactform']) { $this->processForm('contact'); } $this->triggerEvent(); $media = $this->loadMedia4Page($this->page); $this->list2Template($media, 'media_list'); $article = $this->loadArticle4Page($this->page); $this->list2Template($article, 'pagearticle_list'); return $this->config; } /** * Validation completed * * @param patForms $form * @param array $values */ public function onContactValid($form, $values) { $this->eData = $values; $this->eName = 'contact'; return true; } /** * Invalid * * @param patForms $form */ public function onContactInValid($form) { $this->eName = ''; return true; } /** * Trigger Event * * Trigger event on case event name is set * @see eName * @see eData */ private function triggerEvent() { if (empty($this->eName)) { return; } $eData = array_merge($this->page, $this->eData); $eData['user'] = $this->user->getId(); $eData['created'] = gmdate('Y-m-d H:i:s'); $eName = sprintf('landingpage:%s:%s', $this->eName, $this->page['urlpath']); WBEvent::trigger($eName, 'Landing page event for {URLPATH}', $eData); } /** * Load Articles 4 Page * * @param array page * @return array list of articles */ private function loadArticle4Page($page) { $pPage = $this->table->getIdentifier(WBContent_LandingPage::TABLE_LANDINGPAGE); if (empty($page[$pPage])) { return array(); } $option = array(); $option['join'] = array(); $option['join'][] = array( 'table' => WBContent_LandingPage::TABLE_PAGEARTICLE, 'using' => $this->table->getIdentifier(WBContent_LandingPage::TABLE_ARTICLE) ); $clause = array(); $clause[] = array( 'field' => 'enabled', 'value' => 1 ); $clause[] = array( 'table' => WBContent_LandingPage::TABLE_PAGEARTICLE, 'field' => $pPage, 'value' => $page[$pPage] ); $list = $this->table->get(WBContent_LandingPage::TABLE_ARTICLE, null, null, $clause, $option); return $list; } /** * Load Media 4 Page * * @param array page * @return array list of VFS files */ private function loadMedia4Page($page) { $pPage = $this->table->getIdentifier(WBContent_LandingPage::TABLE_LANDINGPAGE); if (empty($page[$pPage])) { return array(); } $option = array(); $option['join'] = array(); $option['join'][] = array( 'table' => WBContent_LandingPage::TABLE_VFSFILE, 'using' => $this->table->getIdentifier('vfsfile') ); $clause = array(); $clause[] = array( 'table' => WBContent_LandingPage::TABLE_VFSFILE, 'field' => $pPage, 'value' => $page[$pPage] ); $list = $this->table->get('vfsfile', null, null, $clause, $option); return $list; } /** * Load Page By URL Path * * @param string * @return bool true on success */ private function loadPage4URLPath($urlpath) { $clause = array(); $clause[] = array( 'field' => 'urlpath', 'value' => $this->config['urlpath'] ); $clause[] = array( 'field' => 'enabled', 'value' => 1 ); $page = $this->table->get(WBContent_LandingPage::TABLE_LANDINGPAGE, null, null, $clause); if (1 > count($page)) { return false; } $page = $page[0]; foreach ($page as $k => &$v) { $v = trim($v); } if (empty($page['urltext'])) { $page['urltext'] = $page['title']; } $this->page = $page; return true; } /** * Get response status code * * @return int */ public function getStatusCode() { return $this->statusCode; } /** * Load templates from file * * @param string $tmpl * @param bool local templates */ protected function loadTemplates($tmpl, $local = true) { if (!$local) { return parent::loadTemplates($tmpl, $local); } switch ($tmpl) { case 'contact': case 'contactValid': $tmpl = 'default/' . $tmpl; break; } return parent::loadTemplates($tmpl, $local); } /** * location of form config * * Return sub directory where form element definitions are located * * @return string folder */ protected function getFormConfigDir() { return 'landingpage/display'; } /** * Fetch list of form elements * * The standard behaviour loads form defintions from XML config * file located in form config dir {@link getFormConfigDir() } * Overwrite this to implement your own behaviour. * * @param string name of the xml- and template-filename * @return array $elements */ protected function getFormElementList($name) { $list = parent::getFormElementList($name); $this->injectElement4Captcha($list); return $list; } }