X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=classes%2Fpref%2Ffeeds.php;h=2f5a0e499d7a51bb631995009f9ebe22515ecedc;hb=1ffe3391f902c4baa984982f19e61a0e45de21ff;hp=452236a7edf3cba34c1a2a705d9b02a9025d55a8;hpb=04d05dcc3f5d95ac1ba201820a4d10812b8068e7;p=tt-rss.git diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 452236a7..2f5a0e49 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", "feedswitherrors", "inactivefeeds"); + "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds", + "batchsubscribe"); return array_search($method, $csrf_ignored) !== false; } @@ -14,11 +15,11 @@ class Pref_Feeds extends Handler_Protected { } function renamecat() { - $title = db_escape_string($_REQUEST['title']); - $id = db_escape_string($_REQUEST['id']); + $title = $this->dbh->escape_string($_REQUEST['title']); + $id = $this->dbh->escape_string($_REQUEST['id']); if ($title) { - db_query($this->link, "UPDATE ttrss_feed_categories SET + $this->dbh->query("UPDATE ttrss_feed_categories SET title = '$title' WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); } return; @@ -33,15 +34,17 @@ class Pref_Feeds extends Handler_Protected { if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')"; - $show_empty_cats = $_REQUEST['mode'] != 2 && !$search && - get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS'); + // 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 = $this->dbh->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)) { + while ($line = $this->dbh->fetch_assoc($result)) { $cat = array(); $cat['id'] = 'CAT:' . $line['id']; @@ -49,27 +52,26 @@ 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 = $this->dbh->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"]. "$search_qpart ORDER BY order_id, title"); - while ($feed_line = db_fetch_assoc($feed_result)) { + while ($feed_line = $this->dbh->fetch_assoc($feed_result)) { $feed = array(); $feed['id'] = 'FEED:' . $feed_line['id']; $feed['bare_id'] = (int)$feed_line['id']; @@ -78,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); @@ -88,6 +90,10 @@ class Pref_Feeds extends Handler_Protected { } function getfeedtree() { + print json_encode($this->makefeedtree()); + } + + function makefeedtree() { if ($_REQUEST['mode'] != 2) $search = $_SESSION["prefs_feed_search"]; @@ -102,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(); } @@ -117,30 +122,52 @@ class Pref_Feeds extends Handler_Protected { array_push($cat['items'], $this->feedlist_init_feed($i)); } + /* Plugin feeds for -1 */ + + $feeds = PluginHost::getInstance()->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 = $this->dbh->query("SELECT * FROM ttrss_labels2 WHERE owner_uid = ".$_SESSION['uid']." ORDER by caption"); - if (db_num_rows($result) > 0) { + if ($this->dbh->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)) { + while ($line = $this->dbh->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']; @@ -157,27 +184,27 @@ class Pref_Feeds extends Handler_Protected { } if ($enable_cats) { - $show_empty_cats = $_REQUEST['mode'] != 2 && !$search && - 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 = $this->dbh->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)) { + while ($line = $this->dbh->fetch_assoc($result)) { $cat = array(); $cat['id'] = 'CAT:' . $line['id']; $cat['bare_id'] = (int)$line['id']; $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); @@ -192,19 +219,18 @@ 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 = $this->dbh->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"]. "$search_qpart ORDER BY order_id, title"); - while ($feed_line = db_fetch_assoc($feed_result)) { + while ($feed_line = $this->dbh->fetch_assoc($feed_result)) { $feed = array(); $feed['id'] = 'FEED:' . $feed_line['id']; $feed['bare_id'] = (int)$feed_line['id']; @@ -212,7 +238,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'; @@ -220,22 +246,22 @@ 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 = $this->dbh->query("SELECT id, title, last_error, ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]. "$search_qpart ORDER BY order_id, title"); - while ($feed_line = db_fetch_assoc($feed_result)) { + while ($feed_line = $this->dbh->fetch_assoc($feed_result)) { $feed = array(); $feed['id'] = 'FEED:' . $feed_line['id']; $feed['bare_id'] = (int)$feed_line['id']; @@ -243,7 +269,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'; @@ -251,7 +277,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(); @@ -264,25 +290,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 + $this->dbh->query("UPDATE ttrss_feed_categories SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]); return; } function feedsortreset() { - db_query($this->link, "UPDATE ttrss_feeds + $this->dbh->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) { @@ -299,12 +324,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 = $this->dbh->escape_string($parent_bare_id); } else { $parent_qpart = 'NULL'; } - db_query($this->link, "UPDATE ttrss_feed_categories + $this->dbh->query("UPDATE ttrss_feed_categories SET parent_cat = $parent_qpart WHERE id = '$bare_item_id' AND owner_uid = " . $_SESSION["uid"]); } @@ -325,12 +350,12 @@ class Pref_Feeds extends Handler_Protected { if (strpos($id, "FEED") === 0) { $cat_id = ($item_id != "root") ? - db_escape_string($bare_item_id) : "NULL"; + $this->dbh->escape_string($bare_item_id) : "NULL"; $cat_qpart = ($cat_id != 0) ? "cat_id = '$cat_id'" : "cat_id = NULL"; - db_query($this->link, "UPDATE ttrss_feeds + $this->dbh->query("UPDATE ttrss_feeds SET order_id = $order_id, $cat_qpart WHERE id = '$bare_id' AND owner_uid = " . $_SESSION["uid"]); @@ -340,12 +365,12 @@ class Pref_Feeds extends Handler_Protected { $nest_level+1); if ($item_id != 'root') { - $parent_qpart = db_escape_string($bare_id); + $parent_qpart = $this->dbh->escape_string($bare_id); } else { $parent_qpart = 'NULL'; } - db_query($this->link, "UPDATE ttrss_feed_categories + $this->dbh->query("UPDATE ttrss_feed_categories SET order_id = '$order_id' WHERE id = '$bare_id' AND owner_uid = " . $_SESSION["uid"]); } @@ -397,7 +422,7 @@ class Pref_Feeds extends Handler_Protected { ++$cat_order_id; if ($bare_id > 0) { - db_query($this->link, "UPDATE ttrss_feed_categories + $this->dbh->query("UPDATE ttrss_feed_categories SET order_id = '$cat_order_id' WHERE id = '$bare_id' AND owner_uid = " . $_SESSION["uid"]); } @@ -414,7 +439,7 @@ class Pref_Feeds extends Handler_Protected { else $cat_query = "cat_id = NULL"; - db_query($this->link, "UPDATE ttrss_feeds + $this->dbh->query("UPDATE ttrss_feeds SET order_id = '$feed_order_id', $cat_query WHERE id = '$feed_id' AND @@ -430,32 +455,63 @@ class Pref_Feeds extends Handler_Protected { } function removeicon() { - $feed_id = db_escape_string($_REQUEST["feed_id"]); + $feed_id = $this->dbh->escape_string($_REQUEST["feed_id"]); - $result = db_query($this->link, "SELECT id FROM ttrss_feeds + $result = $this->dbh->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"); + if ($this->dbh->num_rows($result) != 0) { + @unlink(ICONS_DIR . "/$feed_id.ico"); + + $this->dbh->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 = $this->dbh->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 = $this->dbh->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; + if ($this->dbh->num_rows($result) != 0) { + @unlink(ICONS_DIR . "/$feed_id.ico"); + if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) { + + require_once "colors.php"; + + $favicon_color = $this->dbh->escape_string( + calculate_avg_color(ICONS_DIR . "/$feed_id.ico")); + + $this->dbh->query("UPDATE ttrss_feeds SET + favicon_avg_color = '$favicon_color' + WHERE id = '$feed_id'"); + + $rc = 0; + } } else { $rc = 2; } @@ -466,6 +522,8 @@ class Pref_Feeds extends Handler_Protected { $rc = 2; } + @unlink($icon_file); + print ""; @@ -476,13 +534,16 @@ class Pref_Feeds extends Handler_Protected { global $purge_intervals; global $update_intervals; - $feed_id = db_escape_string($_REQUEST["id"]); + $feed_id = $this->dbh->escape_string($_REQUEST["id"]); - $result = db_query($this->link, + $result = $this->dbh->query( "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); - $title = htmlspecialchars(db_fetch_result($result, + $auth_pass_encrypted = sql_bool_to_bool($this->dbh->fetch_result($result, 0, + "auth_pass_encrypted")); + + $title = htmlspecialchars($this->dbh->fetch_result($result, 0, "title")); print ""; @@ -500,8 +561,8 @@ class Pref_Feeds extends Handler_Protected { /* Feed URL */ - $feed_url = db_fetch_result($result, 0, "feed_url"); - $feed_url = htmlspecialchars(db_fetch_result($result, + $feed_url = $this->dbh->fetch_result($result, 0, "feed_url"); + $feed_url = htmlspecialchars($this->dbh->fetch_result($result, 0, "feed_url")); print "
"; @@ -512,7 +573,7 @@ class Pref_Feeds extends Handler_Protected { regExp='^(http|https)://.*' style=\"width : 20em\" name=\"feed_url\" value=\"$feed_url\">"; - $last_error = db_fetch_result($result, 0, "last_error"); + $last_error = $this->dbh->fetch_result($result, 0, "last_error"); if ($last_error) { print " link, 'ENABLE_FEED_CATS')) { + if (get_pref('ENABLE_FEED_CATS')) { - $cat_id = db_fetch_result($result, 0, "cat_id"); + $cat_id = $this->dbh->fetch_result($result, 0, "cat_id"); print "
"; 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"'); } @@ -541,14 +602,14 @@ class Pref_Feeds extends Handler_Protected { /* Update Interval */ - $update_interval = db_fetch_result($result, 0, "update_interval"); + $update_interval = $this->dbh->fetch_result($result, 0, "update_interval"); print_select_hash("update_interval", $update_interval, $update_intervals, 'dojoType="dijit.form.Select"'); /* Purge intl */ - $purge_interval = db_fetch_result($result, 0, "purge_interval"); + $purge_interval = $this->dbh->fetch_result($result, 0, "purge_interval"); print "
"; print __('Article purging:') . " "; @@ -561,13 +622,20 @@ class Pref_Feeds extends Handler_Protected { print "
".__("Authentication")."
"; print "
"; - $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login")); + $auth_login = htmlspecialchars($this->dbh->fetch_result($result, 0, "auth_login")); print "
"; - $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass")); + $auth_pass = $this->dbh->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 "".__("Options")."
"; print "
"; - $private = sql_bool_to_bool(db_fetch_result($result, 0, "private")); + $private = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "private")); if ($private) { $checked = "checked=\"1\""; @@ -592,18 +660,7 @@ class Pref_Feeds extends Handler_Protected { 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")); + $include_in_digest = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "include_in_digest")); if ($include_in_digest) { $checked = "checked=\"1\""; @@ -616,7 +673,7 @@ class Pref_Feeds extends Handler_Protected { $checked> "; - $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures")); + $always_display_enclosures = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "always_display_enclosures")); if ($always_display_enclosures) { $checked = "checked"; @@ -628,34 +685,33 @@ class Pref_Feeds extends Handler_Protected { name=\"always_display_enclosures\" $checked> "; + $hide_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "hide_images")); - $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images")); - - if ($cache_images) { + if ($hide_images) { $checked = "checked=\"1\""; } else { $checked = ""; } - print "
 "; + print "
 "; - $cache_content = sql_bool_to_bool(db_fetch_result($result, 0, "cache_content")); + $cache_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "cache_images")); - if ($cache_content) { + if ($cache_images) { $checked = "checked=\"1\""; } else { $checked = ""; } - print "
 "; + print "
 "; - $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update")); + $mark_unread_on_update = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "mark_unread_on_update")); if ($mark_unread_on_update) { $checked = "checked"; @@ -667,18 +723,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 */ @@ -712,7 +756,7 @@ class Pref_Feeds extends Handler_Protected { __('Unsubscribe').""; if (PUBSUBHUBBUB_ENABLED) { - $pubsub_state = db_fetch_result($result, 0, "pubsub_state"); + $pubsub_state = $this->dbh->fetch_result($result, 0, "pubsub_state"); $pubsub_btn_disabled = ($pubsub_state == 2) ? "" : "disabled=\"1\""; print " "; + print ""; if (defined('_ENABLE_FEED_DEBUGGING')) { @@ -1411,11 +1451,10 @@ class Pref_Feeds extends Handler_Protected { print __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "

"; - print " "; - global $pluginhost; - $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION, + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "hook_prefs_tab_section", "prefFeedsOPML"); print ""; # pane @@ -1439,30 +1478,6 @@ class Pref_Feeds extends Handler_Protected { print ""; # pane } - print "
"; - - print "

" . __("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.") . "

"; - - $bm_subscribe_url = str_replace('%s', '', add_feed_url()); - - $confirm_str = str_replace("'", "\'", __('Subscribe to %s in Tiny Tiny RSS?')); - - $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}"); - - print "" . __('Subscribe in Tiny Tiny RSS'). ""; - - print "

" . __("Use this bookmarklet to publish arbitrary pages using Tiny Tiny RSS") . "

"; - - $bm_url = htmlspecialchars("javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='".SELF_URL_PATH."/public.php?op=sharepopup',l=d.location,e=encodeURIComponent,g=f+'&title='+((e(s))?e(s):e(document.title))+'&url='+e(l.href);function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=500,height=250')){l.href=g;}}a();})()"); - - print "" . __('Share with Tiny Tiny RSS'). ""; - - global $pluginhost; - $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION, - "hook_prefs_tab_section", "prefFeedsBookmarklets"); - - print "
"; #pane - print "
"; print "

" . __("Published articles and generated feeds") . "

"; @@ -1472,7 +1487,7 @@ class Pref_Feeds extends Handler_Protected { $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() . "/public.php?op=rss&id=-2&view-mode=all_articles");; - print " "; print " "; - global $pluginhost; - $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION, + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "hook_prefs_tab_section", "prefFeedsPublishedGenerated"); print "
"; #pane - global $pluginhost; - - $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB, + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "hook_prefs_tab", "prefFeeds"); print ""; #container } - private function feedlist_init_cat($cat_id, $hidden = false) { + private function feedlist_init_cat($cat_id) { $obj = array(); $cat_id = (int) $cat_id; if ($cat_id > 0) { - $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true); + $cat_unread = ccache_find($cat_id, $_SESSION["uid"], true); } else if ($cat_id == 0 || $cat_id == -2) { - $cat_unread = getCategoryUnread($this->link, $cat_id); + $cat_unread = getCategoryUnread($cat_id); } $obj['id'] = 'CAT:' . $cat_id; $obj['items'] = array(); - $obj['name'] = getCategoryTitle($this->link, $cat_id); + $obj['name'] = getCategoryTitle($cat_id); $obj['type'] = 'category'; $obj['unread'] = (int) $cat_unread; - $obj['hidden'] = $hidden; $obj['bare_id'] = $cat_id; return $obj; @@ -1525,10 +1536,10 @@ class Pref_Feeds extends Handler_Protected { $feed_id = (int) $feed_id; if (!$title) - $title = getFeedTitle($this->link, $feed_id, false); + $title = getFeedTitle($feed_id, false); if ($unread === false) - $unread = getFeedUnread($this->link, $feed_id, false); + $unread = getFeedUnread($feed_id, false); $obj['id'] = 'FEED:' . $feed_id; $obj['name'] = $title; @@ -1550,7 +1561,7 @@ class Pref_Feeds extends Handler_Protected { $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; } - $result = db_query($this->link, "SELECT ttrss_feeds.title, ttrss_feeds.site_url, + $result = $this->dbh->query("SELECT ttrss_feeds.title, ttrss_feeds.site_url, ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE @@ -1562,7 +1573,7 @@ class Pref_Feeds extends Handler_Protected { GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url ORDER BY last_article"); - print "
" . __("These feeds have not been updated with new content for 3 months (oldest first):") . "
"; + print ""; print "
"; print "
". @@ -1581,7 +1592,7 @@ class Pref_Feeds extends Handler_Protected { $lnum = 1; - while ($line = db_fetch_assoc($result)) { + while ($line = $this->dbh->fetch_assoc($result)) { $class = ($lnum % 2) ? "even" : "odd"; $feed_id = $line["id"]; @@ -1604,7 +1615,7 @@ class Pref_Feeds extends Handler_Protected { htmlspecialchars($line["title"]).""; print ""; - print make_local_datetime($this->link, $line['last_article'], false); + print make_local_datetime($line['last_article'], false); print ""; print ""; @@ -1628,9 +1639,10 @@ class Pref_Feeds extends Handler_Protected { } function feedsWithErrors() { - print "
" . __("These feeds have not been updated because of errors:") . "
"; + print "

" . __("These feeds have not been updated because of errors:") . + "

"; - $result = db_query($this->link, "SELECT id,title,feed_url,last_error,site_url + $result = $this->dbh->query("SELECT id,title,feed_url,last_error,site_url FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); print "
"; @@ -1650,7 +1662,7 @@ class Pref_Feeds extends Handler_Protected { $lnum = 1; - while ($line = db_fetch_assoc($result)) { + while ($line = $this->dbh->fetch_assoc($result)) { $class = ($lnum % 2) ? "even" : "odd"; $feed_id = $line["id"]; @@ -1697,5 +1709,239 @@ class Pref_Feeds extends Handler_Protected { print "
"; } + /** + * Purge a feed contents, marked articles excepted. + * + * @param mixed $link The database connection. + * @param integer $id The id of the feed to purge. + * @return void + */ + private function clear_feed_articles($id) { + + if ($id != 0) { + $result = $this->dbh->query("DELETE FROM ttrss_user_entries + WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]); + } else { + $result = $this->dbh->query("DELETE FROM ttrss_user_entries + WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]); + } + + $result = $this->dbh->query("DELETE FROM ttrss_entries WHERE + (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); + + ccache_update($id, $_SESSION['uid']); + } // function clear_feed_articles + + private function remove_feed_category($id, $owner_uid) { + + $this->dbh->query("DELETE FROM ttrss_feed_categories + WHERE id = '$id' AND owner_uid = $owner_uid"); + + ccache_remove($id, $owner_uid, true); + } + + static function remove_feed($id, $owner_uid) { + + if ($id > 0) { + + /* save starred articles in Archived feed */ + + db_query("BEGIN"); + + /* prepare feed if necessary */ + + $result = db_query("SELECT feed_url FROM ttrss_feeds WHERE id = $id + AND owner_uid = $owner_uid"); + + $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); + + $result = db_query("SELECT id FROM ttrss_archived_feeds + WHERE feed_url = '$feed_url' AND owner_uid = $owner_uid"); + + if (db_num_rows($result) == 0) { + $result = db_query("SELECT MAX(id) AS id FROM ttrss_archived_feeds"); + $new_feed_id = (int)db_fetch_result($result, 0, "id") + 1; + + db_query("INSERT INTO ttrss_archived_feeds + (id, owner_uid, title, feed_url, site_url) + SELECT $new_feed_id, owner_uid, title, feed_url, site_url from ttrss_feeds + WHERE id = '$id'"); + + $archive_id = $new_feed_id; + } else { + $archive_id = db_fetch_result($result, 0, "id"); + } + + db_query("UPDATE ttrss_user_entries SET feed_id = NULL, + orig_feed_id = '$archive_id' WHERE feed_id = '$id' AND + marked = true AND owner_uid = $owner_uid"); + + /* Remove access key for the feed */ + + db_query("DELETE FROM ttrss_access_keys WHERE + feed_id = '$id' AND owner_uid = $owner_uid"); + + /* remove the feed */ + + db_query("DELETE FROM ttrss_feeds + WHERE id = '$id' AND owner_uid = $owner_uid"); + + db_query("COMMIT"); + + if (file_exists(ICONS_DIR . "/$id.ico")) { + unlink(ICONS_DIR . "/$id.ico"); + } + + ccache_remove($id, $owner_uid); + + } else { + label_remove(feed_to_label_id($id), $owner_uid); + //ccache_remove($id, $owner_uid); don't think labels are cached + } + } + + function batchSubscribe() { + print ""; + print ""; + + print "
+ ".__("Add one valid RSS feed per line (no feed detection is done)")." + "; + if (get_pref('ENABLE_FEED_CATS')) { + print __('Place in category:') . " "; + print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"'); + } + print "
"; + print ""; + + print "
"; + + print ""; + + print "
"; + + print "
+ +
"; + + print ""; + + print "
"; + + print "
+ + +
"; + } + + function batchAddFeeds() { + $cat_id = $this->dbh->escape_string($_REQUEST['cat']); + $feeds = explode("\n", $_REQUEST['feeds']); + $login = $this->dbh->escape_string($_REQUEST['login']); + $pass = trim($_REQUEST['pass']); + + foreach ($feeds as $feed) { + $feed = $this->dbh->escape_string(trim($feed)); + + if (validate_feed_url($feed)) { + + $this->dbh->query("BEGIN"); + + if ($cat_id == "0" || !$cat_id) { + $cat_qpart = "NULL"; + } else { + $cat_qpart = "'$cat_id'"; + } + + $result = $this->dbh->query( + "SELECT id FROM ttrss_feeds + WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]); + + if (strlen(FEED_CRYPT_KEY) > 0) { + require_once "crypt.php"; + $pass = substr(encrypt_string($pass), 0, 250); + $auth_pass_encrypted = 'true'; + } else { + $auth_pass_encrypted = 'false'; + } + + $pass = $this->dbh->escape_string($pass); + + if ($this->dbh->num_rows($result) == 0) { + $result = $this->dbh->query( + "INSERT INTO ttrss_feeds + (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted) + VALUES ('".$_SESSION["uid"]."', '$feed', + '[Unknown]', $cat_qpart, '$login', '$pass', 0, $auth_pass_encrypted)"); + } + + $this->dbh->query("COMMIT"); + } + } + } + + function regenOPMLKey() { + $this->update_feed_access_key('OPML:Publish', + false, $_SESSION["uid"]); + + $new_link = Opml::opml_publish_url(); + + print json_encode(array("link" => $new_link)); + } + + function regenFeedKey() { + $feed_id = $this->dbh->escape_string($_REQUEST['id']); + $is_cat = $this->dbh->escape_string($_REQUEST['is_cat']) == "true"; + + $new_key = $this->update_feed_access_key($feed_id, $is_cat); + + print json_encode(array("link" => $new_key)); + } + + + private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) { + if (!$owner_uid) $owner_uid = $_SESSION["uid"]; + + $sql_is_cat = bool_to_sql_bool($is_cat); + + $result = $this->dbh->query("SELECT access_key FROM ttrss_access_keys + WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat + AND owner_uid = " . $owner_uid); + + if ($this->dbh->num_rows($result) == 1) { + $key = $this->dbh->escape_string(sha1(uniqid(rand(), true))); + + $this->dbh->query("UPDATE ttrss_access_keys SET access_key = '$key' + WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat + AND owner_uid = " . $owner_uid); + + return $key; + + } else { + return get_feed_access_key($feed_id, $is_cat, $owner_uid); + } + } + + // Silent + function clearKeys() { + $this->dbh->query("DELETE FROM ttrss_access_keys WHERE + owner_uid = " . $_SESSION["uid"]); + } + + } ?>