diff --git a/php/Index.php b/php/Index.php index 97a951c608cb3172e01fe3c3107052f5ecf9a126..b8d4f947ae6f47c9f22b1df2540910c7bf025ee3 100644 --- a/php/Index.php +++ b/php/Index.php @@ -2,6 +2,7 @@ require_once 'Page.php'; require_once 'constants.php'; +require_once 'data/News.php'; class Index extends Page { @@ -36,7 +37,17 @@ class Index extends Page { $json = json_decode($fileContents, true); - return $json["news"]; + $news = array(); + + foreach ($json["news"] as $elem) { + $title = htmlspecialchars($elem["title"]); + $imgurl = htmlspecialchars($elem["imgurl"]); + $content = htmlspecialchars($elem["content"]); + + $news[] = new News($title, $imgurl, $content); + } + + return $news; } protected function generateView():void @@ -107,17 +118,14 @@ class Index extends Page { <div> <div class="article-content-container"> EOT; - - $news = $data[0]; - - $title = htmlspecialchars($news["title"]); - $imageurl = htmlspecialchars($news["imgurl"]); - $content = htmlspecialchars($news["content"]); + $title = $data[0]->title(); + $imgurl = $data[0]->imgurl(); + $content = $data[0]->content(); echo <<<EOT <a class="article-link" href="#"></a> - <img class="article-image" src="$imageurl" alt="" /> + <img class="article-image" src="$imgurl" alt="" /> <div class="article-content nasa-events-container"> @@ -146,17 +154,15 @@ EOT; <div> <div class="article-content-container"> EOT; - $news = $data[1]; - - $title = htmlspecialchars($news["title"]); - $imageurl = htmlspecialchars($news["imgurl"]); - $content = htmlspecialchars($news["content"]); + $title = $data[1]->title(); + $imgurl = $data[1]->imgurl(); + $content = $data[1]->content(); echo <<<EOT <a class="article-link" href="#"></a> - <img class="article-image" src="$imageurl" alt="" /> + <img class="article-image" src="$imgurl" alt="" /> <div class="article-content overlay"> <h4 class="overlay-title">$title</h4> @@ -169,17 +175,15 @@ EOT; <div> <div class="article-content-container"> EOT; - $news = $data[2]; - - $title = htmlspecialchars($news["title"]); - $imageurl = htmlspecialchars($news["imgurl"]); - $content = htmlspecialchars($news["content"]); + $title = $data[2]->title(); + $imgurl = $data[2]->imgurl(); + $content = $data[2]->content(); echo <<<EOT <a class="article-link" href="#"></a> - <img class="article-half-image" src="$imageurl" alt="" /> + <img class="article-half-image" src="$imgurl" alt="" /> <div class="article-triangle"></div> diff --git a/php/data/News.php b/php/data/News.php new file mode 100644 index 0000000000000000000000000000000000000000..5715525cd23d8ef894543c2373da2baede4fa599 --- /dev/null +++ b/php/data/News.php @@ -0,0 +1,25 @@ +<?php declare(strict_types=1); + +class News { + private string $title; + private string $imgurl; + private string $content; + + public function __construct(string $title, string $imgurl, string $content) { + $this->title = $title; + $this->imgurl = $imgurl; + $this->content = $content; + } + + public function title(): string { + return $this->title; + } + + public function imgurl(): string { + return $this->imgurl; + } + + public function content(): string { + return $this->content; + } +} \ No newline at end of file