init.php 2.3 KB

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