]> git.wh0rd.org - tt-rss.git/blob - plugins/mail/init.php
Added the note text to the body of the email sending articles
[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 }
17
18 function get_js() {
19 return file_get_contents(dirname(__FILE__) . "/mail.js");
20 }
21
22 function hook_article_button($line) {
23 return "<img src=\"plugins/mail/mail.png\"
24 class='tagsPic' style=\"cursor : pointer\"
25 onclick=\"emailArticle(".$line["id"].")\"
26 alt='Zoom' title='".__('Forward by email')."'>";
27 }
28
29 function emailArticle() {
30
31 $param = db_escape_string($_REQUEST['param']);
32
33 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">";
34 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"mail\">";
35 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"sendEmail\">";
36
37 $result = db_query("SELECT email, full_name FROM ttrss_users WHERE
38 id = " . $_SESSION["uid"]);
39
40 $user_email = htmlspecialchars(db_fetch_result($result, 0, "email"));
41 $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
42
43 if (!$user_name) $user_name = $_SESSION['name'];
44
45 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"from_email\" value=\"$user_email\">";
46 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"from_name\" value=\"$user_name\">";
47
48 require_once "lib/MiniTemplator.class.php";
49
50 $tpl = new MiniTemplator;
51 $tpl_t = new MiniTemplator;
52
53 $tpl->readTemplateFromFile("templates/email_article_template.txt");
54
55 $tpl->setVariable('USER_NAME', $_SESSION["name"], true);
56 $tpl->setVariable('USER_EMAIL', $user_email, true);
57 $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"], true);
58
59 $result = db_query("SELECT link, content, title, note
60 FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND
61 id IN ($param) AND owner_uid = " . $_SESSION["uid"]);
62
63 if (db_num_rows($result) > 1) {
64 $subject = __("[Forwarded]") . " " . __("Multiple articles");
65 }
66
67 while ($line = db_fetch_assoc($result)) {
68
69 if (!$subject)
70 $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
71
72 $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
73 $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
74 $tpl->setVariable('ARTICLE_NOTE', strip_tags($line["note"]));
75
76 $tpl->addBlock('article');
77 }
78
79 $tpl->addBlock('email');
80
81 $content = "";
82 $tpl->generateOutputToString($content);
83
84 print "<table width='100%'><tr><td>";
85
86 print __('From:');
87
88 print "</td><td>";
89
90 print "<input dojoType=\"dijit.form.TextBox\" disabled=\"1\" style=\"width : 30em;\"
91 value=\"$user_name <$user_email>\">";
92
93 print "</td></tr><tr><td>";
94
95 print __('To:');
96
97 print "</td><td>";
98
99 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
100 style=\"width : 30em;\"
101 name=\"destination\" id=\"emailArticleDlg_destination\">";
102
103 print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\"
104 style=\"z-index: 30; display : none\"></div>";
105
106 print "</td></tr><tr><td>";
107
108 print __('Subject:');
109
110 print "</td><td>";
111
112 print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\"
113 style=\"width : 30em;\"
114 name=\"subject\" value=\"$subject\" id=\"subject\">";
115
116 print "</td></tr>";
117
118 print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 100%' rows=\"20\"
119 name='content'>$content</textarea>";
120
121 print "</td></tr></table>";
122
123 print "<div class='dlgButtons'>";
124 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').execute()\">".__('Send e-mail')."</button> ";
125 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Cancel')."</button>";
126 print "</div>";
127
128 //return;
129 }
130
131 function sendEmail() {
132 require_once 'classes/ttrssmailer.php';
133
134 $reply = array();
135
136 $mail = new ttrssMailer();
137
138 $mail->From = strip_tags($_REQUEST['from_email']);
139 $mail->FromName = strip_tags($_REQUEST['from_name']);
140 //$mail->AddAddress($_REQUEST['destination']);
141 $addresses = preg_split('/;/', $_REQUEST['destination'],-1,PREG_SPLIT_NO_EMPTY);
142 foreach($addresses as $nextaddr)
143 $mail->AddAddress($nextaddr);
144
145 $mail->IsHTML(false);
146 $mail->Subject = $_REQUEST['subject'];
147 $mail->Body = $_REQUEST['content'];
148
149 $rc = $mail->Send();
150
151 if (!$rc) {
152 $reply['error'] = $mail->ErrorInfo;
153 } else {
154 save_email_address(db_escape_string($destination));
155 $reply['message'] = "UPDATE_COUNTERS";
156 }
157
158 print json_encode($reply);
159 }
160
161 function completeEmails() {
162 $search = db_escape_string($_REQUEST["search"]);
163
164 print "<ul>";
165
166 foreach ($_SESSION['stored_emails'] as $email) {
167 if (strpos($email, $search) !== false) {
168 print "<li>$email</li>";
169 }
170 }
171
172 print "</ul>";
173 }
174
175 function api_version() {
176 return 2;
177 }
178
179 }
180 ?>