From 582ff3cf6e617ccb6d6164da7381db80a0183127 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 5 Jul 2016 11:01:36 +0300 Subject: af_redditimgur: make sure content_link is defined even if content dupcheck is disabled --- plugins/af_redditimgur/init.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 2e0748137..8243b94c4 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -301,8 +301,9 @@ class Af_RedditImgur extends Plugin { @$doc->loadHTML($article["content"]); $xpath = new DOMXPath($doc); + $content_link = $xpath->query("(//a[contains(., '[link]')])")->item(0); + if ($this->host->get($this, "enable_content_dupcheck")) { - $content_link = $xpath->query("(//a[contains(., '[link]')])")->item(0); if ($content_link) { $content_href = db_escape_string($content_link->getAttribute("href")); -- cgit v1.2.3 From eb95d1bddf12c6bd11d2d3af5a524e1216ea2264 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 7 Jul 2016 09:04:38 +0300 Subject: af_redditimgur: handle i.reddituploads.com as pictures --- plugins/af_redditimgur/init.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 8243b94c4..f32578450 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -179,7 +179,9 @@ class Af_RedditImgur extends Plugin { $found = true; } - if (preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9][0-9]*)?$/i", $entry->getAttribute("href"))) { + if (preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9][0-9]*)?$/i", $entry->getAttribute("href")) || + mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== FALSE) { + _debug("Handling as a picture", $debug); $img = $doc->createElement('img'); -- cgit v1.2.3 From 76ba1df76e9ce3733c990e1d953706b691ee7b14 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 26 Jul 2016 15:46:54 +0300 Subject: af_redditimgur: use browser UA for readability requests --- plugins/af_redditimgur/init.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index f32578450..1068ec548 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -349,24 +349,27 @@ class Af_RedditImgur extends Plugin { /* 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 */ + $useragent_compat = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"; + $ch = curl_init($content_link->getAttribute("href")); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir")); - curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT); + curl_setopt($ch, CURLOPT_USERAGENT, $useragent_compat); @$result = curl_exec($ch); $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); if ($content_type && strpos($content_type, "text/html") !== FALSE) { - $tmp = fetch_file_contents($content_link->getAttribute("href")); + $tmp = fetch_file_contents(array("url" => $content_link->getAttribute("href"), + "useragent" => $useragent_compat)); //_debug("tmplen: " . mb_strlen($tmp)); - if ($tmp && mb_strlen($tmp) < 65535 * 4) { + if ($tmp && mb_strlen($tmp) < 1024 * 250) { $r = new Readability($tmp, $content_link->getAttribute("href")); -- cgit v1.2.3 From a6fde6c99f7295f0a3fc3e97333158b10e714af5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 26 Jul 2016 16:29:17 +0300 Subject: af_redditimgur: support video elements in imgur albums --- plugins/af_redditimgur/init.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'plugins') diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 1068ec548..af58197cd 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -239,7 +239,7 @@ class Af_RedditImgur extends Plugin { //if ($debug) print_r($album_content); - $aentries = $axpath->query("(//div[@class='post-image']/img[@src] | //a[@class='zoom']/img[@src])"); + $aentries = $axpath->query("(//div[@class='post-image']/img[@src] | //a[@class='zoom']/img[@src] | //div[@class='video-elements']/source)"); $urls = []; foreach ($aentries as $aentry) { @@ -247,14 +247,27 @@ class Af_RedditImgur extends Plugin { $url = $aentry->getAttribute("src"); if (!in_array($url, $urls)) { - $img = $doc->createElement('img'); - $img->setAttribute("src", $url); - $entry->parentNode->insertBefore($doc->createElement('br'), $entry); - $br = $doc->createElement('br'); + if ($aentry->tagName == "img") { - $entry->parentNode->insertBefore($img, $entry); - $entry->parentNode->insertBefore($br, $entry); + $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, "i.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); -- cgit v1.2.3 From d419aed5434cd425a0b9be3f65cd6c8c6f930d1a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 1 Aug 2016 08:26:11 +0300 Subject: trgm plugin: increase check distance to 3 days --- plugins/af_psql_trgm/init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 521db4b85..0de46b085 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -274,7 +274,7 @@ class Af_Psql_Trgm extends Plugin { $result = db_query("SELECT COUNT(id) AS nequal FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND - date_entered >= NOW() - interval '1 day' AND + date_entered >= NOW() - interval '3 days' AND title = '$title_escaped' AND guid != '$entry_guid' AND owner_uid = $owner_uid"); -- cgit v1.2.3 From 90e45935bb5573a94afa369a789f45e923f7bc9f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 1 Aug 2016 16:20:14 +0300 Subject: af_redditimgur: try to guess images to embed using content-type --- plugins/af_redditimgur/init.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'plugins') diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index af58197cd..7414656d5 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -180,7 +180,8 @@ class Af_RedditImgur extends Plugin { } if (preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9][0-9]*)?$/i", $entry->getAttribute("href")) || - mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== FALSE) { + mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== FALSE || + mb_strpos($this->get_content_type($entry->getAttribute("href")), "image/") !== FALSE) { _debug("Handling as a picture", $debug); @@ -364,16 +365,7 @@ class Af_RedditImgur extends Plugin { $useragent_compat = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"; - $ch = curl_init($content_link->getAttribute("href")); - curl_setopt($ch, CURLOPT_TIMEOUT, 5); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_HEADER, true); - curl_setopt($ch, CURLOPT_NOBODY, true); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir")); - curl_setopt($ch, CURLOPT_USERAGENT, $useragent_compat); - - @$result = curl_exec($ch); - $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); + $content_type = $this->get_content_type($content_link->getAttribute("href"), $useragent_compat); if ($content_type && strpos($content_type, "text/html") !== FALSE) { @@ -483,5 +475,24 @@ class Af_RedditImgur extends Plugin { print $doc->saveHTML(); } + + private function get_content_type($url, $useragent = SELF_USER_AGENT) { + $content_type = false; + + if (function_exists("curl_init") && !defined("NO_CURL")) { + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_NOBODY, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir")); + curl_setopt($ch, CURLOPT_USERAGENT, $useragent); + + @$result = curl_exec($ch); + $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); + } + + return $content_type; + } } ?> -- cgit v1.2.3 From 8788698b0531573548dceb1c0db0d3fb2f4c2a0b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 1 Aug 2016 21:03:36 +0300 Subject: basic tweet embedding using oembed --- plugins/af_redditimgur/init.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 7414656d5..e283b8cec 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -29,7 +29,7 @@ class Af_RedditImgur extends Plugin { $enable_content_dupcheck = $this->host->get($this, "enable_content_dupcheck"); $enable_content_dupcheck_checked = $enable_content_dupcheck ? "checked" : ""; - + print "
"; print "