summaryrefslogtreecommitdiffstats
path: root/usr/local/www/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'usr/local/www/widgets')
-rw-r--r--usr/local/www/widgets/widgets/rss.widget.php69
1 files changed, 56 insertions, 13 deletions
diff --git a/usr/local/www/widgets/widgets/rss.widget.php b/usr/local/www/widgets/widgets/rss.widget.php
index 2237f19..09dc309 100644
--- a/usr/local/www/widgets/widgets/rss.widget.php
+++ b/usr/local/www/widgets/widgets/rss.widget.php
@@ -31,14 +31,26 @@ require_once("pfsense-utils.inc");
require_once("functions.inc");
if($_POST) {
- $config['widgets']['rssfeed'] = $_POST['rssfeed'];
- config_write("Saved RSS Widget feed via Dashboard");
+ if($_POST['rssfeed'] <> "")
+ $config['widgets']['rssfeed'] = $_POST['rssfeed'];
+ if($_POST['rssmaxitems'] <> "")
+ $config['widgets']['rssmaxitems'] = $_POST['rssmaxitems'];
+ write_config("Saved RSS Widget feed via Dashboard");
Header("Location: /");
}
+// Use saved feed and max items
+if($config['widgets']['rssfeed'])
+ $rss_feed = $config['widgets']['rssfeed'];
+if($config['widgets']['rssmaxitems'])
+ $max_items = $config['widgets']['rssmaxitems'];
+
// Set a default feed if none exists
if(!$rss_feed)
$rss_feed = "http://blog.pfsense.org";
+
+if(!$max_items)
+ $max_items = 5;
?>
@@ -46,28 +58,59 @@ if(!$rss_feed)
<div id="rss-settings" name="rss-settings" class="widgetconfigdiv" style="display:none;">
</form>
- <form action="/widgets/widgets/rss.widget.php" method="post" name="iforma" enctype="multipart/form-data">
+ <form action="/widgets/widgets/rss.widget.php" method="post" name="iforma">
<input name="rssfeed" class="formfld unknown" id="rssfeed" size="30"></p>
+ Display number of items: <select name='rssmaxitems' id='rssmaxitems'>
+ <?php
+ for($x=1; $x<100; $x++) {
+ echo "<option value='{$x}'>$x</option>\n";
+ }
+ ?>
+ </select>
<input id="submita" name="submita" type="submit" class="formbtn" value="Save" /><br/>
</form>
</div>
<div id="rss-widgets" style="padding: 5px">
<?php
- require_once("simplexml/simplepie.inc");
- $feed = new SimplePie("{$rss_feed}");
+ require_once("simplepie/simplepie.inc");
+ function textLimit($string, $length, $replacer = '...')
+ {
+ if(strlen($string) > $length)
+ return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer;
+
+ return $string;
+ }
+ $feed = new SimplePie();
+ $feed->set_cache_location("/tmp/simplepie/");
+ $feed->set_feed_url("{$rss_feed}");
+ $feed->init();
+ $feed->set_output_encoding('latin-1');
$feed->handle_content_type();
-
- foreach($feed->get_items() as $item) {}
+ if(!is_dir("/tmp/simplepie")) {
+ mkdir("/tmp/simplepie");
+ mkdir("/tmp/simplepie/cache");
+ }
+ exec("chmod a+rw/tmp/simplepie/.");
+ exec("chmod a+rw/tmp/simplepie/cache/.");
+ $counter = 1;
+ foreach($feed->get_items() as $item) {
$feed = $item->get_feed();
-
- echo "<br>";
- echo "<a href='" . $item->get_permalink() . "'>" . $item->get_title() . "</a>";
- echo "<p>" . $item->get_content() . "</p>";
- echo "<p>Source: <a href='" . $item->get_permalink() . "'><img src='" . $feed->get_facicon() . "' alt='" . $feed->get_title() . "' title='" . $feed->get_title() . "' border='0' width='16' height='16'>";
+ $feed->strip_htmltags();
+ echo "<a target='_new' href='" . $item->get_permalink() . "'>" . $item->get_title() . "</a><br/>";
+ $content = $item->get_content();
+// if(strlen($content) > 140)
+// $content = substr($content,0,140) . " (cont)...";
+ $content = strip_tags($content);
+ echo textLimit($content, 140) . "<br/>";
+ echo "Source: <a target='_new' href='" . $item->get_permalink() . "'><img src='" . $feed->get_favicon() . "' alt='" . $feed->get_title() . "' title='" . $feed->get_title() . "' border='0' width='16' height='16'><br/>";
echo "<hr/>";
+ $counter++;
+ if($counter > $max_items)
+ break;
+ }
?>
-</div>
+</div>
<!-- needed to display the widget settings menu -->
<script language="javascript" type="text/javascript">
OpenPOWER on IntegriCloud