]>
git.wh0rd.org - tt-rss.git/blob - classes/mail_button.php
2 class Mail_Button
extends Plugin_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')."'>";
10 function emailArticle() {
12 $param = db_escape_string($_REQUEST['param']);
14 $secretkey = sha1(uniqid(rand(), true));
16 $_SESSION['email_secretkey'] = $secretkey;
18 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"secretkey\" value=\"$secretkey\">";
19 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
20 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"buttonPlugin\">";
21 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"mail\">";
22 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin_method\" value=\"sendEmail\">";
24 $result = db_query($this->link
, "SELECT email, full_name FROM ttrss_users WHERE
25 id = " . $_SESSION["uid"]);
27 $user_email = htmlspecialchars(db_fetch_result($result, 0, "email"));
28 $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
30 if (!$user_name) $user_name = $_SESSION['name'];
32 $_SESSION['email_replyto'] = $user_email;
33 $_SESSION['email_fromname'] = $user_name;
35 require_once "lib/MiniTemplator.class.php";
37 $tpl = new MiniTemplator
;
38 $tpl_t = new MiniTemplator
;
40 $tpl->readTemplateFromFile("templates/email_article_template.txt");
42 $tpl->setVariable('USER_NAME', $_SESSION["name"]);
43 $tpl->setVariable('USER_EMAIL', $user_email);
44 $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"]);
47 $result = db_query($this->link
, "SELECT link, content, title
48 FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND
49 id IN ($param) AND owner_uid = " . $_SESSION["uid"]);
51 if (db_num_rows($result) > 1) {
52 $subject = __("[Forwarded]") . " " . __("Multiple articles");
55 while ($line = db_fetch_assoc($result)) {
58 $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
60 $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
61 $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
63 $tpl->addBlock('article');
66 $tpl->addBlock('email');
69 $tpl->generateOutputToString($content);
71 print "<table width='100%'><tr><td>";
77 print "<input dojoType=\"dijit.form.TextBox\" disabled=\"1\" style=\"width : 30em;\"
78 value=\"$user_name <$user_email>\">";
80 print "</td></tr><tr><td>";
86 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
87 style=\"width : 30em;\"
88 name=\"destination\" id=\"emailArticleDlg_destination\">";
90 print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\"
91 style=\"z-index: 30; display : none\"></div>";
93 print "</td></tr><tr><td>";
99 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
100 style=\"width : 30em;\"
101 name=\"subject\" value=\"$subject\" id=\"subject\">";
105 print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 100%' rows=\"20\"
106 name='content'>$content</textarea>";
108 print "</td></tr></table>";
110 print "<div class='dlgButtons'>";
111 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').execute()\">".__('Send e-mail')."</button> ";
112 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Cancel')."</button>";
118 function sendEmail() {
119 $secretkey = $_REQUEST['secretkey'];
121 require_once 'lib/phpmailer/class.phpmailer.php';
125 if ($_SESSION['email_secretkey'] &&
126 $secretkey == $_SESSION['email_secretkey']) {
128 $_SESSION['email_secretkey'] = '';
130 $destination = $_REQUEST['destination'];
131 $subject = $_REQUEST['subject'];
132 $content = $_REQUEST['content'];
134 $replyto = strip_tags($_SESSION['email_replyto']);
135 $fromname = strip_tags($_SESSION['email_fromname']);
137 $mail = new PHPMailer();
139 $mail->PluginDir
= "lib/phpmailer/";
140 $mail->SetLanguage("en", "lib/phpmailer/language/");
142 $mail->CharSet
= "UTF-8";
144 $mail->From
= $replyto;
145 $mail->FromName
= $fromname;
146 $mail->AddAddress($destination);
149 $mail->Host
= SMTP_HOST
;
150 $mail->Mailer
= "smtp";
151 $mail->SMTPAuth
= SMTP_LOGIN
!= '';
152 $mail->Username
= SMTP_LOGIN
;
153 $mail->Password
= SMTP_PASSWORD
;
156 $mail->IsHTML(false);
157 $mail->Subject
= $subject;
158 $mail->Body
= $content;
163 $reply['error'] = $mail->ErrorInfo
;
165 save_email_address($this->link
, db_escape_string($destination));
166 $reply['message'] = "UPDATE_COUNTERS";
170 $reply['error'] = "Not authorized.";
173 print json_encode($reply);
176 function completeEmails() {
177 $search = db_escape_string($_REQUEST["search"]);
181 foreach ($_SESSION['stored_emails'] as $email) {
182 if (strpos($email, $search) !== false) {
183 print "<li>$email</li>";