caelum-bludit-theme/php/sidebar-info.php

98 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2024-08-17 17:30:35 +02:00
<?php
function getNbrMinutes($text) {
$text = str_replace("~", "", $text);
$text = explode(" ", $text)[0];
return (int)$text;
}
// Page number of the paginator, the first page is 1
$pageNumber = 1;
// The value -1 tell to Bludit to returns all the pages on the system
$numberOfItems = -1;
// Only get the pages with the satus published
$onlyPublished = true;
// Get the list of keys of pages
$items = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
$totalPages = count($staticContent);
$totalArticles = count($items);
$mostRecentDate = null;
$longestArticle = "~1 minute";
foreach ($items as $key) {
// buildPage function returns a Page-Object
$page = buildPage($key);
if ($mostRecentDate == null) {
$mostRecentDate = $page->date('j/m/Y');
}
if (getNbrMinutes($page->readingTime()) > getNbrMinutes($longestArticle)) {
$longestArticle = $page->readingTime();
}
$date = $page->date('j/m/Y');
}
?>
<section class="card">
<h2 class="card-header">Infos</h2>
<p class="flex"><strong>Création du blog</strong>
<span>
<?php echo $date;?>
</span>
</p>
<p class="flex"><strong>Dernier article</strong>
<span>
<?php
echo $mostRecentDate;
?>
</span>
</p>
<p class="flex"><strong>Nombre d'articles</strong><span><?php echo $totalArticles ;?></span></p>
<p class="flex"><strong>Nombre de pages</strong><span><?php echo $totalPages ;?></span></p>
<p class="flex"><strong>Nombre de catégories</strong><span><?php echo count(getCategories()) ;?></span></p>
<p class="flex"><strong>Nombre de tags</strong><span><?php echo count(getTags()) ;?></span></p>
<p class="flex"><strong>Article le + long</strong><span><?php echo $longestArticle;?></span></p>
</section>
<section class="card c-secondary">
<h2 class="card-header">Publications</h2>
<div class="menu fg-dark">
<ul>
<?php
$items = $pages->getList(1, 6, true);
foreach ($items as $key) {
// buildPage function returns a Page-Object
$page = buildPage($key);
?>
<li>
<a class="menu-element" href="<?php echo $page->permalink(); ?>"><?php echo $page->title(); ?></a></li>
</li>
<?php
}
?>
</ul>
</div>
</section>
<section class="card c-secondary" id="sidebar-tags">
<h2 class="card-header">Tags</h2>
<div class="card-body">
<ul class="tag-list">
<?php
$items = getTags();
foreach ($items as $tag) {
if (count($tag->pages()) > 1) {
echo '<li><a class="badge" href="'.$tag->permalink().'">'.$tag->name().'</a></li>';
}
}
?>
</ul>
</div>
</section>