/**
  * Load the data
  */
 private function loadData()
 {
     // get the current page id
     $pageId = Spoon::get('page')->getId();
     $navigation = FrontendNavigation::getNavigation();
     $pageInfo = FrontendNavigation::getPageInfo($pageId);
     $this->navigation = array();
     if (isset($navigation['page'][$pageInfo['parent_id']])) {
         $pages = $navigation['page'][$pageInfo['parent_id']];
         // store
         $pagesPrev = $pages;
         $pagesNext = $pages;
         // check for current id
         foreach ($pagesNext as $key => $value) {
             if ((int) $key != (int) $pageId) {
                 // go to next pointer in array
                 next($pagesNext);
                 next($pagesPrev);
             } else {
                 break;
             }
         }
         // get previous page
         $this->navigation['previous'] = prev($pagesPrev);
         // get next page
         $this->navigation['next'] = next($pagesNext);
         // get parent page
         $this->navigation['parent'] = FrontendNavigation::getPageInfo($pageInfo['parent_id']);
     }
 }
Ejemplo n.º 2
0
 /**
  * Default constructor
  *
  * @return	void
  */
 public function __construct()
 {
     // call parent
     parent::__construct();
     // add into the reference
     Spoon::set('breadcrumb', $this);
     // get more information for the homepage
     $homeInfo = FrontendNavigation::getPageInfo(1);
     // add homepage as first item (with correct element)
     $this->addElement($homeInfo['navigation_title'], FrontendNavigation::getURL(1));
     // get other pages
     $pages = $this->URL->getPages();
     // init vars
     $items = array();
     $errorURL = FrontendNavigation::getUrl(404);
     // loop pages
     while (!empty($pages)) {
         // init vars
         $URL = implode('/', $pages);
         $menuId = FrontendNavigation::getPageId($URL);
         $pageInfo = FrontendNavigation::getPageInfo($menuId);
         // do we know something about the page
         if ($pageInfo !== false && isset($pageInfo['navigation_title'])) {
             // only add pages that aren't direct actions
             if ($pageInfo['tree_type'] != 'direct_action') {
                 // get URL
                 $pageURL = FrontendNavigation::getUrl($menuId);
                 // if this is the error-page, so we won't show an URL.
                 if ($pageURL == $errorURL) {
                     $pageURL = null;
                 }
                 // add to the items
                 $items[] = array('title' => $pageInfo['navigation_title'], 'url' => $pageURL);
             }
         }
         // remove element
         array_pop($pages);
     }
     // reverse so everything is in place
     krsort($items);
     // loop and add elements
     foreach ($items as $row) {
         $this->addElement($row['title'], $row['url']);
     }
 }
Ejemplo n.º 3
0
 /**
  * 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);
     }
     // 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']);
     }
 }
Ejemplo n.º 4
0
 /**
  * Get tags for current "page"
  */
 private function getTags()
 {
     // get page id
     $pageId = FrontendPage::getCurrentPageId();
     // array of excluded records
     $this->exclude[] = array('module' => 'pages', 'other_id' => $pageId);
     // get tags for page
     $tags = (array) FrontendTagsModel::getForItem('pages', $pageId);
     foreach ($tags as $tag) {
         $this->tags = array_merge((array) $this->tags, (array) $tag['name']);
     }
     // get page record
     $record = (array) FrontendNavigation::getPageInfo($pageId);
     // loop blocks
     foreach ((array) $record['extra_blocks'] as $block) {
         // set module class
         $class = 'Frontend' . SpoonFilter::toCamelCase($block['module']) . 'Model';
         // get record for module
         $record = FrontendTagsModel::callFromInterface($block['module'], $class, 'getIdForTags', $this->URL);
         // check if record exists
         if (!$record) {
             continue;
         }
         // add to excluded records
         $this->exclude[] = array('module' => $block['module'], 'other_id' => $record['id']);
         // get record's tags
         $tags = (array) FrontendTagsModel::getForItem($block['module'], $record['id']);
         foreach ($tags as $tag) {
             $this->tags = array_merge((array) $this->tags, (array) $tag['name']);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Get the subnavigation html
  * 	syntax: {$var|getsubnavigation[:type[:parentId[:startdepth[:enddepth[:'excludeIds-splitted-by-dash']]]]]}
  *
  * 	NOTE: When supplying more than 1 ID to exclude, the single quotes around the dash-separated list are mandatory.
  *
  * @param string[optional] $var The variable.
  * @param string[optional] $type The type of navigation, possible values are: page, footer.
  * @param int[optional] $pageId The parent wherefore the navigation should be build.
  * @param int[optional] $startDepth The depth to strat from.
  * @param int[optional] $endDepth The maximum depth that has to be build.
  * @param string[optional] $excludeIds Which pageIds should be excluded (split them by -).
  * @return string
  */
 public static function getSubNavigation($var = null, $type = 'page', $pageId = 0, $startDepth = 1, $endDepth = null, $excludeIds = null)
 {
     // build excludeIds
     if ($excludeIds !== null) {
         $excludeIds = (array) explode('-', $excludeIds);
     }
     // get info about the given page
     $pageInfo = FrontendNavigation::getPageInfo($pageId);
     // validate page info
     if ($pageInfo === false) {
         return '';
     }
     // split URL into chunks
     $chunks = (array) explode('/', $pageInfo['full_url']);
     // init var
     $parentURL = '';
     // build url
     for ($i = 0; $i < $startDepth - 1; $i++) {
         $parentURL .= $chunks[$i] . '/';
     }
     // get parent ID
     $parentID = FrontendNavigation::getPageId($parentURL);
     try {
         // get HTML
         $return = (string) FrontendNavigation::getNavigationHtml($type, $parentID, $endDepth, $excludeIds);
     } catch (Exception $e) {
         return '';
     }
     // return the var
     if ($return != '') {
         return $return;
     }
     // fallback
     return $var;
 }