Author: Davy Hellemans (davy.hellemans@netlash.com)
Author: Tijs Verkoyen (tijs@sumocoders.be)
Inheritance: extends Common\Core\Form
コード例 #1
0
ファイル: DateRangeType.php プロジェクト: forkcms/forkcms
 /**
  * @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();
 }
コード例 #2
0
ファイル: ActionAdd.php プロジェクト: forkcms/forkcms
 /**
  * Parse the form
  */
 protected function parse()
 {
     parent::parse();
     if ($this->frm) {
         $this->frm->parse($this->tpl);
     }
 }
コード例 #3
0
 /**
  * @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();
 }
コード例 #4
0
 /**
  * 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);
     }
 }
コード例 #5
0
ファイル: ResetPassword.php プロジェクト: bwgraves/forkcms
 /**
  * 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')));
         }
     }
 }
コード例 #6
0
 /**
  * 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();
 }
コード例 #7
0
ファイル: Settings.php プロジェクト: bwgraves/forkcms
 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'));
     }
 }
コード例 #8
0
ファイル: Groups.php プロジェクト: bwgraves/forkcms
 /**
  * Load the form.
  */
 private function loadForm()
 {
     // create form
     $this->frm = new BackendForm('filter', BackendModel::createURLForAction(), 'get');
     // add fields
     $this->frm->addText('name', $this->filter['name']);
     // manually parse fields
     $this->frm->parse($this->tpl);
 }
コード例 #9
0
ファイル: Index.php プロジェクト: forkcms/forkcms
 /**
  * Parse the datagrid
  */
 protected function parse()
 {
     parent::parse();
     $this->tpl->assign('dataGrid', (string) $this->dataGrid->getContent());
     $this->tpl->assign('godUser', BackendAuthentication::getUser()->isGod());
     // assign to template
     $this->tpl->assign('items', $this->items);
     $this->tpl->assign('settings', $this->settings);
     $this->form->parse($this->tpl);
 }
コード例 #10
0
ファイル: FormFile.php プロジェクト: forkcms/forkcms
 /**
  * This function will return the errors. It is extended so we can do file checks automatically.
  *
  * @return string
  */
 public function getErrors()
 {
     // if the image is bigger then the allowed configuration it won't show up as filled but it is submitted
     // the empty check is added because otherwise this error is shown like 7 times
     if ($this->isSubmitted() && isset($_FILES[$this->getName()]['error']) && empty($this->errors)) {
         $imageError = $_FILES[$this->getName()]['error'];
         if ($imageError === UPLOAD_ERR_INI_SIZE && empty($this->errors)) {
             $this->addError(SpoonFilter::ucfirst(sprintf(BackendLanguage::err('FileTooBig'), Form::getUploadMaxFileSize())));
         }
     }
     return $this->errors;
 }
コード例 #11
0
ファイル: Index.php プロジェクト: forkcms/forkcms
 /**
  * Load the form
  */
 private function loadForm()
 {
     $this->frm = new BackendForm('filter', BackendModel::createURLForAction(), 'get');
     $this->frm->addDropdown('application', array('' => '-', 'Backend' => 'Backend', 'Frontend' => 'Frontend'), $this->filter['application']);
     $this->frm->addText('name', $this->filter['name']);
     $this->frm->addText('value', $this->filter['value']);
     $this->frm->addMultiCheckbox('language', BackendLocaleModel::getLanguagesForMultiCheckbox($this->isGod), $this->filter['language'], 'noFocus');
     $this->frm->addMultiCheckbox('type', BackendLocaleModel::getTypesForMultiCheckbox(), $this->filter['type'], 'noFocus');
     $this->frm->addDropdown('module', BackendModel::getModulesForDropDown(), $this->filter['module']);
     $this->frm->getField('module')->setDefaultElement('-');
     // manually parse fields
     $this->frm->parse($this->tpl);
 }
