init.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. class Share extends Plugin {
  3. private $host;
  4. function about() {
  5. return array(1.0,
  6. "Share article by unique URL",
  7. "fox");
  8. }
  9. function init($host) {
  10. $this->host = $host;
  11. $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
  12. $host->add_hook($host::HOOK_PREFS_TAB_SECTION, $this);
  13. }
  14. function get_js() {
  15. return file_get_contents(dirname(__FILE__) . "/share.js");
  16. }
  17. function get_prefs_js() {
  18. return file_get_contents(dirname(__FILE__) . "/share_prefs.js");
  19. }
  20. function unshare() {
  21. $id = db_escape_string($_REQUEST['id']);
  22. db_query("UPDATE ttrss_user_entries SET uuid = '' WHERE int_id = '$id'
  23. AND owner_uid = " . $_SESSION['uid']);
  24. print "OK";
  25. }
  26. function hook_prefs_tab_section($id) {
  27. if ($id == "prefFeedsPublishedGenerated") {
  28. print "<p>" . __("You can disable all articles shared by unique URLs here.") . "</p>";
  29. print "<button class=\"danger\" dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">".
  30. __('Unshare all articles')."</button> ";
  31. print "</p>";
  32. }
  33. }
  34. // Silent
  35. function clearArticleKeys() {
  36. db_query("UPDATE ttrss_user_entries SET uuid = '' WHERE
  37. owner_uid = " . $_SESSION["uid"]);
  38. return;
  39. }
  40. function newkey() {
  41. $id = db_escape_string($_REQUEST['id']);
  42. $uuid = db_escape_string(uniqid_short());
  43. db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$id'
  44. AND owner_uid = " . $_SESSION['uid']);
  45. print json_encode(array("link" => $uuid));
  46. }
  47. function hook_article_button($line) {
  48. $img = $line['uuid'] ? "share.png" : "notshared.png";
  49. return "<img id='SHARE-IMG-".$line['int_id']."' src=\"plugins/share/$img\"
  50. class='tagsPic' style=\"cursor : pointer\"
  51. onclick=\"shareArticle(".$line['int_id'].")\"
  52. title='".__('Share by URL')."'>";
  53. }
  54. function shareArticle() {
  55. $param = db_escape_string($_REQUEST['param']);
  56. $result = db_query("SELECT uuid FROM ttrss_user_entries WHERE int_id = '$param'
  57. AND owner_uid = " . $_SESSION['uid']);
  58. if (db_num_rows($result) == 0) {
  59. print "Article not found.";
  60. } else {
  61. $uuid = db_fetch_result($result, 0, "uuid");
  62. if (!$uuid) {
  63. $uuid = db_escape_string(uniqid_short());
  64. db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$param'
  65. AND owner_uid = " . $_SESSION['uid']);
  66. }
  67. print __("You can share this article by the following unique URL:") . "<br/>";
  68. $url_path = get_self_url_prefix();
  69. $url_path .= "/public.php?op=share&key=$uuid";
  70. print "<div class=\"tagCloudContainer\">";
  71. print "<a id='gen_article_url' href='$url_path' target='_blank' rel='noopener noreferrer'>$url_path</a>";
  72. print "</div>";
  73. /* if (!label_find_id(__('Shared'), $_SESSION["uid"]))
  74. label_create(__('Shared'), $_SESSION["uid"]);
  75. label_add_article($ref_id, __('Shared'), $_SESSION['uid']); */
  76. }
  77. print "<div align='center'>";
  78. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').unshare()\">".
  79. __('Unshare article')."</button>";
  80. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').newurl()\">".
  81. __('Generate new URL')."</button>";
  82. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">".
  83. __('Close this window')."</button>";
  84. print "</div>";
  85. }
  86. function api_version() {
  87. return 2;
  88. }
  89. }