]>
Commit | Line | Data |
---|---|---|
1baac280 | 1 | <?php |
5a0e0392 | 2 | class Mail extends Plugin { |
19c73507 | 3 | |
19c73507 AD |
4 | private $host; |
5 | ||
d2a421e3 | 6 | function about() { |
7a866114 | 7 | return array(1.0, |
f044a0b8 | 8 | "Share article via email", |
7a866114 AD |
9 | "fox"); |
10 | } | |
11 | ||
d2a421e3 | 12 | function init($host) { |
19c73507 AD |
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) { | |
2a3b6de0 | 23 | return "<img src=\"plugins/mail/mail.png\" |
1baac280 | 24 | class='tagsPic' style=\"cursor : pointer\" |
19c73507 | 25 | onclick=\"emailArticle(".$line["id"].")\" |
1baac280 AD |
26 | alt='Zoom' title='".__('Forward by email')."'>"; |
27 | } | |
28 | ||
29 | function emailArticle() { | |
30 | ||
a42c55f0 | 31 | $param = db_escape_string($_REQUEST['param']); |
1baac280 | 32 | |
19c73507 | 33 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">"; |
1baac280 | 34 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"mail\">"; |
19c73507 | 35 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"sendEmail\">"; |
1baac280 | 36 | |
a42c55f0 | 37 | $result = db_query("SELECT email, full_name FROM ttrss_users WHERE |
1baac280 AD |
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 | ||
ea4e1103 AD |
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\">"; | |
1baac280 AD |
47 | |
48 | require_once "lib/MiniTemplator.class.php"; | |
49 | ||
50 | $tpl = new MiniTemplator; | |
51 | $tpl_t = new MiniTemplator; | |
52 | ||
a9358e1d | 53 | $tpl->readTemplateFromFile("templates/email_article_template.txt"); |
1baac280 | 54 | |
1d5cf085 AD |
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); | |
1baac280 | 58 | |
d7482a50 | 59 | $result = db_query("SELECT DISTINCT link, content, title, note |
1baac280 AD |
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"])); | |
ed7dd4bf | 73 | $tnote = strip_tags($line["note"]); |
74 | if( $tnote != ''){ | |
75 | $tpl->setVariable('ARTICLE_NOTE', $tnote, true); | |
76 | $tpl->addBlock('note'); | |
77 | } | |
1baac280 AD |
78 | $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"])); |
79 | ||
80 | $tpl->addBlock('article'); | |
81 | } | |
82 | ||
83 | $tpl->addBlock('email'); | |
84 | ||
85 | $content = ""; | |
86 | $tpl->generateOutputToString($content); | |
87 | ||
88 | print "<table width='100%'><tr><td>"; | |
89 | ||
90 | print __('From:'); | |
91 | ||
92 | print "</td><td>"; | |
93 | ||
94 | print "<input dojoType=\"dijit.form.TextBox\" disabled=\"1\" style=\"width : 30em;\" | |
95 | value=\"$user_name <$user_email>\">"; | |
96 | ||
97 | print "</td></tr><tr><td>"; | |
98 | ||
99 | print __('To:'); | |
100 | ||
101 | print "</td><td>"; | |
102 | ||
103 | print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\" | |
104 | style=\"width : 30em;\" | |
105 | name=\"destination\" id=\"emailArticleDlg_destination\">"; | |
106 | ||
107 | print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\" | |
108 | style=\"z-index: 30; display : none\"></div>"; | |
109 | ||
110 | print "</td></tr><tr><td>"; | |
111 | ||
112 | print __('Subject:'); | |
113 | ||
114 | print "</td><td>"; | |
115 | ||
116 | print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\" | |
117 | style=\"width : 30em;\" | |
118 | name=\"subject\" value=\"$subject\" id=\"subject\">"; | |
119 | ||
120 | print "</td></tr>"; | |
121 | ||
122 | print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 100%' rows=\"20\" | |
123 | name='content'>$content</textarea>"; | |
124 | ||
125 | print "</td></tr></table>"; | |
126 | ||
127 | print "<div class='dlgButtons'>"; | |
128 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').execute()\">".__('Send e-mail')."</button> "; | |
129 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Cancel')."</button>"; | |
130 | print "</div>"; | |
131 | ||
132 | //return; | |
133 | } | |
134 | ||
135 | function sendEmail() { | |
1b2afd2b | 136 | require_once 'classes/ttrssmailer.php'; |
1baac280 AD |
137 | |
138 | $reply = array(); | |
139 | ||
83b1ddaf | 140 | $mail = new ttrssMailer(); |
1baac280 | 141 | |
ea4e1103 AD |
142 | $mail->From = strip_tags($_REQUEST['from_email']); |
143 | $mail->FromName = strip_tags($_REQUEST['from_name']); | |
6dd01fce | 144 | //$mail->AddAddress($_REQUEST['destination']); |
ed7dd4bf | 145 | $addresses = explode(';', $_REQUEST['destination']); |
6dd01fce | 146 | foreach($addresses as $nextaddr) |
147 | $mail->AddAddress($nextaddr); | |
1baac280 | 148 | |
83b1ddaf AD |
149 | $mail->IsHTML(false); |
150 | $mail->Subject = $_REQUEST['subject']; | |
151 | $mail->Body = $_REQUEST['content']; | |
1baac280 | 152 | |
83b1ddaf | 153 | $rc = $mail->Send(); |
1baac280 | 154 | |
83b1ddaf AD |
155 | if (!$rc) { |
156 | $reply['error'] = $mail->ErrorInfo; | |
1baac280 | 157 | } else { |
a42c55f0 | 158 | save_email_address(db_escape_string($destination)); |
83b1ddaf | 159 | $reply['message'] = "UPDATE_COUNTERS"; |
1baac280 AD |
160 | } |
161 | ||
162 | print json_encode($reply); | |
163 | } | |
164 | ||
165 | function completeEmails() { | |
a42c55f0 | 166 | $search = db_escape_string($_REQUEST["search"]); |
1baac280 AD |
167 | |
168 | print "<ul>"; | |
169 | ||
170 | foreach ($_SESSION['stored_emails'] as $email) { | |
171 | if (strpos($email, $search) !== false) { | |
172 | print "<li>$email</li>"; | |
173 | } | |
174 | } | |
175 | ||
176 | print "</ul>"; | |
177 | } | |
178 | ||
106a3de9 AD |
179 | function api_version() { |
180 | return 2; | |
181 | } | |
1baac280 AD |
182 | |
183 | } | |
184 | ?> |