コード例 #12
0
ファイル: Edit.php プロジェクト: forkcms/forkcms
 /**
  * Parse the form
  */
 protected function parse()
 {
     parent::parse();
     // assign to template
     $this->tpl->assign('item', $this->record);
     $this->tpl->assign('settings', $this->settings);
     $this->tpl->assign('godUser', BackendAuthentication::getUser()->isGod());
     $this->settingsForm->parse($this->tpl);
     // assign message if address was not be geocoded
     if ($this->record['lat'] == null || $this->record['lng'] == null) {
         $this->tpl->assign('errorMessage', BL::err('AddressCouldNotBeGeocoded'));
     }
 }
コード例 #13
0
ファイル: Index.php プロジェクト: bwgraves/forkcms
 protected function parse()
 {
     parent::parse();
     $this->header->addJS('highcharts.js', 'Core', false);
     $this->form->parse($this->tpl);
     $this->tpl->assign('startTimestamp', $this->startDate);
     $this->tpl->assign('endTimestamp', $this->endDate);
     // if we don't have a token anymore, redirect to the settings page
     if ($this->get('fork.settings')->get($this->getModule(), 'certificate') === null || $this->get('fork.settings')->get($this->getModule(), 'account') === null || $this->get('fork.settings')->get($this->getModule(), 'web_property_id') === null || $this->get('fork.settings')->get($this->getModule(), 'profile') === null) {
         $this->redirect(Model::createURLForAction('Settings'));
     }
     $analytics = $this->get('analytics.connector');
     $this->tpl->assign('page_views', $analytics->getPageViews($this->startDate, $this->endDate));
     $this->tpl->assign('visitors', $analytics->getVisitors($this->startDate, $this->endDate));
     $this->tpl->assign('pages_per_visit', $analytics->getPagesPerVisit($this->startDate, $this->endDate));
     $this->tpl->assign('time_on_site', $analytics->getTimeOnSite($this->startDate, $this->endDate));
     $this->tpl->assign('new_sessions_percentage', $analytics->getNewSessionsPercentage($this->startDate, $this->endDate));
     $this->tpl->assign('bounce_rate', $analytics->getBounceRate($this->startDate, $this->endDate));
     $this->tpl->assign('visitors_graph_data', $analytics->getVisitorsGraphData($this->startDate, $this->endDate));
     $this->tpl->assign('source_graph_data', $analytics->getSourceGraphData($this->startDate, $this->endDate));
     $dataGrid = new DataGridArray($analytics->getMostVisitedPagesData($this->startDate, $this->endDate));
     $this->tpl->assign('dataGridMostViewedPages', (string) $dataGrid->getContent());
 }
コード例 #14
0
ファイル: Addresses.php プロジェクト: bwgraves/forkcms
 /**
  * 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);
     }
 }
コード例 #15
0
ファイル: Users.php プロジェクト: Comsa-Veurne/modules
 /**
  * Load the form.
  */
 private function loadForm()
 {
     // create form
     $this->frm = new BackendForm('filter', BackendModel::createURLForAction(), 'get');
     // add fields
     $this->frm->addText('email', $this->filter['email']);
     $this->frm->addText('name', $this->filter['name']);
     // get categories
     $groups = BackendMailengineModel::getAllGroupsForDropdown();
     $groups = array("0" => "") + $groups;
     // multiple categories?
     if (count($groups) > 1) {
         // create element
         $this->frm->addDropdown('group', $groups, $this->filter["group"]);
         $this->frm->getField('group')->setDefaultElement('');
     }
     // manually parse fields
     $this->frm->parse($this->tpl);
 }
コード例 #16
0
ファイル: Settings.php プロジェクト: bwgraves/forkcms
 /**
  * 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');
         }
     }
 }
コード例 #17
0
ファイル: Index.php プロジェクト: forkcms/forkcms
 /**
  * Load the form.
  */
 private function loadForm()
 {
     // create form
     $this->frm = new BackendForm('filter', BackendModel::createURLForAction(), 'get');
     // values for dropdowns
     $status = BackendProfilesModel::getStatusForDropDown();
     $groups = BackendProfilesModel::getGroups();
     // add fields
     $this->frm->addText('email', $this->filter['email']);
     $this->frm->addDropdown('status', $status, $this->filter['status']);
     $this->frm->getField('status')->setDefaultElement('');
     // add a group filter if wa have groups
     if (!empty($groups)) {
         $this->frm->addDropdown('group', $groups, $this->filter['group']);
         $this->frm->getField('group')->setDefaultElement('');
     }
     // manually parse fields
     $this->frm->parse($this->tpl);
 }
