예제 #1
0
 /**
  * Displays all controllers from the layout map, categories
  * by which sector they are in.
  *
  * @param string $name
  * @param array $args
  * @return mixed
  */
 public function __call($name, $args)
 {
     $this->setOutputType(self::_OT_CONFIG);
     if (!$this->_acl->check('content_layout_config_module')) {
         throw new Module_NoPermission();
     }
     $layoutName = substr($name, 0, -7);
     $siteType = substr($layoutName, 0, strpos($layoutName, '-'));
     if (empty($layoutName) || !$this->_router->siteTypeExists($siteType)) {
         $this->_event->error(t('Unable to manage content layout, invalid name given'));
         return zula_redirect($this->_router->makeUrl('content_layout'));
     }
     $this->setTitle(sprintf(t('"%s" content layout'), $layoutName));
     $this->setOutputType(self::_OT_CONFIG);
     // Create the new content layout object
     $layout = new Layout($layoutName);
     if (!$layout->exists()) {
         $this->_event->error(t('Provided layout does not exist'));
         return zula_redirect($this->_router->makeUrl('content_layout'));
     }
     // Build view form with validation for the regex (for layout)
     $form = new View_form('manage/main.html', 'content_layout');
     $form->caseSensitive();
     $form->action($this->_router->makeUrl('content_layout', 'manage', $layoutName));
     $form->addElement('content_layout/regex', $layout->getRegex(), t('URL/Regex'), new Validator_Length(2, 255));
     if ($form->hasInput() && $form->isValid()) {
         $layout->setRegex($form->getValues('content_layout/regex'));
         if ($layout->save()) {
             $this->_event->success(t('Updated content layout'));
             return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layoutName));
         }
         $this->_event->error(t('Unable to save content layout'));
     }
     /**
      * Gather all controllers in the layout for the theme of the site type
      * this layout is for.
      */
     $theme = new Theme($this->_config->get('theme/' . $siteType . '_default'));
     $themeSectors = array();
     foreach ($theme->getSectors() as $sector) {
         $themeSectors[$sector['id']] = array('sector' => $sector, 'cntrlrs' => $layout->getControllers($sector['id']));
     }
     // Assign additional data
     $form->assign(array('layoutName' => $layout->getName(), 'themeSectors' => $themeSectors));
     $this->_theme->addJsFile('jQuery/plugins/dnd.js');
     $this->addAsset('js/dnd_order.js');
     return $form->getOutput();
 }
예제 #2
0
파일: form.php 프로젝트: jinshana/tangocms
 /**
  * Magic method, allows for shorter URLs. Display the specified
  * contact form to the user.
  *
  * @param string $name
  * @param array $args
  * @return mixed
  */
 public function __call($name, array $args)
 {
     $this->setTitle(t('Contact'));
     $this->setOutputType(self::_OT_COLLECTIVE);
     // Get the correct form identifier to display
     try {
         $contact = $this->_model()->getForm(substr($name, 0, -7), false);
     } catch (Contact_NoExist $e) {
         throw new Module_ControllerNoExist();
     }
     if (!$this->_acl->check('contact-form-' . $contact['id'])) {
         throw new Module_NoPermission();
     }
     $this->setTitle($contact['name']);
     /**
      * Prepare form validation, if needed
      */
     $fields = $this->_model()->getFormFields($contact['id']);
     if ($fields) {
         $form = new View_form('contact.html', 'contact');
         $form->caseSensitive()->antispam(true);
         $form->addElement('contact/email', $this->_session->getUser('email'), t('Email address'), new Validator_Email());
         foreach ($fields as &$tmpField) {
             $tmpField['options'] = zula_split_config($tmpField['options']);
             // Use correct validation for the given types.
             switch ($tmpField['type']) {
                 case 'textbox':
                 case 'password':
                     $validator = new Validator_Length(1, 300);
                     break;
                 case 'textarea':
                     $validator = new Validator_Length(1, 3000);
                     break;
                 case 'radio':
                 case 'select':
                 case 'checkbox':
                     $validator = new Validator_InArray(array_values($tmpField['options']));
                     break;
                 default:
                     $validator = null;
             }
             $form->addElement('contact/fields/' . $tmpField['id'], null, $tmpField['name'], $validator, (bool) $tmpField['required']);
         }
         if ($form->hasInput() && $form->isValid()) {
             /**
              * Send out the contact form email
              */
             $mailBody = $this->loadView('email_body.txt');
             $mailBody->assign(array('form' => $contact, 'fields' => $fields, 'email' => $form->getValues('contact/email')));
             $mailBody->assignHtml(array('contact' => $form->getValues('contact')));
             try {
                 $message = new Email_message(sprintf(t('Contact form "%s"'), $contact['name']), $mailBody->getOutput(), 'text/plain');
                 $message->setTo($contact['email']);
                 $message->setReplyTo($form->getValues('contact/email'));
                 $email = new Email();
                 $email->send($message);
                 $this->_event->success(t('Contact form sent successfully'));
             } catch (Email_Exception $e) {
                 $this->_event->error(t('Sorry, there was a technical error while sending the contact form'));
                 $this->_log->message($e->getMessage(), Log::L_WARNING);
             }
             return zula_redirect($this->_router->getParsedUrl());
         }
     } else {
         $form = $this->loadView('contact.html');
     }
     // Parse the body
     $editor = new Editor($contact['body']);
     unset($contact['body']);
     $form->assignHtml(array('body' => $editor->parse()));
     $form->assign(array('details' => $contact, 'fields' => $fields));
     return $form->getOutput();
 }