]> git.wh0rd.org - tt-rss.git/blame - plugins/mail/init.php
php: remove trailing whitespaces
[tt-rss.git] / plugins / mail / init.php
CommitLineData
1baac280 1<?php
5a0e0392 2class Mail extends Plugin {
19c73507 3
2179332a 4 /* @var PluginHost $host */
19c73507
AD
5 private $host;
6
d2a421e3 7 function about() {
7a866114 8 return array(1.0,
f044a0b8 9 "Share article via email",
7a866114
AD
10 "fox");
11 }
12
d2a421e3 13 function init($host) {
19c73507
AD
14 $this->host = $host;
15
16 $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
3e0f2090 17 $host->add_hook($host::HOOK_PREFS_TAB, $this);
19c73507
AD
18 }
19
20 function get_js() {
21 return file_get_contents(dirname(__FILE__) . "/mail.js");
22 }
23
3e0f2090 24 function save() {
2179332a 25 $addresslist = $_POST["addresslist"];
3e0f2090
AD
26
27 $this->host->set($this, "addresslist", $addresslist);
28
29 echo __("Mail addresses saved.");
30 }
31
32 function hook_prefs_tab($args) {
33 if ($args != "prefPrefs") return;
34
35 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Mail plugin')."\">";
36
37 print "<p>" . __("You can set predefined email addressed here (comma-separated list):") . "</p>";
38
39 print "<form dojoType=\"dijit.form.Form\">";
40
41 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
42 evt.preventDefault();
43 if (this.validate()) {
44 console.log(dojo.objectToQuery(this.getValues()));
45 new Ajax.Request('backend.php', {
46 parameters: dojo.objectToQuery(this.getValues()),
47 onComplete: function(transport) {
48 notify_info(transport.responseText);
49 }
50 });
51 //this.reset();
52 }
53 </script>";
54
328118d1
AD
55 print_hidden("op", "pluginhandler");
56 print_hidden("method", "save");
57 print_hidden("plugin", "mail");
3e0f2090
AD
58
59 $addresslist = $this->host->get($this, "addresslist");
60
61 print "<textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 50%' rows=\"3\"
62 name='addresslist'>$addresslist</textarea>";
63
64 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
65 __("Save")."</button>";
66
67 print "</form>";
68
69 print "</div>";
70 }
71
19c73507 72 function hook_article_button($line) {
2a3b6de0 73 return "<img src=\"plugins/mail/mail.png\"
1baac280 74 class='tagsPic' style=\"cursor : pointer\"
19c73507 75 onclick=\"emailArticle(".$line["id"].")\"
1baac280
AD
76 alt='Zoom' title='".__('Forward by email')."'>";
77 }
78
79 function emailArticle() {
80
2179332a
AD
81 $ids = explode(",", $_REQUEST['param']);
82 $ids_qmarks = arr_qmarks($ids);
1baac280 83
328118d1
AD
84 print_hidden("op", "pluginhandler");
85 print_hidden("plugin", "mail");
86 print_hidden("method", "sendEmail");
1baac280 87
2179332a 88 $sth = $this->pdo->prepare("SELECT email, full_name FROM ttrss_users WHERE
12bfce5e 89 id = ?");
2179332a 90 $sth->execute([$_SESSION['uid']]);
1baac280 91
2179332a
AD
92 if ($row = $sth->fetch()) {
93 $user_email = htmlspecialchars($row['email']);
94 $user_name = htmlspecialchars($row['full_name']);
95 }
1baac280
AD
96
97 if (!$user_name) $user_name = $_SESSION['name'];
98
328118d1
AD
99 print_hidden("from_email", "$user_email");
100 print_hidden("from_name", "$user_name");
1baac280
AD
101
102 require_once "lib/MiniTemplator.class.php";
103
104 $tpl = new MiniTemplator;
1baac280 105
a9358e1d 106 $tpl->readTemplateFromFile("templates/email_article_template.txt");
1baac280 107
1d5cf085
AD
108 $tpl->setVariable('USER_NAME', $_SESSION["name"], true);
109 $tpl->setVariable('USER_EMAIL', $user_email, true);
110 $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"], true);
1baac280 111
2179332a 112 $sth = $this->pdo->prepare("SELECT DISTINCT link, content, title, note
1baac280 113 FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND
2179332a
AD
114 id IN ($ids_qmarks) AND owner_uid = ?");
115 $sth->execute(array_merge($ids, [$_SESSION['uid']]));
1baac280 116
2179332a 117 if (count($ids) > 1) {
1baac280
AD
118 $subject = __("[Forwarded]") . " " . __("Multiple articles");
119 }
120
2179332a 121 while ($line = $sth->fetch()) {
1baac280
AD
122
123 if (!$subject)
124 $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
125
126 $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
ed7dd4bf 127 $tnote = strip_tags($line["note"]);
128 if( $tnote != ''){
129 $tpl->setVariable('ARTICLE_NOTE', $tnote, true);
130 $tpl->addBlock('note');
131 }
1baac280
AD
132 $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
133
134 $tpl->addBlock('article');
135 }
136
137 $tpl->addBlock('email');
138
139 $content = "";
140 $tpl->generateOutputToString($content);
141
142 print "<table width='100%'><tr><td>";
143
3e0f2090
AD
144 $addresslist = explode(",", $this->host->get($this, "addresslist"));
145
1baac280
AD
146 print __('To:');
147
148 print "</td><td>";
149
3e0f2090 150/* print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
1baac280 151 style=\"width : 30em;\"
3e0f2090 152 name=\"destination\" id=\"emailArticleDlg_destination\">"; */
1baac280 153
38bc9dad 154 print_select("destination", "", $addresslist, 'style="width: 30em" dojoType="dijit.form.ComboBox"');
3e0f2090
AD
155
156/* print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\"
157 style=\"z-index: 30; display : none\"></div>"; */
1baac280
AD
158
159 print "</td></tr><tr><td>";
160
161 print __('Subject:');
162
163 print "</td><td>";
164
165 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
166 style=\"width : 30em;\"
167 name=\"subject\" value=\"$subject\" id=\"subject\">";
168
169 print "</td></tr>";
170
3a029230 171 print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\"
8de58e17 172 style='height : 200px; font-size : 12px; width : 98%' rows=\"20\"
1baac280
AD
173 name='content'>$content</textarea>";
174
175 print "</td></tr></table>";
176
177 print "<div class='dlgButtons'>";
178 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').execute()\">".__('Send e-mail')."</button> ";
179 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Cancel')."</button>";
180 print "</div>";
181
182 //return;
183 }
184
185 function sendEmail() {
1b2afd2b 186 require_once 'classes/ttrssmailer.php';
1baac280
AD
187
188 $reply = array();
189
83b1ddaf 190 $mail = new ttrssMailer();
1baac280 191
a6626ebd
AD
192 $mail->AddReplyTo(strip_tags($_REQUEST['from_email']),
193 strip_tags($_REQUEST['from_name']));
6dd01fce 194 //$mail->AddAddress($_REQUEST['destination']);
ed7dd4bf 195 $addresses = explode(';', $_REQUEST['destination']);
6dd01fce 196 foreach($addresses as $nextaddr)
197 $mail->AddAddress($nextaddr);
1baac280 198
83b1ddaf
AD
199 $mail->IsHTML(false);
200 $mail->Subject = $_REQUEST['subject'];
201 $mail->Body = $_REQUEST['content'];
1baac280 202
83b1ddaf 203 $rc = $mail->Send();
1baac280 204
83b1ddaf
AD
205 if (!$rc) {
206 $reply['error'] = $mail->ErrorInfo;
1baac280 207 } else {
2179332a 208 //save_email_address($destination);
83b1ddaf 209 $reply['message'] = "UPDATE_COUNTERS";
1baac280
AD
210 }
211
212 print json_encode($reply);
213 }
214
3e0f2090 215 /* function completeEmails() {
2179332a 216 $search = $_REQUEST["search"];
1baac280
AD
217
218 print "<ul>";
219
220 foreach ($_SESSION['stored_emails'] as $email) {
221 if (strpos($email, $search) !== false) {
222 print "<li>$email</li>";
223 }
224 }
225
226 print "</ul>";
3e0f2090 227 } */
1baac280 228
106a3de9
AD
229 function api_version() {
230 return 2;
231 }
1baac280 232
21ce7d9e 233}