Exemple #1
0
 function display($tpl = null)
 {
     $configHelper = new JXConfig();
     $my = JFactory::getUser();
     $defaultLang = JText::_('JXLIB_DEFAULT_LANGUAGE');
     $defaultTz = JText::_('JXLIB_DEFAULT_TIMEZONE');
     $defaultInvite = JXConfig::DISALLOW;
     $defaultAnon = JXConfig::ALLOW;
     // Additional Configuration which are not Joomla! native variables
     $siteName = $configHelper->get(JXConfig::SITENAME) == '' ? '' : $configHelper->get(JXConfig::SITENAME);
     $timeZone = $configHelper->getTimezone();
     $language = $configHelper->getLanguage();
     $allowAnon = $configHelper->get(JXConfig::ALLOW_ANON) == '' ? $defaultAnon : $configHelper->get(JXConfig::ALLOW_ANON);
     $allowInvite = $configHelper->get(JXConfig::ALLOW_INVITE) == '' ? $defaultInvite : $configHelper->get(JXConfig::ALLOW_INVITE);
     $limitEmailDomain = $configHelper->get(JXConfig::LIMIT_EMAIL_DOMAIN) == '' ? '' : $configHelper->get(JXConfig::LIMIT_EMAIL_DOMAIN);
     $domainName = $configHelper->getDomainName(true) == '' ? '' : $configHelper->getDomainName(true);
     //overwrite value with postParam when save error
     $error = array();
     if ($_POST) {
         $postParam = JRequest::getVar('params');
         $timeZone = isset($postParam['timezone']) ? $postParam['timezone'] : $timeZone;
         $language = isset($postParam['language']) ? $postParam['language'] : $language;
         $siteName = isset($postParam['sitename']) ? $postParam['sitename'] : $configHelper->get('sitename');
         $allowInvite = isset($postParam['allow_invite']) ? $postParam['allow_invite'] : $allowInvite;
         $limitEmailDomain = isset($postParam['limit_email_domain']) ? $postParam['limit_email_domain'] : $limitEmailDomain;
         $domainName = isset($postParam['domain_name']) ? $postParam['domain_name'] : $domainName;
     }
     $form = JForm::getInstance('profileForm', JPATH_ROOT . DS . 'components' . DS . 'com_profile' . DS . 'models' . DS . 'forms' . DS . 'edit.xml');
     $this->assignRef('profileForm', $form);
     $this->assignRef('my', $my);
     $this->assignRef('sitename', $siteName);
     $this->assignRef('default_timezone', $timeZone);
     $this->assignRef('default_language', $language);
     $this->assignRef('domain_name', $domainName);
     $this->assignRef('limit_email_domain', $limitEmailDomain);
     $this->assignRef('allow_invite', $allowInvite);
     $this->assignRef('allow_anon', $allowAnon);
     $this->assign('domain_editable', $configHelper->allowChangeDomain());
     $doc = JFactory::getDocument();
     $doc->setTitle(JText::_("COM_ACCOUNT_LABEL_ACCOUNT_SETTING"));
     parent::display($tpl);
 }
Exemple #2
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();
 }