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