Example #1
0
 private function validateForm()
 {
     if ($this->form->isSubmitted()) {
         $fields = $this->form->getFields();
         if (!$fields['start_date']->isFilled(Language::err('FieldIsRequired')) || !$fields['end_date']->isFilled(Language::err('FieldIsRequired'))) {
             return;
         }
         if (!$fields['start_date']->isValid(Language::err('DateIsInvalid')) || !$fields['end_date']->isValid(Language::err('DateIsInvalid'))) {
             return;
         }
         $newStartDate = Model::getUTCTimestamp($fields['start_date']);
         $newEndDate = Model::getUTCTimestamp($fields['end_date']);
         // startdate cannot be before 2005 (earliest valid google startdate)
         if ($newStartDate < mktime(0, 0, 0, 1, 1, 2005)) {
             $fields['start_date']->setError(BL::err('DateRangeIsInvalid'));
         }
         // enddate cannot be in the future
         if ($newEndDate > time()) {
             $fields['start_date']->setError(BL::err('DateRangeIsInvalid'));
         }
         // enddate cannot be before the startdate
         if ($newStartDate > $newEndDate) {
             $fields['start_date']->setError(BL::err('DateRangeIsInvalid'));
         }
         if ($this->form->isCorrect()) {
             $this->startDate = $newStartDate;
             $this->endDate = $newEndDate;
         }
     }
 }
 /**
  * @return bool
  */
 public function handle()
 {
     $this->form->cleanupFields();
     if (!$this->form->isSubmitted() || !$this->isValid()) {
         return false;
     }
     $this->settings->set('Analytics', 'web_property_id', $this->form->getField('web_property_id')->getValue());
     return true;
 }
 /**
  * @return bool
  */
 public function handle()
 {
     $this->form->cleanupFields();
     if (!$this->form->isSubmitted() || !$this->isValid()) {
         return false;
     }
     $certificate = base64_encode(file_get_contents($this->form->getField('certificate')->getTempFileName()));
     $this->settings->set('Analytics', 'certificate', $certificate);
     $this->settings->set('Analytics', 'email', $this->form->getField('email')->getValue());
     return true;
 }
Example #4
0
 /**
  * @return bool
  */
 public function handle()
 {
     $this->form->cleanupFields();
     if (!$this->form->isSubmitted() || !$this->isValid()) {
         return false;
     }
     $fields = $this->form->getFields();
     $newStartDate = Model::getUTCTimestamp($fields['start_date']);
     $newEndDate = Model::getUTCTimestamp($fields['end_date']);
     $this->dateRange->update($newStartDate, $newEndDate);
     return true;
 }
 /**
  * Handles the form
  *
  * @return bool
  */
 public function handle()
 {
     if (!$this->form->isSubmitted() || !$this->isValid()) {
         return false;
     }
     $fields = $this->form->getFields();
     // we already have a teammember? Let's update
     if ($this->teamMember instanceof TeamMember) {
         $this->teamMember->change($this->meta->save(), $fields['name']->getValue(), $fields['description']->getValue());
         return true;
     }
     // time to create a new entity
     $this->teamMember = TeamMember::create($this->meta->save(), Language::getWorkingLanguage(), $fields['name']->getValue(), $fields['description']->getValue());
     return true;
 }
