]>
git.wh0rd.org - tt-rss.git/blob - plugins/mail/init.php
2 class Mail
extends Plugin
{
8 "Share article via email",
12 function init($host) {
15 $host->add_hook($host::HOOK_ARTICLE_BUTTON
, $this);
19 return file_get_contents(dirname(__FILE__
) . "/mail.js");
22 function hook_article_button($line) {
23 return "<img src=\"plugins/mail/mail.png\"
24 class='tagsPic' style=\"cursor : pointer\"
25 onclick=\"emailArticle(".$line["id"].")\"
26 alt='Zoom' title='".__('Forward by email')."'>";
29 function emailArticle() {
31 $param = db_escape_string($_REQUEST['param']);
33 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">";
34 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"mail\">";
35 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"sendEmail\">";
37 $result = db_query("SELECT email, full_name FROM ttrss_users WHERE
38 id = " . $_SESSION["uid"]);
40 $user_email = htmlspecialchars(db_fetch_result($result, 0, "email"));
41 $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
43 if (!$user_name) $user_name = $_SESSION['name'];
45 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"from_email\" value=\"$user_email\">";
46 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"from_name\" value=\"$user_name\">";
48 require_once "lib/MiniTemplator.class.php";
50 $tpl = new MiniTemplator
;
51 $tpl_t = new MiniTemplator
;
53 $templ_name = "templates/email_article_template.txt";
54 if(file_exists("templates/my_email_article_template.txt"))
55 $templ_name = "templates/my_email_article_template.txt";
56 $tpl->readTemplateFromFile($templ_name);
58 $tpl->setVariable('USER_NAME', $_SESSION["name"], true);
59 $tpl->setVariable('USER_EMAIL', $user_email, true);
60 $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"], true);
62 $result = db_query("SELECT link, content, title, note
63 FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND
64 id IN ($param) AND owner_uid = " . $_SESSION["uid"]);
66 if (db_num_rows($result) > 1) {
67 $subject = __("[Forwarded]") . " " . __("Multiple articles");
70 while ($line = db_fetch_assoc($result)) {
73 $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
75 $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
76 $tnote = strip_tags($line["note"]);
78 $tpl->setVariable('ARTICLE_NOTE', $tnote, true);
79 $tpl->addBlock('note');
81 $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
83 $tpl->addBlock('article');
86 $tpl->addBlock('email');
89 $tpl->generateOutputToString($content);
91 print "<table width='100%'><tr><td>";
97 print "<input dojoType=\"dijit.form.TextBox\" disabled=\"1\" style=\"width : 30em;\"
98 value=\"$user_name <$user_email>\">";
100 print "</td></tr><tr><td>";
106 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
107 style=\"width : 30em;\"
108 name=\"destination\" id=\"emailArticleDlg_destination\">";
110 print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\"
111 style=\"z-index: 30; display : none\"></div>";
113 print "</td></tr><tr><td>";
115 print __('Subject:');
119 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
120 style=\"width : 30em;\"
121 name=\"subject\" value=\"$subject\" id=\"subject\">";
125 print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 100%' rows=\"20\"
126 name='content'>$content</textarea>";
128 print "</td></tr></table>";
130 print "<div class='dlgButtons'>";
131 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').execute()\">".__('Send e-mail')."</button> ";
132 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Cancel')."</button>";
138 function sendEmail() {
139 require_once 'classes/ttrssmailer.php';
143 $mail = new ttrssMailer();
145 $mail->From
= strip_tags($_REQUEST['from_email']);
146 $mail->FromName
= strip_tags($_REQUEST['from_name']);
147 //$mail->AddAddress($_REQUEST['destination']);
148 $addresses = explode(';', $_REQUEST['destination']);
149 foreach($addresses as $nextaddr)
150 $mail->AddAddress($nextaddr);
152 $mail->IsHTML(false);
153 $mail->Subject
= $_REQUEST['subject'];
154 $mail->Body
= $_REQUEST['content'];
159 $reply['error'] = $mail->ErrorInfo
;
161 save_email_address(db_escape_string($destination));
162 $reply['message'] = "UPDATE_COUNTERS";
165 print json_encode($reply);
168 function completeEmails() {
169 $search = db_escape_string($_REQUEST["search"]);
173 foreach ($_SESSION['stored_emails'] as $email) {
174 if (strpos($email, $search) !== false) {
175 print "<li>$email</li>";
182 function api_version() {