api: add updateArticle

This commit is contained in:
Andrew Dolgov 2009-12-16 13:29:16 +03:00
parent 03e5f9eb02
commit 1c3fffbbc7
1 changed files with 47 additions and 1 deletions

View File

@ -188,12 +188,57 @@
print json_encode($headlines); print json_encode($headlines);
break; break;
case "updateArticle":
$article_id = (int) db_escape_string($_GET["article_id"]);
$mode = (int) db_escape_string($_REQUEST["mode"]);
$field_raw = (int)db_escape_string($_REQUEST["field"]);
$field = "";
$set_to = "";
switch ($field_raw) {
case 0:
$field = "marked";
break;
case 1:
$field = "published";
break;
case 2:
$field = "unread";
break;
};
switch ($mode) {
case 1:
$set_to = "true";
break;
case 0:
$set_to = "false";
break;
case 2:
$set_to = "NOT $field";
break;
}
if ($field && $set_to) {
if ($field == "unread") {
$result = db_query($link, "UPDATE ttrss_user_entries SET $field = $set_to,
last_read = NOW()
WHERE ref_id = '$article_id' AND owner_uid = " . $_SESSION["uid"]);
} else {
$result = db_query($link, "UPDATE ttrss_user_entries SET $field = $set_to
WHERE ref_id = '$article_id' AND owner_uid = " . $_SESSION["uid"]);
}
}
break;
case "getArticle": case "getArticle":
$article_id = (int)db_escape_string($_REQUEST["article_id"]); $article_id = (int)db_escape_string($_REQUEST["article_id"]);
$query = "SELECT title,link,content,feed_id,comments,int_id, $query = "SELECT title,link,content,feed_id,comments,int_id,
marked,unread, marked,unread,published,
".SUBSTRING_FOR_DATE."(updated,1,16) as updated, ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
author author
FROM ttrss_entries,ttrss_user_entries FROM ttrss_entries,ttrss_user_entries
@ -212,6 +257,7 @@
"link" => $line["link"], "link" => $line["link"],
"unread" => sql_bool_to_bool($line["unread"]), "unread" => sql_bool_to_bool($line["unread"]),
"marked" => sql_bool_to_bool($line["marked"]), "marked" => sql_bool_to_bool($line["marked"]),
"published" => sql_bool_to_bool($line["published"]),
"comments" => $line["comments"], "comments" => $line["comments"],
"author" => $line["author"], "author" => $line["author"],
"updated" => strtotime($line["updated"]), "updated" => strtotime($line["updated"]),