Example #6
0
 /**
  * Validates the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // no errors ?
         if ($this->frm->isCorrect()) {
             // smtp settings
             $this->get('fork.settings')->set('Core', 'seo_noodp', $this->frm->getField('seo_noodp')->getValue());
             $this->get('fork.settings')->set('Core', 'seo_noydir', $this->frm->getField('seo_noydir')->getValue());
             $this->get('fork.settings')->set('Core', 'seo_nofollow_in_comments', $this->frm->getField('seo_nofollow_in_comments')->getValue());
             // assign report
             $this->tpl->assign('report', true);
             $this->tpl->assign('reportMessage', BL::msg('Saved'));
         }
     }
 }
Example #7
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         // shorten fields
         $newPassword = $this->frm->getField('backend_new_password');
         $newPasswordRepeated = $this->frm->getField('backend_new_password_repeated');
         // required fields
         $newPassword->isFilled(BL::err('PasswordIsRequired'));
         $newPasswordRepeated->isFilled(BL::err('PasswordRepeatIsRequired'));
         // all fields are ok?
         if ($newPassword->isFilled() && $newPasswordRepeated->isFilled()) {
             // the passwords entered match
             if ($newPassword->getValue() !== $newPasswordRepeated->getValue()) {
                 // add error
                 $this->frm->addError(BL::err('PasswordsDontMatch'));
                 // show error
                 $this->tpl->assign('error', BL::err('PasswordsDontMatch'));
             }
         }
         if ($this->frm->isCorrect()) {
             // change the users password
             BackendUsersModel::updatePassword($this->user, $newPassword->getValue());
             // attempt to login the user
             if (!BackendAuthentication::loginUser($this->user->getEmail(), $newPassword->getValue())) {
                 // redirect to the login form with an error
                 $this->redirect(BackendModel::createURLForAction('Index', null, null, array('login' => 'failed')));
             }
             // redirect to the login form
             $this->redirect(BackendModel::createUrlForAction('Index', 'Dashboard', null, array('password_reset' => 'success')));
         }
     }
 }
Example #8
0
 /**
  * Add all element into the form
  */
 protected function loadForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         /**
          * If the fields are disabled we don't have any values in the post.
          * When an error occurs in the other fields of the form the meta-fields would be cleared
          * therefore we alter the POST so it contains the initial values.
          */
         if (!isset($_POST['page_title'])) {
             $_POST['page_title'] = isset($this->data['title']) ? $this->data['title'] : null;
         }
         if (!isset($_POST['meta_description'])) {
             $_POST['meta_description'] = isset($this->data['description']) ? $this->data['description'] : null;
         }
         if (!isset($_POST['meta_keywords'])) {
             $_POST['meta_keywords'] = isset($this->data['keywords']) ? $this->data['keywords'] : null;
         }
         if (!isset($_POST['url'])) {
             $_POST['url'] = isset($this->data['url']) ? $this->data['url'] : null;
         }
         if ($this->custom && !isset($_POST['meta_custom'])) {
             $_POST['meta_custom'] = isset($this->data['custom']) ? $this->data['custom'] : null;
         }
         if (!isset($_POST['seo_index'])) {
             $_POST['seo_index'] = isset($this->data['data']['seo_index']) ? $this->data['data']['seo_index'] : 'none';
         }
         if (!isset($_POST['seo_follow'])) {
             $_POST['seo_follow'] = isset($this->data['data']['seo_follow']) ? $this->data['data']['seo_follow'] : 'none';
         }
     }
     // add page title elements into the form
     $this->frm->addCheckbox('page_title_overwrite', isset($this->data['title_overwrite']) && $this->data['title_overwrite'] == 'Y');
     $this->frm->addText('page_title', isset($this->data['title']) ? $this->data['title'] : null);
     // add meta description elements into the form
     $this->frm->addCheckbox('meta_description_overwrite', isset($this->data['description_overwrite']) && $this->data['description_overwrite'] == 'Y');
     $this->frm->addText('meta_description', isset($this->data['description']) ? $this->data['description'] : null);
     // add meta keywords elements into the form
     $this->frm->addCheckbox('meta_keywords_overwrite', isset($this->data['keywords_overwrite']) && $this->data['keywords_overwrite'] == 'Y');
     $this->frm->addText('meta_keywords', isset($this->data['keywords']) ? $this->data['keywords'] : null);
     // add URL elements into the form
     $this->frm->addCheckbox('url_overwrite', isset($this->data['url_overwrite']) && $this->data['url_overwrite'] == 'Y');
     $this->frm->addText('url', isset($this->data['url']) ? urldecode($this->data['url']) : null);
     // advanced SEO
     $indexValues = array(array('value' => 'none', 'label' => BackendLanguage::getLabel('None')), array('value' => 'index', 'label' => 'index'), array('value' => 'noindex', 'label' => 'noindex'));
     $this->frm->addRadiobutton('seo_index', $indexValues, isset($this->data['data']['seo_index']) ? $this->data['data']['seo_index'] : 'none');
     $followValues = array(array('value' => 'none', 'label' => BackendLanguage::getLabel('None')), array('value' => 'follow', 'label' => 'follow'), array('value' => 'nofollow', 'label' => 'nofollow'));
     $this->frm->addRadiobutton('seo_follow', $followValues, isset($this->data['data']['seo_follow']) ? $this->data['data']['seo_follow'] : 'none');
     // should we add the meta-custom field
     if ($this->custom) {
         // add meta custom element into the form
         $this->frm->addTextarea('meta_custom', isset($this->data['custom']) ? $this->data['custom'] : null);
     }
     $this->frm->addHidden('meta_id', $this->id);
     $this->frm->addHidden('base_field_name', $this->baseFieldName);
     $this->frm->addHidden('custom', $this->custom);
     $this->frm->addHidden('class_name', $this->callback['class']);
     $this->frm->addHidden('method_name', $this->callback['method']);
     $this->frm->addHidden('parameters', \SpoonFilter::htmlspecialchars(serialize($this->callback['parameters'])));
 }
 /**
  * Parse the form
  */
 protected function parse()
 {
     parent::parse();
     // Add jsTree plugin
     $this->header->addJS('jstree.min.js', $this->getModule(), false, false);
     $this->header->addCSS('jstree/style.min.css', $this->getModule(), false, false);
     // Show the API key form if we don't have one set
     if (!isset($this->apiKey)) {
         $this->tpl->assign('NoApiKey', true);
         $this->tpl->assign('Wizard', true);
         // create api key form
         $this->frmApiKey = new BackendForm('apiKey');
         $this->frmApiKey->addText('key', $this->apiKey);
         if ($this->frmApiKey->isSubmitted()) {
             $this->frmApiKey->getField('key')->isFilled(BL::err('FieldIsRequired'));
             if ($this->frmApiKey->isCorrect()) {
                 BackendModel::setModuleSetting($this->getModule(), 'api_key', $this->frmApiKey->getField('key')->getValue());
                 $this->redirect(BackendModel::createURLForAction('Settings') . '&report=saved');
             }
         }
         $this->frmApiKey->parse($this->tpl);
     } else {
         // show the settings form
         $this->tpl->assign('EverythingIsPresent', true);
         $this->loadCompressionSettingsForm();
         $this->tpl->assign('directoryTree', $this->directoryTreeHtml);
         $this->validateCompressionSettingsForm();
         $this->frmCompressionSettings->parse($this->tpl);
     }
 }
