52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Controllers;
|
||
|
|
||
|
use App\Blogs\Blogs;
|
||
|
use App\Utils\Debug;
|
||
|
|
||
|
class Posts {
|
||
|
|
||
|
private $title = 'Posts';
|
||
|
public $page;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Displaying a list of blog posts, including pagination
|
||
|
*
|
||
|
* @param array|null $params Optional parameters for pagination, extra filtering, and other settings
|
||
|
* @return string The rendered HTML content for the post listing page
|
||
|
*/
|
||
|
function index(?array $params = null): string {
|
||
|
ob_start();
|
||
|
if (empty($params['page'])) {
|
||
|
$params['page'] = 1;
|
||
|
} else {
|
||
|
$params['page'] = (int) $params['page'];
|
||
|
}
|
||
|
|
||
|
$this->page = $params['page'];
|
||
|
|
||
|
$posts = new Blogs($params);
|
||
|
|
||
|
$list = $posts->makeList();
|
||
|
|
||
|
if (!empty($params['extraParams'])) {
|
||
|
if (isset($params['extraParams']['year']) && (int)$params['extraParams']['year']) {
|
||
|
$posts->findPostByYear($params['extraParams']['year']);
|
||
|
}
|
||
|
}
|
||
|
$getPostList = $posts->getFilesForPage($params['page']);
|
||
|
$pagination = $posts->makePagination($params['page']);
|
||
|
|
||
|
require __DIR__ . '/../../template/posts.php';
|
||
|
$content = ob_get_contents();
|
||
|
ob_end_clean();
|
||
|
return $content;
|
||
|
}
|
||
|
|
||
|
function title() {
|
||
|
return $this->title;
|
||
|
}
|
||
|
}
|