init.php 2.0 KB

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