/** * Get the data */ private function getData() { // get cookie $this->orderId = Cookie::get('order_id'); // check if cookies are available $this->cookiesEnabled = Cookie::hasAllowedCookies(); // check if cookies exists if ($this->orderId || $this->cookiesEnabled == true) { // get the products $this->products = FrontendCatalogModel::getProductsByOrder($this->orderId); // count amount of products in shopping cart $this->amountOfProducts = count($this->products); // total price $this->totalPrice = '0'; // calculate total amount foreach ($this->products as &$product) { // calculate total $subtotal = (int) $product['subtotal_price']; $this->totalPrice = (int) $this->totalPrice; $this->totalPrice = $this->totalPrice + $subtotal; } $this->totalPriceArr['total'] = $this->totalPrice; // insert total price in db FrontendCatalogModel::updateOrder($this->totalPriceArr, $this->orderId); } }
/** * Load the data, don't forget to validate the incoming data */ private function getData() { // requested page $requestedPage = $this->URL->getParameter('page', 'int', 1); $this->firstName = Cookie::get('fname'); $this->catalogUrl = FrontendNavigation::getURLForBlock('Catalog'); }
/** * Execute the order save */ public function execute() { parent::execute(); // get order values $this->orderValues['product_id'] = \SpoonFilter::getPostValue('productId', null, ''); $this->orderValues['amount'] = \SpoonFilter::getPostValue('productAmount', null, ''); $action = \SpoonFilter::getPostValue('action', null, ''); // get cookie $cookieOrderId = Cookie::get('order_id'); // check if cookies are enabled $cookiesEnabled = Cookie::set('enabled', 'true'); $cookieExists = Cookie::exists('enabled'); // check if cookies are set, when true update the order if (isset($cookieOrderId) && FrontendCatalogModel::existsOrder($cookieOrderId) == true) { $this->orderValues['order_id'] = $cookieOrderId; // action add or update if ($action == 'add-update') { if (FrontendCatalogModel::existsOrderValue($this->orderValues['product_id'], $this->orderValues['order_id']) == true) { // update the order values FrontendCatalogModel::updateOrderValue($this->orderValues, $this->orderValues['order_id'], $this->orderValues['product_id']); $this->output(self::OK, null, 'Order values updated.'); } else { // insert order values FrontendCatalogModel::insertOrderValue($this->orderValues); $this->output(self::OK, null, 'Order values inserted.'); } } elseif ($action == 'delete') { if (FrontendCatalogModel::existsOrderValue($this->orderValues['product_id'], $this->orderValues['order_id']) == true) { // delete the order values FrontendCatalogModel::deleteOrderValue($this->orderValues['order_id'], $this->orderValues['product_id']); $this->output(self::OK, null, 'Order values deleted.'); } } } else { // when no cookies are set, create new cookie and insert order $orderId = FrontendCatalogModel::insertOrder(); if ($orderId != '') { // set order id $this->orderValues['order_id'] = $orderId; // set cookie Cookie::set('order_id', $orderId); // insert order values FrontendCatalogModel::insertOrderValue($this->orderValues); $this->output(self::OK, null, 'Order imported.'); } } }
/** * Load the data, don't forget to validate the incoming data */ private function getData() { // get cookie $this->orderId = Cookie::get('order_id'); if ($this->orderId) { // get the products $this->products = FrontendCatalogModel::getProductsByOrder($this->orderId); // total price $this->totalPrice = '0'; // calculate total amount foreach ($this->products as &$product) { // calculate total $subtotal = (int) $product['subtotal_price']; $this->totalPrice = (int) $this->totalPrice; $this->totalPrice = $this->totalPrice + $subtotal; } } }
/** * Load the form */ private function loadForm() { // create form $this->frm = new FrontendForm('personalDataForm'); // init vars $email = Cookie::exists('email') ? Cookie::get('email') : null; $fname = Cookie::exists('fname') ? Cookie::get('fname') : null; $lname = Cookie::exists('lname') ? Cookie::get('lname') : null; $address = Cookie::exists('address') ? Cookie::get('address') : null; $hnumber = Cookie::exists('hnumber') ? Cookie::get('hnumber') : null; $postal = Cookie::exists('postal') ? Cookie::get('postal') : null; $hometown = Cookie::exists('hometown') ? Cookie::get('hometown') : null; // create elements $this->frm->addText('email', $email)->setAttributes(array('required' => null, 'type' => 'email')); $this->frm->addText('fname', $fname, null)->setAttributes(array('required' => null)); $this->frm->addText('lname', $lname, null)->setAttributes(array('required' => null)); $this->frm->addText('address', $address, null)->setAttributes(array('required' => null)); $this->frm->addText('hnumber', $hnumber, null)->setAttributes(array('required' => null)); $this->frm->addText('postal', $postal, null)->setAttributes(array('required' => null)); $this->frm->addText('hometown', $hometown, null)->setAttributes(array('required' => null)); $this->frm->addTextarea('message'); }
/** * Get the data */ private function getData() { // get cookie $this->orderId = Cookie::get('order_id'); if ($this->orderId) { // get the products $this->products = FrontendCatalogModel::getProductsByOrder($this->orderId); // count amount of products in shopping cart $this->amountOfProducts = count($this->products); // total price $this->totalPrice = '0'; // calculate total amount foreach ($this->products as &$product) { // calculate total $subtotal = (int) $product['subtotal_price']; $this->totalPrice = (int) $this->totalPrice; $this->totalPrice = $this->totalPrice + $subtotal; } // url for next step $this->personalDataUrl = FrontendNavigation::getURLForBlock('Catalog', 'PersonalData'); // url for next step $this->catalogUrl = FrontendNavigation::getURLForBlock('Catalog'); } }
/** * Process the query string */ private function processQueryString() { // store the query string local, so we don't alter it. $queryString = trim($this->request->getPathInfo(), '/'); // split into chunks $chunks = (array) explode('/', $queryString); $hasMultiLanguages = $this->getContainer()->getParameter('site.multilanguage'); // single language if (!$hasMultiLanguages) { // set language id $language = $this->get('fork.settings')->get('Core', 'default_language', SITE_DEFAULT_LANGUAGE); } else { // multiple languages // default value $mustRedirect = false; // get possible languages $possibleLanguages = (array) Language::getActiveLanguages(); $redirectLanguages = (array) Language::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 CommonCookie::set('frontend_language', $language); } 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 (CommonCookie::exists('frontend_language') && in_array(CommonCookie::get('frontend_language'), $redirectLanguages)) { // set languageId $language = (string) CommonCookie::get('frontend_language'); // redirect is needed $mustRedirect = true; } else { // default browser language // set languageId & abbreviation $language = Language::getBrowserLanguage(); // try to set a cookie with the language try { // set cookie CommonCookie::set('frontend_language', $language); } 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 // trim the first / from the query string to prevent double slashes $url = rtrim('/' . $language . '/' . trim($this->getQueryString(), '/'), '/'); // when we are just adding the language to the domain, it's a temporary redirect because // Safari keeps the 301 in cache, so the cookie to switch language doesn't work any more $redirectCode = $url == '/' . $language ? 302 : 301; // set header & redirect throw new RedirectException('Redirect', new RedirectResponse($url, $redirectCode)); } } // define the language defined('FRONTEND_LANGUAGE') || define('FRONTEND_LANGUAGE', $language); defined('LANGUAGE') || define('LANGUAGE', $language); // sets the locale file Language::setLocale($language); // list of pageIds & their full URL $keys = Navigation::getKeys(); // rebuild our URL, but without the language parameter. (it's tripped earlier) $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); } // remove language from query string if ($hasMultiLanguages) { $queryString = trim(mb_substr($queryString, mb_strlen($language)), '/'); } // if it's the homepage AND parameters were given (not allowed!) if ($url == '' && $queryString != '') { // get 404 URL $url = Navigation::getURL(404); // remove language if ($hasMultiLanguages) { $url = str_replace('/' . $language, '', $url); } } // set pages $url = trim($url, '/'); // currently not in the homepage if ($url != '') { // explode in pages $pages = explode('/', $url); // reset pages $this->setPages($pages); // reset parameters $this->setParameters(array()); } // set parameters $parameters = trim(mb_substr($startURL, mb_strlen($url)), '/'); // has at least one parameter if ($parameters != '') { // parameters will be separated by / $parameters = explode('/', $parameters); // set parameters $this->setParameters($parameters); } // pageId, parentId & depth $pageId = Navigation::getPageId(implode('/', $this->getPages())); $pageInfo = Navigation::getPageInfo($pageId); // invalid page, or parameters but no extra if ($pageInfo === false || !empty($parameters) && !$pageInfo['has_extra']) { // get 404 URL $url = Navigation::getURL(404); // remove language if ($hasMultiLanguages) { $url = str_replace('/' . $language, '', $url); } // remove the first slash $url = trim($url, '/'); // currently not in the homepage if ($url != '') { // explode in pages $pages = explode('/', $url); // reset pages $this->setPages($pages); // reset parameters $this->setParameters(array()); } } // is this an internal redirect? if (isset($pageInfo['redirect_page_id']) && $pageInfo['redirect_page_id'] != '') { // get url for item $newPageURL = Navigation::getURL((int) $pageInfo['redirect_page_id']); $errorURL = Navigation::getURL(404); // not an error? if ($newPageURL != $errorURL) { // redirect throw new RedirectException('Redirect', new RedirectResponse($newPageURL, $pageInfo['redirect_code'])); } } // is this an external redirect? if (isset($pageInfo['redirect_url']) && $pageInfo['redirect_url'] != '') { // redirect throw new RedirectException('Redirect', new RedirectResponse($pageInfo['redirect_url'], $pageInfo['redirect_code'])); } }
/** * Set the locale */ private function setLocale() { $default = $this->get('fork.settings')->get('Core', 'default_interface_language'); $locale = $default; $possibleLocale = array_keys(BackendLanguage::getInterfaceLanguages()); // is the user authenticated if (Authentication::getUser()->isAuthenticated()) { $locale = Authentication::getUser()->getSetting('interface_language', $default); } elseif (CommonCookie::exists('interface_language')) { // no authenticated user, but available from a cookie $locale = CommonCookie::get('interface_language'); } // validate if the requested locale is possible if (!in_array($locale, $possibleLocale)) { $locale = $default; } BackendLanguage::setLocale($locale); }
/** * Load the form */ private function loadForm() { // create form $this->frm = new FrontendForm('subscriptionsForm'); $this->frm->setAction($this->frm->getAction() . '#' . FL::act('Subscribe')); // init vars $name = Cookie::exists('subscription_author') ? Cookie::get('subscription_author') : null; $email = Cookie::exists('subscription_email') && \SpoonFilter::isEmail(Cookie::get('subscription_email')) ? Cookie::get('subscription_email') : null; // create elements $this->frm->addText('name', $name, 255, 'form-control')->setAttributes(array('required' => null)); $this->frm->addText('email', $email, 255, 'form-control')->setAttributes(array('required' => null, 'type' => 'email')); }
/** * Get the visitor's id (using a tracking cookie) * * @return string */ public static function getVisitorId() { // check if tracking id is fetched already if (self::$visitorId !== null) { return self::$visitorId; } // get/init tracking identifier self::$visitorId = CommonCookie::exists('track') && !empty($_COOKIE['track']) ? (string) CommonCookie::get('track') : md5(uniqid() . \SpoonSession::getSessionId()); if (!self::get('fork.settings')->get('Core', 'show_cookie_bar', false) || CommonCookie::hasAllowedCookies()) { CommonCookie::set('track', self::$visitorId, 86400 * 365); } return self::getVisitorId(); }
/** * Load the form */ private function loadForm() { // create form $this->frm = new FrontendForm('commentsForm'); $this->frm->setAction($this->frm->getAction() . '#' . FL::act('Comment')); // init vars $author = CommonCookie::exists('comment_author') ? CommonCookie::get('comment_author') : null; $email = CommonCookie::exists('comment_email') && \SpoonFilter::isEmail(CommonCookie::get('comment_email')) ? CommonCookie::get('comment_email') : null; $website = CommonCookie::exists('comment_website') && \SpoonFilter::isURL(CommonCookie::get('comment_website')) ? CommonCookie::get('comment_website') : 'http://'; // create elements $this->frm->addText('author', $author)->setAttributes(array('required' => null)); $this->frm->addText('email', $email)->setAttributes(array('required' => null, 'type' => 'email')); $this->frm->addText('website', $website, null); $this->frm->addTextarea('message')->setAttributes(array('required' => null)); }
/** * Check if a profile is logged in. * * @return bool */ public static function isLoggedIn() { // profile object exist? (this means the session/cookie checks have // already happened in the current request and we cached the profile) if (isset(self::$profile)) { return true; } elseif (\SpoonSession::exists('frontend_profile_logged_in') && \SpoonSession::get('frontend_profile_logged_in') === true) { // get session id $sessionId = \SpoonSession::getSessionId(); // get profile id $profileId = (int) FrontendModel::getContainer()->get('database')->getVar('SELECT p.id FROM profiles AS p INNER JOIN profiles_sessions AS ps ON ps.profile_id = p.id WHERE ps.session_id = ?', (string) $sessionId); // valid profile id if ($profileId !== 0) { // update session date FrontendModel::getContainer()->get('database')->update('profiles_sessions', array('date' => FrontendModel::getUTCDate()), 'session_id = ?', $sessionId); // new user object self::$profile = new FrontendProfilesProfile($profileId); // logged in return true; } else { // invalid session \SpoonSession::set('frontend_profile_logged_in', false); } } elseif (CommonCookie::exists('frontend_profile_secret_key') && CommonCookie::get('frontend_profile_secret_key') != '') { // secret $secret = (string) CommonCookie::get('frontend_profile_secret_key'); // get profile id $profileId = (int) FrontendModel::getContainer()->get('database')->getVar('SELECT p.id FROM profiles AS p INNER JOIN profiles_sessions AS ps ON ps.profile_id = p.id WHERE ps.secret_key = ?', $secret); // valid profile id if ($profileId !== 0) { // get new secret key $profileSecret = FrontendProfilesModel::getEncryptedString(\SpoonSession::getSessionId(), FrontendProfilesModel::getRandomString()); // update session record FrontendModel::getContainer()->get('database')->update('profiles_sessions', array('session_id' => \SpoonSession::getSessionId(), 'secret_key' => $profileSecret, 'date' => FrontendModel::getUTCDate()), 'secret_key = ?', $secret); // set new cookie CommonCookie::set('frontend_profile_secret_key', $profileSecret); // set is_logged_in to true \SpoonSession::set('frontend_profile_logged_in', true); // update last login FrontendProfilesModel::update($profileId, array('last_login' => FrontendModel::getUTCDate())); // new user object self::$profile = new FrontendProfilesProfile($profileId); // logged in return true; } else { // invalid cookie CommonCookie::delete('frontend_profile_secret_key'); } } // no one is logged in return false; }
/** * Load the form */ private function loadForm() { // create form $this->frm = new FrontendForm('commentsForm'); $this->frm->setAction($this->frm->getAction() . '#' . FL::act('Comment')); // init vars $author = Cookie::exists('comment_author') ? Cookie::get('comment_author') : null; $email = Cookie::exists('comment_email') && \SpoonFilter::isEmail(Cookie::get('comment_email')) ? Cookie::get('comment_email') : null; $website = Cookie::exists('comment_website') && \SpoonFilter::isURL(Cookie::get('comment_website')) ? Cookie::get('comment_website') : 'http://'; // create elements $this->frm->addText('author', $author)->setAttributes(array('required' => null)); $this->frm->addText('email', $email)->setAttributes(array('required' => null, 'type' => 'email')); $this->frm->addText('website', $website, null); $this->frm->addTextarea('message')->setAttributes(array('required' => null)); $this->frmContact = new FrontendForm('contact', null, 'post'); $this->frmContact->addText('name')->setAttribute('class', 'form-control'); $this->frmContact->addText('emailContact', null, 255, 'form-control'); //->setAttribute('class', 'form-control'); $this->frmContact->addText('phone')->setAttribute('class', 'form-control'); $this->frmContact->addTextarea('messageContact', Language::lbl('ProductMoreInfo') . ' ' . $this->record['title'])->setAttribute('class', 'form-control'); }