'300 Multiple Choices', 301 => '301 Moved Permanently', 302 => '302 Moved temporarily', 303 => '303 See Other', 304 => '304 Not Modified', 307 => '307 Temporary Redirect' ); protected $_currentPageId = null; public function getMode() { if (null == $this->_mode) { $this->_mode = 'edit'; } return $this->_mode; } public function setMode($mode) { $this->_mode = $mode; } public function setViewController($viewController) { $this->_viewController = $viewController; } public function getViewController() { return $this->_viewController; } public function setLanguage($language) { $this->_language = $language; return $this; } public function setDoc($doc) { $this->_doc = $doc; return $this; } public function setMetaOptions($options) { $this->_metaOptions = $options; } public function setIsCustomOptions($mode) { $this->_isCustomOptions = $mode; } public function setIsRedirectFields($value) { $this->_isRedirectFields = (bool) $value; } public function getIsRedirectFields() { if ($this->_doc->getAuth()->getSuMode()) { return ($this->_isRedirectFields && isset($this->_metaOptions['redirect'])); } return ($this->_isRedirectFields && isset($this->_metaOptions['redirect']) && 'y' == $this->_metaOptions['redirect']['show']); } public function getLanguage() { return $this->_language; } public function isDefaultLanguage() { return $this->_language === Qs_Constant::get('DEFAULT_LANGUAGE'); } public function init() { parent::init(); $this->setLegend('Meta'); $this->addElement('hidden', 'id'); if ($this->isDefaultLanguage()) { $this->addElement('select', 'idParent', array('label' => 'Parent Page', 'escapeLabel' => false)); if (!$this->_doc->getAuth()->getSuMode()) { $this->idParent->setAttrib('disabled', 'disabled'); } $this->addElement( 'text', 'alias', array('label' => 'Alias', 'required' => true, 'description' => 'Allowed characters: a-z, A-Z, 0-9, "-", "_", "."') ); $this->alias->addValidator( 'Regex', false, array('pattern' => '/^[-_a-zA-Z0-9\.]+$/', 'messages' => array( Zend_Validate_Regex::NOT_MATCH => 'You have used unallowed symbols. Please note: ' . 'the allowed ones are a-z, A-Z, 0-9, "-", "_", "."')) ); if ($this->_doc->getAuth()->getSuMode()) { $this->addElement('select', 'handler', array('label' => 'Handler', 'required' => true)); foreach($this->_metaOptions as $name => $option) { $this->_addOptionCheckbox($name, $option['title']); if ($this->_isCustomOptions) { $this->_addOptionCheckbox($name, $option['title'], true, ('y' == $option['show'])); } } $this->addElement('select', 'bodyTemplate', array('label' => 'Body Template')); } else { $this->addElement('hidden', 'handler'); foreach ($this->_metaOptions as $name => $option) { if ('y' == $option['show']) { $this->_addOptionCheckbox($name, $option['title']); } } } } if (!empty($this->_optionsElements)) { $this->addDisplayGroup( $this->_optionsElements, 'optionsGroup', array( 'legend' => 'Options', ) ); $this->optionsGroup->removeDecorator('HtmlTag'); } $this->addElement('text', 'title', array('label' => 'Title', 'required' => true)); $this->addElement('text', 'header', array('label' => 'Header')); $this->addElement('text', 'menuTitle', array('label' => 'Menu Title')); $this->_addRedirectElements(); $this->addElement('textarea', 'keywords', array('label' => 'Keywords', 'attribs' => array('rows' => 2))); $this->addElement('textarea', 'description', array('label' => 'Description', 'attribs' => array('rows' => 2))); $this->addElement('button', 'save', array('label' => 'Save', 'decorators' => array('ViewHelper', 'HtmlTag'))); $this->addElement('button', 'cancel', array('label' => 'Cancel', 'decorators' => array('ViewHelper', 'HtmlTag'))); $this->addElement('button', 'edit', array('label' => 'Edit', 'decorators' => array('ViewHelper', 'HtmlTag'))); $this->addDisplayGroup( array('save', 'cancel', 'edit'), 'meta_toolbar', array( 'decorators' => array( 'FormElements', array( 'decorator' => 'HtmlTag', 'options' => array('tag' => 'dd', 'class' => 'meta_toolbar') ) ) ) ); return $this; } protected function _addOptionCheckbox($name, $label, $suMode = false, $checked = false) { if ($suMode) { $name = $name . '4Dommy'; $label = 'Allow change ('.$label.')'; } $this->addElement( 'checkbox', $name, array( 'label' => $label, 'class' => ($suMode) ? 'allow_change' : '', 'checkedValue' => 'y', 'uncheckedValue' => 'n', 'decorators' => array( array( 'decorator' => 'ViewHelper', 'options' => array('separator' => '
')), array( 'decorator' => 'Label', 'options' => array('placement' => 'APPEND', 'class' => ($suMode) ? 'allow_change_label' : '')) ) ) ); if ($checked) { $this->{$name}->checked = 'checked'; } $this->_optionsElements[] = $name; } protected function _addRedirectElements() { if ($this->getIsRedirectFields()) { if ($this->_doc->getAuth()->getSuMode()) { $this->addElement( 'select', 'redirectStatus', array( 'label' => 'Redirect Status', 'value' => 302, 'multiOptions' => $this->_redirectStatuses, ) ); } $this->addElement( 'select', 'redirectType', array( 'label' => 'Redirect Type', 'multiOptions' => array('' => '- Select Type -', 'page' => 'Site Page', 'url' => 'Url') ) ); $this->_currentPageId = intval(Qs_Request::getRequestValue('id')); $this->addElement( 'select', 'redirectPageId', array( 'label' => 'Site Page', 'multiOptions' => array('0' => '- Select Page -') ) ); $this->addElement( 'text', 'redirectAlias', array( 'label' => 'Redirect page to:', 'description' => 'Example: http://www.adaptainc.com', ) ); $this->redirectType->getDecorator('label')->setOption('class', 'required'); $this->redirectPageId->getDecorator('label')->setOption('class', 'required'); $this->redirectAlias->addValidator('StringLength', false, array('max' => 255)); $this->redirectAlias->getDecorator('label')->setOption('class', 'required'); $this->addFormRule(array($this, 'validateForm')); } } public function validateForm($data) { $errors = array(); if ($this->getIsRedirectFields()) { if (isset($data['redirect']) && 'y' == $data['redirect']) { if (!isset($data['redirectType']) || empty($data['redirectType'])) { $errors['redirectType'] = "Value is required and can't be empty"; } else { if ('page' == $data['redirectType']) { if (empty($data['redirectPageId'])) { $errors['redirectPageId'] = "Value is required and can't be empty"; } elseif (isset($this->_currentPageId) && $this->_currentPageId == $data['redirectPageId']) { $errors['redirectPageId'] = 'Please choose another page to prevent recursive redirects'; } else { $validator = new Zend_Validate_Int(); if (!$validator->isValid($data['redirectPageId'])) { $errors['redirectPageId'] = '"Site Page" is in wrong format'; } $page = Qs_SiteMap::findFirst(array('id' => intval($data['redirectPageId']))); if (!empty($page) && $page['redirect'] == 'y') { $errors['redirectPageId'] = 'Please choose another page. Page "title" has redirect'; } } } else { if (empty($data['redirectAlias'])) { $errors['redirectAlias'] = "Value is required and can't be empty"; } else { $url = str_replace('{BASE_URL}', BASE_URL_LANGUAGE, $data['redirectAlias']); $validator = new Qs_Validate_Url(); if (!$validator->isValid($url)) { $errors['redirectAlias'] = '"Redirect page to" is in wrong format'; } } } } } } return (empty($errors)) ? true : $errors; } public function beforeRender() { $mode = $this->getMode(); switch ($mode) { case 'view': $this->getDecorator('HtmlTag')->setOption('class', 'meta view_mode'); break; default: break; } } public function render(Zend_View_Interface $view = null) { $this->beforeRender(); return parent::render($view); } public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return; } $decorators = $this->getDecorators(); if (empty($decorators)) { $this->addDecorator('FormElements') ->addDecorator('HtmlTag', array('tag' => 'dl')) ->addDecorator('Fieldset'); } } public function addElement($element, $name = null, $options = null) { $hiddenFields = $this->_viewController->getConfig('hiddenFields'); if (is_array($hiddenFields) && in_array($name, $hiddenFields)) { return $this; } parent::addElement($element, $name, $options); } }