/** * Validates the form * * @return void */ 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')); // 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 BackendModel::setModuleSetting('core', 'mailer_type', $this->frm->getField('mailer_type')->getValue()); BackendModel::setModuleSetting('core', 'mailer_from', array('name' => $this->frm->getField('mailer_from_name')->getValue(), 'email' => $this->frm->getField('mailer_from_email')->getValue())); BackendModel::setModuleSetting('core', 'mailer_to', array('name' => $this->frm->getField('mailer_to_name')->getValue(), 'email' => $this->frm->getField('mailer_to_email')->getValue())); BackendModel::setModuleSetting('core', 'mailer_reply_to', array('name' => $this->frm->getField('mailer_reply_to_name')->getValue(), 'email' => $this->frm->getField('mailer_reply_to_email')->getValue())); // smtp settings BackendModel::setModuleSetting('core', 'smtp_server', $this->frm->getField('smtp_server')->getValue()); BackendModel::setModuleSetting('core', 'smtp_port', $this->frm->getField('smtp_port')->getValue()); BackendModel::setModuleSetting('core', 'smtp_username', $this->frm->getField('smtp_username')->getValue()); BackendModel::setModuleSetting('core', 'smtp_password', $this->frm->getField('smtp_password')->getValue()); // assign report $this->tpl->assign('report', true); $this->tpl->assign('reportMessage', BL::msg('Saved')); } } }
/** * Validates the form * * @return void */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // no errors ? if ($this->frm->isCorrect()) { // smtp settings BackendModel::setModuleSetting('core', 'seo_noodp', $this->frm->getField('seo_noodp')->getValue()); BackendModel::setModuleSetting('core', 'seo_noydir', $this->frm->getField('seo_noydir')->getValue()); BackendModel::setModuleSetting('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')); } } }
/** * Validate the form * * @return void */ private function validateForm() { // is the form submitted 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')); } } // is the form submitted 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'))); } } }
/** * Validates the form * * @return void */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // no errors? if ($this->frm->isCorrect()) { // determine themes $newTheme = $this->frm->getField('theme')->getValue(); $oldTheme = BackendModel::getModuleSetting('core', 'theme', 'core'); // check if we actually switched themes if ($newTheme != $oldTheme) { // fetch templates $oldTemplates = BackendPagesModel::getTemplates($oldTheme); $newTemplates = BackendPagesModel::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[BackendModel::getModuleSetting('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 BackendModel::setModuleSetting('core', 'theme', $newTheme); // set amount of blocks BackendPagesModel::setMaximumBlocks(); // save new default template BackendModel::setModuleSetting('pages', 'default_template', $newDefaultTemplateId); // loop old templates foreach ($oldTemplates as $oldTemplateId => $oldTemplate) { // loop new templates foreach ($newTemplates as $newTemplateId => $newTemplate) { // check if we have a matching template if ($oldTemplate['path'] == $newTemplate['path']) { // 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')); } } }
/** * Validates the form * * @return void */ 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() != BackendModel::getModuleSetting('core', 'akismet_key', null)) { // load akismet require_once PATH_LIBRARY . '/external/akismet.php'; // 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; } } } // no errors ? if ($this->frm->isCorrect()) { // general settings BackendModel::setModuleSetting('core', 'site_title_' . BL::getWorkingLanguage(), $this->frm->getField('site_title')->getValue()); BackendModel::setModuleSetting('core', 'site_html_header', $this->frm->getField('site_html_header')->getValue()); BackendModel::setModuleSetting('core', 'site_html_footer', $this->frm->getField('site_html_footer')->getValue()); // facebook settings BackendModel::setModuleSetting('core', 'facebook_admin_ids', $this->frm->getField('facebook_admin_ids')->isFilled() ? $this->frm->getField('facebook_admin_ids')->getValue() : null); BackendModel::setModuleSetting('core', 'facebook_app_id', $this->frm->getField('facebook_application_id')->isFilled() ? $this->frm->getField('facebook_application_id')->getValue() : null); BackendModel::setModuleSetting('core', 'facebook_app_secret', $this->frm->getField('facebook_application_secret')->isFilled() ? $this->frm->getField('facebook_application_secret')->getValue() : null); // api keys BackendModel::setModuleSetting('core', 'fork_api_public_key', $this->frm->getField('fork_api_public_key')->getValue()); BackendModel::setModuleSetting('core', 'fork_api_private_key', $this->frm->getField('fork_api_private_key')->getValue()); if ($this->needsAkismet) { BackendModel::setModuleSetting('core', 'akismet_key', $this->frm->getField('akismet_key')->getValue()); } if ($this->needsGoogleMaps) { BackendModel::setModuleSetting('core', 'google_maps_key', $this->frm->getField('google_maps_key')->getValue()); } // date & time formats BackendModel::setModuleSetting('core', 'time_format', $this->frm->getField('time_format')->getValue()); BackendModel::setModuleSetting('core', 'date_format_short', $this->frm->getField('date_format_short')->getValue()); BackendModel::setModuleSetting('core', 'date_format_long', $this->frm->getField('date_format_long')->getValue()); // date & time formats BackendModel::setModuleSetting('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); // save active languages BackendModel::setModuleSetting('core', 'active_languages', array_unique(array_merge($languages, $this->frm->getField('active_languages')->getValue()))); BackendModel::setModuleSetting('core', 'redirect_languages', array_unique(array_merge($languages, $this->frm->getField('redirect_languages')->getValue()))); // 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 BackendModel::setModuleSetting('core', 'site_domains', $siteDomains); // assign report $this->tpl->assign('report', true); $this->tpl->assign('reportMessage', BL::msg('Saved')); } } }
/** * 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(BL::err('FieldIsRequired')); } // meta description overwrite is checked if ($this->frm->getField('meta_description_overwrite')->isChecked()) { $this->frm->getField('meta_description')->isFilled(BL::err('FieldIsRequired')); } // meta keywords overwrite is checked if ($this->frm->getField('meta_keywords_overwrite')->isChecked()) { $this->frm->getField('meta_keywords')->isFilled(BL::err('FieldIsRequired')); } // URL overwrite is checked if ($this->frm->getField('url_overwrite')->isChecked()) { // filled $this->frm->getField('url')->isFilled(BL::err('FieldIsRequired')); // fetch url $URL = $this->frm->getField('url')->getValue(); // get the real url $generatedUrl = $this->generateURL($URL); // check if urls are different if ($URL != $generatedUrl) { $this->frm->getField('url')->addError(BL::err('URLAlreadyExists')); } } // if the form was submitted correctly the data array should be populated if ($this->frm->isCorrect()) { // get meta keywords if ($this->frm->getField('meta_keywords_overwrite')->isChecked()) { $keywords = $this->frm->getField('meta_keywords')->getValue(); } else { $keywords = $this->frm->getField($this->baseFieldName)->getValue(); } // get meta description if ($this->frm->getField('meta_description_overwrite')->isChecked()) { $description = $this->frm->getField('meta_description')->getValue(); } else { $description = $this->frm->getField($this->baseFieldName)->getValue(); } // get page title if ($this->frm->getField('page_title_overwrite')->isChecked()) { $title = $this->frm->getField('page_title')->getValue(); } else { $title = $this->frm->getField($this->baseFieldName)->getValue(); } // get URL if ($this->frm->getField('url_overwrite')->isChecked()) { $URL = SpoonFilter::htmlspecialcharsDecode($this->frm->getField('url')->getValue()); } else { $URL = 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')->isChecked() ? 'Y' : 'N'; $this->data['description'] = $description; $this->data['description_overwrite'] = $this->frm->getField('meta_description_overwrite')->isChecked() ? 'Y' : 'N'; $this->data['title'] = $title; $this->data['title_overwrite'] = $this->frm->getField('page_title_overwrite')->isChecked() ? 'Y' : 'N'; $this->data['url'] = $URL; $this->data['url_overwrite'] = $this->frm->getField('url_overwrite')->isChecked() ? 'Y' : 'N'; $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(); } } }
/** * Form for periodpicker * * @return void * @param BackendTemplate $tpl The template to parse the period picker in. * @param int $startTimestamp The start timestamp for the google call. * @param int $endTimestamp The end timestamp for the google call. * @param array[optional] $parameters The extra GET parameters to set on redirect. */ public static function parsePeriodPicker(BackendTemplate $tpl, $startTimestamp, $endTimestamp, $parameters = array()) { // redefine $startTimestamp = (int) $startTimestamp; $endTimestamp = (int) $endTimestamp; // assign $tpl->assign('startTimestamp', $startTimestamp); $tpl->assign('endTimestamp', $endTimestamp); // create form $frm = new BackendForm('periodPickerForm'); // create datepickers $frm->addDate('start_date', $startTimestamp, 'range', mktime(0, 0, 0, 1, 1, 2005), time(), 'noFocus'); $frm->addDate('end_date', $endTimestamp, 'range', mktime(0, 0, 0, 1, 1, 2005), time(), 'noFocus'); // submitted if ($frm->isSubmitted()) { // show the form $tpl->assign('showForm', true); // cleanup fields $frm->cleanupFields(); // shorten fields $txtStartDate = $frm->getField('start_date'); $txtEndDate = $frm->getField('end_date'); // required fields $txtStartDate->isFilled(BL::err('StartDateIsInvalid')); $txtEndDate->isFilled(BL::err('EndDateIsInvalid')); // dates within valid range if ($txtStartDate->isFilled() && $txtEndDate->isFilled()) { // valid dates if ($txtStartDate->isValid(BL::err('StartDateIsInvalid')) && $txtEndDate->isValid(BL::err('EndDateIsInvalid'))) { // get timestamps $newStartDate = BackendModel::getUTCTimestamp($txtStartDate); $newEndDate = BackendModel::getUTCTimestamp($txtEndDate); // init valid $valid = true; // startdate cannot be before 2005 (earliest valid google startdate) if ($newStartDate < mktime(0, 0, 0, 1, 1, 2005)) { $valid = false; } elseif ($newEndDate > time()) { $valid = false; } elseif ($newStartDate > $newEndDate) { $valid = false; } // invalid range if (!$valid) { $txtStartDate->setError(BL::err('DateRangeIsInvalid')); } } } // valid if ($frm->isCorrect()) { // parameters $parameters['start_timestamp'] = $newStartDate; $parameters['end_timestamp'] = $newEndDate; // build redirect string $redirect = html_entity_decode(BackendModel::createURLForAction(null, null, null, $parameters)); // redirect SpoonHTTP::redirect($redirect); } } // parse $frm->parse($tpl); // we only allow live data fetching when the end date is today, no point in fetching and older range because it will never change if ($endTimestamp == mktime(0, 0, 0, date('n'), date('j'), date('Y'))) { // url of current action $liveDataUrl = BackendModel::createURLForAction('loading') . '&redirect_action=' . Spoon::get('url')->getAction(); // page id set if (isset($_GET['page_id']) && $_GET['page_id'] != '') { $liveDataUrl .= '&page_id=' . (int) $_GET['page_id']; } // page path set if (isset($_GET['page_path']) && $_GET['page_path'] != '') { $liveDataUrl .= '&page_path=' . (string) $_GET['page_path']; } // assign $tpl->assign('liveDataURL', $liveDataUrl); } }
/** * Validates the form * It checks if there is a value when a checkbox is checked * * @return void */ public function validate() { // no callback set by user? if (empty($this->callback)) { // build class- & method-name $className = 'Backend' . SpoonFilter::toCamelCase($this->URL->getModule()) . 'Model'; $methodName = 'getURL'; // set $this->setUrlCallback($className, $methodName); } // page title overwrite is checked if ($this->frm->getField('page_title_overwrite')->isChecked()) { $this->frm->getField('page_title')->isFilled(BL::err('FieldIsRequired')); } // meta description overwrite is checked if ($this->frm->getField('meta_description_overwrite')->isChecked()) { $this->frm->getField('meta_description')->isFilled(BL::err('FieldIsRequired')); } // meta keywords overwrite is checked if ($this->frm->getField('meta_keywords_overwrite')->isChecked()) { $this->frm->getField('meta_keywords')->isFilled(BL::err('FieldIsRequired')); } // URL overwrite is checked if ($this->frm->getField('url_overwrite')->isChecked()) { // filled $this->frm->getField('url')->isFilled(BL::err('FieldIsRequired')); // fetch url $URL = SpoonFilter::urlise($this->frm->getField('url')->getValue()); // build parameters for use in the callback $parameters[] = $URL; // add parameters set by user if (!empty($this->callback['parameters'])) { foreach ($this->callback['parameters'] as $parameter) { $parameters[] = $parameter; } } // get the real url $generatedUrl = call_user_func_array(array($this->callback['class'], $this->callback['method']), $parameters); // check if urls are different if ($URL != $generatedUrl) { $this->frm->getField('url')->addError(BL::err('URLAlreadyExists')); } } // if the form was submitted correctly the data array should be populated if ($this->frm->isCorrect()) { // no callback set by user? if (empty($this->callback)) { // build class- & method-name $className = 'Backend' . SpoonFilter::toCamelCase($this->URL->getModule()) . 'Model'; $methodName = 'getURL'; // set $this->setUrlCallback($className, $methodName); } // get meta keywords if ($this->frm->getField('meta_keywords_overwrite')->isChecked()) { $keywords = $this->frm->getField('meta_keywords')->getValue(); } else { $keywords = $this->frm->getField($this->baseFieldName)->getValue(); } // get meta description if ($this->frm->getField('meta_description_overwrite')->isChecked()) { $description = $this->frm->getField('meta_description')->getValue(); } else { $description = $this->frm->getField($this->baseFieldName)->getValue(); } // get page title if ($this->frm->getField('page_title_overwrite')->isChecked()) { $title = $this->frm->getField('page_title')->getValue(); } else { $title = $this->frm->getField($this->baseFieldName)->getValue(); } // get URL if ($this->frm->getField('url_overwrite')->isChecked()) { $URL = SpoonFilter::urlise(SpoonFilter::htmlspecialcharsDecode($this->frm->getField('url')->getValue())); } else { $URL = SpoonFilter::urlise(SpoonFilter::htmlspecialcharsDecode($this->frm->getField($this->baseFieldName)->getValue())); } // build parameters for use in the callback $parameters[] = $URL; // add parameters set by user if (!empty($this->callback['parameters'])) { foreach ($this->callback['parameters'] as $parameter) { $parameters[] = $parameter; } } // get the real URL $URL = call_user_func_array(array($this->callback['class'], $this->callback['method']), $parameters); // 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')->isChecked() ? 'Y' : 'N'; $this->data['description'] = $description; $this->data['description_overwrite'] = $this->frm->getField('meta_description_overwrite')->isChecked() ? 'Y' : 'N'; $this->data['title'] = $title; $this->data['title_overwrite'] = $this->frm->getField('page_title_overwrite')->isChecked() ? 'Y' : 'N'; $this->data['url'] = $URL; $this->data['url_overwrite'] = $this->frm->getField('url_overwrite')->isChecked() ? 'Y' : 'N'; $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(); } } }