]>
Commit | Line | Data |
---|---|---|
1baac280 | 1 | <?php |
5a0e0392 | 2 | class Mail extends Plugin { |
19c73507 AD |
3 | |
4 | private $link; | |
5 | private $host; | |
6 | ||
d2a421e3 | 7 | function about() { |
7a866114 | 8 | return array(1.0, |
0ac22f29 | 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) { | |
25 | return "<img src=\"".theme_image($link, '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 | ||
33 | $param = db_escape_string($_REQUEST['param']); | |
34 | ||
35 | $secretkey = sha1(uniqid(rand(), true)); | |
36 | ||
37 | $_SESSION['email_secretkey'] = $secretkey; | |
38 | ||
39 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"secretkey\" value=\"$secretkey\">"; | |
19c73507 | 40 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">"; |
1baac280 | 41 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"mail\">"; |
19c73507 | 42 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"sendEmail\">"; |
1baac280 AD |
43 | |
44 | $result = db_query($this->link, "SELECT email, full_name FROM ttrss_users WHERE | |
45 | id = " . $_SESSION["uid"]); | |
46 | ||
47 | $user_email = htmlspecialchars(db_fetch_result($result, 0, "email")); | |
48 | $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name")); | |
49 | ||
50 | if (!$user_name) $user_name = $_SESSION['name']; | |
51 | ||
52 | $_SESSION['email_replyto'] = $user_email; | |
53 | $_SESSION['email_fromname'] = $user_name; | |
54 | ||
55 | require_once "lib/MiniTemplator.class.php"; | |
56 | ||
57 | $tpl = new MiniTemplator; | |
58 | $tpl_t = new MiniTemplator; | |
59 | ||
60 | $tpl->readTemplateFromFile("templates/email_article_template.txt"); | |
61 | ||
62 | $tpl->setVariable('USER_NAME', $_SESSION["name"]); | |
63 | $tpl->setVariable('USER_EMAIL', $user_email); | |
64 | $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"]); | |
65 | ||
66 | ||
67 | $result = db_query($this->link, "SELECT link, content, title | |
68 | FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND | |
69 | id IN ($param) AND owner_uid = " . $_SESSION["uid"]); | |
70 | ||
71 | if (db_num_rows($result) > 1) { | |
72 | $subject = __("[Forwarded]") . " " . __("Multiple articles"); | |
73 | } | |
74 | ||
75 | while ($line = db_fetch_assoc($result)) { | |
76 | ||
77 | if (!$subject) | |
78 | $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]); | |
79 | ||
80 | $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"])); | |
81 | $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"])); | |
82 | ||
83 | $tpl->addBlock('article'); | |
84 | } | |
85 | ||
86 | $tpl->addBlock('email'); | |
87 | ||
88 | $content = ""; | |
89 | $tpl->generateOutputToString($content); | |
90 | ||
91 | print "<table width='100%'><tr><td>"; | |
92 | ||
93 | print __('From:'); | |
94 | ||
95 | print "</td><td>"; | |
96 | ||
97 | print "<input dojoType=\"dijit.form.TextBox\" disabled=\"1\" style=\"width : 30em;\" | |
98 | value=\"$user_name <$user_email>\">"; | |
99 | ||
100 | print "</td></tr><tr><td>"; | |
101 | ||
102 | print __('To:'); | |
103 | ||
104 | print "</td><td>"; | |
105 | ||
106 | print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\" | |
107 | style=\"width : 30em;\" | |
108 | name=\"destination\" id=\"emailArticleDlg_destination\">"; | |
109 | ||
110 | print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\" | |
111 | style=\"z-index: 30; display : none\"></div>"; | |
112 | ||
113 | print "</td></tr><tr><td>"; | |
114 | ||
115 | print __('Subject:'); | |
116 | ||
117 | print "</td><td>"; | |
118 | ||
119 | print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\" | |
120 | style=\"width : 30em;\" | |
121 | name=\"subject\" value=\"$subject\" id=\"subject\">"; | |
122 | ||
123 | print "</td></tr>"; | |
124 | ||
125 | print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 100%' rows=\"20\" | |
126 | name='content'>$content</textarea>"; | |
127 | ||
128 | print "</td></tr></table>"; | |
129 | ||
130 | print "<div class='dlgButtons'>"; | |
131 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').execute()\">".__('Send e-mail')."</button> "; | |
132 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Cancel')."</button>"; | |
133 | print "</div>"; | |
134 | ||
135 | //return; | |
136 | } | |
137 | ||
138 | function sendEmail() { | |
139 | $secretkey = $_REQUEST['secretkey']; | |
140 | ||
141 | require_once 'lib/phpmailer/class.phpmailer.php'; | |
142 | ||
143 | $reply = array(); | |
144 | ||
145 | if ($_SESSION['email_secretkey'] && | |
146 | $secretkey == $_SESSION['email_secretkey']) { | |
147 | ||
148 | $_SESSION['email_secretkey'] = ''; | |
149 | ||
150 | $destination = $_REQUEST['destination']; | |
151 | $subject = $_REQUEST['subject']; | |
152 | $content = $_REQUEST['content']; | |
153 | ||
154 | $replyto = strip_tags($_SESSION['email_replyto']); | |
155 | $fromname = strip_tags($_SESSION['email_fromname']); | |
156 | ||
157 | $mail = new PHPMailer(); | |
158 | ||
159 | $mail->PluginDir = "lib/phpmailer/"; | |
160 | $mail->SetLanguage("en", "lib/phpmailer/language/"); | |
161 | ||
162 | $mail->CharSet = "UTF-8"; | |
163 | ||
164 | $mail->From = $replyto; | |
165 | $mail->FromName = $fromname; | |
166 | $mail->AddAddress($destination); | |
167 | ||
168 | if (SMTP_HOST) { | |
169 | $mail->Host = SMTP_HOST; | |
170 | $mail->Mailer = "smtp"; | |
171 | $mail->SMTPAuth = SMTP_LOGIN != ''; | |
172 | $mail->Username = SMTP_LOGIN; | |
173 | $mail->Password = SMTP_PASSWORD; | |
174 | } | |
175 | ||
176 | $mail->IsHTML(false); | |
177 | $mail->Subject = $subject; | |
178 | $mail->Body = $content; | |
179 | ||
180 | $rc = $mail->Send(); | |
181 | ||
182 | if (!$rc) { | |
183 | $reply['error'] = $mail->ErrorInfo; | |
184 | } else { | |
185 | save_email_address($this->link, db_escape_string($destination)); | |
186 | $reply['message'] = "UPDATE_COUNTERS"; | |
187 | } | |
188 | ||
189 | } else { | |
190 | $reply['error'] = "Not authorized."; | |
191 | } | |
192 | ||
193 | print json_encode($reply); | |
194 | } | |
195 | ||
196 | function completeEmails() { | |
197 | $search = db_escape_string($_REQUEST["search"]); | |
198 | ||
199 | print "<ul>"; | |
200 | ||
201 | foreach ($_SESSION['stored_emails'] as $email) { | |
202 | if (strpos($email, $search) !== false) { | |
203 | print "<li>$email</li>"; | |
204 | } | |
205 | } | |
206 | ||
207 | print "</ul>"; | |
208 | } | |
209 | ||
210 | ||
211 | } | |
212 | ?> |