Пример #1
0
 /**
  * Builds a form that allows users to add or edit a category
  * and can fill the values with default values
  *
  * @param string $title
  * @param string $desc
  * @param int $id
  * @return string
  */
 protected function buildCategoryForm($title = null, $desc = null, $id = null)
 {
     $op = is_null($id) ? 'add' : 'edit';
     $form = new View_Form('config/form_category.html', 'article', is_null($id));
     $form->action($this->_router->makeUrl('article', 'config', $op . 'cat', null, array('id' => $id)));
     $form->addElement('article/title', $title, t('Title'), new Validator_Length(1, 255));
     $form->addElement('article/description', $desc, t('Description'), new Validator_Length(0, 255));
     // Set op and other tags
     $form->assign(array('OP' => $op, 'ID' => $id));
     $resource = $op == 'edit' ? 'article-cat-' . $id : 'article-cat';
     $form->assignHtml(array('ACL_FORM' => $this->_acl->buildForm(array(t('View category') => $resource))));
     return $form;
 }
Пример #2
0
 /**
  * Provides ability to add a new content layout. The user will
  * be redirect to the page, as if they had gone 'Edit' on the
  * layout once it has been created.
  *
  * @return string
  */
 public function addSection()
 {
     $this->setTitle(t('Add new layout'));
     $this->setOutputType(self::_OT_CONFIG);
     try {
         $cloner = $this->_router->getArgument('clone');
         $cloner = new Layout($cloner);
         if ($cloner->exists()) {
             $cloneName = $cloner->getName();
             $cloneRegex = $cloner->getRegex();
             $this->setTitle(sprintf(t('Clone layout "%1$s"'), $cloneName));
         } else {
             throw new Exception();
         }
     } catch (Exception $e) {
         $cloneName = null;
         $cloneRegex = null;
     }
     // Build and check form
     $form = new View_Form('index/form_layout.html', 'content_layout');
     $form->action($this->_router->makeUrl('content_layout', 'index', 'add'));
     $form->addElement('content_layout/name', null, t('Name'), array(new Validator_Alphanumeric('-'), new Validator_Length(2, 225)));
     $form->addElement('content_layout/regex', $cloneRegex, t('URL/Regex'), new Validator_Length(2, 255));
     $form->addElement('content_layout/site_type', $this->_router->getDefaultSiteType(), t('Site type'), new Validator_InArray($this->_router->getSiteTypes()));
     $form->addElement('content_layout/clone', $cloneName, t('Clone'), array(new Validator_Alphanumeric('-'), new Validator_Length(0, 225)));
     if ($form->hasInput() && $form->isValid()) {
         $fd = $form->getValues('content_layout');
         // Check if we are cloning a layout
         if ($fd['clone']) {
             $layout = new Layout($fd['clone']);
             $layout->setName($fd['site_type'] . '-' . $fd['name']);
         } else {
             $layout = new Layout($fd['site_type'] . '-' . $fd['name']);
         }
         $layout->setRegex($fd['regex']);
         $path = $this->_zula->getDir('config') . '/layouts/' . $layout->getName() . '.xml';
         if ($layout->save($path)) {
             $this->_event->success(t('Added new content layout'));
             return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layout->getName()));
         }
         $this->_event->error(t('Unable to save content layout'));
     }
     return $form->getOutput();
 }
