aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcapo <capo@riseup.net>2013-12-16 00:12:26 +0100
committercapo <capo@riseup.net>2013-12-16 00:12:26 +0100
commite5dd9906d16d97aed7ba3511b7e1132bd4da3761 (patch)
tree79d6ff965e20c54fb498433fa1435bf92f9e64c8
parent408a27487d24938a3fa86c69a567b8666877347b (diff)
downloadelgg-e5dd9906d16d97aed7ba3511b7e1132bd4da3761.tar.gz
elgg-e5dd9906d16d97aed7ba3511b7e1132bd4da3761.tar.bz2
Added feature to be able to use simplepie rss module in the groups
-rw-r--r--actions/simplepie/group_module.php8
-rw-r--r--languages/es.php16
-rw-r--r--start.php7
-rw-r--r--views/default/forms/simplepie/group_module.php35
-rw-r--r--views/default/simplepie/group_module.php113
-rw-r--r--views/default/widgets/feed_reader/content.php.save81
6 files changed, 260 insertions, 0 deletions
diff --git a/actions/simplepie/group_module.php b/actions/simplepie/group_module.php
new file mode 100644
index 0000000..93fe353
--- /dev/null
+++ b/actions/simplepie/group_module.php
@@ -0,0 +1,8 @@
+<?php
+
+$group = get_entity(get_input('group_guid'));
+$feed_url = get_input('feed_url');
+
+if ($group && $group->canEdit()) {
+ $group->feed_url = $feed_url;
+}
diff --git a/languages/es.php b/languages/es.php
new file mode 100644
index 0000000..51b53e9
--- /dev/null
+++ b/languages/es.php
@@ -0,0 +1,16 @@
+<?php
+
+$spanish = array(
+ 'simplepie:widget' => 'Enlace RSS',
+ 'simplepie:description' => 'Agregar un blog externo',
+ 'simplepie:notset' => 'Enlace RSS no configurado',
+ 'simplepie:notfind' => 'no se encontro el feed. Revisa el feed url.',
+ 'simplepie:feed_url' => 'Feed URL',
+ 'simplepie:num_items' => 'Numero de items',
+ 'simplepie:excerpt' => 'Incluir contenido',
+ 'simplepie:post_date' => 'Incluir fecha del post',
+ 'simplepie:postedon' => 'Posted on',
+);
+
+add_translation("en", $english);
+
diff --git a/start.php b/start.php
index 20adc75..26c2e50 100644
--- a/start.php
+++ b/start.php
@@ -20,4 +20,11 @@ function simplepie_init() {
$lib = elgg_get_plugins_path() . 'simplepie/vendors/simplepie.inc';
elgg_register_library('simplepie', $lib);
+
+ // Add group option
+ add_group_tool_option('rss', elgg_echo('simplepie:enablerss'), false);
+ elgg_extend_view('groups/tool_latest', 'simplepie/group_module');
+
+ elgg_register_action('simplepie/group_module', elgg_get_plugins_path() . 'simplepie/actions/simplepie/group_module.php');
}
+
diff --git a/views/default/forms/simplepie/group_module.php b/views/default/forms/simplepie/group_module.php
new file mode 100644
index 0000000..a7c1f68
--- /dev/null
+++ b/views/default/forms/simplepie/group_module.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Simplepie feed reader widget settings
+ */
+
+// set default value
+
+$url_label = elgg_echo("simplepie:feed_url");
+$url_textbox = elgg_view('input/text', array(
+ 'name' => 'feed_url',
+ 'value' => $vars['entity']->feed_url,
+));
+
+$group_field = elgg_view('input/hidden', array(
+ 'name' => 'group_guid',
+ 'value' => $vars['entity']->guid,
+));
+
+$save_button = elgg_view('input/submit', array(
+ 'value' => elgg_echo('save'),
+));
+
+
+
+
+echo <<<HTML
+<div>
+ $url_label
+ $url_textbox
+ $group_field
+</div>
+<div>
+ $save_button
+</div>
+HTML;
diff --git a/views/default/simplepie/group_module.php b/views/default/simplepie/group_module.php
new file mode 100644
index 0000000..7d0a7bc
--- /dev/null
+++ b/views/default/simplepie/group_module.php
@@ -0,0 +1,113 @@
+<?php
+/**
+ * Group simplepie:rss module
+ */
+elgg_load_library('simplepie');
+
+$group = elgg_get_page_owner_entity();
+
+if ($group->rss_enable != "yes") {
+ return true;
+}
+
+elgg_push_context('widgets');
+
+$allowed_tags = '<a><p><br><b><i><em><del><pre><strong><ul><ol><li><img>';
+$feed_url = $group->feed_url;
+$content = '';
+
+if ($group->canEdit()) {
+ $content .= elgg_view_form("simplepie/group_module", array(
+ 'id' => 'simplepie-form',
+ 'class' => $feed_url ? 'hidden' : '',
+ ), $vars);
+}
+
+if ($feed_url) {
+
+ // get widget settings
+ $excerpt = true;
+ $post_date = true;
+ $num_items = 7;
+
+ $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()) {
+ $content .= '<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
+ $content .= "<h2 class=\"simplepie-heading\">$feed_link</h2>";
+ $content .= '<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 = elgg_get_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";
+ }
+
+ $content .= <<<HTML
+<li class="mbm elgg-item">
+ <h4 class="mbs">$item_link</h4>
+ <p class="elgg-subtext">$post_date</p>
+ <div class="elgg-content">$excerpt</div>
+</li>
+HTML;
+
+ }
+ $content .= "</ul>";
+
+}
+
+
+
+elgg_pop_context();
+
+if (!$content) {
+ $content = '<p>' . elgg_echo('simplepie:none') . '</p>';
+}
+
+$edit = elgg_view('output/url', array(
+ 'href' => '#simplepie-form',
+ 'text' => elgg_echo('edit'),
+ 'rel' => 'toggle'
+));
+
+echo elgg_view('groups/profile/module', array(
+ 'title' => elgg_echo('RSS Group'),
+ 'content' => $content,
+ 'all_link' => $edit,
+));
+
diff --git a/views/default/widgets/feed_reader/content.php.save b/views/default/widgets/feed_reader/content.php.save
new file mode 100644
index 0000000..f13b00f
--- /dev/null
+++ b/views/default/widgets/feed_reader/content.php.save
@@ -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>';
+ }
+}