From 6e3acb1066577738d4b75c5b5cd77b921bd4465d Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Fri, 6 Sep 2024 15:35:09 +0000 Subject: [PATCH] WEB: Add a description and a descriptive title for OpenGraph --- include/Controller.php | 15 +++++++++++++++ include/Pages/ArticlePage.php | 2 ++ include/Pages/CompatibilityPage.php | 3 +++ include/Pages/DemosPage.php | 1 + include/Pages/DirectorDemosPage.php | 1 + include/Pages/DownloadsPage.php | 1 + include/Pages/GamesPage.php | 1 + include/Pages/LinksPage.php | 1 + include/Pages/NewsPage.php | 9 ++++++++- include/Pages/ScreenshotsPage.php | 5 +++++ include/Pages/SimplePage.php | 1 + templates/pages/index.tpl | 5 +++-- 12 files changed, 42 insertions(+), 3 deletions(-) diff --git a/include/Controller.php b/include/Controller.php index 0f059d507..3202a0881 100644 --- a/include/Controller.php +++ b/include/Controller.php @@ -225,4 +225,19 @@ protected function getConfigVars($title) { return $this->smarty->getConfigVars($title); } + + protected function getHeadline($body) + { + $headline = ''; + for ($line = \strtok($body, PHP_EOL); $line !== false; $line = \strtok(PHP_EOL)) { + $line = \strip_tags($line); + $headline .= $line . ' '; + if (\strlen($headline) > 250) { + $headline = substr($headline, 0, 249); + $headline .= "\u{2026}"; + break; + } + } + return $headline; + } } diff --git a/include/Pages/ArticlePage.php b/include/Pages/ArticlePage.php index a9473bc8d..ba13672ba 100644 --- a/include/Pages/ArticlePage.php +++ b/include/Pages/ArticlePage.php @@ -56,6 +56,8 @@ public function index($params) $content = $purifier->purify($Parsedown->text($article->body())); return $this->renderPage([ + 'title' => $title, + 'description' => htmlentities($this->getHeadline($content)), 'content_title' => $title, 'date' => $date, 'author' => $author, diff --git a/include/Pages/CompatibilityPage.php b/include/Pages/CompatibilityPage.php index 6d604a8f7..aa89921ca 100644 --- a/include/Pages/CompatibilityPage.php +++ b/include/Pages/CompatibilityPage.php @@ -90,6 +90,8 @@ public function getGame($target, $version) return $this->renderPage( array( 'title' => preg_replace('/{version}/', $version, $this->getConfigVars('compatibilityTitle')), + 'subtitle' => $game->getGame()->getName(), + 'description' => $this->getConfigVars('compatibilityIntro'), 'content_title' => preg_replace( '/{version}/', $version, @@ -116,6 +118,7 @@ public function getAll($version, $versions) return $this->renderPage( [ 'title' => preg_replace('/{version}/', $version, $this->getConfigVars('compatibilityTitle')), + 'description' => $this->getConfigVars('compatibilityIntro'), 'content_title' => preg_replace( '/{version}/', $version, diff --git a/include/Pages/DemosPage.php b/include/Pages/DemosPage.php index 6741fa406..d80599a0e 100644 --- a/include/Pages/DemosPage.php +++ b/include/Pages/DemosPage.php @@ -23,6 +23,7 @@ public function index() return $this->renderPage( array( 'title' => $this->getConfigVars('demosTitle'), + 'description' => $this->getConfigVars('gamesDemosContentP1'), 'content_title' => $this->getConfigVars('demosContentTitle'), 'demos' => $demos, ) diff --git a/include/Pages/DirectorDemosPage.php b/include/Pages/DirectorDemosPage.php index 9cad59203..62bc08c38 100644 --- a/include/Pages/DirectorDemosPage.php +++ b/include/Pages/DirectorDemosPage.php @@ -23,6 +23,7 @@ public function index() return $this->renderPage( array( 'title' => $this->getConfigVars('directorDemosTitle'), + 'description' => $this->getConfigVars('gamesDemosContentP1'), 'content_title' => $this->getConfigVars('directorDemosContentTitle'), 'demos' => $demos, ) diff --git a/include/Pages/DownloadsPage.php b/include/Pages/DownloadsPage.php index 93bf14373..33086f12a 100644 --- a/include/Pages/DownloadsPage.php +++ b/include/Pages/DownloadsPage.php @@ -23,6 +23,7 @@ public function index() return $this->renderPage( array( 'title' => $this->getConfigVars('downloadsTitle'), + 'description' => \strip_tags($this->getConfigVars('downloadsContentP1')), 'content_title' => $this->getConfigVars('downloadsContentTitle'), 'downloads' => $downloads, 'recommendedDownload' => $recommendedDownload diff --git a/include/Pages/GamesPage.php b/include/Pages/GamesPage.php index c9961f570..cf4757e52 100644 --- a/include/Pages/GamesPage.php +++ b/include/Pages/GamesPage.php @@ -23,6 +23,7 @@ public function index() return $this->renderPage( array( 'title' => $this->getConfigVars('gamesTitle'), + 'description' => strip_tags($this->getConfigVars('gamesContentP1')), 'content_title' => $this->getConfigVars('gamesContentTitle'), 'downloads' => $downloads, ) diff --git a/include/Pages/LinksPage.php b/include/Pages/LinksPage.php index 1751c509e..ef0d8f863 100644 --- a/include/Pages/LinksPage.php +++ b/include/Pages/LinksPage.php @@ -24,6 +24,7 @@ public function index() return $this->renderPage( array( 'title' => $this->getConfigVars('linksTitle'), + // TODO: add a description 'content_title' => $this->getConfigVars('linksContentTitle'), 'links' => $links, ) diff --git a/include/Pages/NewsPage.php b/include/Pages/NewsPage.php index 2797c2cea..54e5cc023 100644 --- a/include/Pages/NewsPage.php +++ b/include/Pages/NewsPage.php @@ -38,14 +38,19 @@ public function getNews($filename = null) { if ($filename == null) { $news_items = $this->newsModel->getAllNews(); - $filename = 'archive'; + $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())); } return $this->renderPage( array( 'title' => $this->getConfigVars('newsTitle'), + 'subtitle' => $subtitle, + 'description' => $description, 'content_title' => $this->getConfigVars('newsContentTitle'), 'show_intro' => false, 'news_items' => $news_items, @@ -69,6 +74,8 @@ public function getNewsIntro() return $this->renderPage( array( 'title' => $this->getConfigVars('newsTitle'), + 'subtitle' => $this->getConfigVars('newsContentTitle'), + 'description' => $this->getConfigVars('introHeaderContentP1'), 'content_title' => $this->getConfigVars('newsContentTitle'), 'show_intro' => true, 'news_items' => $news_items, diff --git a/include/Pages/ScreenshotsPage.php b/include/Pages/ScreenshotsPage.php index c9726b824..8f6b78785 100644 --- a/include/Pages/ScreenshotsPage.php +++ b/include/Pages/ScreenshotsPage.php @@ -39,6 +39,7 @@ public function index($args) return $this->renderPage( [ 'title' => $this->getConfigVars('screenshotsTitle'), + // TODO: Add a description 'content_title' => $this->getConfigVars('screenshotsContentTitle'), 'screenshots' => $screenshot, 'random_shot' => $random_shot, @@ -51,17 +52,21 @@ public function getCategory($category, $game) { if (empty($game)) { $screenshots = $this->screenshotsModel->getScreenshotsByCompanyId($category); + $subtitle = $screenshots['title']; } else { $screenshots = [ 'category' => $category, 'games' => $this->screenshotsModel->getScreenshotsBySubcategory($game) ]; + $subtitle = $screenshots['games'][0]->getName(); } $this->template = 'pages/screenshots_category.tpl'; return $this->renderPage( [ 'title' => $this->getConfigVars('screenshotsTitle'), + // TODO: Add a description + 'subtitle' => $subtitle, 'content_title' => $this->getConfigVars('screenshotsContentTitle'), 'screenshots' => $screenshots, 'category' => $category, diff --git a/include/Pages/SimplePage.php b/include/Pages/SimplePage.php index 3745bb5f9..ab4797c21 100644 --- a/include/Pages/SimplePage.php +++ b/include/Pages/SimplePage.php @@ -42,6 +42,7 @@ public function index($data = null) return $this->renderPage([ 'title' => $this->getConfigVars("{$this->key}Title"), + 'description' => $this->getConfigVars("{$this->key}Description"), 'content_title' => $this->getConfigVars("{$this->key}ContentTitle"), 'data' => $data ]); diff --git a/templates/pages/index.tpl b/templates/pages/index.tpl index f6af2c2b2..2634da22a 100644 --- a/templates/pages/index.tpl +++ b/templates/pages/index.tpl @@ -9,6 +9,7 @@ ScummVM :: {$title} + {if isset($description)}{/if} @@ -23,8 +24,8 @@ - - + + {if isset($description)}{/if}