♻️ Handle pages in MenuHelper
This commit is contained in:
parent
849b15ed59
commit
8e406fd8ba
6 changed files with 62 additions and 68 deletions
|
@ -2,31 +2,38 @@
|
|||
|
||||
class MenuHelper {
|
||||
|
||||
public static function getArchive($monthly, $classUl = "", $classLink = "", $classActive = "active")
|
||||
{
|
||||
global $archives;
|
||||
return MenuHelper::toMenu($archives->getLinkList($monthly, $classLink, $classActive), $classUl);
|
||||
}
|
||||
|
||||
|
||||
public static function getCategories($showEmpty, $showCount, $classUl = "", $classLink = "", $classActive = "active")
|
||||
{
|
||||
global $categories;
|
||||
return MenuHelper::toMenu($categories->getLinkList($showEmpty, $showCount, $classLink, $classActive), $classUl);
|
||||
}
|
||||
|
||||
public static function getArticles($monthly, $classUl = "", $classLink = "", $classActive = "active")
|
||||
public static function getArticles($numberOfItems, $showStatic = false, $classUl = "", $classLink = "", $classActive = "active", $include = "")
|
||||
{
|
||||
global $pages;
|
||||
return MenuHelper::toMenu($pages->getLinkList($monthly, $classLink, $classActive), $classUl);
|
||||
return MenuHelper::toMenu($pages->getArticleLinkList($numberOfItems, $showStatic, $classLink, $classActive), $classUl, $include);
|
||||
}
|
||||
|
||||
private static function toMenu($links, $classUl)
|
||||
public static function getStatics($numberOfItems, $showHome = true, $classUl = "", $classLink = "", $classActive = "active", $include = "")
|
||||
{
|
||||
global $pages;
|
||||
return MenuHelper::toMenu($pages->getStaticLinkList($numberOfItems, $showHome, $classLink, $classActive), $classUl, $include);
|
||||
}
|
||||
|
||||
public static function getArchive($monthly, $classUl = "", $classLink = "", $classActive = "active", $include = "")
|
||||
{
|
||||
global $archives;
|
||||
return MenuHelper::toMenu($archives->getLinkList($monthly, $classLink, $classActive), $classUl, $include);
|
||||
}
|
||||
|
||||
|
||||
public static function getCategories($showEmpty, $showCount, $classUl = "", $classLink = "", $classActive = "active", $include = "")
|
||||
{
|
||||
global $categories;
|
||||
return MenuHelper::toMenu($categories->getLinkList($showEmpty, $showCount, $classLink, $classActive), $classUl, $include);
|
||||
}
|
||||
|
||||
private static function toMenu($links, $classUl, $include = "")
|
||||
{
|
||||
$html = '<ul '. ($classUl != '' ? 'class="'.$classUl.'"' : '') .'>';
|
||||
foreach ($links as $link) {
|
||||
$html .= "<li>" . $link->toHTML() . "</li>";
|
||||
}
|
||||
$html .= $include;
|
||||
$html .= "</ul>";
|
||||
return $html;
|
||||
}
|
||||
|
|
|
@ -535,6 +535,36 @@ class Pages extends dbJSON
|
|||
return false;
|
||||
}
|
||||
|
||||
public function getArticleLinkList($numberOfItems, $showStatic = false, $classLink = "", $classActive = "active")
|
||||
{
|
||||
return $this->getLinkList($numberOfItems, false, true, false, $showStatic, $classLink, $classActive);
|
||||
}
|
||||
|
||||
public function getStaticLinkList($numberOfItems, $showHome = true, $classLink = "", $classActive = "active")
|
||||
{
|
||||
return $this->getLinkList($numberOfItems, $showHome, false, true, false, $classLink, $classActive);
|
||||
}
|
||||
|
||||
private function getLinkList($numberOfItems, $showHome, $published = true, $static = false, $sticky = false, $classLink = "", $classActive = "active")
|
||||
{
|
||||
$publishedPages = $this->getList(1, $numberOfItems, $published, $static, $sticky);
|
||||
$linkList = array();
|
||||
if ($showHome) {
|
||||
global $site;
|
||||
global $L;
|
||||
$linkList[] = new Link($L->get('Home'), $site->url(), $classLink, $classActive);
|
||||
}
|
||||
foreach ($publishedPages as $pageKey) {
|
||||
try {
|
||||
$page = new Page($pageKey);
|
||||
$linkList[] = new Link($page->title(), $page->permalink(), $classLink, $classActive);
|
||||
} catch (Exception $e) {
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
return $linkList;
|
||||
}
|
||||
|
||||
// Returns an array with a list of key of pages, FALSE if out of range
|
||||
// The database is sorted by date or by position
|
||||
// (int) $pageNumber, the page number
|
||||
|
|
|
@ -632,4 +632,10 @@ class Page
|
|||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getLink($class, $classActive = "active")
|
||||
{
|
||||
return new Link($this->name(), $this->permalink(), $class, $classActive);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,26 +50,7 @@ class pluginLastArticles extends Plugin
|
|||
}
|
||||
|
||||
$html .= '<div class="plugin-content">';
|
||||
$html .= '<ul>';
|
||||
|
||||
// List of published pages
|
||||
$onlyPublished = true;
|
||||
$pageNumber = 1;
|
||||
$numberOfItems = $this->getValue('numberOfItems');
|
||||
$publishedPages = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
|
||||
|
||||
foreach ($publishedPages as $pageKey) {
|
||||
try {
|
||||
$page = new Page($pageKey);
|
||||
$html .= '<li>';
|
||||
$html .= '<a href="' . $page->permalink() . '">' . $page->title() . '</a>';
|
||||
$html .= '</li>';
|
||||
} catch (Exception $e) {
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '</ul>';
|
||||
$html .= MenuHelper::getArticles($this->getValue('numberOfItems'), false);
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
|
||||
|
|
|
@ -53,28 +53,7 @@ class pluginStaticPages extends Plugin
|
|||
}
|
||||
|
||||
$html .= '<div class="plugin-content">';
|
||||
$html .= '<ul>';
|
||||
|
||||
// Show Home page link
|
||||
if ($this->getValue('homeLink')) {
|
||||
$html .= '<li>';
|
||||
$html .= '<a href="' . $site->url() . '">' . $L->get('Home') . '</a>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
|
||||
// Show static pages
|
||||
$staticPages = buildStaticPages();
|
||||
foreach ($staticPages as $page) {
|
||||
if ($page->isParent()) {
|
||||
$html .= '<li class="parent">';
|
||||
} else {
|
||||
$html .= '<li class="subpage" style="margin-left: 10px">';
|
||||
}
|
||||
$html .= '<a href="' . $page->permalink() . '">' . $page->title() . '</a>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
|
||||
$html .= '</ul>';
|
||||
$html .= MenuHelper::getStatics(-1, $this->getValue('homeLink'));
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
|
||||
|
|
|
@ -1,14 +1,5 @@
|
|||
<header id="main-header">
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="<?php echo Theme::siteUrl() ?>"><?php echo $L->get('Home'); ?></a></li>
|
||||
<!-- Static pages -->
|
||||
<?php foreach ($staticContent as $staticPage) : ?>
|
||||
<li><a href="<?php echo $staticPage->permalink() ?>"><?php echo $staticPage->title() ?></a></li>
|
||||
<?php endforeach ?>
|
||||
<li class="separator-left"><a href="<?php echo Theme::siteUrl() ?>rss.xml">RSS</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<nav><?php echo MenuHelper::getStatics(6, true, "", "", "active", '<li class="separator-left"><a href="'.Theme::siteUrl().'rss.xml">RSS</a></li>'); ?></nav>
|
||||
<hgroup id="title-container">
|
||||
<?php $logo = MediaHelper::getLogo(); ?>
|
||||
<?php if ($logo) : ?>
|
||||
|
|
Loading…
Add table
Reference in a new issue