Пример #3
0
 /**
  * Displays and handles the form for new users to register an account
  *
  * @return string
  */
 public function indexSection()
 {
     $this->setTitle(t('Register an account'));
     // Check that registrations are actually available
     if ($this->_config->get('session/allow_register') == false) {
         throw new Module_ControllerNoExist();
     } else {
         if ($this->_config->get('session/force_https')) {
             $formUrl = $this->_router->makeUrl('session', 'register')->makeFull('&', null, true);
             if ($this->_router->getScheme() != 'https') {
                 return zula_redirect($formUrl);
             }
         } else {
             $formUrl = $this->_router->makeUrl('session', 'register');
         }
     }
     // Build the form and prepare validation
     $form = new View_Form('register/form.html', 'session');
     $form->action($formUrl)->antispam(true);
     $form->addElement('session/username', null, t('Username'), array(new Validator_Alphanumeric('_()!:@.^-'), new Validator_Length(2, 32), array($this, 'validateUsername')));
     $form->addElement('session/password', null, t('Password'), array(new Validator_Length(4, 64), new Validator_Confirm('session/password_confirm', Validator_Confirm::_POST)));
     $form->addElement('session/email', null, t('Email'), array(new Validator_Email(), new Validator_Confirm('session/email_confirm', Validator_Confirm::_POST), array($this, 'validateEmail')));
     $form->addElement('session/terms_agree', null, t('Terms'), new Validator_Bool(), false);
     if ($form->hasInput()) {
         if ($this->_config->get('session/register_terms') && !$this->_input->has('post', 'session/terms')) {
             $this->_event->error(t('Please agree to the terms and conditions'));
             $hasTerms = false;
         } else {
             $hasTerms = true;
         }
         if ($form->isValid() && $hasTerms) {
             /**
              * Attempt to add the new user and send correct email
              */
             $fd = $form->getValues('session');
             $userDetails = array('status' => 'locked', 'username' => $fd['username'], 'password' => $fd['password'], 'email' => $fd['email'], 'group' => $this->_config->get('session/register_group'), 'activate_code' => zula_create_key());
             $validationMethod = $this->_config->get('session/validation_method');
             switch ($validationMethod) {
                 case 'none':
                     $userDetails['status'] = 'active';
                     $userDetails['activate_code'] = '';
                     $eventMsg = t('Successfully registered, you may now login.');
                     break;
                 case 'admin':
                     $eventMsg = t('Successfully registered, an admin will review your registration shortly.');
                     break;
                 case 'user':
                 default:
                     $validationMethod = 'user';
                     # Ensure a known validation method.
                     $eventMsg = t('Successfully registered, an email has been sent to confirm your registration.');
             }
             // Add the new user and attempt to send the email.
             $uid = $this->_ugmanager->addUser($userDetails);
             try {
                 $msgView = $this->loadView('register/validation_' . $validationMethod . '.txt');
                 $msgView->assign($userDetails);
                 $message = new Email_Message(t('Account Details'), $msgView->getOutput());
                 $message->addTo($userDetails['email']);
                 $email = new Email();
                 $email->send($message);
                 // All done, redirect user
                 $this->_event->success($eventMsg);
                 return zula_redirect($this->_router->makeUrl('session'));
             } catch (Email_Exception $e) {
                 $this->_ugmanager->deleteUser($uid);
                 $this->_event->error(t('An error occurred while sending the email. Please try again later'));
                 $this->_log->message('Unable to send registration email: ' . $e->getMessage(), Log::L_WARNING);
             }
         }
     }
     // Add T&Cs then output the form
     $form->assign(array('TERMS' => $this->_config->get('session/register_terms')));
     return $form->getOutput();
 }
Пример #4
0
 /**
  * Builds the view for adding/editing a field
  *
  * @param int $fid
  * @param string $name
  * @param bool $required
  * @param string $type
  * @param string $options
  * @param int $id
  * @return string
  */
 protected function buildFieldForm($fid = null, $name = null, $required = false, $type = null, $options = null, $id = null)
 {
     if ($id === null) {
         $op = 'add';
         $args = array('id' => $fid);
     } else {
         $op = 'edit';
         $args = array('id' => $id);
     }
     $form = new View_Form('config/field_form.html', 'contact', is_null($id));
     $form->action($this->_router->makeUrl('contact', 'config', $op . 'field', null, $args));
     $form->addElement('contact/name', $name, t('Name'), new Validator_Length(1, 255));
     $form->addElement('contact/required', $required, t('Required'), new Validator_Bool());
     $form->addElement('contact/type', $type, t('Type'), new Validator_Alphanumeric());
     $form->addElement('contact/options', $options, t('Options'), new Validator_Length(0, 255));
     // Assign some additional tags
     $form->assign(array('OP' => $op, 'FORM_ID' => $fid, 'ID' => $id, 'TYPES' => array('textbox' => t('Textbox'), 'textarea' => t('Textarea'), 'radio' => t('Radio options'), 'checkbox' => t('Checkbox'), 'select' => t('Drop down Menu'), 'password' => t('Password textbox'))));
     return $form;
 }