Example #10
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // create form
     $this->frm = new BackendForm('filter', null, 'get');
     // add fields
     $this->frm->addText('email', $this->filter['email']);
     $this->frm->addHidden('group_id', $this->group['id']);
     // manually parse fields
     $this->frm->parse($this->tpl);
     // check if the filter form was set
     if ($this->frm->isSubmitted()) {
         $this->tpl->assign('oPost', true);
     }
 }
Example #11
0
 private function validateForm()
 {
     if (!$this->form->isSubmitted()) {
         return;
     }
     if ($this->form->existsField('certificate')) {
         return $this->validateAuthConfigFileForm();
     }
     if ($this->form->existsField('account')) {
         return $this->validateAccountForm();
     }
     if ($this->form->existsField('web_property_id')) {
         return $this->validatePropertyForm();
     }
     if ($this->form->existsField('profile')) {
         return $this->validateProfileForm();
     }
 }
Example #12
0
 /**
  * Validates the account tab. On successful validation it will unlink an existing campaignmonitor account.
  */
 private function validateAccountForm()
 {
     // form is submitted
     if ($this->frmAccount->isSubmitted()) {
         // form is validated
         if ($this->frmAccount->isCorrect()) {
             // unlink the account and client ID
             $this->get('fork.settings')->set($this->getModule(), 'cm_account', false);
             $this->get('fork.settings')->set($this->getModule(), 'cm_url', null);
             $this->get('fork.settings')->set($this->getModule(), 'cm_username', null);
             $this->get('fork.settings')->set($this->getModule(), 'cm_password', null);
             $this->get('fork.settings')->set($this->getModule(), 'cm_client_id', null);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_saved_account_settings');
             // redirect to the settings page
             $this->redirect(BackendModel::createURLForAction('Settings') . '&report=unlinked#tabSettingsAccount');
         }
     }
 }
