From 88bf000f8d85c195ef484415a3caa4e5317549f8 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 7 Jul 2015 13:07:58 +0300 Subject: [PATCH 1/6] cache_starred_images: also handle html5 mp4 video files --- plugins/cache_starred_images/init.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/plugins/cache_starred_images/init.php b/plugins/cache_starred_images/init.php index b851479c0..f1341a350 100644 --- a/plugins/cache_starred_images/init.php +++ b/plugins/cache_starred_images/init.php @@ -6,7 +6,7 @@ class Cache_Starred_Images extends Plugin implements IHandler { function about() { return array(1.0, - "Automatically cache images in Starred articles", + "Automatically cache Starred articles' images and HTML5 video files", "fox", true); } @@ -59,7 +59,8 @@ class Cache_Starred_Images extends Plugin implements IHandler { if ($hash) { - $filename = $this->cache_dir . "/" . $hash . '.png'; + $filename = $this->cache_dir . "/" . $hash; + $is_video = strpos($filename, ".mp4") !== FALSE; if (file_exists($filename)) { /* See if we can use X-Sendfile */ @@ -73,7 +74,7 @@ class Cache_Starred_Images extends Plugin implements IHandler { header("Content-type: application/octet-stream"); header('Content-Disposition: attachment; filename="' . basename($filename) . '"'); } else { - header("Content-type: image/png"); + header("Content-type: " . ($is_video ? "video/mp4" : "image/png")); $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)). " GMT"; header("Last-Modified: $stamp", true); readfile($filename); @@ -86,7 +87,7 @@ class Cache_Starred_Images extends Plugin implements IHandler { } function hook_house_keeping() { - $files = glob($this->cache_dir . "/*.png"); + $files = glob($this->cache_dir . "/*.{png,mp4}", GLOB_BRACE); $last_article_id = 0; $article_exists = 1; @@ -113,18 +114,19 @@ class Cache_Starred_Images extends Plugin implements IHandler { $xpath = new DOMXpath($doc); if ($article_id) { - $entries = $xpath->query('(//img[@src])'); + $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); foreach ($entries as $entry) { if ($entry->hasAttribute('src')) { $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); - $local_filename = $this->cache_dir . $article_id . "-" . sha1($src) . ".png"; + $extension = $entry->tagName == 'source' ? '.mp4' : '.png'; + $local_filename = $this->cache_dir . $article_id . "-" . sha1($src) . $extension; if (file_exists($local_filename)) { $entry->setAttribute("src", get_self_url_prefix() . "/public.php?op=cache_starred_images_getimage&method=image&hash=" . - $article_id . "-" . sha1($src)); + $article_id . "-" . sha1($src) . $extension); } } @@ -140,12 +142,11 @@ class Cache_Starred_Images extends Plugin implements IHandler { (ttrss_user_entries.feed_id = ttrss_feeds.id) WHERE ref_id = ttrss_entries.id AND marked = true AND - UPPER(content) LIKE '%cache_article_images($line["content"], $line["site_url"], $line["owner_uid"], $line["id"]); @@ -170,17 +171,20 @@ class Cache_Starred_Images extends Plugin implements IHandler { $doc->loadHTML($charset_hack . $content); $xpath = new DOMXPath($doc); - $entries = $xpath->query('(//img[@src])'); + $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); $success = false; $has_images = false; foreach ($entries as $entry) { + if ($entry->hasAttribute('src')) { $has_images = true; $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); - $local_filename = $this->cache_dir . $article_id . "-" . sha1($src) . ".png"; + $extension = $entry->tagName == 'source' ? '.mp4' : '.png'; + + $local_filename = $this->cache_dir . $article_id . "-" . sha1($src) . $extension; //_debug("cache_images: downloading: $src to $local_filename"); From f7745af9525b2d35b5cb0891452f3cbeeea56734 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 7 Jul 2015 14:21:13 +0300 Subject: [PATCH 2/6] af_redditimgur: improve youtube detection a bit --- plugins/af_redditimgur/init.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 265999e2b..3b37c0a71 100644 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -114,8 +114,8 @@ class Af_RedditImgur extends Plugin { } $matches = array(); - if (preg_match("/\/\/www\.youtube\.com\/v\/([\w-]+)/", $entry->getAttribute("href"), $matches) || - preg_match("/\/\/www\.youtube\.com\/watch\?v=([\w-]+)/", $entry->getAttribute("href"), $matches) || + if (preg_match("/\.youtube\.com\/v\/([\w-]+)/", $entry->getAttribute("href"), $matches) || + preg_match("/\.youtube\.com\/watch\?v=([\w-]+)/", $entry->getAttribute("href"), $matches) || preg_match("/\/\/youtu.be\/([\w-]+)/", $entry->getAttribute("href"), $matches)) { $vid_id = $matches[1]; From 2374294529305dde857a8f7966217ead9b93dc0e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 7 Jul 2015 14:23:18 +0300 Subject: [PATCH 3/6] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6aad45ceb..77216b695 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +Thumbs.db /deploy.exclude /deploy.sh /messages.mo From 9090b874abd254954a11d393a162bcf4ea7eb160 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 7 Jul 2015 15:59:32 +0300 Subject: [PATCH 4/6] simplify search, remove search_mode as useless remove dialog to select by tags, simplify browsing by tag query --- classes/api.php | 8 +- classes/dlg.php | 31 -------- classes/feeds.php | 49 ++---------- classes/handler/public.php | 11 +-- include/functions2.php | 150 +++++++++++-------------------------- index.php | 1 - js/tt-rss.js | 3 - 7 files changed, 57 insertions(+), 196 deletions(-) diff --git a/classes/api.php b/classes/api.php index 3c5d08408..8267572f4 100644 --- a/classes/api.php +++ b/classes/api.php @@ -222,11 +222,10 @@ class API extends Handler { /* do not rely on params below */ $search = $this->dbh->escape_string($_REQUEST["search"]); - $search_mode = $this->dbh->escape_string($_REQUEST["search_mode"]); $headlines = $this->api_get_headlines($feed_id, $limit, $offset, $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order, - $include_attachments, $since_id, $search, $search_mode, + $include_attachments, $since_id, $search, $include_nested, $sanitize_content, $force_update, $excerpt_length); $this->wrap(self::STATUS_OK, $headlines); @@ -636,8 +635,7 @@ class API extends Handler { static function api_get_headlines($feed_id, $limit, $offset, $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order, $include_attachments, $since_id, - $search = "", $search_mode = "", - $include_nested = false, $sanitize_content = true, $force_update = false, $excerpt_length = 100) { + $search = "", $include_nested = false, $sanitize_content = true, $force_update = false, $excerpt_length = 100) { if ($force_update && $feed_id > 0 && is_numeric($feed_id)) { // Update the feed if required with some basic flood control @@ -661,7 +659,7 @@ class API extends Handler { } $qfh_ret = queryFeedHeadlines($feed_id, $limit, - $view_mode, $is_cat, $search, $search_mode, + $view_mode, $is_cat, $search, false, $order, $offset, 0, false, $since_id, $include_nested); $result = $qfh_ret[0]; diff --git a/classes/dlg.php b/classes/dlg.php index eee720ed4..7b1abca3a 100644 --- a/classes/dlg.php +++ b/classes/dlg.php @@ -161,37 +161,6 @@ class Dlg extends Handler_Protected { } - function printTagSelect() { - - print __("Match:"). " " . - ""; - print ""; - print " "; - print ""; - print "