summaryrefslogtreecommitdiff
path: root/plugins/af_redditimgur/init.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/af_redditimgur/init.php')
-rwxr-xr-xplugins/af_redditimgur/init.php63
1 files changed, 17 insertions, 46 deletions
diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php
index 17ba432fd..c8ba4a1b2 100755
--- a/plugins/af_redditimgur/init.php
+++ b/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 */
@@ -37,9 +34,9 @@ class Af_RedditImgur extends Plugin {
print_error("Readability requires PHP version 5.6.");
}
- print "<form dojoType=\"dijit.form.Form\">";
+ print "<form dojoType='dijit.form.Form'>";
- print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
+ print "<script type='dojo/method' event='onSubmit' args='evt'>
evt.preventDefault();
if (this.validate()) {
console.log(dojo.objectToQuery(this.getValues()));
@@ -57,14 +54,19 @@ class Af_RedditImgur extends Plugin {
print_hidden("method", "save");
print_hidden("plugin", "af_redditimgur");
+ print "<fieldset class='narrow'>";
+ print "<label class='checkbox'>";
print_checkbox("enable_readability", $enable_readability);
- print "&nbsp;<label for=\"enable_readability\">" . __("Extract missing content using Readability") . "</label>";
-
- print "<br/>";
+ print " " . __("Extract missing content using Readability (requires af_readability)") . "</label>";
+ print "</fieldset>";
+ print "<fieldset class='narrow'>";
+ print "<label class='checkbox'>";
print_checkbox("enable_content_dupcheck", $enable_content_dupcheck);
- print "&nbsp;<label for=\"enable_content_dupcheck\">" . __("Enable additional duplicate checking") . "</label>";
- print "<p>"; print_button("submit", __("Save"));
+ print " " . __("Enable additional duplicate checking") . "</label>";
+ print "</fieldset>";
+
+ print_button("submit", __("Save"), 'class="alt-primary"');
print "</form>";
print "</div>";
@@ -546,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 ($this->host->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) {
+ $extracted_content = $p->hook_get_full_text($url);
- foreach ($entries as $entry) {
- if ($entry->hasAttribute("href")) {
- $entry->setAttribute("href",
- rewrite_relative_url($url, $entry->getAttribute("href")));
-
- }
-
- 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;
}
}
}