/** * 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'))); } } }
/** * 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' => BL::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' => BL::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']))); }
/** * 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')); } } }
/** * 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); } }
/** * Parse */ protected function parse() { parent::parse(); if (!isset($this->sessionToken)) { // show the link to the google account authentication form $this->tpl->assign('NoSessionToken', true); $this->tpl->assign('Wizard', true); // build the link to the google account authentication form $redirectUrl = SITE_URL . '/' . (strpos($this->URL->getQueryString(), '?') === false ? $this->URL->getQueryString() : substr($this->URL->getQueryString(), 0, strpos($this->URL->getQueryString(), '?'))); $googleAccountAuthenticationForm = sprintf(BackendAnalyticsModel::GOOGLE_ACCOUNT_AUTHENTICATION_URL, urlencode($redirectUrl), urlencode(BackendAnalyticsModel::GOOGLE_ACCOUNT_AUTHENTICATION_SCOPE)); // parse the link to the google account authentication form $this->tpl->assign('googleAccountAuthenticationForm', $googleAccountAuthenticationForm); } // session token is present but no table id if (isset($this->sessionToken) && isset($this->profiles) && !isset($this->tableId)) { // show all possible accounts with their profiles $this->tpl->assign('NoTableId', true); $this->tpl->assign('Wizard', true); $accounts = array(); // no profiles or not authorized if (!empty($this->profiles) && $this->profiles !== 'UNAUTHORIZED') { $accounts[''][0] = BL::msg('ChooseWebsiteProfile'); // prepare accounts array foreach ((array) $this->profiles as $profile) { $accounts[$profile['accountName']][$profile['tableId']] = $profile['title']; } // there are accounts if (!empty($accounts)) { // sort accounts uksort($accounts, array('BackendAnalyticsSettings', 'sortAccounts')); // create form $frm = new BackendForm('linkProfile', BackendModel::createURLForAction(), 'get'); $frm->addDropdown('table_id', $accounts); $frm->parse($this->tpl); if ($frm->isSubmitted()) { if ($frm->getField('table_id')->getValue() == '0') { $this->tpl->assign('ddmTableIdError', BL::err('FieldIsRequired')); } } // parse accounts $this->tpl->assign('accounts', true); } } } // everything is fine if (isset($this->sessionToken) && isset($this->tableId) && isset($this->accountName)) { // show the linked account $this->tpl->assign('EverythingIsPresent', true); // show the title of the linked account and profile $this->tpl->assign('accountName', $this->accountName); $this->tpl->assign('profileTitle', $this->profileTitle); } }