]> git.wh0rd.org - tt-rss.git/blame - plugins/note/init.php
plugins/note: use PDO
[tt-rss.git] / plugins / note / init.php
CommitLineData
55ad22fa 1<?php
5a0e0392 2class Note extends Plugin {
ef2438a5
AD
3
4 /* @var PluginHost $host */
19c73507
AD
5 private $host;
6
d2a421e3 7 function about() {
7a866114
AD
8 return array(1.0,
9 "Adds support for setting article notes",
10 "fox");
11 }
12
d2a421e3 13 function init($host) {
19c73507
AD
14 $this->host = $host;
15
16 $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
17 }
18
19 function get_js() {
20 return file_get_contents(dirname(__FILE__) . "/note.js");
21 }
22
23
24 function hook_article_button($line) {
2a3b6de0 25 return "<img src=\"plugins/note/note.png\"
19c73507
AD
26 style=\"cursor : pointer\" style=\"cursor : pointer\"
27 onclick=\"editArticleNote(".$line["id"].")\"
28 class='tagsPic' title='".__('Edit article note')."'>";
55ad22fa
AD
29 }
30
31 function edit() {
ef2438a5
AD
32 $param = $_REQUEST['param'];
33
34 $sth = $this->pdo->prepare("SELECT note FROM ttrss_user_entries WHERE
35 ref_id = ? AND owner_uid = ?");
36 $sth->execute([$param, $_SESSION['uid']]);
37
38 if ($row = $sth->fetch()) {
55ad22fa 39
ef2438a5 40 $note = $row['note'];
55ad22fa 41
ef2438a5
AD
42 print_hidden("id", "$param");
43 print_hidden("op", "pluginhandler");
44 print_hidden("method", "setNote");
45 print_hidden("plugin", "note");
55ad22fa 46
ef2438a5
AD
47 print "<table width='100%'><tr><td>";
48 print "<textarea dojoType=\"dijit.form.SimpleTextarea\"
49 style='font-size : 12px; width : 98%; height: 100px;'
50 placeHolder='body#ttrssMain { font-size : 14px; };'
51 name='note'>$note</textarea>";
52 print "</td></tr></table>";
55ad22fa 53
ef2438a5 54 }
55ad22fa
AD
55
56 print "<div class='dlgButtons'>";
57 print "<button dojoType=\"dijit.form.Button\"
58 onclick=\"dijit.byId('editNoteDlg').execute()\">".__('Save')."</button> ";
59 print "<button dojoType=\"dijit.form.Button\"
60 onclick=\"dijit.byId('editNoteDlg').hide()\">".__('Cancel')."</button>";
61 print "</div>";
62
63 }
64
65 function setNote() {
ef2438a5
AD
66 $id = $_REQUEST["id"];
67 $note = trim(strip_tags($_REQUEST["note"]));
55ad22fa 68
ef2438a5
AD
69 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET note = ?
70 WHERE ref_id = ? AND owner_uid = ?");
71 $sth->execute([$note, $id, $_SESSION['uid']]);
55ad22fa 72
7c9b5a3f 73 $formatted_note = Article::format_article_note($id, $note);
55ad22fa
AD
74
75 print json_encode(array("note" => $formatted_note,
76 "raw_length" => mb_strlen($note)));
77 }
78
106a3de9
AD
79 function api_version() {
80 return 2;
81 }
82
21ce7d9e 83}