rendered paste body<?php
/*
Plugin Name: FirstRSS
Plugin URI: http://www.underjc.com/node/13
Description: FirstRSS is a simple RSS aggregator for posts. Insert "[rsspara:URL]" or "[rsslist:URL]" into the post for paragraph or list format respectively. Replace "URL" with the URL of the RSS feed starting with "http://".
Author: Chris Hatcher
Author URI: http://www.UnderJC.com
Version: 7.2.1
*/
function ujc_firstrss($content) {
// --- Initialize ---
require_once (ABSPATH . WPINC . '/rss-functions.php');
// --- Arrays ---
$find[] = "";
$replace[] = "";
// --- Search ---
// Find all "[rsslist:*]" and "[rsspara:*]"
preg_match_all('/\[rss(list|para):(\S+)\]/', $content, $matches, PREG_SET_ORDER);
// --- Display Credits? ---
$used = false;
// For each one you find...
foreach ($matches as $val) {
$url = html_entity_decode($val[2]);
// --- Syntax Display ---
if (strtoupper($url) == "URL") {
$disp = $val[0];
// --- Get RSS ---
} elseif ($rss = fetch_rss($url)) {
// --- Display Credits? ---
$used = true;
$disp = "\n<!-- FirstRSS -->\n";
// --- Paragraph format ---
if ($val[1] == 'para') {
// Image
if ($rss->image[url] != '') {
$title = $rss->image[title];
$link = htmlentities($rss->image[link]);
$url = $rss->image[url];
$disp .= "\t<a href='$link'><img src='$url' alt='$title' /></a><br />\n";
}
// Title, copyright, and description
$title = $rss->channel[title];
$copy = $rss->channel[copyright];
$link = htmlentities($rss->channel[link]);
$desc = $rss->channel[description];
$disp .= "\t<big><a href='$link'>$title</a></big><br />\n";
if ($copy != '') $disp .= "\t<small>$copy</small><br />\n";
if ($desc != '') $disp .= "\t$desc<br />\n";
$disp .= "\n\t<br />\n";
// For each item...
foreach($rss->items as $item) {
$title = $item[title];
$link = htmlentities($item[link]);
$desc = $item[description];
if ($title != '') $disp .= "\t<b><a href='$link'>$title</a></b>\n<br />";
if ($desc != '') $disp .= "\t$desc\n<br />";
}
// --- List format ---
} elseif ($val[1] == 'list') {
// Feed title, description, link, & copyright
$title = $rss->channel[title];
$link = htmlentities($rss->channel[link]);
$copy = $rss->channel[copyright];
$disp .= "\t<big><a href='$link'>$title</a></big><br />\n";
if ($copy != '') $disp .= "\t<small>$copy</small><br />\n";
$disp .= "\n\t<br />\n";
// Item title, description, & link
foreach($rss->items as $item) {
$title = $item[title];
$link = htmlentities($item[link]);
if ($title != '') $disp .= "\t<a href='$link'>$title</a><br />\n";
}
}
// --- Not Found ---
} else {
$disp = "\nFirstRSS ERROR: "$url" NOT FOUND!<br />\n";
}
// --- Replace ---
$find[] = $val[0];
$replace[] = $disp;
}
// --- Display Credits? ---
// Yes, you can remove this line. If I were you, I would. Any questions?
if ($used) $appendage .= "\n<p align='center'><small>Powered by <a href='http://www.underjc.com/firstrss/' "
. "title='UnderJC.com'>FirstRSS Plugin</a></small></p>\n";
// --- Return ---
return str_replace($find, $replace, $content) . $appendage;
}
// --- Filter ---
add_filter('the_content', 'ujc_firstrss');
?>