mail.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. class Button_Mail extends Button {
  3. function render($article_id) {
  4. return "<img src=\"".theme_image($link, 'images/art-email.png')."\"
  5. class='tagsPic' style=\"cursor : pointer\"
  6. onclick=\"emailArticle($article_id)\"
  7. alt='Zoom' title='".__('Forward by email')."'>";
  8. }
  9. function emailArticle() {
  10. $param = db_escape_string($_REQUEST['param']);
  11. $secretkey = sha1(uniqid(rand(), true));
  12. $_SESSION['email_secretkey'] = $secretkey;
  13. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"secretkey\" value=\"$secretkey\">";
  14. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
  15. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"buttonPlugin\">";
  16. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"mail\">";
  17. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin_method\" value=\"sendEmail\">";
  18. $result = db_query($this->link, "SELECT email, full_name FROM ttrss_users WHERE
  19. id = " . $_SESSION["uid"]);
  20. $user_email = htmlspecialchars(db_fetch_result($result, 0, "email"));
  21. $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
  22. if (!$user_name) $user_name = $_SESSION['name'];
  23. $_SESSION['email_replyto'] = $user_email;
  24. $_SESSION['email_fromname'] = $user_name;
  25. require_once "lib/MiniTemplator.class.php";
  26. $tpl = new MiniTemplator;
  27. $tpl_t = new MiniTemplator;
  28. $tpl->readTemplateFromFile("templates/email_article_template.txt");
  29. $tpl->setVariable('USER_NAME', $_SESSION["name"]);
  30. $tpl->setVariable('USER_EMAIL', $user_email);
  31. $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"]);
  32. $result = db_query($this->link, "SELECT link, content, title
  33. FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND
  34. id IN ($param) AND owner_uid = " . $_SESSION["uid"]);
  35. if (db_num_rows($result) > 1) {
  36. $subject = __("[Forwarded]") . " " . __("Multiple articles");
  37. }
  38. while ($line = db_fetch_assoc($result)) {
  39. if (!$subject)
  40. $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
  41. $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
  42. $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
  43. $tpl->addBlock('article');
  44. }
  45. $tpl->addBlock('email');
  46. $content = "";
  47. $tpl->generateOutputToString($content);
  48. print "<table width='100%'><tr><td>";
  49. print __('From:');
  50. print "</td><td>";
  51. print "<input dojoType=\"dijit.form.TextBox\" disabled=\"1\" style=\"width : 30em;\"
  52. value=\"$user_name <$user_email>\">";
  53. print "</td></tr><tr><td>";
  54. print __('To:');
  55. print "</td><td>";
  56. print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
  57. style=\"width : 30em;\"
  58. name=\"destination\" id=\"emailArticleDlg_destination\">";
  59. print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\"
  60. style=\"z-index: 30; display : none\"></div>";
  61. print "</td></tr><tr><td>";
  62. print __('Subject:');
  63. print "</td><td>";
  64. print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
  65. style=\"width : 30em;\"
  66. name=\"subject\" value=\"$subject\" id=\"subject\">";
  67. print "</td></tr>";
  68. print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 100%' rows=\"20\"
  69. name='content'>$content</textarea>";
  70. print "</td></tr></table>";
  71. print "<div class='dlgButtons'>";
  72. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').execute()\">".__('Send e-mail')."</button> ";
  73. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Cancel')."</button>";
  74. print "</div>";
  75. //return;
  76. }
  77. function sendEmail() {
  78. $secretkey = $_REQUEST['secretkey'];
  79. require_once 'lib/phpmailer/class.phpmailer.php';
  80. $reply = array();
  81. if ($_SESSION['email_secretkey'] &&
  82. $secretkey == $_SESSION['email_secretkey']) {
  83. $_SESSION['email_secretkey'] = '';
  84. $destination = $_REQUEST['destination'];
  85. $subject = $_REQUEST['subject'];
  86. $content = $_REQUEST['content'];
  87. $replyto = strip_tags($_SESSION['email_replyto']);
  88. $fromname = strip_tags($_SESSION['email_fromname']);
  89. $mail = new PHPMailer();
  90. $mail->PluginDir = "lib/phpmailer/";
  91. $mail->SetLanguage("en", "lib/phpmailer/language/");
  92. $mail->CharSet = "UTF-8";
  93. $mail->From = $replyto;
  94. $mail->FromName = $fromname;
  95. $mail->AddAddress($destination);
  96. if (SMTP_HOST) {
  97. $mail->Host = SMTP_HOST;
  98. $mail->Mailer = "smtp";
  99. $mail->SMTPAuth = SMTP_LOGIN != '';
  100. $mail->Username = SMTP_LOGIN;
  101. $mail->Password = SMTP_PASSWORD;
  102. }
  103. $mail->IsHTML(false);
  104. $mail->Subject = $subject;
  105. $mail->Body = $content;
  106. $rc = $mail->Send();
  107. if (!$rc) {
  108. $reply['error'] = $mail->ErrorInfo;
  109. } else {
  110. save_email_address($this->link, db_escape_string($destination));
  111. $reply['message'] = "UPDATE_COUNTERS";
  112. }
  113. } else {
  114. $reply['error'] = "Not authorized.";
  115. }
  116. print json_encode($reply);
  117. }
  118. function completeEmails() {
  119. $search = db_escape_string($_REQUEST["search"]);
  120. print "<ul>";
  121. foreach ($_SESSION['stored_emails'] as $email) {
  122. if (strpos($email, $search) !== false) {
  123. print "<li>$email</li>";
  124. }
  125. }
  126. print "</ul>";
  127. }
  128. }
  129. ?>