Beispiel #1
0
 /**
  *
  * This function to helper save configs for the component
  *
  * @param: (Number) ($componentId) is id of component in extension table
  * @param: (string) ($componentName) is name of component
  * @param: (Array) ($config) is array store key and value to save
  * @return: Save to the database table
  */
 public static function extension($extension_name, $configs = array())
 {
     // Import files used for Joomla 3.2
     JSNFactory::import('plugins.system.jsnframework.libraries.joomlashine.version.version', 'site');
     // Import files for Joomla 3.2
     if (JSNVersion::isJoomlaCompatible('3.2')) {
         JSNFactory::import('components.com_config.model.cms', 'site');
         JSNFactory::import('components.com_config.model.form', 'site');
     }
     $extension_name = JString::strtolower(JString::trim($extension_name));
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select("params");
     $query->from("#__extensions");
     $query->where("name = " . $db->quote($extension_name));
     $db->setQuery($query);
     $paramsString = $db->loadResult();
     if (!empty($paramsString)) {
         $jParams = new JRegistry();
         //$jParams = new JParameter();
         $jParams->loadObject(json_decode($paramsString));
         $params = $jParams->toArray();
         foreach ($configs as $k => $val) {
             $params[$k] = (string) $val;
         }
         $query->clear();
         $query->select("extension_id");
         $query->from("#__extensions");
         $query->where("name=" . $db->quote(JString::strtolower($extension_name)));
         $db->setQuery($query);
         $ext_id = $db->loadResult();
         JSNFactory::import('components.com_config.model.component');
         $config = new ConfigModelComponent();
         $config->save(array('params' => $params, 'id' => $ext_id, 'option' => $extension_name));
         return true;
     }
     return false;
 }
Beispiel #2
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;
 }
Beispiel #3
0
 /**
  * Instantiates a new component configuration model
  * from Joomla! own com_config
  *
  * @param string $component name of component for which the model should be initialized
  * @param string $path path to a folder where config xml file can be found
  * @return ConfigModelComponent
  */
 public static function getComConfigComponentModel($component = 'com_sh404sef', $path = '')
 {
     require_once JPATH_ROOT . '/administrator/components/com_config/models/component.php';
     $comConfigModel = new ConfigModelComponent(array('ignore_request' => true));
     $comConfigModel->setState('component.option', $component);
     if (!empty($path)) {
         $comConfigModel->setState('component.path', $path);
     }
     return $comConfigModel;
 }
