]>
Commit | Line | Data |
---|---|---|
1baac280 | 1 | <?php |
19c73507 AD |
2 | class Mail { |
3 | ||
4 | private $link; | |
5 | private $host; | |
6 | ||
7 | function __construct($host) { | |
8 | $this->link = $host->get_link(); | |
9 | $this->host = $host; | |
10 | ||
11 | $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); | |
12 | } | |
13 | ||
14 | function get_js() { | |
15 | return file_get_contents(dirname(__FILE__) . "/mail.js"); | |
16 | } | |
17 | ||
18 | function hook_article_button($line) { | |
19 | return "<img src=\"".theme_image($link, 'plugins/mail/mail.png')."\" | |
1baac280 | 20 | class='tagsPic' style=\"cursor : pointer\" |
19c73507 | 21 | onclick=\"emailArticle(".$line["id"].")\" |
1baac280 AD |
22 | alt='Zoom' title='".__('Forward by email')."'>"; |
23 | } | |
24 | ||
25 | function emailArticle() { | |
26 | ||
27 | $param = db_escape_string($_REQUEST['param']); | |
28 | ||
29 | $secretkey = sha1(uniqid(rand(), true)); | |
30 | ||
31 | $_SESSION['email_secretkey'] = $secretkey; | |
32 | ||
33 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"secretkey\" value=\"$secretkey\">"; | |
19c73507 | 34 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">"; |
1baac280 | 35 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"mail\">"; |
19c73507 | 36 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"sendEmail\">"; |
1baac280 AD |
37 | |
38 | $result = db_query($this->link, "SELECT email, full_name FROM ttrss_users WHERE | |
39 | id = " . $_SESSION["uid"]); | |
40 | ||
41 | $user_email = htmlspecialchars(db_fetch_result($result, 0, "email")); | |
42 | $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name")); | |
43 | ||
44 | if (!$user_name) $user_name = $_SESSION['name']; | |
45 | ||
46 | $_SESSION['email_replyto'] = $user_email; | |
47 | $_SESSION['email_fromname'] = $user_name; | |
48 | ||
49 | require_once "lib/MiniTemplator.class.php"; | |
50 | ||
51 | $tpl = new MiniTemplator; | |
52 | $tpl_t = new MiniTemplator; | |
53 | ||
54 | $tpl->readTemplateFromFile("templates/email_article_template.txt"); | |
55 | ||
56 | $tpl->setVariable('USER_NAME', $_SESSION["name"]); | |
57 | $tpl->setVariable('USER_EMAIL', $user_email); | |
58 | $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"]); | |
59 | ||
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() { | |
133 | $secretkey = $_REQUEST['secretkey']; | |
134 | ||
135 | require_once 'lib/phpmailer/class.phpmailer.php'; | |
136 | ||
137 | $reply = array(); | |
138 | ||
139 | if ($_SESSION['email_secretkey'] && | |
140 | $secretkey == $_SESSION['email_secretkey']) { | |
141 | ||
142 | $_SESSION['email_secretkey'] = ''; | |
143 | ||
144 | $destination = $_REQUEST['destination']; | |
145 | $subject = $_REQUEST['subject']; | |
146 | $content = $_REQUEST['content']; | |
147 | ||
148 | $replyto = strip_tags($_SESSION['email_replyto']); | |
149 | $fromname = strip_tags($_SESSION['email_fromname']); | |
150 | ||
151 | $mail = new PHPMailer(); | |
152 | ||
153 | $mail->PluginDir = "lib/phpmailer/"; | |
154 | $mail->SetLanguage("en", "lib/phpmailer/language/"); | |
155 | ||
156 | $mail->CharSet = "UTF-8"; | |
157 | ||
158 | $mail->From = $replyto; | |
159 | $mail->FromName = $fromname; | |
160 | $mail->AddAddress($destination); | |
161 | ||
162 | if (SMTP_HOST) { | |
163 | $mail->Host = SMTP_HOST; | |
164 | $mail->Mailer = "smtp"; | |
165 | $mail->SMTPAuth = SMTP_LOGIN != ''; | |
166 | $mail->Username = SMTP_LOGIN; | |
167 | $mail->Password = SMTP_PASSWORD; | |
168 | } | |
169 | ||
170 | $mail->IsHTML(false); | |
171 | $mail->Subject = $subject; | |
172 | $mail->Body = $content; | |
173 | ||
174 | $rc = $mail->Send(); | |
175 | ||
176 | if (!$rc) { | |
177 | $reply['error'] = $mail->ErrorInfo; | |
178 | } else { | |
179 | save_email_address($this->link, db_escape_string($destination)); | |
180 | $reply['message'] = "UPDATE_COUNTERS"; | |
181 | } | |
182 | ||
183 | } else { | |
184 | $reply['error'] = "Not authorized."; | |
185 | } | |
186 | ||
187 | print json_encode($reply); | |
188 | } | |
189 | ||
190 | function completeEmails() { | |
191 | $search = db_escape_string($_REQUEST["search"]); | |
192 | ||
193 | print "<ul>"; | |
194 | ||
195 | foreach ($_SESSION['stored_emails'] as $email) { | |
196 | if (strpos($email, $search) !== false) { | |
197 | print "<li>$email</li>"; | |
198 | } | |
199 | } | |
200 | ||
201 | print "</ul>"; | |
202 | } | |
203 | ||
204 | ||
205 | } | |
206 | ?> |