init.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_warning(__("You can disable all articles shared by unique URLs here."));
  29. print "<p>";
  30. print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">".
  31. __('Unshare all articles')."</button> ";
  32. print "</p>";
  33. }
  34. }
  35. // Silent
  36. function clearArticleKeys() {
  37. db_query("UPDATE ttrss_user_entries SET uuid = '' WHERE
  38. owner_uid = " . $_SESSION["uid"]);
  39. return;
  40. }
  41. function newkey() {
  42. $id = db_escape_string($_REQUEST['id']);
  43. $uuid = db_escape_string(sha1(uniqid(rand(), true)));
  44. db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$id'
  45. AND owner_uid = " . $_SESSION['uid']);
  46. print json_encode(array("link" => $uuid));
  47. }
  48. function hook_article_button($line) {
  49. $img = $line['uuid'] ? "share.png" : "notshared.png";
  50. return "<img id='SHARE-IMG-".$line['int_id']."' src=\"plugins/share/$img\"
  51. class='tagsPic' style=\"cursor : pointer\"
  52. onclick=\"shareArticle(".$line['int_id'].")\"
  53. title='".__('Share by URL')."'>";
  54. }
  55. function shareArticle() {
  56. $param = db_escape_string($_REQUEST['param']);
  57. $result = db_query("SELECT uuid, ref_id FROM ttrss_user_entries WHERE int_id = '$param'
  58. AND owner_uid = " . $_SESSION['uid']);
  59. if (db_num_rows($result) == 0) {
  60. print "Article not found.";
  61. } else {
  62. $uuid = db_fetch_result($result, 0, "uuid");
  63. $ref_id = db_fetch_result($result, 0, "ref_id");
  64. if (!$uuid) {
  65. $uuid = db_escape_string(sha1(uniqid(rand(), true)));
  66. db_query("UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$param'
  67. AND owner_uid = " . $_SESSION['uid']);
  68. }
  69. print "<h2>". __("You can share this article by the following unique URL:") . "</h2>";
  70. $url_path = get_self_url_prefix();
  71. $url_path .= "/public.php?op=share&key=$uuid";
  72. print "<div class=\"tagCloudContainer\">";
  73. print "<a id='gen_article_url' href='$url_path' target='_blank'>$url_path</a>";
  74. print "</div>";
  75. /* if (!label_find_id(__('Shared'), $_SESSION["uid"]))
  76. label_create(__('Shared'), $_SESSION["uid"]);
  77. label_add_article($ref_id, __('Shared'), $_SESSION['uid']); */
  78. }
  79. print "<div align='center'>";
  80. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').unshare()\">".
  81. __('Unshare article')."</button>";
  82. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').newurl()\">".
  83. __('Generate new URL')."</button>";
  84. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">".
  85. __('Close this window')."</button>";
  86. print "</div>";
  87. }
  88. function api_version() {
  89. return 2;
  90. }
  91. }
  92. ?>