init.php 2.0 KB

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