init.php 6.5 KB

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