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