Esempio n. 1
0
 /**
  * Method to save global configuration.
  *
  * @return  boolean  True on success.
  *
  * @since   3.2
  */
 public function execute()
 {
     // Check for request forgeries.
     if (!JSession::checkToken()) {
         $this->app->enqueueMessage(JText::_('JINVALID_TOKEN'));
         $this->app->redirect('index.php');
     }
     // Check if the user is authorized to do this.
     if (!JFactory::getUser()->authorise('core.admin')) {
         $this->app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'));
         $this->app->redirect('index.php');
     }
     // Set FTP credentials, if given.
     JClientHelper::setCredentialsFromRequest('ftp');
     $model = new ConfigModelConfig();
     $form = $model->getForm();
     $data = $this->input->post->get('jform', array(), 'array');
     // Validate the posted data.
     $return = $model->validate($form, $data);
     // Check for validation errors.
     if ($return === false) {
         /*
          * The validate method enqueued all messages for us, so we just need to redirect back.
          */
         // Save the data in the session.
         $this->app->setUserState('com_config.config.global.data', $data);
         // Redirect back to the edit screen.
         $this->app->redirect(JRoute::_('index.php?option=com_config&controller=config.display.config', false));
     }
     // Attempt to save the configuration.
     $data = $return;
     // Access back-end com_config
     JLoader::registerPrefix('Config', JPATH_ADMINISTRATOR . '/components/com_config');
     $saveClass = new ConfigControllerApplicationSave();
     // Get a document object
     $document = JFactory::getDocument();
     // Set back-end required params
     $document->setType('json');
     // Execute back-end controller
     $return = $saveClass->execute();
     // Reset params back after requesting from service
     $document->setType('html');
     // Check the return value.
     if ($return === false) {
         /*
          * The save method enqueued all messages for us, so we just need to redirect back.
          */
         // Save the data in the session.
         $this->app->setUserState('com_config.config.global.data', $data);
         // Save failed, go back to the screen and display a notice.
         $this->app->redirect(JRoute::_('index.php?option=com_config&controller=config.display.config', false));
     }
     // Redirect back to com_config display
     $this->app->enqueueMessage(JText::_('COM_CONFIG_SAVE_SUCCESS'));
     $this->app->redirect(JRoute::_('index.php?option=com_config&controller=config.display.config', false));
     return true;
 }
