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