コード例 #18
0
ファイル: Seo.php プロジェクト: bwgraves/forkcms
 /**
  * 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'));
         }
     }
 }
コード例 #19
0
ファイル: Email.php プロジェクト: forkcms/forkcms
 /**
  * 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'));
         }
     }
 }
コード例 #20
0
ファイル: Data.php プロジェクト: forkcms/forkcms
 /**
  * Load the form
  */
 private function loadForm()
 {
     $startDate = '';
     $endDate = '';
     if (isset($this->filter['start_date']) && $this->filter['start_date'] != '') {
         $chunks = explode('/', $this->filter['start_date']);
         $startDate = (int) mktime(0, 0, 0, (int) $chunks[1], (int) $chunks[0], (int) $chunks[2]);
         if ($startDate == 0) {
             $startDate = '';
         }
     }
     if (isset($this->filter['end_date']) && $this->filter['end_date'] != '') {
         $chunks = explode('/', $this->filter['end_date']);
         $endDate = (int) mktime(0, 0, 0, (int) $chunks[1], (int) $chunks[0], (int) $chunks[2]);
         if ($endDate == 0) {
             $endDate = '';
         }
     }
     $this->frm = new BackendForm('filter', BackendModel::createURLForAction() . '&amp;id=' . $this->id, 'get');
     $this->frm->addDate('start_date', $startDate);
     $this->frm->addDate('end_date', $endDate);
     // manually parse fields
     $this->frm->parse($this->tpl);
 }
