summaryrefslogtreecommitdiff
path: root/classes/api.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/api.php')
-rwxr-xr-xclasses/api.php96
1 files changed, 43 insertions, 53 deletions
diff --git a/classes/api.php b/classes/api.php
index 339e9eef1..3bba4fa8d 100755
--- a/classes/api.php
+++ b/classes/api.php
@@ -1,7 +1,7 @@
<?php
class API extends Handler {
- const API_LEVEL = 14;
+ const API_LEVEL = 15;
const STATUS_OK = 0;
const STATUS_ERR = 1;
@@ -74,10 +74,10 @@ class API extends Handler {
}
if (get_pref("ENABLE_API_ACCESS", $uid)) {
- if (authenticate_user($login, $password, false, Auth_Base::AUTH_SERVICE_API)) { // try login with normal password
+ if (UserHelper::authenticate($login, $password, false, Auth_Base::AUTH_SERVICE_API)) { // try login with normal password
$this->wrap(self::STATUS_OK, array("session_id" => session_id(),
"api_level" => self::API_LEVEL));
- } else if (authenticate_user($login, $password_base64, false, Auth_Base::AUTH_SERVICE_API)) { // else try with base64_decoded password
+ } else if (UserHelper::authenticate($login, $password_base64, false, Auth_Base::AUTH_SERVICE_API)) { // else try with base64_decoded password
$this->wrap(self::STATUS_OK, array("session_id" => session_id(),
"api_level" => self::API_LEVEL));
} else { // else we are not logged in
@@ -91,7 +91,7 @@ class API extends Handler {
}
function logout() {
- logout_user();
+ Pref_Users::logout_user();
$this->wrap(self::STATUS_OK, array("status" => "OK"));
}
@@ -117,10 +117,10 @@ class API extends Handler {
function getFeeds() {
$cat_id = clean($_REQUEST["cat_id"]);
- $unread_only = API::param_to_bool(clean($_REQUEST["unread_only"]));
+ $unread_only = self::param_to_bool(clean($_REQUEST["unread_only"]));
$limit = (int) clean($_REQUEST["limit"]);
$offset = (int) clean($_REQUEST["offset"]);
- $include_nested = API::param_to_bool(clean($_REQUEST["include_nested"]));
+ $include_nested = self::param_to_bool(clean($_REQUEST["include_nested"]));
$feeds = $this->api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested);
@@ -128,9 +128,9 @@ class API extends Handler {
}
function getCategories() {
- $unread_only = API::param_to_bool(clean($_REQUEST["unread_only"]));
- $enable_nested = API::param_to_bool(clean($_REQUEST["enable_nested"]));
- $include_empty = API::param_to_bool(clean($_REQUEST['include_empty']));
+ $unread_only = self::param_to_bool(clean($_REQUEST["unread_only"]));
+ $enable_nested = self::param_to_bool(clean($_REQUEST["enable_nested"]));
+ $include_empty = self::param_to_bool(clean($_REQUEST['include_empty']));
// TODO do not return empty categories, return Uncategorized and standard virtual cats
@@ -160,9 +160,9 @@ class API extends Handler {
$unread += Feeds::getCategoryChildrenUnread($line["id"]);
if ($unread || !$unread_only) {
- array_push($cats, array("id" => $line["id"],
+ array_push($cats, array("id" => (int) $line["id"],
"title" => $line["title"],
- "unread" => $unread,
+ "unread" => (int) $unread,
"order_id" => (int) $line["order_id"],
));
}
@@ -174,9 +174,9 @@ class API extends Handler {
$unread = getFeedUnread($cat_id, true);
if ($unread || !$unread_only) {
- array_push($cats, array("id" => $cat_id,
+ array_push($cats, array("id" => (int) $cat_id,
"title" => Feeds::getCategoryTitle($cat_id),
- "unread" => $unread));
+ "unread" => (int) $unread));
}
}
}
@@ -196,39 +196,25 @@ class API extends Handler {
$offset = (int)clean($_REQUEST["skip"]);
$filter = clean($_REQUEST["filter"]);
- $is_cat = API::param_to_bool(clean($_REQUEST["is_cat"]));
- $show_excerpt = API::param_to_bool(clean($_REQUEST["show_excerpt"]));
- $show_content = API::param_to_bool(clean($_REQUEST["show_content"]));
+ $is_cat = self::param_to_bool(clean($_REQUEST["is_cat"]));
+ $show_excerpt = self::param_to_bool(clean($_REQUEST["show_excerpt"]));
+ $show_content = self::param_to_bool(clean($_REQUEST["show_content"]));
/* all_articles, unread, adaptive, marked, updated */
$view_mode = clean($_REQUEST["view_mode"]);
- $include_attachments = API::param_to_bool(clean($_REQUEST["include_attachments"]));
+ $include_attachments = self::param_to_bool(clean($_REQUEST["include_attachments"]));
$since_id = (int)clean($_REQUEST["since_id"]);
- $include_nested = API::param_to_bool(clean($_REQUEST["include_nested"]));
+ $include_nested = self::param_to_bool(clean($_REQUEST["include_nested"]));
$sanitize_content = !isset($_REQUEST["sanitize"]) ||
- API::param_to_bool($_REQUEST["sanitize"]);
- $force_update = API::param_to_bool(clean($_REQUEST["force_update"]));
- $has_sandbox = API::param_to_bool(clean($_REQUEST["has_sandbox"]));
+ self::param_to_bool($_REQUEST["sanitize"]);
+ $force_update = self::param_to_bool(clean($_REQUEST["force_update"]));
+ $has_sandbox = self::param_to_bool(clean($_REQUEST["has_sandbox"]));
$excerpt_length = (int)clean($_REQUEST["excerpt_length"]);
$check_first_id = (int)clean($_REQUEST["check_first_id"]);
- $include_header = API::param_to_bool(clean($_REQUEST["include_header"]));
+ $include_header = self::param_to_bool(clean($_REQUEST["include_header"]));
$_SESSION['hasSandbox'] = $has_sandbox;
- $skip_first_id_check = false;
-
- $override_order = false;
- switch (clean($_REQUEST["order_by"])) {
- case "title":
- $override_order = "ttrss_entries.title, date_entered, updated";
- break;
- case "date_reverse":
- $override_order = "score DESC, date_entered, updated";
- $skip_first_id_check = true;
- break;
- case "feed_dates":
- $override_order = "updated DESC";
- break;
- }
+ list($override_order, $skip_first_id_check) = Feeds::order_to_override_query(clean($_REQUEST["order_by"]));
/* do not rely on params below */
@@ -313,7 +299,7 @@ class API extends Handler {
$article_ids = explode(",", clean($_REQUEST["article_id"]));
$sanitize_content = !isset($_REQUEST["sanitize"]) ||
- API::param_to_bool($_REQUEST["sanitize"]);
+ self::param_to_bool($_REQUEST["sanitize"]);
if ($article_ids) {
@@ -342,9 +328,9 @@ class API extends Handler {
"title" => $line["title"],
"link" => $line["link"],
"labels" => Article::get_article_labels($line['id']),
- "unread" => API::param_to_bool($line["unread"]),
- "marked" => API::param_to_bool($line["marked"]),
- "published" => API::param_to_bool($line["published"]),
+ "unread" => self::param_to_bool($line["unread"]),
+ "marked" => self::param_to_bool($line["marked"]),
+ "published" => self::param_to_bool($line["published"]),
"comments" => $line["comments"],
"author" => $line["author"],
"updated" => (int) strtotime($line["updated"]),
@@ -357,9 +343,9 @@ class API extends Handler {
);
if ($sanitize_content) {
- $article["content"] = sanitize(
+ $article["content"] = Sanitizer::sanitize(
$line["content"],
- API::param_to_bool($line['hide_images']),
+ self::param_to_bool($line['hide_images']),
false, $line["site_url"], false, $line["id"]);
} else {
$article["content"] = $line["content"];
@@ -411,8 +397,12 @@ class API extends Handler {
function catchupFeed() {
$feed_id = clean($_REQUEST["feed_id"]);
$is_cat = clean($_REQUEST["is_cat"]);
+ @$mode = clean($_REQUEST["mode"]);
+
+ if (!in_array($mode, ["all", "1day", "1week", "2week"]))
+ $mode = "all";
- Feeds::catchup_feed($feed_id, $is_cat);
+ Feeds::catchup_feed($feed_id, $is_cat, $_SESSION["uid"], $mode);
$this->wrap(self::STATUS_OK, array("status" => "OK"));
}
@@ -463,7 +453,7 @@ class API extends Handler {
$article_ids = explode(",", clean($_REQUEST["article_ids"]));
$label_id = (int) clean($_REQUEST['label_id']);
- $assign = API::param_to_bool(clean($_REQUEST['assign']));
+ $assign = self::param_to_bool(clean($_REQUEST['assign']));
$label = Labels::find_caption(Labels::feed_to_label_id($label_id), $_SESSION["uid"]);
@@ -670,7 +660,7 @@ class API extends Handler {
if ($row = $sth->fetch()) {
$last_updated = strtotime($row["last_updated"]);
- $cache_images = API::param_to_bool($row["cache_images"]);
+ $cache_images = self::param_to_bool($row["cache_images"]);
if (!$cache_images && time() - $last_updated > 120) {
RSSUtils::update_rss_feed($feed_id, true);
@@ -740,9 +730,9 @@ class API extends Handler {
$headline_row = array(
"id" => (int)$line["id"],
"guid" => $line["guid"],
- "unread" => API::param_to_bool($line["unread"]),
- "marked" => API::param_to_bool($line["marked"]),
- "published" => API::param_to_bool($line["published"]),
+ "unread" => self::param_to_bool($line["unread"]),
+ "marked" => self::param_to_bool($line["marked"]),
+ "published" => self::param_to_bool($line["published"]),
"updated" => (int)strtotime($line["updated"]),
"is_updated" => $is_updated,
"title" => $line["title"],
@@ -762,9 +752,9 @@ class API extends Handler {
if ($show_content) {
if ($sanitize_content) {
- $headline_row["content"] = sanitize(
+ $headline_row["content"] = Sanitizer::sanitize(
$line["content"],
- API::param_to_bool($line['hide_images']),
+ self::param_to_bool($line['hide_images']),
false, $line["site_url"], false, $line["id"]);
} else {
$headline_row["content"] = $line["content"];
@@ -782,7 +772,7 @@ class API extends Handler {
$headline_row["comments_count"] = (int)$line["num_comments"];
$headline_row["comments_link"] = $line["comments"];
- $headline_row["always_display_attachments"] = API::param_to_bool($line["always_display_enclosures"]);
+ $headline_row["always_display_attachments"] = self::param_to_bool($line["always_display_enclosures"]);
$headline_row["author"] = $line["author"];
@@ -841,7 +831,7 @@ class API extends Handler {
}
function getFeedTree() {
- $include_empty = API::param_to_bool(clean($_REQUEST['include_empty']));
+ $include_empty = self::param_to_bool(clean($_REQUEST['include_empty']));
$pf = new Pref_Feeds($_REQUEST);