OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
newsapi
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
11/28/2024 11:03:35 AM
rwxrwxr-x
📄
main.php
10.62 KB
06/19/2024 06:43:29 AM
rw-r--r--
Editing: main.php
Close
<!-- apiKey = "f044a117-fd52-49e4-837d-ba707739f008" --> <?php session_start(); ?> <!DOCTYPE html> <html lang="en" style="overflow-x: hidden;"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>News Search</title> <style> body { width: 100%; font-family: Arial, sans-serif; background-color: #f0f0f0; margin: 0; /* display: flex; */ justify-content: center; align-items: flex-start; min-height: 100vh; } .sidebar { flex: 0 0 auto; width: 250px; background-color: #333; color: #fff; padding: 20px; height: 100%; overflow-y: auto; /* Enable scrollbar if content exceeds height */ } .container { flex: 1; max-width: 100%; /* width: 100%; */ background-color: #fff; padding: 20px; border-radius: 8px; /* box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); */ /* margin-left: 20px; */ /* Ensure space between sidebar and container */ } h2 { text-align: center; } form { display: flex; justify-content: center; align-items: center; margin-bottom: 20px; } input[type="text"] { flex: 1; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 4px 0 0 4px; border-right: none; } button[type="submit"] { padding: 10px 20px; font-size: 16px; background-color: #4CAF50; color: white; border: 1px solid #4CAF50; border-radius: 0 4px 4px 0; cursor: pointer; } button[type="submit"]:hover { background-color: #45a049; } .news-item { margin-bottom: 20px; padding: 10px; border: 1px solid #ccc; border-radius: 5px; background-color: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } .news-item h3 { margin-top: 0; margin-bottom: 10px; } .news-item p { font-size: 14px; margin: 0; } .search-history { margin-bottom: 20px; /* Adjust margin as needed */ } .search-history h3 { margin-bottom: 10px; color: #fff; } .search-history ul { list-style-type: none; padding: 0; margin: 0; } .search-history ul li { margin-bottom: 5px; color: #ccc; } .header-container { display: grid; justify-content: center; justify-items: center; } @media only screen and (max-width: 900px) { .container { margin-left: 0; margin-top: 20px; /* Provide space on top for smaller screens */ } .sidebar { display: none; /* Hide sidebar on smaller screens */ } } .main { display: flex; justify-content: center; margin-top: 20px; } .div-img { width: 100%; display: flex; justify-content: center; } .content-img { max-width: 50%; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); margin-bottom: 20px; border-radius: 10px; display: grid; justify-self: center; justify-content: center; justify-items: center; } .news-item img { display: flex; justify-content: center; } .footer { background-color: #f8f9fa; text-align: center; padding: 10px 0; position: relative; width: 100%; bottom: 0; } </style> </head> <body> <div class="news-container" style="width: 100%;"> <header class="bg-light"> <div class="container header-container text-center py-3" style="width: 100;"> <a href="/"><img src="../grfx/logo.png" alt="Knobly Cream" style="max-width: 200px;"></a> <p class="lead">Create • Reach • Engage • Amaze • Motivate</p> </div> </header> <div class="main"> <div class="sidebar"> <!-- Sidebar content for history can be added here --> <div class="search-history"> <h3> Search History</h3> <ul> <?php // Check if history array exists in session if (isset($_SESSION['search_history']) && is_array($_SESSION['search_history'])) { // Display each search history item foreach ($_SESSION['search_history'] as $search) { echo '<li>' . htmlspecialchars($search) . '</li>'; } } ?> </ul> </div> </div> <div class="container"> <h2>Search News by Keywords</h2> <form method="post"> <input type="text" id="keyword" name="keyword" placeholder="Enter keywords" required> <button type="submit">Search</button> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // Ensure keyword is set and not empty if (isset($_POST["keyword"]) && !empty($_POST["keyword"])) { $keyword = $_POST["keyword"]; // Store keyword in session history if (!isset($_SESSION['search_history'])) { $_SESSION['search_history'] = []; } array_unshift($_SESSION['search_history'], $keyword); // Function to handle POST requests using cURL function postRequest($url, $data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' ]); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); $response = curl_exec($ch); if (curl_errno($ch)) { die('Error occurred while making POST request: ' . curl_error($ch)); } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpCode == 401) { die('Error: Unauthorized. Check your API key.'); } curl_close($ch); return $response; } // Example usage of POST request function $url = "https://eventregistry.org/api/v1/article/getArticles"; $data = [ "action" => "getArticles", 'keyword' => $keyword, "resultType" => "articles", "articlesCount" => 20, // Adjust as needed "dataType" => "news", 'apiKey' => 'f044a117-fd52-49e4-837d-ba707739f008' // Replace with your actual API key ]; $response = postRequest($url, $data); // Decode the JSON response into a PHP array $responseData = json_decode($response, true); // print_r("<pre>"); // print_r($responseData ); // print_r("</pre>"); // Check if the responseData is decoded correctly if ($responseData === null && json_last_error() !== JSON_ERROR_NONE) { die("Error decoding JSON response: " . json_last_error_msg()); } // Output the parsed data echo "<h3>Search Results:</h3>"; if (isset($responseData['articles']['results']) && is_array($responseData['articles']['results'])) { foreach ($responseData['articles']['results'] as $display) { echo '<div class="news-item">'; echo '<h3>' . htmlspecialchars($display['title']) . '</h3>'; echo '<div class="div-img">'; echo '<img class="content-img" src="' . htmlspecialchars($display['image']) . '" alt="' . $display["title"] . '"></div>'; echo '<p>' . htmlspecialchars($display['body']) . '</p><br><br>'; echo '<a href="' . htmlspecialchars($display["url"]) . '">View the Source</a><br>'; echo '<p>Date and Time: ' . htmlspecialchars($display['dateTime']) . '</p>'; echo '</div>'; } } else { echo '<p>No articles found.</p>'; } } else { echo '<p>Please enter a keyword to search.</p>'; } } ?> </div> </div> </div> <footer class="footer"> <div class="container"> <span class="text-muted">© 2024 Knobly Cream. All rights reserved.</span> </div> </footer> </body> </html>