Exemple #1
0
 /**
  * 	Save the configuration to component
  *
  *  @return void
  *  @since  1.0
  */
 function save()
 {
     // Check for request forgeries.
     JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     // Set FTP credentials, if given.
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     // Initialise variables.
     $app = JFactory::getApplication();
     $model = $this->getModel('configuration');
     $form = $model->getForm();
     $data = JRequest::getVar('jform', array(), 'post', 'array');
     $id = JRequest::getInt('id');
     $option = "com_newsletter";
     // Check if the user is authorized to do this.
     if (!AclHelper::canConfigureComponent()) {
         AclHelper::redirectToAccessDenied();
         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 (JError::isError($errors[$i])) {
                 $app->enqueueMessage($errors[$i]->getMessage(), 'warning');
             } else {
                 $app->enqueueMessage($errors[$i], 'warning');
             }
         }
         // Save the data in the session.
         $app->setUserState('com_newsletter.config.global.data', $data);
         // Redirect back to the edit screen.
         $this->setRedirect(JRoute::_('index.php?option=com_newsletter&view=configuration', false));
         return false;
     }
     // Attempt to save the configuration.
     $data = array('params' => $return, 'id' => $id, 'option' => $option);
     $newsletter = JModel::getInstance('Newsletter', 'NewsletterModelEntity');
     $newsletter->loadFallBackNewsletter();
     $newsletter->subject = $data['params']['confirm_mail_subject'];
     $newsletter->plain = $data['params']['confirm_mail_body'];
     $return2 = $newsletter->save();
     unset($data['params']['confirm_mail_subject']);
     unset($data['params']['confirm_mail_body']);
     $data['option'] = 'com_newsletter';
     $return = $model->save($data);
     // Check the return value.
     if ($return2 === false || $return === false) {
         // Save the data in the session.
         $app->setUserState('com_newsletter.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('index.php?option=com_newsletter&view=configuration', $message, 'error');
         return false;
     }
     // Set the redirect based on the task.
     switch ($this->getTask()) {
         case 'apply':
             $message = JText::_('COM_NEWSLETTER_SAVE_SUCCESS');
             $this->setRedirect('index.php?option=com_newsletter&view=configuration', $message);
             break;
         case 'save':
         default:
             $this->setRedirect('index.php?option=com_newsletter&view=configuration');
             break;
     }
     JFactory::getCache('com_newsletter')->clean();
     $this->licDontCheck = true;
     return true;
 }
Exemple #2
0
defined('_JEXEC') or die('Restricted access');
//  Uncoment this rows for debug
//  ini_set('error_reporting', E_ALL | E_NOTICE);
//  ini_set('display_errors', '1');
//  ini_set("log_errors" , "0");
//  ini_set("error_log" , "/var/log/php-error.log");
try {
    // import joomla controller library
    jimport('joomla.application.component.controller');
    jimport('joomla.application.component.view');
    jimport('joomla.form.helper');
    jimport('migur.migur');
    JLoader::import('helpers.acl', JPATH_COMPONENT_ADMINISTRATOR, '');
    // First check if user has access to the component.
    if (!AclHelper::canAccessComponent()) {
        AclHelper::redirectToAccessDenied();
    }
    // Add the helper
    JLoader::import('helpers.javascript', JPATH_COMPONENT_ADMINISTRATOR, '');
    JLoader::import('helpers.rssfeed', JPATH_COMPONENT_ADMINISTRATOR, '');
    JLoader::import('helpers.newsletter', JPATH_COMPONENT_ADMINISTRATOR, '');
    JLoader::import('helpers.log', JPATH_COMPONENT_ADMINISTRATOR, '');
    JHtml::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'html');
    // Add translations used in JavaScript
    JavascriptHelper::requireTranslations();
    // Load 'Migur' group of plugins
    JPluginHelper::importPlugin('migur');
    $app = JFactory::getApplication();
    $app->triggerEvent('onMigurNewsletterStart');
    // Handle the messages from previous requests
    $sess = JFactory::getSession();