sitemap WIP

This commit is contained in:
fredtempez 2021-12-10 15:39:09 +01:00
parent 2746ac553b
commit 63a309b5f1
3 changed files with 112 additions and 92 deletions

View File

@ -13,21 +13,100 @@
* @link http://zwiicms.fr/
*/
class sitemap extends common {
class sitemap extends common
{
public static $actions = [
'index' => self::GROUP_VISITOR
];
public static $actions = [
'index' => self::GROUP_VISITOR
];
public static $siteMap = '';
/**
* Plan du site
*/
public function index() {
// Valeurs en sortie
$this->addOutput([
'title' => 'Plan du site',
'view' => 'index'
]);
}
/**
* Plan du site
*/
public function index()
{
$items = '<ul>';
foreach ($this->getHierarchy(null, true, null) as $parentId => $childIds) {
$items .= '<li class="pageIcon">';
if ($this->getData(['page', $parentId, 'disable']) === false && $this->getUser('group') >= $this->getData(['page', $parentId, 'group'])) {
$items .= '<a href="' .helper::baseUrl() . $parentId .'">' .$this->getData(['page', $parentId, 'title']) . '</a>';
// $items .= '<';
} else {
// page désactivée
$items .= $this->getData(['page', $parentId, 'title']);
}
// ou articles d'un blog
if ($this->getData(['page', $parentId, 'moduleId']) === 'blog' &&
!empty($this->getData(['module',$parentId, 'posts' ]))) {
$items .= '<ul>';
// Ids des articles par ordre de publication
$articleIdsPublishedOns = helper::arrayCollumn($this->getData(['module', $parentId,'posts']), 'publishedOn', 'SORT_DESC');
$articleIdsStates = helper::arrayCollumn($this->getData(['module', $parentId, 'posts']), 'state', 'SORT_DESC');
$articleIds = [];
foreach ($articleIdsPublishedOns as $articleId => $articlePublishedOn) {
if ($articlePublishedOn <= time() and $articleIdsStates[$articleId]) {
$articleIds[] = $articleId;
}
}
foreach ($articleIds as $articleId => $article) {
if ($this->getData(['module',$parentId,'posts',$article,'state']) === true) {
$items .= '<li class="articleIcon">';
$items .= '<a href="' . helper::baseUrl() . $parentId. '/' . $article . '">' . $this->getData(['module',$parentId,'posts',$article,'title']) . '</a>';
$items .= '</li>';
}
}
$items .= '</ul>';
}
foreach ($childIds as $childId) {
$items .= '<ul>';
// Sous-page
$items .= '<li class="pageIcon">';
if ($this->getData(['page', $childId, 'disable']) === false && $this->getUser('group') >= $this->getData(['page', $parentId, 'group'])) {
$items .= '<a href="' . helper::baseUrl() . $childId . '">' . $this->getData(['page', $childId, 'title']) . '</a>';
} else {
// page désactivée
$items .= $this->getData(['page', $childId, 'title']);
}
$items .= '</li>';
}
// Articles d'une sous-page blog
if ($this->getData(['page', $childId, 'moduleId']) === 'blog' &&
!empty($this->getData(['module', $childId, 'posts' ]))) {
$items .= '<ul>';
// Ids des articles par ordre de publication
$articleIdsPublishedOns = helper::arrayCollumn($this->getData(['module', $childId,'posts']), 'publishedOn', 'SORT_DESC');
$articleIdsStates = helper::arrayCollumn($this->getData(['module', $childId, 'posts']), 'state', 'SORT_DESC');
$articleIds = [];
foreach ($articleIdsPublishedOns as $articleId => $articlePublishedOn) {
if ($articlePublishedOn <= time() and $articleIdsStates[$articleId]) {
$articleIds[] = $articleId;
}
}
foreach ($articleIds as $articleId => $article) {
if ($this->getData(['module',$childId,'posts',$article,'state']) === true) {
$items .= '<li class="articleIcon">';
$items .= '<a href="' . helper::baseUrl() . $childId . '/' . $article . '">' . $this->getData(['module',$childId,'posts',$article,'title']) . '</a>';
$items .= '</li>';
}
}
$items .= '</ul>';
}
$items .= '</li>';
// Fin du grand bloc
$items .= '</ul>';
}
}
self::$siteMap = $items;
// Valeurs en sortie
$this->addOutput([
'title' => 'Plan du site',
'view' => 'index'
]);
}
}