コード例 #21
0
ファイル: Index.php プロジェクト: bwgraves/forkcms
 /**
  * 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);
         }
     }
 }
コード例 #22
0
ファイル: Helper.php プロジェクト: newaltcoin/forkcms
 /**
  * Parse a field and return the HTML.
  *
  * @param array $field Field data.
  * @return string
  */
 public static function parseField(array $field)
 {
     if (!empty($field)) {
         // init
         $frm = new BackendForm('tmp', '');
         $tpl = BackendModel::getContainer()->has('template') ? BackendModel::getContainer()->get('template') : new BackendTemplate();
         $fieldHTML = '';
         $fieldName = 'field' . $field['id'];
         $values = isset($field['settings']['values']) ? $field['settings']['values'] : null;
         $defaultValues = isset($field['settings']['default_values']) ? $field['settings']['default_values'] : null;
         $placeholder = isset($field['settings']['placeholder']) ? $field['settings']['placeholder'] : null;
         /**
          * Create form and parse to HTML
          */
         // dropdown
         if ($field['type'] == 'dropdown') {
             // values and labels are the same
             $values = array_combine($values, $values);
             // get index of selected item
             $defaultIndex = array_search($defaultValues, $values, true);
             if ($defaultIndex === false) {
                 $defaultIndex = null;
             }
             // create element
             $ddm = $frm->addDropdown($fieldName, $values, $defaultIndex);
             // empty default element
             $ddm->setDefaultElement('');
             // get content
             $fieldHTML = $ddm->parse();
         } elseif ($field['type'] == 'datetime') {
             // create element
             if ($field['settings']['input_type'] == 'date') {
                 // calculate default value
                 $amount = $field['settings']['value_amount'];
                 $type = $field['settings']['value_type'];
                 if ($type != '') {
                     switch ($type) {
                         case 'today':
                             $defaultValues = date('d/m/Y');
                             break;
                         case 'day':
                         case 'week':
                         case 'month':
                         case 'year':
                             if ($amount != '') {
                                 $defaultValues = date('d/m/Y', strtotime('+' . $amount . ' ' . $type));
                             }
                             break;
                     }
                 }
                 $datetime = $frm->addText($fieldName, $defaultValues);
             } else {
                 $datetime = $frm->addTime($fieldName, $defaultValues);
             }
             $datetime->setAttribute('disabled', 'disabled');
             // get content
             $fieldHTML = $datetime->parse();
         } elseif ($field['type'] == 'radiobutton') {
             // create element
             $rbt = $frm->addRadiobutton($fieldName, $values, $defaultValues);
             // get content
             $fieldHTML = $rbt->parse();
         } elseif ($field['type'] == 'checkbox') {
             // rebuild values
             foreach ($values as $value) {
                 $newValues[] = array('label' => $value, 'value' => $value);
             }
             // create element
             $chk = $frm->addMultiCheckbox($fieldName, $newValues, $defaultValues);
             // get content
             $fieldHTML = $chk->parse();
         } elseif ($field['type'] == 'textbox') {
             // create element
             $txt = $frm->addText($fieldName, $defaultValues);
             $txt->setAttribute('disabled', 'disabled');
             $txt->setAttribute('placeholder', $placeholder);
             // get content
             $fieldHTML = $txt->parse();
         } elseif ($field['type'] == 'textarea') {
             // create element
             $txt = $frm->addTextarea($fieldName, $defaultValues);
             $txt->setAttribute('cols', 30);
             $txt->setAttribute('disabled', 'disabled');
             $txt->setAttribute('placeholder', $placeholder);
             // get content
             $fieldHTML = $txt->parse();
         } elseif ($field['type'] == 'heading') {
             $fieldHTML = '<h3>' . $values . '</h3>';
         } elseif ($field['type'] == 'paragraph') {
             $fieldHTML = $values;
         }
         /**
          * Parse the field into the template
          */
         // init
         $tpl->assign('plaintext', false);
         $tpl->assign('simple', false);
         $tpl->assign('multiple', false);
         $tpl->assign('id', $field['id']);
         $tpl->assign('required', isset($field['validations']['required']));
         // plaintext items
         if ($field['type'] == 'heading' || $field['type'] == 'paragraph') {
             // assign
             $tpl->assign('content', $fieldHTML);
             $tpl->assign('plaintext', true);
         } elseif ($field['type'] == 'checkbox' || $field['type'] == 'radiobutton') {
             // name (prefixed by type)
             $name = $field['type'] == 'checkbox' ? 'chk' . \SpoonFilter::ucfirst($fieldName) : 'rbt' . \SpoonFilter::ucfirst($fieldName);
             // rebuild so the html is stored in a general name (and not rbtName)
             foreach ($fieldHTML as &$item) {
                 $item['field'] = $item[$name];
             }
             // show multiple
             $tpl->assign('label', $field['settings']['label']);
             $tpl->assign('items', $fieldHTML);
             $tpl->assign('multiple', true);
         } else {
             // assign
             $tpl->assign('label', $field['settings']['label']);
             $tpl->assign('field', $fieldHTML);
             $tpl->assign('simple', true);
         }
         return $tpl->getContent(BACKEND_MODULES_PATH . '/FormBuilder/Layout/Templates/Field.tpl');
     } else {
         // empty field so return empty string
         return '';
     }
 }
コード例 #23
0
ファイル: Index.php プロジェクト: bwgraves/forkcms
 /**
  * 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'));
         }
     }
 }
コード例 #24
0
ファイル: Index.php プロジェクト: Comsa-Veurne/modules
 /**
  * Parse the page
  */
 protected function parse()
 {
     // parse the datagrid for all products
     $this->tpl->assign('dgProducts', $this->dgProducts->getNumResults() != 0 ? $this->dgProducts->getContent() : false);
     // get categories
     $categories = BackendCatalogModel::getCategories(true);
     // multiple categories?
     if (count($categories) > 1) {
         // create form
         $frm = new BackendForm('filter', null, 'get', true);
         // create element
         $frm->addDropdown('category', $categories, $this->categoryId);
         $frm->getField('category')->setDefaultElement('');
         // parse the form
         $frm->parse($this->tpl);
     }
     // parse category
     if (!empty($this->category)) {
         $this->tpl->assign('filterCategory', $this->category);
     }
 }
