1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2026-01-30 13:37:11 +00:00

split some more functions from functions.php

This commit is contained in:
Andrew Dolgov
2013-01-22 22:32:17 +04:00
parent 04f60eb729
commit 87d7e8507a
8 changed files with 666 additions and 655 deletions

View File

@@ -52,7 +52,7 @@ class Article extends Handler_Protected {
return;
}
catchupArticleById($this->link, $id, 0);
$this->catchupArticleById($this->link, $id, 0);
if (!$_SESSION["bw_limit"]) {
foreach ($cids as $cid) {
@@ -63,7 +63,27 @@ class Article extends Handler_Protected {
}
print json_encode($articles);
}
private function catchupArticleById($link, $id, $cmode) {
if ($cmode == 0) {
db_query($link, "UPDATE ttrss_user_entries SET
unread = false,last_read = NOW()
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
} else if ($cmode == 1) {
db_query($link, "UPDATE ttrss_user_entries SET
unread = true
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
} else {
db_query($link, "UPDATE ttrss_user_entries SET
unread = NOT unread,last_read = NOW()
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
}
$feed_id = getArticleFeed($link, $id);
ccache_update($link, $feed_id, $_SESSION["uid"]);
}
}

View File

@@ -807,7 +807,7 @@ class Feeds extends Handler_Protected {
* when there's nothing to load - e.g. no stuff in fresh feed */
if ($feed == -5) {
print json_encode(generate_dashboard_feed($this->link));
print json_encode($this->generate_dashboard_feed($this->link));
return;
}
@@ -826,7 +826,7 @@ class Feeds extends Handler_Protected {
}
if ($result && db_num_rows($result) == 0) {
print json_encode(generate_error_feed($this->link, __("Feed not found.")));
print json_encode($this->generate_error_feed($this->link, __("Feed not found.")));
return;
}
@@ -929,5 +929,63 @@ class Feeds extends Handler_Protected {
print json_encode($reply);
}
private function generate_dashboard_feed($link) {
$reply = array();
$reply['headlines']['id'] = -5;
$reply['headlines']['is_cat'] = false;
$reply['headlines']['toolbar'] = '';
$reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
$reply['headlines']['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
$result = db_query($link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
WHERE owner_uid = " . $_SESSION['uid']);
$last_updated = db_fetch_result($result, 0, "last_updated");
$last_updated = make_local_datetime($link, $last_updated, false);
$reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
$result = db_query($link, "SELECT COUNT(id) AS num_errors
FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
$num_errors = db_fetch_result($result, 0, "num_errors");
if ($num_errors > 0) {
$reply['headlines']['content'] .= "<br/>";
$reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
__('Some feeds have update errors (click for details)')."</a>";
}
$reply['headlines']['content'] .= "</span></p>";
$reply['headlines-info'] = array("count" => 0,
"vgroup_last_feed" => '',
"unread" => 0,
"disable_cache" => true);
return $reply;
}
private function generate_error_feed($link, $error) {
$reply = array();
$reply['headlines']['id'] = -6;
$reply['headlines']['is_cat'] = false;
$reply['headlines']['toolbar'] = '';
$reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
$reply['headlines-info'] = array("count" => 0,
"vgroup_last_feed" => '',
"unread" => 0,
"disable_cache" => true);
return $reply;
}
}
?>

View File

@@ -1070,7 +1070,7 @@ class Pref_Feeds extends Handler_Protected {
function clear() {
$id = db_escape_string($_REQUEST["id"]);
clear_feed_articles($this->link, $id);
$this->clear_feed_articles($this->link, $id);
}
function rescore() {
@@ -1677,5 +1677,29 @@ class Pref_Feeds extends Handler_Protected {
print "</div>";
}
/**
* 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($link, $id) {
if ($id != 0) {
$result = db_query($link, "DELETE FROM ttrss_user_entries
WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]);
} else {
$result = db_query($link, "DELETE FROM ttrss_user_entries
WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]);
}
$result = db_query($link, "DELETE FROM ttrss_entries WHERE
(SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
ccache_update($link, $id, $_SESSION['uid']);
} // function clear_feed_articles
}
?>

View File

@@ -169,12 +169,44 @@ class RPC extends Handler_Protected {
$ids = explode(",", db_escape_string($_REQUEST["ids"]));
foreach ($ids as $id) {
archive_article($this->link, $id, $_SESSION["uid"]);
$this->archive_article($this->link, $id, $_SESSION["uid"]);
}
print json_encode(array("message" => "UPDATE_COUNTERS"));
}
private function archive_article($link, $id, $owner_uid) {
db_query($link, "BEGIN");
$result = db_query($link, "SELECT feed_id FROM ttrss_user_entries
WHERE ref_id = '$id' AND owner_uid = $owner_uid");
if (db_num_rows($result) != 0) {
/* prepare the archived table */
$feed_id = (int) db_fetch_result($result, 0, "feed_id");
if ($feed_id) {
$result = db_query($link, "SELECT id FROM ttrss_archived_feeds
WHERE id = '$feed_id'");
if (db_num_rows($result) == 0) {
db_query($link, "INSERT INTO ttrss_archived_feeds
(id, owner_uid, title, feed_url, site_url)
SELECT id, owner_uid, title, feed_url, site_url from ttrss_feeds
WHERE id = '$feed_id'");
}
db_query($link, "UPDATE ttrss_user_entries
SET orig_feed_id = feed_id, feed_id = NULL
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
}
}
db_query($link, "COMMIT");
}
function publ() {
$pub = $_REQUEST["pub"];
$id = db_escape_string($_REQUEST["id"]);
@@ -241,7 +273,7 @@ class RPC extends Handler_Protected {
$ids = explode(",", db_escape_string($_REQUEST["ids"]));
$cmode = sprintf("%d", $_REQUEST["cmode"]);
markArticlesById($this->link, $ids, $cmode);
$this->markArticlesById($this->link, $ids, $cmode);
print json_encode(array("message" => "UPDATE_COUNTERS"));
}
@@ -250,7 +282,7 @@ class RPC extends Handler_Protected {
$ids = explode(",", db_escape_string($_REQUEST["ids"]));
$cmode = sprintf("%d", $_REQUEST["cmode"]);
publishArticlesById($this->link, $ids, $cmode);
$this->publishArticlesById($this->link, $ids, $cmode);
print json_encode(array("message" => "UPDATE_COUNTERS"));
}
@@ -335,7 +367,7 @@ class RPC extends Handler_Protected {
}
function regenOPMLKey() {
update_feed_access_key($this->link, 'OPML:Publish',
$this->update_feed_access_key($this->link, 'OPML:Publish',
false, $_SESSION["uid"]);
$new_link = opml_publish_url($this->link);
@@ -544,7 +576,7 @@ class RPC extends Handler_Protected {
$feed_id = db_escape_string($_REQUEST['id']);
$is_cat = db_escape_string($_REQUEST['is_cat']) == "true";
$new_key = update_feed_access_key($this->link, $feed_id, $is_cat);
$new_key = $this->update_feed_access_key($this->link, $feed_id, $is_cat);
print json_encode(array("link" => $new_key));
}
@@ -716,5 +748,88 @@ class RPC extends Handler_Protected {
}
function update_feed_access_key($link, $feed_id, $is_cat, $owner_uid = false) {
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
$sql_is_cat = bool_to_sql_bool($is_cat);
$result = db_query($link, "SELECT access_key FROM ttrss_access_keys
WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat
AND owner_uid = " . $owner_uid);
if (db_num_rows($result) == 1) {
$key = db_escape_string(sha1(uniqid(rand(), true)));
db_query($link, "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($link, $feed_id, $is_cat, $owner_uid);
}
}
private function markArticlesById($link, $ids, $cmode) {
$tmp_ids = array();
foreach ($ids as $id) {
array_push($tmp_ids, "ref_id = '$id'");
}
$ids_qpart = join(" OR ", $tmp_ids);
if ($cmode == 0) {
db_query($link, "UPDATE ttrss_user_entries SET
marked = false,last_read = NOW()
WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
} else if ($cmode == 1) {
db_query($link, "UPDATE ttrss_user_entries SET
marked = true
WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
} else {
db_query($link, "UPDATE ttrss_user_entries SET
marked = NOT marked,last_read = NOW()
WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
}
}
private function publishArticlesById($link, $ids, $cmode) {
$tmp_ids = array();
foreach ($ids as $id) {
array_push($tmp_ids, "ref_id = '$id'");
}
$ids_qpart = join(" OR ", $tmp_ids);
if ($cmode == 0) {
db_query($link, "UPDATE ttrss_user_entries SET
published = false,last_read = NOW()
WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
} else if ($cmode == 1) {
db_query($link, "UPDATE ttrss_user_entries SET
published = true,last_read = NOW()
WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
} else {
db_query($link, "UPDATE ttrss_user_entries SET
published = NOT published,last_read = NOW()
WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
}
if (PUBSUBHUBBUB_HUB) {
$rss_link = get_self_url_prefix() .
"/public.php?op=rss&id=-2&key=" .
get_feed_access_key($link, -2, false);
$p = new Publisher(PUBSUBHUBBUB_HUB);
$pubsub_result = $p->publish_update($rss_link);
}
}
}
?>