Beispiel #1
0
 /**
  * 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') ? (string) CommonCookie::get('track') : md5(uniqid() . SpoonSession::getSessionId());
     // set/prolong tracking cookie
     CommonCookie::set('track', self::$visitorId, 86400 * 365);
     return self::getVisitorId();
 }
    /**
     * Check if a profile is loggedin.
     *
     * @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::getDB()->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::getDB(true)->update('profiles_sessions', array('date' => FrontendModel::getUTCDate()), 'session_id = ?', $sessionId);
                // new user object
                self::$profile = new FrontendProfilesProfile($profileId);
                // logged in
                return true;
            } else {
                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::getDB()->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::getDB(true)->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 {
                CommonCookie::delete('frontend_profile_secret_key');
            }
        }
        // no one is logged in
        return false;
    }
Beispiel #3
0
 /**
  * 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);
     $this->frm->addText('email', $email);
     $this->frm->addText('website', $website, null);
     $this->frm->addTextarea('message');
 }
Beispiel #4
0
 /**
  * Process the querystring
  */
 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
                 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 {
             // set languageId & abbreviation
             $language = FrontendLanguage::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
             $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);
     }
     // remove language from querystring
     if (SITE_MULTILANGUAGE) {
         $queryString = trim(substr($queryString, strlen($language)), '/');
     }
     // if it's the homepage AND parameters were given (not allowed!)
     if ($URL == '' && $queryString != '') {
         // get 404 URL
         $URL = FrontendNavigation::getURL(404);
         // remove language
         if (SITE_MULTILANGUAGE) {
             $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(substr($startURL, 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 = FrontendNavigation::getPageId(implode('/', $this->getPages()));
     $pageInfo = FrontendNavigation::getPageInfo($pageId);
     // invalid page, or parameters but no extra
     if ($pageInfo === false || !empty($parameters) && !$pageInfo['has_extra']) {
         // get 404 URL
         $URL = FrontendNavigation::getURL(404);
         // remove language
         if (SITE_MULTILANGUAGE) {
             $URL = trim(str_replace('/' . $language, '', $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 = FrontendNavigation::getURL((int) $pageInfo['redirect_page_id']);
         $errorURL = FrontendNavigation::getURL(404);
         // not an error?
         if ($newPageURL != $errorURL) {
             // redirect
             SpoonHTTP::redirect($newPageURL, $pageInfo['redirect_code']);
         }
     }
     // is this an external redirect?
     if (isset($pageInfo['redirect_url']) && $pageInfo['redirect_url'] != '') {
         // redirect
         SpoonHTTP::redirect($pageInfo['redirect_url'], $pageInfo['redirect_code']);
     }
 }