/** * Get parsed template content * * @return string */ public function getContent() { return $this->tpl->getContent($this->templatePath, false, true); }
/** * Get navigation HTML * * @return string * @param string[optional] $type The type of navigation the HTML should be build for. * @param int[optional] $parentId The parentID to start of. * @param int[optional] $depth The maximum depth to parse. * @param array[optional] $excludeIds PageIDs to be excluded. * @param bool[optional] $includeChildren Children can be included regardless of whether we're at the current page. * @param int[optional] $depthCounter A counter that will hold the current depth. */ public static function getNavigationHTML($type = 'page', $parentId = 0, $depth = null, $excludeIds = array(), $includeChildren = false, $depthCounter = 1) { // get navigation $navigation = self::getNavigation(); // meta-navigation is requested but meta isn't enabled if ($type == 'meta' && !FrontendModel::getModuleSetting('pages', 'meta_navigation', true)) { return ''; } // validate if (!isset($navigation[$type])) { throw new FrontendException('This type (' . $type . ') isn\'t a valid navigation type. Possible values are: page, footer, meta.'); } if (!isset($navigation[$type][$parentId])) { throw new FrontendException('The parent (' . $parentId . ') doesn\'t exists.'); } // special construction to merge home with it's immediate children $mergedHome = false; while (true) { // loop elements foreach ($navigation[$type][$parentId] as $id => $page) { // home is a special item, it should live on the same depth if ($page['page_id'] == 1 && !$mergedHome) { // extra checks otherwise exceptions will wbe triggered. if (!isset($navigation[$type][$parentId]) || !is_array($navigation[$type][$parentId])) { $navigation[$type][$parentId] = array(); } if (!isset($navigation[$type][$page['page_id']]) || !is_array($navigation[$type][$page['page_id']])) { $navigation[$type][$page['page_id']] = array(); } // add children $navigation[$type][$parentId] = array_merge($navigation[$type][$parentId], $navigation[$type][$page['page_id']]); // mark as merged $mergedHome = true; // restart loop continue 2; } // not hidden if ($page['hidden']) { unset($navigation[$type][$parentId][$id]); continue; } // some ids should be excluded if (in_array($page['page_id'], (array) $excludeIds)) { unset($navigation[$type][$parentId][$id]); continue; } // if the item is in the selected page it should get an selected class if (in_array($page['page_id'], self::$selectedPageIds)) { $navigation[$type][$parentId][$id]['selected'] = true; } else { $navigation[$type][$parentId][$id]['selected'] = false; } // add nofollow attribute if needed if ($page['no_follow']) { $navigation[$type][$parentId][$id]['nofollow'] = true; } else { $navigation[$type][$parentId][$id]['nofollow'] = false; } // has children and is selected and is desired? if (isset($navigation[$type][$page['page_id']]) && $page['page_id'] != 1 && ($navigation[$type][$parentId][$id]['selected'] == true || $includeChildren) && ($depth == null || $depthCounter + 1 <= $depth)) { $navigation[$type][$parentId][$id]['children'] = self::getNavigationHTML($type, $page['page_id'], $depth, $excludeIds, $includeChildren, $depthCounter + 1); } else { $navigation[$type][$parentId][$id]['children'] = false; } // add parent id $navigation[$type][$parentId][$id]['parent_id'] = $parentId; // add depth $navigation[$type][$parentId][$id]['depth'] = $depth; // set link $navigation[$type][$parentId][$id]['link'] = FrontendNavigation::getURL($page['page_id']); // is this an internal redirect? if (isset($page['redirect_page_id']) && $page['redirect_page_id'] != '') { $navigation[$type][$parentId][$id]['link'] = FrontendNavigation::getURL((int) $page['redirect_page_id']); } // is this an external redirect? if (isset($page['redirect_url']) && $page['redirect_url'] != '') { $navigation[$type][$parentId][$id]['link'] = $page['redirect_url']; } } // break the loop (it is only used for the special construction with home) break; } // create template $tpl = new FrontendTemplate(false); // assign navigation to template $tpl->assign('navigation', $navigation[$type][$parentId]); // return parsed content return $tpl->getContent(self::$templatePath, true, true); }
/** * Returns the content from a given template * * @return string * @param string $template The template to use. * @param array[optional] $variables The variabled to assign. */ private static function getTemplateContent($template, $variables = null) { // new template instance $tpl = new FrontendTemplate(false); // set some options $tpl->setForceCompile(true); // variables were set if (!empty($variables)) { $tpl->assign($variables); } // grab the content $content = $tpl->getContent($template); // replace internal links/images $search = array('href="/', 'src="/'); $replace = array('href="' . SITE_URL . '/', 'src="' . SITE_URL . '/'); $content = str_replace($search, $replace, $content); // require CSSToInlineStyles require_once 'external/css_to_inline_styles.php'; // create instance $cssToInlineStyles = new CSSToInlineStyles(); // set some properties $cssToInlineStyles->setHTML($content); $cssToInlineStyles->setUseInlineStylesBlock(true); $cssToInlineStyles->setEncoding(SPOON_CHARSET); // return the content return (string) $cssToInlineStyles->convert(); }