Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/ExampleRssWidget/RssRenderer.php')
-rw-r--r--plugins/ExampleRssWidget/RssRenderer.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/plugins/ExampleRssWidget/RssRenderer.php b/plugins/ExampleRssWidget/RssRenderer.php
new file mode 100644
index 0000000000..1b7baa1ba2
--- /dev/null
+++ b/plugins/ExampleRssWidget/RssRenderer.php
@@ -0,0 +1,84 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ * @category Piwik_Plugins
+ * @package ExampleRssWidget
+ */
+
+namespace Piwik\Plugins\ExampleRssWidget;
+
+use Zend_Feed;
+use Zend_Feed_Exception;
+
+/**
+ *
+ * @package ExampleRssWidget
+ */
+class RssRenderer
+{
+ protected $url = null;
+ protected $count = 3;
+ protected $showDescription = false;
+ protected $showContent = false;
+
+ public function __construct($url)
+ {
+ $this->url = $url;
+ }
+
+ public function showDescription($bool)
+ {
+ $this->showDescription = $bool;
+ }
+
+ public function showContent($bool)
+ {
+ $this->showContent = $bool;
+ }
+
+ public function setCountPosts($count)
+ {
+ $this->count = $count;
+ }
+
+ public function get()
+ {
+ try {
+ $rss = Zend_Feed::import($this->url);
+ } catch (Zend_Feed_Exception $e) {
+ echo "Error while importing feed: {$e->getMessage()}\n";
+ exit;
+ }
+
+ $output = '<div style="padding:10px 15px;"><ul class="rss">';
+ $i = 0;
+
+ foreach ($rss as $post) {
+ $title = $post->title();
+ $date = @strftime("%B %e, %Y", strtotime($post->pubDate()));
+ $link = $post->link();
+
+ $output .= '<li><a class="rss-title" title="" target="_blank" href="?module=Proxy&action=redirect&url=' . $link . '">' . $title . '</a>' .
+ '<span class="rss-date">' . $date . '</span>';
+ if ($this->showDescription) {
+ $output .= '<div class="rss-description">' . $post->description() . '</div>';
+ }
+
+ if ($this->showContent) {
+ $output .= '<div class="rss-content">' . $post->content() . '</div>';
+ }
+ $output .= '</li>';
+
+ if (++$i == $this->count) {
+ break;
+ }
+ }
+
+ $output .= '</ul></div>';
+ return $output;
+ }
+}