Example #13
0
 /**
  * Validates the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // validate required fields
         $this->frm->getField('mailer_from_name')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('mailer_from_email')->isEmail(BL::err('EmailIsInvalid'));
         $this->frm->getField('mailer_to_name')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('mailer_to_email')->isEmail(BL::err('EmailIsInvalid'));
         $this->frm->getField('mailer_reply_to_name')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('mailer_reply_to_email')->isEmail(BL::err('EmailIsInvalid'));
         if ($this->isGod) {
             // SMTP type was chosen
             if ($this->frm->getField('mailer_type')->getValue() == 'smtp') {
                 // server & port are required
                 $this->frm->getField('smtp_server')->isFilled(BL::err('FieldIsRequired'));
                 $this->frm->getField('smtp_port')->isFilled(BL::err('FieldIsRequired'));
             }
         }
         // no errors ?
         if ($this->frm->isCorrect()) {
             // e-mail settings
             $this->get('fork.settings')->set('Core', 'mailer_from', array('name' => $this->frm->getField('mailer_from_name')->getValue(), 'email' => $this->frm->getField('mailer_from_email')->getValue()));
             $this->get('fork.settings')->set('Core', 'mailer_to', array('name' => $this->frm->getField('mailer_to_name')->getValue(), 'email' => $this->frm->getField('mailer_to_email')->getValue()));
             $this->get('fork.settings')->set('Core', 'mailer_reply_to', array('name' => $this->frm->getField('mailer_reply_to_name')->getValue(), 'email' => $this->frm->getField('mailer_reply_to_email')->getValue()));
             if ($this->isGod) {
                 $this->get('fork.settings')->set('Core', 'mailer_type', $this->frm->getField('mailer_type')->getValue());
                 // smtp settings
                 $this->get('fork.settings')->set('Core', 'smtp_server', $this->frm->getField('smtp_server')->getValue());
                 $this->get('fork.settings')->set('Core', 'smtp_port', $this->frm->getField('smtp_port')->getValue());
                 $this->get('fork.settings')->set('Core', 'smtp_username', $this->frm->getField('smtp_username')->getValue());
                 $this->get('fork.settings')->set('Core', 'smtp_password', $this->frm->getField('smtp_password')->getValue());
                 $this->get('fork.settings')->set('Core', 'smtp_secure_layer', $this->frm->getField('smtp_secure_layer')->getValue());
             }
             // assign report
             $this->tpl->assign('report', true);
             $this->tpl->assign('reportMessage', BL::msg('Saved'));
         }
     }
 }
Example #14
0
 /**
  * Validate the forms
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $txtEmail = $this->frm->getField('backend_email');
         $txtPassword = $this->frm->getField('backend_password');
         // required fields
         if (!$txtEmail->isFilled() || !$txtPassword->isFilled()) {
             // add error
             $this->frm->addError('fields required');
             // show error
             $this->tpl->assign('hasError', true);
         }
         $this->getContainer()->get('logger')->info("Trying to authenticate user '{$txtEmail->getValue()}'.");
         // invalid form-token?
         if ($this->frm->getToken() != $this->frm->getField('form_token')->getValue()) {
             // set a correct header, so bots understand they can't mess with us.
             if (!headers_sent()) {
                 header('400 Bad Request', true, 400);
             }
         }
         // get the user's id
         $userId = BackendUsersModel::getIdByEmail($txtEmail->getValue());
         // all fields are ok?
         if ($txtEmail->isFilled() && $txtPassword->isFilled() && $this->frm->getToken() == $this->frm->getField('form_token')->getValue()) {
             // try to login the user
             if (!BackendAuthentication::loginUser($txtEmail->getValue(), $txtPassword->getValue())) {
                 $this->getContainer()->get('logger')->info("Failed authenticating user '{$txtEmail->getValue()}'.");
                 // add error
                 $this->frm->addError('invalid login');
                 // store attempt in session
                 $current = \SpoonSession::exists('backend_login_attempts') ? (int) \SpoonSession::get('backend_login_attempts') : 0;
                 // increment and store
                 \SpoonSession::set('backend_login_attempts', ++$current);
                 // save the failed login attempt in the user's settings
                 if ($userId !== false) {
                     BackendUsersModel::setSetting($userId, 'last_failed_login_attempt', time());
                 }
                 // show error
                 $this->tpl->assign('hasError', true);
             }
         }
         // check sessions
         if (\SpoonSession::exists('backend_login_attempts') && (int) \SpoonSession::get('backend_login_attempts') >= 5) {
             // get previous attempt
             $previousAttempt = \SpoonSession::exists('backend_last_attempt') ? \SpoonSession::get('backend_last_attempt') : time();
             // calculate timeout
             $timeout = 5 * (\SpoonSession::get('backend_login_attempts') - 4);
             // too soon!
             if (time() < $previousAttempt + $timeout) {
                 // sleep until the user can login again
                 sleep($timeout);
                 // set a correct header, so bots understand they can't mess with us.
                 if (!headers_sent()) {
                     header('503 Service Unavailable', true, 503);
                 }
             } else {
                 // increment and store
                 \SpoonSession::set('backend_last_attempt', time());
             }
             // too many attempts
             $this->frm->addEditor('too many attempts');
             $this->getContainer()->get('logger')->info("Too many login attempts for user '{$txtEmail->getValue()}'.");
             // show error
             $this->tpl->assign('hasTooManyAttemps', true);
             $this->tpl->assign('hasError', false);
         }
         // no errors in the form?
         if ($this->frm->isCorrect()) {
             // cleanup sessions
             \SpoonSession::delete('backend_login_attempts');
             \SpoonSession::delete('backend_last_attempt');
             // save the login timestamp in the user's settings
             $lastLogin = BackendUsersModel::getSetting($userId, 'current_login');
             BackendUsersModel::setSetting($userId, 'current_login', time());
             if ($lastLogin) {
                 BackendUsersModel::setSetting($userId, 'last_login', $lastLogin);
             }
             $this->getContainer()->get('logger')->info("Successfully authenticated user '{$txtEmail->getValue()}'.");
             // redirect to the correct URL (URL the user was looking for or fallback)
             $this->redirectToAllowedModuleAndAction();
         }
     }
     // is the form submitted
     if ($this->frmForgotPassword->isSubmitted()) {
         // backend email
         $email = $this->frmForgotPassword->getField('backend_email_forgot')->getValue();
         // required fields
         if ($this->frmForgotPassword->getField('backend_email_forgot')->isEmail(BL::err('EmailIsInvalid'))) {
             // check if there is a user with the given emailaddress
             if (!BackendUsersModel::existsEmail($email)) {
                 $this->frmForgotPassword->getField('backend_email_forgot')->addError(BL::err('EmailIsUnknown'));
             }
         }
         // no errors in the form?
         if ($this->frmForgotPassword->isCorrect()) {
             // generate the key for the reset link and fetch the user ID for this email
             $key = BackendAuthentication::getEncryptedString($email, uniqid());
             // insert the key and the timestamp into the user settings
             $userId = BackendUsersModel::getIdByEmail($email);
             $user = new User($userId);
             $user->setSetting('reset_password_key', $key);
             $user->setSetting('reset_password_timestamp', time());
             // variables to parse in the e-mail
             $variables['resetLink'] = SITE_URL . BackendModel::createURLForAction('ResetPassword') . '&email=' . $email . '&key=' . $key;
             // send e-mail to user
             $from = $this->get('fork.settings')->get('Core', 'mailer_from');
             $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
             $message = \Common\Mailer\Message::newInstance(\SpoonFilter::ucfirst(BL::msg('ResetYourPasswordMailSubject')))->setFrom(array($from['email'] => $from['name']))->setTo(array($email))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(BACKEND_MODULES_PATH . '/Authentication/Layout/Templates/Mails/ResetPassword.tpl', $variables);
             $this->get('mailer')->send($message);
             // clear post-values
             $_POST['backend_email_forgot'] = '';
             // show success message
             $this->tpl->assign('isForgotPasswordSuccess', true);
             // show form
             $this->tpl->assign('showForm', true);
         } else {
             // errors?
             $this->tpl->assign('showForm', true);
         }
     }
 }
Example #15
0
 /**
  * Validates the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // validate required fields
         $this->frm->getField('site_title')->isFilled(BL::err('FieldIsRequired'));
         // date & time
         $this->frm->getField('time_format')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('date_format_short')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('date_format_long')->isFilled(BL::err('FieldIsRequired'));
         // number
         $this->frm->getField('number_format')->isFilled(BL::err('FieldIsRequired'));
         // akismet key may be filled in
         if ($this->needsAkismet && $this->frm->getField('akismet_key')->isFilled()) {
             // key has changed
             if ($this->frm->getField('akismet_key')->getValue() != $this->get('fork.settings')->get('Core', 'akismet_key', null)) {
                 // create instance
                 $akismet = new Akismet($this->frm->getField('akismet_key')->getValue(), SITE_URL);
                 // invalid key
                 if (!$akismet->verifyKey()) {
                     $this->frm->getField('akismet_key')->setError(BL::err('InvalidAPIKey'));
                 }
             }
         }
         // domains filled in
         if ($this->frm->getField('site_domains')->isFilled()) {
             // split on newlines
             $domains = explode("\n", trim($this->frm->getField('site_domains')->getValue()));
             // loop domains
             foreach ($domains as $domain) {
                 // strip funky stuff
                 $domain = trim(str_replace(array('www.', 'http://', 'https://'), '', $domain));
                 // invalid URL
                 if (!\SpoonFilter::isURL('http://' . $domain)) {
                     // set error
                     $this->frm->getField('site_domains')->setError(BL::err('InvalidDomain'));
                     // stop looping domains
                     break;
                 }
             }
         }
         if ($this->frm->getField('ckfinder_image_max_width')->isFilled()) {
             $this->frm->getField('ckfinder_image_max_width')->isInteger(BL::err('InvalidInteger'));
         }
         if ($this->frm->getField('ckfinder_image_max_height')->isFilled()) {
             $this->frm->getField('ckfinder_image_max_height')->isInteger(BL::err('InvalidInteger'));
         }
         // no errors ?
         if ($this->frm->isCorrect()) {
             // general settings
             $this->get('fork.settings')->set('Core', 'site_title_' . BL::getWorkingLanguage(), $this->frm->getField('site_title')->getValue());
             $this->get('fork.settings')->set('Core', 'site_html_header', $this->frm->getField('site_html_header')->getValue());
             $this->get('fork.settings')->set('Core', 'site_start_of_body_scripts', $this->frm->getField('site_start_of_body_scripts')->getValue());
             $this->get('fork.settings')->set('Core', 'site_html_footer', $this->frm->getField('site_html_footer')->getValue());
             // facebook settings
             $this->get('fork.settings')->set('Core', 'facebook_admin_ids', $this->frm->getField('facebook_admin_ids')->isFilled() ? $this->frm->getField('facebook_admin_ids')->getValue() : null);
             $this->get('fork.settings')->set('Core', 'facebook_app_id', $this->frm->getField('facebook_application_id')->isFilled() ? $this->frm->getField('facebook_application_id')->getValue() : null);
             $this->get('fork.settings')->set('Core', 'facebook_app_secret', $this->frm->getField('facebook_application_secret')->isFilled() ? $this->frm->getField('facebook_application_secret')->getValue() : null);
             // twitter settings
             /** @var \SpoonFormText $txtTwitterSiteName */
             $txtTwitterSiteName = $this->frm->getField('twitter_site_name');
             if ($txtTwitterSiteName->isFilled()) {
                 $this->get('fork.settings')->set('Core', 'twitter_site_name', '@' . ltrim($txtTwitterSiteName->getValue(), '@'));
             }
             // ckfinder settings
             $this->get('fork.settings')->set('Core', 'ckfinder_license_name', $this->frm->getField('ckfinder_license_name')->isFilled() ? $this->frm->getField('ckfinder_license_name')->getValue() : null);
             $this->get('fork.settings')->set('Core', 'ckfinder_license_key', $this->frm->getField('ckfinder_license_key')->isFilled() ? $this->frm->getField('ckfinder_license_key')->getValue() : null);
             $this->get('fork.settings')->set('Core', 'ckfinder_image_max_width', $this->frm->getField('ckfinder_image_max_width')->isFilled() ? $this->frm->getField('ckfinder_image_max_width')->getValue() : 1600);
             $this->get('fork.settings')->set('Core', 'ckfinder_image_max_height', $this->frm->getField('ckfinder_image_max_height')->isFilled() ? $this->frm->getField('ckfinder_image_max_height')->getValue() : 1200);
             // api keys
             $this->get('fork.settings')->set('Core', 'fork_api_public_key', $this->frm->getField('fork_api_public_key')->getValue());
             $this->get('fork.settings')->set('Core', 'fork_api_private_key', $this->frm->getField('fork_api_private_key')->getValue());
             if ($this->needsAkismet) {
                 $this->get('fork.settings')->set('Core', 'akismet_key', $this->frm->getField('akismet_key')->getValue());
             }
             if ($this->needsGoogleMaps) {
                 $this->get('fork.settings')->set('Core', 'google_maps_key', $this->frm->getField('google_maps_key')->getValue());
             }
             // date & time formats
             $this->get('fork.settings')->set('Core', 'time_format', $this->frm->getField('time_format')->getValue());
             $this->get('fork.settings')->set('Core', 'date_format_short', $this->frm->getField('date_format_short')->getValue());
             $this->get('fork.settings')->set('Core', 'date_format_long', $this->frm->getField('date_format_long')->getValue());
             // date & time formats
             $this->get('fork.settings')->set('Core', 'number_format', $this->frm->getField('number_format')->getValue());
             // before we save the languages, we need to ensure that each language actually exists and may be chosen.
             $languages = array(SITE_DEFAULT_LANGUAGE);
             $activeLanguages = array_unique(array_merge($languages, $this->frm->getField('active_languages')->getValue()));
             $redirectLanguages = array_unique(array_merge($languages, $this->frm->getField('redirect_languages')->getValue()));
             // cleanup redirect-languages, by removing the values that aren't present in the active languages
             $redirectLanguages = array_intersect($redirectLanguages, $activeLanguages);
             // save active languages
             $this->get('fork.settings')->set('Core', 'active_languages', $activeLanguages);
             $this->get('fork.settings')->set('Core', 'redirect_languages', $redirectLanguages);
             // domains may not contain www, http or https. Therefor we must loop and create the list of domains.
             $siteDomains = array();
             // domains filled in
             if ($this->frm->getField('site_domains')->isFilled()) {
                 // split on newlines
                 $domains = explode("\n", trim($this->frm->getField('site_domains')->getValue()));
                 // loop domains
                 foreach ($domains as $domain) {
                     // strip funky stuff
                     $siteDomains[] = trim(str_replace(array('www.', 'http://', 'https://'), '', $domain));
                 }
             }
             // save domains
             $this->get('fork.settings')->set('Core', 'site_domains', $siteDomains);
             $this->get('fork.settings')->set('Core', 'show_cookie_bar', $this->frm->getField('show_cookie_bar')->getChecked());
             // assign report
             $this->tpl->assign('report', true);
             $this->tpl->assign('reportMessage', BL::msg('Saved'));
         }
     }
 }