Esempio n. 2
0
 /**
  * Method to handle any login logic and report back to the subject.
  *
  * @param   array  $user     Holds the user data.
  * @param   array  $options  Array holding options (remember, autoregister, group).
  *
  * @return  boolean  True on success.
  *
  * @since   1.5
  */
 public function onUserLogin($user, $options = array())
 {
     $menu = $this->app->getMenu();
     if ($this->app->isSite() && $this->params->get('automatic_change', 1)) {
         $assoc = JLanguageAssociations::isEnabled();
         $lang_code = $user['language'];
         if (empty($lang_code)) {
             $lang_code = $this->default_lang;
         }
         // Get a 1-dimensional array of published language codes
         $query = $this->db->getQuery(true)->select($this->db->quoteName('a.lang_code'))->from($this->db->quoteName('#__languages', 'a'))->where($this->db->quoteName('published') . ' = 1');
         $this->db->setQuery($query);
         $lang_codes = $this->db->loadColumn();
         // The user language has been deleted/disabled or the related content language does not exist/has been unpublished
         // or the related home page does not exist/has been unpublished
         if (!array_key_exists($lang_code, MultilangstatusHelper::getSitelangs()) || !in_array($lang_code, $lang_codes) || !array_key_exists($lang_code, MultilangstatusHelper::getHomepages())) {
             $lang_code = $this->current_lang;
         }
         // Try to get association from the current active menu item
         $active = $menu->getActive();
         $foundAssociation = false;
         if ($active) {
             if ($assoc) {
                 $associations = MenusHelper::getAssociations($active->id);
             }
             if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code])) {
                 $associationItemid = $associations[$lang_code];
                 $this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $associationItemid);
                 $foundAssociation = true;
             } elseif ($active->home) {
                 // We are on a Home page, we redirect to the user site language home page
                 $item = $menu->getDefault($lang_code);
                 if ($item && $item->language != $active->language && $item->language != '*') {
                     $this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $item->id);
                     $foundAssociation = true;
                 }
             }
         }
         if ($foundAssociation && $lang_code != $this->current_lang) {
             // Change language.
             $this->current_lang = $lang_code;
             // Create a cookie.
             $this->setLanguageCookie($lang_code);
             // Change the language code.
             JFactory::getLanguage()->setLanguage($lang_code);
         }
     }
 }
 /**
  * Method to handle any login logic and report back to the subject.
  *
  * @param   array  $user     Holds the user data.
  * @param   array  $options  Array holding options (remember, autoregister, group).
  *
  * @return  boolean  True on success.
  *
  * @since   1.5
  */
 public function onUserLogin($user, $options = array())
 {
     $menu = $this->app->getMenu();
     if ($this->app->isSite() && $this->params->get('automatic_change', 1)) {
         $assoc = JLanguageAssociations::isEnabled();
         $lang_code = $user['language'];
         // If no language is specified for this user, we set it to the site default language
         if (empty($lang_code)) {
             $lang_code = $this->default_lang;
         }
         jimport('joomla.filesystem.folder');
         // The language has been deleted/disabled or the related content language does not exist/has been unpublished
         // or the related home page does not exist/has been unpublished
         if (!array_key_exists($lang_code, $this->lang_codes) || !array_key_exists($lang_code, JLanguageMultilang::getSiteHomePages()) || !JFolder::exists(JPATH_SITE . '/language/' . $lang_code)) {
             $lang_code = $this->current_lang;
         }
         // Try to get association from the current active menu item
         $active = $menu->getActive();
         $foundAssociation = false;
         if ($active) {
             if ($assoc) {
                 $associations = MenusHelper::getAssociations($active->id);
             }
             if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code])) {
                 $associationItemid = $associations[$lang_code];
                 $this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $associationItemid);
                 $foundAssociation = true;
             } elseif ($active->home) {
                 // We are on a Home page, we redirect to the user site language home page
                 $item = $menu->getDefault($lang_code);
                 if ($item && $item->language != $active->language && $item->language != '*') {
                     $this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $item->id);
                     $foundAssociation = true;
                 }
             }
         }
         if ($foundAssociation && $lang_code != $this->current_lang) {
             // Change language.
             $this->current_lang = $lang_code;
             // Create a cookie.
             $this->setLanguageCookie($lang_code);
             // Change the language code.
             JFactory::getLanguage()->setLanguage($lang_code);
         }
     }
 }
Esempio n. 4
0
 /**
  * Validates uploaded files from a form.
  *
  * @param   array                    $files             Array containing the files to validate.
  * @param   array                    $data              Other data from the form.
  * @param   MonitorModelAttachments  $modelAttachments  Model to use.
  *
  * @return  array|null  A filtered array if all files are valid, null if not.
  */
 public function validateFiles($files, $data, $modelAttachments = null)
 {
     if (!$modelAttachments) {
         $modelAttachments = new MonitorModelAttachments($this->app);
     }
     foreach ($files as $i => $file) {
         if ($file[0]['error'] === UPLOAD_ERR_NO_FILE) {
             unset($files[$i]);
         }
     }
     if (!$modelAttachments->canUpload($files)) {
         // Store data for redirects.
         if (!$this->form) {
             $this->loadForm();
         }
         $this->app->setUserState($this->form->getName() . '.data', $data);
         return null;
     }
     return $files;
 }
