/**
  * Creates $this->sysPage if it does not exist yet
  *
  * @return void
  */
 protected function createSysPageIfNecessary()
 {
     if (!is_object($this->sysPage)) {
         $this->sysPage = t3lib_div::makeInstance('t3lib_pageSelect');
         $this->sysPage->init($GLOBALS['TSFE']->showHiddenPage || $this->pObj->isBEUserLoggedIn());
     }
 }
 /**
  * Creates $this->sysPage if it does not exist yet
  *
  * @return void
  */
 protected function createSysPageIfNecessary()
 {
     if (!is_object($this->sysPage)) {
         $this->sysPage = $this->apiWrapper->getPageRepository();
         $this->sysPage->init($GLOBALS['TSFE']->showHiddenPage || $this->pObj->isBEUserLoggedIn());
     }
 }
	/**
	 * Fetch the page path (in the correct language)
	 * Return it in an array like:
	 *   array(
	 *     'pagepath' => 'product_omschrijving/another_page_title/',
	 *     'langID' => '2',
	 *   );
	 *
	 * @param	integer		Page ID
	 * @param	string		MP variable string
	 * @param	integer		Language id
	 * @return	array		The page path etc.
	 */
	function IDtoPagePathSegments($id, $mpvar, $langID) {
		// Check to see if we already built this one in this session
		$cacheKey = $id . '.' . $mpvar . '.' . $langID;
		if (!isset($this->IDtoPagePathCache[$cacheKey])) {

			// Get rootLine for current site (overlaid with any language overlay records).
			if (!is_object($this->sys_page)) { // Create object if not found before:
				// Initialize the page-select functions.
				$this->sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
				$this->sys_page->init($GLOBALS['TSFE']->showHiddenPage || $this->pObj->isBEUserLoggedIn());
			}
			$this->sys_page->sys_language_uid = $langID;
			$rootLine = $this->sys_page->getRootLine($id, $mpvar);
			$cc = count($rootLine);
			$newRootLine = array();
			$rootFound = FALSE;
			if (!$GLOBALS['TSFE']->tmpl->rootLine) {
				$GLOBALS['TSFE']->tmpl->start($GLOBALS['TSFE']->rootLine);
			}
			// Pass #1 -- check if linking a page in subdomain inside main domain
			$innerSubDomain = false;
			for ($a = $cc - 1; $a >= 0; $a--) {
				if ($rootLine[$a]['is_siteroot']) {
					if ($this->pObj->enableDevLog) {
						t3lib_div::devLog('Found siteroot in the rootline for id=' . $id, 'realurl', 0);
					}
					$rootFound = true;
					$innerSubDomain = true;
					for ( ; $a < $cc; $a++) {
						$newRootLine[] = $rootLine[$a];
					}
					break;
				}
			}
			if (!$rootFound) {
				// Pass #2 -- check normal page
				if ($this->pObj->enableDevLog) {
					t3lib_div::devLog('Starting to walk rootline for id=' . $id . ' from index=' . $a, 'realurl', 0, $rootLine);
				}
				for ($a = 0; $a < $cc; $a++) {
					if ($GLOBALS['TSFE']->tmpl->rootLine[0]['uid'] == $rootLine[$a]['uid']) {
						if ($this->pObj->enableDevLog) {
							t3lib_div::devLog('Found rootline', 'realurl', 0, array('uid' => $id, 'rootline start pid' => $rootLine[$a]['uid']));
						}
						$rootFound = true;
						for ( ; $a < $cc; $a++) {
							$newRootLine[] = $rootLine[$a];
						}
						break;
					}
				}
			}
			if ($rootFound) {
				// Translate the rootline to a valid path (rootline contains localized titles at this point!):
				$pagepath = $this->rootLineToPath($newRootLine, $langID);
				if ($this->pObj->enableDevLog) {
					t3lib_div::devLog('Got page path', 'realurl', 0, array('uid' => $id, 'pagepath' => $pagepath));
				}
				$rootpage_id = $this->conf['rootpage_id'];
				if ($innerSubDomain) {
					$parts = parse_url($pagepath);
					if ($this->pObj->enableDevLog) {
						t3lib_div::devLog('$innerSubDomain=true, showing page path parts', 'realurl', 0, $parts);
					}
					if ($parts['host'] == '') {
						$domain = '';
						foreach ($newRootLine as $rl) {
							$rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('domainName', 'sys_domain', 'pid=' . $rl['uid'] . ' AND redirectTo=\'\' AND hidden=0', '', 'sorting');
							if (count($rows)) {
								$domain = $rows[0]['domainName'];
								if ($this->pObj->enableDevLog) {
									t3lib_div::devLog('Found domain', 'realurl', 0, $domain);
								}
								$rootpage_id = $rl['uid'];
							}
						}
					}
				}
				$this->IDtoPagePathCache[$cacheKey] = array(
						'pagepath' => $pagepath,
						'langID' => $langID,
						'rootpage_id' => $rootpage_id,
					);
			}
			else { // Outside of root line:
				$this->IDtoPagePathCache[$cacheKey] = false;
			}
		}

		return $this->IDtoPagePathCache[$cacheKey];
	}