Repository navigation
Expand file tree
/
Copy pathinit.php
More file actions
163 lines (122 loc) · 5.25 KB
/
Copy pathinit.php
File metadata and controls
163 lines (122 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
class Kindle extends Plugin {
private $host;
function about() {
return array(0.2,
"Share articles to kindle using tinderizer",
"usr42");
}
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
$host->add_hook($host::HOOK_PREFS_TAB_SECTION, $this);
$host->add_hook($host::HOOK_HOTKEY_MAP, $this);
$host->add_hook($host::HOOK_HOTKEY_INFO, $this);
}
function hook_hotkey_map($hotkeys) {
// Use the new target "open_in_background_tab" to define your own
// hotkey to this function in other plugins.
$hotkeys['*k'] = 'send_to_kindle';
return $hotkeys;
}
function hook_hotkey_info($hotkeys) {
$hotkeys[__("Article")]["send_to_kindle"] = __("Send Article to your Kindle");
return $hotkeys;
}
function get_js() {
return file_get_contents(dirname(__FILE__) . "/kindle.js");
}
function hook_article_button($line) {
return "<img src=\"plugins/kindle/kindle.png\"
class='tagsPic' style=\"cursor : pointer\"
onclick=\"emailArticleKindle(".$line["id"].")\"
alt='Zoom' title='Send to kindle'>";
}
function hook_prefs_tab_section($args) {
if ($args != "prefPrefsAuth") return;
print "<h2>Kindle ".__('E-mail')."</h2>";
$email = $this->host->get($this, "kindle-mail");
print "<form dojoType=\"dijit.form.Form\">";
print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
evt.preventDefault();
if (this.validate()) {
new Ajax.Request('backend.php', {
parameters: dojo.objectToQuery(this.getValues()),
onComplete: function(transport) {
notify_info(transport.responseText);
}
});
}
</script>";
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">";
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">";
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"kindle\">";
print "<table width=\"100%\" class=\"prefPrefsList\">";
print "<tr><td width=\"40%\">Kindle ".__('E-mail')."</td>";
print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
print "</table>";
print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".__("Save")."</button>";
print "</form>";
}
function save() {
$email = db_escape_string($_POST["email"]);
if ( !filter_var($email, FILTER_VALIDATE_EMAIL) ) {
echo "Mail address is not valid!";
exit;
}
$this->host->set($this, "kindle-mail", $email);
echo __("Configuration saved.");
}
function sendEmail() {
require_once 'classes/ttrssmailer.php';
$id = db_escape_string($_REQUEST['id']);
$email = $this->host->get($this, "kindle-mail");
if ( !filter_var($email, FILTER_VALIDATE_EMAIL) ) {
$reply['error'] = "No valid mail-address is configured.\nGo to Preferences->'Personal data / Authentication'->'Kindle E-Mail' and save your kindle mail address.";
print json_encode($reply);
exit;
}
$hex = '';
$ascii = $email;
for ($i = 0; $i < strlen($ascii); $i++) {
$byte = strtolower(dechex(ord($ascii{$i})));
$byte = str_repeat('0', 2 - strlen($byte)).$byte;
$hex .= $byte;
}
$tindmail = $hex."@tinderizer.com";
$reply = array();
$link = "";
$mail = new ttrssMailer();
$result = db_query("SELECT email, full_name FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
$mail->From = strip_tags(htmlspecialchars(db_fetch_result($result, 0, "email")));
$mail->FromName = strip_tags(htmlspecialchars(db_fetch_result($result, 0, "full_name")));
$mail->AddAddress($tindmail);
$result = db_query("SELECT link, content, title, note
FROM ttrss_user_entries, ttrss_entries
WHERE id = '$id' AND ref_id = id AND owner_uid = " .$_SESSION['uid']);
$mail->IsHTML(false);
if (db_num_rows($result) > 1) {
$subject = __("[Forwarded]") . " " . __("Multiple articles");
}
while ($line = db_fetch_assoc($result)) {
if (!$subject) {
$subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
}
$link = strip_tags($line["link"]);
}
$article_link = db_fetch_result($result, 0, 'link');
$mail->Subject = $subject;
$mail->Body = strip_tags($article_link);
$rc = $mail->Send();
if (!$rc) {
$reply['error'] = $mail->ErrorInfo;
} else {
$reply['message'] = 'To address: '.$tindmail.'\nLink: '.$article_link;
}
print json_encode($reply);
}
function api_version() {
return 2;
}
}
?>