rework STRIP_IMAGES to remove embedding; add per-feed control over embedded images (bump schema)

This commit is contained in:
Andrew Dolgov 2013-03-19 22:41:10 +04:00
parent 2229e6ed6b
commit bfd61d3f85
9 changed files with 89 additions and 13 deletions

View 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"];
}

View 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);

View 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;

View 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;
@ -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") {

View 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";

View 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);

View 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);

View file

@ -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;

View file

@ -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;