diff options
author | Andrew Dolgov <[email protected]> | 2013-03-19 22:41:10 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2013-03-19 22:41:10 +0400 |
commit | bfd61d3f85d9b2554a016e4c2f711a1285ff8818 (patch) | |
tree | fd94cb22ce5a2df59ab540a1d8769cbf36f73282 | |
parent | 2229e6ed6b07d4a28b04689a21c645bdb83652f7 (diff) |
rework STRIP_IMAGES to remove embedding; add per-feed control over embedded images (bump schema)
-rw-r--r-- | classes/api.php | 4 | ||||
-rw-r--r-- | classes/feeds.php | 2 | ||||
-rw-r--r-- | classes/pref/feeds.php | 28 | ||||
-rw-r--r-- | include/functions.php | 27 | ||||
-rw-r--r-- | js/prefs.js | 7 | ||||
-rw-r--r-- | schema/ttrss_schema_mysql.sql | 5 | ||||
-rw-r--r-- | schema/ttrss_schema_pgsql.sql | 5 | ||||
-rw-r--r-- | schema/versions/mysql/106.sql | 12 | ||||
-rw-r--r-- | schema/versions/pgsql/106.sql | 12 |
9 files changed, 89 insertions, 13 deletions
diff --git a/classes/api.php b/classes/api.php index 74464821f..92e19e70a 100644 --- a/classes/api.php +++ b/classes/api.php @@ -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"]; } diff --git a/classes/feeds.php b/classes/feeds.php index d598a9e4f..297cad300 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -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); diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index bfcc75f0d..285995dfc 100644 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -613,6 +613,18 @@ class Pref_Feeds extends Handler_Protected { name=\"always_display_enclosures\" $checked> <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> <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 " "; $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\"> <label class='insensitive' id=\"hide_images_l\" + for=\"hide_images\">". + __('Do not embed images')."</label>"; + + print " "; $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\"> <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; diff --git a/include/functions.php b/include/functions.php index affd4d4dc..1feedcbf0 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@ <?php define('EXPECTED_CONFIG_VERSION', 26); - define('SCHEMA_VERSION', 105); + define('SCHEMA_VERSION', 106); $fetch_last_error = false; $pluginhost = false; @@ -2461,6 +2461,7 @@ 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, @@ -2505,6 +2506,7 @@ "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 . @@ -2560,15 +2562,11 @@ } - 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); @@ -2605,6 +2603,23 @@ $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") { diff --git a/js/prefs.js b/js/prefs.js index e6257e1fb..082f62679 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -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"; diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index d4873ecb0..438865478 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -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); diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 5063c4dd8..3895ccc56 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -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 index 000000000..b819416b9 --- /dev/null +++ b/schema/versions/mysql/106.sql @@ -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 index 000000000..6e3dee2c9 --- /dev/null +++ b/schema/versions/pgsql/106.sql @@ -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; |