X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=classes%2Fpref%2Ffeeds.php;h=27e03f0e2db0f4a9f876a7ca9e738789c90d54d7;hb=6322ac79a020ab584d412d782d62b2ee77d7c6cf;hp=ef308ee1c9751f95e66d7f2c421050a4bc3f7b1b;hpb=304aadb907c5173b90f97812b4b2614b96e39c23;p=tt-rss.git
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index ef308ee1..27e03f0e 100644
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -3,7 +3,8 @@ class Pref_Feeds extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed",
- "savefeedorder", "uploadicon");
+ "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds",
+ "batchsubscribe");
return array_search($method, $csrf_ignored) !== false;
}
@@ -14,23 +15,33 @@ class Pref_Feeds extends Handler_Protected {
}
function renamecat() {
- $title = db_escape_string($_REQUEST['title']);
- $id = db_escape_string($_REQUEST['id']);
+ $title = db_escape_string( $_REQUEST['title']);
+ $id = db_escape_string( $_REQUEST['id']);
if ($title) {
- db_query($this->link, "UPDATE ttrss_feed_categories SET
+ db_query( "UPDATE ttrss_feed_categories SET
title = '$title' WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
}
return;
}
private function get_category_items($cat_id) {
- $show_empty_cats = $_REQUEST['mode'] != 2 &&
- get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
+
+ if ($_REQUEST['mode'] != 2)
+ $search = $_SESSION["prefs_feed_search"];
+ else
+ $search = "";
+
+ if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')";
+
+ // first one is set by API
+ $show_empty_cats = $_REQUEST['force_show_empty'] ||
+ ($_REQUEST['mode'] != 2 && !$search &&
+ get_pref( '_PREFS_SHOW_EMPTY_CATS'));
$items = array();
- $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories
+ $result = db_query( "SELECT id, title FROM ttrss_feed_categories
WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat = '$cat_id' ORDER BY order_id, title");
while ($line = db_fetch_assoc($result)) {
@@ -41,21 +52,20 @@ class Pref_Feeds extends Handler_Protected {
$cat['name'] = $line['title'];
$cat['items'] = array();
$cat['checkbox'] = false;
- $cat['hidden'] = sql_bool_to_bool($line['collapsed']);
$cat['type'] = 'category';
$cat['unread'] = 0;
$cat['child_unread'] = 0;
$cat['items'] = $this->get_category_items($line['id']);
- $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
+ $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
if (count($cat['items']) > 0 || $show_empty_cats)
array_push($items, $cat);
}
- $feed_result = db_query($this->link, "SELECT id, title, last_error,
+ $feed_result = db_query( "SELECT id, title, last_error,
".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
FROM ttrss_feeds
WHERE cat_id = '$cat_id' AND owner_uid = ".$_SESSION["uid"].
@@ -70,7 +80,7 @@ class Pref_Feeds extends Handler_Protected {
$feed['unread'] = 0;
$feed['error'] = $feed_line['last_error'];
$feed['icon'] = getFeedIcon($feed_line['id']);
- $feed['param'] = make_local_datetime($this->link,
+ $feed['param'] = make_local_datetime(
$feed_line['last_updated'], true);
array_push($items, $feed);
@@ -80,8 +90,15 @@ class Pref_Feeds extends Handler_Protected {
}
function getfeedtree() {
+ print json_encode($this->makefeedtree());
+ }
- $search = $_SESSION["prefs_feed_search"];
+ function makefeedtree() {
+
+ if ($_REQUEST['mode'] != 2)
+ $search = $_SESSION["prefs_feed_search"];
+ else
+ $search = "";
if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')";
@@ -91,13 +108,12 @@ class Pref_Feeds extends Handler_Protected {
$root['items'] = array();
$root['type'] = 'category';
- $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');
+ $enable_cats = get_pref( 'ENABLE_FEED_CATS');
if ($_REQUEST['mode'] == 2) {
if ($enable_cats) {
- $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");
- $cat = $this->feedlist_init_cat(-1, $cat_hidden);
+ $cat = $this->feedlist_init_cat(-1);
} else {
$cat['items'] = array();
}
@@ -106,30 +122,54 @@ class Pref_Feeds extends Handler_Protected {
array_push($cat['items'], $this->feedlist_init_feed($i));
}
+ /* Plugin feeds for -1 */
+
+ global $pluginhost;
+
+ $feeds = $pluginhost->get_feeds(-1);
+
+ if ($feeds) {
+ foreach ($feeds as $feed) {
+ $feed_id = PluginHost::pfeed_to_feed_id($feed['id']);
+
+ $item = array();
+ $item['id'] = 'FEED:' . $feed_id;
+ $item['bare_id'] = (int)$feed_id;
+ $item['name'] = $feed['title'];
+ $item['checkbox'] = false;
+ $item['error'] = '';
+ $item['icon'] = $feed['icon'];
+
+ $item['param'] = '';
+ $item['unread'] = 0; //$feed['sender']->get_unread($feed['id']);
+ $item['type'] = 'feed';
+
+ array_push($cat['items'], $item);
+ }
+ }
+
if ($enable_cats) {
array_push($root['items'], $cat);
} else {
$root['items'] = array_merge($root['items'], $cat['items']);
}
- $result = db_query($this->link, "SELECT * FROM
+ $result = db_query( "SELECT * FROM
ttrss_labels2 WHERE owner_uid = ".$_SESSION['uid']." ORDER by caption");
if (db_num_rows($result) > 0) {
- if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
- $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS");
- $cat = $this->feedlist_init_cat(-2, $cat_hidden);
+ if (get_pref( 'ENABLE_FEED_CATS')) {
+ $cat = $this->feedlist_init_cat(-2);
} else {
$cat['items'] = array();
}
while ($line = db_fetch_assoc($result)) {
- $label_id = -$line['id'] - 11;
- $count = getFeedUnread($this->link, $label_id);
+ $label_id = label_to_feed_id($line['id']);
- $feed = $this->feedlist_init_feed($label_id, false, $count);
+ $feed = $this->feedlist_init_feed($label_id, false, 0);
$feed['fg_color'] = $line['fg_color'];
$feed['bg_color'] = $line['bg_color'];
@@ -146,10 +186,11 @@ class Pref_Feeds extends Handler_Protected {
}
if ($enable_cats) {
- $show_empty_cats = $_REQUEST['mode'] != 2 &&
- get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
+ $show_empty_cats = $_REQUEST['force_show_empty'] ||
+ ($_REQUEST['mode'] != 2 && !$search &&
+ get_pref( '_PREFS_SHOW_EMPTY_CATS'));
- $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories
+ $result = db_query( "SELECT id, title FROM ttrss_feed_categories
WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title");
while ($line = db_fetch_assoc($result)) {
@@ -159,14 +200,13 @@ class Pref_Feeds extends Handler_Protected {
$cat['name'] = $line['title'];
$cat['items'] = array();
$cat['checkbox'] = false;
- $cat['hidden'] = sql_bool_to_bool($line['collapsed']);
$cat['type'] = 'category';
$cat['unread'] = 0;
$cat['child_unread'] = 0;
$cat['items'] = $this->get_category_items($line['id']);
- $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
+ $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
if (count($cat['items']) > 0 || $show_empty_cats)
array_push($root['items'], $cat);
@@ -181,13 +221,12 @@ class Pref_Feeds extends Handler_Protected {
$cat['bare_id'] = 0;
$cat['name'] = __("Uncategorized");
$cat['items'] = array();
- $cat['hidden'] = get_pref($this->link, "_COLLAPSED_UNCAT");
$cat['type'] = 'category';
$cat['checkbox'] = false;
$cat['unread'] = 0;
$cat['child_unread'] = 0;
- $feed_result = db_query($this->link, "SELECT id, title,last_error,
+ $feed_result = db_query( "SELECT id, title,last_error,
".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
FROM ttrss_feeds
WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"].
@@ -201,7 +240,7 @@ class Pref_Feeds extends Handler_Protected {
$feed['checkbox'] = false;
$feed['error'] = $feed_line['last_error'];
$feed['icon'] = getFeedIcon($feed_line['id']);
- $feed['param'] = make_local_datetime($this->link,
+ $feed['param'] = make_local_datetime(
$feed_line['last_updated'], true);
$feed['unread'] = 0;
$feed['type'] = 'feed';
@@ -209,16 +248,16 @@ class Pref_Feeds extends Handler_Protected {
array_push($cat['items'], $feed);
}
- $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
+ $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
if (count($cat['items']) > 0 || $show_empty_cats)
array_push($root['items'], $cat);
$root['param'] += count($cat['items']);
- $root['param'] = T_sprintf('(%d feeds)', $root['param']);
+ $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
} else {
- $feed_result = db_query($this->link, "SELECT id, title, last_error,
+ $feed_result = db_query( "SELECT id, title, last_error,
".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
FROM ttrss_feeds
WHERE owner_uid = ".$_SESSION["uid"].
@@ -232,7 +271,7 @@ class Pref_Feeds extends Handler_Protected {
$feed['checkbox'] = false;
$feed['error'] = $feed_line['last_error'];
$feed['icon'] = getFeedIcon($feed_line['id']);
- $feed['param'] = make_local_datetime($this->link,
+ $feed['param'] = make_local_datetime(
$feed_line['last_updated'], true);
$feed['unread'] = 0;
$feed['type'] = 'feed';
@@ -240,7 +279,7 @@ class Pref_Feeds extends Handler_Protected {
array_push($root['items'], $feed);
}
- $root['param'] = T_sprintf('(%d feeds)', count($root['items']));
+ $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
}
$fl = array();
@@ -253,25 +292,24 @@ class Pref_Feeds extends Handler_Protected {
$fl['items'] =& $root['items'];
}
- print json_encode($fl);
- return;
+ return $fl;
}
function catsortreset() {
- db_query($this->link, "UPDATE ttrss_feed_categories
+ db_query( "UPDATE ttrss_feed_categories
SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
return;
}
function feedsortreset() {
- db_query($this->link, "UPDATE ttrss_feeds
+ db_query( "UPDATE ttrss_feeds
SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
return;
}
function togglehiddenfeedcats() {
- set_pref($this->link, '_PREFS_SHOW_EMPTY_CATS',
- (get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS') ? 'false' : 'true'));
+ set_pref( '_PREFS_SHOW_EMPTY_CATS',
+ (get_pref( '_PREFS_SHOW_EMPTY_CATS') ? 'false' : 'true'));
}
private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) {
@@ -288,12 +326,12 @@ class Pref_Feeds extends Handler_Protected {
if ($item_id != 'root') {
if ($parent_id && $parent_id != 'root') {
$parent_bare_id = substr($parent_id, strpos($parent_id, ':')+1);
- $parent_qpart = db_escape_string($parent_bare_id);
+ $parent_qpart = db_escape_string( $parent_bare_id);
} else {
$parent_qpart = 'NULL';
}
- db_query($this->link, "UPDATE ttrss_feed_categories
+ db_query( "UPDATE ttrss_feed_categories
SET parent_cat = $parent_qpart WHERE id = '$bare_item_id' AND
owner_uid = " . $_SESSION["uid"]);
}
@@ -314,10 +352,13 @@ class Pref_Feeds extends Handler_Protected {
if (strpos($id, "FEED") === 0) {
$cat_id = ($item_id != "root") ?
- db_escape_string($bare_item_id) : "NULL";
+ db_escape_string( $bare_item_id) : "NULL";
- db_query($this->link, "UPDATE ttrss_feeds
- SET order_id = $order_id, cat_id = '$cat_id'
+ $cat_qpart = ($cat_id != 0) ? "cat_id = '$cat_id'" :
+ "cat_id = NULL";
+
+ db_query( "UPDATE ttrss_feeds
+ SET order_id = $order_id, $cat_qpart
WHERE id = '$bare_id' AND
owner_uid = " . $_SESSION["uid"]);
@@ -326,12 +367,12 @@ class Pref_Feeds extends Handler_Protected {
$nest_level+1);
if ($item_id != 'root') {
- $parent_qpart = db_escape_string($bare_id);
+ $parent_qpart = db_escape_string( $bare_id);
} else {
$parent_qpart = 'NULL';
}
- db_query($this->link, "UPDATE ttrss_feed_categories
+ db_query( "UPDATE ttrss_feed_categories
SET order_id = '$order_id' WHERE id = '$bare_id' AND
owner_uid = " . $_SESSION["uid"]);
}
@@ -383,7 +424,7 @@ class Pref_Feeds extends Handler_Protected {
++$cat_order_id;
if ($bare_id > 0) {
- db_query($this->link, "UPDATE ttrss_feed_categories
+ db_query( "UPDATE ttrss_feed_categories
SET order_id = '$cat_order_id' WHERE id = '$bare_id' AND
owner_uid = " . $_SESSION["uid"]);
}
@@ -400,7 +441,7 @@ class Pref_Feeds extends Handler_Protected {
else
$cat_query = "cat_id = NULL";
- db_query($this->link, "UPDATE ttrss_feeds
+ db_query( "UPDATE ttrss_feeds
SET order_id = '$feed_order_id',
$cat_query
WHERE id = '$feed_id' AND
@@ -416,32 +457,63 @@ class Pref_Feeds extends Handler_Protected {
}
function removeicon() {
- $feed_id = db_escape_string($_REQUEST["feed_id"]);
+ $feed_id = db_escape_string( $_REQUEST["feed_id"]);
- $result = db_query($this->link, "SELECT id FROM ttrss_feeds
+ $result = db_query( "SELECT id FROM ttrss_feeds
WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
if (db_num_rows($result) != 0) {
- unlink(ICONS_DIR . "/$feed_id.ico");
+ @unlink(ICONS_DIR . "/$feed_id.ico");
+
+ db_query( "UPDATE ttrss_feeds SET favicon_avg_color = NULL
+ where id = '$feed_id'");
}
return;
}
function uploadicon() {
- $icon_file = $_FILES['icon_file']['tmp_name'];
- $feed_id = db_escape_string($_REQUEST["feed_id"]);
+ header("Content-type: text/html");
+
+ $tmp_file = false;
+
+ if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) {
+ $tmp_file = tempnam(CACHE_DIR . '/upload', 'icon');
+
+ $result = move_uploaded_file($_FILES['icon_file']['tmp_name'],
+ $tmp_file);
+
+ if (!$result) {
+ return;
+ }
+ } else {
+ return;
+ }
+
+ $icon_file = $tmp_file;
+ $feed_id = db_escape_string( $_REQUEST["feed_id"]);
if (is_file($icon_file) && $feed_id) {
if (filesize($icon_file) < 20000) {
- $result = db_query($this->link, "SELECT id FROM ttrss_feeds
+ $result = db_query( "SELECT id FROM ttrss_feeds
WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
if (db_num_rows($result) != 0) {
- unlink(ICONS_DIR . "/$feed_id.ico");
- move_uploaded_file($icon_file, ICONS_DIR . "/$feed_id.ico");
- $rc = 0;
+ @unlink(ICONS_DIR . "/$feed_id.ico");
+ if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) {
+
+ require_once "colors.php";
+
+ $favicon_color = db_escape_string(
+ calculate_avg_color(ICONS_DIR . "/$feed_id.ico"));
+
+ db_query( "UPDATE ttrss_feeds SET
+ favicon_avg_color = '$favicon_color'
+ WHERE id = '$feed_id'");
+
+ $rc = 0;
+ }
} else {
$rc = 2;
}
@@ -452,6 +524,8 @@ class Pref_Feeds extends Handler_Protected {
$rc = 2;
}
+ @unlink($icon_file);
+
print "";
@@ -461,14 +535,16 @@ class Pref_Feeds extends Handler_Protected {
function editfeed() {
global $purge_intervals;
global $update_intervals;
- global $update_methods;
- $feed_id = db_escape_string($_REQUEST["id"]);
+ $feed_id = db_escape_string( $_REQUEST["id"]);
- $result = db_query($this->link,
+ $result = db_query(
"SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
owner_uid = " . $_SESSION["uid"]);
+ $auth_pass_encrypted = sql_bool_to_bool(db_fetch_result($result, 0,
+ "auth_pass_encrypted"));
+
$title = htmlspecialchars(db_fetch_result($result,
0, "title"));
@@ -509,7 +585,7 @@ class Pref_Feeds extends Handler_Protected {
/* Category */
- if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
+ if (get_pref( 'ENABLE_FEED_CATS')) {
$cat_id = db_fetch_result($result, 0, "cat_id");
@@ -517,7 +593,7 @@ class Pref_Feeds extends Handler_Protected {
print __('Place in category:') . " ";
- print_feed_cat_select($this->link, "cat_id", $cat_id,
+ print_feed_cat_select( "cat_id", $cat_id,
'dojoType="dijit.form.Select"');
}
@@ -533,20 +609,10 @@ class Pref_Feeds extends Handler_Protected {
print_select_hash("update_interval", $update_interval, $update_intervals,
'dojoType="dijit.form.Select"');
- /* Update method */
-
- $update_method = db_fetch_result($result, 0, "update_method",
- 'dojoType="dijit.form.Select"');
-
- print " " . __('using') . " ";
- print_select_hash("update_method", $update_method, $update_methods,
- 'dojoType="dijit.form.Select"');
+ /* Purge intl */
$purge_interval = db_fetch_result($result, 0, "purge_interval");
-
- /* Purge intl */
-
print "
";
print __('Article purging:') . " ";
@@ -564,7 +630,14 @@ class Pref_Feeds extends Handler_Protected {
placeHolder=\"".__("Login")."\"
name=\"auth_login\" value=\"$auth_login\">
";
- $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass"));
+ $auth_pass = db_fetch_result($result, 0, "auth_pass");
+
+ if ($auth_pass_encrypted) {
+ require_once "crypt.php";
+ $auth_pass = decrypt_string($auth_pass);
+ }
+
+ $auth_pass = htmlspecialchars($auth_pass);
print " ";
- $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
-
- if ($rtl_content) {
- $checked = "checked=\"1\"";
- } else {
- $checked = "";
- }
-
- print "
";
-
$include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
if ($include_in_digest) {
@@ -625,6 +687,18 @@ class Pref_Feeds extends Handler_Protected {
name=\"always_display_enclosures\"
$checked> ";
+ $hide_images = sql_bool_to_bool(db_fetch_result($result, 0, "hide_images"));
+
+ if ($hide_images) {
+ $checked = "checked=\"1\"";
+ } else {
+ $checked = "";
+ }
+
+ print "
";
$cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
@@ -651,18 +725,6 @@ class Pref_Feeds extends Handler_Protected {
name=\"mark_unread_on_update\"
$checked> ";
- $update_on_checksum_change = sql_bool_to_bool(db_fetch_result($result, 0, "update_on_checksum_change"));
-
- if ($update_on_checksum_change) {
- $checked = "checked";
- } else {
- $checked = "";
- }
-
- print "
";
-
print "";
/* Icon */
@@ -719,11 +781,12 @@ class Pref_Feeds extends Handler_Protected {
function editfeeds() {
global $purge_intervals;
global $update_intervals;
- global $update_methods;
- $feed_ids = db_escape_string($_REQUEST["ids"]);
+ $feed_ids = db_escape_string( $_REQUEST["ids"]);
+
+ print_notice("Enable the options you wish to apply using checkboxes on the right:");
- print "" . __("Enable the options you wish to apply using checkboxes on the right:") . "
";
+ print "";
print "";
print "";
@@ -753,13 +816,13 @@ class Pref_Feeds extends Handler_Protected {
/* Category */
- if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
+ if (get_pref( 'ENABLE_FEED_CATS')) {
print "
";
print __('Place in category:') . " ";
- print_feed_cat_select($this->link, "cat_id", $cat_id,
+ print_feed_cat_select( "cat_id", $cat_id,
'disabled="1" dojoType="dijit.form.Select"');
$this->batch_edit_cbox("cat_id");
@@ -778,13 +841,6 @@ class Pref_Feeds extends Handler_Protected {
$this->batch_edit_cbox("update_interval");
- /* Update method */
-
- print " " . __('using') . " ";
- print_select_hash("update_method", $update_method, $update_methods,
- 'disabled="1" dojoType="dijit.form.Select"');
- $this->batch_edit_cbox("update_method");
-
/* Purge intl */
if (FORCE_ARTICLE_PURGE == 0) {
@@ -824,11 +880,6 @@ class Pref_Feeds extends Handler_Protected {
print " "; $this->batch_edit_cbox("private", "private_l");
- print "
";
-
- print " "; $this->batch_edit_cbox("rtl_content", "rtl_content_l");
-
print "
";
@@ -841,6 +892,14 @@ class Pref_Feeds extends Handler_Protected {
print " "; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
+ print "
";
+
+ print " "; $this->batch_edit_cbox("hide_images", "hide_images_l");
+
print "