]> git.wh0rd.org Git - tt-rss.git/commitdiff
rework STRIP_IMAGES to remove embedding; add per-feed control over embedded images...
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 19 Mar 2013 18:41:10 +0000 (22:41 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 19 Mar 2013 18:41:10 +0000 (22:41 +0400)
classes/api.php
classes/feeds.php
classes/pref/feeds.php
include/functions.php
js/prefs.js
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/versions/mysql/106.sql [new file with mode: 0644]
schema/versions/pgsql/106.sql [new file with mode: 0644]

index 74464821f5c19a40746bdfe98673b54b757f9fa3..92e19e70a7bdbe37005f83fd3739783445fdd579 100644 (file)
@@ -636,7 +636,9 @@ class API extends Handler {
 
                                        if ($sanitize_content) {
                                                $headline_row["content"] = sanitize($link,
-                                                       $line["content_preview"], false, false, $line["site_url"]);
+                                                       $line["content_preview"],
+                                                       sql_bool_to_bool($line['hide_images']),
+                                                       false, $line["site_url"]);
                                        } else {
                                                $headline_row["content"] = $line["content_preview"];
                                        }
index d598a9e4fcef29d2c4c9bac6fad3debfc6e34e5a..297cad3006914dc9122c5d30f054c0c727cf0ac2 100644 (file)
@@ -481,7 +481,7 @@ class Feeds extends Handler_Protected {
                                        unset($line["tag_cache"]);
 
                                        $line["content"] = sanitize($this->link, $line["content_preview"],
-                                                       false, false, $entry_site_url);
+                                                       sql_bool_to_bool($line['hide_images']), false, $entry_site_url);
 
                                        foreach ($pluginhost->get_hooks($pluginhost::HOOK_RENDER_ARTICLE_CDM) as $p) {
                                                $line = $p->hook_render_article_cdm($line);
index bfcc75f0d4c0cd1b30a710fd7ef5ed104292b3b6..285995dfc044c75191681d24519cc98be1d8795f 100644 (file)
@@ -613,6 +613,18 @@ class Pref_Feeds extends Handler_Protected {
                        name=\"always_display_enclosures\"
                        $checked>&nbsp;<label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
 
+               $hide_images = sql_bool_to_bool(db_fetch_result($result, 0, "hide_images"));
+
+               if ($hide_images) {
+                       $checked = "checked=\"1\"";
+               } else {
+                       $checked = "";
+               }
+
+               print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"hide_images\"
+               name=\"hide_images\"
+                       $checked>&nbsp;<label for=\"hide_images\">".
+               __('Do not embed images')."</label>";
 
                $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
 
@@ -804,6 +816,14 @@ class Pref_Feeds extends Handler_Protected {
 
                print "&nbsp;"; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
 
+               print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"hide_images\"
+                       name=\"hide_images\"
+                       dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"hide_images_l\"
+                       for=\"hide_images\">".
+               __('Do not embed images')."</label>";
+
+               print "&nbsp;"; $this->batch_edit_cbox("hide_images", "hide_images_l");
+
                print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\"
                        name=\"cache_images\"
                        dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"cache_images_l\"
@@ -856,7 +876,8 @@ class Pref_Feeds extends Handler_Protected {
                        db_escape_string($_POST["include_in_digest"]));
                $cache_images = checkbox_to_sql_bool(
                        db_escape_string($_POST["cache_images"]));
-
+               $hide_images = checkbox_to_sql_bool(
+                       db_escape_string($_POST["hide_images"]));
                $always_display_enclosures = checkbox_to_sql_bool(
                        db_escape_string($_POST["always_display_enclosures"]));
 
@@ -887,6 +908,7 @@ class Pref_Feeds extends Handler_Protected {
                                auth_pass = '$auth_pass',
                                private = $private,
                                cache_images = $cache_images,
+                               hide_images = $hide_images,
                                include_in_digest = $include_in_digest,
                                always_display_enclosures = $always_display_enclosures,
                                mark_unread_on_update = $mark_unread_on_update
@@ -952,6 +974,10 @@ class Pref_Feeds extends Handler_Protected {
                                                $qpart = "cache_images = $cache_images";
                                                break;
 
+                                       case "hide_images":
+                                               $qpart = "hide_images = $hide_images";
+                                               break;
+
                                        case "cat_id":
                                                $qpart = $category_qpart_nocomma;
                                                break;
index affd4d4dcdb9abb598620670a37a6338b46b127a..1feedcbf0172f8fa76ca5833644629504a311959 100644 (file)
@@ -1,6 +1,6 @@
 <?php
        define('EXPECTED_CONFIG_VERSION', 26);
-       define('SCHEMA_VERSION', 105);
+       define('SCHEMA_VERSION', 106);
 
        $fetch_last_error = false;
        $pluginhost = false;
                                                num_comments,
                                                comments,
                                                int_id,
+                                               hide_images,
                                                unread,feed_id,marked,published,link,last_read,orig_feed_id,
                                                last_marked, last_published,
                                                ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms,
                                                                "label_cache," .
                                                                "link," .
                                                                "last_read," .
+                                                               "hide_images," .
                                                                "last_marked, last_published, " .
                                                                SUBSTRING_FOR_DATE . "(last_read,1,19) as last_read_noms," .
                                                                $since_id_part .
 
        }
 
-       function sanitize($link, $str, $force_strip_tags = false, $owner = false, $site_url = false) {
+       function sanitize($link, $str, $force_remove_images = false, $owner = false, $site_url = false) {
                if (!$owner) $owner = $_SESSION["uid"];
 
                $res = trim($str); if (!$res) return '';
 
-               if (get_pref($link, "STRIP_IMAGES", $owner)) {
-                       $res = preg_replace('/<img[^>]+>/is', '', $res);
-               }
-
                if (strpos($res, "href=") === false)
                        $res = rewrite_urls($res);
 
 
                                        $entry->setAttribute('src', $src);
                                }
+
+                               if ($entry->nodeName == 'img') {
+                                       if (get_pref($link, "STRIP_IMAGES", $owner) || $force_remove_images) {
+
+                                               $p = $doc->createElement('p');
+
+                                               $a = $doc->createElement('a');
+                                               $a->setAttribute('href', $entry->getAttribute('src'));
+
+                                               $a->appendChild(new DOMText($entry->getAttribute('src')));
+                                               $a->setAttribute('target', '_blank');
+
+                                               $p->appendChild($a);
+
+                                               $entry->parentNode->replaceChild($p, $entry);
+                                       }
+                               }
                        }
 
                        if (strtolower($entry->nodeName) == "a") {
index e6257e1fb261f4b3f7077962c123ce4d2085f6fa..082f62679c045675dd33415bbb3e067e59efac38 100644 (file)
@@ -722,6 +722,13 @@ function editSelectedFeeds() {
                                                                }
                                                        } catch (e) { }
 
+                                                       try {
+                                                               if (!query.match("&hide_images=") &&
+                                                                               this.getChildByName('hide_images').attr('disabled') == false) {
+                                                                       query = query + "&hide_images=false";
+                                                               }
+                                                       } catch (e) { }
+
                                                        if (!query.match("&include_in_digest=") &&
                                                                        this.getChildByName('include_in_digest').attr('disabled') == false) {
                                                                query = query + "&include_in_digest=false";
index d4873ecb0efda98710e460cda39503a9eba0b619..4388654787c42e1f88bae7385f1bb6211f3ca5cc 100644 (file)
@@ -117,6 +117,7 @@ create table ttrss_feeds (id integer not null auto_increment primary key,
        hidden bool not null default false,
        include_in_digest boolean not null default true,
        cache_images boolean not null default false,
+       hide_images boolean not null default false,
        cache_content boolean not null default false,
        auth_pass_encrypted boolean not null default false,
        last_viewed datetime default null,
@@ -312,7 +313,7 @@ create table ttrss_tags (id integer primary key auto_increment,
 
 create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
 
-insert into ttrss_version values (105);
+insert into ttrss_version values (106);
 
 create table ttrss_enclosures (id integer primary key auto_increment,
        content_url text not null,
@@ -414,7 +415,7 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
 
 insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('VFEED_GROUP_BY_FEED', 1, 'false', 'Group headlines in virtual feeds',2, 'When this option is enabled, headlines in Special feeds and Labels are grouped by feeds');
 
-insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('STRIP_IMAGES', 1, 'false', 'Hide images in articles', 2);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('STRIP_IMAGES', 1, 'false', 'Do not embed images in articles', 2);
 
 insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_DEFAULT_VIEW_ORDER_BY', 2, 'default', '', 1);
 
index 5063c4dd81a1c7f5ce893cf386a6abe7800e1c9b..3895ccc56353fb8855dd42f3ae00d759ce3b57ae 100644 (file)
@@ -79,6 +79,7 @@ create table ttrss_feeds (id serial not null primary key,
        include_in_digest boolean not null default true,
        rtl_content boolean not null default false,
        cache_images boolean not null default false,
+       hide_images boolean not null default false,
        cache_content boolean not null default false,
        last_viewed timestamp default null,
        last_update_started timestamp default null,
@@ -260,7 +261,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (105);
+insert into ttrss_version values (106);
 
 create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
@@ -354,7 +355,7 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
 
 insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('VFEED_GROUP_BY_FEED', 1, 'false', 'Group headlines in virtual feeds',2, 'When this option is enabled, headlines in Special feeds and Labels are grouped by feeds');
 
-insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('STRIP_IMAGES', 1, 'false', 'Hide images in articles', 2);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('STRIP_IMAGES', 1, 'false', 'Do not embed images in articles', 2);
 
 insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_DEFAULT_VIEW_ORDER_BY', 2, 'default', '', 1);
 
diff --git a/schema/versions/mysql/106.sql b/schema/versions/mysql/106.sql
new file mode 100644 (file)
index 0000000..b819416
--- /dev/null
@@ -0,0 +1,12 @@
+begin;
+
+update ttrss_prefs set short_desc = 'Do not embed images in articles' where pref_name = 'STRIP_IMAGES';
+
+alter table ttrss_feeds add column hide_images bool;
+update ttrss_feeds set hide_images = false;
+alter table ttrss_feeds change hide_images hide_images bool not null;
+alter table ttrss_feeds alter column hide_images set default false;
+
+update ttrss_version set schema_version = 106;
+
+commit;
diff --git a/schema/versions/pgsql/106.sql b/schema/versions/pgsql/106.sql
new file mode 100644 (file)
index 0000000..6e3dee2
--- /dev/null
@@ -0,0 +1,12 @@
+begin;
+
+update ttrss_prefs set short_desc = 'Do not embed images in articles' where pref_name = 'STRIP_IMAGES';
+
+alter table ttrss_feeds add column hide_images boolean;
+update ttrss_feeds set hide_images = false;
+alter table ttrss_feeds alter column hide_images set not null;
+alter table ttrss_feeds alter column hide_images set default false;
+
+update ttrss_version set schema_version = 106;
+
+commit;