init.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. class Mail extends Plugin {
  3. /* @var PluginHost $host */
  4. private $host;
  5. function about() {
  6. return array(1.0,
  7. "Share article via email",
  8. "fox");
  9. }
  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, $this);
  14. }
  15. function get_js() {
  16. return file_get_contents(dirname(__FILE__) . "/mail.js");
  17. }
  18. function save() {
  19. $addresslist = $_POST["addresslist"];
  20. $this->host->set($this, "addresslist", $addresslist);
  21. echo __("Mail addresses saved.");
  22. }
  23. function hook_prefs_tab($args) {
  24. if ($args != "prefPrefs") return;
  25. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Mail plugin')."\">";
  26. print "<p>" . __("You can set predefined email addressed here (comma-separated list):") . "</p>";
  27. print "<form dojoType=\"dijit.form.Form\">";
  28. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  29. evt.preventDefault();
  30. if (this.validate()) {
  31. console.log(dojo.objectToQuery(this.getValues()));
  32. new Ajax.Request('backend.php', {
  33. parameters: dojo.objectToQuery(this.getValues()),
  34. onComplete: function(transport) {
  35. notify_info(transport.responseText);
  36. }
  37. });
  38. //this.reset();
  39. }
  40. </script>";
  41. print_hidden("op", "pluginhandler");
  42. print_hidden("method", "save");
  43. print_hidden("plugin", "mail");
  44. $addresslist = $this->host->get($this, "addresslist");
  45. print "<textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 50%' rows=\"3\"
  46. name='addresslist'>$addresslist</textarea>";
  47. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  48. __("Save")."</button>";
  49. print "</form>";
  50. print "</div>";
  51. }
  52. function hook_article_button($line) {
  53. return "<img src=\"plugins/mail/mail.png\"
  54. class='tagsPic' style=\"cursor : pointer\"
  55. onclick=\"emailArticle(".$line["id"].")\"
  56. alt='Zoom' title='".__('Forward by email')."'>";
  57. }
  58. function emailArticle() {
  59. $ids = explode(",", $_REQUEST['param']);
  60. $ids_qmarks = arr_qmarks($ids);
  61. print_hidden("op", "pluginhandler");
  62. print_hidden("plugin", "mail");
  63. print_hidden("method", "sendEmail");
  64. $sth = $this->pdo->prepare("SELECT email, full_name FROM ttrss_users WHERE
  65. id = ?");
  66. $sth->execute([$_SESSION['uid']]);
  67. if ($row = $sth->fetch()) {
  68. $user_email = htmlspecialchars($row['email']);
  69. $user_name = htmlspecialchars($row['full_name']);
  70. }
  71. if (!$user_name) $user_name = $_SESSION['name'];
  72. print_hidden("from_email", "$user_email");
  73. print_hidden("from_name", "$user_name");
  74. require_once "lib/MiniTemplator.class.php";
  75. $tpl = new MiniTemplator;
  76. $tpl->readTemplateFromFile("templates/email_article_template.txt");
  77. $tpl->setVariable('USER_NAME', $_SESSION["name"], true);
  78. $tpl->setVariable('USER_EMAIL', $user_email, true);
  79. $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"], true);
  80. $sth = $this->pdo->prepare("SELECT DISTINCT link, content, title, note
  81. FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND
  82. id IN ($ids_qmarks) AND owner_uid = ?");
  83. $sth->execute(array_merge($ids, [$_SESSION['uid']]));
  84. if (count($ids) > 1) {
  85. $subject = __("[Forwarded]") . " " . __("Multiple articles");
  86. }
  87. while ($line = $sth->fetch()) {
  88. if (!$subject)
  89. $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
  90. $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
  91. $tnote = strip_tags($line["note"]);
  92. if( $tnote != ''){
  93. $tpl->setVariable('ARTICLE_NOTE', $tnote, true);
  94. $tpl->addBlock('note');
  95. }
  96. $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
  97. $tpl->addBlock('article');
  98. }
  99. $tpl->addBlock('email');
  100. $content = "";
  101. $tpl->generateOutputToString($content);
  102. print "<table width='100%'><tr><td>";
  103. $addresslist = explode(",", $this->host->get($this, "addresslist"));
  104. print __('To:');
  105. print "</td><td>";
  106. /* print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
  107. style=\"width : 30em;\"
  108. name=\"destination\" id=\"emailArticleDlg_destination\">"; */
  109. print_select("destination", "", $addresslist, 'style="width: 30em" dojoType="dijit.form.ComboBox"');
  110. /* print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\"
  111. style=\"z-index: 30; display : none\"></div>"; */
  112. print "</td></tr><tr><td>";
  113. print __('Subject:');
  114. print "</td><td>";
  115. print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
  116. style=\"width : 30em;\"
  117. name=\"subject\" value=\"$subject\" id=\"subject\">";
  118. print "</td></tr>";
  119. print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\"
  120. style='height : 200px; font-size : 12px; width : 98%' rows=\"20\"
  121. name='content'>$content</textarea>";
  122. print "</td></tr></table>";
  123. print "<div class='dlgButtons'>";
  124. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').execute()\">".__('Send e-mail')."</button> ";
  125. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Cancel')."</button>";
  126. print "</div>";
  127. //return;
  128. }
  129. function sendEmail() {
  130. require_once 'classes/ttrssmailer.php';
  131. $reply = array();
  132. $mail = new ttrssMailer();
  133. $mail->AddReplyTo(strip_tags($_REQUEST['from_email']),
  134. strip_tags($_REQUEST['from_name']));
  135. //$mail->AddAddress($_REQUEST['destination']);
  136. $addresses = explode(';', $_REQUEST['destination']);
  137. foreach($addresses as $nextaddr)
  138. $mail->AddAddress($nextaddr);
  139. $mail->IsHTML(false);
  140. $mail->Subject = $_REQUEST['subject'];
  141. $mail->Body = $_REQUEST['content'];
  142. $rc = $mail->Send();
  143. if (!$rc) {
  144. $reply['error'] = $mail->ErrorInfo;
  145. } else {
  146. //save_email_address($destination);
  147. $reply['message'] = "UPDATE_COUNTERS";
  148. }
  149. print json_encode($reply);
  150. }
  151. /* function completeEmails() {
  152. $search = $_REQUEST["search"];
  153. print "<ul>";
  154. foreach ($_SESSION['stored_emails'] as $email) {
  155. if (strpos($email, $search) !== false) {
  156. print "<li>$email</li>";
  157. }
  158. }
  159. print "</ul>";
  160. } */
  161. function api_version() {
  162. return 2;
  163. }
  164. }