]> git.wh0rd.org - tt-rss.git/blob - classes/button/mail.php
support comments on simplepie properly
[tt-rss.git] / classes / button / mail.php
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
10 function emailArticle() {
11
12 $param = db_escape_string($_REQUEST['param']);
13
14 $secretkey = sha1(uniqid(rand(), true));
15
16 $_SESSION['email_secretkey'] = $secretkey;
17
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\">";
23
24 $result = db_query($this->link, "SELECT email, full_name FROM ttrss_users WHERE
25 id = " . $_SESSION["uid"]);
26
27 $user_email = htmlspecialchars(db_fetch_result($result, 0, "email"));
28 $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
29
30 if (!$user_name) $user_name = $_SESSION['name'];
31
32 $_SESSION['email_replyto'] = $user_email;
33 $_SESSION['email_fromname'] = $user_name;
34
35 require_once "lib/MiniTemplator.class.php";
36
37 $tpl = new MiniTemplator;
38 $tpl_t = new MiniTemplator;
39
40 $tpl->readTemplateFromFile("templates/email_article_template.txt");
41
42 $tpl->setVariable('USER_NAME', $_SESSION["name"]);
43 $tpl->setVariable('USER_EMAIL', $user_email);
44 $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"]);
45
46
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"]);
50
51 if (db_num_rows($result) > 1) {
52 $subject = __("[Forwarded]") . " " . __("Multiple articles");
53 }
54
55 while ($line = db_fetch_assoc($result)) {
56
57 if (!$subject)
58 $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
59
60 $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
61 $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
62
63 $tpl->addBlock('article');
64 }
65
66 $tpl->addBlock('email');
67
68 $content = "";
69 $tpl->generateOutputToString($content);
70
71 print "<table width='100%'><tr><td>";
72
73 print __('From:');
74
75 print "</td><td>";
76
77 print "<input dojoType=\"dijit.form.TextBox\" disabled=\"1\" style=\"width : 30em;\"
78 value=\"$user_name <$user_email>\">";
79
80 print "</td></tr><tr><td>";
81
82 print __('To:');
83
84 print "</td><td>";
85
86 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
87 style=\"width : 30em;\"
88 name=\"destination\" id=\"emailArticleDlg_destination\">";
89
90 print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\"
91 style=\"z-index: 30; display : none\"></div>";
92
93 print "</td></tr><tr><td>";
94
95 print __('Subject:');
96
97 print "</td><td>";
98
99 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
100 style=\"width : 30em;\"
101 name=\"subject\" value=\"$subject\" id=\"subject\">";
102
103 print "</td></tr>";
104
105 print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 100%' rows=\"20\"
106 name='content'>$content</textarea>";
107
108 print "</td></tr></table>";
109
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>";
113 print "</div>";
114
115 //return;
116 }
117
118 function sendEmail() {
119 $secretkey = $_REQUEST['secretkey'];
120
121 require_once 'lib/phpmailer/class.phpmailer.php';
122
123 $reply = array();
124
125 if ($_SESSION['email_secretkey'] &&
126 $secretkey == $_SESSION['email_secretkey']) {
127
128 $_SESSION['email_secretkey'] = '';
129
130 $destination = $_REQUEST['destination'];
131 $subject = $_REQUEST['subject'];
132 $content = $_REQUEST['content'];
133
134 $replyto = strip_tags($_SESSION['email_replyto']);
135 $fromname = strip_tags($_SESSION['email_fromname']);
136
137 $mail = new PHPMailer();
138
139 $mail->PluginDir = "lib/phpmailer/";
140 $mail->SetLanguage("en", "lib/phpmailer/language/");
141
142 $mail->CharSet = "UTF-8";
143
144 $mail->From = $replyto;
145 $mail->FromName = $fromname;
146 $mail->AddAddress($destination);
147
148 if (SMTP_HOST) {
149 $mail->Host = SMTP_HOST;
150 $mail->Mailer = "smtp";
151 $mail->SMTPAuth = SMTP_LOGIN != '';
152 $mail->Username = SMTP_LOGIN;
153 $mail->Password = SMTP_PASSWORD;
154 }
155
156 $mail->IsHTML(false);
157 $mail->Subject = $subject;
158 $mail->Body = $content;
159
160 $rc = $mail->Send();
161
162 if (!$rc) {
163 $reply['error'] = $mail->ErrorInfo;
164 } else {
165 save_email_address($this->link, db_escape_string($destination));
166 $reply['message'] = "UPDATE_COUNTERS";
167 }
168
169 } else {
170 $reply['error'] = "Not authorized.";
171 }
172
173 print json_encode($reply);
174 }
175
176 function completeEmails() {
177 $search = db_escape_string($_REQUEST["search"]);
178
179 print "<ul>";
180
181 foreach ($_SESSION['stored_emails'] as $email) {
182 if (strpos($email, $search) !== false) {
183 print "<li>$email</li>";
184 }
185 }
186
187 print "</ul>";
188 }
189
190
191 }
192 ?>