Browse Source

move readability library to af_readability/vendor out of global vendor directory
af_redditimgur: use HOOK_GET_FULL_TEXT instead of invoking readability directly

Andrew Dolgov 5 months ago
parent
commit
d0a9aeaf80
20 changed files with 5 additions and 39 deletions
  1. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Configuration.php
  2. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMAttr.php
  3. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMCdataSection.php
  4. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMCharacterData.php
  5. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMComment.php
  6. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMDocument.php
  7. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMDocumentFragment.php
  8. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMDocumentType.php
  9. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMElement.php
  10. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMEntity.php
  11. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMEntityReference.php
  12. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMNode.php
  13. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMNotation.php
  14. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMProcessingInstruction.php
  15. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMText.php
  16. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/NodeTrait.php
  17. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Nodes/NodeUtility.php
  18. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/ParseException.php
  19. 0 0
      plugins/af_readability/vendor/andreskrey/Readability/Readability.php
  20. 5 39
      plugins/af_redditimgur/init.php

vendor/andreskrey/Readability/Configuration.php → plugins/af_readability/vendor/andreskrey/Readability/Configuration.php


vendor/andreskrey/Readability/Nodes/DOM/DOMAttr.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMAttr.php


vendor/andreskrey/Readability/Nodes/DOM/DOMCdataSection.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMCdataSection.php


vendor/andreskrey/Readability/Nodes/DOM/DOMCharacterData.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMCharacterData.php


vendor/andreskrey/Readability/Nodes/DOM/DOMComment.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMComment.php


vendor/andreskrey/Readability/Nodes/DOM/DOMDocument.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMDocument.php


vendor/andreskrey/Readability/Nodes/DOM/DOMDocumentFragment.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMDocumentFragment.php


vendor/andreskrey/Readability/Nodes/DOM/DOMDocumentType.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMDocumentType.php


vendor/andreskrey/Readability/Nodes/DOM/DOMElement.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMElement.php


vendor/andreskrey/Readability/Nodes/DOM/DOMEntity.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMEntity.php


vendor/andreskrey/Readability/Nodes/DOM/DOMEntityReference.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMEntityReference.php


vendor/andreskrey/Readability/Nodes/DOM/DOMNode.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMNode.php


vendor/andreskrey/Readability/Nodes/DOM/DOMNotation.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMNotation.php


vendor/andreskrey/Readability/Nodes/DOM/DOMProcessingInstruction.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMProcessingInstruction.php


vendor/andreskrey/Readability/Nodes/DOM/DOMText.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/DOM/DOMText.php


vendor/andreskrey/Readability/Nodes/NodeTrait.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/NodeTrait.php


vendor/andreskrey/Readability/Nodes/NodeUtility.php → plugins/af_readability/vendor/andreskrey/Readability/Nodes/NodeUtility.php


vendor/andreskrey/Readability/ParseException.php → plugins/af_readability/vendor/andreskrey/Readability/ParseException.php


vendor/andreskrey/Readability/Readability.php → plugins/af_readability/vendor/andreskrey/Readability/Readability.php


+ 5 - 39
plugins/af_redditimgur/init.php

@@ -1,7 +1,4 @@
 <?php
-use andreskrey\Readability\Readability;
-use andreskrey\Readability\Configuration;
-
 class Af_RedditImgur extends Plugin {
 
 	/* @var PluginHost $host */
@@ -551,47 +548,16 @@ class Af_RedditImgur extends Plugin {
 				parse it which p much requires curl */
 
 				$useragent_compat = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)";
-
 				$content_type = $this->get_content_type($url, $useragent_compat);
 
 				if ($content_type && strpos($content_type, "text/html") !== FALSE) {
 
-					$tmp = fetch_file_contents(["url" => $url,
-						"useragent" => $useragent_compat,
-						"http_accept" => "text/html"]);
-
-					Debug::log("tmplen: " . mb_strlen($tmp), Debug::$LOG_VERBOSE);
-
-					if ($tmp && mb_strlen($tmp) < 1024 * 500) {
-
-						$r = new Readability(new Configuration());
-
-						try {
-							if ($r->parse($tmp)) {
-
-								$tmpxpath = new DOMXPath($r->getDOMDocument());
-
-								$entries = $tmpxpath->query('(//a[@href]|//img[@src])');
-
-								foreach ($entries as $entry) {
-									if ($entry->hasAttribute("href")) {
-										$entry->setAttribute("href",
-											rewrite_relative_url($url, $entry->getAttribute("href")));
+					foreach ($this->host->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) {
+						$extracted_content = $p->hook_get_full_text($url);
 
-									}
-
-									if ($entry->hasAttribute("src")) {
-										$entry->setAttribute("src",
-											rewrite_relative_url($url, $entry->getAttribute("src")));
-
-									}
-
-								}
-
-								$article["content"] = $r->getContent() . "<hr/>" . $article["content"];
-							}
-						} catch (Exception $e) {
-							//
+						if ($extracted_content) {
+							$article["content"] = $extracted_content;
+							break;
 						}
 					}
 				}