1

Update index.php

This commit is contained in:
Evan Pratten 2017-09-12 20:23:11 -04:00 committed by GitHub
parent 16a2f236e3
commit 86369b1c2f

View File

@ -98,56 +98,61 @@
<div class="rantlist-bg"> <div class="rantlist-bg">
<ul class="rantlist"> <ul class="rantlist">
<?PHP <?php
// define script parameters function getContent() {
$BLOGURL = "http://www.rssmix.com/u/8252161/rss.xml"; //Thanks to https://davidwalsh.name/php-cache-function for cache idea
$NUMITEMS = 2; $file = "./feed-cache.txt";
$TIMEFORMAT = "j F Y, g:ia"; $current_time = time();
$CACHEFILE = "/tmp/" . md5($BLOGURL); $expire_time = 5 * 60;
$CACHETIME = 4; // hours $file_time = filemtime($file);
if(file_exists($file) && ($current_time - $expire_time < $file_time)) {
// download the feed iff a cached version is missing or too old return file_get_contents($file);
if(!file_exists($CACHEFILE) || ((time() - filemtime($CACHEFILE)) > 3600 * $CACHETIME)) { }
if($feed_contents = http_get_contents($BLOGURL)) { else {
// write feed contents to cache file $content = getFreshContent();
$fp = fopen($CACHEFILE, 'w'); file_put_contents($file, $content);
fwrite($fp, $feed_contents); return $content;
fclose($fp); }
} }
} function getFreshContent() {
$html = "";
include "rssparser.php"; $newsSource = array(
$rss_parser = new RSSParser($CACHEFILE); array(
"title" => "RetryLife",
// read feed data from cache file "url" => "https://twitrss.me/twitter_user_to_rss/?user=RetryLife_music"
$feeddata = $rss_parser->getRawOutput(); ),
extract($feeddata['RSS']['CHANNEL'][0], EXTR_PREFIX_ALL, 'rss'); array(
"title" => "ewpratten",
// display leading image "url" => "https://twitrss.me/twitter_user_to_rss/?user=Ewpratten"
if(isset($rss_IMAGE[0]) && $rss_IMAGE[0]) { ),
extract($rss_IMAGE[0], EXTR_PREFIX_ALL, 'img'); array(
echo "<p><a title=\"{$img_TITLE}\" href=\"{$img_LINK}\"><img src=\"{$img_URL}\" alt=\"\"></a></p>\n"; "title" => "nsdesjardins",
} "url" => "https://twitrss.me/twitter_user_to_rss/?user=Nsdesjardins345"
)
// display feed title
echo "<h4><a title=\"",htmlspecialchars($rss_DESCRIPTION),"\" href=\"{$rss_LINK}\" target=\"_blank\">"; );
echo htmlspecialchars($rss_TITLE); function getFeed($url){
echo "</a></h4>\n"; $rss = simplexml_load_file($url);
$count = 0;
// display feed items $html .= '<ul>';
$count = 0; foreach($rss->channel->item as$item) {
foreach($rss_ITEM as $itemdata) { $count++;
echo "<p><b><a href=\"{$itemdata['LINK']}\" target=\"_blank\">"; if($count > 7){
echo htmlspecialchars(stripslashes($itemdata['TITLE'])); break;
echo "</a></b><br>\n"; }
echo htmlspecialchars(stripslashes($itemdata['DESCRIPTION'])),"<br>\n"; $html .= '<li><a href="'.htmlspecialchars($item->link).'">'.htmlspecialchars($item->title).'</a></li>';
echo "<i>",date($TIMEFORMAT, strtotime($itemdata['PUBDATE'])),"</i></p>\n\n"; }
if(++$count >= $NUMITEMS) break; $html .= '</ul>';
} return $html;
}
// display copyright information foreach($newsSource as $source) {
echo "<p><small>&copy; {",htmlspecialchars($rss_COPYRIGHT),"}</small></p>\n"; $html .= '<h2>'.$source["title"].'</h2>';
?> $html .= getFeed($source["url"]);
}
return $html;
}
print getContent();
?>
<?php <?php