mirror of
https://github.com/scummvm/scummvm-web.git
synced 2026-05-21 05:40:47 +00:00
93 lines
2.7 KiB
PHP
93 lines
2.7 KiB
PHP
<?php
|
|
namespace ScummVM\Pages;
|
|
|
|
use ScummVM\Controller;
|
|
use ScummVM\Models\NewsModel;
|
|
use ScummVM\Models\ScreenshotsModel;
|
|
|
|
class NewsPage extends Controller
|
|
{
|
|
private NewsModel $newsModel;
|
|
private ScreenshotsModel $screenshotModels;
|
|
|
|
/* Constructor. */
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->template = 'pages/news.tpl';
|
|
$this->newsModel = new NewsModel();
|
|
$this->screenshotModels = new ScreenshotsModel();
|
|
}
|
|
|
|
/**
|
|
* Display the index page.
|
|
*
|
|
* @param array{'date'?: string} $args
|
|
*/
|
|
public function index(array $args): void
|
|
{
|
|
$filename = $args['date'] ?? null;
|
|
|
|
if ($filename === null) {
|
|
$this->getNewsIntro();
|
|
return;
|
|
}
|
|
|
|
if (strtolower($filename) == 'archive' || $filename == '') {
|
|
$filename = null;
|
|
}
|
|
$this->getNews($filename);
|
|
}
|
|
|
|
/* Display a specific news item, or all news items. */
|
|
public function getNews(?string $filename = null): void
|
|
{
|
|
if ($filename == null) {
|
|
$news_items = $this->newsModel->getAllNews();
|
|
$subtitle = null;
|
|
$description = $this->getConfigVars('introHeaderContentP1');
|
|
} else {
|
|
$news_items = array($this->newsModel->getOneByFilename($filename));
|
|
$subtitle = $news_items[0]->getTitle();
|
|
$description = htmlentities($this->getHeadline($news_items[0]->getContent()));
|
|
}
|
|
|
|
$this->renderPage(
|
|
array(
|
|
'title' => $this->getConfigVars('newsTitle'),
|
|
'subtitle' => $subtitle,
|
|
'description' => $description,
|
|
'content_title' => $this->getConfigVars('newsContentTitle'),
|
|
'show_intro' => false,
|
|
'news_items' => $news_items,
|
|
'news_archive_link' => false,
|
|
)
|
|
);
|
|
}
|
|
|
|
/* Display the main page with limited news items and intro text. */
|
|
public function getNewsIntro(): void
|
|
{
|
|
$news_items = $this->newsModel->getLatestNews(NEWS_ITEMS);
|
|
$random_shot = $this->screenshotModels->getRandomScreenshot();
|
|
|
|
$this->addJSFiles(
|
|
array(
|
|
'baguetteBox.min.js'
|
|
)
|
|
);
|
|
|
|
$this->renderPage(
|
|
array(
|
|
'title' => $this->getConfigVars('homeTitle'),
|
|
'description' => $this->getConfigVars('introHeaderContentP1'),
|
|
'content_title' => $this->getConfigVars('newsContentTitle'),
|
|
'show_intro' => true,
|
|
'news_items' => $news_items,
|
|
'news_archive_link' => true,
|
|
'random_shot' => $random_shot,
|
|
)
|
|
);
|
|
}
|
|
}
|