Browse Source

af_readability: check if sanitized content has anything before replacing
original excerpt
af_readability, af_redditimgur: check php version before using Readability

Andrew Dolgov 5 years ago
parent
commit
6d95e53524
2 changed files with 18 additions and 63 deletions
  1. 12 1
      plugins/af_readability/init.php
  2. 6 62
      plugins/af_redditimgur/init.php

+ 12 - 1
plugins/af_readability/init.php

@@ -29,6 +29,10 @@ class Af_Readability extends Plugin {
 	{
 		$this->host = $host;
 
+		if (version_compare(PHP_VERSION, '5.6.0', '<')) {
+			return;
+		}
+
 		$host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
 		$host->add_hook($host::HOOK_PREFS_TAB, $this);
 		$host->add_hook($host::HOOK_PREFS_EDIT_FEED, $this);
@@ -42,6 +46,10 @@ class Af_Readability extends Plugin {
 
 		print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Readability settings (af_readability)')."\">";
 
+		if (version_compare(PHP_VERSION, '5.6.0', '<')) {
+			print_error("This plugin requires PHP version 5.6.");
+		}
+
 		print_notice("Enable the plugin for specific feeds in the feed editor.");
 
 		print "<form dojoType=\"dijit.form.Form\">";
@@ -201,7 +209,10 @@ class Af_Readability extends Plugin {
 
 		$extracted_content = $this->extract_content($article["link"]);
 
-		if ($extracted_content) {
+		# let's see if there's anything of value in there
+		$content_test = trim(strip_tags(sanitize($extracted_content)));
+
+		if ($content_test) {
 			$article["content"] = $extracted_content;
 		}
 

+ 6 - 62
plugins/af_redditimgur/init.php

@@ -32,6 +32,10 @@ class Af_RedditImgur extends Plugin {
 		$enable_readability = $this->host->get($this, "enable_readability");
 		$enable_content_dupcheck = $this->host->get($this, "enable_content_dupcheck");
 
+		if (version_compare(PHP_VERSION, '5.6.0', '<')) {
+			print_error("Readability requires PHP version 5.6.");
+		}
+
 		print "<form dojoType=\"dijit.form.Form\">";
 
 		print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
@@ -52,9 +56,6 @@ class Af_RedditImgur extends Plugin {
 		print_hidden("method", "save");
 		print_hidden("plugin", "af_redditimgur");
 
-		print "<p>" . __("Uses Readability (full-text-rss) implementation by <a target='_blank' href='https://bitbucket.org/fivefilters/'>FiveFilters.org</a>");
-		print "<p/>";
-
 		print_checkbox("enable_readability", $enable_readability);
 		print "&nbsp;<label for=\"enable_readability\">" . __("Extract missing content using Readability") . "</label>";
 
@@ -287,64 +288,6 @@ class Af_RedditImgur extends Plugin {
 					$found = true;
 				}
 
-				// linked albums & pages
-
-				/*if (!$found && preg_match("/^https?:\/\/(m\.)?imgur.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches) ||
-					preg_match("/^https?:\/\/(m\.)?imgur.com\/(a|album|gallery)\/[^\.]+$/", $entry->getAttribute("href"), $matches)) {
-
-					_debug("Handling as an imgur page/album/gallery", $debug);
-
-					$album_content = fetch_file_contents($entry->getAttribute("href"),
-						false, false, false, false, 10);
-
-					if ($album_content) {
-						$adoc = new DOMDocument();
-
-						if (@$adoc->loadHTML($album_content)) {
-							$axpath = new DOMXPath($adoc);
-
-							$aentries = $axpath->query("(//div[@class='post-image']/img[@src] | //a[@class='zoom']/img[@src] | //div[@class='video-elements']/source)");
-							$urls = [];
-
-							foreach ($aentries as $aentry) {
-
-								$url = $aentry->getAttribute("src");
-
-								if (!in_array($url, $urls)) {
-
-									if ($aentry->tagName == "img") {
-
-										$img = $doc->createElement('img');
-										$img->setAttribute("src", $url);
-										$entry->parentNode->insertBefore($doc->createElement('br'), $entry);
-
-										$br = $doc->createElement('br');
-
-										$entry->parentNode->insertBefore($img, $entry);
-										$entry->parentNode->insertBefore($br, $entry);
-									} else if ($aentry->tagName == "source") {
-
-										if (strpos($url, "imgur.com") !== FALSE)
-											$poster_url = str_replace(".mp4", "h.jpg", $url);
-										else
-											$poster_url = "";
-
-										$this->handle_as_video($doc, $entry, $url, $poster_url);
-
-									}
-
-									array_push($urls, $url);
-
-									$found = true;
-								}
-
-							}
-
-							if ($debug) print_r($urls);
-						}
-					}
-				} */
-
 				// wtf is this even
 				if (!$found && preg_match("/^https?:\/\/gyazo\.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches)) {
 					$img_id = $matches[1];
@@ -558,7 +501,8 @@ class Af_RedditImgur extends Plugin {
 			mb_strlen(strip_tags($article["content"])) <= 150) {
 
 			// do not try to embed posts linking back to other reddit posts
-			if ($url &&	strpos($url, "reddit.com") === FALSE) {
+			// readability.php requires PHP 5.6
+			if ($url &&	strpos($url, "reddit.com") === FALSE && version_compare(PHP_VERSION, '5.6.0', '>=')) {
 
 				/* link may lead to a huge video file or whatever, we need to check content type before trying to
 				parse it which p much requires curl */