Esempio n. 5
0
 /**
  * Method to handle any login logic and report back to the subject.
  *
  * @param   array  $user     Holds the user data.
  * @param   array  $options  Array holding options (remember, autoregister, group).
  *
  * @return  boolean  True on success.
  *
  * @since   1.5
  */
 public function onUserLogin($user, $options = array())
 {
     $menu = $this->app->getMenu();
     if ($this->app->isSite() && $this->params->get('automatic_change', 1)) {
         // Load associations.
         $assoc = JLanguageAssociations::isEnabled();
         if ($assoc) {
             $active = $menu->getActive();
             if ($active) {
                 $associations = MenusHelper::getAssociations($active->id);
             }
         }
         $lang_code = $user['language'];
         if (empty($lang_code)) {
             $lang_code = $this->default_lang;
         }
         if ($lang_code != $this->default_lang) {
             // Change language.
             $this->default_lang = $lang_code;
             // Create a cookie.
             $cookie_domain = $this->app->get('cookie_domain', '');
             $cookie_path = $this->app->get('cookie_path', '/');
             setcookie(JApplicationHelper::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
             // Change the language code.
             JFactory::getLanguage()->setLanguage($lang_code);
             // Change the redirect (language has changed).
             if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code])) {
                 $itemid = $associations[$lang_code];
                 $this->app->setUserState('users.login.form.return', 'index.php?&Itemid=' . $itemid);
             } else {
                 JLoader::register('MultilangstatusHelper', JPATH_ADMINISTRATOR . '/components/com_languages/helpers/multilangstatus.php');
                 $homes = MultilangstatusHelper::getHomepages();
                 $itemid = isset($homes[$lang_code]) ? $homes[$lang_code]->id : $homes['*']->id;
                 $this->app->setUserState('users.login.form.return', 'index.php?&Itemid=' . $itemid);
             }
         }
     }
 }
Esempio n. 6
0
 /**
  * Method to save global configuration.
  *
  * @return  mixed  Calls $app->redirect() for all cases except JSON
  *
  * @since   3.2
  */
 public function execute()
 {
     // Check for request forgeries.
     if (!JSession::checkToken()) {
         $this->app->enqueueMessage(JText::_('JINVALID_TOKEN'));
         $this->app->redirect('index.php');
     }
     // Check if the user is authorized to do this.
     if (!JFactory::getUser()->authorise('core.admin')) {
         $this->app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'));
         $this->app->redirect('index.php');
     }
     // Set FTP credentials, if given.
     JClientHelper::setCredentialsFromRequest('ftp');
     $model = new ConfigModelApplication();
     $data = $this->input->post->get('jform', array(), 'array');
     // Complete data array if needed
     $oldData = $model->getData();
     $data = array_replace($oldData, $data);
     // Get request type
     $saveFormat = JFactory::getDocument()->getType();
     // Handle service requests
     if ($saveFormat == 'json') {
         return $model->save($data);
     }
     // Must load after serving service-requests
     $form = $model->getForm();
     // Validate the posted data.
     $return = $model->validate($form, $data);
     // Check for validation errors.
     if ($return === false) {
         /*
          * The validate method enqueued all messages for us, so we just need to redirect back.
          */
         // Save the data in the session.
         $this->app->setUserState('com_config.config.global.data', $data);
         // Redirect back to the edit screen.
         $this->app->redirect(JRoute::_('index.php?option=com_config&controller=config.display.application', false));
     }
     // Attempt to save the configuration.
     $data = $return;
     $return = $model->save($data);
     // Check the return value.
     if ($return === false) {
         /*
          * The save method enqueued all messages for us, so we just need to redirect back.
          */
         // Save the data in the session.
         $this->app->setUserState('com_config.config.global.data', $data);
         // Save failed, go back to the screen and display a notice.
         $this->app->redirect(JRoute::_('index.php?option=com_config&controller=config.display.application', false));
     }
     // Set the success message.
     $this->app->enqueueMessage(JText::_('COM_CONFIG_SAVE_SUCCESS'));
     // Set the redirect based on the task.
     switch ($this->options[3]) {
         case 'apply':
             $this->app->redirect(JRoute::_('index.php?option=com_config', false));
             break;
         case 'save':
         default:
             $this->app->redirect(JRoute::_('index.php', false));
             break;
     }
 }
