示例#1
0
 /**
  * Display some RSS options, and a list of the current feeds
  *
  * @return string
  */
 public function indexSection()
 {
     if (!$this->_acl->check('rss_edit')) {
         throw new Module_NoPermission();
     }
     $this->setTitle(t('RSS configuration'));
     $this->setOutputType(self::_OT_CONFIG);
     /**
      * Prepare form validation
      */
     $form = new View_Form('config/main.html', 'rss');
     $form->addElement('rss/global', (bool) $this->_config->get('rss/global_agg_enable'), t('Global aggregation'), new Validator_Bool());
     $form->addElement('rss/default', $this->_config->get('rss/default_feed'), t('Default feed'), new Validator_Alphanumeric('_-'));
     $form->addElement('rss/items', $this->_config->get('rss/items_per_feed'), t('Number of items'), new Validator_Numeric());
     if ($form->hasInput() && $form->isValid()) {
         $fd = $form->getValues('rss');
         // Check default feed given is valid
         if ($fd['default'] != 0 && !in_array($fd['default'], array_keys($this->feeds))) {
             $this->_event->error(t('Please select a valid default RSS feed.'));
         } else {
             $this->_config_sql->update(array('rss/global_agg_enable', 'rss/items_per_feed', 'rss/default_feed'), array($fd['global'], $fd['items'], $fd['default']));
             $this->_event->success(t('Updated RSS configuration'));
             return zula_redirect($this->_router->makeUrl('rss', 'config'));
         }
     }
     // Add additional data
     $form->assign(array('RSS_FEEDS' => $this->feeds));
     return $form->getOutput();
 }
示例#2
0
 /**
  * Add the first user which will be created in the special
  * 'root' group.
  *
  * @return bool|string
  */
 public function indexSection()
 {
     $this->setTitle(t('First user'));
     if ($this->_zula->getMode() != 'cli' && (!isset($_SESSION['installStage']) || $_SESSION['installStage'] !== 3)) {
         return zula_redirect($this->_router->makeUrl('install', 'checks'));
     }
     // Get data from either a form or CLI arguments
     if ($this->_zula->getMode() == 'cli') {
         $data = array('username' => $this->_input->cli('u'), 'password' => $this->_input->cli('p'), 'email' => $this->_input->cli('e'));
     } else {
         $form = new View_Form('user.html', 'install');
         $form->addElement('username', null, t('Username'), array(new Validator_Alphanumeric('_-'), new Validator_Length(2, 32)));
         $form->addElement('password', null, t('Password'), array(new Validator_Length(4, 32), new Validator_Confirm('password2', Validator_Confirm::_POST)));
         $form->addElement('email', null, t('Email'), array(new Validator_Email(), new Validator_Confirm('email2', Validator_Confirm::_POST)));
         if ($form->hasInput() && $form->isValid()) {
             $data = $form->getValues();
         } else {
             return $form->getOutput();
         }
     }
     if (strcasecmp($data['username'], 'guest') === 0) {
         $this->_event->error(t('Username of "guest" is invalid'));
         if (isset($form)) {
             return $form->getOutput();
         } else {
             $this->_zula->setExitCode(3);
             return false;
         }
     }
     $this->_ugmanager->editUser(2, $data);
     if (isset($_SESSION['installStage'])) {
         ++$_SESSION['installStage'];
     }
     $this->_event->success(t('First user has been created'));
     return zula_redirect($this->_router->makeUrl('install', 'modules'));
 }
示例#3
0
 /**
  * Change settings regarding themeing and style
  *
  * @return string
  */
 public function settingsSection()
 {
     $this->setTitle(t('Theme settings'));
     $this->setOutputType(self::_OT_CONFIG);
     // Prepare form validation
     $form = new View_Form('settings.html', 'theme');
     $form->addElement('theme/allow_user_override', $this->_config->get('theme/allow_user_override'), t('Allow user override'), new Validator_Bool());
     if ($form->hasInput() && $form->isValid()) {
         $allowOverride = $form->getValues('theme/allow_user_override');
         try {
             $this->_config_sql->update('theme/allow_user_override', $allowOverride);
         } catch (Config_KeyNoExist $e) {
             $this->_config_sql->add('theme/allow_user_override', $allowOverride);
         }
         $this->_event->success(t('Updated theme settings'));
         return zula_redirect($this->_router->makeUrl('theme', 'index', 'settings'));
     }
     return $form->getOutput();
 }
示例#4
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();
 }
示例#5
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();
 }