View File

@ -12,6 +12,17 @@
* @link http://zwiicms.fr/
*/
ul {
list-style-type: circle;
}
#siteMap ul {
list-style: none ;
margin-left: .5em;
padding-left: 1em;
line-height: 1.5em;
}
.pageIcon li::before {
content: "📄 ";
}
.articleIcon li::before {
content: "📝 ";
}

View File

@ -1,74 +1,4 @@
<ul>
<?php foreach($this->getHierarchy(null,true,null) as $parentId => $childIds): ?>
<li>
<?php
if ($this->getData(['page', $parentId, 'disable']) === false && $this->getUser('group') >= $this->getData(['page', $parentId, 'group']))
{ ?>
<a href="<?php echo helper::baseUrl() . $parentId; ?>"><?php echo $this->getData(['page', $parentId, 'title']); ?></a>
<?php
} else {
// page désactivée
echo $this->getData(['page', $parentId, 'title']);
} ?>
<ul>
<?php foreach($childIds as $childId): ?>
<li>
<!-- Sous-page -->
<?php if ($this->getData(['page', $childId, 'disable']) === false && $this->getUser('group') >= $this->getData(['page', $parentId, 'group']))
{ ?>
<a href="<?php echo helper::baseUrl() . $childId; ?>"><?php echo $this->getData(['page', $childId, 'title']); ?></a>
<?php } else { ?>
<!-- page désactivée -->
<?php echo $this->getData(['page', $childId, 'title']); }?>
<!-- articles d'une sous-page blog-->
<ul>
<?php if ($this->getData(['page', $childId, 'moduleId']) === 'blog' &&
!empty($this->getData(['module', $childId, 'posts' ])) ) { ?>
<?php
// Ids des articles par ordre de publication
$articleIdsPublishedOns = helper::arrayCollumn($this->getData(['module', $childId,'posts']), 'publishedOn', 'SORT_DESC');
$articleIdsStates = helper::arrayCollumn($this->getData(['module', $childId, 'posts']), 'state', 'SORT_DESC');
$articleIds = [];
foreach($articleIdsPublishedOns as $articleId => $articlePublishedOn) {
if($articlePublishedOn <= time() AND $articleIdsStates[$articleId]) {
$articleIds[] = $articleId;
}
}
foreach($articleIds as $articleId => $article): ?>
<?php if($this->getData(['module',$childId,'posts',$article,'state']) === true) {?>
<li>
<a href="<?php echo helper::baseUrl() . $childId . '/' . $article;?>"><?php echo $this->getData(['module',$childId,'posts',$article,'title']); ?></a>
</li>
<?php } ?>
<?php endforeach;
} ?>
</ul>
</li>
<?php endforeach; ?>
<!-- ou articles d'un blog-->
<?php if ($this->getData(['page', $parentId, 'moduleId']) === 'blog' &&
!empty($this->getData(['module',$parentId, 'posts' ])) ) { ?>
<?php
// Ids des articles par ordre de publication
$articleIdsPublishedOns = helper::arrayCollumn($this->getData(['module', $parentId,'posts']), 'publishedOn', 'SORT_DESC');
$articleIdsStates = helper::arrayCollumn($this->getData(['module', $parentId, 'posts']), 'state', 'SORT_DESC');
$articleIds = [];
foreach($articleIdsPublishedOns as $articleId => $articlePublishedOn) {
if($articlePublishedOn <= time() AND $articleIdsStates[$articleId]) {
$articleIds[] = $articleId;
}
}
foreach($articleIds as $articleId => $article): ?>
<?php if($this->getData(['module',$parentId,'posts',$article,'state']) === true ): ?>
<li>
<a href="<?php echo helper::baseUrl() . $parentId. '/' . $article;?>"><?php echo $this->getData(['module',$parentId,'posts',$article,'title']); ?></a>
</li>
<?php endif; ?>
<?php endforeach;
} ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
<?php
echo "<div id='siteMap'>";
echo $module::$siteMap;
echo "</div>";