コード例 #1
0
 /**
  * Method to get the configuration data.
  *
  * This method will load the global configuration data straight from
  * JConfig. If configuration data has been saved in the session, that
  * data will be merged into the original data, overwriting it.
  *
  * @return  array  An array containg all global config data.
  * @since   1.6
  */
 public function getData()
 {
     // Get the config data.
     //$config = new JConfig();
     $data = Config::getRoot()->toArray();
     //\Hubzero\Utility\Arr::fromObject($config);
     // Prime the asset_id for the rules.
     $data['asset_id'] = 1;
     // Get the text filter data
     $params = \Component::params('com_config');
     $data['filters'] = \Hubzero\Utility\Arr::fromObject($params->get('filters'));
     // If no filter data found, get from com_content (update of 1.6/1.7 site)
     if (empty($data['filters'])) {
         $contentParams = \Component::params('com_content');
         $data['filters'] = \Hubzero\Utility\Arr::fromObject($contentParams->get('filters'));
     }
     // Check for data in the session.
     $temp = User::getState('com_config.config.global.data');
     // Merge in the session data.
     if (!empty($temp)) {
         $data = array_merge($data, $temp);
     }
     return $data;
 }
コード例 #2
0
ファイル: component.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Save the configuration
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries.
     \Session::checkToken();
     // Set FTP credentials, if given.
     \JClientHelper::setCredentialsFromRequest('ftp');
     // Initialise variables.
     $model = new Models\Component();
     $form = $model->getForm();
     $data = Request::getVar('jform', array(), 'post', 'array');
     $id = Request::getInt('id');
     $option = Request::getCmd('component');
     // Check if the user is authorized to do this.
     if (!User::authorise('core.admin', $option)) {
         App::redirect('index.php', \Lang::txt('JERROR_ALERTNOAUTHOR'));
         return;
     }
     // Validate the posted data.
     $return = $model->validate($form, $data);
     // Check for validation errors.
     if ($return === false) {
         // Get the validation messages.
         $errors = $model->getErrors();
         // Push up to three validation messages out to the user.
         for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
             if ($errors[$i] instanceof Exception) {
                 Notify::warning($errors[$i]->getMessage());
             } else {
                 Notify::warning($errors[$i]);
             }
         }
         // Save the data in the session.
         User::setState($this->_option . '.config.global.data', $data);
         // Redirect back to the edit screen.
         App::redirect(Route::url('index.php?option=' . $this->_option . '&view=component&component=' . $option . '&tmpl=component&path=' . $model->getState('component.path'), false));
         return false;
     }
     // Attempt to save the configuration.
     $data = array('params' => $return, 'id' => $id, 'option' => $option);
     $return = $model->save($data);
     // Check the return value.
     if ($return === false) {
         // Save the data in the session.
         User::setState($this->_option . '.config.global.data', $data);
         // Save failed, go back to the screen and display a notice.
         App::redirect(Route::url('index.php?option=' . $this->_option . '&view=component&component=' . $option . '&tmpl=component&path=' . $model->getState('component.path'), false), Lang::txt('JERROR_SAVE_FAILED', $model->getError()), 'error');
         return false;
     }
     // Set the redirect based on the task.
     switch (Request::getCmd('task')) {
         case 'apply':
             App::redirect(Route::url('index.php?option=' . $this->_option . '&view=component&component=' . $option . '&tmpl=component&path=' . $model->getState('component.path') . '&refresh=1', false), Lang::txt('COM_CONFIG_SAVE_SUCCESS'));
             break;
         case 'save':
         default:
             App::redirect(Route::url('index.php?option=' . $this->_option . '&view=close&tmpl=component&path=' . $model->getState('component.path'), false));
             break;
     }
 }