";
}
function module_pref_feeds($link) {
global $update_intervals;
global $purge_intervals;
global $update_methods;
$subop = $_REQUEST["subop"];
$quiet = $_REQUEST["quiet"];
$mode = $_REQUEST["mode"];
if ($subop == "renamecat") {
$title = db_escape_string($_REQUEST['title']);
$id = db_escape_string($_REQUEST['id']);
if ($title) {
db_query($link, "UPDATE ttrss_feed_categories SET
title = '$title' WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
}
return;
}
if ($subop == "getfeedtree") {
$root = array();
$root['id'] = 'root';
$root['name'] = __('Feeds');
$root['items'] = array();
if (get_pref($link, 'ENABLE_FEED_CATS')) {
$result = db_query($link, "SELECT id, title FROM ttrss_feed_categories
WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY order_id, title");
while ($line = db_fetch_assoc($result)) {
$cat = array();
$cat['id'] = 'CAT:' . $line['id'];
$cat['bare_id'] = $feed_id;
$cat['name'] = $line['title'];
$cat['items'] = array();
$feed_result = db_query($link, "SELECT id, title, last_error
FROM ttrss_feeds
WHERE cat_id = '".$line['id']."' AND owner_uid = ".$_SESSION["uid"].
" ORDER BY order_id, title");
while ($feed_line = db_fetch_assoc($feed_result)) {
$feed = array();
$feed['id'] = 'FEED:' . $feed_line['id'];
$feed['bare_id'] = $feed_line['id'];
$feed['name'] = $feed_line['title'];
$feed['checkbox'] = false;
$feed['error'] = $feed_line['last_error'];
$feed['icon'] = getFeedIcon($feed_line['id']);
array_push($cat['items'], $feed);
}
array_push($root['items'], $cat);
}
/* Uncategorized is a special case */
$cat = array();
$cat['id'] = 'CAT:0';
$cat['bare_id'] = 0;
$cat['name'] = __("Uncategorized");
$cat['items'] = array();
$feed_result = db_query($link, "SELECT id, title,last_error
FROM ttrss_feeds
WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"].
" ORDER BY order_id, title");
while ($feed_line = db_fetch_assoc($feed_result)) {
$feed = array();
$feed['id'] = 'FEED:' . $feed_line['id'];
$feed['bare_id'] = $feed_line['id'];
$feed['name'] = $feed_line['title'];
$feed['checkbox'] = false;
$feed['error'] = $feed_line['last_error'];
$feed['icon'] = getFeedIcon($feed_line['id']);
array_push($cat['items'], $feed);
}
array_push($root['items'], $cat);
} else {
$feed_result = db_query($link, "SELECT id, title, last_error
FROM ttrss_feeds
WHERE owner_uid = ".$_SESSION["uid"].
" ORDER BY order_id, title");
while ($feed_line = db_fetch_assoc($feed_result)) {
$feed = array();
$feed['id'] = 'FEED:' . $feed_line['id'];
$feed['bare_id'] = $feed_line['id'];
$feed['name'] = $feed_line['title'];
$feed['checkbox'] = false;
$feed['error'] = $feed_line['last_error'];
$feed['icon'] = getFeedIcon($feed_line['id']);
array_push($root['items'], $feed);
}
}
$fl = array();
$fl['identifier'] = 'id';
$fl['label'] = 'name';
$fl['items'] = array($root);
print json_encode($fl);
return;
}
if ($subop == "catsortreset") {
db_query($link, "UPDATE ttrss_feed_categories
SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
return;
}
if ($subop == "feedsortreset") {
db_query($link, "UPDATE ttrss_feeds
SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
return;
}
if ($subop == "savefeedorder") {
if ($_POST['payload']) {
file_put_contents("/tmp/blahblah.txt", $_POST['payload']);
}
$data = file_get_contents("/tmp/blahblah.txt");
$data = json_decode($data, true);
if (is_array($data) && is_array($data['items'])) {
$cat_order_id = 0;
$data_map = array();
foreach ($data['items'] as $item) {
$data_map[$item['id']] =& $item['items'];
}
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($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'];
$bare_id = substr($id, strpos($id, ':')+1);
db_query($link, "UPDATE ttrss_feeds
SET order_id = '$feed_order_id' WHERE id = '$bare_id' AND
owner_uid = " . $_SESSION["uid"]);
++$feed_order_id;
}
}
}
}
return;
}
if ($subop == "removeicon") {
$feed_id = db_escape_string($_REQUEST["feed_id"]);
$result = db_query($link, "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");
}
return;
}
if ($subop == "uploadicon") {
$icon_file = $_FILES['icon_file']['tmp_name'];
$feed_id = db_escape_string($_REQUEST["feed_id"]);
if (is_file($icon_file) && $feed_id) {
if (filesize($icon_file) < 20000) {
$result = db_query($link, "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;
} else {
$rc = 2;
}
} else {
$rc = 1;
}
} else {
$rc = 2;
}
print "";
return;
}
if ($subop == "editfeed") {
header("Content-Type: text/xml");
print "
";
print "
";
print __('URL:') . " ";
print "";
batch_edit_cbox("feed_url");
/* Category */
if (get_pref($link, 'ENABLE_FEED_CATS')) {
print "
";
print __('Place in category:') . " ";
print_feed_cat_select($link, "cat_id", $cat_id, "disabled");
batch_edit_cbox("cat_id");
}
print "
";
print __('Article purging:') . " ";
print_select_hash("purge_interval", $purge_interval, $purge_intervals,
"disabled");
batch_edit_cbox("purge_interval");
}
print "
";
print " "; batch_edit_cbox("rtl_content", "rtl_content_l");
print "
";
print " "; batch_edit_cbox("include_in_digest", "include_in_digest_l");
print "
";
print " "; batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
print "
";
if (SIMPLEPIE_CACHE_IMAGES) {
print " "; batch_edit_cbox("cache_images", "cache_images_l");
}
print "
";
}
}
db_query($link, "COMMIT");
}
}
if ($subop == "remove") {
$ids = split(",", db_escape_string($_REQUEST["ids"]));
foreach ($ids as $id) {
remove_feed($link, $id, $_SESSION["uid"]);
}
return;
}
if ($subop == "clear") {
$id = db_escape_string($_REQUEST["id"]);
clear_feed_articles($link, $id);
}
if ($subop == "rescore") {
$ids = split(",", db_escape_string($_REQUEST["ids"]));
foreach ($ids as $id) {
$filters = load_filters($link, $id, $_SESSION["uid"], 6);
$result = db_query($link, "SELECT
title, content, link, ref_id, author,".
SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
FROM
ttrss_user_entries, ttrss_entries
WHERE ref_id = id AND feed_id = '$id' AND
owner_uid = " .$_SESSION['uid']."
");
$scores = array();
while ($line = db_fetch_assoc($result)) {
$tags = get_article_tags($link, $line["ref_id"]);
$article_filters = get_article_filters($filters, $line['title'],
$line['content'], $line['link'], strtotime($line['updated']),
$line['author'], $tags);
$new_score = calculate_article_score($article_filters);
if (!$scores[$new_score]) $scores[$new_score] = array();
array_push($scores[$new_score], $line['ref_id']);
}
foreach (array_keys($scores) as $s) {
if ($s > 1000) {
db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
marked = true WHERE
ref_id IN (" . join(',', $scores[$s]) . ")");
} else if ($s < -500) {
db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
unread = false WHERE
ref_id IN (" . join(',', $scores[$s]) . ")");
} else {
db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
ref_id IN (" . join(',', $scores[$s]) . ")");
}
}
}
print __("All done.");
}
if ($subop == "rescoreAll") {
$result = db_query($link,
"SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
while ($feed_line = db_fetch_assoc($result)) {
$id = $feed_line["id"];
$filters = load_filters($link, $id, $_SESSION["uid"], 6);
$tmp_result = db_query($link, "SELECT
title, content, link, ref_id, author,".
SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
FROM
ttrss_user_entries, ttrss_entries
WHERE ref_id = id AND feed_id = '$id' AND
owner_uid = " .$_SESSION['uid']."
");
$scores = array();
while ($line = db_fetch_assoc($tmp_result)) {
$tags = get_article_tags($link, $line["ref_id"]);
$article_filters = get_article_filters($filters, $line['title'],
$line['content'], $line['link'], strtotime($line['updated']),
$line['author'], $tags);
$new_score = calculate_article_score($article_filters);
if (!$scores[$new_score]) $scores[$new_score] = array();
array_push($scores[$new_score], $line['ref_id']);
}
foreach (array_keys($scores) as $s) {
if ($s > 1000) {
db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
marked = true WHERE
ref_id IN (" . join(',', $scores[$s]) . ")");
} else {
db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
ref_id IN (" . join(',', $scores[$s]) . ")");
}
}
}
print __("All done.");
}
if ($subop == "add") {
$feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
$cat_id = db_escape_string($_REQUEST["cat_id"]);
$p_from = db_escape_string($_REQUEST["from"]);
/* only read authentication information from POST */
$auth_login = db_escape_string(trim($_POST["auth_login"]));
$auth_pass = db_escape_string(trim($_POST["auth_pass"]));
if ($p_from != 'tt-rss') {
print "
"; if ($feed_id) { print "
"; } print ""; print ""; return; } } if ($subop == "categorize") { $ids = split(",", db_escape_string($_REQUEST["ids"])); $cat_id = db_escape_string($_REQUEST["cat_id"]); if ($cat_id == 0) { $cat_id_qpart = 'NULL'; } else { $cat_id_qpart = "'$cat_id'"; } db_query($link, "BEGIN"); foreach ($ids as $id) { db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); } db_query($link, "COMMIT"); } if ($subop == "editCats") { $action = $_REQUEST["action"]; if ($action == "save") { $cat_title = db_escape_string(trim($_REQUEST["value"])); $cat_id = db_escape_string($_REQUEST["cid"]); db_query($link, "BEGIN"); $result = db_query($link, "SELECT title FROM ttrss_feed_categories WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]); if (db_num_rows($result) == 1) { $old_title = db_fetch_result($result, 0, "title"); if ($cat_title != "") { $result = db_query($link, "UPDATE ttrss_feed_categories SET title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]); print $cat_title; } else { print $old_title; } } else { print $_REQUEST["value"]; } db_query($link, "COMMIT"); return; } header("Content-Type: text/xml"); print ""; if (db_num_rows($result) != 0) { print __('Select:')." ".__('All').", ".__('None').""; print "
".__('No feed categories defined.')."
"; } print "" . __("Using OPML you can export and import your feeds and Tiny Tiny RSS settings."); print "
".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.'); print "
" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "
"; print ""; print ""; 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 = __('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 "".__('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() . "/backend.php?op=rss&id=-2&view-mode=all_articles");; print " "; print " "; print "".__('No feeds found.')."