init.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. }
  13. function get_js() {
  14. return file_get_contents(dirname(__FILE__) . "/mail.js");
  15. }
  16. function hook_article_button($line) {
  17. return "<img src=\"plugins/mail/mail.png\"
  18. class='tagsPic' style=\"cursor : pointer\"
  19. onclick=\"emailArticle(".$line["id"].")\"
  20. alt='Zoom' title='".__('Forward by email')."'>";
  21. }
  22. function emailArticle() {
  23. $param = db_escape_string($_REQUEST['param']);
  24. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">";
  25. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"mail\">";
  26. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"sendEmail\">";
  27. $result = db_query("SELECT email, full_name FROM ttrss_users WHERE
  28. id = " . $_SESSION["uid"]);
  29. $user_email = htmlspecialchars(db_fetch_result($result, 0, "email"));
  30. $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
  31. if (!$user_name) $user_name = $_SESSION['name'];
  32. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"from_email\" value=\"$user_email\">";
  33. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"from_name\" value=\"$user_name\">";
  34. require_once "lib/MiniTemplator.class.php";
  35. $tpl = new MiniTemplator;
  36. $tpl_t = new MiniTemplator;
  37. $tpl->readTemplateFromFile("templates/email_article_template.txt");
  38. $tpl->setVariable('USER_NAME', $_SESSION["name"], true);
  39. $tpl->setVariable('USER_EMAIL', $user_email, true);
  40. $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"], true);
  41. $result = db_query("SELECT link, content, title, note
  42. FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND
  43. id IN ($param) AND owner_uid = " . $_SESSION["uid"]);
  44. if (db_num_rows($result) > 1) {
  45. $subject = __("[Forwarded]") . " " . __("Multiple articles");
  46. }
  47. while ($line = db_fetch_assoc($result)) {
  48. if (!$subject)
  49. $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
  50. $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
  51. $tnote = strip_tags($line["note"]);
  52. if( $tnote != ''){
  53. $tpl->setVariable('ARTICLE_NOTE', $tnote, true);
  54. $tpl->addBlock('note');
  55. }
  56. $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
  57. $tpl->addBlock('article');
  58. }
  59. $tpl->addBlock('email');
  60. $content = "";
  61. $tpl->generateOutputToString($content);
  62. print "<table width='100%'><tr><td>";
  63. print __('From:');
  64. print "</td><td>";
  65. print "<input dojoType=\"dijit.form.TextBox\" disabled=\"1\" style=\"width : 30em;\"
  66. value=\"$user_name <$user_email>\">";
  67. print "</td></tr><tr><td>";
  68. print __('To:');
  69. print "</td><td>";
  70. print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
  71. style=\"width : 30em;\"
  72. name=\"destination\" id=\"emailArticleDlg_destination\">";
  73. print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\"
  74. style=\"z-index: 30; display : none\"></div>";
  75. print "</td></tr><tr><td>";
  76. print __('Subject:');
  77. print "</td><td>";
  78. print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
  79. style=\"width : 30em;\"
  80. name=\"subject\" value=\"$subject\" id=\"subject\">";
  81. print "</td></tr>";
  82. print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 100%' rows=\"20\"
  83. name='content'>$content</textarea>";
  84. print "</td></tr></table>";
  85. print "<div class='dlgButtons'>";
  86. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').execute()\">".__('Send e-mail')."</button> ";
  87. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Cancel')."</button>";
  88. print "</div>";
  89. //return;
  90. }
  91. function sendEmail() {
  92. require_once 'classes/ttrssmailer.php';
  93. $reply = array();
  94. $mail = new ttrssMailer();
  95. $mail->From = strip_tags($_REQUEST['from_email']);
  96. $mail->FromName = strip_tags($_REQUEST['from_name']);
  97. //$mail->AddAddress($_REQUEST['destination']);
  98. $addresses = explode(';', $_REQUEST['destination']);
  99. foreach($addresses as $nextaddr)
  100. $mail->AddAddress($nextaddr);
  101. $mail->IsHTML(false);
  102. $mail->Subject = $_REQUEST['subject'];
  103. $mail->Body = $_REQUEST['content'];
  104. $rc = $mail->Send();
  105. if (!$rc) {
  106. $reply['error'] = $mail->ErrorInfo;
  107. } else {
  108. save_email_address(db_escape_string($destination));
  109. $reply['message'] = "UPDATE_COUNTERS";
  110. }
  111. print json_encode($reply);
  112. }
  113. function completeEmails() {
  114. $search = db_escape_string($_REQUEST["search"]);
  115. print "<ul>";
  116. foreach ($_SESSION['stored_emails'] as $email) {
  117. if (strpos($email, $search) !== false) {
  118. print "<li>$email</li>";
  119. }
  120. }
  121. print "</ul>";
  122. }
  123. function api_version() {
  124. return 2;
  125. }
  126. }
  127. ?>