aboutsummaryrefslogtreecommitdiff
path: root/views/default/widgets/feed_reader
diff options
context:
space:
mode:
Diffstat (limited to 'views/default/widgets/feed_reader')
-rw-r--r--views/default/widgets/feed_reader/content.php81
-rw-r--r--views/default/widgets/feed_reader/edit.php119
-rw-r--r--views/default/widgets/feed_reader/view.php82
3 files changed, 137 insertions, 145 deletions
diff --git a/views/default/widgets/feed_reader/content.php b/views/default/widgets/feed_reader/content.php
new file mode 100644
index 000000000..f13b00fe7
--- /dev/null
+++ b/views/default/widgets/feed_reader/content.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * View a feed in a widget
+ */
+
+elgg_load_library('simplepie');
+
+$allowed_tags = '<a><p><br><b><i><em><del><pre><strong><ul><ol><li><img>';
+$feed_url = $vars['entity']->feed_url;
+if ($feed_url) {
+
+ // get widget settings
+ $excerpt = $vars['entity']->excerpt;
+ $num_items = $vars['entity']->num_items;
+ $post_date = $vars['entity']->post_date;
+
+ $cache_location = elgg_get_data_path() . '/simplepie_cache/';
+ if (!file_exists($cache_location)) {
+ mkdir($cache_location, 0777);
+ }
+
+ $feed = new SimplePie($feed_url, $cache_location);
+
+ // doubles timeout if going through a proxy
+ //$feed->set_timeout(20);
+
+ // only display errors to profile owner
+ $num_posts_in_feed = $feed->get_item_quantity();
+ if (!$num_posts_in_feed) {
+ if (elgg_get_logged_in_user_guid() == elgg_get_page_owner_guid()) {
+ echo '<p>' . elgg_echo('simplepie:notfind') . '</p>';
+ }
+ }
+
+ // don't display more feed items than user requested
+ if ($num_items > $num_posts_in_feed) {
+ $num_items = $num_posts_in_feed;
+ }
+
+ $feed_link = elgg_view('output/url', array(
+ 'href' => $feed->get_permalink(),
+ 'text' => $feed->get_title(),
+ ));
+
+ // need to center
+ echo "<h2 class=\"simplepie-heading\">$feed_link</h2>";
+ echo '<ul class="simplepie-list">';
+ foreach ($feed->get_items(0, $num_items) as $item) {
+ $item_link = elgg_view('output/url', array(
+ 'href' => $item->get_permalink(),
+ 'text' => $item->get_title(),
+ ));
+
+ if ($excerpt) {
+ $text = strip_tags($item->get_description(true), $allowed_tags);
+ $excerpt = $text;
+ }
+
+ if ($post_date) {
+ $item_date_label = elgg_echo('simplepie:postedon');
+ $item_date = $item->get_date('j F Y | g:i a');
+ $post_date = "$item_date_label $item_date";
+ }
+
+ echo <<<HTML
+<li class="mbm">
+ <h4 class="mbs">$item_link</h4>
+ <div class="mbs clearfix">$excerpt</div>
+ <p class="elgg-subtext">$post_date</p>
+</li>
+HTML;
+
+ }
+ echo "</ul>";
+
+} else {
+ // display message only to owner
+ if (elgg_get_logged_in_user_guid() == elgg_get_page_owner_guid()) {
+ echo '<p>' . elgg_echo('simplepie:notset') . '</p>';
+ }
+}
diff --git a/views/default/widgets/feed_reader/edit.php b/views/default/widgets/feed_reader/edit.php
index a721f0e8a..83218dcbb 100644
--- a/views/default/widgets/feed_reader/edit.php
+++ b/views/default/widgets/feed_reader/edit.php
@@ -1,69 +1,62 @@
<?php
- $num_items = $vars['entity']->num_items;
- if (!isset($num_items)) {
- $num_items = 10;
- }
+/**
+ * Simplepie feed reader widget settings
+ */
- $excerpt = $vars['entity']->excerpt;
- if (!isset($excerpt)) {
- $excerpt = 0;
- }
-
- $post_date = $vars['entity']->post_date;
- if (!isset($post_date)) {
- $post_date = 0;
- }
-?>
-
-<p>
- <?php echo elgg_echo("simplepie:feed_url"); ?>
- <input type="text" onclick="this.select();" name="params[feed_url]" value="<?php echo htmlentities($vars['entity']->feed_url); ?>" />
-</p>
-
-<p>
-<?php echo elgg_echo('simplepie:num_items'); ?>
-
-<?php
- echo elgg_view('input/pulldown', array(
- 'internalname' => 'params[num_items]',
- 'options_values' => array( '3' => '3',
- '5' => '5',
- '8' => '8',
- '10' => '10',
- '12' => '12',
- '15' => '15',
- '20' => '20',
- ),
- 'value' => $num_items
- ));
-?>
-</p>
+// set default value
+if (!isset($vars['entity']->num_items)) {
+ $vars['entity']->num_items = 10;
+}
-<p>
-<?php
-// used a hidden input field so that something is always sent unlike a checkbox
-echo elgg_view('input/hidden', array('internalname' => 'params[excerpt]',
- 'js' => 'id="params[excerpt]"',
- 'value' => $excerpt ));
-echo "<input class='input-checkboxes' type='checkbox' value='' name='excerptcheckbox' onclick=\"document.getElementById('params[excerpt]').value = 1 - document.getElementById('params[excerpt]').value;\" ";
-if ($excerpt) {
- echo "checked='yes'";
+if (!isset($vars['entity']->excerpt)) {
+ $vars['entity']->excerpt = false;
}
-echo " />";
-echo ' ' . elgg_echo('simplepie:excerpt');
-?>
-</p>
-<p>
-<?php
-echo elgg_view('input/hidden', array('internalname' => 'params[post_date]',
- 'js' => 'id="params[post_date]"',
- 'value' => $post_date ));
-echo "<input class='input-checkboxes' type='checkbox' value='' name='post_datecheckbox' onclick=\"document.getElementById('params[post_date]').value = 1 - document.getElementById('params[post_date]').value;\" ";
-if ($post_date) {
- echo "checked='yes'";
+if (!isset($vars['entity']->post_date)) {
+ $vars['entity']->post_date = false;
}
-echo " />";
-echo ' ' . elgg_echo('simplepie:post_date');
-?>
-</p>
+
+$url_label = elgg_echo("simplepie:feed_url");
+$url_textbox = elgg_view('input/text', array(
+ 'name' => 'params[feed_url]',
+ 'value' => $vars['entity']->feed_url,
+ 'onclick' => 'this.select();',
+));
+
+$num_items_label = elgg_echo('simplepie:num_items');
+$num_items_select = elgg_view('input/dropdown', array(
+ 'name' => 'params[num_items]',
+ 'value' => $vars['entity']->num_items,
+ 'options' => array(3, 5, 8, 10, 12, 15, 20),
+));
+
+$excerpt_label = elgg_echo('simplepie:excerpt');
+$excerpt_checkbox = elgg_view('input/checkbox', array(
+ 'name' => 'params[excerpt]',
+ 'value' => true,
+ 'checked' => $vars['entity']->excerpt ? 'checked' : '',
+));
+
+$post_date_label = elgg_echo('simplepie:post_date');
+$post_date_checkbox = elgg_view('input/checkbox', array(
+ 'name' => 'params[post_date]',
+ 'value' => true,
+ 'checked' => $vars['entity']->post_date ? 'checked' : '',
+));
+
+echo <<<HTML
+<div>
+ $url_label
+ $url_textbox
+</div>
+<div>
+ $num_items_label
+ $num_items_select
+</div>
+<div>
+ $excerpt_checkbox $excerpt_label
+</div>
+<div>
+ $post_date_checkbox $post_date_label
+</div>
+HTML;
diff --git a/views/default/widgets/feed_reader/view.php b/views/default/widgets/feed_reader/view.php
deleted file mode 100644
index 329b2fb98..000000000
--- a/views/default/widgets/feed_reader/view.php
+++ /dev/null
@@ -1,82 +0,0 @@
-<div class="contentWrapper">
-<?php
-global $CONFIG;
-
-if (!class_exists('SimplePie')) {
- require_once $CONFIG->pluginspath . '/simplepie/simplepie.inc';
-}
-
-$allow_tags = '<a><p><br><b><i><em><del><pre><strong><ul><ol><li>';
-$feed_url = $vars['entity']->feed_url;
-if ($feed_url) {
-
- // get widget settings
- $excerpt = $vars['entity']->excerpt;
- $num_items = $vars['entity']->num_items;
- $post_date = $vars['entity']->post_date;
-
- $cache_location = $CONFIG->dataroot . '/simplepie_cache/';
- if (!file_exists($cache_location)) {
- mkdir($cache_location, 0777);
- }
-
- $feed = new SimplePie($feed_url, $cache_location);
-
- // doubles timeout if going through a proxy
- //$feed->set_timeout(20);
-
- $num_posts_in_feed = $feed->get_item_quantity();
-
- // only display errors to profile owner
- if (get_loggedin_userid() == page_owner()) {
- if (!$num_posts_in_feed) {
- echo '<p>' . elgg_echo('simplepie:notfind') . '</p>';
- }
- }
-?>
-<div class="simplepie_blog_title">
- <h2><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h2>
-</div>
-<?php
- // don't display more feed items than user requested
- if ($num_items > $num_posts_in_feed) {
- $num_items = $num_posts_in_feed;
- }
-
- foreach ($feed->get_items(0, $num_items) as $item):
-?>
- <div class="simplepie_item">
- <div class="simplepie_title">
- <h4><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h4>
- </div>
-<?php
- if ($excerpt) {
-?>
- <div class="simplepie_excerpt">
- <?php echo strip_tags($item->get_description(true), $allow_tags); ?>
- </div>
-<?php
- }
-
- if ($post_date) {
-?>
- <div class="simplepie_date">
- <?php echo elgg_echo('simplepie:postedon'); ?>
- <?php echo $item->get_date('j F Y | g:i a'); ?>
- </div>
-<?php
- }
-?>
- </div>
-
- <?php endforeach; ?>
-
-<?php
-} else {
- // display message only to owner
- if (get_loggedin_userid() == page_owner()) {
- echo '<p>' . elgg_echo('simplepie:notset') . '</p>';
- }
-}
-?>
-</div>