[44] | 1 | <?php
|
---|
| 2 | /*
|
---|
| 3 | Plugin Name: FirstRSS
|
---|
| 4 | Plugin URI: http://www.underjc.com/2007/10/firstrss-plugin-for-wordpress.html
|
---|
| 5 | 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://".
|
---|
| 6 | Author: Chris Hatcher
|
---|
| 7 | Author URI: http://www.UnderJC.com
|
---|
| 8 | Version: 7.10.18
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | function ujc_firstrss($content) {
|
---|
| 12 |
|
---|
| 13 | // --- Initialize ---
|
---|
| 14 | require_once (ABSPATH . WPINC . '/rss-functions.php');
|
---|
| 15 |
|
---|
| 16 | // --- Arrays ---
|
---|
| 17 | $find[] = "";
|
---|
| 18 | $replace[] = "";
|
---|
| 19 |
|
---|
| 20 | // --- Search ---
|
---|
| 21 | // Find all "[rsslist:*]" and "[rsspara:*]"
|
---|
| 22 | preg_match_all('/\[rss(list|para):(\S+)\]/', $content, $matches, PREG_SET_ORDER);
|
---|
| 23 |
|
---|
| 24 | // --- Display Credits? ---
|
---|
| 25 | $used = false;
|
---|
| 26 |
|
---|
| 27 | // For each one you find...
|
---|
| 28 | foreach ($matches as $val) {
|
---|
| 29 | $url = html_entity_decode($val[2]);
|
---|
| 30 |
|
---|
| 31 | // --- Syntax Display ---
|
---|
| 32 | if (strtoupper($url) == "URL") {
|
---|
| 33 | $disp = $val[0];
|
---|
| 34 |
|
---|
| 35 | // --- Get RSS ---
|
---|
| 36 | } elseif ($rss = fetch_rss($url)) {
|
---|
| 37 |
|
---|
| 38 | // --- Display Credits? ---
|
---|
| 39 | $used = true;
|
---|
| 40 | $disp = "\n<!-- FirstRSS -->\n";
|
---|
| 41 |
|
---|
| 42 | // --- Paragraph format ---
|
---|
| 43 | if ($val[1] == 'para') {
|
---|
| 44 |
|
---|
| 45 | // Image
|
---|
| 46 | if ($rss->image[url] != '') {
|
---|
| 47 | $title = $rss->image[title];
|
---|
| 48 | $link = htmlentities($rss->image[link]);
|
---|
| 49 | $url = $rss->image[url];
|
---|
| 50 | $disp .= "\t<a href='$link'><img src='$url' alt='$title' /></a><br />\n";
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | // Title, copyright, and description
|
---|
| 54 |
|
---|
| 55 | $title = $rss->channel[title];
|
---|
| 56 | $copy = $rss->channel[copyright];
|
---|
| 57 | $link = htmlentities($rss->channel[link]);
|
---|
| 58 | $desc = $rss->channel[description];
|
---|
| 59 |
|
---|
| 60 | $disp .= "\t<big><a href='$link'>$title</a></big><br />\n";
|
---|
| 61 | if ($copy != '') $disp .= "\t<small>$copy</small><br />\n";
|
---|
| 62 | if ($desc != '') $disp .= "\t$desc<br />\n";
|
---|
| 63 | $disp .= "\n\t<br />\n";
|
---|
| 64 |
|
---|
| 65 | // For each item...
|
---|
| 66 | foreach($rss->items as $item) {
|
---|
| 67 | $title = $item[title];
|
---|
| 68 | $link = htmlentities($item[link]);
|
---|
| 69 | $desc = $item[description];
|
---|
| 70 |
|
---|
| 71 | if ($title != '') $disp .= "\t<b><a href='$link'>$title</a></b>\n<br />";
|
---|
| 72 | if ($desc != '') $disp .= "\t$desc\n<br />";
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | // --- List format ---
|
---|
| 76 | } elseif ($val[1] == 'list') {
|
---|
| 77 |
|
---|
| 78 | // Feed title, description, link, & copyright
|
---|
| 79 | $title = $rss->channel[title];
|
---|
| 80 | $link = htmlentities($rss->channel[link]);
|
---|
| 81 | $copy = $rss->channel[copyright];
|
---|
| 82 |
|
---|
| 83 | $disp .= "\t<big><a href='$link'>$title</a></big><br />\n";
|
---|
| 84 | if ($copy != '') $disp .= "\t<small>$copy</small><br />\n";
|
---|
| 85 | $disp .= "\n\t<br />\n";
|
---|
| 86 |
|
---|
| 87 | // Item title, description, & link
|
---|
| 88 | foreach($rss->items as $item) {
|
---|
| 89 | $title = $item[title];
|
---|
| 90 | $link = htmlentities($item[link]);
|
---|
| 91 |
|
---|
| 92 | if ($title != '') $disp .= "\t<a href='$link'>$title</a><br />\n";
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | // --- Not Found ---
|
---|
| 97 | } else {
|
---|
| 98 | $disp = "\nFirstRSS ERROR: "$url" NOT FOUND!<br />\n";
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | // --- Replace ---
|
---|
| 102 | $find = $val[0];
|
---|
| 103 | $replace = $disp;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | // --- Display Credits? ---
|
---|
| 107 | // Yes, you can remove this line. If I were you, I would. Any questions?
|
---|
| 108 | if ($used) $appendage .= "\n<p align='center'><small>Powered by <a href='http://www.underjc.com/2007/10/firstrss-plugin-for-wordpress.html' "
|
---|
| 109 | . "title='UnderJC.com'>FirstRSS Plugin</a></small></p>\n";
|
---|
| 110 |
|
---|
| 111 | // --- Return ---
|
---|
| 112 | return str_replace($find, $replace, $content) . $appendage;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | // --- Filter ---
|
---|
| 116 | add_filter('the_content', 'ujc_firstrss');
|
---|
| 117 |
|
---|
| 118 | ?>
|
---|