/**
* Recursively get all quicknav pages and return them as array
*
* @param integer $pid
* @param integer $level
* @param string $host
* @param string $language
*
* @return array
*/
protected function getQuicknavPages($pid, $level = 1, $host = null, $language = null)
{
/** @var PageModel $objPage */
global $objPage;
$groups = array();
$arrPages = array();
// Get all groups of the current front end user
if (FE_USER_LOGGED_IN) {
$this->import('FrontendUser', 'User');
$groups = $this->User->groups;
}
// Get all active subpages
$objSubpages = \PageModel::findPublishedRegularWithoutGuestsByPid($pid);
if ($objSubpages === null) {
return array();
}
++$level;
foreach ($objSubpages as $objSubpage) {
$_groups = \StringUtil::deserialize($objSubpage->groups);
// Override the domain (see #3765)
if ($host !== null) {
$objSubpage->domain = $host;
}
// Do not show protected pages unless a back end or front end user is logged in
if (!$objSubpage->protected || !is_array($_groups) && FE_USER_LOGGED_IN || BE_USER_LOGGED_IN || is_array($_groups) && array_intersect($_groups, $groups) || $this->showProtected) {
// Do not skip the current page here! (see #4523)
// Check hidden pages
if (!$objSubpage->hide || $this->showHidden) {
$arrPages[] = array('level' => $level - 2, 'title' => \StringUtil::specialchars(\StringUtil::stripInsertTags($objSubpage->pageTitle ?: $objSubpage->title)), 'href' => $objSubpage->getFrontendUrl(), 'link' => \StringUtil::stripInsertTags($objSubpage->title));
// Subpages
if (!$this->showLevel || $this->showLevel >= $level || !$this->hardLimit && ($objPage->id == $objSubpage->id || in_array($objPage->id, $this->Database->getChildRecords($objSubpage->id, 'tl_page')))) {
$subpages = $this->getQuicknavPages($objSubpage->id, $level);
if (is_array($subpages)) {
$arrPages = array_merge($arrPages, $subpages);
}
}
}
}
}
return $arrPages;
}