]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | class Mail extends Plugin { | |
3 | ||
4 | /* @var PluginHost $host */ | |
5 | private $host; | |
6 | ||
7 | function about() { | |
8 | return array(1.0, | |
9 | "Share article via email", | |
10 | "fox"); | |
11 | } | |
12 | ||
13 | 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 | function get_js() { | |
21 | return file_get_contents(dirname(__FILE__) . "/mail.js"); | |
22 | } | |
23 | ||
24 | function save() { | |
25 | $addresslist = $_POST["addresslist"]; | |
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 | ||
55 | print_hidden("op", "pluginhandler"); | |
56 | print_hidden("method", "save"); | |
57 | print_hidden("plugin", "mail"); | |
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 | ||
72 | function hook_article_button($line) { | |
73 | return "<img src=\"plugins/mail/mail.png\" | |
74 | class='tagsPic' style=\"cursor : pointer\" | |
75 | onclick=\"emailArticle(".$line["id"].")\" | |
76 | alt='Zoom' title='".__('Forward by email')."'>"; | |
77 | } | |
78 | ||
79 | function emailArticle() { | |
80 | ||
81 | $ids = explode(",", $_REQUEST['param']); | |
82 | $ids_qmarks = arr_qmarks($ids); | |
83 | ||
84 | print_hidden("op", "pluginhandler"); | |
85 | print_hidden("plugin", "mail"); | |
86 | print_hidden("method", "sendEmail"); | |
87 | ||
88 | $sth = $this->pdo->prepare("SELECT email, full_name FROM ttrss_users WHERE | |
89 | id = ?"); | |
90 | $sth->execute([$_SESSION['uid']]); | |
91 | ||
92 | if ($row = $sth->fetch()) { | |
93 | $user_email = htmlspecialchars($row['email']); | |
94 | $user_name = htmlspecialchars($row['full_name']); | |
95 | } | |
96 | ||
97 | if (!$user_name) $user_name = $_SESSION['name']; | |
98 | ||
99 | print_hidden("from_email", "$user_email"); | |
100 | print_hidden("from_name", "$user_name"); | |
101 | ||
102 | require_once "lib/MiniTemplator.class.php"; | |
103 | ||
104 | $tpl = new MiniTemplator; | |
105 | ||
106 | $tpl->readTemplateFromFile("templates/email_article_template.txt"); | |
107 | ||
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); | |
111 | ||
112 | $sth = $this->pdo->prepare("SELECT DISTINCT link, content, title, note | |
113 | FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND | |
114 | id IN ($ids_qmarks) AND owner_uid = ?"); | |
115 | $sth->execute(array_merge($ids, [$_SESSION['uid']])); | |
116 | ||
117 | if (count($ids) > 1) { | |
118 | $subject = __("[Forwarded]") . " " . __("Multiple articles"); | |
119 | } | |
120 | ||
121 | while ($line = $sth->fetch()) { | |
122 | ||
123 | if (!$subject) | |
124 | $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]); | |
125 | ||
126 | $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"])); | |
127 | $tnote = strip_tags($line["note"]); | |
128 | if( $tnote != ''){ | |
129 | $tpl->setVariable('ARTICLE_NOTE', $tnote, true); | |
130 | $tpl->addBlock('note'); | |
131 | } | |
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 | ||
144 | $addresslist = explode(",", $this->host->get($this, "addresslist")); | |
145 | ||
146 | print __('To:'); | |
147 | ||
148 | print "</td><td>"; | |
149 | ||
150 | /* print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\" | |
151 | style=\"width : 30em;\" | |
152 | name=\"destination\" id=\"emailArticleDlg_destination\">"; */ | |
153 | ||
154 | print_select("destination", "", $addresslist, 'style="width: 30em" dojoType="dijit.form.ComboBox"'); | |
155 | ||
156 | /* print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\" | |
157 | style=\"z-index: 30; display : none\"></div>"; */ | |
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 | ||
171 | print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" | |
172 | style='height : 200px; font-size : 12px; width : 98%' rows=\"20\" | |
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() { | |
186 | $reply = array(); | |
187 | ||
188 | /*$mail->AddReplyTo(strip_tags($_REQUEST['from_email']), | |
189 | strip_tags($_REQUEST['from_name'])); | |
190 | //$mail->AddAddress($_REQUEST['destination']); | |
191 | $addresses = explode(';', $_REQUEST['destination']); | |
192 | foreach($addresses as $nextaddr) | |
193 | $mail->AddAddress($nextaddr); | |
194 | ||
195 | $mail->IsHTML(false); | |
196 | $mail->Subject = $_REQUEST['subject']; | |
197 | $mail->Body = $_REQUEST['content']; | |
198 | ||
199 | $rc = $mail->Send(); */ | |
200 | ||
201 | $to = $_REQUEST["destination"]; | |
202 | $subject = strip_tags($_REQUEST["subject"]); | |
203 | $message = strip_tags($_REQUEST["content"]); | |
204 | $from = strip_tags($_REQUEST["from_email"]); | |
205 | ||
206 | $mailer = new Mailer(); | |
207 | ||
208 | $rc = $mailer->mail(["to_address" => $to, | |
209 | "headers" => ["Reply-To: $from"], | |
210 | "subject" => $subject, | |
211 | "message" => $message]); | |
212 | ||
213 | if (!$rc) { | |
214 | $reply['error'] = $mailer->error(); | |
215 | } else { | |
216 | //save_email_address($destination); | |
217 | $reply['message'] = "UPDATE_COUNTERS"; | |
218 | } | |
219 | ||
220 | print json_encode($reply); | |
221 | } | |
222 | ||
223 | /* function completeEmails() { | |
224 | $search = $_REQUEST["search"]; | |
225 | ||
226 | print "<ul>"; | |
227 | ||
228 | foreach ($_SESSION['stored_emails'] as $email) { | |
229 | if (strpos($email, $search) !== false) { | |
230 | print "<li>$email</li>"; | |
231 | } | |
232 | } | |
233 | ||
234 | print "</ul>"; | |
235 | } */ | |
236 | ||
237 | function api_version() { | |
238 | return 2; | |
239 | } | |
240 | ||
241 | } |