diff options
author | Matthieu Aubry <mattab@users.noreply.github.com> | 2016-09-22 12:47:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-22 12:47:00 +0300 |
commit | d7bb13ca855839084de7527c5ccc66b317489d75 (patch) | |
tree | 9bb2e028dca49973d4341b6ff3ac304598773991 /plugins/RssWidget/RssRenderer.php | |
parent | a251989030ae17729f0c200e9c404fbec09dec1f (diff) |
Renamed plugin ExampleRssWidget -> RssWidget (#10528)
* Renamed plugin ExampleRssWidget -> RssWidget
* Activate file on upgrade to 3.0.0-b1
* Fix system test
Diffstat (limited to 'plugins/RssWidget/RssRenderer.php')
-rw-r--r-- | plugins/RssWidget/RssRenderer.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/plugins/RssWidget/RssRenderer.php b/plugins/RssWidget/RssRenderer.php new file mode 100644 index 0000000000..51c831cd4c --- /dev/null +++ b/plugins/RssWidget/RssRenderer.php @@ -0,0 +1,84 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ + +namespace Piwik\Plugins\RssWidget; +use Piwik\Http; + +/** + * + */ +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 { + $content = Http::fetchRemoteFile($this->url); + $rss = simplexml_load_string($content); + } catch (\Exception $e) { + echo "Error while importing feed: {$e->getMessage()}\n"; + exit; + } + + $output = '<div style="padding:10px 15px;"><ul class="rss">'; + $i = 0; + + $items = array(); + if (!empty($rss->channel->item)) { + $items = $rss->channel->item; + } + foreach ($items 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; + } +} |