Esempio n. 1
0
 public function display($cachable = false, $urlparams = false)
 {
     if ($_POST) {
         $proceedSave = true;
         $configHelper = new JXConfig();
         $mainframe = JFactory::getApplication();
         // Set the posted data to update the configuration
         $postdata = JRequest::getVar('params');
         $param[JXConfig::TIMEZONE] = $postdata['timezone'];
         $param[JXConfig::LANGUAGE] = $postdata['language'];
         $param[JXConfig::SITENAME] = $postdata['sitename'];
         $param[JXConfig::ALLOW_INVITE] = isset($postdata['allow_invite']) ? intval($postdata['allow_invite']) : '0';
         $param[JXConfig::ALLOW_ANON] = isset($postdata['allow_anon']) ? intval($postdata['allow_anon']) : '0';
         // Check list of limit email domains and append limit email list into param
         $limitEmailDomain = JXConfig::LIMIT_EMAIL_DOMAIN;
         if (empty($postdata['limit_email_domain'])) {
             $param[$limitEmailDomain] = '';
         } else {
             $arrEmailDomain = explode(',', $postdata['limit_email_domain']);
             $arrEmailDomain = $this->_cleanEmailDomain($arrEmailDomain);
             if (is_array($arrEmailDomain)) {
                 $param[$limitEmailDomain] = implode(',', $arrEmailDomain);
             } elseif ($arrEmailDomain === false) {
                 $mainframe->enqueueMessage(JText::_('COM_ACCOUNT_ERRMSG_INVALID_EMAIL_DOMAIN_PROVIDED'), 'error');
                 $proceedSave = false;
             }
         }
         // Default to no domain changed
         $updatedDomain = false;
         // Only allow to change domain if registered user does not exceed the predefined number in JXConfig
         if ($configHelper->allowChangeDomain() && $proceedSave) {
             // This part needs to identify if the domain is changed and need to perform cURL to change the domain at signup.offiria.com
             if ($postdata['domain_name'] != $configHelper->getDomainName()) {
                 // New domain is valid and can be changed
                 if (preg_match('/^[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*$/', $postdata['domain_name'])) {
                     // Use library function to do cURL request to signup.offiria.com to check if domain can be used
                     $sanitizedDomain = $configHelper->sanitizeDomain(strtolower($postdata['domain_name']));
                     // cURL shows domain can be used
                     if ($sanitizedDomain['error'] === false) {
                         $user = JXFactory::getUser();
                         // perform another cURL to change the domain
                         $updateCurl = $configHelper->updateDomain($user->get('username'), $configHelper->getDomainName(), $sanitizedDomain['msg']);
                         // Domain changed successfully
                         if ($updateCurl['error'] === false) {
                             $updatedDomain = true;
                             $param[JXConfig::DOMAIN_NAME] = $sanitizedDomain['msg'];
                         } else {
                             $updatedDomain = false;
                             $sanitizedDomain['error'] = true;
                             $sanitizedDomain['msg'] = $updateCurl['msg'] . ' Please contact the site administrator for more information.';
                         }
                     }
                 } else {
                     $sanitizedDomain['error'] = true;
                     $sanitizedDomain['msg'] = JText::sprintf('COM_ACCOUNT_ERRMSG_INVALID_ITEM', JText::_('COM_ACCOUNT_LABEL_DOMAIN_NAME'));
                 }
             }
             // IF there is error from Curl Sanitize domain
             if (isset($sanitizedDomain['error']) && $sanitizedDomain['error'] === true) {
                 $mainframe->enqueueMessage($sanitizedDomain['msg'], 'error');
                 $proceedSave = false;
             }
         }
         // If everything is safe and sound to proceed saving, then only write into configuration.php
         if ($proceedSave) {
             $saveAction = $configHelper->saveConfig($param);
             /* Redirect to clear the previous post values */
             if (!$updatedDomain) {
                 $newUrl = JRoute::_('index.php?option=com_account&view=account', false);
             } else {
                 $jUri = JURI::getInstance();
                 $newUrl = $jUri->toString(array('scheme')) . $param[JXConfig::DOMAIN_NAME] . $configHelper->getDomainSuffix();
             }
             // if failed to save into configuration.php
             if (!$saveAction) {
                 $mainframe->enqueueMessage(JText::_('COM_ACCOUNT_ACTION_SAVE_SETTING_FAIL'), 'error');
             } else {
                 /* Redirect to clear the previous post values */
                 $mainframe->redirect($newUrl, JText::_('COM_ACCOUNT_ACTION_SAVE_SETTING_SUCCESS'));
             }
         }
     }
     parent::display();
 }