diff --git a/admin.html b/admin.html deleted file mode 100644 index 8813c116aa7e5a5ca52aa580256758c8b3406dd2..0000000000000000000000000000000000000000 --- a/admin.html +++ /dev/null @@ -1,20 +0,0 @@ -<!DOCTYPE html> -<html lang="de"> - <head> - <title>NASA - Admin</title> - <meta charset="UTF-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1"> - <link rel="stylesheet" style="text/css" href="styles.css" /> - </head> - <body> - <header class="admin-header"><h1>Admin-Page</h1></header> - - <form class="admin-form" action="admin.html" method="post" accept-charset="UTF-8"> - <fieldset> - <legend>Select a News file</legend> - <input id="news-file" name="news-file" type="file" accept=".json" required /> - <input type="submit" value="Apply" /> - </fieldset> - </form> - </body> -</html> \ No newline at end of file diff --git a/data/news_01.json b/data/uploads/news_01.json similarity index 60% rename from data/news_01.json rename to data/uploads/news_01.json index 19e79202179aab8088a2a86d548305e027b3f60a..7061226f78abcaba8553ab93c5f4a72d5106c3fd 100644 --- a/data/news_01.json +++ b/data/uploads/news_01.json @@ -1,18 +1,18 @@ { "news":[ { - "title":"SpaceX's Next Starship Prototype Taking Shape ", - "imgurl":"", - "content":"Construction of the test craft is proceeding apace, as two new photos posted on Twitter today (Sept. 17) by company founder and CEO Elon Musk reveal." + "title": "SpaceX's Next Starship Prototype Taking Shape ", + "imgurl": "../img/astronaut.jpg", + "content": "Construction of the test craft is proceeding apace, as two new photos posted on Twitter today (Sept. 17) by company founder and CEO Elon Musk reveal." }, { "title":"NASA's Juno Mission Cheks Out Eclipse on Jupiter", - "imgurl":"img/astronaut.jpg", + "imgurl":"../img/astronaut.jpg", "content":"All is well on our largest neighbor; NASA's Juno spacecraft just managed to spot the shadow of Jupiter's moon, Io, passing over its marbled clouds." }, { "title":"Europe Wants Ideas for Cave-Spelumking Moon Robots", - "imgurl":"img/nasa_launch.jpg", + "imgurl":"../img/nasa_launch.jpg", "content":"As NASA makes a big push to land humans on the moon's surface by 2024, the European Space Agency (ESA) wants to learn more about the lunar caves that lie beneath." } ] diff --git a/data/news_02.json b/data/uploads/news_02.json similarity index 87% rename from data/news_02.json rename to data/uploads/news_02.json index fa5438e7d04ba60867aaef1b8e2c56ea8e5e521f..4814fef86defd460ffdedf5d98ca3fc6f56f2a32 100644 --- a/data/news_02.json +++ b/data/uploads/news_02.json @@ -7,12 +7,12 @@ }, { "title":"Expedition 48", - "imgurl":"img/astronaut.jpg", + "imgurl":"../img/astronaut.jpg", "content":"NASA's Record-braking Astronaut Crewmates Safely Return to Earth" }, { "title":"NASA to Launch First U.S. Asteroid Sample Return Mission", - "imgurl":"img/nasa_launch.jpg", + "imgurl":"../img/nasa_launch.jpg", "content":"Launching on Sept. 8, 2016 OSIRIS-REx will travel to a near-Earth asteroid called Bennu and bring a small sample back for study." } ] diff --git a/first.php b/first.php deleted file mode 100644 index b95842750c1f0ef1ec7ed28c603deb0a01300e47..0000000000000000000000000000000000000000 --- a/first.php +++ /dev/null @@ -1,13 +0,0 @@ -<html> -<?php - ini_set("display_errors", 0); - ini_set("display_startup_errors", 0); -?> - -<head></head> -<body> - <?php - echo "Hello World, this is my first PHP"; - ?> -</body> -</html> \ No newline at end of file diff --git a/index.php b/index.php deleted file mode 100644 index 688df6962e85667d6b0f4a9fbfb8b2e9739c8ec4..0000000000000000000000000000000000000000 --- a/index.php +++ /dev/null @@ -1,205 +0,0 @@ -<?php declare(strict_types=1); - ini_set("display_errors", 1); - ini_set("display_startup_errors", 1); - - $file = "data/news_01.json"; - - if (!file_exists($file)) { - die("File not found"); - } - - $fileContents = file_get_contents('data/news_01.json'); - - if ($fileContents === NULL) - return; - - $json = json_decode($fileContents, true); - $newsList = $json["news"]; -?> -<!DOCTYPE html> -<html lang="de"> - <head> - <title>NASA</title> - <meta charset="UTF-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1"> - <script src="functions.js"></script> - <link rel="stylesheet" type="text/css" href="styles.css" /> - </head> - <body class="nasa-body"> - <header class="nasa-header"> - <img class="nasa-img" src="img/nasa.png" alt="" /> - - <nav> - <ul class="top-nav"> - <li><a href="#">Missions</a></li> - <li><a href="#">Galleries</a></li> - <li><a href="#">NASA TV</a></li> - <li><a href="#">Follow NASA</a></li> - <li><a href="#">Downloads</a></li> - <li><a href="#">About</a></li> - <li><a href="#">NASA Audiences</a></li> - <li> - <form class="search-form" method="post" accept-charset="UTF-8"> - <input type="search" placeholder="Search" /> - <input type="button" value="" /> - </form> - </li> - <li><img src="img/share_icon.png" alt="" /></li> - <li class="admin-button"><a href="php/admin.php">Admin</a></li> - </ul> - - <ul class="center-nav"> - <li><a href="#">International Space Station</a></li> - <li><a href="#">Journey to Mars</a></li> - <li><a href="#">Earth</a></li> - <li><a href="#">Technology</a></li> - <li><a href="#">Aeronautics</a></li> - <li><a href="#">Solar System and Beyond</a></li> - <li><a href="#">Education</a></li> - <li><a href="#">History</a></li> - <li><a href="#">Benefits to You</a></li> - </ul> - </nav> - </header> - - <main> - <article class="content-large"> - <div> - <div class="article-content-container"> - <a class="article-link" href="#"></a> - - <img id="slide-image" class="article-image" src="img/nasa_news_1.jpg" alt="" /> - - <div class="article-content"> - <div id="slide-container" class="news-headline"> - <h3>Space Station</h3> - <h2>Expedition 48 Crew Lands Safely on Earth</h2> - </div> - - <div class="camera-triangle"></div> - <img class="camera-img" src="img/camera.png" alt="" /> - </div> - </div> - </div> - </article> - <article class="content-small"> - <div> - <div class="article-content-container"> - <a class="article-link" href="#"></a> - - <div class="article-content nasa-events-container"> - <div class="nasa-events-top"> - <?php - $news = $newsList[0]; - - $title = htmlspecialchars($news["title"]); - $imageurl = htmlspecialchars($news["imgurl"]); - $content = htmlspecialchars($news["content"]); - ?> - - <p class="nasa-events-title"><?= $title ?></p> - - <div class="line"></div> - - <a class="nasa-event" href="#"><?= $content ?></a> - </div> - - <div class="nasa-events-bottom"> - <div class="line"></div> - - <div class="nasa-events-bottom-horizontal"> - <a href="#">Calendar</a> - <a href="#">Launches and Landings</a> - </div> - </div> - </div> - </div> - </div> - </article> - - <article class="content-small"> - <div> - <div class="article-content-container"> - <?php - $news = $newsList[1]; - - $title = htmlspecialchars($news["title"]); - $imageurl = htmlspecialchars($news["imgurl"]); - $content = htmlspecialchars($news["content"]); - ?> - - <a class="article-link" href="#"></a> - - <img class="article-image" src="<?= $imageurl ?>" alt="" /> - - <div class="article-content overlay"> - <h4 class="overlay-title"><?= $title ?></h4> - <h4 class="overlay-description"><?= $content ?></h4> - </div> - </div> - </div> - </article> - <article class="content-medium"> - <div> - <div class="article-content-container"> - <?php - $news = $newsList[2]; - - $title = htmlspecialchars($news["title"]); - $imageurl = htmlspecialchars($news["imgurl"]); - $content = htmlspecialchars($news["content"]); - ?> - - <a class="article-link" href="#"></a> - - <img class="article-half-image" src="<?= $imageurl ?>" alt="" /> - - <div class="article-triangle"></div> - - <div class="article-content-second-half nasa-launch"> - <h4><?= $title ?></h4> - - <p><?= $content ?></p> - - <div class="nasa-launch-links"> - <a href="#">Mission Site</a> - <a href="#">Briefing Schedule</a> - <a href="#">Launch Updates</a> - <a href="#">Video to Bennu and Back</a> - </div> - </div> - </div> - </div> - </article> - <article class="content-small"> - <div> - <div class="article-content-container"> - <a class="article-link" href="#"></a> - - <div class="article-content"> - <iframe src="https://www.youtube.com/embed/XY6idnRlPsU?si=HnFL8-if6-zB6tU2" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> - </div> - </div> - </div> - </article> - <article class="content-medium"> - <div> - <div class="article-content-container"> - <a class="article-link" href="#"></a> - - <img class="article-image" src="img/ocean_worlds.jpg" alt="" /> - </div> - </div> - </article> - <article class="content-small"> - <div> - <div class="article-content-container"> - <a class="article-link" href="#"></a> - - <img class="article-image article-image-full" src="img/tweet.png" alt="" /> - </div> - </div> - </article> - </main> - </body> -</html> \ No newline at end of file diff --git a/php/Admin.php b/php/Admin.php index d6f5483d03007fe1610b3c23f2eb22ff63605755..8491b3e2a0d6a6e835303e0d98c0e6883bbbf892 100644 --- a/php/Admin.php +++ b/php/Admin.php @@ -5,7 +5,7 @@ require_once 'constants.php'; class Admin extends Page { - private const FILE_NAME = "fileName"; + private const FILE = "file"; protected function __construct() { @@ -37,18 +37,20 @@ class Admin extends Page $data = $this->getViewData(); $this->generatePageHeader('NASA Admin'); - $fileName = self::FILE_NAME; + $file = self::FILE; echo <<<EOT -<header class="admin-header"><h1>Admin-Page</h1></header> - -<form class="admin-form" action="Admin.php" method="post" accept-charset="UTF-8"> - <fieldset> - <legend>Select a News file</legend> - <input id="$fileName" name="$fileName" type="file" accept=".json" required /> - <input type="submit" value="Apply" /> - </fieldset> -</form> +<body> + <header class="admin-header"><h1>Admin-Page</h1></header> + + <form class="admin-form" action="Admin.php" method="post" enctype="multipart/form-data" accept-charset="UTF-8"> + <fieldset> + <legend>Select a News file</legend> + <input id="$file" name="$file" type="file" accept=".json" required /> + <input type="submit" value="Apply" /> + </fieldset> + </form> +</body> EOT; $this->generatePageFooter(); @@ -59,9 +61,15 @@ EOT; parent::processReceivedData(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { - if (isset($_POST[self::FILE_NAME])) { - $_SESSION[NEWS_FILE] = $_POST[self::FILE_NAME]; - header("Location: ../index.php"); + if (isset($_FILES[self::FILE])) { + $name = $_FILES[self::FILE]["name"]; + $tmp = $_FILES[self::FILE]["tmp_name"]; + $target = "../data/uploads/" . $name; + move_uploaded_file($tmp, $target); + + $_SESSION[NEWS_FILE] = $target; + + header("Location: Index.php"); die(); } } diff --git a/php/Index.php b/php/Index.php index 3cb41103e90ba0c12a56b86d7b409203c2450930..97a951c608cb3172e01fe3c3107052f5ecf9a126 100644 --- a/php/Index.php +++ b/php/Index.php @@ -19,19 +19,36 @@ class Index extends Page { protected function getViewData():array { - return array(); + $file = DEFAULT_NEWS_FILE; + + if (isset($_SESSION[NEWS_FILE])) { + $file = $_SESSION[NEWS_FILE]; + } + + if (!file_exists($file)) { + die("File not found"); + } + + $fileContents = file_get_contents($file); + + if ($fileContents === NULL) + return array(); + + $json = json_decode($fileContents, true); + + return $json["news"]; } protected function generateView():void { $data = $this->getViewData(); $this->generatePageHeader('NASA'); - - $news = $this->fetchNews(); echo <<<EOT + +<body class="nasa-body"> <header class="nasa-header"> -<img class="nasa-img" src="img/nasa.png" alt="" /> +<img class="nasa-img" src="../img/nasa.png" alt="" /> <nav> <ul class="top-nav"> @@ -49,7 +66,7 @@ class Index extends Page { </form> </li> <li><img src="img/share_icon.png" alt="" /></li> - <li class="admin-button"><a href="php/admin.php">Admin</a></li> + <li class="admin-button"><a href="Admin.php">Admin</a></li> </ul> <ul class="center-nav"> @@ -72,7 +89,7 @@ class Index extends Page { <div class="article-content-container"> <a class="article-link" href="#"></a> - <img id="slide-image" class="article-image" src="img/nasa_news_1.jpg" alt="" /> + <img id="slide-image" class="article-image" src="../img/nasa_news_1.jpg" alt="" /> <div class="article-content"> <div id="slide-container" class="news-headline"> @@ -81,7 +98,7 @@ class Index extends Page { </div> <div class="camera-triangle"></div> - <img class="camera-img" src="img/camera.png" alt="" /> + <img class="camera-img" src="../img/camera.png" alt="" /> </div> </div> </div> @@ -89,18 +106,22 @@ class Index extends Page { <article class="content-small"> <div> <div class="article-content-container"> - <a class="article-link" href="#"></a> - - <div class="article-content nasa-events-container"> - <div class="nasa-events-top"> EOT; - $news = $newsList[0]; + + $news = $data[0]; $title = htmlspecialchars($news["title"]); $imageurl = htmlspecialchars($news["imgurl"]); $content = htmlspecialchars($news["content"]); echo <<<EOT + <a class="article-link" href="#"></a> + + <img class="article-image" src="$imageurl" alt="" /> + + <div class="article-content nasa-events-container"> + + <div class="nasa-events-top"> <p class="nasa-events-title">$title</p> <div class="line"></div> @@ -125,7 +146,7 @@ EOT; <div> <div class="article-content-container"> EOT; - $news = $newsList[1]; + $news = $data[1]; $title = htmlspecialchars($news["title"]); $imageurl = htmlspecialchars($news["imgurl"]); @@ -148,7 +169,7 @@ EOT; <div> <div class="article-content-container"> EOT; - $news = $newsList[0]; + $news = $data[2]; $title = htmlspecialchars($news["title"]); $imageurl = htmlspecialchars($news["imgurl"]); @@ -193,7 +214,7 @@ EOT; <div class="article-content-container"> <a class="article-link" href="#"></a> - <img class="article-image" src="img/ocean_worlds.jpg" alt="" /> + <img class="article-image" src="../img/ocean_worlds.jpg" alt="" /> </div> </div> </article> @@ -202,11 +223,12 @@ EOT; <div class="article-content-container"> <a class="article-link" href="#"></a> - <img class="article-image article-image-full" src="img/tweet.png" alt="" /> + <img class="article-image article-image-full" src="../img/tweet.png" alt="" /> </div> </div> </article> </main> +</body> EOT; $this->generatePageFooter(); @@ -225,26 +247,6 @@ EOT; } } - private function fetchNews(): array { - $file = DEFAULT_NEWS_FILE; - - if (isset($_SESSION[NEWS_FILE])) - $file = $_SESSION[NEWS_FILE] - - if (!file_exists($file)) { - die("File not found"); - } - - $fileContents = file_get_contents('data/news_01.json'); - - if ($fileContents === NULL) - return; - - $json = json_decode($fileContents, true); - - return $json["news"]; - } - public static function main():void { try { diff --git a/php/Page.php b/php/Page.php index d2f31a58004146be6a19f9e2c0968b7ea7a52588..9d67992f00980218df464386fcf2bc12b8a8b931 100644 --- a/php/Page.php +++ b/php/Page.php @@ -50,14 +50,12 @@ abstract class Page { <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" style="text/css" href="../styles.css" /> </head> -<body>\n EOT; } protected function generatePageFooter():void { echo <<<EOT -</body> </html> EOT; } diff --git a/php/constants.php b/php/constants.php index 6cf2f45ffddc16e51dd9dac3939be4d6513368b4..eeb262a59b012ee9a7e12764fcbfdbb5ddf3dc54 100644 --- a/php/constants.php +++ b/php/constants.php @@ -1,4 +1,4 @@ <?php define("NEWS_FILE", "news_file"); - define("DEFAULT_NEWS_FILE", "data/news_01.json"); + define("DEFAULT_NEWS_FILE", "../data/upload/news_01.json"); ?> \ No newline at end of file diff --git a/styles.css b/styles.css index b3f742d4ffe617b7368c0f04e0e4e8152b4baf6e..2cb4474e2fca745c08c5254b6bd8135b12d99f66 100644 --- a/styles.css +++ b/styles.css @@ -32,7 +32,7 @@ a { background-size: auto 100%; } -.top-nav ul, .center-nav ul { +.top-nav, .center-nav { list-style-type: none; margin: 0; padding: 0;