]>
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 | ||
3e0f2090 AD |
138 | $addresslist = explode(",", $this->host->get($this, "addresslist")); |
139 | ||
1baac280 AD |
140 | print __('To:'); |
141 | ||
142 | print "</td><td>"; | |
143 | ||
3e0f2090 | 144 | /* print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\" |
1baac280 | 145 | style=\"width : 30em;\" |
3e0f2090 | 146 | name=\"destination\" id=\"emailArticleDlg_destination\">"; */ |
1baac280 | 147 | |
38bc9dad | 148 | print_select("destination", "", $addresslist, 'style="width: 30em" dojoType="dijit.form.ComboBox"'); |
3e0f2090 AD |
149 | |
150 | /* print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\" | |
151 | style=\"z-index: 30; display : none\"></div>"; */ | |
1baac280 AD |
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() { | |
1b2afd2b | 179 | require_once 'classes/ttrssmailer.php'; |
1baac280 AD |
180 | |
181 | $reply = array(); | |
182 | ||
83b1ddaf | 183 | $mail = new ttrssMailer(); |
1baac280 | 184 | |
a6626ebd AD |
185 | $mail->AddReplyTo(strip_tags($_REQUEST['from_email']), |
186 | strip_tags($_REQUEST['from_name'])); | |
6dd01fce | 187 | //$mail->AddAddress($_REQUEST['destination']); |
ed7dd4bf | 188 | $addresses = explode(';', $_REQUEST['destination']); |
6dd01fce | 189 | foreach($addresses as $nextaddr) |
190 | $mail->AddAddress($nextaddr); | |
1baac280 | 191 | |
83b1ddaf AD |
192 | $mail->IsHTML(false); |
193 | $mail->Subject = $_REQUEST['subject']; | |
194 | $mail->Body = $_REQUEST['content']; | |
1baac280 | 195 | |
83b1ddaf | 196 | $rc = $mail->Send(); |
1baac280 | 197 | |
83b1ddaf AD |
198 | if (!$rc) { |
199 | $reply['error'] = $mail->ErrorInfo; | |
1baac280 | 200 | } else { |
3e0f2090 | 201 | //save_email_address(db_escape_string($destination)); |
83b1ddaf | 202 | $reply['message'] = "UPDATE_COUNTERS"; |
1baac280 AD |
203 | } |
204 | ||
205 | print json_encode($reply); | |
206 | } | |
207 | ||
3e0f2090 | 208 | /* function completeEmails() { |
a42c55f0 | 209 | $search = db_escape_string($_REQUEST["search"]); |
1baac280 AD |
210 | |
211 | print "<ul>"; | |
212 | ||
213 | foreach ($_SESSION['stored_emails'] as $email) { | |
214 | if (strpos($email, $search) !== false) { | |
215 | print "<li>$email</li>"; | |
216 | } | |
217 | } | |
218 | ||
219 | print "</ul>"; | |
3e0f2090 | 220 | } */ |
1baac280 | 221 | |
106a3de9 AD |
222 | function api_version() { |
223 | return 2; | |
224 | } | |
1baac280 AD |
225 | |
226 | } | |
227 | ?> |