/**
	 * Checks if the the page is any child of the root page.
	 *
	 * @param int $pid
	 * @param int $rootPid
	 * @return boolean
	 */
	protected function isAnyChildOf($pid, $rootPid) {
		$this->createSysPageIfNecessary();
		$rootLine = $this->sysPage->getRootLine($pid);
		foreach ($rootLine as $page) {
			if ($page['uid'] == $rootPid) {
				return true;
			}
		}
		return false;
	}
Example #2
0
 /**
  * Automatically render a menu
  *
  * @param array $menu
  * @param integer $level
  * @return string
  */
 protected function autoRender($menu, $level = 1)
 {
     $tagName = $this->arguments['tagNameChildren'];
     $substElementUid = $this->arguments['substElementUid'];
     $linkCurrent = (bool) $this->arguments['linkCurrent'];
     $linkActive = (bool) $this->arguments['linkActive'];
     $showCurrent = (bool) $this->arguments['showCurrent'];
     $html = array();
     foreach ($menu as $page) {
         if ($page['current'] && !$showCurrent) {
             continue;
         }
         $class = trim($page['class']) != '' ? ' class="' . $page['class'] . '"' : '';
         $elementId = $substElementUid ? ' id="elem_' . $page['uid'] . '"' : '';
         $target = $page['target'] != '' ? ' target="' . $page['target'] . '"' : '';
         $html[] = '<' . $tagName . $elementId . $class . '>';
         if ($page['current'] && $linkCurrent === FALSE) {
             $html[] = $page['title'];
         } elseif ($page['active'] && $linkActive === FALSE) {
             $html[] = $page['title'];
         } else {
             $html[] = '<a href="' . $page['link'] . '"' . $class . $target . '>' . $page['title'] . '</a>';
         }
         if (($page['active'] || $this->arguments['expandAll']) && $page['hasSubPages'] && $level < $this->arguments['levels']) {
             $rootLine = $this->pageSelect->getRootLine($page['uid']);
             $rootLine = $this->parseMenu($rootLine, $rootLine);
             $subMenu = $this->pageSelect->getMenu($page['uid']);
             $subMenu = $this->parseMenu($subMenu, $rootLine);
             $renderedSubMenu = $this->autoRender($subMenu, $level + 1);
             $this->tag->setTagName($this->arguments['tagName']);
             $this->tag->setContent($renderedSubMenu);
             $this->tag->addAttribute('class', ($this->arguments['class'] ? $this->arguments['class'] . ' lvl-' : 'lvl-') . strval($level));
             $html[] = $this->tag->render();
             $this->tag->addAttribute('class', $this->arguments['class']);
         }
         $html[] = '</' . $tagName . '>';
     }
     return implode(LF, $html);
 }
	/**
	 * 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];
	}
Example #4
0
 /**
  * Get content records based on column and pid
  *
  * @return array
  */
 protected function getContentRecords()
 {
     $loadRegister = FALSE;
     if (empty($this->arguments['loadRegister']) === FALSE) {
         $this->contentObject->cObjGetSingle('LOAD_REGISTER', $this->arguments['loadRegister']);
         $loadRegister = TRUE;
     }
     $pid = $this->arguments['pageUid'] ? $this->arguments['pageUid'] : $GLOBALS['TSFE']->id;
     $order = $this->arguments['order'] . ' ' . $this->arguments['sortDirection'];
     $colPos = $this->arguments['column'];
     $contentUids = $this->arguments['contentUids'];
     $slide = $this->arguments['slide'] ? $this->arguments['slide'] : FALSE;
     $slideCollect = $this->arguments['slideCollect'] ? $this->arguments['slideCollect'] : FALSE;
     if ($slideCollect !== FALSE) {
         $slide = min($slide, $slideCollect);
     }
     $slideCollectReverse = $this->arguments['slideCollectReverse'];
     $rootLine = NULL;
     if ($slide) {
         $pageSelect = new t3lib_pageSelect();
         $rootLine = $pageSelect->getRootLine($pid);
         if ($slideCollectReverse) {
             $rootLine = array_reverse($rootLine);
         }
     }
     $content = array();
     do {
         if ($slide) {
             $page = array_shift($rootLine);
             if (!$page) {
                 break;
             }
             $pid = $page['uid'];
         }
         if (is_array($contentUids)) {
             $conditions = 'uid IN (' . implode(',', $contentUids) . ')';
         } else {
             $conditions = "pid = '" . $pid . "' AND colPos = '" . $colPos . "' AND (tx_flux_column = '' OR tx_flux_column IS NULL) " . $GLOBALS['TSFE']->cObj->enableFields('tt_content') . " AND (sys_language_uid IN (-1,0) OR (sys_language_uid = '" . $GLOBALS['TSFE']->sys_language_uid . "' AND l18n_parent = '0'))";
         }
         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tt_content', $conditions, 'uid', $order, $this->arguments['limit']);
         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
             $conf = array('tables' => 'tt_content', 'source' => $row['uid'], 'dontCheckPid' => 0);
             array_push($content, $GLOBALS['TSFE']->cObj->RECORDS($conf));
         }
         $GLOBALS['TYPO3_DB']->sql_free_result($res);
         if (count($content) && !$slideCollect) {
             break;
         }
     } while ($slide !== FALSE && --$slide !== -1);
     if ($loadRegister) {
         $this->contentObject->cObjGetSingle('RESTORE_REGISTER', '');
     }
     return $content;
 }
 /**
  * Gets the page and rootline arrays based on the id, $this->id
  *
  * If the id does not correspond to a proper page, the 'previous' valid page in the rootline is found
  * If the page is a shortcut (doktype=4), the ->id is loaded with that id
  *
  * Whether or not the ->id is changed to the shortcut id or the previous id in rootline (eg if a page is hidden), the ->page-array and ->rootline is found and must also be valid.
  *
  * Sets or manipulates internal variables such as: $this->id, $this->page, $this->rootLine, $this->MP, $this->pageNotFound
  *
  * @return	void
  * @access private
  */
 function getPageAndRootline()
 {
     $this->page = $this->sys_page->getPage($this->id);
     if (!count($this->page)) {
         // If no page, we try to find the page before in the rootLine.
         $this->pageNotFound = 1;
         // Page is 'not found' in case the id itself was not an accessible page. code 1
         $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
         if (count($this->rootLine)) {
             $c = count($this->rootLine) - 1;
             while ($c > 0) {
                 // Add to page access failure history:
                 $this->pageAccessFailureHistory['direct_access'][] = $this->rootLine[$c];
                 // Decrease to next page in rootline and check the access to that, if OK, set as page record and ID value.
                 $c--;
                 $this->id = $this->rootLine[$c]['uid'];
                 $this->page = $this->sys_page->getPage($this->id);
                 if (count($this->page)) {
                     break;
                 }
             }
         }
         // If still no page...
         if (!count($this->page)) {
             if ($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling']) {
                 $this->pageNotFoundAndExit('The requested page does not exist!');
             } else {
                 $message = 'The requested page does not exist!';
                 header('HTTP/1.0 404 Page Not Found');
                 t3lib_div::sysLog($message, 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
                 $this->printError($message);
                 exit;
             }
         }
     }
     // Spacer is not accessible in frontend
     if ($this->page['doktype'] == 199) {
         if ($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling']) {
             $this->pageNotFoundAndExit('The requested page does not exist!');
         } else {
             $message = 'The requested page does not exist!';
             header('HTTP/1.0 404 Page Not Found');
             t3lib_div::sysLog($message, 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
             $this->printError($message);
             exit;
         }
     }
     // Is the ID a link to another page??
     if ($this->page['doktype'] == 4) {
         $this->MP = '';
         // We need to clear MP if the page is a shortcut. Reason is if the short cut goes to another page, then we LEAVE the rootline which the MP expects.
         // saving the page so that we can check later - when we know
         // about languages - whether we took the correct shortcut or
         // whether a translation of the page overwrites the shortcut
         // target and we need to follow the new target
         $this->originalShortcutPage = $this->page;
         $this->page = $this->getPageShortcut($this->page['shortcut'], $this->page['shortcut_mode'], $this->page['uid']);
         $this->id = $this->page['uid'];
     }
     // Gets the rootLine
     $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
     // If not rootline we're off...
     if (!count($this->rootLine)) {
         $ws = $this->whichWorkspace();
         if ($this->sys_page->error_getRootLine_failPid == -1 && $ws) {
             $this->sys_page->versioningPreview = TRUE;
             $this->versioningWorkspaceId = $ws;
             $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
         }
         if (!count($this->rootLine)) {
             if ($this->checkPageUnavailableHandler()) {
                 $this->pageUnavailableAndExit('The requested page didn\'t have a proper connection to the tree-root!');
             } else {
                 $message = 'The requested page didn\'t have a proper connection to the tree-root! <br /><br />(' . $this->sys_page->error_getRootLine . ')';
                 header('HTTP/1.0 503 Service Temporarily Unavailable');
                 t3lib_div::sysLog(str_replace('<br /><br />', '', $message), 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
                 $this->printError($message);
                 exit;
             }
         }
         $this->fePreview = 1;
     }
     // Checking for include section regarding the hidden/starttime/endtime/fe_user (that is access control of a whole subbranch!)
     if ($this->checkRootlineForIncludeSection()) {
         if (!count($this->rootLine)) {
             if ($this->checkPageUnavailableHandler()) {
                 $this->pageUnavailableAndExit('The requested page was not accessible!');
             } else {
                 $message = 'The requested page was not accessible!';
                 header('HTTP/1.0 503 Service Temporarily Unavailable');
                 t3lib_div::sysLog($message, 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
                 $this->printError($message);
                 exit;
             }
         } else {
             $el = reset($this->rootLine);
             $this->id = $el['uid'];
             $this->page = $this->sys_page->getPage($this->id);
             $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
         }
     }
 }