]>
Commit | Line | Data |
---|---|---|
1baac280 | 1 | <?php |
5a0e0392 | 2 | class Mail extends Plugin { |
19c73507 | 3 | |
19c73507 AD |
4 | private $host; |
5 | ||
d2a421e3 | 6 | function about() { |
7a866114 | 7 | return array(1.0, |
f044a0b8 | 8 | "Share article via email", |
7a866114 AD |
9 | "fox"); |
10 | } | |
11 | ||
d2a421e3 | 12 | function init($host) { |
19c73507 AD |
13 | $this->host = $host; |
14 | ||
15 | $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); | |
3e0f2090 | 16 | $host->add_hook($host::HOOK_PREFS_TAB, $this); |
19c73507 AD |
17 | } |
18 | ||
19 | function get_js() { | |
20 | return file_get_contents(dirname(__FILE__) . "/mail.js"); | |
21 | } | |
22 | ||
3e0f2090 AD |
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 | ||
19c73507 | 71 | function hook_article_button($line) { |
2a3b6de0 | 72 | return "<img src=\"plugins/mail/mail.png\" |
1baac280 | 73 | class='tagsPic' style=\"cursor : pointer\" |
19c73507 | 74 | onclick=\"emailArticle(".$line["id"].")\" |
1baac280 AD |
75 | alt='Zoom' title='".__('Forward by email')."'>"; |
76 | } | |
77 | ||
78 | function emailArticle() { | |
79 | ||
a42c55f0 | 80 | $param = db_escape_string($_REQUEST['param']); |
1baac280 | 81 | |
19c73507 | 82 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">"; |
1baac280 | 83 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"mail\">"; |
19c73507 | 84 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"sendEmail\">"; |
1baac280 | 85 | |
a42c55f0 | 86 | $result = db_query("SELECT email, full_name FROM ttrss_users WHERE |
1baac280 AD |
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 | ||
ea4e1103 AD |
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\">"; | |
1baac280 AD |
96 | |
97 | require_once "lib/MiniTemplator.class.php"; | |
98 | ||
99 | $tpl = new MiniTemplator; | |
1baac280 | 100 | |
a9358e1d | 101 | $tpl->readTemplateFromFile("templates/email_article_template.txt"); |
1baac280 | 102 | |
1d5cf085 AD |
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); | |
1baac280 | 106 | |
d7482a50 | 107 | $result = db_query("SELECT DISTINCT link, content, title, note |
1baac280 AD |
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"])); | |
ed7dd4bf | 121 | $tnote = strip_tags($line["note"]); |
122 | if( $tnote != ''){ | |
123 | $tpl->setVariable('ARTICLE_NOTE', $tnote, true); | |
124 | $tpl->addBlock('note'); | |
125 | } | |
1baac280 AD |
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 | print __('From:'); | |
139 | ||
140 | print "</td><td>"; | |
141 | ||
142 | print "<input dojoType=\"dijit.form.TextBox\" disabled=\"1\" style=\"width : 30em;\" | |
143 | value=\"$user_name <$user_email>\">"; | |
144 | ||
145 | print "</td></tr><tr><td>"; | |
146 | ||
3e0f2090 AD |
147 | $addresslist = explode(",", $this->host->get($this, "addresslist")); |
148 | ||
1baac280 AD |
149 | print __('To:'); |
150 | ||
151 | print "</td><td>"; | |
152 | ||
3e0f2090 | 153 | /* print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\" |
1baac280 | 154 | style=\"width : 30em;\" |
3e0f2090 | 155 | name=\"destination\" id=\"emailArticleDlg_destination\">"; */ |
1baac280 | 156 | |
2d3ff643 | 157 | print_select("destination", "", $addresslist, 'style="width: 30em" dojoType="dijit.form.FilteringSelect"'); |
3e0f2090 AD |
158 | |
159 | /* print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\" | |
160 | style=\"z-index: 30; display : none\"></div>"; */ | |
1baac280 AD |
161 | |
162 | print "</td></tr><tr><td>"; | |
163 | ||
164 | print __('Subject:'); | |
165 | ||
166 | print "</td><td>"; | |
167 | ||
168 | print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\" | |
169 | style=\"width : 30em;\" | |
170 | name=\"subject\" value=\"$subject\" id=\"subject\">"; | |
171 | ||
172 | print "</td></tr>"; | |
173 | ||
174 | print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 100%' rows=\"20\" | |
175 | name='content'>$content</textarea>"; | |
176 | ||
177 | print "</td></tr></table>"; | |
178 | ||
179 | print "<div class='dlgButtons'>"; | |
180 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').execute()\">".__('Send e-mail')."</button> "; | |
181 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Cancel')."</button>"; | |
182 | print "</div>"; | |
183 | ||
184 | //return; | |
185 | } | |
186 | ||
187 | function sendEmail() { | |
1b2afd2b | 188 | require_once 'classes/ttrssmailer.php'; |
1baac280 AD |
189 | |
190 | $reply = array(); | |
191 | ||
83b1ddaf | 192 | $mail = new ttrssMailer(); |
1baac280 | 193 | |
ea4e1103 AD |
194 | $mail->From = strip_tags($_REQUEST['from_email']); |
195 | $mail->FromName = strip_tags($_REQUEST['from_name']); | |
6dd01fce | 196 | //$mail->AddAddress($_REQUEST['destination']); |
ed7dd4bf | 197 | $addresses = explode(';', $_REQUEST['destination']); |
6dd01fce | 198 | foreach($addresses as $nextaddr) |
199 | $mail->AddAddress($nextaddr); | |
1baac280 | 200 | |
83b1ddaf AD |
201 | $mail->IsHTML(false); |
202 | $mail->Subject = $_REQUEST['subject']; | |
203 | $mail->Body = $_REQUEST['content']; | |
1baac280 | 204 | |
83b1ddaf | 205 | $rc = $mail->Send(); |
1baac280 | 206 | |
83b1ddaf AD |
207 | if (!$rc) { |
208 | $reply['error'] = $mail->ErrorInfo; | |
1baac280 | 209 | } else { |
3e0f2090 | 210 | //save_email_address(db_escape_string($destination)); |
83b1ddaf | 211 | $reply['message'] = "UPDATE_COUNTERS"; |
1baac280 AD |
212 | } |
213 | ||
214 | print json_encode($reply); | |
215 | } | |
216 | ||
3e0f2090 | 217 | /* function completeEmails() { |
a42c55f0 | 218 | $search = db_escape_string($_REQUEST["search"]); |
1baac280 AD |
219 | |
220 | print "<ul>"; | |
221 | ||
222 | foreach ($_SESSION['stored_emails'] as $email) { | |
223 | if (strpos($email, $search) !== false) { | |
224 | print "<li>$email</li>"; | |
225 | } | |
226 | } | |
227 | ||
228 | print "</ul>"; | |
3e0f2090 | 229 | } */ |
1baac280 | 230 | |
106a3de9 AD |
231 | function api_version() { |
232 | return 2; | |
233 | } | |
1baac280 AD |
234 | |
235 | } | |
236 | ?> |