Beispiel #4
0
 /**
  * Save the parameters
  */
 public function save($key = null, $urlVar = null)
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     // Get the old component parameters
     jimport('joomla.application.component.helper');
     $old_params = JComponentHelper::getParams('com_attachments');
     $old_secure = JRequest::getInt('old_secure');
     // Set FTP credentials, if given.
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     // Initialise variables.
     $model = new ConfigModelComponent();
     $form = $model->getForm();
     $data = JRequest::getVar('jform', array(), 'post', 'array');
     $id = JRequest::getInt('id');
     $option = JRequest::getCmd('component');
     // Get the new component parameters
     $new_secure = $data['secure'];
     // Check if the user is authorized to do this.
     if (!JFactory::getUser()->authorise('core.admin', $option)) {
         JFactory::getApplication()->redirect('index.php', JText::_('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) {
                 $app->enqueueMessage($errors[$i]->getMessage(), 'warning');
             } else {
                 $app->enqueueMessage($errors[$i], 'warning');
             }
         }
         // Save the data in the session.
         $app->setUserState('com_config.config.global.data', $data);
         // Redirect back to the edit screen.
         $this->setRedirect(JRoute::_('index.php?option=com_attachments&task=params.edit', 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.
         $app->setUserState('com_config.config.global.data', $data);
         // Save failed, go back to the screen and display a notice.
         $message = JText::sprintf('JERROR_SAVE_FAILED', $model->getError());
         $this->setRedirect(JRoute::_('index.php?option=com_attachments&task=params.edit'), $message, 'error');
         return false;
     }
     // Deal with any changes in the 'secure mode' (or upload directories)
     if ($new_secure != $old_secure) {
         // Check/update the security status
         require_once JPATH_SITE . '/components/com_attachments/helper.php';
         $attach_dir = JPATH_SITE . '/' . AttachmentsDefines::$ATTACHMENTS_SUBDIR;
         AttachmentsHelper::setup_upload_directory($attach_dir, $new_secure == 1);
         $msg = JText::_('ATTACH_UPDATED_ATTACHMENTS_PARAMETERS_AND_SECURITY_SETTINGS');
     } else {
         $msg = JText::_('ATTACH_UPDATED_ATTACHMENTS_PARAMETERS');
     }
     // Set the redirect based on the task.
     switch ($this->getTask()) {
         case 'apply':
             $this->setRedirect('index.php?option=com_attachments&task=params.edit', $msg, 'message');
             break;
         case 'save':
         default:
             $this->setRedirect('index.php?option=com_attachments', $msg, 'message');
             break;
     }
     return true;
 }
Beispiel #5
0
 function save($data)
 {
     $app = JFactory::getApplication();
     if (file_exists(JPATH_SITE . '/components/com_config/model/cms.php')) {
         require_once JPATH_SITE . '/components/com_config/model/cms.php';
     }
     if (file_exists(JPATH_SITE . '/components/com_config/model/form.php')) {
         require_once JPATH_SITE . '/components/com_config/model/form.php';
     }
     if (file_exists(JPATH_ADMINISTRATOR . '/components/com_config/model/component.php')) {
         require_once JPATH_ADMINISTRATOR . '/components/com_config/model/component.php';
     }
     if (file_exists(JPATH_ADMINISTRATOR . '/components/com_config/models/component.php')) {
         require_once JPATH_ADMINISTRATOR . '/components/com_config/models/component.php';
     }
     $model = new ConfigModelComponent();
     //Get joomdle extension id
     $db = JFactory::getDBO();
     $query = 'SELECT extension_id ' . ' FROM #__extensions' . " WHERE name = 'com_joomdle'";
     $db->setQuery($query);
     $extension_id = $db->loadResult();
     $option = 'com_joomdle';
     $data = array('params' => $data, 'id' => $extension_id, 'option' => $option);
     $return = $model->save($data);
     return $return;
 }
Beispiel #6
0
 function save($data)
 {
     $app = JFactory::getApplication();
     if (file_exists(JPATH_SITE . '/components/com_config/model/cms.php')) {
         require_once JPATH_SITE . '/components/com_config/model/cms.php';
     }
     if (file_exists(JPATH_SITE . '/components/com_config/model/form.php')) {
         require_once JPATH_SITE . '/components/com_config/model/form.php';
     }
     if (file_exists(JPATH_ADMINISTRATOR . '/components/com_config/model/component.php')) {
         require_once JPATH_ADMINISTRATOR . '/components/com_config/model/component.php';
     }
     if (file_exists(JPATH_ADMINISTRATOR . '/components/com_config/models/component.php')) {
         require_once JPATH_ADMINISTRATOR . '/components/com_config/models/component.php';
     }
     $model = new ConfigModelComponent();
     //Get joomdle extension id
     $db = JFactory::getDBO();
     $query = 'SELECT extension_id ' . ' FROM #__extensions' . " WHERE name = 'com_joomdle'";
     $db->setQuery($query);
     $extension_id = $db->loadResult();
     $option = 'com_joomdle';
     // Generate auth token if needed
     if ($data['joomla_auth_token'] == '') {
         $token = JUserHelper::genRandomPassword(32);
         $token = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $token);
         $data['joomla_auth_token'] = $token;
     }
     $data = array('params' => $data, 'id' => $extension_id, 'option' => $option);
     $return = $model->save($data);
     return $return;
 }