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:
authorLukas Winkler <github@lw1.at>2019-01-22 08:16:33 +0300
committerdiosmosis <diosmosis@users.noreply.github.com>2019-01-22 08:16:33 +0300
commitfb633f5f649df67caffa4a7f64a7002656b0332d (patch)
tree62288ec9fad80762bcd93ff35e3c10920a117700 /plugins/RssWidget
parentd24e794df6aa7e8ad31ed190de551a456df57f6f (diff)
improve RSS fetching (#13904)
* improve RSS fetching * add cache to rss fetching and remove "appeared first on" appendix * remove special handling of RSS description * Make sure links in rss content open in new tab and have noreferrer noopener.
Diffstat (limited to 'plugins/RssWidget')
-rw-r--r--plugins/RssWidget/RssRenderer.php75
-rw-r--r--plugins/RssWidget/Widgets/RssChangelog.php8
-rw-r--r--plugins/RssWidget/Widgets/RssPiwik.php8
-rw-r--r--plugins/RssWidget/stylesheets/rss.less3
4 files changed, 54 insertions, 40 deletions
diff --git a/plugins/RssWidget/RssRenderer.php b/plugins/RssWidget/RssRenderer.php
index a2df5c1d8d..b2d6a691a9 100644
--- a/plugins/RssWidget/RssRenderer.php
+++ b/plugins/RssWidget/RssRenderer.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\Plugins\RssWidget;
+use Piwik\Cache;
use Piwik\Http;
/**
@@ -19,10 +20,16 @@ class RssRenderer
protected $count = 3;
protected $showDescription = false;
protected $showContent = false;
+ /**
+ * @var Cache\Lazy
+ */
+ private $cache;
+
public function __construct($url)
{
$this->url = $url;
+ $this->cache = Cache::getLazyCache();
}
public function showDescription($bool)
@@ -42,42 +49,54 @@ class RssRenderer
public function get()
{
- try {
- $content = Http::fetchRemoteFile($this->url);
- $rss = simplexml_load_string($content);
- } catch (\Exception $e) {
- throw new \Exception("Error while importing feed: {$e->getMessage()}\n");
- }
+ $cacheId = 'RSS_' . md5($this->url);
- $output = '<div style="padding:10px 15px;"><ul class="rss">';
- $i = 0;
+ $output = $this->cache->fetch($cacheId);
- $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" rel="noreferrer noopener" href="' . htmlspecialchars($link, ENT_COMPAT, 'UTF-8') . '">' . $title . '</a>' .
- '<span class="rss-date">' . $date . '</span>';
- if ($this->showDescription) {
- $output .= '<div class="rss-description">' . $post->description . '</div>';
+ if (!$output) {
+ try {
+ $content = Http::fetchRemoteFile($this->url);
+ $rss = simplexml_load_string($content);
+ } catch (\Exception $e) {
+ throw new \Exception("Error while importing feed: {$e->getMessage()}\n");
}
- if ($this->showContent) {
- $output .= '<div class="rss-content">' . $post->content . '</div>';
+ $output = '<div style="padding:10px 15px;"><ul class="rss">';
+ $i = 0;
+
+ $items = array();
+ if (!empty($rss->channel->item)) {
+ $items = $rss->channel->item;
}
- $output .= '</li>';
+ 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" rel="noreferrer noopener" href="' . htmlspecialchars($link, ENT_COMPAT, 'UTF-8') . '">' . $title . '</a>' .
+ '<span class="rss-date">' . $date . '</span>';
+ if ($this->showDescription) {
+ $output .= '<div class="rss-description">' . $this->addTargetBlankAndNoReferrerToLinks($post->description) . '</div>';
+ }
+
+ if ($this->showContent) {
+ $output .= '<div class="rss-content">' . $this->addTargetBlankAndNoReferrerToLinks($post->content) . '</div>';
+ }
+ $output .= '</li>';
- if (++$i == $this->count) {
- break;
+ if (++$i == $this->count) {
+ break;
+ }
}
- }
- $output .= '</ul></div>';
+ $output .= '</ul></div>';
+ $this->cache->save($cacheId, $output, 60 * 60 * 24);
+ }
return $output;
}
+
+ private function addTargetBlankAndNoReferrerToLinks($content)
+ {
+ return str_replace('<a ', '<a target="_blank" rel="noreferrer noopener"', $content);
+ }
}
diff --git a/plugins/RssWidget/Widgets/RssChangelog.php b/plugins/RssWidget/Widgets/RssChangelog.php
index 6b5d13e81d..25a38d6b9d 100644
--- a/plugins/RssWidget/Widgets/RssChangelog.php
+++ b/plugins/RssWidget/Widgets/RssChangelog.php
@@ -41,13 +41,9 @@ class RssChangelog extends \Piwik\Widget\Widget
public function render()
{
try {
- return $this->getFeed('https://feeds.feedburner.com/PiwikReleases');
+ return $this->getFeed('https://matomo.org/changelog/feed');
} catch (\Exception $e) {
- try {
- return $this->getFeed('http://feeds.feedburner.com/PiwikReleases');
- } catch (\Exception $e) {
- return $this->error($e);
- }
+ return $this->error($e);
}
}
diff --git a/plugins/RssWidget/Widgets/RssPiwik.php b/plugins/RssWidget/Widgets/RssPiwik.php
index 68a1bf310c..fe09c632e2 100644
--- a/plugins/RssWidget/Widgets/RssPiwik.php
+++ b/plugins/RssWidget/Widgets/RssPiwik.php
@@ -39,13 +39,9 @@ class RssPiwik extends \Piwik\Widget\Widget
public function render()
{
try {
- return $this->getFeed('https://feeds.feedburner.com/Piwik');
+ return $this->getFeed('https://matomo.org/feed/');
} catch (\Exception $e) {
- try {
- return $this->getFeed('http://feeds.feedburner.com/Piwik');
- } catch (\Exception $e) {
- return $this->error($e);
- }
+ return $this->error($e);
}
}
diff --git a/plugins/RssWidget/stylesheets/rss.less b/plugins/RssWidget/stylesheets/rss.less
index 5becda42f3..e3bcdcd028 100644
--- a/plugins/RssWidget/stylesheets/rss.less
+++ b/plugins/RssWidget/stylesheets/rss.less
@@ -30,6 +30,9 @@
line-height: 1.5em;
font-size: 13px;
color: #333333;
+ .screen-reader-text {
+ display: none;
+ }
}
/* hide changing blog post title and date in UI test */