コード例 #25
0
ファイル: Meta.php プロジェクト: forkcms/forkcms
 /**
  * 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();
         }
     }
 }
コード例 #26
0
ファイル: Index.php プロジェクト: forkcms/forkcms
 /**
  * Parse all datagrids
  */
 protected function parse()
 {
     parent::parse();
     // parse the datagrid for the drafts
     $this->tpl->assign('dgDrafts', (string) $this->dgDrafts->getContent());
     // parse the datagrid for all blogposts
     $this->tpl->assign('dgPosts', (string) $this->dgPosts->getContent());
     // parse the datagrid for the most recent blogposts
     $this->tpl->assign('dgRecent', is_object($this->dgRecent) ? $this->dgRecent->getContent() : false);
     // get categories
     $categories = BackendBlogModel::getCategories(true);
     $hasMultipleCategories = count($categories) > 1;
     $this->tpl->assign('hasMultipleCategories', $hasMultipleCategories);
     // multiple categories?
     if ($hasMultipleCategories) {
         // create form
         $frm = new BackendForm('filter', null, 'get', false);
         // create element
         $frm->addDropdown('category', $categories, $this->categoryId);
         $frm->getField('category')->setDefaultElement('');
         // parse the form
         $frm->parse($this->tpl);
     }
     // parse category
     if (!empty($this->category)) {
         $this->tpl->assign('filterCategory', $this->category);
     }
 }
コード例 #27
0
ファイル: FormImage.php プロジェクト: forkcms/forkcms
 /**
  * Parses the html for this filefield.
  *
  * @param TwigTemplate $template The template to parse the element in.
  *
  * @throws \SpoonFormException
  *
  * @return string
  */
 public function parse($template = null)
 {
     // name is required
     if ($this->attributes['name'] == '') {
         throw new \SpoonFormException('A name is required for a file field. Please provide a name.');
     }
     // start html generation
     $output = '<input type="file"';
     // add attributes
     $output .= $this->getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'])) . ' />';
     // add help txt if needed
     if (!$this->hideHelpTxt) {
         $output .= '<p class="help-block">' . sprintf(BackendLanguage::getMessage('HelpImageFieldWithMaxFileSize', 'core'), Form::getUploadMaxFileSize()) . '</p>';
     }
     // parse to template
     if ($template !== null) {
         $template->assign('file' . SpoonFilter::toCamelCase($this->attributes['name']), $output);
         $template->assign('file' . SpoonFilter::toCamelCase($this->attributes['name']) . 'Error', $this->errors != '' ? '<span class="formError text-danger">' . $this->errors . '</span>' : '');
     }
     return $output;
 }
コード例 #28
0
 /**
  * @return bool
  */
 private function isValid()
 {
     $this->form->getField('web_property_id')->isFilled(Language::err('FieldIsRequired'));
     return $this->form->isCorrect();
 }
コード例 #29
0
ファイル: Categories.php プロジェクト: Comsa-Veurne/modules
 private function loadFilterForm()
 {
     // get categories
     $categories = BackendCatalogModel::getCategories(true);
     // multiple categories?
     if (count($categories) > 1) {
         // create form
         $frm = new BackendForm('filter', null, 'get', false);
         // create element
         $frm->addDropdown('category', $categories, $this->categoryId);
         //			$frm->getField('category')->setDefaultElement('');
         // parse the form
         $frm->parse($this->tpl);
     }
     // parse category
     if (!empty($this->category)) {
         $this->tpl->assign('filterCategory', $this->category);
     }
 }
コード例 #30
0
ファイル: Groups.php プロジェクト: Comsa-Veurne/modules
 private function loadFilterForm()
 {
     // get categories
     $groups = BackendAddressesModel::getAllGroupsTree();
     //$groups = array('') + $groups;
     // multiple categories?
     if (count($groups) > 1) {
         // create form
         $frm = new BackendForm('filter', null, 'get', false);
         // create element
         $frm->addDropdown('group', $groups, $this->groupId);
         //			$frm->getField('category')->setDefaultElement('');
         // parse the form
         $frm->parse($this->tpl);
     }
     // parse category
     if (!empty($this->category)) {
         $this->tpl->assign('filterGroup', $this->group);
     }
 }