first commit

This commit is contained in:
Neovoid Pineapple 2023-06-25 12:54:54 +00:00
commit 2f21f6071e
3 changed files with 185 additions and 0 deletions

75
index.php Normal file
View file

@ -0,0 +1,75 @@
<!DOCTYPE html>
<html>
<head>
<title>RSS Feed Reader</title>
<link href="style.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/dompurify@2.3.3/dist/purify.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('#get-feeds').click(function() {
var rssUrl = $('#rss-url').val();
if (rssUrl !== '') {
$.ajax({
url: 'parse_rss.php',
method: 'POST',
data: { rssUrl: rssUrl },
dataType: 'json',
success: function(response) {
if (response.success) {
displayFeeds(response.feeds, response.feedTitle);
} else {
alert(response.message);
}
},
error: function() {
alert('An error occurred while retrieving the feeds.');
}
});
}
});
function displayFeeds(feeds, feedTitle) {
$('#feeds-container').empty();
$('#feed-title').text('RSS Feeds of ' + sanitizeHTML(feedTitle));
feeds.forEach(function(feed) {
var feedContainer = $('<div>').addClass('feed');
var date = $('<span>').addClass('date').text(sanitizeHTML(feed.date));
var title = $('<h2>').addClass('title').text(sanitizeHTML(feed.title));
var content = $('<div>').addClass('content').html(sanitizeHTML(feed.content));
title.click(function() {
content.toggle();
});
// Sanitize HTML content using DOMPurify
var sanitizedContent = DOMPurify.sanitize(feed.content);
content.html(sanitizedContent);
feedContainer.append(date);
feedContainer.append(title);
feedContainer.append(content);
$('#feeds-container').append(feedContainer);
});
}
function sanitizeHTML(value) {
var tempElement = document.createElement('div');
tempElement.textContent = value;
return tempElement.innerHTML;
}
});
</script>
</head>
<body>
<h1 id="feed-title"> RSS Feeds Reader</span></h1>
<input type="text" id="rss-url" placeholder="Enter RSS URL">
<button id="get-feeds">Get Feeds</button>
<div id="feeds-container"></div>
</body>
</html>

43
parse_rss.php Normal file
View file

@ -0,0 +1,43 @@
<?php
if (isset($_POST['rssUrl'])) {
$rssUrl = $_POST['rssUrl'];
$feed = simplexml_load_file($rssUrl);
if ($feed) {
$feedTitle = (string) $feed->channel->title;
$feeds = array();
foreach ($feed->channel->item as $item) {
$title = (string) $item->title;
$date = (string) $item->pubDate;
$content = (string) $item->description;
$feeds[] = array(
'title' => $title,
'date' => $date,
'content' => $content
);
}
$response = array(
'success' => true,
'feedTitle' => $feedTitle,
'feeds' => $feeds
);
} else {
$response = array(
'success' => false,
'message' => 'Failed to parse RSS feed.'
);
}
} else {
$response = array(
'success' => false,
'message' => 'Invalid request.'
);
}
header('Content-Type: application/json');
echo json_encode($response);
?>

67
style.css Normal file
View file

@ -0,0 +1,67 @@
body {
font-family: "JetBrains Mono", system-ui, sans-serif;
font-size: 1.01rem;
line-height: 1.4;
color: white;
position: relative;
background: #0f0d11;
max-width: 64em; /* remove this for a full-width layout */
margin: 0 auto; /* centers the layout */
}
h1 {
margin: 16px 29px 12px;
color: #F5DF50;
}
input {
margin: 16px 29px 12px;
padding: 10px;
border: 1px solid #F5DF50;
background: bottom;
color: #4CAF50;
outline: none;
}
input:focus {
border-color:#F5DF50;
border-width:2px;
box-shadow:0 0 15px #F5DF50;
}
button {
margin: -19px;
padding: 10px;
box-shadow:0 0 15px #F5DF50;
border-color:#F5DF50;
background: #1f1d11;
color: #F5DF50;
}
.feed {
margin: 15px;
}
.date {
font-weight: bold;
margin: 15px;
color: #4CAF50;
}
.title {
cursor: pointer;
color: #F5DF50;
background-color: #1f1d11;
margin: 15px;
padding: 5px;
}
.content {
display: none;
margin: 15px;
padding: 35px;
border: 1px solid #F5DF50;
}