Example #16
0
 /**
  * Validates the form.
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // no errors?
         if ($this->frm->isCorrect()) {
             // determine themes
             $newTheme = $this->frm->getField('installedThemes')->getValue();
             $oldTheme = $this->get('fork.settings')->get('Core', 'theme', 'core');
             // check if we actually switched themes
             if ($newTheme != $oldTheme) {
                 // fetch templates
                 $oldTemplates = BackendExtensionsModel::getTemplates($oldTheme);
                 $newTemplates = BackendExtensionsModel::getTemplates($newTheme);
                 // check if templates already exist
                 if (empty($newTemplates)) {
                     // templates do not yet exist; don't switch
                     $this->redirect(BackendModel::createURLForAction('Themes') . '&error=no-templates-available');
                     exit;
                 }
                 // fetch current default template
                 $oldDefaultTemplatePath = $oldTemplates[$this->get('fork.settings')->get('Pages', 'default_template')]['path'];
                 // loop new templates
                 foreach ($newTemplates as $newTemplateId => $newTemplate) {
                     // check if a a similar default template exists
                     if ($newTemplate['path'] == $oldDefaultTemplatePath) {
                         // set new default id
                         $newDefaultTemplateId = (int) $newTemplateId;
                         break;
                     }
                 }
                 // no default template was found, set first template as default
                 if (!isset($newDefaultTemplateId)) {
                     $newDefaultTemplateId = array_keys($newTemplates);
                     $newDefaultTemplateId = $newDefaultTemplateId[0];
                 }
                 // update theme
                 $this->get('fork.settings')->set('Core', 'theme', $newTheme);
                 // save new default template
                 $this->get('fork.settings')->set('Pages', 'default_template', $newDefaultTemplateId);
                 // loop old templates
                 foreach ($oldTemplates as $oldTemplateId => $oldTemplate) {
                     // loop new templates
                     foreach ($newTemplates as $newTemplateId => $newTemplate) {
                         // if the templates don't match we can skip this one
                         if ($oldTemplate['path'] != $newTemplate['path']) {
                             continue;
                         }
                         // switch template
                         BackendPagesModel::updatePagesTemplates($oldTemplateId, $newTemplateId);
                         // break loop
                         continue 2;
                     }
                     // getting here meant we found no matching template for the new theme; pick first theme's template as default
                     BackendPagesModel::updatePagesTemplates($oldTemplateId, $newDefaultTemplateId);
                 }
                 // trigger event
                 BackendModel::triggerEvent($this->getModule(), 'after_changed_theme');
             }
             // assign report
             $this->tpl->assign('report', true);
             $this->tpl->assign('reportMessage', BL::msg('Saved'));
         }
     }
 }