Download<!-- Improved compatibility of back to top link: See: https://github.com/othneildrew/Best-README-Template/pull/73 -->
<a id="readme-top"></a>
<h3 align="center">rssFetchXml</h3>
<p align="center"> rssFetchXml is an RSS and Atom reader that uses PHP, Javascript and HTML to display XML feeds
<br />
<a href="https://github.com/github_username/repo_name">View Demo</a>
</p>
</div>
<!-- TABLE OF CONTENTS -->
<details>
<summary>Table of Contents</summary>
<ol> <li>
<a href="#about-the-project">About The Project</a>
<ul>
<li><a href="#built-with">Built With</a></li>
</ul>
</li>
<li>
<a href="#getting-started">Getting Started</a>
<ul>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#installation">Installation</a></li>
</ul>
</li>
<li><a href="#usage">Usage</a></li>
<li><a href="#license">License</a></li>
<li><a href="#contact">Contact</a></li>
</ol>
</details>
<!-- ABOUT THE PROJECT -->
About The Project
<b>rssFetchXml Features:</b>
-
Avoids using commercial RSS APIs that may require a subscription and fees
-
Compact code that simplifies adding an RSS feed to a webpage utilizing
PHP's simplexml, cURL and Javascript.
-
Does not require allow_url_fopen enabled.
-
Using simplexml with cURL sends "friendly" RSS requests that CDNs such
as Cloudflare may treat as bots with other methods.
-
Auto saves cached XML files.
-
Cache dir, cache expiration time, max number of feed links and custom error
message set in config file.
<p align="right">(<a href="#readme-top">back to top</a>)</p>
Built With
<p align="right">(<a href="#readme-top">back to top</a>)</p>
<!-- GETTING STARTED -->
Getting Started
Prerequisites
-
PHP (v7.2+)
-
cURL extension enabled
-
libxml extension enabled
Installation
-
Upload rssFetchXml.php, rss_config.php and rss_fetch.js to a directory on your server. rssFetchXml.php and rss_config.php must be in the same directory.
-
Open `rss_config.php` and edit the following variables
return [
"cache_dir" => "path/to/cache/", //Path to cache dir
"cache_expire" => 3600, //Cache expire in secs - ie: 3600 = 1 hr
"rss_error" => "RSS fetch failed - RSS Url or feed may be unavailable", //Custom error message on feed failure
"rss_max" => 12 //Max number of links displayed
];
-
Open `rss_fetch.js` and edit the following variable
let rssUrl = "https://somesite.com/rss/rssFetchXml.php";
-
Add `rss_fetch.js` script link to your HTML template right before the closing `</body>` tag
<script src="https://somesite.com/rss/rss_fetch.js"></script>
<p align="right">(<a href="#readme-top">back to top</a>)</p>
<!-- USAGE EXAMPLES -->
Usage
-
Add an empty HTML div where you want to display the RSS feed. Set its class as `rss-feed` and the data attribute `data-rss` value as the RSS feed URL.
<div class="rss-feed" data-rss="https://somesite.com/rss/feeds/feed.xml"></div>
-
This will return a HTML formatted block with the following structure:
<div class="rss-feed" data-rss="https://somesite.com/rss/feeds/feed.xml">
<div class="rss-header"><a href="https://somesite.com/" target="_blank">Channel Title</a></div>
<div class="rss-wrapper">
<div class="rss-link"><a href="https://somesite.com/item.html" target="_blank">Item 1 Title</a></div>
<div class="rss-link"><a href="https://somesite.com/item2.html" target="_blank">Item 2 Title</a></div>
<div class="rss-link"><a href="https://somesite.com/item3.html" target="_blank">Item 3 Title</a></div>
</div>
</div>
-
Add the following CSS properties to your CSS file to format your feed
.rss-feed {
padding: .5rem;
background-color: #fff;
border: .063rem solid #aaa;
}
.rss-header {
padding: .5rem;
}
.rss-header a {
font-weight: bold;
padding: .5rem;
color: #000;
text-decoration: none;
}
.rss-wrapper {
height: 10rem;
overflow-x: hidden;
overflow-y: scroll;
padding: .5rem;
}
.rss-link a {
text-decoration: none;
}
<p align="right">(<a href="#readme-top">back to top</a>)</p>
<!-- TROUBLESHOOTING -->
Troubleshooting
-
If your are displaying the custom error message, check that the RSS feed URL is correct. Some site's CDNs may use strict security
and are treating you request as a bot and returning forbidden codes. You will need to create a proxy feed from a site such as Google's <a href="https://feedburner.google.com/">Feedburner</a>.
-
If no RSS content or error messages are being displayed, check the cache dir path you set in `rss_config` is valid and exists. Also check the URL set in `rss_fetch.js` is correct as well the
script URL.
<p align="right">(<a href="#readme-top">back to top</a>)</p>
<!-- LICENSE -->
License
Distributed under the MIT license. See LICENSE.txt for more information.
<p align="right">(<a href="#readme-top">back to top</a>)</p>
<!-- CONTACT -->
Contact
Mike Jordan: mtjo62@gmail.com
Project Link: https://github.com/mtjo62/rssFetchXml
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|