]>
git.wh0rd.org - tt-rss.git/blob - plugins/mail/init.php
2 class Mail
extends Plugin
{
4 /* @var PluginHost $host */
9 "Share article via email",
13 function init($host) {
16 $host->add_hook($host::HOOK_ARTICLE_BUTTON
, $this);
17 $host->add_hook($host::HOOK_PREFS_TAB
, $this);
21 return file_get_contents(dirname(__FILE__
) . "/mail.js");
25 $addresslist = $_POST["addresslist"];
27 $this->host
->set($this, "addresslist", $addresslist);
29 echo __("Mail addresses saved.");
32 function hook_prefs_tab($args) {
33 if ($args != "prefPrefs") return;
35 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Mail plugin')."\">";
37 print "<p>" . __("You can set predefined email addressed here (comma-separated list):") . "</p>";
39 print "<form dojoType=\"dijit.form.Form\">";
41 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
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);
55 print_hidden("op", "pluginhandler");
56 print_hidden("method", "save");
57 print_hidden("plugin", "mail");
59 $addresslist = $this->host
->get($this, "addresslist");
61 print "<textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 50%' rows=\"3\"
62 name='addresslist'>$addresslist</textarea>";
64 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
65 __("Save")."</button>";
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')."'>";
79 function emailArticle() {
81 $ids = explode(",", $_REQUEST['param']);
82 $ids_qmarks = arr_qmarks($ids);
84 print_hidden("op", "pluginhandler");
85 print_hidden("plugin", "mail");
86 print_hidden("method", "sendEmail");
88 $sth = $this->pdo
->prepare("SELECT email, full_name FROM ttrss_users WHERE
90 $sth->execute([$_SESSION['uid']]);
92 if ($row = $sth->fetch()) {
93 $user_email = htmlspecialchars($row['email']);
94 $user_name = htmlspecialchars($row['full_name']);
97 if (!$user_name) $user_name = $_SESSION['name'];
99 print_hidden("from_email", "$user_email");
100 print_hidden("from_name", "$user_name");
102 require_once "lib/MiniTemplator.class.php";
104 $tpl = new MiniTemplator
;
106 $tpl->readTemplateFromFile("templates/email_article_template.txt");
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);
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']]));
117 if (count($ids) > 1) {
118 $subject = __("[Forwarded]") . " " . __("Multiple articles");
121 while ($line = $sth->fetch()) {
124 $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
126 $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
127 $tnote = strip_tags($line["note"]);
129 $tpl->setVariable('ARTICLE_NOTE', $tnote, true);
130 $tpl->addBlock('note');
132 $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
134 $tpl->addBlock('article');
137 $tpl->addBlock('email');
140 $tpl->generateOutputToString($content);
142 print "<table width='100%'><tr><td>";
144 $addresslist = explode(",", $this->host
->get($this, "addresslist"));
150 /* print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
151 style=\"width : 30em;\"
152 name=\"destination\" id=\"emailArticleDlg_destination\">"; */
154 print_select("destination", "", $addresslist, 'style="width: 30em" dojoType="dijit.form.ComboBox"');
156 /* print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\"
157 style=\"z-index: 30; display : none\"></div>"; */
159 print "</td></tr><tr><td>";
161 print __('Subject:');
165 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
166 style=\"width : 30em;\"
167 name=\"subject\" value=\"$subject\" id=\"subject\">";
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>";
175 print "</td></tr></table>";
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>";
185 function sendEmail() {
186 require_once 'classes/ttrssmailer.php';
190 $mail = new ttrssMailer();
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);
199 $mail->IsHTML(false);
200 $mail->Subject
= $_REQUEST['subject'];
201 $mail->Body
= $_REQUEST['content'];
206 $reply['error'] = $mail->ErrorInfo
;
208 //save_email_address($destination);
209 $reply['message'] = "UPDATE_COUNTERS";
212 print json_encode($reply);
215 /* function completeEmails() {
216 $search = $_REQUEST["search"];
220 foreach ($_SESSION['stored_emails'] as $email) {
221 if (strpos($email, $search) !== false) {
222 print "<li>$email</li>";
229 function api_version() {