本文整理汇总了PHP中SpoonSession::set方法的典型用法代码示例。如果您正苦于以下问题:PHP SpoonSession::set方法的具体用法?PHP SpoonSession::set怎么用?PHP SpoonSession::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpoonSession
的用法示例。
在下文中一共展示了SpoonSession::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Execute the action
*/
public function execute()
{
parent::execute();
// get parameters
$charset = $this->getContainer()->getParameter('kernel.charset');
$searchTerm = \SpoonFilter::getPostValue('term', null, '');
$term = $charset == 'utf-8' ? \SpoonFilter::htmlspecialchars($searchTerm) : \SpoonFilter::htmlentities($searchTerm);
// validate search term
if ($term == '') {
$this->output(self::BAD_REQUEST, null, 'term-parameter is missing.');
} else {
// previous search result
$previousTerm = \SpoonSession::exists('searchTerm') ? \SpoonSession::get('searchTerm') : '';
\SpoonSession::set('searchTerm', '');
// save this term?
if ($previousTerm != $term) {
// format data
$this->statistics = array();
$this->statistics['term'] = $term;
$this->statistics['language'] = LANGUAGE;
$this->statistics['time'] = FrontendModel::getUTCDate();
$this->statistics['data'] = serialize(array('server' => $_SERVER));
$this->statistics['num_results'] = FrontendSearchModel::getTotal($term);
// save data
FrontendSearchModel::save($this->statistics);
}
// save current search term in cookie
\SpoonSession::set('searchTerm', $term);
// output
$this->output(self::OK);
}
}
示例2: validateForm
/**
* Validate the form
*/
protected function validateForm()
{
if ($this->frm->isSubmitted()) {
$this->frm->cleanupFields();
// validation
$fields = $this->frm->getFields();
$fields['title']->isFilled(Language::err('TitleIsRequired'));
$fields['description']->isFilled(Language::err('FieldIsRequired'));
$fields['author_name']->isFilled(Language::err('FieldIsRequired'));
$fields['author_url']->isFilled(Language::err('FieldIsRequired'));
$fields['author_email']->isFilled(Language::err('FieldIsRequired'));
// cleanup the modulename
$title = preg_replace('/[^A-Za-z ]/', '', $fields['title']->getValue());
// check if there is already a module with this name
if (BackendExtensionsModel::existsModule($title)) {
$fields['title']->addError(Language::err('DuplicateModuleName'));
}
if ($this->frm->isCorrect()) {
$this->record['title'] = $title;
$this->record['description'] = trim($fields['description']->getValue());
$this->record['author_name'] = $fields['author_name']->getValue();
$this->record['author_url'] = $fields['author_url']->getValue();
$this->record['author_email'] = $fields['author_email']->getValue();
$this->record['camel_case_name'] = BackendModuleMakerHelper::buildCamelCasedName($title);
$this->record['underscored_name'] = BackendModuleMakerHelper::buildUnderscoredName($title);
\SpoonSession::set('module', $this->record);
$this->redirect(Model::createURLForAction('AddStep2'));
}
}
}
示例3: validateForm
/**
* Validate the form
*/
protected function validateForm()
{
if ($this->frm->isSubmitted()) {
$this->frm->cleanupFields();
$frmFields = $this->frm->getFields();
// validate form
if ($frmFields['twitter']->isChecked()) {
// we need fields when search is ticked
$frmFields['twitter_name']->isFilled(Language::err('FieldIsRequired'));
}
if ($this->frm->isCorrect()) {
// if this field is checked, let's add a boolean searchable true to the chosen fields
if ($frmFields['twitter']->isChecked()) {
$this->record['twitter'] = $frmFields['twitter_name']->getValue();
} else {
if (array_key_exists('twitter', $this->record)) {
unset($this->record['twitter']);
}
}
// save the object in our session
\SpoonSession::set('module', $this->record);
$this->redirect(Model::createURLForAction('Generate'));
}
}
}
示例4: execute
/**
* Execute the action
*
* @return void
*/
public function execute()
{
// call parent, this will probably add some general CSS/JS or other required files
parent::execute();
// get parameters
$term = SpoonFilter::getGetValue('term', null, '');
// validate
if ($term == '') {
$this->output(self::BAD_REQUEST, null, 'term-parameter is missing.');
}
// previous search result
$previousTerm = SpoonSession::exists('searchTerm') ? SpoonSession::get('searchTerm') : '';
SpoonSession::set('searchTerm', '');
// save this term?
if ($previousTerm != $term) {
// format data
$this->statistics = array();
$this->statistics['term'] = $term;
$this->statistics['language'] = FRONTEND_LANGUAGE;
$this->statistics['time'] = FrontendModel::getUTCDate();
$this->statistics['data'] = serialize(array('server' => $_SERVER));
$this->statistics['num_results'] = FrontendSearchModel::getTotal($term);
// save data
FrontendSearchModel::save($this->statistics);
}
// save current search term in cookie
SpoonSession::set('searchTerm', $term);
// output
$this->output(self::OK);
}
示例5: checkToken
/**
* Check if the token is ok
*/
public function checkToken()
{
$fromSession = \SpoonSession::exists('csrf_token') ? \SpoonSession::get('csrf_token') : '';
$fromGet = \SpoonFilter::getGetValue('token', null, '');
if ($fromSession != '' && $fromGet != '' && $fromSession == $fromGet) {
return;
}
// clear the token
\SpoonSession::set('csrf_token', '');
$this->redirect(BackendModel::createURLForAction('Index', null, null, array('error' => 'csrf')));
}
示例6: validateForm
/**
* Validate the form based on the variables in $_POST
*
* @return void
*/
private function validateForm()
{
// form submitted
if ($this->frm->isSubmitted()) {
// required fields
$this->frm->getField('email')->isEmail('Please provide a valid e-mailaddress.');
$this->frm->getField('password')->isFilled('This field is required.');
$this->frm->getField('confirm')->isFilled('This field is required.');
if ($this->frm->getField('password')->getValue() != $this->frm->getField('confirm')->getValue()) {
$this->frm->getField('confirm')->addError('The passwords do not match.');
}
// all valid
if ($this->frm->isCorrect()) {
// update session
SpoonSession::set('email', $this->frm->getField('email')->getValue());
SpoonSession::set('password', $this->frm->getField('password')->getValue());
SpoonSession::set('confirm', $this->frm->getField('confirm')->getValue());
// redirect
SpoonHTTP::redirect('index.php?step=7');
}
}
}
示例7: execute
/**
* Execute the action
*/
public function execute()
{
// If step 1 isn't entered, redirect back to the first step of the wizard
$this->record = \SpoonSession::get('module');
if (!$this->record || !array_key_exists('title', $this->record)) {
$this->redirect(Model::createURLForAction('Add'));
}
// If there are no fields added, redirect back to the second step of the wizard
if (!array_key_exists('fields', $this->record) || empty($this->record['fields'])) {
$this->redirect(Model::createURLForAction('AddStep2') . '&error=non-existing');
}
// get parameters
$this->id = $this->getParameter('id', 'int');
// does the item exist
if ($this->id !== null && array_key_exists($this->id, $this->record['fields'])) {
unset($this->record['fields'][$this->id]);
\SpoonSession::set('module', $this->record);
$this->redirect(Model::createURLForAction('AddStep2') . '&report=deleted');
} else {
$this->redirect(Model::createURLForAction('AddStep2') . '&error=non-existing');
}
}
示例8: validateForm
/**
* Validate the form
*/
private function validateForm()
{
// get settings
$subscriptionsAllowed = isset($this->settings['allow_subscriptions']) && $this->settings['allow_subscriptions'];
// subscriptions aren't allowed so we don't have to validate
if (!$subscriptionsAllowed) {
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('agenda_subscription_' . $this->record['id'])) {
// calculate difference
$diff = time() - (int) \SpoonSession::get('agenda_subscription_' . $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('name')->isFilled(FL::err('NameIsRequired'));
$this->frm->getField('email')->isEmail(FL::err('EmailIsRequired'));
// no errors?
if ($this->frm->isCorrect()) {
// get module setting
$moderationEnabled = isset($this->settings['moderation']) && $this->settings['moderation'];
// reformat data
$name = $this->frm->getField('name')->getValue();
$email = $this->frm->getField('email')->getValue();
// build array
$subscription['agenda_id'] = $this->record['id'];
$subscription['language'] = FRONTEND_LANGUAGE;
$subscription['created_on'] = FrontendModel::getUTCDate();
$subscription['name'] = $name;
$subscription['email'] = $email;
$subscription['status'] = 'subscribed';
// get URL for article
$permaLink = $this->record['full_url'];
$redirectLink = $permaLink;
// is moderation enabled
if ($moderationEnabled) {
// if the commenter isn't moderated before alter the subscription status so it will appear in the moderation queue
if (!FrontendAgendaModel::isModerated($name, $email)) {
$subscription['status'] = 'moderation';
}
}
// insert comment
$subscription['id'] = FrontendAgendaModel::insertSubscription($subscription);
// trigger event
FrontendModel::triggerEvent('agenda', 'after_add_subscription', array('subscription' => $subscription));
// append a parameter to the URL so we can show moderation
if (strpos($redirectLink, '?') === false) {
if ($subscription['status'] == 'moderation') {
$redirectLink .= '?subscription=moderation#' . FL::act('Subscribe');
}
if ($subscription['status'] == 'subscribed') {
$redirectLink .= '?subscription=true#subscription-' . $subscription['id'];
}
} else {
if ($subscription['status'] == 'moderation') {
$redirectLink .= '&subscription=moderation#' . FL::act('Subscribe');
}
if ($subscription['status'] == 'subscribed') {
$redirectLink .= '&subscription=true#comment-' . $subscription['id'];
}
}
// set title
$subscription['agenda_title'] = $this->record['title'];
$subscription['agenda_url'] = $this->record['url'];
// notify the admin
FrontendAgendaModel::notifyAdmin($subscription);
// store timestamp in session so we can block excessive usage
\SpoonSession::set('agenda_subscription_' . $this->record['id'], time());
// store author-data in cookies
try {
Cookie::set('subscription_author', $name);
Cookie::set('subscription_email', $email);
} catch (Exception $e) {
// settings cookies isn't allowed, but because this isn't a real problem we ignore the exception
}
// redirect
$this->redirect($redirectLink);
}
}
}
示例9: processQueryString
/**
* Process the querystring
*
* @return void
*/
private function processQueryString()
{
// store the querystring local, so we don't alter it.
$queryString = $this->getQueryString();
// fix GET-parameters
$getChunks = explode('?', $queryString);
// are there GET-parameters
if (isset($getChunks[1])) {
// get key-value pairs
$get = explode('&', $getChunks[1]);
// remove from querystring
$queryString = str_replace('?' . $getChunks[1], '', $this->getQueryString());
// loop pairs
foreach ($get as $getItem) {
// get key and value
$getChunks = explode('=', $getItem, 2);
// key available?
if (isset($getChunks[0])) {
// reset in $_GET
$_GET[$getChunks[0]] = isset($getChunks[1]) ? (string) $getChunks[1] : '';
// add into parameters
if (isset($getChunks[1])) {
$this->parameters[(string) $getChunks[0]] = (string) $getChunks[1];
}
}
}
}
// split into chunks
$chunks = (array) explode('/', $queryString);
// single language
if (!SITE_MULTILANGUAGE) {
// set language id
$language = FrontendModel::getModuleSetting('core', 'default_language', SITE_DEFAULT_LANGUAGE);
} else {
// default value
$mustRedirect = false;
// get possible languages
$possibleLanguages = (array) FrontendLanguage::getActiveLanguages();
$redirectLanguages = (array) FrontendLanguage::getRedirectLanguages();
// the language is present in the URL
if (isset($chunks[0]) && in_array($chunks[0], $possibleLanguages)) {
// define language
$language = (string) $chunks[0];
// try to set a cookie with the language
try {
// set cookie
SpoonCookie::set('frontend_language', $language, 7 * 24 * 60 * 60, '/', '.' . $this->getDomain());
} catch (SpoonCookieException $e) {
// settings cookies isn't allowed, because this isn't a real problem we ignore the exception
}
// set sessions
SpoonSession::set('frontend_language', $language);
// remove the language part
array_shift($chunks);
} elseif (SpoonCookie::exists('frontend_language') && in_array(SpoonCookie::get('frontend_language'), $redirectLanguages)) {
// set languageId
$language = (string) SpoonCookie::get('frontend_language');
// redirect is needed
$mustRedirect = true;
} else {
// set languageId & abbreviation
$language = FrontendLanguage::getBrowserLanguage();
// try to set a cookie with the language
try {
// set cookie
SpoonCookie::set('frontend_language', $language, 7 * 24 * 60 * 60, '/', '.' . $this->getDomain());
} catch (SpoonCookieException $e) {
// settings cookies isn't allowed, because this isn't a real problem we ignore the exception
}
// redirect is needed
$mustRedirect = true;
}
// redirect is required
if ($mustRedirect) {
// build URL
$URL = rtrim('/' . $language . '/' . $this->getQueryString(), '/');
// set header & redirect
SpoonHTTP::redirect($URL, 301);
}
}
// define the language
define('FRONTEND_LANGUAGE', $language);
// sets the localefile
FrontendLanguage::setLocale($language);
// list of pageIds & their full URL
$keys = FrontendNavigation::getKeys();
// full URL
$URL = implode('/', $chunks);
$startURL = $URL;
// loop until we find the URL in the list of pages
while (!in_array($URL, $keys)) {
// remove the last chunk
array_pop($chunks);
// redefine the URL
$URL = implode('/', $chunks);
//.........这里部分代码省略.........
示例10: validateForm
/**
* Validate the form based on the variables in $_POST
*/
private function validateForm()
{
// form submitted
if ($this->frm->isSubmitted()) {
// all valid
if ($this->frm->isCorrect()) {
// get selected modules
$modules = $this->frm->getField('modules')->getValue();
// add blog if example data was checked
if ($this->frm->getField('example_data')->getChecked() && !in_array('blog', $modules)) {
$modules[] = 'blog';
}
// set modules
SpoonSession::set('modules', $modules);
// example data
SpoonSession::set('example_data', $this->frm->getField('example_data')->getChecked());
// debug mode
SpoonSession::set('debug_mode', $this->frm->getField('debug_mode')->getChecked());
// redirect
SpoonHTTP::redirect('index.php?step=5');
}
}
}
示例11: logout
/**
* Logout a profile.
*
* @return void
*/
public static function logout()
{
// delete session records
FrontendModel::getDB(true)->delete('profiles_sessions', 'session_id = ?', array(SpoonSession::getSessionId()));
// set is_logged_in to false
SpoonSession::set('frontend_profile_logged_in', false);
// delete cookie
SpoonCookie::delete('frontend_profile_secret_key');
}
示例12: validateForm
/**
* Validate the form
*/
protected function validateForm()
{
if ($this->frm->isSubmitted()) {
$this->frm->cleanupFields();
// validation
$fields = $this->frm->getFields();
$fields['label']->isFilled(Language::err('FieldIsRequired'));
// get existing fields
$this->record = \SpoonSession::get('module');
if (array_key_exists('fields', $this->record)) {
foreach ($this->record['fields'] as $field) {
// check if we already have a type with the same label
if (strtolower($field['label']) == strtolower($fields['label']->getValue())) {
$fields['label']->addError(Language::err('LabelAlreadyExist'));
break;
}
}
}
// for certain types, the options field is required
$type = $fields['type']->getValue();
if ($type == 'dropdown' || $type == 'multicheckbox' || $type == 'radiobutton') {
$fields['tags']->isFilled(Language::err('FieldIsRequired'));
// check if the default field is one of the options
if ($fields['default']->isFilled()) {
$options = explode(',', $fields['tags']->getValue());
if (!in_array($fields['default']->getValue(), $options)) {
$fields['default']->addError(Language::err('DefaultShouldBeAnOption'));
}
} elseif ($type == 'radiobutton') {
$fields['default']->addError(Language::err('FieldIsRequired'));
}
}
// if the type is images, the options should be in the form 200x200 seperated by a comma
if ($type == 'image') {
$fields['tags']->isFilled(Language::err('FieldIsRequired'));
$tags = explode(',', $fields['tags']->getValue());
// loop all tags and check on format, example (400x400)
foreach ($tags as $tag) {
if (!preg_match('\'([1-9][0-9]*x[1-9][0-9]*|x[1-9][0-9]*|[1-9][0-9]*x)\'', $tag)) {
$fields['tags']->addError(Language::err('ImageSizeNotWellFormed'));
break;
}
}
}
// check if the default value is valid
if ($fields['default']->isFilled()) {
// get default value
$defaultValue = $fields['default']->getValue();
// check the default values
if ($type == 'text' || $type == 'password' || $type == 'file' || $type == 'image') {
if (strlen($defaultValue) > 255) {
$fields['default']->addError(Language::err('Max255Characters'));
}
} elseif ($type == 'number') {
if (!is_numeric($defaultValue)) {
$fields['default']->addError(Language::err('FieldIsNotNumeric'));
}
} elseif ($type == 'datetime') {
if (!BackendModuleMakerHelper::isValidDateTime($defaultValue)) {
$fields['default']->addError(Language::err('FieldIsNotAValidDateTime'));
}
} elseif ($type == 'checkbox') {
if (strtoupper($defaultValue) != 'Y' && strtoupper($defaultValue) != 'N') {
$fields['default']->addError(Language::err('MustBeAYOrAN'));
}
}
}
if ($this->frm->isCorrect()) {
// create the item
$item['label'] = strtolower($fields['label']->getValue());
$item['type'] = $type;
$item['options'] = $fields['tags']->getValue();
$item['required'] = $fields['required']->isChecked();
$item['default'] = $fields['default']->getValue();
$item['camel_cased_label'] = BackendModuleMakerHelper::buildCamelCasedName($item['label']);
$item['underscored_label'] = BackendModuleMakerHelper::buildUnderscoredName($item['label']);
$item['lower_ccased_label'] = BackendModuleMakerHelper::buildLowerCamelCasedName($item['label']);
$item['meta'] = false;
$item['searchable'] = false;
if ($item['type'] == 'image' && $fields['caption']->isChecked()) {
$item['type'] = 'image_caption';
}
// generate the SQL for the field
$item['sql'] = $this->generateSQL($item);
// if the record has no fields key yet, add it
if (!array_key_exists('fields', $this->record)) {
$this->record['fields'] = array();
}
// add the item to the fields array of the record
$this->record['fields'][] = $item;
// save
\SpoonSession::set('module', $this->record);
$this->redirect(Model::createURLForAction('AddStep2'));
}
}
}
示例13: 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) {
// field name
$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']);
}
} elseif ($rule == 'time') {
$regexTime = '/^(([0-1][0-9]|2[0-3]|[0-9])|([0-1][0-9]|2[0-3]|[0-9])(:|h)[0-5]?[0-9]?)$/';
if (!\SpoonFilter::isValidAgainstRegexp($regexTime, $this->frm->getField($fieldName)->getValue())) {
$this->frm->getField($fieldName)->setError($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();
if ($field['type'] == 'radiobutton') {
$values = array();
foreach ($field['settings']['values'] as $value) {
$values[$value['value']] = $value['label'];
}
$fieldData['value'] = $values[$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[$field['id']] = $fieldData;
// insert
FrontendFormBuilderModel::insertDataField($fieldData);
}
$this->get('event_dispatcher')->dispatch(FormBuilderEvents::FORM_SUBMITTED, new FormBuilderSubmittedEvent($this->item, $fields, $dataId));
// trigger event
FrontendModel::triggerEvent('FormBuilder', '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 excessive usage
\SpoonSession::set('formbuilder_' . $this->item['id'], time());
// redirect
$redirect = SITE_URL . $this->URL->getQueryString();
$redirect .= stripos($redirect, '?') === false ? '?' : '&';
//.........这里部分代码省略.........
示例14: 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
//.........这里部分代码省略.........
示例15: logout
/**
* Logsout the current user
*
* @return void
*/
public static function logout()
{
// remove all rows owned by the current user
BackendModel::getDB(true)->delete('users_sessions', 'session_id = ?', SpoonSession::getSessionId());
// reset values. We can't destroy the session because session-data can be used on the site.
SpoonSession::set('backend_logged_in', false);
SpoonSession::set('backend_secret_key', '');
}