Преглед изворни кода

Support for media: tags (#1920)

* Support for media: tags

https://github.com/FreshRSS/FreshRSS/issues/944
E.g.  YouTube

* Fix for medium attribute

* Changelog 944

https://github.com/FreshRSS/FreshRSS/issues/944
https://github.com/FreshRSS/FreshRSS/pull/1920

* enclosure styling

* Compatibility old enclosure content
Alexandre Alapetite пре 7 година
родитељ
комит
7ab4a2609a
4 измењених фајлова са 47 додато и 12 уклоњено
  1. 3 1
      CHANGELOG.md
  2. 33 9
      app/Models/Feed.php
  3. 6 1
      lib/SimplePie/SimplePie.php
  4. 5 1
      p/themes/base-theme/template.css

+ 3 - 1
CHANGELOG.md

@@ -1,7 +1,9 @@
 # FreshRSS changelog
 
-## 2018-0X-XX FreshRSS 1.11.1-dev
+## 2018-06-XX FreshRSS 1.11.1-dev
 
+* Features
+	* Better support of `media:` tags such as thumbnails and descriptions (e.g. for YouTube) [#944](https://github.com/FreshRSS/FreshRSS/issues/944)
 * Bug fixing
 	* Fix regression in fetching full articles content [#1917](https://github.com/FreshRSS/FreshRSS/issues/1917)
 	* Updated sharing to Mastodon [#1904](https://github.com/FreshRSS/FreshRSS/issues/1904)

+ 33 - 9
app/Models/Feed.php

@@ -359,21 +359,45 @@ class FreshRSS_Feed extends Minz_Model {
 			foreach ($item->get_enclosures() as $enclosure) {
 				$elink = $enclosure->get_link();
 				if ($elink != '' && empty($elinks[$elink])) {
-					$elinks[$elink] = '1';
+					$content .= '<div class="enclosure">';
+
+					if ($enclosure->get_title() != '') {
+						$content .= '<p class="enclosure-title">' . $enclosure->get_title() . '</p>';
+					}
+
+					$enclosureContent = '';
+					$elinks[$elink] = true;
 					$mime = strtolower($enclosure->get_type());
-					if (strpos($mime, 'image/') === 0) {
-						$content .= '<p class="enclosure"><img src="' . $elink . '" alt="" /></p>';
-					} elseif (strpos($mime, 'audio/') === 0) {
-						$content .= '<p class="enclosure"><audio preload="none" src="' . $elink
+					$medium = strtolower($enclosure->get_medium());
+					if ($medium === 'image' || strpos($mime, 'image/') === 0) {
+						$enclosureContent .= '<p class="enclosure-content"><img src="' . $elink . '" alt="" /></p>';
+					} elseif ($medium === 'audio' || strpos($mime, 'audio/') === 0) {
+						$enclosureContent .= '<p class="enclosure-content"><audio preload="none" src="' . $elink
 							. '" controls="controls"></audio> <a download="" href="' . $elink . '">💾</a></p>';
-					} elseif (strpos($mime, 'video/') === 0) {
-						$content .= '<p class="enclosure"><video preload="none" src="' . $elink
+					} elseif ($medium === 'video' || strpos($mime, 'video/') === 0) {
+						$enclosureContent .= '<p class="enclosure-content"><video preload="none" src="' . $elink
 							. '" controls="controls"></video> <a download="" href="' . $elink . '">💾</a></p>';
-					} elseif (strpos($mime, 'application/') === 0 || strpos($mime, 'text/') === 0) {
-						$content .= '<p class="enclosure"><a download="" href="' . $elink . '">💾</a></p>';
+					} elseif ($medium != '' || strpos($mime, 'application/') === 0 || strpos($mime, 'text/') === 0) {
+						$enclosureContent .= '<p class="enclosure-content"><a download="" href="' . $elink . '">💾</a></p>';
 					} else {
 						unset($elinks[$elink]);
 					}
+
+					$thumbnailContent = '';
+					foreach ($enclosure->get_thumbnails() as $thumbnail) {
+						if (empty($elinks[$thumbnail])) {
+							$elinks[$thumbnail] = true;
+							$thumbnailContent .= '<p><img class="enclosure-thumbnail" src="' . $thumbnail . '" alt="" /></p>';
+						}
+					}
+
+					$content .= $thumbnailContent;
+					$content .= $enclosureContent;
+
+					if ($enclosure->get_description() != '') {
+						$content .= '<pre class="enclosure-description">' . $enclosure->get_description() . '</pre>';
+					}
+					$content .= "</div>\n";
 				}
 			}
 

+ 6 - 1
lib/SimplePie/SimplePie.php

@@ -1322,7 +1322,12 @@ class SimplePie
 
 	function cleanMd5($rss)
 	{
-		return md5(preg_replace(array('#<(lastBuildDate|pubDate|updated|feedDate|dc:date|slash:comments)>[^<]+</\\1>#', '#<!--.+?-->#s'), '', $rss));
+		return md5(preg_replace(array(
+			'#<(lastBuildDate|pubDate|updated|feedDate|dc:date|slash:comments)>[^<]+</\\1>#',
+			'#<(media:starRating|media:statistics) [^/<>]+/>#',
+			'#<!--.+?-->#s',
+			), '', $rss));
+		
 	}
 
 	/**

+ 5 - 1
p/themes/base-theme/template.css

@@ -832,11 +832,15 @@ input:checked + .slide-container .properties {
 	display: none;
 }
 
-.enclosure > [download] {
+.enclosure [download] {
 	font-size: xx-large;
 	margin-left: .8em;
 }
 
+pre.enclosure-description {
+	white-space: pre-line;
+}
+
 /*=== MOBILE */
 /*===========*/
 @media(max-width: 840px) {