本文整理汇总了PHP中FrontendModel::triggerEvent方法的典型用法代码示例。如果您正苦于以下问题:PHP FrontendModel::triggerEvent方法的具体用法?PHP FrontendModel::triggerEvent怎么用?PHP FrontendModel::triggerEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FrontendModel
的用法示例。
在下文中一共展示了FrontendModel::triggerEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateForm
/**
* Validate the form
*/
private function validateForm()
{
// is the form submitted
if ($this->frm->isSubmitted()) {
// validate required fields
$email = $this->frm->getField('email');
// validate required fields
if ($email->isEmail(FL::err('EmailIsInvalid'))) {
if (FrontendMailmotorModel::isSubscribed($email->getValue())) {
$email->addError(FL::err('AlreadySubscribed'));
}
}
// no errors
if ($this->frm->isCorrect()) {
try {
// subscribe the user to our default group
FrontendMailmotorCMHelper::subscribe($email->getValue());
// trigger event
FrontendModel::triggerEvent('mailmotor', 'after_subscribe', array('email' => $email->getValue()));
// redirect
$this->redirect(FrontendNavigation::getURLForBlock('mailmotor', 'subscribe') . '?sent=true#subscribeForm');
} catch (Exception $e) {
// when debugging we need to see the exceptions
if (SPOON_DEBUG) {
throw $e;
}
// show error
$this->tpl->assign('subscribeHasError', true);
}
} else {
$this->tpl->assign('subscribeHasFormError', true);
}
}
}
示例2: execute
/**
* Execute the extra.
*/
public function execute()
{
// get activation key
$key = $this->URL->getParameter(0);
// load template
$this->loadTemplate();
// do we have an activation key?
if (isset($key)) {
// get profile id
$profileId = FrontendProfilesModel::getIdBySetting('activation_key', $key);
// have id?
if ($profileId != null) {
// update status
FrontendProfilesModel::update($profileId, array('status' => 'active'));
// delete activation key
FrontendProfilesModel::deleteSetting($profileId, 'activation_key');
// login profile
FrontendProfilesAuthentication::login($profileId);
// trigger event
FrontendModel::triggerEvent('profiles', 'after_activate', array('id' => $profileId));
// show success message
$this->tpl->assign('activationSuccess', true);
} else {
$this->redirect(FrontendNavigation::getURL(404));
}
} else {
$this->redirect(FrontendNavigation::getURL(404));
}
}
示例3: execute
/**
* Execute the extra.
*
* @return void
*/
public function execute()
{
// logout
if (FrontendProfilesAuthentication::isLoggedIn()) {
FrontendProfilesAuthentication::logout();
}
// trigger event
FrontendModel::triggerEvent('profiles', 'after_logout');
// redirect
$this->redirect(SITE_URL);
}
示例4: initializeFacebook
/**
* Initialize Facebook
*/
private function initializeFacebook()
{
// get settings
$facebookApplicationId = FrontendModel::getModuleSetting('core', 'facebook_app_id');
$facebookApplicationSecret = FrontendModel::getModuleSetting('core', 'facebook_app_secret');
// needed data available?
if ($facebookApplicationId != '' && $facebookApplicationSecret != '') {
// require
require_once 'external/facebook.php';
// create instance
$facebook = new Facebook($facebookApplicationSecret, $facebookApplicationId);
// get the cookie, this will set the access token.
$facebook->getCookie();
// store in reference
Spoon::set('facebook', $facebook);
// trigger event
FrontendModel::triggerEvent('core', 'after_facebook_initialization');
}
}
示例5: validateForm
/**
* Validate the form.
*/
private function validateForm()
{
// submitted
if ($this->frm->isSubmitted()) {
// does the key exists?
if (SpoonSession::exists('formbuilder_' . $this->item['id'])) {
// calculate difference
$diff = time() - (int) SpoonSession::get('formbuilder_' . $this->item['id']);
// calculate difference, it it isn't 10 seconds the we tell the user to slow down
if ($diff < 10 && $diff != 0) {
$this->frm->addError(FL::err('FormTimeout'));
}
}
// validate fields
foreach ($this->item['fields'] as $field) {
// fieldname
$fieldName = 'field' . $field['id'];
// skip
if ($field['type'] == 'submit' || $field['type'] == 'paragraph' || $field['type'] == 'heading') {
continue;
}
// loop other validations
foreach ($field['validations'] as $rule => $settings) {
// already has an error so skip
if ($this->frm->getField($fieldName)->getErrors() !== null) {
continue;
}
// required
if ($rule == 'required') {
$this->frm->getField($fieldName)->isFilled($settings['error_message']);
} elseif ($rule == 'email') {
// only check this if the field is filled, if the field is required it will be validated before
if ($this->frm->getField($fieldName)->isFilled()) {
$this->frm->getField($fieldName)->isEmail($settings['error_message']);
}
} elseif ($rule == 'numeric') {
// only check this if the field is filled, if the field is required it will be validated before
if ($this->frm->getField($fieldName)->isFilled()) {
$this->frm->getField($fieldName)->isNumeric($settings['error_message']);
}
}
}
}
// valid form
if ($this->frm->isCorrect()) {
// item
$data['form_id'] = $this->item['id'];
$data['session_id'] = SpoonSession::getSessionId();
$data['sent_on'] = FrontendModel::getUTCDate();
$data['data'] = serialize(array('server' => $_SERVER));
// insert data
$dataId = FrontendFormBuilderModel::insertData($data);
// init fields array
$fields = array();
// loop all fields
foreach ($this->item['fields'] as $field) {
// skip
if ($field['type'] == 'submit' || $field['type'] == 'paragraph' || $field['type'] == 'heading') {
continue;
}
// field data
$fieldData['data_id'] = $dataId;
$fieldData['label'] = $field['settings']['label'];
$fieldData['value'] = $this->frm->getField('field' . $field['id'])->getValue();
// prepare fields for email
if ($this->item['method'] == 'database_email') {
// add field for email
$emailFields[] = array('label' => $field['settings']['label'], 'value' => is_array($fieldData['value']) ? implode(',', $fieldData['value']) : nl2br($fieldData['value']));
}
// clean up
if (is_array($fieldData['value']) && empty($fieldData['value'])) {
$fieldData['value'] = null;
}
// serialize
if ($fieldData['value'] !== null) {
$fieldData['value'] = serialize($fieldData['value']);
}
// save fields data
$fields[] = $fieldData;
// insert
FrontendFormBuilderModel::insertDataField($fieldData);
}
// need to send mail
if ($this->item['method'] == 'database_email') {
// build variables
$variables['sentOn'] = time();
$variables['name'] = $this->item['name'];
$variables['fields'] = $emailFields;
// loop recipients
foreach ($this->item['email'] as $address) {
// add email
FrontendMailer::addEmail(sprintf(FL::getMessage('FormBuilderSubject'), $this->item['name']), FRONTEND_MODULES_PATH . '/form_builder/layout/templates/mails/form.tpl', $variables, $address, $this->item['name']);
}
}
// trigger event
FrontendModel::triggerEvent('form_builder', 'after_submission', array('form_id' => $this->item['id'], 'data_id' => $dataId, 'data' => $data, 'fields' => $fields, 'visitorId' => FrontendModel::getVisitorId()));
// store timestamp in session so we can block excesive usage
//.........这里部分代码省略.........
示例6: validateForm
/**
* Validate the form
*/
private function validateForm()
{
// get settings
$commentsAllowed = isset($this->settings['allow_comments']) && $this->settings['allow_comments'];
// comments aren't allowed so we don't have to validate
if (!$commentsAllowed) {
return false;
}
// is the form submitted
if ($this->frm->isSubmitted()) {
// cleanup the submitted fields, ignore fields that were added by hackers
$this->frm->cleanupFields();
// does the key exists?
if (SpoonSession::exists('blog_comment_' . $this->record['id'])) {
// calculate difference
$diff = time() - (int) SpoonSession::get('blog_comment_' . $this->record['id']);
// calculate difference, it it isn't 10 seconds the we tell the user to slow down
if ($diff < 10 && $diff != 0) {
$this->frm->getField('message')->addError(FL::err('CommentTimeout'));
}
}
// validate required fields
$this->frm->getField('author')->isFilled(FL::err('AuthorIsRequired'));
$this->frm->getField('email')->isEmail(FL::err('EmailIsRequired'));
$this->frm->getField('message')->isFilled(FL::err('MessageIsRequired'));
// validate optional fields
if ($this->frm->getField('website')->isFilled() && $this->frm->getField('website')->getValue() != 'http://') {
$this->frm->getField('website')->isURL(FL::err('InvalidURL'));
}
// no errors?
if ($this->frm->isCorrect()) {
// get module setting
$spamFilterEnabled = isset($this->settings['spamfilter']) && $this->settings['spamfilter'];
$moderationEnabled = isset($this->settings['moderation']) && $this->settings['moderation'];
// reformat data
$author = $this->frm->getField('author')->getValue();
$email = $this->frm->getField('email')->getValue();
$website = $this->frm->getField('website')->getValue();
if (trim($website) == '' || $website == 'http://') {
$website = null;
}
$text = $this->frm->getField('message')->getValue();
// build array
$comment['post_id'] = $this->record['id'];
$comment['language'] = FRONTEND_LANGUAGE;
$comment['created_on'] = FrontendModel::getUTCDate();
$comment['author'] = $author;
$comment['email'] = $email;
$comment['website'] = $website;
$comment['text'] = $text;
$comment['status'] = 'published';
$comment['data'] = serialize(array('server' => $_SERVER));
// get URL for article
$permaLink = FrontendNavigation::getURLForBlock('blog', 'detail') . '/' . $this->record['url'];
$redirectLink = $permaLink;
// is moderation enabled
if ($moderationEnabled) {
// if the commenter isn't moderated before alter the comment status so it will appear in the moderation queue
if (!FrontendBlogModel::isModerated($author, $email)) {
$comment['status'] = 'moderation';
}
}
// should we check if the item is spam
if ($spamFilterEnabled) {
// check for spam
$result = FrontendModel::isSpam($text, SITE_URL . $permaLink, $author, $email, $website);
// if the comment is spam alter the comment status so it will appear in the spam queue
if ($result) {
$comment['status'] = 'spam';
} elseif ($result == 'unknown') {
$comment['status'] = 'moderation';
}
}
// insert comment
$comment['id'] = FrontendBlogModel::insertComment($comment);
// trigger event
FrontendModel::triggerEvent('blog', 'after_add_comment', array('comment' => $comment));
// append a parameter to the URL so we can show moderation
if (strpos($redirectLink, '?') === false) {
if ($comment['status'] == 'moderation') {
$redirectLink .= '?comment=moderation#' . FL::act('Comment');
}
if ($comment['status'] == 'spam') {
$redirectLink .= '?comment=spam#' . FL::act('Comment');
}
if ($comment['status'] == 'published') {
$redirectLink .= '?comment=true#comment-' . $comment['id'];
}
} else {
if ($comment['status'] == 'moderation') {
$redirectLink .= '&comment=moderation#' . FL::act('Comment');
}
if ($comment['status'] == 'spam') {
$redirectLink .= '&comment=spam#' . FL::act('Comment');
}
if ($comment['status'] == 'published') {
$redirectLink .= '&comment=true#comment-' . $comment['id'];
//.........这里部分代码省略.........
示例7: validateForm
/**
* Validate the form
*/
private function validateForm()
{
// is the form submitted
if ($this->frm->isSubmitted()) {
// get field
$txtEmail = $this->frm->getField('email');
// field is filled in?
if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
// valid email?
if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
// email exists?
if (!FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
$txtEmail->addError(FL::getError('EmailIsUnknown'));
}
}
}
// valid login
if ($this->frm->isCorrect()) {
// get profile id
$profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
// generate forgot password key
$key = FrontendProfilesModel::getEncryptedString($profileId . microtime(), FrontendProfilesModel::getRandomString());
// insert forgot password key
FrontendProfilesModel::setSetting($profileId, 'forgot_password_key', $key);
// reset url
$mailValues['resetUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'reset_password') . '/' . $key;
$mailValues['firstName'] = FrontendProfilesModel::getSetting($profileId, 'first_name');
$mailValues['lastName'] = FrontendProfilesModel::getSetting($profileId, 'last_name');
// trigger event
FrontendModel::triggerEvent('profiles', 'after_forgot_password', array('id' => $profileId));
// send email
FrontendMailer::addEmail(FL::getMessage('ForgotPasswordSubject'), FRONTEND_MODULES_PATH . '/profiles/layout/templates/mails/forgot_password.tpl', $mailValues, $txtEmail->getValue(), '');
// redirect
$this->redirect(SELF . '?sent=true');
} else {
$this->tpl->assign('forgotPasswordHasError', true);
}
}
}
示例8: validateForm
/**
* Validate the form
*/
private function validateForm()
{
// is the form submitted
if ($this->frm->isSubmitted()) {
// get fields
$txtEmail = $this->frm->getField('email');
$txtPassword = $this->frm->getField('password');
// check email
if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
// valid email?
if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
// email already exists?
if (FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
// set error
$txtEmail->setError(FL::getError('EmailExists'));
}
}
}
// check password
$txtPassword->isFilled(FL::getError('PasswordIsRequired'));
// no errors
if ($this->frm->isCorrect()) {
// generate salt
$salt = FrontendProfilesModel::getRandomString();
// init values
$values = array();
// values
$values['email'] = $txtEmail->getValue();
$values['password'] = FrontendProfilesModel::getEncryptedString($txtPassword->getValue(), $salt);
$values['status'] = 'inactive';
$values['display_name'] = $txtEmail->getValue();
$values['registered_on'] = FrontendModel::getUTCDate();
/*
* Add a profile.
* We use a try-catch statement to catch errors when more users sign up simultaneously.
*/
try {
// insert profile
$profileId = FrontendProfilesModel::insert($values);
// use the profile id as url until we have an actual url
FrontendProfilesModel::update($profileId, array('url' => FrontendProfilesModel::getUrl($values['display_name'])));
// trigger event
FrontendModel::triggerEvent('profiles', 'after_register', array('id' => $profileId));
// generate activation key
$activationKey = FrontendProfilesModel::getEncryptedString($profileId . microtime(), $salt);
// set settings
FrontendProfilesModel::setSetting($profileId, 'salt', $salt);
FrontendProfilesModel::setSetting($profileId, 'activation_key', $activationKey);
// login
FrontendProfilesAuthentication::login($profileId);
// activation URL
$mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'activate') . '/' . $activationKey;
// send email
FrontendMailer::addEmail(FL::getMessage('RegisterSubject'), FRONTEND_MODULES_PATH . '/profiles/layout/templates/mails/register.tpl', $mailValues, $values['email'], '');
// redirect
$this->redirect(SELF . '?sent=true');
} catch (Exception $e) {
// when debugging we need to see the exceptions
if (SPOON_DEBUG) {
throw $e;
}
// show error
$this->tpl->assign('registerHasFormError', true);
}
} else {
$this->tpl->assign('registerHasFormError', true);
}
}
}
示例9: __construct
public function __construct()
{
parent::__construct();
// set tracking cookie
FrontendModel::getVisitorId();
// add reference
Spoon::set('page', $this);
// get pageId for requested URL
$this->pageId = FrontendNavigation::getPageId(implode('/', $this->URL->getPages()));
// set headers if this is a 404 page
if ($this->pageId == 404) {
$this->statusCode = 404;
}
// create breadcrumb instance
$this->breadcrumb = new FrontendBreadcrumb();
// create header instance
$this->header = new FrontendHeader();
// new footer instance
$this->footer = new FrontendFooter();
// get pagecontent
$this->getPageContent();
// process page
$this->processPage();
// execute all extras linked to the page
$this->processExtras();
// store statistics
$this->storeStatistics();
// display
$this->display();
// trigger event
FrontendModel::triggerEvent('core', 'after_page_processed', array('id' => $this->getId(), 'record' => $this->getRecord(), 'statusCode' => $this->getStatusCode(), 'sessionId' => SpoonSession::getSessionId(), 'visitorId' => FrontendModel::getVisitorId(), 'SESSION' => $_SESSION, 'COOKIE' => $_COOKIE, 'GET' => $_GET, 'POST' => $_POST, 'SERVER' => $_SERVER));
}
示例10: validateForm
/**
* Validate the form.
*
* @return void
*/
private function validateForm()
{
// is the form submitted
if ($this->frm->isSubmitted()) {
// get fields
$txtPassword = $this->frm->getField('password');
// field is filled in?
$txtPassword->isFilled(FL::getError('PasswordIsRequired'));
// valid
if ($this->frm->isCorrect()) {
// get profile id
$profileId = FrontendProfilesModel::getIdBySetting('forgot_password_key', $this->URL->getParameter(0));
// remove key (we can only update the password once with this key)
FrontendProfilesModel::deleteSetting($profileId, 'forgot_password_key');
// update password
FrontendProfilesAuthentication::updatePassword($profileId, $txtPassword->getValue());
// login (check again because we might have logged in in the meanwhile)
if (!FrontendProfilesAuthentication::isLoggedIn()) {
FrontendProfilesAuthentication::login($profileId);
}
// trigger event
FrontendModel::triggerEvent('profiles', 'after_reset_password', array('id' => $profileId));
// redirect
$this->redirect(FrontendNavigation::getURLForBlock('profiles', 'reset_password') . '/' . $this->URL->getParameter(0) . '?saved=true');
} else {
$this->tpl->assign('forgotPasswordHasError', true);
}
}
}
示例11: validateForm
/**
* Validate the form.
*/
private function validateForm()
{
// is the form submitted
if ($this->frm->isSubmitted()) {
// get fields
$txtPassword = $this->frm->getField('password');
$txtEmail = $this->frm->getField('email');
// password filled in?
if ($txtPassword->isFilled(FL::getError('PasswordIsRequired'))) {
// password correct?
if (FrontendProfilesAuthentication::getLoginStatus($this->profile->getEmail(), $txtPassword->getValue()) !== FrontendProfilesAuthentication::LOGIN_ACTIVE) {
// set error
$txtPassword->addError(FL::getError('InvalidPassword'));
}
// email filled in?
if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
// valid email?
if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
// email already exists?
if (FrontendProfilesModel::existsByEmail($txtEmail->getValue(), $this->profile->getId())) {
// set error
$txtEmail->setError(FL::getError('EmailExists'));
}
}
}
}
// no errors
if ($this->frm->isCorrect()) {
// update email
FrontendProfilesModel::update($this->profile->getId(), array('email' => $txtEmail->getValue()));
// trigger event
FrontendModel::triggerEvent('profiles', 'after_change_email', array('id' => $this->profile->getId()));
// redirect
$this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'change_email') . '?sent=true');
} else {
$this->tpl->assign('updateEmailHasFormError', true);
}
}
}
示例12: validateForm
/**
* Validate the form
*/
private function validateForm()
{
// is the form submitted
if ($this->frm->isSubmitted()) {
// get field
$txtEmail = $this->frm->getField('email');
// field is filled in?
if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
// valid email?
if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
// email exists?
if (FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
// get profile id using the filled in email
$profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
// get profile
$profile = FrontendProfilesModel::get($profileId);
// must be inactive
if ($profile->getStatus() != FrontendProfilesAuthentication::LOGIN_INACTIVE) {
$txtEmail->addError(FL::getError('ProfileIsActive'));
}
} else {
$txtEmail->addError(FL::getError('EmailIsInvalid'));
}
}
}
// valid login
if ($this->frm->isCorrect()) {
// activation URL
$mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'activate') . '/' . $profile->getSetting('activation_key');
// trigger event
FrontendModel::triggerEvent('profiles', 'after_resend_activation', array('id' => $profileId));
// send email
FrontendMailer::addEmail(FL::getMessage('RegisterSubject'), FRONTEND_MODULES_PATH . '/profiles/layout/templates/mails/register.tpl', $mailValues, $profile->getEmail(), '');
// redirect
$this->redirect(SELF . '?sent=true');
} else {
$this->tpl->assign('resendActivationHasError', true);
}
}
}
示例13: send
/**
* Send an email
*
* @return void
* @param int $id The id of the mail to send.
*/
public static function send($id)
{
// redefine
$id = (int) $id;
// get db
$db = FrontendModel::getDB(true);
// get record
$emailRecord = (array) $db->getRecord('SELECT *
FROM emails AS e
WHERE e.id = ?', array($id));
// mailer type
$mailerType = FrontendModel::getModuleSetting('core', 'mailer_type', 'mail');
// create new SpoonEmail-instance
$email = new SpoonEmail();
$email->setTemplateCompileDirectory(FRONTEND_CACHE_PATH . '/compiled_templates');
// send via SMTP
if ($mailerType == 'smtp') {
// get settings
$SMTPServer = FrontendModel::getModuleSetting('core', 'smtp_server');
$SMTPPort = FrontendModel::getModuleSetting('core', 'smtp_port', 25);
$SMTPUsername = FrontendModel::getModuleSetting('core', 'smtp_username');
$SMTPPassword = FrontendModel::getModuleSetting('core', 'smtp_password');
// set server and connect with SMTP
$email->setSMTPConnection($SMTPServer, $SMTPPort, 10);
// set authentication if needed
if ($SMTPUsername !== null && $SMTPPassword !== null) {
$email->setSMTPAuth($SMTPUsername, $SMTPPassword);
}
}
// set some properties
$email->setFrom($emailRecord['from_email'], $emailRecord['from_name']);
$email->addRecipient($emailRecord['to_email'], $emailRecord['to_name']);
$email->setReplyTo($emailRecord['reply_to_email']);
$email->setSubject($emailRecord['subject']);
$email->setHTMLContent($emailRecord['html']);
$email->setCharset(SPOON_CHARSET);
$email->setContentTransferEncoding('base64');
if ($emailRecord['plain_text'] != '') {
$email->setPlainContent($emailRecord['plain_text']);
}
// attachments added
if (isset($emailRecord['attachments']) && $emailRecord['attachments'] !== null) {
// unserialize
$attachments = (array) unserialize($emailRecord['attachments']);
// add attachments to email
foreach ($attachments as $attachment) {
$email->addAttachment($attachment);
}
}
// send the email
if ($email->send()) {
// remove the email
$db->delete('emails', 'id = ?', array($id));
// trigger event
FrontendModel::triggerEvent('core', 'after_email_sent', array('id' => $id));
}
}
示例14: validateForm
/**
* Validate the form.
*/
private function validateForm()
{
// is the form submitted
if ($this->frm->isSubmitted()) {
// get fields
$txtDisplayName = $this->frm->getField('display_name');
$txtFirstName = $this->frm->getField('first_name');
$txtLastName = $this->frm->getField('last_name');
$txtCity = $this->frm->getField('city');
$ddmCountry = $this->frm->getField('country');
$ddmGender = $this->frm->getField('gender');
$ddmDay = $this->frm->getField('day');
$ddmMonth = $this->frm->getField('month');
$ddmYear = $this->frm->getField('year');
// get number of display name changes
$nameChanges = (int) FrontendProfilesModel::getSetting($this->profile->getId(), 'display_name_changes');
// has there been a valid display name change request?
if ($this->profile->getDisplayName() !== $txtDisplayName->getValue() && $nameChanges <= FrontendProfilesModel::MAX_DISPLAY_NAME_CHANGES) {
// display name filled in?
if ($txtDisplayName->isFilled(FL::getError('FieldIsRequired'))) {
// display name exists?
if (FrontendProfilesModel::existsDisplayName($txtDisplayName->getValue(), $this->profile->getId())) {
// set error
$txtDisplayName->addError(FL::getError('DisplayNameExists'));
}
}
}
// birthdate is not required but if one is filled we need all
if ($ddmMonth->isFilled() || $ddmDay->isFilled() || $ddmYear->isFilled()) {
// valid birth date?
if (!checkdate($ddmMonth->getValue(), $ddmDay->getValue(), $ddmYear->getValue())) {
// set error
$ddmYear->addError(FL::getError('DateIsInvalid'));
}
}
// no errors
if ($this->frm->isCorrect()) {
// init
$values = array();
// has there been a valid display name change request?
if ($this->profile->getDisplayName() !== $txtDisplayName->getValue() && $nameChanges <= FrontendProfilesModel::MAX_DISPLAY_NAME_CHANGES) {
// get display name value
$values['display_name'] = $txtDisplayName->getValue();
// update url based on the new display name
$values['url'] = FrontendProfilesModel::getUrl($txtDisplayName->getValue(), $this->profile->getId());
// update display name count
$this->profile->setSetting('display_name_changes', $nameChanges + 1);
}
// update values
if (!empty($values)) {
FrontendProfilesModel::update($this->profile->getId(), $values);
}
// bday is filled in
if ($ddmYear->isFilled()) {
// mysql format
$birthDate = $ddmYear->getValue() . '-';
$birthDate .= str_pad($ddmMonth->getValue(), 2, '0', STR_PAD_LEFT) . '-';
$birthDate .= str_pad($ddmDay->getValue(), 2, '0', STR_PAD_LEFT);
} else {
$birthDate = null;
}
// update settings
$this->profile->setSetting('first_name', $txtFirstName->getValue());
$this->profile->setSetting('last_name', $txtLastName->getValue());
$this->profile->setSetting('city', $txtCity->getValue());
$this->profile->setSetting('country', $ddmCountry->getValue());
$this->profile->setSetting('gender', $ddmGender->getValue());
$this->profile->setSetting('birth_date', $birthDate);
// trigger event
FrontendModel::triggerEvent('profiles', 'after_saved_settings', array('id' => $this->profile->getId()));
// redirect
$this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'settings') . '?sent=true');
} else {
$this->tpl->assign('updateSettingsHasFormError', true);
}
}
}
示例15: validateForm
/**
* Validate the form
*
* @return void
*/
private function validateForm()
{
// is the form submitted
if ($this->frm->isSubmitted()) {
// get fields
$txtOldPassword = $this->frm->getField('old_password');
$txtNewPassword = $this->frm->getField('new_password');
// old password filled in?
if ($txtOldPassword->isFilled(FL::getError('PasswordIsRequired'))) {
// old password correct?
if (FrontendProfilesAuthentication::getLoginStatus($this->profile->getEmail(), $txtOldPassword->getValue()) !== FrontendProfilesAuthentication::LOGIN_ACTIVE) {
// set error
$txtOldPassword->addError(FL::getError('InvalidPassword'));
}
// new password filled in?
$txtNewPassword->isFilled(FL::getError('PasswordIsRequired'));
}
// no errors
if ($this->frm->isCorrect()) {
// update password
FrontendProfilesAuthentication::updatePassword($this->profile->getId(), $txtNewPassword->getValue());
// trigger event
FrontendModel::triggerEvent('profiles', 'after_profile_password', array('id' => $this->profile->getId()));
// redirect
$this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'profile_password') . '?saved=true');
} else {
$this->tpl->assign('updatePasswordHasFormError', true);
}
}
}