]> git.wh0rd.org - tt-rss.git/blobdiff - classes/article.php
rpc: move completeTags to article
[tt-rss.git] / classes / article.php
index 595c6c4325cad16d8055333be98d349daf2858f0..e75af0e7a457375cf0fef0e501d7f996dab695f1 100644 (file)
@@ -2,7 +2,7 @@
 class Article extends Handler_Protected {
 
        function csrf_ignore($method) {
-               $csrf_ignored = array("redirect");
+               $csrf_ignored = array("redirect", "editarticletags");
 
                return array_search($method, $csrf_ignored) !== false;
        }
@@ -122,14 +122,16 @@ class Article extends Handler_Protected {
                                db_query($link, "UPDATE ttrss_entries SET
                                        content = '$content', content_hash = '$content_hash' WHERE id = '$ref_id'");
 
-                               db_query($link, "UPDATE ttrss_user_entries SET published = true WHERE
+                               db_query($link, "UPDATE ttrss_user_entries SET published = true,
+                                               last_published = NOW() WHERE
                                                int_id = '$int_id' AND owner_uid = '$owner_uid'");
                        } else {
 
                                db_query($link, "INSERT INTO ttrss_user_entries
-                                       (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread)
+                                       (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache,
+                                               last_read, note, unread, last_published)
                                        VALUES
-                                       ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");
+                                       ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false, NOW())");
                        }
 
                        if (count($labels) != 0) {
@@ -152,9 +154,10 @@ class Article extends Handler_Protected {
                                $ref_id = db_fetch_result($result, 0, "id");
 
                                db_query($link, "INSERT INTO ttrss_user_entries
-                                       (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread)
+                                       (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache,
+                                               last_read, note, unread, last_published)
                                        VALUES
-                                       ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");
+                                       ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false, NOW())");
 
                                if (count($labels) != 0) {
                                        foreach ($labels as $label) {
@@ -171,6 +174,131 @@ class Article extends Handler_Protected {
                return $rc;
        }
 
+       function editArticleTags() {
+
+               print __("Tags for this article (separated by commas):")."<br>";
+
+               $param = db_escape_string($this->link, $_REQUEST['param']);
+
+               $tags = get_article_tags($this->link, db_escape_string($this->link, $param));
+
+               $tags_str = join(", ", $tags);
+
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$param\">";
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"article\">";
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setArticleTags\">";
+
+               print "<table width='100%'><tr><td>";
+
+               print "<textarea dojoType=\"dijit.form.SimpleTextarea\" rows='4'
+                       style='font-size : 12px; width : 100%' id=\"tags_str\"
+                       name='tags_str'>$tags_str</textarea>
+               <div class=\"autocomplete\" id=\"tags_choices\"
+                               style=\"display:none\"></div>";
+
+               print "</td></tr></table>";
+
+               print "<div class='dlgButtons'>";
+
+               print "<button dojoType=\"dijit.form.Button\"
+                       onclick=\"dijit.byId('editTagsDlg').execute()\">".__('Save')."</button> ";
+               print "<button dojoType=\"dijit.form.Button\"
+                       onclick=\"dijit.byId('editTagsDlg').hide()\">".__('Cancel')."</button>";
+               print "</div>";
+
+       }
+
+       function setScore() {
+               $ids = db_escape_string($this->link, $_REQUEST['id']);
+               $score = (int)db_escape_string($this->link, $_REQUEST['score']);
+
+               db_query($this->link, "UPDATE ttrss_user_entries SET
+                       score = '$score' WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
+
+               print json_encode(array("id" => $id,
+                       "score_pic" => get_score_pic($score)));
+       }
+
+
+       function setArticleTags() {
+
+               $id = db_escape_string($this->link, $_REQUEST["id"]);
+
+               $tags_str = db_escape_string($this->link, $_REQUEST["tags_str"]);
+               $tags = array_unique(trim_array(explode(",", $tags_str)));
+
+               db_query($this->link, "BEGIN");
+
+               $result = db_query($this->link, "SELECT int_id FROM ttrss_user_entries WHERE
+                               ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1");
+
+               if (db_num_rows($result) == 1) {
+
+                       $tags_to_cache = array();
+
+                       $int_id = db_fetch_result($result, 0, "int_id");
+
+                       db_query($this->link, "DELETE FROM ttrss_tags WHERE
+                               post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
+
+                       foreach ($tags as $tag) {
+                               $tag = sanitize_tag($tag);
+
+                               if (!tag_is_valid($tag)) {
+                                       continue;
+                               }
+
+                               if (preg_match("/^[0-9]*$/", $tag)) {
+                                       continue;
+                               }
+
+                               //                                      print "<!-- $id : $int_id : $tag -->";
+
+                               if ($tag != '') {
+                                       db_query($this->link, "INSERT INTO ttrss_tags
+                                                               (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
+                               }
+
+                               array_push($tags_to_cache, $tag);
+                       }
+
+                       /* update tag cache */
+
+                       sort($tags_to_cache);
+                       $tags_str = join(",", $tags_to_cache);
+
+                       db_query($this->link, "UPDATE ttrss_user_entries
+                               SET tag_cache = '$tags_str' WHERE ref_id = '$id'
+                                               AND owner_uid = " . $_SESSION["uid"]);
+               }
+
+               db_query($this->link, "COMMIT");
+
+               $tags = get_article_tags($this->link, $id);
+               $tags_str = format_tags_string($tags, $id);
+               $tags_str_full = join(", ", $tags);
+
+               if (!$tags_str_full) $tags_str_full = __("no tags");
+
+               print json_encode(array("id" => (int)$id,
+                               "content" => $tags_str, "content_full" => $tags_str_full));
+       }
+
+
+       function completeTags() {
+               $search = db_escape_string($this->link, $_REQUEST["search"]);
+
+               $result = db_query($this->link, "SELECT DISTINCT tag_name FROM ttrss_tags
+                               WHERE owner_uid = '".$_SESSION["uid"]."' AND
+                               tag_name LIKE '$search%' ORDER BY tag_name
+                               LIMIT 10");
+
+               print "<ul>";
+               while ($line = db_fetch_assoc($result)) {
+                       print "<li>" . $line["tag_name"] . "</li>";
+               }
+               print "</ul>";
+       }
 
 
 }