Esempio n. 7
0
 /**
  * Method to save global configuration.
  *
  * @return  mixed  Calls $app->redirect()
  *
  * @since   3.2
  */
 public function execute()
 {
     // Check for request forgeries.
     if (!JSession::checkToken()) {
         $this->app->enqueueMessage(JText::_('JINVALID_TOKEN'));
         $this->app->redirect('index.php');
     }
     // Set FTP credentials, if given.
     JClientHelper::setCredentialsFromRequest('ftp');
     $model = new ConfigModelComponent();
     $form = $model->getForm();
     $data = $this->input->get('jform', array(), 'array');
     $id = $this->input->getInt('id');
     $option = $this->input->get('component');
     // Check if the user is authorized to do this.
     if (!JFactory::getUser()->authorise('core.admin', $option)) {
         $this->app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'));
         $this->app->redirect('index.php');
     }
     $returnUri = $this->input->post->get('return', null, 'base64');
     $redirect = '';
     if (!empty($returnUri)) {
         $redirect = '&return=' . urlencode($returnUri);
     }
     // Validate the posted data.
     $return = $model->validate($form, $data);
     // Check for validation errors.
     if ($return === false) {
         /*
          * The validate method enqueued all messages for us, so we just need to redirect back.
          */
         // Save the data in the session.
         $this->app->setUserState('com_config.config.global.data', $data);
         // Redirect back to the edit screen.
         $this->app->redirect(JRoute::_('index.php?option=com_config&view=component&component=' . $option . $redirect, false));
     }
     // Attempt to save the configuration.
     $data = array('params' => $return, 'id' => $id, 'option' => $option);
     try {
         $model->save($data);
     } catch (RuntimeException $e) {
         // Save the data in the session.
         $this->app->setUserState('com_config.config.global.data', $data);
         // Save failed, go back to the screen and display a notice.
         $this->app->enqueueMessage(JText::sprintf('JERROR_SAVE_FAILED', $e->getMessage()), 'error');
         $this->app->redirect(JRoute::_('index.php?option=com_config&view=component&component=' . $option . $redirect, false));
     }
     // Set the redirect based on the task.
     switch ($this->options[3]) {
         case 'apply':
             $this->app->enqueueMessage(JText::_('COM_CONFIG_SAVE_SUCCESS'));
             $this->app->redirect(JRoute::_('index.php?option=com_config&view=component&component=' . $option . $redirect, false));
             break;
         case 'save':
         default:
             $redirect = 'index.php?option=' . $option;
             if (!empty($returnUri)) {
                 $redirect = base64_decode($returnUri);
             }
             $this->app->redirect(JRoute::_($redirect, false));
             break;
     }
     return true;
 }
Esempio n. 8
0
 /**
  * Store filters in the registry
  *
  * @param   array  $request  filters to store
  *
  * @return  void
  */
 public function storeRequestData($request)
 {
     $package = $this->app->getUserState('com_fabrik.package', 'fabrik');
     $input = $this->app->input;
     $registry = $this->session->get('registry');
     $option = 'com_' . $package;
     $tid = 'list' . $this->getRenderContext();
     // Make sure that we only store data thats been entered from this page first test we aren't in a plugin
     if ($input->get('option') == $option && is_object($registry)) {
         // Don't do this when you are viewing a form or details page as it wipes out the table filters
         $reg = $registry->get('_registry');
         if (isset($reg[$option]) && !in_array($input->get('view'), array('form', 'details'))) {
             unset($reg[$option]['data']->{$tid}->filter);
         }
     }
     $context = $option . '.' . $tid . '.filter';
     // @TODO test for _clear_ in values and if so delete session data
     foreach ($request as $key => $val) {
         if (is_array($val)) {
             $key = $context . '.' . $key;
             $this->app->setUserState($key, array_values($val));
         }
     }
 }