init.php 3.4 KB

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