From 4baa1afa430aa87c49cc02e111c6b3de8491d1a3 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 16 Oct 2014 09:53:54 +0400 Subject: add force_update to api getHeadlines; bump api version to 9 --- classes/api.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'classes/api.php') diff --git a/classes/api.php b/classes/api.php index 6bcb92152..97f17cc74 100644 --- a/classes/api.php +++ b/classes/api.php @@ -2,7 +2,7 @@ class API extends Handler { - const API_LEVEL = 8; + const API_LEVEL = 9; const STATUS_OK = 0; const STATUS_ERR = 1; @@ -200,6 +200,7 @@ class API extends Handler { $include_nested = sql_bool_to_bool($_REQUEST["include_nested"]); $sanitize_content = !isset($_REQUEST["sanitize"]) || sql_bool_to_bool($_REQUEST["sanitize"]); + $force_update = sql_bool_to_bool($_REQUEST["force_update"]); $override_order = false; switch ($_REQUEST["order_by"]) { @@ -222,7 +223,7 @@ class API extends Handler { $headlines = $this->api_get_headlines($feed_id, $limit, $offset, $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order, $include_attachments, $since_id, $search, $search_mode, - $include_nested, $sanitize_content); + $include_nested, $sanitize_content, $force_update); $this->wrap(self::STATUS_OK, $headlines); } else { @@ -632,7 +633,28 @@ class API extends Handler { $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order, $include_attachments, $since_id, $search = "", $search_mode = "", - $include_nested = false, $sanitize_content = true) { + $include_nested = false, $sanitize_content = true, $force_update = false) { + + if ($force_update && $feed_id > 0 && is_numeric($feed_id)) { + // Update the feed if required with some basic flood control + + $result = db_query( + "SELECT cache_images,".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated + FROM ttrss_feeds WHERE id = '$feed_id'"); + + if (db_num_rows($result) != 0) { + $last_updated = strtotime(db_fetch_result($result, 0, "last_updated")); + $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images")); + + if (!$cache_images && time() - $last_updated > 120) { + include "rssfuncs.php"; + update_rss_feed($feed_id, true, true); + } else { + db_query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01' + WHERE id = '$feed_id'"); + } + } + } $qfh_ret = queryFeedHeadlines($feed_id, $limit, $view_mode, $is_cat, $search, $search_mode, -- cgit v1.2.3 From f71a669b7dc9e2048cfea02f39ab4ef8cde4178a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 27 Oct 2014 22:07:20 +0300 Subject: api: handle uncached labels the way main headlines function does it --- classes/api.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'classes/api.php') diff --git a/classes/api.php b/classes/api.php index 97f17cc74..730e20ab9 100644 --- a/classes/api.php +++ b/classes/api.php @@ -675,7 +675,22 @@ class API extends Handler { ($line["unread"] != "t" && $line["unread"] != "1")); $tags = explode(",", $line["tag_cache"]); - $labels = json_decode($line["label_cache"], true); + + $label_cache = $line["label_cache"]; + $labels = false; + + if ($label_cache) { + $label_cache = json_decode($label_cache, true); + + if ($label_cache) { + if ($label_cache["no-labels"] == 1) + $labels = array(); + else + $labels = $label_cache; + } + } + + if (!is_array($labels)) $labels = get_article_labels($line["id"]); //if (!$tags) $tags = get_article_tags($line["id"]); //if (!$labels) $labels = get_article_labels($line["id"]); -- cgit v1.2.3 From 9997b38e3eada4d079491110c3bc9f11b76e693b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 25 Nov 2014 13:45:21 +0300 Subject: api: allow requesting headlines as if client supports iframe sandboxing --- classes/api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'classes/api.php') diff --git a/classes/api.php b/classes/api.php index 730e20ab9..b9b1a7aa3 100644 --- a/classes/api.php +++ b/classes/api.php @@ -2,7 +2,7 @@ class API extends Handler { - const API_LEVEL = 9; + const API_LEVEL = 10; const STATUS_OK = 0; const STATUS_ERR = 1; @@ -201,6 +201,9 @@ class API extends Handler { $sanitize_content = !isset($_REQUEST["sanitize"]) || sql_bool_to_bool($_REQUEST["sanitize"]); $force_update = sql_bool_to_bool($_REQUEST["force_update"]); + $has_sandbox = sql_bool_to_bool($_REQUEST["has_sandbox"]); + + $_SESSION['hasSandbox'] = $has_sandbox; $override_order = false; switch ($_REQUEST["order_by"]) { -- cgit v1.2.3 From 3194a70a037d70f3d3ce4eb3a5882ccb748b40ff Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 29 Nov 2014 20:16:09 +0300 Subject: api: getHeadlines: add configurable excerpt_length (bump api version) --- classes/api.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'classes/api.php') diff --git a/classes/api.php b/classes/api.php index b9b1a7aa3..3c5d08408 100644 --- a/classes/api.php +++ b/classes/api.php @@ -2,7 +2,7 @@ class API extends Handler { - const API_LEVEL = 10; + const API_LEVEL = 11; const STATUS_OK = 0; const STATUS_ERR = 1; @@ -202,6 +202,7 @@ class API extends Handler { sql_bool_to_bool($_REQUEST["sanitize"]); $force_update = sql_bool_to_bool($_REQUEST["force_update"]); $has_sandbox = sql_bool_to_bool($_REQUEST["has_sandbox"]); + $excerpt_length = (int)$this->dbh->escape_string($_REQUEST["excerpt_length"]); $_SESSION['hasSandbox'] = $has_sandbox; @@ -226,7 +227,7 @@ class API extends Handler { $headlines = $this->api_get_headlines($feed_id, $limit, $offset, $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order, $include_attachments, $since_id, $search, $search_mode, - $include_nested, $sanitize_content, $force_update); + $include_nested, $sanitize_content, $force_update, $excerpt_length); $this->wrap(self::STATUS_OK, $headlines); } else { @@ -636,7 +637,7 @@ class API extends Handler { $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order, $include_attachments, $since_id, $search = "", $search_mode = "", - $include_nested = false, $sanitize_content = true, $force_update = false) { + $include_nested = false, $sanitize_content = true, $force_update = false, $excerpt_length = 100) { if ($force_update && $feed_id > 0 && is_numeric($feed_id)) { // Update the feed if required with some basic flood control @@ -669,9 +670,9 @@ class API extends Handler { $headlines = array(); while ($line = db_fetch_assoc($result)) { - $line["content_preview"] = truncate_string(strip_tags($line["content"]), 100); + $line["content_preview"] = truncate_string(strip_tags($line["content"]), $excerpt_length); foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { - $line = $p->hook_query_headlines($line, 100, true); + $line = $p->hook_query_headlines($line, $excerpt_length, true); } $is_updated = ($line["last_read"] == "" && -- cgit v1.2.3