示例#6
0
文件: sql.php 项目: jinshana/tangocms
 /**
  * Gathers all details needed to connect to the database
  * and create the initial tables to populate.
  *
  * The config.ini.php file also gets updated with the SQL
  * details and others such as hashing salt and router type.
  *
  * @return bool|string
  */
 public function indexSection()
 {
     $this->setTitle(t('SQL details'));
     if ($this->_zula->getMode() != 'cli' && (!isset($_SESSION['installStage']) || $_SESSION['installStage'] !== 2)) {
         return zula_redirect($this->_router->makeUrl('install', 'checks'));
     }
     // Get data from either a form or CLI arguments
     if ($this->_zula->getMode() == 'cli') {
         $dsn = parse_url($this->_input->cli('dsn'));
         if (isset($dsn['scheme'], $dsn['host'], $dsn['user'], $dsn['path'])) {
             $data = array('type' => $dsn['scheme'], 'user' => $dsn['user'], 'pass' => isset($dsn['pass']) ? $dsn['pass'] : '', 'host' => $dsn['host'], 'port' => isset($dsn['port']) ? $dsn['port'] : 3306, 'dbname' => ltrim($dsn['path'], '/'), 'prefix' => $this->_input->cli('dbPrefix'));
         } else {
             $this->_event->error(t('Invalid DSN string'));
             $this->_zula->setExitCode(3);
             return false;
         }
     } else {
         $form = new View_Form('sql.html', 'install');
         $form->addElement('user', null, t('Username'), new Validator_Length(1, 16));
         $form->addElement('pass', null, t('Password'), array(new Validator_Length(0, 64), new Validator_Regex('#^[^"]*$#')));
         $form->addElement('host', 'localhost', t('SQL host'), new Validator_Length(1, 80));
         $form->addElement('port', 3306, t('SQL Port'), new Validator_Int());
         $form->addElement('dbname', null, t('SQL Database'), new Validator_Length(1, 64));
         $form->addElement('prefix', 'tcm_', t('Table prefix'), array(new Validator_Length(0, 12), new Validator_Alphanumeric('_-')));
         if ($form->hasInput() && $form->isValid()) {
             $data = $form->getValues();
             $data['type'] = 'mysql';
         } else {
             return $form->getOutput();
         }
     }
     try {
         $sql = new SQL($data['type'], $data['dbname'], $data['host'], $data['user'], $data['pass'], $data['port']);
         $sql->setPrefix($data['prefix']);
         $sql->query("SET NAMES 'utf8'");
         # Use UTF-8 character set for the connection
         $sql->loadSqlFile($this->getPath() . '/schema.sql');
         /**
          * Update config.ini.php file with the new values
          */
         $confKeys = array('sql/enable' => true, 'sql/host' => $data['host'], 'sql/user' => $data['user'], 'sql/pass' => $data['pass'], 'sql/database' => $data['dbname'], 'sql/type' => $data['type'], 'sql/prefix' => $data['prefix'], 'sql/port' => $data['port'], 'hashing/salt' => zula_make_salt(), 'acl/enable' => true);
         if ($this->_input->has('get', 'ns')) {
             $confKeys['url_router/type'] = 'standard';
         }
         $this->_config_ini->update(array_keys($confKeys), array_values($confKeys));
         try {
             $this->_config_ini->writeIni();
             if (isset($_SESSION['installStage'])) {
                 ++$_SESSION['installStage'];
             }
             $this->_event->success(t('Initial database tables have been created'));
             return zula_redirect($this->_router->makeUrl('install', 'user'));
         } catch (Config_ini_FileNotWriteable $e) {
             $this->_event->error($e->getMessage());
         }
     } catch (SQL_UnableToConnect $e) {
         $this->_event->error(t('Unable to connect to, or select SQL database'));
     }
     if (isset($form)) {
         return $form->getOutput();
     } else {
         $this->_zula->setExitCode(3);
         return false;
     }
 }
示例#7
0
 /**
  * Allows the current user to edit account details, such as password and email.
  *
  * @return string
  */
 public function settingsSection()
 {
     if (!$this->_session->isLoggedIn()) {
         throw new Module_NoPermission();
     }
     $this->setTitle(t('Edit account settings'));
     // Gather user details
     $this->displayPageLinks();
     $user = $this->_session->getUser();
     if (!isset($user['theme'])) {
         $user['theme'] = null;
     }
     /**
      * Prepare form validation
      */
     $form = new View_Form('profile/settings.html', 'users');
     $form->addElement('users/passwd/current', null, t('Current password'), array(array($this, 'validatePassword')));
     $form->addElement('users/passwd/new', null, t('Password'), array(new Validator_Length(4, 32), new Validator_Confirm('users/passwd/conf', Validator_Confirm::_POST)), false);
     $form->addElement('users/hide_email', $user['hide_email'], t('Hide email'), new Validator_Bool());
     $form->addElement('users/theme', $user['theme'], t('Theme name'), new Validator_InArray(Theme::getAll()), false);
     try {
         // Add Email validation if needed
         $emailConf = $this->_input->post('users/email_confirm');
         if ($emailConf) {
             $form->addElement('users/email', $user['email'], t('Email'), array(new Validator_Email(), new Validator_Confirm($emailConf)));
         } else {
             throw new Exception();
         }
     } catch (Exception $e) {
         $form->assign(array('USERS' => array('EMAIL' => $user['email'])));
     }
     if ($form->hasInput() && $form->isValid()) {
         try {
             $fd = $form->getValues('users');
             if (empty($fd['theme'])) {
                 $fd['theme'] = null;
             }
             $fd['password'] = $fd['passwd']['new'];
             unset($fd['passwd']);
             $this->_ugmanager->editUser($this->_session->getUserId(), $fd);
             $this->_event->success(t('Updated Profile'));
             return zula_redirect($this->_router->makeUrl('users', 'profile', 'settings'));
         } catch (Exception $e) {
             $this->_event->error($e->getMessage());
         }
     }
     return $form->getOutput();
 }