76 lines
2.4 KiB
PHP
76 lines
2.4 KiB
PHP
<!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>
|
|
|