]>
git.wh0rd.org - tt-rss.git/blob - plugins/mail/init.php
eba4a5ce97df0214c3d22c1225b95293b1e4084b
2 class Mail
extends Plugin
{
8 "Share article via email",
12 function init($host) {
15 $host->add_hook($host::HOOK_ARTICLE_BUTTON
, $this);
16 $host->add_hook($host::HOOK_PREFS_TAB
, $this);
20 return file_get_contents(dirname(__FILE__
) . "/mail.js");
24 $addresslist = db_escape_string($_POST["addresslist"]);
26 $this->host
->set($this, "addresslist", $addresslist);
28 echo __("Mail addresses saved.");
31 function hook_prefs_tab($args) {
32 if ($args != "prefPrefs") return;
34 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Mail plugin')."\">";
36 print "<p>" . __("You can set predefined email addressed here (comma-separated list):") . "</p>";
38 print "<form dojoType=\"dijit.form.Form\">";
40 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
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);
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\">";
58 $addresslist = $this->host
->get($this, "addresslist");
60 print "<textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 50%' rows=\"3\"
61 name='addresslist'>$addresslist</textarea>";
63 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
64 __("Save")."</button>";
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')."'>";
78 function emailArticle() {
80 $param = db_escape_string($_REQUEST['param']);
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\">";
86 $result = db_query("SELECT email, full_name FROM ttrss_users WHERE
87 id = " . $_SESSION["uid"]);
89 $user_email = htmlspecialchars(db_fetch_result($result, 0, "email"));
90 $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
92 if (!$user_name) $user_name = $_SESSION['name'];
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\">";
97 require_once "lib/MiniTemplator.class.php";
99 $tpl = new MiniTemplator
;
101 $tpl->readTemplateFromFile("templates/email_article_template.txt");
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);
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"]);
111 if (db_num_rows($result) > 1) {
112 $subject = __("[Forwarded]") . " " . __("Multiple articles");
115 while ($line = db_fetch_assoc($result)) {
118 $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
120 $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
121 $tnote = strip_tags($line["note"]);
123 $tpl->setVariable('ARTICLE_NOTE', $tnote, true);
124 $tpl->addBlock('note');
126 $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
128 $tpl->addBlock('article');
131 $tpl->addBlock('email');
134 $tpl->generateOutputToString($content);
136 print "<table width='100%'><tr><td>";
138 $addresslist = explode(",", $this->host
->get($this, "addresslist"));
144 /* print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
145 style=\"width : 30em;\"
146 name=\"destination\" id=\"emailArticleDlg_destination\">"; */
148 print_select("destination", "", $addresslist, 'style="width: 30em" dojoType="dijit.form.ComboBox"');
150 /* print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\"
151 style=\"z-index: 30; display : none\"></div>"; */
153 print "</td></tr><tr><td>";
155 print __('Subject:');
159 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
160 style=\"width : 30em;\"
161 name=\"subject\" value=\"$subject\" id=\"subject\">";
165 print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 98%' rows=\"20\"
166 name='content'>$content</textarea>";
168 print "</td></tr></table>";
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>";
178 function sendEmail() {
179 require_once 'classes/ttrssmailer.php';
183 $mail = new ttrssMailer();
185 $mail->AddReplyTo(strip_tags($_REQUEST['from_email']),
186 strip_tags($_REQUEST['from_name']));
187 //$mail->AddAddress($_REQUEST['destination']);
188 $addresses = explode(';', $_REQUEST['destination']);
189 foreach($addresses as $nextaddr)
190 $mail->AddAddress($nextaddr);
192 $mail->IsHTML(false);
193 $mail->Subject
= $_REQUEST['subject'];
194 $mail->Body
= $_REQUEST['content'];
199 $reply['error'] = $mail->ErrorInfo
;
201 //save_email_address(db_escape_string($destination));
202 $reply['message'] = "UPDATE_COUNTERS";
205 print json_encode($reply);
208 /* function completeEmails() {
209 $search = db_escape_string($_REQUEST["search"]);
213 foreach ($_SESSION['stored_emails'] as $email) {
214 if (strpos($email, $search) !== false) {
215 print "<li>$email</li>";
222 function api_version() {