isCorrect() public method

Checks to see if this form has been correctly submitted. Will revalidate by default.
public isCorrect ( boolean $revalidate = true ) : boolean
$revalidate boolean Do we need to enforce validation again, even if it might already been done before?
return boolean
Example #1
0
 /**
  * @return bool
  */
 private function isValid()
 {
     $fields = $this->form->getFields();
     if (!$fields['start_date']->isFilled(Language::err('FieldIsRequired')) || !$fields['end_date']->isFilled(Language::err('FieldIsRequired'))) {
         return $this->form->isCorrect();
     }
     if (!$fields['start_date']->isValid(Language::err('DateIsInvalid')) || !$fields['end_date']->isValid(Language::err('DateIsInvalid'))) {
         return $this->form->isCorrect();
     }
     $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(Language::err('DateRangeIsInvalid'));
     }
     // enddate cannot be in the future
     if ($newEndDate > time()) {
         $fields['start_date']->setError(Language::err('DateRangeIsInvalid'));
     }
     // enddate cannot be before the startdate
     if ($newStartDate > $newEndDate) {
         $fields['start_date']->setError(Language::err('DateRangeIsInvalid'));
     }
     return $this->form->isCorrect();
 }
 /**
  * @return bool
  */
 private function isValid()
 {
     $fileField = $this->form->getField('certificate');
     $emailField = $this->form->getField('email');
     if ($fileField->isFilled(Language::err('FieldIsRequired'))) {
         $fileField->isAllowedExtension(['p12'], Language::err('P12Only'));
     }
     $emailField->isFilled(Language::err('FieldIsRequired'));
     $emailField->isEmail(Language::err('EmailIsInvalid'));
     return $this->form->isCorrect();
 }
Example #3
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 #4
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')));
         }
     }
 }
 /**
  * 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);
     }
 }
 /**
  * Checks if the form is valid
  *
  * @return bool
  */
 private function isValid()
 {
     $fields = $this->form->getFields();
     $fields['name']->isFilled(Language::err('FieldIsRequired'));
     $fields['description']->isFilled(Language::err('FieldIsRequired'));
     $this->meta->validate();
     return $this->form->isCorrect();
 }
Example #7
0
 private function validateProfileForm()
 {
     $profileField = $this->form->getField('profile');
     $profileField->isFilled(Language::err('FieldIsRequired'));
     if ($this->form->isCorrect()) {
         $this->get('fork.settings')->set($this->getModule(), 'profile', $profileField->getValue());
         $this->redirect(Model::createURLForAction('Settings'));
     }
 }
Example #8
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 #9
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 #10
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 #11
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'));
         }
     }
 }
 /**
  * @return bool
  */
 private function isValid()
 {
     $this->form->getField('web_property_id')->isFilled(Language::err('FieldIsRequired'));
     return $this->form->isCorrect();
 }
Example #13
0
 /**
  * Validates the form
  * It checks if there is a value when a checkbox is checked
  */
 public function validate()
 {
     // page title overwrite is checked
     if ($this->frm->getField('page_title_overwrite')->isChecked()) {
         $this->frm->getField('page_title')->isFilled(BackendLanguage::err('FieldIsRequired'));
     }
     // meta description overwrite is checked
     if ($this->frm->getField('meta_description_overwrite')->isChecked()) {
         $this->frm->getField('meta_description')->isFilled(BackendLanguage::err('FieldIsRequired'));
     }
     // meta keywords overwrite is checked
     if ($this->frm->getField('meta_keywords_overwrite')->isChecked()) {
         $this->frm->getField('meta_keywords')->isFilled(BackendLanguage::err('FieldIsRequired'));
     }
     // URL overwrite is checked
     if ($this->frm->getField('url_overwrite')->isChecked()) {
         $this->frm->getField('url')->isFilled(BackendLanguage::err('FieldIsRequired'));
         $url = \SpoonFilter::htmlspecialcharsDecode($this->frm->getField('url')->getValue());
         $generatedUrl = $this->generateURL($url);
         // check if urls are different
         if (CommonUri::getUrl($url) != $generatedUrl) {
             $this->frm->getField('url')->addError(BackendLanguage::err('URLAlreadyExists'));
         }
     }
     // if the form was submitted correctly the data array should be populated
     if ($this->frm->isCorrect()) {
         // get meta keywords
         $keywords = $this->frm->getField('meta_keywords_overwrite')->getActualValue($this->frm->getField('meta_keywords')->getValue(), $this->frm->getField($this->baseFieldName)->getValue());
         // get meta description
         $description = $this->frm->getField('meta_description_overwrite')->getActualValue($this->frm->getField('meta_description')->getValue(), $this->frm->getField($this->baseFieldName)->getValue());
         // get page title
         $title = $this->frm->getField('page_title_overwrite')->getActualValue($this->frm->getField('page_title')->getValue(), $this->frm->getField($this->baseFieldName)->getValue());
         // get URL
         $url = $this->frm->getField('url_overwrite')->getActualValue(\SpoonFilter::htmlspecialcharsDecode($this->frm->getField('url')->getValue()), \SpoonFilter::htmlspecialcharsDecode($this->frm->getField($this->baseFieldName)->getValue()));
         // get the real URL
         $url = $this->generateURL($url);
         // get meta custom
         if ($this->custom && $this->frm->getField('meta_custom')->isFilled()) {
             $custom = $this->frm->getField('meta_custom')->getValue();
         } else {
             $custom = null;
         }
         // set data
         $this->data['keywords'] = $keywords;
         $this->data['keywords_overwrite'] = $this->frm->getField('meta_keywords_overwrite')->getActualValue();
         $this->data['description'] = $description;
         $this->data['description_overwrite'] = $this->frm->getField('meta_description_overwrite')->getActualValue();
         $this->data['title'] = $title;
         $this->data['title_overwrite'] = $this->frm->getField('page_title_overwrite')->getActualValue();
         $this->data['url'] = $url;
         $this->data['url_overwrite'] = $this->frm->getField('url_overwrite')->getActualValue();
         $this->data['custom'] = $custom;
         if ($this->frm->getField('seo_index')->getValue() == 'none') {
             unset($this->data['data']['seo_index']);
         } else {
             $this->data['data']['seo_index'] = $this->frm->getField('seo_index')->getValue();
         }
         if ($this->frm->getField('seo_follow')->getValue() == 'none') {
             unset($this->data['data']['seo_follow']);
         } else {
             $this->data['data']['seo_follow'] = $this->frm->getField('seo_follow')->getValue();
         }
     }
 }
Example #14
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'));
         }
     }
 }