getVisitorId() public static method

Get the visitor's id (using a tracking cookie)
public static getVisitorId ( ) : string
return string
Example #1
0
 /**
  * Loads the actual components on the page
  */
 public function load()
 {
     // set tracking cookie
     Model::getVisitorId();
     // create header instance
     $this->header = new Header($this->getKernel());
     // get page content from pageId of the requested URL
     $this->record = $this->getPageContent(Navigation::getPageId(implode('/', $this->URL->getPages())));
     if (empty($this->record)) {
         $this->record = Model::getPage(404);
     }
     // authentication
     if (BackendModel::isModuleInstalled('Profiles') && isset($this->record['data']['auth_required'])) {
         $data = $this->record['data'];
         // is auth required and is profile logged in
         if ($data['auth_required']) {
             if (!FrontendAuthenticationModel::isLoggedIn()) {
                 // redirect to login page
                 $queryString = $this->URL->getQueryString();
                 throw new RedirectException('Redirect', new RedirectResponse(Navigation::getURLForBlock('Profiles', 'Login') . '?queryString=' . $queryString));
             }
             // specific groups for auth?
             if (!empty($data['auth_groups'])) {
                 $inGroup = false;
                 foreach ($data['auth_groups'] as $group) {
                     if (FrontendAuthenticationModel::getProfile()->isInGroup($group)) {
                         $inGroup = true;
                     }
                 }
                 if (!$inGroup) {
                     $this->record = Model::getPage(404);
                 }
             }
         }
     }
     // we need to set the correct id
     $this->pageId = (int) $this->record['id'];
     // set headers if this is a 404 page
     if ($this->pageId == 404) {
         $this->statusCode = 404;
         if (extension_loaded('newrelic')) {
             newrelic_name_transaction('404');
         }
     }
     // create breadcrumb instance
     $this->breadcrumb = new Breadcrumb($this->getKernel());
     // new footer instance
     $this->footer = new Footer($this->getKernel());
     // process page
     $this->processPage();
     // execute all extras linked to the page
     $this->processExtras();
     // store statistics
     $this->storeStatistics();
     // trigger event
     Model::triggerEvent('Core', 'after_page_processed', array('id' => $this->getId(), 'record' => $this->getRecord(), 'statusCode' => $this->getStatusCode(), 'sessionId' => \SpoonSession::getSessionId(), 'visitorId' => Model::getVisitorId(), 'SESSION' => $_SESSION, 'COOKIE' => $_COOKIE, 'GET' => $_GET, 'POST' => $_POST, 'SERVER' => $_SERVER));
 }
Example #2
0
 /**
  * Loads the actual components on the page
  */
 public function load()
 {
     // set tracking cookie
     Model::getVisitorId();
     // get pageId for requested URL
     $this->pageId = Navigation::getPageId(implode('/', $this->URL->getPages()));
     // set headers if this is a 404 page
     if ($this->pageId == 404) {
         $this->statusCode = 404;
         if (extension_loaded('newrelic')) {
             newrelic_name_transaction('404');
         }
     }
     // create breadcrumb instance
     $this->breadcrumb = new Breadcrumb($this->getKernel());
     // create header instance
     $this->header = new Header($this->getKernel());
     // new footer instance
     $this->footer = new Footer($this->getKernel());
     // get page content
     $this->getPageContent();
     // process page
     $this->processPage();
     // execute all extras linked to the page
     $this->processExtras();
     // store statistics
     $this->storeStatistics();
     // trigger event
     Model::triggerEvent('Core', 'after_page_processed', array('id' => $this->getId(), 'record' => $this->getRecord(), 'statusCode' => $this->getStatusCode(), 'sessionId' => \SpoonSession::getSessionId(), 'visitorId' => Model::getVisitorId(), 'SESSION' => $_SESSION, 'COOKIE' => $_COOKIE, 'GET' => $_GET, 'POST' => $_POST, 'SERVER' => $_SERVER));
 }
Example #3
0
 /**
  * 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 ? '?' : '&';
             $redirect .= 'identifier=' . $this->item['identifier'];
             $redirect .= '#' . $this->formName;
             throw new RedirectException('Redirect', new RedirectResponse($redirect));
         } else {
             // not correct, show errors
             // global form errors set
             if ($this->frm->getErrors() != '') {
                 $this->tpl->assign('formBuilderError', $this->frm->getErrors());
             } else {
                 // general error
                 $this->tpl->assign('formBuilderError', FL::err('FormError'));
             }
         }
     }
 }