X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=classes%2Fpref%2Ffeeds.php;h=ab280a98e9a8eb67fd8c0d5e4d1659b5c0337a50;hb=fbff72e081e812926f89e608cf7af1b7d8c841cb;hp=46c3d083b3f33521db03bca6cc2acb89edd85116;hpb=1a293f10ab3e93581d3e63c05301ec4ff812491d;p=tt-rss.git diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php old mode 100644 new mode 100755 index 46c3d083..d6abe232 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1,5 +1,7 @@ link, $_REQUEST['title']); - $id = db_escape_string($this->link, $_REQUEST['id']); + $title = clean($_REQUEST['title']); + $id = clean($_REQUEST['id']); if ($title) { - db_query($this->link, "UPDATE ttrss_feed_categories SET - title = '$title' WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); + $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories SET + title = ? WHERE id = ? AND owner_uid = ?"); + $sth->execute([$title, $id, $_SESSION['uid']]); } - return; } private function get_category_items($cat_id) { - if ($_REQUEST['mode'] != 2) + if (clean($_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($this->link, '_PREFS_SHOW_EMPTY_CATS')); + $show_empty_cats = clean($_REQUEST['force_show_empty']) || + (clean($_REQUEST['mode']) != 2 && !$search); $items = array(); - $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories - WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat = '$cat_id' ORDER BY order_id, title"); + $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories + WHERE owner_uid = ? AND parent_cat = ? ORDER BY order_id, title"); + $sth->execute([$_SESSION['uid'], $cat_id]); - while ($line = db_fetch_assoc($result)) { + while ($line = $sth->fetch()) { $cat = array(); $cat['id'] = 'CAT:' . $line['id']; @@ -55,33 +55,42 @@ class Pref_Feeds extends Handler_Protected { $cat['type'] = 'category'; $cat['unread'] = 0; $cat['child_unread'] = 0; + $cat['auxcounter'] = 0; + $cat['parent_id'] = $cat_id; $cat['items'] = $this->get_category_items($line['id']); - $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); + $num_children = $this->calculate_children_count($cat); + $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); - if (count($cat['items']) > 0 || $show_empty_cats) + if ($num_children > 0 || $show_empty_cats) array_push($items, $cat); } - $feed_result = db_query($this->link, "SELECT id, title, last_error, - ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated + $fsth = $this->pdo->prepare("SELECT id, title, last_error, + ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, update_interval FROM ttrss_feeds - WHERE cat_id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]. - "$search_qpart ORDER BY order_id, title"); + WHERE cat_id = :cat AND + owner_uid = :uid AND + (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search)) + ORDER BY order_id, title"); + + $fsth->execute([":cat" => $cat_id, ":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); - while ($feed_line = db_fetch_assoc($feed_result)) { + while ($feed_line = $fsth->fetch()) { $feed = array(); $feed['id'] = 'FEED:' . $feed_line['id']; $feed['bare_id'] = (int)$feed_line['id']; + $feed['auxcounter'] = 0; $feed['name'] = $feed_line['title']; $feed['checkbox'] = false; $feed['unread'] = 0; $feed['error'] = $feed_line['last_error']; - $feed['icon'] = getFeedIcon($feed_line['id']); - $feed['param'] = make_local_datetime($this->link, + $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); + $feed['param'] = make_local_datetime( $feed_line['last_updated'], true); + $feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0); array_push($items, $feed); } @@ -95,22 +104,20 @@ class Pref_Feeds extends Handler_Protected { function makefeedtree() { - if ($_REQUEST['mode'] != 2) + if (clean($_REQUEST['mode']) != 2) $search = $_SESSION["prefs_feed_search"]; else $search = ""; - if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')"; - $root = array(); $root['id'] = 'root'; $root['name'] = __('Feeds'); $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 (clean($_REQUEST['mode']) == 2) { if ($enable_cats) { $cat = $this->feedlist_init_cat(-1); @@ -124,9 +131,7 @@ class Pref_Feeds extends Handler_Protected { /* Plugin feeds for -1 */ - global $pluginhost; - - $feeds = $pluginhost->get_feeds(-1); + $feeds = PluginHost::getInstance()->get_feeds(-1); if ($feeds) { foreach ($feeds as $feed) { @@ -135,6 +140,7 @@ class Pref_Feeds extends Handler_Protected { $item = array(); $item['id'] = 'FEED:' . $feed_id; $item['bare_id'] = (int)$feed_id; + $item['auxcounter'] = 0; $item['name'] = $feed['title']; $item['checkbox'] = false; $item['error'] = ''; @@ -154,29 +160,31 @@ class Pref_Feeds extends Handler_Protected { $root['items'] = array_merge($root['items'], $cat['items']); } - $result = db_query($this->link, "SELECT * FROM - ttrss_labels2 WHERE owner_uid = ".$_SESSION['uid']." ORDER by caption"); - - if (db_num_rows($result) > 0) { + $sth = $this->pdo->prepare("SELECT * FROM + ttrss_labels2 WHERE owner_uid = ? ORDER by caption"); + $sth->execute([$_SESSION['uid']]); - if (get_pref($this->link, 'ENABLE_FEED_CATS')) { - $cat = $this->feedlist_init_cat(-2); - } else { - $cat['items'] = array(); - } + if (get_pref('ENABLE_FEED_CATS')) { + $cat = $this->feedlist_init_cat(-2); + } else { + $cat['items'] = array(); + } - while ($line = db_fetch_assoc($result)) { + $num_labels = 0; + while ($line = $sth->fetch()) { + ++$num_labels; - $label_id = label_to_feed_id($line['id']); + $label_id = Labels::label_to_feed_id($line['id']); - $feed = $this->feedlist_init_feed($label_id, false, 0); + $feed = $this->feedlist_init_feed($label_id, false, 0); - $feed['fg_color'] = $line['fg_color']; - $feed['bg_color'] = $line['bg_color']; + $feed['fg_color'] = $line['fg_color']; + $feed['bg_color'] = $line['bg_color']; - array_push($cat['items'], $feed); - } + array_push($cat['items'], $feed); + } + if ($num_labels) { if ($enable_cats) { array_push($root['items'], $cat); } else { @@ -186,17 +194,18 @@ class Pref_Feeds extends Handler_Protected { } if ($enable_cats) { - $show_empty_cats = $_REQUEST['force_show_empty'] || - ($_REQUEST['mode'] != 2 && !$search && - get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS')); + $show_empty_cats = clean($_REQUEST['force_show_empty']) || + (clean($_REQUEST['mode']) != 2 && !$search); - $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories - WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title"); + $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories + WHERE owner_uid = ? AND parent_cat IS NULL ORDER BY order_id, title"); + $sth->execute([$_SESSION['uid']]); - while ($line = db_fetch_assoc($result)) { + while ($line = $sth->fetch()) { $cat = array(); $cat['id'] = 'CAT:' . $line['id']; $cat['bare_id'] = (int)$line['id']; + $cat['auxcounter'] = 0; $cat['name'] = $line['title']; $cat['items'] = array(); $cat['checkbox'] = false; @@ -206,9 +215,10 @@ class Pref_Feeds extends Handler_Protected { $cat['items'] = $this->get_category_items($line['id']); - $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); + $num_children = $this->calculate_children_count($cat); + $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); - if (count($cat['items']) > 0 || $show_empty_cats) + if ($num_children > 0 || $show_empty_cats) array_push($root['items'], $cat); $root['param'] += count($cat['items']); @@ -219,6 +229,7 @@ class Pref_Feeds extends Handler_Protected { $cat = array(); $cat['id'] = 'CAT:0'; $cat['bare_id'] = 0; + $cat['auxcounter'] = 0; $cat['name'] = __("Uncategorized"); $cat['items'] = array(); $cat['type'] = 'category'; @@ -226,24 +237,29 @@ class Pref_Feeds extends Handler_Protected { $cat['unread'] = 0; $cat['child_unread'] = 0; - $feed_result = db_query($this->link, "SELECT id, title,last_error, - ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated + $fsth = $this->pdo->prepare("SELECT id, title,last_error, + ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, update_interval FROM ttrss_feeds - WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"]. - "$search_qpart ORDER BY order_id, title"); + WHERE cat_id IS NULL AND + owner_uid = :uid AND + (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search)) + ORDER BY order_id, title"); + $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); - while ($feed_line = db_fetch_assoc($feed_result)) { + while ($feed_line = $fsth->fetch()) { $feed = array(); $feed['id'] = 'FEED:' . $feed_line['id']; $feed['bare_id'] = (int)$feed_line['id']; + $feed['auxcounter'] = 0; $feed['name'] = $feed_line['title']; $feed['checkbox'] = false; $feed['error'] = $feed_line['last_error']; - $feed['icon'] = getFeedIcon($feed_line['id']); - $feed['param'] = make_local_datetime($this->link, + $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); + $feed['param'] = make_local_datetime( $feed_line['last_updated'], true); $feed['unread'] = 0; $feed['type'] = 'feed'; + $feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0); array_push($cat['items'], $feed); } @@ -253,28 +269,32 @@ class Pref_Feeds extends Handler_Protected { if (count($cat['items']) > 0 || $show_empty_cats) array_push($root['items'], $cat); - $root['param'] += count($cat['items']); - $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); + $num_children = $this->calculate_children_count($root); + $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); } else { - $feed_result = db_query($this->link, "SELECT id, title, last_error, - ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated + $fsth = $this->pdo->prepare("SELECT id, title, last_error, + ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, update_interval FROM ttrss_feeds - WHERE owner_uid = ".$_SESSION["uid"]. - "$search_qpart ORDER BY order_id, title"); + WHERE owner_uid = :uid AND + (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search)) + ORDER BY order_id, title"); + $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); - while ($feed_line = db_fetch_assoc($feed_result)) { + while ($feed_line = $fsth->fetch()) { $feed = array(); $feed['id'] = 'FEED:' . $feed_line['id']; $feed['bare_id'] = (int)$feed_line['id']; + $feed['auxcounter'] = 0; $feed['name'] = $feed_line['title']; $feed['checkbox'] = false; $feed['error'] = $feed_line['last_error']; - $feed['icon'] = getFeedIcon($feed_line['id']); - $feed['param'] = make_local_datetime($this->link, + $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); + $feed['param'] = make_local_datetime( $feed_line['last_updated'], true); $feed['unread'] = 0; $feed['type'] = 'feed'; + $feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0); array_push($root['items'], $feed); } @@ -286,57 +306,52 @@ class Pref_Feeds extends Handler_Protected { $fl['identifier'] = 'id'; $fl['label'] = 'name'; - if ($_REQUEST['mode'] != 2) { + if (clean($_REQUEST['mode']) != 2) { $fl['items'] = array($root); } else { - $fl['items'] =& $root['items']; + $fl['items'] = $root['items']; } return $fl; } function catsortreset() { - db_query($this->link, "UPDATE ttrss_feed_categories - SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]); - return; + $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories + SET order_id = 0 WHERE owner_uid = ?"); + $sth->execute([$_SESSION['uid']]); } function feedsortreset() { - db_query($this->link, "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')); + $sth = $this->pdo->prepare("UPDATE ttrss_feeds + SET order_id = 0 WHERE owner_uid = ?"); + $sth->execute([$_SESSION['uid']]); } private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) { - $debug = isset($_REQUEST["debug"]); $prefix = ""; for ($i = 0; $i < $nest_level; $i++) $prefix .= " "; - if ($debug) _debug("$prefix C: $item_id P: $parent_id"); + Debug::log("$prefix C: $item_id P: $parent_id"); $bare_item_id = substr($item_id, strpos($item_id, ':')+1); 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($this->link, $parent_bare_id); + $parent_qpart = $parent_bare_id; } else { - $parent_qpart = 'NULL'; + $parent_qpart = null; } - db_query($this->link, "UPDATE ttrss_feed_categories - SET parent_cat = $parent_qpart WHERE id = '$bare_item_id' AND - owner_uid = " . $_SESSION["uid"]); + $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories + SET parent_cat = ? WHERE id = ? AND + owner_uid = ?"); + $sth->execute([$parent_qpart, $bare_item_id, $_SESSION['uid']]); } - $order_id = 0; + $order_id = 1; $cat = $data_map[$item_id]; @@ -345,36 +360,28 @@ class Pref_Feeds extends Handler_Protected { $id = $item['_reference']; $bare_id = substr($id, strpos($id, ':')+1); - if ($debug) _debug("$prefix [$order_id] $id/$bare_id"); + Debug::log("$prefix [$order_id] $id/$bare_id"); if ($item['_reference']) { if (strpos($id, "FEED") === 0) { - $cat_id = ($item_id != "root") ? - db_escape_string($this->link, $bare_item_id) : "NULL"; + $cat_id = ($item_id != "root") ? $bare_item_id : null; - $cat_qpart = ($cat_id != 0) ? "cat_id = '$cat_id'" : - "cat_id = NULL"; + $sth = $this->pdo->prepare("UPDATE ttrss_feeds + SET order_id = ?, cat_id = ? + WHERE id = ? AND owner_uid = ?"); - db_query($this->link, "UPDATE ttrss_feeds - SET order_id = $order_id, $cat_qpart - WHERE id = '$bare_id' AND - owner_uid = " . $_SESSION["uid"]); + $sth->execute([$order_id, $cat_id ? $cat_id : null, $bare_id, $_SESSION['uid']]); } else if (strpos($id, "CAT:") === 0) { $this->process_category_order($data_map, $item['_reference'], $item_id, $nest_level+1); - if ($item_id != 'root') { - $parent_qpart = db_escape_string($this->link, $bare_id); - } else { - $parent_qpart = 'NULL'; - } - - db_query($this->link, "UPDATE ttrss_feed_categories - SET order_id = '$order_id' WHERE id = '$bare_id' AND - owner_uid = " . $_SESSION["uid"]); + $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories + SET order_id = ? WHERE id = ? AND + owner_uid = ?"); + $sth->execute([$order_id, $bare_id, $_SESSION['uid']]); } } @@ -386,7 +393,7 @@ class Pref_Feeds extends Handler_Protected { function savefeedorder() { $data = json_decode($_POST['payload'], true); - #file_put_contents("/tmp/saveorder.json", $_POST['payload']); + #file_put_contents("/tmp/saveorder.json", clean($_POST['payload'])); #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true); if (!is_array($data['items'])) @@ -395,7 +402,7 @@ class Pref_Feeds extends Handler_Protected { # print_r($data['items']); if (is_array($data) && is_array($data['items'])) { - $cat_order_id = 0; +# $cat_order_id = 0; $data_map = array(); $root_item = false; @@ -407,7 +414,7 @@ class Pref_Feeds extends Handler_Protected { if (isset($item['items']['_reference'])) { $data_map[$item['id']] = array($item['items']); } else { - $data_map[$item['id']] =& $item['items']; + $data_map[$item['id']] = $item['items']; } } if ($item['id'] == 'root') { @@ -416,75 +423,62 @@ class Pref_Feeds extends Handler_Protected { } $this->process_category_order($data_map, $root_item); - - /* foreach ($data['items'][0]['items'] as $item) { - $id = $item['_reference']; - $bare_id = substr($id, strpos($id, ':')+1); - - ++$cat_order_id; - - if ($bare_id > 0) { - db_query($this->link, "UPDATE ttrss_feed_categories - SET order_id = '$cat_order_id' WHERE id = '$bare_id' AND - owner_uid = " . $_SESSION["uid"]); - } - - $feed_order_id = 0; - - if (is_array($data_map[$id])) { - foreach ($data_map[$id] as $feed) { - $id = $feed['_reference']; - $feed_id = substr($id, strpos($id, ':')+1); - - if ($bare_id != 0) - $cat_query = "cat_id = '$bare_id'"; - else - $cat_query = "cat_id = NULL"; - - db_query($this->link, "UPDATE ttrss_feeds - SET order_id = '$feed_order_id', - $cat_query - WHERE id = '$feed_id' AND - owner_uid = " . $_SESSION["uid"]); - - ++$feed_order_id; - } - } - } */ } - - return; } function removeicon() { - $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]); + $feed_id = clean($_REQUEST["feed_id"]); - $result = db_query($this->link, "SELECT id FROM ttrss_feeds - WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]); + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds + WHERE id = ? AND owner_uid = ?"); + $sth->execute([$feed_id, $_SESSION['uid']]); - if (db_num_rows($result) != 0) { - unlink(ICONS_DIR . "/$feed_id.ico"); - } + if ($row = $sth->fetch()) { + @unlink(ICONS_DIR . "/$feed_id.ico"); - return; + $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = NULL + where id = ?"); + $sth->execute([$feed_id]); + } } function uploadicon() { header("Content-type: text/html"); - $icon_file = $_FILES['icon_file']['tmp_name']; - $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]); + 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 = clean($_REQUEST["feed_id"]); if (is_file($icon_file) && $feed_id) { - if (filesize($icon_file) < 20000) { + if (filesize($icon_file) < 65535) { - $result = db_query($this->link, "SELECT id FROM ttrss_feeds - WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]); + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds + WHERE id = ? AND owner_uid = ?"); + $sth->execute([$feed_id, $_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 ($row = $sth->fetch()) { + @unlink(ICONS_DIR . "/$feed_id.ico"); + if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) { + + $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET + favicon_avg_color = '' + WHERE id = ?"); + $sth->execute([$feed_id]); + + $rc = 0; + } } else { $rc = 2; } @@ -495,6 +489,8 @@ class Pref_Feeds extends Handler_Protected { $rc = 2; } + @unlink($icon_file); + print ""; @@ -505,287 +501,325 @@ class Pref_Feeds extends Handler_Protected { global $purge_intervals; global $update_intervals; - $feed_id = db_escape_string($this->link, $_REQUEST["id"]); - $result = db_query($this->link, - "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND - owner_uid = " . $_SESSION["uid"]); + $feed_id = clean($_REQUEST["id"]); - $title = htmlspecialchars(db_fetch_result($result, - 0, "title")); + $sth = $this->pdo->prepare("SELECT * FROM ttrss_feeds WHERE id = ? AND + owner_uid = ?"); + $sth->execute([$feed_id, $_SESSION['uid']]); - print ""; - print ""; - print ""; + if ($row = $sth->fetch()) { + print '
"; - print ""; - print ""; - print ""; + print_hidden("ids", "$feed_ids"); + print_hidden("op", "pref-feeds"); + print_hidden("method", "batchEditSave"); print "
" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . " "; - - print __("Only main settings profile can be migrated using OPML.") . "
"; + print "" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . + __("Only main settings profile can be migrated using OPML.") . "
"; print "" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "
"; - - print ""; - - print ""; - - print "
"; - - print "".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."
"; + print "" . __('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.') . "
"; $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() . "/public.php?op=rss&id=-2&view-mode=all_articles");; + print ""; + 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 ""; print "
".__("Add one valid RSS feed per line (no feed detection is done)")." | "; - if (get_pref($this->link, 'ENABLE_FEED_CATS')) { + if (get_pref('ENABLE_FEED_CATS')) { print __('Place in category:') . " "; - print_feed_cat_select($this->link, "cat", false, 'dojoType="dijit.form.Select"'); + print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"'); } print " |
"; print ""; @@ -1777,6 +1652,7 @@ class Pref_Feeds extends Handler_Protected { " ". ""; @@ -1798,6 +1674,110 @@ class Pref_Feeds extends Handler_Protected { "; } + function batchAddFeeds() { + $cat_id = clean($_REQUEST['cat']); + $feeds = explode("\n", clean($_REQUEST['feeds'])); + $login = clean($_REQUEST['login']); + $pass = trim(clean($_REQUEST['pass'])); + + foreach ($feeds as $feed) { + $feed = trim($feed); + + if (validate_feed_url($feed)) { + + $this->pdo->beginTransaction(); + + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds + WHERE feed_url = ? AND owner_uid = ?"); + $sth->execute([$feed, $_SESSION['uid']]); + + if (!$sth->fetch()) { + $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds + (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted) + VALUES (?, ?, '[Unknown]', ?, ?, ?, 0, false)"); + + $sth->execute([$_SESSION['uid'], $feed, $cat_id ? $cat_id : null, $login, $pass]); + } + + $this->pdo->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 = clean($_REQUEST['id']); + $is_cat = clean($_REQUEST['is_cat']); + + $new_key = $this->update_feed_access_key($feed_id, $is_cat); + + print json_encode(["link" => $new_key]); + } + + + private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) { + if (!$owner_uid) $owner_uid = $_SESSION["uid"]; + + // clear old value and generate new one + $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys + WHERE feed_id = ? AND is_cat = ? AND owner_uid = ?"); + $sth->execute([$feed_id, bool_to_sql_bool($is_cat), $owner_uid]); + + return get_feed_access_key($feed_id, $is_cat, $owner_uid); + } + + // Silent + function clearKeys() { + $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys WHERE + owner_uid = ?"); + $sth->execute([$_SESSION['uid']]); + } + + private function calculate_children_count($cat) { + $c = 0; + + foreach ($cat['items'] as $child) { + if ($child['type'] == 'category') { + $c += $this->calculate_children_count($child); + } else { + $c += 1; + } + } + + return $c; + } + + function getinactivefeeds() { + if (DB_TYPE == "pgsql") { + $interval_qpart = "NOW() - INTERVAL '3 months'"; + } else { + $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; + } + + $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_inactive FROM ttrss_feeds WHERE + (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE + ttrss_entries.id = ref_id AND + ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND + ttrss_feeds.owner_uid = ?"); + $sth->execute([$_SESSION['uid']]); + + if ($row = $sth->fetch()) { + print (int)$row["num_inactive"]; + } + } + + static function subscribe_to_feed_url() { + $url_path = get_self_url_prefix() . + "/public.php?op=subscribe&feed_url=%s"; + return $url_path; + } } -?> |