getPageId() public static method

Get a menuId for an specified URL
public static getPageId ( string $url, string $language = null ) : integer
$url string The URL wherefore you want a pageID.
$language string The language wherefore the pageID should be retrieved, if not provided we will load the language that was provided in the URL.
return integer
Beispiel #1
0
 /**
  * @param KernelInterface $kernel
  */
 public function __construct(KernelInterface $kernel)
 {
     parent::__construct($kernel);
     // store in reference
     $this->getContainer()->set('breadcrumb', $this);
     // get more information for the homepage
     $homeInfo = Navigation::getPageInfo(1);
     // add homepage as first item (with correct element)
     $this->addElement($homeInfo['navigation_title'], Navigation::getURL(1));
     // get other pages
     $pages = $this->URL->getPages();
     // init vars
     $items = array();
     $errorURL = Navigation::getUrl(404);
     // loop pages
     while (!empty($pages)) {
         // init vars
         $URL = implode('/', $pages);
         $menuId = Navigation::getPageId($URL);
         $pageInfo = Navigation::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 = Navigation::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']);
     }
 }
Beispiel #2
0
 /**
  * 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']));
     }
 }
Beispiel #3
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));
 }
Beispiel #4
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));
 }
Beispiel #5
0
 /**
  * Get the id of an item by the full URL of the current page.
  * Selects the proper part of the full URL to get the item's id from the database.
  *
  * @param FrontendURL $URL The current URL.
  * @return int
  */
 public static function getIdForTags(FrontendURL $URL)
 {
     return FrontendNavigation::getPageId($URL->getQueryString());
 }
Beispiel #6
0
 /**
  * Get the subnavigation html
  *   syntax: {{ getsubnavigation($type, $parentId, $startdepth, $enddepth, $excludeIds-splitted-by-dash, $template) }}
  *
  *   NOTE: When supplying more than 1 ID to exclude, the single quotes around the dash-separated list are mandatory.
  *
  * @param string $type       The type of navigation, possible values are: page, footer.
  * @param int    $pageId     The parent wherefore the navigation should be build.
  * @param int    $startDepth The depth to start from.
  * @param int    $endDepth   The maximum depth that has to be build.
  * @param string $excludeIds Which pageIds should be excluded (split them by -).
  * @param string $template        The template that will be used.
  *
  * @return string
  */
 public static function getSubNavigation($type = 'page', $pageId = 0, $startDepth = 1, $endDepth = null, $excludeIds = null, $template = '/Core/Layout/Templates/Navigation.html.twig')
 {
     // build excludeIds
     if ($excludeIds !== null) {
         $excludeIds = (array) explode('-', $excludeIds);
     }
     // get info about the given page
     $pageInfo = Navigation::getPageInfo($pageId);
     // validate page info
     if ($pageInfo === false) {
         return '';
     }
     // split URL into chunks
     $chunks = (array) explode('/', $pageInfo['full_url']);
     // remove language chunk
     $hasMultiLanguages = FrontendModel::getContainer()->getParameter('site.multilanguage');
     $chunks = $hasMultiLanguages ? (array) array_slice($chunks, 2) : (array) array_slice($chunks, 1);
     if (count($chunks) == 0) {
         $chunks[0] = '';
     }
     // init var
     $parentURL = '';
     // build url
     for ($i = 0; $i < $startDepth - 1; ++$i) {
         $parentURL .= $chunks[$i] . '/';
     }
     // get parent ID
     $parentID = Navigation::getPageId($parentURL);
     try {
         // get HTML
         $return = (string) Navigation::getNavigationHTML($type, $parentID, $endDepth, $excludeIds, (string) $template);
     } catch (Exception $e) {
         return '';
     }
     // return the var
     if ($return != '') {
         return $return;
     }
     // fallback
     return;
 }