init.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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, ref_id 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. $ref_id = db_fetch_result($result, 0, "ref_id");
  63. if (!$uuid) {
  64. $uuid = db_escape_string(uniqid_short());
  65. db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$param'
  66. AND owner_uid = " . $_SESSION['uid']);
  67. }
  68. print __("You can share this article by the following unique URL:") . "<br/>";
  69. $url_path = get_self_url_prefix();
  70. $url_path .= "/public.php?op=share&key=$uuid";
  71. print "<div class=\"tagCloudContainer\">";
  72. print "<a id='gen_article_url' href='$url_path' target='_blank'>$url_path</a>";
  73. print "</div>";
  74. /* if (!label_find_id(__('Shared'), $_SESSION["uid"]))
  75. label_create(__('Shared'), $_SESSION["uid"]);
  76. label_add_article($ref_id, __('Shared'), $_SESSION['uid']); */
  77. }
  78. print "<div align='center'>";
  79. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').unshare()\">".
  80. __('Unshare article')."</button>";
  81. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').newurl()\">".
  82. __('Generate new URL')."</button>";
  83. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">".
  84. __('Close this window')."</button>";
  85. print "</div>";
  86. }
  87. function api_version() {
  88. return 2;
  89. }
  90. }
  91. ?>