]> git.wh0rd.org - tt-rss.git/commitdiff
move get_article_labels to Article
authorAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Thu, 4 May 2017 12:26:21 +0000 (15:26 +0300)
committerAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Thu, 4 May 2017 12:26:21 +0000 (15:26 +0300)
classes/api.php
classes/article.php
classes/feeds.php
include/labels.php
include/rssfuncs.php

index 31dd3c086a3fba5baed841db8e2cda13af201df7..cb035c86be8b20119025773b9a2ea15754b552f7 100644 (file)
@@ -354,7 +354,7 @@ class API extends Handler {
                                                "guid" => $line["guid"],
                                                "title" => $line["title"],
                                                "link" => $line["link"],
-                                               "labels" => get_article_labels($line['id']),
+                                               "labels" => Article::get_article_labels($line['id']),
                                                "unread" => sql_bool_to_bool($line["unread"]),
                                                "marked" => sql_bool_to_bool($line["marked"]),
                                                "published" => sql_bool_to_bool($line["published"]),
@@ -450,7 +450,7 @@ class API extends Handler {
                        WHERE owner_uid = '".$_SESSION['uid']."' ORDER BY caption");
 
                if ($article_id)
-                       $article_labels = get_article_labels($article_id);
+                       $article_labels = Article::get_article_labels($article_id);
                else
                        $article_labels = array();
 
@@ -740,10 +740,7 @@ class API extends Handler {
                                                }
                                        }
 
-                                       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"]);
+                                       if (!is_array($labels)) $labels = Article::get_article_labels($line["id"]);
 
                                        $headline_row = array(
                                                "id" => (int)$line["id"],
index 6d881f50ed2b2b94c9daeb5ae0ec43ea97acd193..95f1704c95f20c66ced3c39e9940e19b904a204f 100644 (file)
@@ -358,7 +358,7 @@ class Article extends Handler_Protected {
                                else
                                        label_remove_article($id, $label, $_SESSION["uid"]);
 
-                               $labels = get_article_labels($id, $_SESSION["uid"]);
+                               $labels = $this->get_article_labels($id, $_SESSION["uid"]);
 
                                array_push($reply["info-for-headlines"],
                                array("id" => $id, "labels" => $this->format_article_labels($labels)));
@@ -924,4 +924,49 @@ class Article extends Handler_Protected {
                }
        }
 
+       static function get_article_labels($id, $owner_uid = false) {
+               $rv = array();
+
+               if (!$owner_uid) $owner_uid = $_SESSION["uid"];
+
+               $result = db_query("SELECT label_cache FROM
+                       ttrss_user_entries WHERE ref_id = '$id' AND owner_uid = " .
+                       $owner_uid);
+
+               if (db_num_rows($result) > 0) {
+                       $label_cache = db_fetch_result($result, 0, "label_cache");
+
+                       if ($label_cache) {
+                               $label_cache = json_decode($label_cache, true);
+
+                               if ($label_cache["no-labels"] == 1)
+                                       return $rv;
+                               else
+                                       return $label_cache;
+                       }
+               }
+
+               $result = db_query(
+                       "SELECT DISTINCT label_id,caption,fg_color,bg_color
+                               FROM ttrss_labels2, ttrss_user_labels2
+                       WHERE id = label_id
+                               AND article_id = '$id'
+                               AND owner_uid = ". $owner_uid . "
+                       ORDER BY caption");
+
+               while ($line = db_fetch_assoc($result)) {
+                       $rk = array(label_to_feed_id($line["label_id"]),
+                               $line["caption"], $line["fg_color"],
+                               $line["bg_color"]);
+                       array_push($rv, $rk);
+               }
+
+               if (count($rv) > 0)
+                       label_update_cache($owner_uid, $id, $rv);
+               else
+                       label_update_cache($owner_uid, $id, array("no-labels" => 1));
+
+               return $rv;
+       }
+
 }
index 23571c3692a3bf5834d267ef2c4bfb93461c7536..a96e53fcf1feb50b705600de9d58714cf03bc638 100755 (executable)
@@ -350,7 +350,7 @@ class Feeds extends Handler_Protected {
                                        }
                                }
 
-                               if (!is_array($labels)) $labels = get_article_labels($id);
+                               if (!is_array($labels)) $labels = Article::get_article_labels($id);
 
                                $labels_str = "<span class=\"HLLCTR-$id\">";
                                $labels_str .= Article::format_article_labels($labels);
index 9e2674b98a931fc4fabdf8ca3ffe3bcb71d77d96..fd0d40af65eb3821a74e18aabdc89b4f4331b083 100644 (file)
                }
        }
 
-       function get_article_labels($id, $owner_uid = false) {
-               $rv = array();
-
-               if (!$owner_uid) $owner_uid = $_SESSION["uid"];
-
-               $result = db_query("SELECT label_cache FROM
-                       ttrss_user_entries WHERE ref_id = '$id' AND owner_uid = " .
-                       $owner_uid);
-
-               if (db_num_rows($result) > 0) {
-                       $label_cache = db_fetch_result($result, 0, "label_cache");
-
-                       if ($label_cache) {
-                               $label_cache = json_decode($label_cache, true);
-
-                               if ($label_cache["no-labels"] == 1)
-                                       return $rv;
-                               else
-                                       return $label_cache;
-                       }
-               }
-
-               $result = db_query(
-                       "SELECT DISTINCT label_id,caption,fg_color,bg_color
-                               FROM ttrss_labels2, ttrss_user_labels2
-                       WHERE id = label_id
-                               AND article_id = '$id'
-                               AND owner_uid = ". $owner_uid . "
-                       ORDER BY caption");
-
-               while ($line = db_fetch_assoc($result)) {
-                       $rk = array(label_to_feed_id($line["label_id"]),
-                               $line["caption"], $line["fg_color"],
-                               $line["bg_color"]);
-                       array_push($rv, $rk);
-               }
-
-               if (count($rv) > 0)
-                       label_update_cache($owner_uid, $id, $rv);
-               else
-                       label_update_cache($owner_uid, $id, array("no-labels" => 1));
-
-               return $rv;
-       }
-
-
        function label_find_caption($label, $owner_uid) {
                $result = db_query(
                        "SELECT caption FROM ttrss_labels2 WHERE id = '$label'
index a7d30d674dfc039a71a0e2d172d7f70ba627aa56..5e1bdd2cb83d03c2ec6afd8aa0e0e5c13f51e990 100644 (file)
                                if (db_num_rows($result) != 0) {
                                        $base_entry_id = db_fetch_result($result, 0, "id");
                                        $entry_stored_hash = db_fetch_result($result, 0, "content_hash");
-                                       $article_labels = get_article_labels($base_entry_id, $owner_uid);
+                                       $article_labels = Article::get_article_labels($base_entry_id, $owner_uid);
                                        $entry_language = db_fetch_result($result, 0, "lang");
 
                                        $existing_tags = Article::get_article_tags($base_entry_id, $owner_uid);