@@ -99,8 +99,9 @@ |
||
99 | 99 | if ($service && get_schema_version() > 138) { |
100 | 100 | $user_id = $this->check_app_password($login, $password, $service); |
101 | 101 | |
102 | - if ($user_id) |
|
103 | - return $user_id; |
|
102 | + if ($user_id) { |
|
103 | + return $user_id; |
|
104 | + } |
|
104 | 105 | } |
105 | 106 | |
106 | 107 | if (get_schema_version() > 87) { |
@@ -1,63 +1,63 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Auth_Internal extends Plugin implements IAuthModule { |
3 | 3 | |
4 | - private $host; |
|
4 | + private $host; |
|
5 | 5 | |
6 | - public function about() { |
|
7 | - return array(1.0, |
|
8 | - "Authenticates against internal tt-rss database", |
|
9 | - "fox", |
|
10 | - true); |
|
11 | - } |
|
6 | + public function about() { |
|
7 | + return array(1.0, |
|
8 | + "Authenticates against internal tt-rss database", |
|
9 | + "fox", |
|
10 | + true); |
|
11 | + } |
|
12 | 12 | |
13 | - /* @var PluginHost $host */ |
|
14 | - public function init($host) { |
|
15 | - $this->host = $host; |
|
16 | - $this->pdo = Db::pdo(); |
|
13 | + /* @var PluginHost $host */ |
|
14 | + public function init($host) { |
|
15 | + $this->host = $host; |
|
16 | + $this->pdo = Db::pdo(); |
|
17 | 17 | |
18 | - $host->add_hook($host::HOOK_AUTH_USER, $this); |
|
19 | - } |
|
18 | + $host->add_hook($host::HOOK_AUTH_USER, $this); |
|
19 | + } |
|
20 | 20 | |
21 | - public function authenticate($login, $password, $service = '') { |
|
21 | + public function authenticate($login, $password, $service = '') { |
|
22 | 22 | |
23 | - $pwd_hash1 = encrypt_password($password); |
|
24 | - $pwd_hash2 = encrypt_password($password, $login); |
|
25 | - $otp = $_REQUEST["otp"]; |
|
23 | + $pwd_hash1 = encrypt_password($password); |
|
24 | + $pwd_hash2 = encrypt_password($password, $login); |
|
25 | + $otp = $_REQUEST["otp"]; |
|
26 | 26 | |
27 | - if (get_schema_version() > 96) { |
|
27 | + if (get_schema_version() > 96) { |
|
28 | 28 | |
29 | - $sth = $this->pdo->prepare("SELECT otp_enabled,salt FROM ttrss_users WHERE |
|
29 | + $sth = $this->pdo->prepare("SELECT otp_enabled,salt FROM ttrss_users WHERE |
|
30 | 30 | login = ?"); |
31 | - $sth->execute([$login]); |
|
31 | + $sth->execute([$login]); |
|
32 | 32 | |
33 | - if ($row = $sth->fetch()) { |
|
34 | - $otp_enabled = $row['otp_enabled']; |
|
33 | + if ($row = $sth->fetch()) { |
|
34 | + $otp_enabled = $row['otp_enabled']; |
|
35 | 35 | |
36 | - if ($otp_enabled) { |
|
36 | + if ($otp_enabled) { |
|
37 | 37 | |
38 | - // only allow app password checking if OTP is enabled |
|
39 | - if ($service && get_schema_version() > 138) { |
|
40 | - return $this->check_app_password($login, $password, $service); |
|
41 | - } |
|
38 | + // only allow app password checking if OTP is enabled |
|
39 | + if ($service && get_schema_version() > 138) { |
|
40 | + return $this->check_app_password($login, $password, $service); |
|
41 | + } |
|
42 | 42 | |
43 | - if ($otp) { |
|
44 | - $base32 = new \OTPHP\Base32(); |
|
43 | + if ($otp) { |
|
44 | + $base32 = new \OTPHP\Base32(); |
|
45 | 45 | |
46 | - $secret = $base32->encode(mb_substr(sha1($row["salt"]), 0, 12), false); |
|
47 | - $secret_legacy = $base32->encode(sha1($row["salt"])); |
|
46 | + $secret = $base32->encode(mb_substr(sha1($row["salt"]), 0, 12), false); |
|
47 | + $secret_legacy = $base32->encode(sha1($row["salt"])); |
|
48 | 48 | |
49 | - $totp = new \OTPHP\TOTP($secret); |
|
50 | - $otp_check = $totp->now(); |
|
49 | + $totp = new \OTPHP\TOTP($secret); |
|
50 | + $otp_check = $totp->now(); |
|
51 | 51 | |
52 | - $totp_legacy = new \OTPHP\TOTP($secret_legacy); |
|
53 | - $otp_check_legacy = $totp_legacy->now(); |
|
52 | + $totp_legacy = new \OTPHP\TOTP($secret_legacy); |
|
53 | + $otp_check_legacy = $totp_legacy->now(); |
|
54 | 54 | |
55 | - if ($otp != $otp_check && $otp != $otp_check_legacy) { |
|
56 | - return false; |
|
57 | - } |
|
58 | - } else { |
|
59 | - $return = urlencode($_REQUEST["return"]); |
|
60 | - ?> |
|
55 | + if ($otp != $otp_check && $otp != $otp_check_legacy) { |
|
56 | + return false; |
|
57 | + } |
|
58 | + } else { |
|
59 | + $return = urlencode($_REQUEST["return"]); |
|
60 | + ?> |
|
61 | 61 | <!DOCTYPE html> |
62 | 62 | <html> |
63 | 63 | <head> |
@@ -87,208 +87,208 @@ discard block |
||
87 | 87 | document.forms[0].otp.focus(); |
88 | 88 | </script> |
89 | 89 | <?php |
90 | - exit; |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
90 | + exit; |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | 95 | |
96 | - // check app passwords first but allow regular password as a fallback for the time being |
|
97 | - // if OTP is not enabled |
|
96 | + // check app passwords first but allow regular password as a fallback for the time being |
|
97 | + // if OTP is not enabled |
|
98 | 98 | |
99 | - if ($service && get_schema_version() > 138) { |
|
100 | - $user_id = $this->check_app_password($login, $password, $service); |
|
99 | + if ($service && get_schema_version() > 138) { |
|
100 | + $user_id = $this->check_app_password($login, $password, $service); |
|
101 | 101 | |
102 | - if ($user_id) |
|
103 | - return $user_id; |
|
104 | - } |
|
102 | + if ($user_id) |
|
103 | + return $user_id; |
|
104 | + } |
|
105 | 105 | |
106 | - if (get_schema_version() > 87) { |
|
106 | + if (get_schema_version() > 87) { |
|
107 | 107 | |
108 | - $sth = $this->pdo->prepare("SELECT salt FROM ttrss_users WHERE login = ?"); |
|
109 | - $sth->execute([$login]); |
|
108 | + $sth = $this->pdo->prepare("SELECT salt FROM ttrss_users WHERE login = ?"); |
|
109 | + $sth->execute([$login]); |
|
110 | 110 | |
111 | - if ($row = $sth->fetch()) { |
|
112 | - $salt = $row['salt']; |
|
111 | + if ($row = $sth->fetch()) { |
|
112 | + $salt = $row['salt']; |
|
113 | 113 | |
114 | - if ($salt == "") { |
|
114 | + if ($salt == "") { |
|
115 | 115 | |
116 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
116 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
117 | 117 | login = ? AND (pwd_hash = ? OR pwd_hash = ?)"); |
118 | 118 | |
119 | - $sth->execute([$login, $pwd_hash1, $pwd_hash2]); |
|
119 | + $sth->execute([$login, $pwd_hash1, $pwd_hash2]); |
|
120 | 120 | |
121 | - // verify and upgrade password to new salt base |
|
121 | + // verify and upgrade password to new salt base |
|
122 | 122 | |
123 | - if ($row = $sth->fetch()) { |
|
124 | - // upgrade password to MODE2 |
|
123 | + if ($row = $sth->fetch()) { |
|
124 | + // upgrade password to MODE2 |
|
125 | 125 | |
126 | - $user_id = $row['id']; |
|
126 | + $user_id = $row['id']; |
|
127 | 127 | |
128 | - $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
129 | - $pwd_hash = encrypt_password($password, $salt, true); |
|
128 | + $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
129 | + $pwd_hash = encrypt_password($password, $salt, true); |
|
130 | 130 | |
131 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
131 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
132 | 132 | pwd_hash = ?, salt = ? WHERE login = ?"); |
133 | 133 | |
134 | - $sth->execute([$pwd_hash, $salt, $login]); |
|
134 | + $sth->execute([$pwd_hash, $salt, $login]); |
|
135 | 135 | |
136 | - return $user_id; |
|
136 | + return $user_id; |
|
137 | 137 | |
138 | - } else { |
|
139 | - return false; |
|
140 | - } |
|
138 | + } else { |
|
139 | + return false; |
|
140 | + } |
|
141 | 141 | |
142 | - } else { |
|
143 | - $pwd_hash = encrypt_password($password, $salt, true); |
|
142 | + } else { |
|
143 | + $pwd_hash = encrypt_password($password, $salt, true); |
|
144 | 144 | |
145 | - $sth = $this->pdo->prepare("SELECT id |
|
145 | + $sth = $this->pdo->prepare("SELECT id |
|
146 | 146 | FROM ttrss_users WHERE |
147 | 147 | login = ? AND pwd_hash = ?"); |
148 | - $sth->execute([$login, $pwd_hash]); |
|
148 | + $sth->execute([$login, $pwd_hash]); |
|
149 | 149 | |
150 | - if ($row = $sth->fetch()) { |
|
151 | - return $row['id']; |
|
152 | - } |
|
153 | - } |
|
150 | + if ($row = $sth->fetch()) { |
|
151 | + return $row['id']; |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | - } else { |
|
156 | - $sth = $this->pdo->prepare("SELECT id |
|
155 | + } else { |
|
156 | + $sth = $this->pdo->prepare("SELECT id |
|
157 | 157 | FROM ttrss_users WHERE |
158 | 158 | login = ? AND (pwd_hash = ? OR pwd_hash = ?)"); |
159 | 159 | |
160 | - $sth->execute([$login, $pwd_hash1, $pwd_hash2]); |
|
160 | + $sth->execute([$login, $pwd_hash1, $pwd_hash2]); |
|
161 | 161 | |
162 | - if ($row = $sth->fetch()) { |
|
163 | - return $row['id']; |
|
164 | - } |
|
165 | - } |
|
166 | - } else { |
|
167 | - $sth = $this->pdo->prepare("SELECT id |
|
162 | + if ($row = $sth->fetch()) { |
|
163 | + return $row['id']; |
|
164 | + } |
|
165 | + } |
|
166 | + } else { |
|
167 | + $sth = $this->pdo->prepare("SELECT id |
|
168 | 168 | FROM ttrss_users WHERE |
169 | 169 | login = ? AND (pwd_hash = ? OR pwd_hash = ?)"); |
170 | 170 | |
171 | - $sth->execute([$login, $pwd_hash1, $pwd_hash2]); |
|
171 | + $sth->execute([$login, $pwd_hash1, $pwd_hash2]); |
|
172 | 172 | |
173 | - if ($row = $sth->fetch()) { |
|
174 | - return $row['id']; |
|
175 | - } |
|
176 | - } |
|
173 | + if ($row = $sth->fetch()) { |
|
174 | + return $row['id']; |
|
175 | + } |
|
176 | + } |
|
177 | 177 | |
178 | - return false; |
|
179 | - } |
|
178 | + return false; |
|
179 | + } |
|
180 | 180 | |
181 | - public function check_password($owner_uid, $password) { |
|
181 | + public function check_password($owner_uid, $password) { |
|
182 | 182 | |
183 | - $sth = $this->pdo->prepare("SELECT salt,login,otp_enabled FROM ttrss_users WHERE |
|
183 | + $sth = $this->pdo->prepare("SELECT salt,login,otp_enabled FROM ttrss_users WHERE |
|
184 | 184 | id = ?"); |
185 | - $sth->execute([$owner_uid]); |
|
185 | + $sth->execute([$owner_uid]); |
|
186 | 186 | |
187 | - if ($row = $sth->fetch()) { |
|
187 | + if ($row = $sth->fetch()) { |
|
188 | 188 | |
189 | - $salt = $row['salt']; |
|
190 | - $login = $row['login']; |
|
189 | + $salt = $row['salt']; |
|
190 | + $login = $row['login']; |
|
191 | 191 | |
192 | - if (!$salt) { |
|
193 | - $password_hash1 = encrypt_password($password); |
|
194 | - $password_hash2 = encrypt_password($password, $login); |
|
192 | + if (!$salt) { |
|
193 | + $password_hash1 = encrypt_password($password); |
|
194 | + $password_hash2 = encrypt_password($password, $login); |
|
195 | 195 | |
196 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
196 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
197 | 197 | id = ? AND (pwd_hash = ? OR pwd_hash = ?)"); |
198 | 198 | |
199 | - $sth->execute([$owner_uid, $password_hash1, $password_hash2]); |
|
199 | + $sth->execute([$owner_uid, $password_hash1, $password_hash2]); |
|
200 | 200 | |
201 | - return $sth->fetch(); |
|
201 | + return $sth->fetch(); |
|
202 | 202 | |
203 | - } else { |
|
204 | - $password_hash = encrypt_password($password, $salt, true); |
|
203 | + } else { |
|
204 | + $password_hash = encrypt_password($password, $salt, true); |
|
205 | 205 | |
206 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
206 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
207 | 207 | id = ? AND pwd_hash = ?"); |
208 | 208 | |
209 | - $sth->execute([$owner_uid, $password_hash]); |
|
209 | + $sth->execute([$owner_uid, $password_hash]); |
|
210 | 210 | |
211 | - return $sth->fetch(); |
|
212 | - } |
|
213 | - } |
|
211 | + return $sth->fetch(); |
|
212 | + } |
|
213 | + } |
|
214 | 214 | |
215 | - return false; |
|
216 | - } |
|
215 | + return false; |
|
216 | + } |
|
217 | 217 | |
218 | - public function change_password($owner_uid, $old_password, $new_password) { |
|
218 | + public function change_password($owner_uid, $old_password, $new_password) { |
|
219 | 219 | |
220 | - if ($this->check_password($owner_uid, $old_password)) { |
|
220 | + if ($this->check_password($owner_uid, $old_password)) { |
|
221 | 221 | |
222 | - $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
223 | - $new_password_hash = encrypt_password($new_password, $new_salt, true); |
|
222 | + $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
223 | + $new_password_hash = encrypt_password($new_password, $new_salt, true); |
|
224 | 224 | |
225 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
225 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
226 | 226 | pwd_hash = ?, salt = ?, otp_enabled = false |
227 | 227 | WHERE id = ?"); |
228 | - $sth->execute([$new_password_hash, $new_salt, $owner_uid]); |
|
228 | + $sth->execute([$new_password_hash, $new_salt, $owner_uid]); |
|
229 | 229 | |
230 | - $_SESSION["pwd_hash"] = $new_password_hash; |
|
230 | + $_SESSION["pwd_hash"] = $new_password_hash; |
|
231 | 231 | |
232 | - $sth = $this->pdo->prepare("SELECT email, login FROM ttrss_users WHERE id = ?"); |
|
233 | - $sth->execute([$owner_uid]); |
|
232 | + $sth = $this->pdo->prepare("SELECT email, login FROM ttrss_users WHERE id = ?"); |
|
233 | + $sth->execute([$owner_uid]); |
|
234 | 234 | |
235 | - if ($row = $sth->fetch()) { |
|
236 | - $mailer = new Mailer(); |
|
235 | + if ($row = $sth->fetch()) { |
|
236 | + $mailer = new Mailer(); |
|
237 | 237 | |
238 | - require_once "lib/MiniTemplator.class.php"; |
|
238 | + require_once "lib/MiniTemplator.class.php"; |
|
239 | 239 | |
240 | - $tpl = new MiniTemplator; |
|
240 | + $tpl = new MiniTemplator; |
|
241 | 241 | |
242 | - $tpl->readTemplateFromFile("templates/password_change_template.txt"); |
|
242 | + $tpl->readTemplateFromFile("templates/password_change_template.txt"); |
|
243 | 243 | |
244 | - $tpl->setVariable('LOGIN', $row["login"]); |
|
245 | - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
244 | + $tpl->setVariable('LOGIN', $row["login"]); |
|
245 | + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
246 | 246 | |
247 | - $tpl->addBlock('message'); |
|
247 | + $tpl->addBlock('message'); |
|
248 | 248 | |
249 | - $tpl->generateOutputToString($message); |
|
249 | + $tpl->generateOutputToString($message); |
|
250 | 250 | |
251 | - $mailer->mail(["to_name" => $row["login"], |
|
252 | - "to_address" => $row["email"], |
|
253 | - "subject" => "[tt-rss] Password change notification", |
|
254 | - "message" => $message]); |
|
251 | + $mailer->mail(["to_name" => $row["login"], |
|
252 | + "to_address" => $row["email"], |
|
253 | + "subject" => "[tt-rss] Password change notification", |
|
254 | + "message" => $message]); |
|
255 | 255 | |
256 | - } |
|
256 | + } |
|
257 | 257 | |
258 | - return __("Password has been changed."); |
|
259 | - } else { |
|
260 | - return "ERROR: ".__('Old password is incorrect.'); |
|
261 | - } |
|
262 | - } |
|
258 | + return __("Password has been changed."); |
|
259 | + } else { |
|
260 | + return "ERROR: ".__('Old password is incorrect.'); |
|
261 | + } |
|
262 | + } |
|
263 | 263 | |
264 | - private function check_app_password($login, $password, $service) { |
|
265 | - $sth = $this->pdo->prepare("SELECT p.id, p.pwd_hash, u.id AS uid |
|
264 | + private function check_app_password($login, $password, $service) { |
|
265 | + $sth = $this->pdo->prepare("SELECT p.id, p.pwd_hash, u.id AS uid |
|
266 | 266 | FROM ttrss_app_passwords p, ttrss_users u |
267 | 267 | WHERE p.owner_uid = u.id AND u.login = ? AND service = ?"); |
268 | - $sth->execute([$login, $service]); |
|
268 | + $sth->execute([$login, $service]); |
|
269 | 269 | |
270 | - while ($row = $sth->fetch()) { |
|
271 | - list ($algo, $hash, $salt) = explode(":", $row["pwd_hash"]); |
|
270 | + while ($row = $sth->fetch()) { |
|
271 | + list ($algo, $hash, $salt) = explode(":", $row["pwd_hash"]); |
|
272 | 272 | |
273 | - if ($algo == "SSHA-512") { |
|
274 | - $test_hash = hash('sha512', $salt . $password); |
|
273 | + if ($algo == "SSHA-512") { |
|
274 | + $test_hash = hash('sha512', $salt . $password); |
|
275 | 275 | |
276 | - if ($test_hash == $hash) { |
|
277 | - $usth = $this->pdo->prepare("UPDATE ttrss_app_passwords SET last_used = NOW() WHERE id = ?"); |
|
278 | - $usth->execute([$row['id']]); |
|
276 | + if ($test_hash == $hash) { |
|
277 | + $usth = $this->pdo->prepare("UPDATE ttrss_app_passwords SET last_used = NOW() WHERE id = ?"); |
|
278 | + $usth->execute([$row['id']]); |
|
279 | 279 | |
280 | - return $row['uid']; |
|
281 | - } |
|
282 | - } else { |
|
283 | - user_error("Got unknown algo of app password for user $login: $algo"); |
|
284 | - } |
|
285 | - } |
|
280 | + return $row['uid']; |
|
281 | + } |
|
282 | + } else { |
|
283 | + user_error("Got unknown algo of app password for user $login: $algo"); |
|
284 | + } |
|
285 | + } |
|
286 | 286 | |
287 | - return false; |
|
288 | - } |
|
287 | + return false; |
|
288 | + } |
|
289 | 289 | |
290 | - public function api_version() { |
|
291 | - return 2; |
|
292 | - } |
|
290 | + public function api_version() { |
|
291 | + return 2; |
|
292 | + } |
|
293 | 293 | |
294 | 294 | } |
@@ -23,8 +23,9 @@ |
||
23 | 23 | $entries = $xpath->query('//iframe'); |
24 | 24 | |
25 | 25 | foreach ($entries as $entry) { |
26 | - if (!iframe_whitelisted($entry)) |
|
27 | - $entry->parentNode->removeChild($entry); |
|
26 | + if (!iframe_whitelisted($entry)) { |
|
27 | + $entry->parentNode->removeChild($entry); |
|
28 | + } |
|
28 | 29 | } |
29 | 30 | |
30 | 31 | return array($doc, $allowed_elements, $disallowed_attributes); |
@@ -1,37 +1,37 @@ |
||
1 | 1 | <?php |
2 | 2 | class No_Iframes extends Plugin { |
3 | - private $host; |
|
3 | + private $host; |
|
4 | 4 | |
5 | - public function about() { |
|
6 | - return array(1.0, |
|
7 | - "Remove embedded iframes (unless whitelisted)", |
|
8 | - "fox"); |
|
9 | - } |
|
5 | + public function about() { |
|
6 | + return array(1.0, |
|
7 | + "Remove embedded iframes (unless whitelisted)", |
|
8 | + "fox"); |
|
9 | + } |
|
10 | 10 | |
11 | - public function init($host) { |
|
12 | - $this->host = $host; |
|
11 | + public function init($host) { |
|
12 | + $this->host = $host; |
|
13 | 13 | |
14 | - $host->add_hook($host::HOOK_SANITIZE, $this); |
|
15 | - } |
|
14 | + $host->add_hook($host::HOOK_SANITIZE, $this); |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
19 | - */ |
|
20 | - public function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes) { |
|
17 | + /** |
|
18 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
19 | + */ |
|
20 | + public function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes) { |
|
21 | 21 | |
22 | - $xpath = new DOMXpath($doc); |
|
23 | - $entries = $xpath->query('//iframe'); |
|
22 | + $xpath = new DOMXpath($doc); |
|
23 | + $entries = $xpath->query('//iframe'); |
|
24 | 24 | |
25 | - foreach ($entries as $entry) { |
|
26 | - if (!iframe_whitelisted($entry)) |
|
27 | - $entry->parentNode->removeChild($entry); |
|
28 | - } |
|
25 | + foreach ($entries as $entry) { |
|
26 | + if (!iframe_whitelisted($entry)) |
|
27 | + $entry->parentNode->removeChild($entry); |
|
28 | + } |
|
29 | 29 | |
30 | - return array($doc, $allowed_elements, $disallowed_attributes); |
|
31 | - } |
|
30 | + return array($doc, $allowed_elements, $disallowed_attributes); |
|
31 | + } |
|
32 | 32 | |
33 | - public function api_version() { |
|
34 | - return 2; |
|
35 | - } |
|
33 | + public function api_version() { |
|
34 | + return 2; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | } |
@@ -14,8 +14,9 @@ |
||
14 | 14 | |
15 | 15 | global $fetch_last_error_content; |
16 | 16 | |
17 | - if (!$res && $fetch_last_error_content) |
|
18 | - $res = $fetch_last_error_content; |
|
17 | + if (!$res && $fetch_last_error_content) { |
|
18 | + $res = $fetch_last_error_content; |
|
19 | + } |
|
19 | 20 | |
20 | 21 | $doc = new DOMDocument(); |
21 | 22 |
@@ -1,36 +1,36 @@ |
||
1 | 1 | <?php |
2 | 2 | class Af_Comics_Whomp extends Af_ComicFilter { |
3 | 3 | |
4 | - public function supported() { |
|
5 | - return array("Whomp!"); |
|
6 | - } |
|
4 | + public function supported() { |
|
5 | + return array("Whomp!"); |
|
6 | + } |
|
7 | 7 | |
8 | - public function process(&$article) { |
|
9 | - if (strpos($article["guid"], "whompcomic.com") !== false) { |
|
8 | + public function process(&$article) { |
|
9 | + if (strpos($article["guid"], "whompcomic.com") !== false) { |
|
10 | 10 | |
11 | - $res = fetch_file_contents($article["link"], false, false, false, |
|
12 | - false, false, 0, |
|
13 | - "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); |
|
11 | + $res = fetch_file_contents($article["link"], false, false, false, |
|
12 | + false, false, 0, |
|
13 | + "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); |
|
14 | 14 | |
15 | - global $fetch_last_error_content; |
|
15 | + global $fetch_last_error_content; |
|
16 | 16 | |
17 | - if (!$res && $fetch_last_error_content) |
|
18 | - $res = $fetch_last_error_content; |
|
17 | + if (!$res && $fetch_last_error_content) |
|
18 | + $res = $fetch_last_error_content; |
|
19 | 19 | |
20 | - $doc = new DOMDocument(); |
|
20 | + $doc = new DOMDocument(); |
|
21 | 21 | |
22 | - if (@$doc->loadHTML($res)) { |
|
23 | - $xpath = new DOMXPath($doc); |
|
24 | - $basenode = $xpath->query('//img[@id="cc-comic"]')->item(0); |
|
22 | + if (@$doc->loadHTML($res)) { |
|
23 | + $xpath = new DOMXPath($doc); |
|
24 | + $basenode = $xpath->query('//img[@id="cc-comic"]')->item(0); |
|
25 | 25 | |
26 | - if ($basenode) { |
|
27 | - $article["content"] = $doc->saveHTML($basenode); |
|
28 | - } |
|
29 | - } |
|
26 | + if ($basenode) { |
|
27 | + $article["content"] = $doc->saveHTML($basenode); |
|
28 | + } |
|
29 | + } |
|
30 | 30 | |
31 | - return true; |
|
32 | - } |
|
31 | + return true; |
|
32 | + } |
|
33 | 33 | |
34 | - return false; |
|
35 | - } |
|
34 | + return false; |
|
35 | + } |
|
36 | 36 | } |
@@ -15,8 +15,9 @@ |
||
15 | 15 | |
16 | 16 | global $fetch_last_error_content; |
17 | 17 | |
18 | - if (!$res && $fetch_last_error_content) |
|
19 | - $res = $fetch_last_error_content; |
|
18 | + if (!$res && $fetch_last_error_content) { |
|
19 | + $res = $fetch_last_error_content; |
|
20 | + } |
|
20 | 21 | |
21 | 22 | $doc = new DOMDocument(); |
22 | 23 |
@@ -1,38 +1,38 @@ |
||
1 | 1 | <?php |
2 | 2 | class Af_Comics_DarkLegacy extends Af_ComicFilter { |
3 | 3 | |
4 | - public function supported() { |
|
5 | - return array("Dark Legacy Comics"); |
|
6 | - } |
|
4 | + public function supported() { |
|
5 | + return array("Dark Legacy Comics"); |
|
6 | + } |
|
7 | 7 | |
8 | - public function process(&$article) { |
|
8 | + public function process(&$article) { |
|
9 | 9 | |
10 | - if (strpos($article["guid"], "darklegacycomics.com") !== false) { |
|
10 | + if (strpos($article["guid"], "darklegacycomics.com") !== false) { |
|
11 | 11 | |
12 | - $res = fetch_file_contents($article["link"], false, false, false, |
|
13 | - false, false, 0, |
|
14 | - "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); |
|
12 | + $res = fetch_file_contents($article["link"], false, false, false, |
|
13 | + false, false, 0, |
|
14 | + "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); |
|
15 | 15 | |
16 | - global $fetch_last_error_content; |
|
16 | + global $fetch_last_error_content; |
|
17 | 17 | |
18 | - if (!$res && $fetch_last_error_content) |
|
19 | - $res = $fetch_last_error_content; |
|
18 | + if (!$res && $fetch_last_error_content) |
|
19 | + $res = $fetch_last_error_content; |
|
20 | 20 | |
21 | - $doc = new DOMDocument(); |
|
21 | + $doc = new DOMDocument(); |
|
22 | 22 | |
23 | - if (@$doc->loadHTML($res)) { |
|
24 | - $xpath = new DOMXPath($doc); |
|
25 | - $basenode = $xpath->query('//div[@class="comic"]')->item(0); |
|
23 | + if (@$doc->loadHTML($res)) { |
|
24 | + $xpath = new DOMXPath($doc); |
|
25 | + $basenode = $xpath->query('//div[@class="comic"]')->item(0); |
|
26 | 26 | |
27 | - if ($basenode) { |
|
27 | + if ($basenode) { |
|
28 | 28 | |
29 | - $article["content"] = $doc->saveHTML($basenode); |
|
30 | - } |
|
31 | - } |
|
29 | + $article["content"] = $doc->saveHTML($basenode); |
|
30 | + } |
|
31 | + } |
|
32 | 32 | |
33 | - return true; |
|
34 | - } |
|
33 | + return true; |
|
34 | + } |
|
35 | 35 | |
36 | - return false; |
|
37 | - } |
|
36 | + return false; |
|
37 | + } |
|
38 | 38 | } |
@@ -46,8 +46,9 @@ |
||
46 | 46 | |
47 | 47 | $avatar = $xpath->query('(//div[@class="avatar"]//img)')->item(0); |
48 | 48 | |
49 | - if ($basenode) |
|
50 | - $basenode->insertBefore($avatar, $basenode->firstChild); |
|
49 | + if ($basenode) { |
|
50 | + $basenode->insertBefore($avatar, $basenode->firstChild); |
|
51 | + } |
|
51 | 52 | |
52 | 53 | $uninteresting = $xpath->query('(//div[@class="avatar"])'); |
53 | 54 | foreach ($uninteresting as $i) { |
@@ -1,67 +1,67 @@ |
||
1 | 1 | <?php |
2 | 2 | class Af_Comics_Pa extends Af_ComicFilter { |
3 | 3 | |
4 | - public function supported() { |
|
5 | - return array("Penny Arcade"); |
|
6 | - } |
|
4 | + public function supported() { |
|
5 | + return array("Penny Arcade"); |
|
6 | + } |
|
7 | 7 | |
8 | - public function process(&$article) { |
|
9 | - if (strpos($article["link"], "penny-arcade.com") !== false && strpos($article["title"], "Comic:") !== false) { |
|
8 | + public function process(&$article) { |
|
9 | + if (strpos($article["link"], "penny-arcade.com") !== false && strpos($article["title"], "Comic:") !== false) { |
|
10 | 10 | |
11 | - $doc = new DOMDocument(); |
|
11 | + $doc = new DOMDocument(); |
|
12 | 12 | |
13 | - if ($doc->loadHTML(fetch_file_contents($article["link"]))) { |
|
14 | - $xpath = new DOMXPath($doc); |
|
15 | - $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0); |
|
13 | + if ($doc->loadHTML(fetch_file_contents($article["link"]))) { |
|
14 | + $xpath = new DOMXPath($doc); |
|
15 | + $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0); |
|
16 | 16 | |
17 | - if ($basenode) { |
|
18 | - $article["content"] = $doc->saveHTML($basenode); |
|
19 | - } |
|
20 | - } |
|
17 | + if ($basenode) { |
|
18 | + $article["content"] = $doc->saveHTML($basenode); |
|
19 | + } |
|
20 | + } |
|
21 | 21 | |
22 | - return true; |
|
23 | - } |
|
22 | + return true; |
|
23 | + } |
|
24 | 24 | |
25 | - if (strpos($article["link"], "penny-arcade.com") !== false && strpos($article["title"], "News Post:") !== false) { |
|
26 | - $doc = new DOMDocument(); |
|
25 | + if (strpos($article["link"], "penny-arcade.com") !== false && strpos($article["title"], "News Post:") !== false) { |
|
26 | + $doc = new DOMDocument(); |
|
27 | 27 | |
28 | - if ($doc->loadHTML(fetch_file_contents($article["link"]))) { |
|
29 | - $xpath = new DOMXPath($doc); |
|
30 | - $entries = $xpath->query('(//div[@class="post"])'); |
|
28 | + if ($doc->loadHTML(fetch_file_contents($article["link"]))) { |
|
29 | + $xpath = new DOMXPath($doc); |
|
30 | + $entries = $xpath->query('(//div[@class="post"])'); |
|
31 | 31 | |
32 | - $basenode = false; |
|
32 | + $basenode = false; |
|
33 | 33 | |
34 | - foreach ($entries as $entry) { |
|
35 | - $basenode = $entry; |
|
36 | - } |
|
34 | + foreach ($entries as $entry) { |
|
35 | + $basenode = $entry; |
|
36 | + } |
|
37 | 37 | |
38 | - $meta = $xpath->query('(//div[@class="meta"])')->item(0); |
|
39 | - if ($meta->parentNode) { $meta->parentNode->removeChild($meta); } |
|
38 | + $meta = $xpath->query('(//div[@class="meta"])')->item(0); |
|
39 | + if ($meta->parentNode) { $meta->parentNode->removeChild($meta); } |
|
40 | 40 | |
41 | - $header = $xpath->query('(//div[@class="postBody"]/h2)')->item(0); |
|
42 | - if ($header->parentNode) { $header->parentNode->removeChild($header); } |
|
41 | + $header = $xpath->query('(//div[@class="postBody"]/h2)')->item(0); |
|
42 | + if ($header->parentNode) { $header->parentNode->removeChild($header); } |
|
43 | 43 | |
44 | - $header = $xpath->query('(//div[@class="postBody"]/div[@class="comicPost"])')->item(0); |
|
45 | - if ($header->parentNode) { $header->parentNode->removeChild($header); } |
|
44 | + $header = $xpath->query('(//div[@class="postBody"]/div[@class="comicPost"])')->item(0); |
|
45 | + if ($header->parentNode) { $header->parentNode->removeChild($header); } |
|
46 | 46 | |
47 | - $avatar = $xpath->query('(//div[@class="avatar"]//img)')->item(0); |
|
47 | + $avatar = $xpath->query('(//div[@class="avatar"]//img)')->item(0); |
|
48 | 48 | |
49 | - if ($basenode) |
|
50 | - $basenode->insertBefore($avatar, $basenode->firstChild); |
|
49 | + if ($basenode) |
|
50 | + $basenode->insertBefore($avatar, $basenode->firstChild); |
|
51 | 51 | |
52 | - $uninteresting = $xpath->query('(//div[@class="avatar"])'); |
|
53 | - foreach ($uninteresting as $i) { |
|
54 | - $i->parentNode->removeChild($i); |
|
55 | - } |
|
52 | + $uninteresting = $xpath->query('(//div[@class="avatar"])'); |
|
53 | + foreach ($uninteresting as $i) { |
|
54 | + $i->parentNode->removeChild($i); |
|
55 | + } |
|
56 | 56 | |
57 | - if ($basenode){ |
|
58 | - $article["content"] = $doc->saveHTML($basenode); |
|
59 | - } |
|
60 | - } |
|
57 | + if ($basenode){ |
|
58 | + $article["content"] = $doc->saveHTML($basenode); |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - return true; |
|
63 | - } |
|
62 | + return true; |
|
63 | + } |
|
64 | 64 | |
65 | - return false; |
|
66 | - } |
|
65 | + return false; |
|
66 | + } |
|
67 | 67 | } |
@@ -17,8 +17,9 @@ |
||
17 | 17 | false, false, 0, |
18 | 18 | "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"); |
19 | 19 | |
20 | - if (!$res && $fetch_last_error_content) |
|
21 | - $res = $fetch_last_error_content; |
|
20 | + if (!$res && $fetch_last_error_content) { |
|
21 | + $res = $fetch_last_error_content; |
|
22 | + } |
|
22 | 23 | |
23 | 24 | if (@$doc->loadHTML($res)) { |
24 | 25 | $xpath = new DOMXPath($doc); |
@@ -1,39 +1,39 @@ |
||
1 | 1 | <?php |
2 | 2 | class Af_Comics_Cad extends Af_ComicFilter { |
3 | 3 | |
4 | - public function supported() { |
|
5 | - return array("Ctrl+Alt+Del"); |
|
6 | - } |
|
4 | + public function supported() { |
|
5 | + return array("Ctrl+Alt+Del"); |
|
6 | + } |
|
7 | 7 | |
8 | - public function process(&$article) { |
|
9 | - if (strpos($article["link"], "cad-comic.com") !== false) { |
|
10 | - if (strpos($article["title"], "News:") === false) { |
|
8 | + public function process(&$article) { |
|
9 | + if (strpos($article["link"], "cad-comic.com") !== false) { |
|
10 | + if (strpos($article["title"], "News:") === false) { |
|
11 | 11 | |
12 | - global $fetch_last_error_content; |
|
12 | + global $fetch_last_error_content; |
|
13 | 13 | |
14 | - $doc = new DOMDocument(); |
|
14 | + $doc = new DOMDocument(); |
|
15 | 15 | |
16 | - $res = fetch_file_contents($article["link"], false, false, false, |
|
17 | - false, false, 0, |
|
18 | - "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"); |
|
16 | + $res = fetch_file_contents($article["link"], false, false, false, |
|
17 | + false, false, 0, |
|
18 | + "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"); |
|
19 | 19 | |
20 | - if (!$res && $fetch_last_error_content) |
|
21 | - $res = $fetch_last_error_content; |
|
20 | + if (!$res && $fetch_last_error_content) |
|
21 | + $res = $fetch_last_error_content; |
|
22 | 22 | |
23 | - if (@$doc->loadHTML($res)) { |
|
24 | - $xpath = new DOMXPath($doc); |
|
25 | - $basenode = $xpath->query('//div[@class="comicpage"]/a/img')->item(0); |
|
23 | + if (@$doc->loadHTML($res)) { |
|
24 | + $xpath = new DOMXPath($doc); |
|
25 | + $basenode = $xpath->query('//div[@class="comicpage"]/a/img')->item(0); |
|
26 | 26 | |
27 | - if ($basenode) { |
|
28 | - $article["content"] = $doc->saveHTML($basenode); |
|
29 | - } |
|
30 | - } |
|
27 | + if ($basenode) { |
|
28 | + $article["content"] = $doc->saveHTML($basenode); |
|
29 | + } |
|
30 | + } |
|
31 | 31 | |
32 | - } |
|
32 | + } |
|
33 | 33 | |
34 | - return true; |
|
35 | - } |
|
34 | + return true; |
|
35 | + } |
|
36 | 36 | |
37 | - return false; |
|
38 | - } |
|
37 | + return false; |
|
38 | + } |
|
39 | 39 | } |
@@ -17,11 +17,13 @@ discard block |
||
17 | 17 | $this->host = $host; |
18 | 18 | $this->cache = new DiskCache("starred-images"); |
19 | 19 | |
20 | - if ($this->cache->makeDir()) |
|
21 | - chmod($this->cache->getDir(), 0777); |
|
20 | + if ($this->cache->makeDir()) { |
|
21 | + chmod($this->cache->getDir(), 0777); |
|
22 | + } |
|
22 | 23 | |
23 | - if (!$this->cache->exists(".no-auto-expiry")) |
|
24 | - $this->cache->touch(".no-auto-expiry"); |
|
24 | + if (!$this->cache->exists(".no-auto-expiry")) { |
|
25 | + $this->cache->touch(".no-auto-expiry"); |
|
26 | + } |
|
25 | 27 | |
26 | 28 | if ($this->cache->isWritable()) { |
27 | 29 | $host->add_hook($host::HOOK_HOUSE_KEEPING, $this); |
@@ -141,8 +143,10 @@ discard block |
||
141 | 143 | |
142 | 144 | $data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); |
143 | 145 | |
144 | - if ($data) |
|
145 | - return $this->cache->put($local_filename, $data);; |
|
146 | + if ($data) { |
|
147 | + return $this->cache->put($local_filename, $data); |
|
148 | + } |
|
149 | + ; |
|
146 | 150 | |
147 | 151 | } else { |
148 | 152 | //Debug::log("cache_images: local file exists for $url", Debug::$LOG_VERBOSE); |
@@ -167,10 +171,11 @@ discard block |
||
167 | 171 | |
168 | 172 | Debug::log("status: $status_filename", Debug::$LOG_VERBOSE); |
169 | 173 | |
170 | - if ($this->cache->exists($status_filename)) |
|
171 | - $status = json_decode($this->cache->get($status_filename), true); |
|
172 | - else |
|
173 | - $status = []; |
|
174 | + if ($this->cache->exists($status_filename)) { |
|
175 | + $status = json_decode($this->cache->get($status_filename), true); |
|
176 | + } else { |
|
177 | + $status = []; |
|
178 | + } |
|
174 | 179 | |
175 | 180 | $status["attempt"] += 1; |
176 | 181 |
@@ -1,43 +1,43 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Cache_Starred_Images extends Plugin { |
3 | 3 | |
4 | - /* @var PluginHost $host */ |
|
5 | - private $host; |
|
6 | - /* @var DiskCache $cache */ |
|
7 | - private $cache; |
|
4 | + /* @var PluginHost $host */ |
|
5 | + private $host; |
|
6 | + /* @var DiskCache $cache */ |
|
7 | + private $cache; |
|
8 | 8 | private $max_cache_attempts = 5; // per-article |
9 | 9 | |
10 | - public function about() { |
|
11 | - return array(1.0, |
|
12 | - "Automatically cache media files in Starred articles", |
|
13 | - "fox"); |
|
14 | - } |
|
10 | + public function about() { |
|
11 | + return array(1.0, |
|
12 | + "Automatically cache media files in Starred articles", |
|
13 | + "fox"); |
|
14 | + } |
|
15 | 15 | |
16 | - public function init($host) { |
|
17 | - $this->host = $host; |
|
18 | - $this->cache = new DiskCache("starred-images"); |
|
16 | + public function init($host) { |
|
17 | + $this->host = $host; |
|
18 | + $this->cache = new DiskCache("starred-images"); |
|
19 | 19 | |
20 | - if ($this->cache->makeDir()) |
|
21 | - chmod($this->cache->getDir(), 0777); |
|
20 | + if ($this->cache->makeDir()) |
|
21 | + chmod($this->cache->getDir(), 0777); |
|
22 | 22 | |
23 | - if (!$this->cache->exists(".no-auto-expiry")) |
|
24 | - $this->cache->touch(".no-auto-expiry"); |
|
23 | + if (!$this->cache->exists(".no-auto-expiry")) |
|
24 | + $this->cache->touch(".no-auto-expiry"); |
|
25 | 25 | |
26 | - if ($this->cache->isWritable()) { |
|
27 | - $host->add_hook($host::HOOK_HOUSE_KEEPING, $this); |
|
28 | - $host->add_hook($host::HOOK_ENCLOSURE_ENTRY, $this); |
|
29 | - $host->add_hook($host::HOOK_SANITIZE, $this); |
|
30 | - } else { |
|
31 | - user_error("Starred cache directory ".$this->cache->getDir()." is not writable.", E_USER_WARNING); |
|
32 | - } |
|
33 | - } |
|
26 | + if ($this->cache->isWritable()) { |
|
27 | + $host->add_hook($host::HOOK_HOUSE_KEEPING, $this); |
|
28 | + $host->add_hook($host::HOOK_ENCLOSURE_ENTRY, $this); |
|
29 | + $host->add_hook($host::HOOK_SANITIZE, $this); |
|
30 | + } else { |
|
31 | + user_error("Starred cache directory ".$this->cache->getDir()." is not writable.", E_USER_WARNING); |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | - public function hook_house_keeping() { |
|
36 | - /* since HOOK_UPDATE_TASK is not available to user plugins, this hook is a next best thing */ |
|
35 | + public function hook_house_keeping() { |
|
36 | + /* since HOOK_UPDATE_TASK is not available to user plugins, this hook is a next best thing */ |
|
37 | 37 | |
38 | - Debug::log("caching media of starred articles for user " . $this->host->get_owner_uid() . "..."); |
|
38 | + Debug::log("caching media of starred articles for user " . $this->host->get_owner_uid() . "..."); |
|
39 | 39 | |
40 | - $sth = $this->pdo->prepare("SELECT content, ttrss_entries.title, |
|
40 | + $sth = $this->pdo->prepare("SELECT content, ttrss_entries.title, |
|
41 | 41 | ttrss_user_entries.owner_uid, link, site_url, ttrss_entries.id, plugin_data |
42 | 42 | FROM ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON |
43 | 43 | (ttrss_user_entries.feed_id = ttrss_feeds.id) |
@@ -48,115 +48,115 @@ discard block |
||
48 | 48 | plugin_data NOT LIKE '%starred_cache_images%' |
49 | 49 | ORDER BY ".sql_random_function()." LIMIT 100"); |
50 | 50 | |
51 | - if ($sth->execute([$this->host->get_owner_uid()])) { |
|
51 | + if ($sth->execute([$this->host->get_owner_uid()])) { |
|
52 | 52 | |
53 | - $usth = $this->pdo->prepare("UPDATE ttrss_entries SET plugin_data = ? WHERE id = ?"); |
|
53 | + $usth = $this->pdo->prepare("UPDATE ttrss_entries SET plugin_data = ? WHERE id = ?"); |
|
54 | 54 | |
55 | - while ($line = $sth->fetch()) { |
|
56 | - Debug::log("processing article " . $line["title"], Debug::$LOG_VERBOSE); |
|
55 | + while ($line = $sth->fetch()) { |
|
56 | + Debug::log("processing article " . $line["title"], Debug::$LOG_VERBOSE); |
|
57 | 57 | |
58 | - if ($line["site_url"]) { |
|
59 | - $success = $this->cache_article_images($line["content"], $line["site_url"], $line["owner_uid"], $line["id"]); |
|
58 | + if ($line["site_url"]) { |
|
59 | + $success = $this->cache_article_images($line["content"], $line["site_url"], $line["owner_uid"], $line["id"]); |
|
60 | 60 | |
61 | - if ($success) { |
|
62 | - $plugin_data = "starred_cache_images,${line['owner_uid']}:" . $line["plugin_data"]; |
|
61 | + if ($success) { |
|
62 | + $plugin_data = "starred_cache_images,${line['owner_uid']}:" . $line["plugin_data"]; |
|
63 | 63 | |
64 | - $usth->execute([$plugin_data, $line['id']]); |
|
65 | - } |
|
66 | - } |
|
67 | - } |
|
68 | - } |
|
64 | + $usth->execute([$plugin_data, $line['id']]); |
|
65 | + } |
|
66 | + } |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /* actual housekeeping */ |
|
70 | + /* actual housekeeping */ |
|
71 | 71 | |
72 | - Debug::log("expiring " . $this->cache->getDir() . "..."); |
|
72 | + Debug::log("expiring " . $this->cache->getDir() . "..."); |
|
73 | 73 | |
74 | - $files = glob($this->cache->getDir() . "/*.{png,mp4,status}", GLOB_BRACE); |
|
74 | + $files = glob($this->cache->getDir() . "/*.{png,mp4,status}", GLOB_BRACE); |
|
75 | 75 | |
76 | - $last_article_id = 0; |
|
77 | - $article_exists = 1; |
|
76 | + $last_article_id = 0; |
|
77 | + $article_exists = 1; |
|
78 | 78 | |
79 | - foreach ($files as $file) { |
|
80 | - list ($article_id, $hash) = explode("-", basename($file)); |
|
79 | + foreach ($files as $file) { |
|
80 | + list ($article_id, $hash) = explode("-", basename($file)); |
|
81 | 81 | |
82 | - if ($article_id != $last_article_id) { |
|
83 | - $last_article_id = $article_id; |
|
82 | + if ($article_id != $last_article_id) { |
|
83 | + $last_article_id = $article_id; |
|
84 | 84 | |
85 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_entries WHERE id = ?"); |
|
86 | - $sth->execute([$article_id]); |
|
85 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_entries WHERE id = ?"); |
|
86 | + $sth->execute([$article_id]); |
|
87 | 87 | |
88 | - $article_exists = $sth->fetch(); |
|
89 | - } |
|
88 | + $article_exists = $sth->fetch(); |
|
89 | + } |
|
90 | 90 | |
91 | - if (!$article_exists) { |
|
92 | - unlink($file); |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
91 | + if (!$article_exists) { |
|
92 | + unlink($file); |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - public function hook_enclosure_entry($enc, $article_id) { |
|
98 | - $local_filename = $article_id . "-" . sha1($enc["content_url"]); |
|
97 | + public function hook_enclosure_entry($enc, $article_id) { |
|
98 | + $local_filename = $article_id . "-" . sha1($enc["content_url"]); |
|
99 | 99 | |
100 | - if ($this->cache->exists($local_filename)) { |
|
101 | - $enc["content_url"] = $this->cache->getUrl($local_filename); |
|
102 | - } |
|
100 | + if ($this->cache->exists($local_filename)) { |
|
101 | + $enc["content_url"] = $this->cache->getUrl($local_filename); |
|
102 | + } |
|
103 | 103 | |
104 | - return $enc; |
|
105 | - } |
|
104 | + return $enc; |
|
105 | + } |
|
106 | 106 | |
107 | - public function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id) { |
|
108 | - $xpath = new DOMXpath($doc); |
|
107 | + public function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id) { |
|
108 | + $xpath = new DOMXpath($doc); |
|
109 | 109 | |
110 | - if ($article_id) { |
|
111 | - $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
|
110 | + if ($article_id) { |
|
111 | + $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
|
112 | 112 | |
113 | - foreach ($entries as $entry) { |
|
114 | - if ($entry->hasAttribute('src')) { |
|
115 | - $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
113 | + foreach ($entries as $entry) { |
|
114 | + if ($entry->hasAttribute('src')) { |
|
115 | + $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
116 | 116 | |
117 | - $local_filename = $article_id . "-" . sha1($src); |
|
117 | + $local_filename = $article_id . "-" . sha1($src); |
|
118 | 118 | |
119 | - if ($this->cache->exists($local_filename)) { |
|
120 | - $entry->setAttribute("src", $this->cache->getUrl($local_filename)); |
|
121 | - $entry->removeAttribute("srcset"); |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
119 | + if ($this->cache->exists($local_filename)) { |
|
120 | + $entry->setAttribute("src", $this->cache->getUrl($local_filename)); |
|
121 | + $entry->removeAttribute("srcset"); |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | 126 | |
127 | - return $doc; |
|
128 | - } |
|
127 | + return $doc; |
|
128 | + } |
|
129 | 129 | |
130 | - private function cache_url($article_id, $url) { |
|
131 | - $local_filename = $article_id . "-" . sha1($url); |
|
130 | + private function cache_url($article_id, $url) { |
|
131 | + $local_filename = $article_id . "-" . sha1($url); |
|
132 | 132 | |
133 | - if (!$this->cache->exists($local_filename)) { |
|
134 | - Debug::log("cache_images: downloading: $url to $local_filename", Debug::$LOG_VERBOSE); |
|
133 | + if (!$this->cache->exists($local_filename)) { |
|
134 | + Debug::log("cache_images: downloading: $url to $local_filename", Debug::$LOG_VERBOSE); |
|
135 | 135 | |
136 | - $data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); |
|
136 | + $data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); |
|
137 | 137 | |
138 | - if ($data) |
|
139 | - return $this->cache->put($local_filename, $data);; |
|
138 | + if ($data) |
|
139 | + return $this->cache->put($local_filename, $data);; |
|
140 | 140 | |
141 | - } else { |
|
142 | - //Debug::log("cache_images: local file exists for $url", Debug::$LOG_VERBOSE); |
|
141 | + } else { |
|
142 | + //Debug::log("cache_images: local file exists for $url", Debug::$LOG_VERBOSE); |
|
143 | 143 | |
144 | - return true; |
|
145 | - } |
|
144 | + return true; |
|
145 | + } |
|
146 | 146 | |
147 | - return false; |
|
148 | - } |
|
147 | + return false; |
|
148 | + } |
|
149 | 149 | |
150 | - private function cache_article_images($content, $site_url, $owner_uid, $article_id) { |
|
151 | - $status_filename = $article_id . "-" . sha1($site_url) . ".status"; |
|
150 | + private function cache_article_images($content, $site_url, $owner_uid, $article_id) { |
|
151 | + $status_filename = $article_id . "-" . sha1($site_url) . ".status"; |
|
152 | 152 | |
153 | - /* housekeeping might run as a separate user, in this case status/media might not be writable */ |
|
154 | - if (!$this->cache->isWritable($status_filename)) { |
|
155 | - Debug::log("status not writable: $status_filename", Debug::$LOG_VERBOSE); |
|
156 | - return false; |
|
157 | - } |
|
153 | + /* housekeeping might run as a separate user, in this case status/media might not be writable */ |
|
154 | + if (!$this->cache->isWritable($status_filename)) { |
|
155 | + Debug::log("status not writable: $status_filename", Debug::$LOG_VERBOSE); |
|
156 | + return false; |
|
157 | + } |
|
158 | 158 | |
159 | - Debug::log("status: $status_filename", Debug::$LOG_VERBOSE); |
|
159 | + Debug::log("status: $status_filename", Debug::$LOG_VERBOSE); |
|
160 | 160 | |
161 | 161 | if ($this->cache->exists($status_filename)) |
162 | 162 | $status = json_decode($this->cache->get($status_filename), true); |
@@ -176,49 +176,49 @@ discard block |
||
176 | 176 | return false; |
177 | 177 | } |
178 | 178 | |
179 | - $doc = new DOMDocument(); |
|
179 | + $doc = new DOMDocument(); |
|
180 | 180 | |
181 | - $has_images = false; |
|
182 | - $success = false; |
|
181 | + $has_images = false; |
|
182 | + $success = false; |
|
183 | 183 | |
184 | 184 | if ($doc->loadHTML('<?xml encoding="UTF-8">' . $content)) { |
185 | - $xpath = new DOMXPath($doc); |
|
186 | - $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
|
185 | + $xpath = new DOMXPath($doc); |
|
186 | + $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
|
187 | 187 | |
188 | - foreach ($entries as $entry) { |
|
188 | + foreach ($entries as $entry) { |
|
189 | 189 | |
190 | - if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) { |
|
190 | + if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) { |
|
191 | 191 | |
192 | - $has_images = true; |
|
192 | + $has_images = true; |
|
193 | 193 | |
194 | - $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
194 | + $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
195 | 195 | |
196 | - if ($this->cache_url($article_id, $src)) { |
|
197 | - $success = true; |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
196 | + if ($this->cache_url($article_id, $src)) { |
|
197 | + $success = true; |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | 202 | |
203 | - $esth = $this->pdo->prepare("SELECT content_url FROM ttrss_enclosures WHERE post_id = ? AND |
|
203 | + $esth = $this->pdo->prepare("SELECT content_url FROM ttrss_enclosures WHERE post_id = ? AND |
|
204 | 204 | (content_type LIKE '%image%' OR content_type LIKE '%video%')"); |
205 | 205 | |
206 | 206 | if ($esth->execute([$article_id])) { |
207 | - while ($enc = $esth->fetch()) { |
|
207 | + while ($enc = $esth->fetch()) { |
|
208 | 208 | |
209 | - $has_images = true; |
|
210 | - $url = rewrite_relative_url($site_url, $enc["content_url"]); |
|
209 | + $has_images = true; |
|
210 | + $url = rewrite_relative_url($site_url, $enc["content_url"]); |
|
211 | 211 | |
212 | - if ($this->cache_url($article_id, $url)) { |
|
213 | - $success = true; |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
212 | + if ($this->cache_url($article_id, $url)) { |
|
213 | + $success = true; |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | 217 | |
218 | - return $success || !$has_images; |
|
219 | - } |
|
218 | + return $success || !$has_images; |
|
219 | + } |
|
220 | 220 | |
221 | - public function api_version() { |
|
222 | - return 2; |
|
223 | - } |
|
221 | + public function api_version() { |
|
222 | + return 2; |
|
223 | + } |
|
224 | 224 | } |
@@ -53,8 +53,9 @@ |
||
53 | 53 | |
54 | 54 | while ($line = $sth->fetch()) { |
55 | 55 | |
56 | - if (!$subject) |
|
57 | - $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]); |
|
56 | + if (!$subject) { |
|
57 | + $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]); |
|
58 | + } |
|
58 | 59 | |
59 | 60 | $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"])); |
60 | 61 | $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"])); |
@@ -1,95 +1,95 @@ |
||
1 | 1 | <?php |
2 | 2 | class MailTo extends Plugin { |
3 | - private $host; |
|
3 | + private $host; |
|
4 | 4 | |
5 | - public function about() { |
|
6 | - return array(1.0, |
|
7 | - "Share article via email (using mailto: links, invoking your mail client)", |
|
8 | - "fox"); |
|
9 | - } |
|
5 | + public function about() { |
|
6 | + return array(1.0, |
|
7 | + "Share article via email (using mailto: links, invoking your mail client)", |
|
8 | + "fox"); |
|
9 | + } |
|
10 | 10 | |
11 | - public function init($host) { |
|
12 | - $this->host = $host; |
|
11 | + public function init($host) { |
|
12 | + $this->host = $host; |
|
13 | 13 | |
14 | - $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); |
|
15 | - } |
|
14 | + $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); |
|
15 | + } |
|
16 | 16 | |
17 | - public function get_js() { |
|
18 | - return file_get_contents(dirname(__FILE__) . "/init.js"); |
|
19 | - } |
|
17 | + public function get_js() { |
|
18 | + return file_get_contents(dirname(__FILE__) . "/init.js"); |
|
19 | + } |
|
20 | 20 | |
21 | - public function hook_article_button($line) { |
|
22 | - return "<i class='material-icons' style=\"cursor : pointer\" |
|
21 | + public function hook_article_button($line) { |
|
22 | + return "<i class='material-icons' style=\"cursor : pointer\" |
|
23 | 23 | onclick=\"Plugins.Mailto.send(".$line["id"].")\" |
24 | 24 | title='".__('Forward by email')."'>mail_outline</i>"; |
25 | - } |
|
25 | + } |
|
26 | 26 | |
27 | - public function emailArticle() { |
|
27 | + public function emailArticle() { |
|
28 | 28 | |
29 | - $ids = explode(",", $_REQUEST['param']); |
|
30 | - $ids_qmarks = arr_qmarks($ids); |
|
29 | + $ids = explode(",", $_REQUEST['param']); |
|
30 | + $ids_qmarks = arr_qmarks($ids); |
|
31 | 31 | |
32 | - require_once "lib/MiniTemplator.class.php"; |
|
32 | + require_once "lib/MiniTemplator.class.php"; |
|
33 | 33 | |
34 | - $tpl = new MiniTemplator; |
|
34 | + $tpl = new MiniTemplator; |
|
35 | 35 | |
36 | - $tpl->readTemplateFromFile("templates/email_article_template.txt"); |
|
36 | + $tpl->readTemplateFromFile("templates/email_article_template.txt"); |
|
37 | 37 | |
38 | - $tpl->setVariable('USER_NAME', $_SESSION["name"], true); |
|
39 | - //$tpl->setVariable('USER_EMAIL', $user_email, true); |
|
40 | - $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"], true); |
|
38 | + $tpl->setVariable('USER_NAME', $_SESSION["name"], true); |
|
39 | + //$tpl->setVariable('USER_EMAIL', $user_email, true); |
|
40 | + $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"], true); |
|
41 | 41 | |
42 | 42 | |
43 | - $sth = $this->pdo->prepare("SELECT DISTINCT link, content, title |
|
43 | + $sth = $this->pdo->prepare("SELECT DISTINCT link, content, title |
|
44 | 44 | FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND |
45 | 45 | id IN ($ids_qmarks) AND owner_uid = ?"); |
46 | - $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
46 | + $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
47 | 47 | |
48 | - if (count($ids) > 1) { |
|
49 | - $subject = __("[Forwarded]") . " " . __("Multiple articles"); |
|
50 | - } else { |
|
51 | - $subject = ""; |
|
52 | - } |
|
48 | + if (count($ids) > 1) { |
|
49 | + $subject = __("[Forwarded]") . " " . __("Multiple articles"); |
|
50 | + } else { |
|
51 | + $subject = ""; |
|
52 | + } |
|
53 | 53 | |
54 | - while ($line = $sth->fetch()) { |
|
54 | + while ($line = $sth->fetch()) { |
|
55 | 55 | |
56 | - if (!$subject) |
|
57 | - $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]); |
|
56 | + if (!$subject) |
|
57 | + $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]); |
|
58 | 58 | |
59 | - $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"])); |
|
60 | - $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"])); |
|
59 | + $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"])); |
|
60 | + $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"])); |
|
61 | 61 | |
62 | - $tpl->addBlock('article'); |
|
63 | - } |
|
62 | + $tpl->addBlock('article'); |
|
63 | + } |
|
64 | 64 | |
65 | - $tpl->addBlock('email'); |
|
65 | + $tpl->addBlock('email'); |
|
66 | 66 | |
67 | - $content = ""; |
|
68 | - $tpl->generateOutputToString($content); |
|
67 | + $content = ""; |
|
68 | + $tpl->generateOutputToString($content); |
|
69 | 69 | |
70 | - $mailto_link = htmlspecialchars("mailto:?subject=".rawurlencode($subject). |
|
71 | - "&body=".rawurlencode($content)); |
|
70 | + $mailto_link = htmlspecialchars("mailto:?subject=".rawurlencode($subject). |
|
71 | + "&body=".rawurlencode($content)); |
|
72 | 72 | |
73 | - print __("Clicking the following link to invoke your mail client:"); |
|
73 | + print __("Clicking the following link to invoke your mail client:"); |
|
74 | 74 | |
75 | - print "<div class='panel text-center'>"; |
|
76 | - print "<a target=\"_blank\" href=\"$mailto_link\">". |
|
77 | - __("Forward selected article(s) by email.")."</a>"; |
|
78 | - print "</div>"; |
|
75 | + print "<div class='panel text-center'>"; |
|
76 | + print "<a target=\"_blank\" href=\"$mailto_link\">". |
|
77 | + __("Forward selected article(s) by email.")."</a>"; |
|
78 | + print "</div>"; |
|
79 | 79 | |
80 | - print __("You should be able to edit the message before sending in your mail client."); |
|
80 | + print __("You should be able to edit the message before sending in your mail client."); |
|
81 | 81 | |
82 | - print "<p>"; |
|
82 | + print "<p>"; |
|
83 | 83 | |
84 | - print "<footer class='text-center'>"; |
|
85 | - print "<button dojoType='dijit.form.Button' onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Close this dialog')."</button>"; |
|
86 | - print "</footer>"; |
|
84 | + print "<footer class='text-center'>"; |
|
85 | + print "<button dojoType='dijit.form.Button' onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Close this dialog')."</button>"; |
|
86 | + print "</footer>"; |
|
87 | 87 | |
88 | - //return; |
|
89 | - } |
|
88 | + //return; |
|
89 | + } |
|
90 | 90 | |
91 | - public function api_version() { |
|
92 | - return 2; |
|
93 | - } |
|
91 | + public function api_version() { |
|
92 | + return 2; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | } |
@@ -86,15 +86,17 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | public static function instance() { |
89 | - if (self::$instance == null) |
|
90 | - self::$instance = new self(); |
|
89 | + if (self::$instance == null) { |
|
90 | + self::$instance = new self(); |
|
91 | + } |
|
91 | 92 | |
92 | 93 | return self::$instance; |
93 | 94 | } |
94 | 95 | |
95 | 96 | public static function get() { |
96 | - if (self::$instance == null) |
|
97 | - self::$instance = new self(); |
|
97 | + if (self::$instance == null) { |
|
98 | + self::$instance = new self(); |
|
99 | + } |
|
98 | 100 | |
99 | 101 | if (!self::$instance->adapter) { |
100 | 102 | self::$instance->legacy_connect(); |
@@ -104,8 +106,9 @@ discard block |
||
104 | 106 | } |
105 | 107 | |
106 | 108 | public static function pdo() { |
107 | - if (self::$instance == null) |
|
108 | - self::$instance = new self(); |
|
109 | + if (self::$instance == null) { |
|
110 | + self::$instance = new self(); |
|
111 | + } |
|
109 | 112 | |
110 | 113 | if (!self::$instance->pdo) { |
111 | 114 | self::$instance->pdo = self::$instance->pdo_connect(); |
@@ -2,115 +2,115 @@ |
||
2 | 2 | class Db |
3 | 3 | { |
4 | 4 | |
5 | - /* @var Db $instance */ |
|
6 | - private static $instance; |
|
5 | + /* @var Db $instance */ |
|
6 | + private static $instance; |
|
7 | 7 | |
8 | - /* @var IDb $adapter */ |
|
9 | - private $adapter; |
|
8 | + /* @var IDb $adapter */ |
|
9 | + private $adapter; |
|
10 | 10 | |
11 | - private $link; |
|
11 | + private $link; |
|
12 | 12 | |
13 | - /* @var PDO $pdo */ |
|
14 | - private $pdo; |
|
13 | + /* @var PDO $pdo */ |
|
14 | + private $pdo; |
|
15 | 15 | |
16 | - private function __clone() { |
|
17 | - // |
|
18 | - } |
|
16 | + private function __clone() { |
|
17 | + // |
|
18 | + } |
|
19 | 19 | |
20 | - private function legacy_connect() { |
|
20 | + private function legacy_connect() { |
|
21 | 21 | |
22 | - user_error("Legacy connect requested to " . DB_TYPE, E_USER_NOTICE); |
|
22 | + user_error("Legacy connect requested to " . DB_TYPE, E_USER_NOTICE); |
|
23 | 23 | |
24 | - $er = error_reporting(E_ALL); |
|
24 | + $er = error_reporting(E_ALL); |
|
25 | 25 | |
26 | - switch (DB_TYPE) { |
|
27 | - case "mysql": |
|
28 | - $this->adapter = new Db_Mysqli(); |
|
29 | - break; |
|
30 | - case "pgsql": |
|
31 | - $this->adapter = new Db_Pgsql(); |
|
32 | - break; |
|
33 | - default: |
|
34 | - die("Unknown DB_TYPE: " . DB_TYPE); |
|
35 | - } |
|
26 | + switch (DB_TYPE) { |
|
27 | + case "mysql": |
|
28 | + $this->adapter = new Db_Mysqli(); |
|
29 | + break; |
|
30 | + case "pgsql": |
|
31 | + $this->adapter = new Db_Pgsql(); |
|
32 | + break; |
|
33 | + default: |
|
34 | + die("Unknown DB_TYPE: " . DB_TYPE); |
|
35 | + } |
|
36 | 36 | |
37 | - if (!$this->adapter) { |
|
38 | - print("Error initializing database adapter for " . DB_TYPE); |
|
39 | - exit(100); |
|
40 | - } |
|
37 | + if (!$this->adapter) { |
|
38 | + print("Error initializing database adapter for " . DB_TYPE); |
|
39 | + exit(100); |
|
40 | + } |
|
41 | 41 | |
42 | - $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : ""); |
|
42 | + $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : ""); |
|
43 | 43 | |
44 | - if (!$this->link) { |
|
45 | - print("Error connecting through adapter: " . $this->adapter->last_error()); |
|
46 | - exit(101); |
|
47 | - } |
|
44 | + if (!$this->link) { |
|
45 | + print("Error connecting through adapter: " . $this->adapter->last_error()); |
|
46 | + exit(101); |
|
47 | + } |
|
48 | 48 | |
49 | - error_reporting($er); |
|
50 | - } |
|
49 | + error_reporting($er); |
|
50 | + } |
|
51 | 51 | |
52 | - // this really shouldn't be used unless a separate PDO connection is needed |
|
53 | - // normal usage is Db::pdo()->prepare(...) etc |
|
54 | - public function pdo_connect() { |
|
52 | + // this really shouldn't be used unless a separate PDO connection is needed |
|
53 | + // normal usage is Db::pdo()->prepare(...) etc |
|
54 | + public function pdo_connect() { |
|
55 | 55 | |
56 | - $db_port = defined('DB_PORT') && DB_PORT ? ';port=' . DB_PORT : ''; |
|
57 | - $db_host = defined('DB_HOST') && DB_HOST ? ';host=' . DB_HOST : ''; |
|
56 | + $db_port = defined('DB_PORT') && DB_PORT ? ';port=' . DB_PORT : ''; |
|
57 | + $db_host = defined('DB_HOST') && DB_HOST ? ';host=' . DB_HOST : ''; |
|
58 | 58 | |
59 | - try { |
|
60 | - $pdo = new PDO(DB_TYPE . ':dbname=' . DB_NAME . $db_host . $db_port, |
|
61 | - DB_USER, |
|
62 | - DB_PASS); |
|
63 | - } catch (Exception $e) { |
|
64 | - print "<pre>Exception while creating PDO object:" . $e->getMessage() . "</pre>"; |
|
65 | - exit(101); |
|
66 | - } |
|
59 | + try { |
|
60 | + $pdo = new PDO(DB_TYPE . ':dbname=' . DB_NAME . $db_host . $db_port, |
|
61 | + DB_USER, |
|
62 | + DB_PASS); |
|
63 | + } catch (Exception $e) { |
|
64 | + print "<pre>Exception while creating PDO object:" . $e->getMessage() . "</pre>"; |
|
65 | + exit(101); |
|
66 | + } |
|
67 | 67 | |
68 | - $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
68 | + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
69 | 69 | |
70 | - if (DB_TYPE == "pgsql") { |
|
70 | + if (DB_TYPE == "pgsql") { |
|
71 | 71 | |
72 | - $pdo->query("set client_encoding = 'UTF-8'"); |
|
73 | - $pdo->query("set datestyle = 'ISO, european'"); |
|
74 | - $pdo->query("set TIME ZONE 0"); |
|
75 | - $pdo->query("set cpu_tuple_cost = 0.5"); |
|
72 | + $pdo->query("set client_encoding = 'UTF-8'"); |
|
73 | + $pdo->query("set datestyle = 'ISO, european'"); |
|
74 | + $pdo->query("set TIME ZONE 0"); |
|
75 | + $pdo->query("set cpu_tuple_cost = 0.5"); |
|
76 | 76 | |
77 | - } else if (DB_TYPE == "mysql") { |
|
78 | - $pdo->query("SET time_zone = '+0:0'"); |
|
77 | + } else if (DB_TYPE == "mysql") { |
|
78 | + $pdo->query("SET time_zone = '+0:0'"); |
|
79 | 79 | |
80 | - if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { |
|
81 | - $pdo->query("SET NAMES " . MYSQL_CHARSET); |
|
82 | - } |
|
83 | - } |
|
80 | + if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { |
|
81 | + $pdo->query("SET NAMES " . MYSQL_CHARSET); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - return $pdo; |
|
86 | - } |
|
85 | + return $pdo; |
|
86 | + } |
|
87 | 87 | |
88 | - public static function instance() { |
|
89 | - if (self::$instance == null) |
|
90 | - self::$instance = new self(); |
|
88 | + public static function instance() { |
|
89 | + if (self::$instance == null) |
|
90 | + self::$instance = new self(); |
|
91 | 91 | |
92 | - return self::$instance; |
|
93 | - } |
|
92 | + return self::$instance; |
|
93 | + } |
|
94 | 94 | |
95 | - public static function get() { |
|
96 | - if (self::$instance == null) |
|
97 | - self::$instance = new self(); |
|
95 | + public static function get() { |
|
96 | + if (self::$instance == null) |
|
97 | + self::$instance = new self(); |
|
98 | 98 | |
99 | - if (!self::$instance->adapter) { |
|
100 | - self::$instance->legacy_connect(); |
|
101 | - } |
|
99 | + if (!self::$instance->adapter) { |
|
100 | + self::$instance->legacy_connect(); |
|
101 | + } |
|
102 | 102 | |
103 | - return self::$instance->adapter; |
|
104 | - } |
|
103 | + return self::$instance->adapter; |
|
104 | + } |
|
105 | 105 | |
106 | - public static function pdo() { |
|
107 | - if (self::$instance == null) |
|
108 | - self::$instance = new self(); |
|
106 | + public static function pdo() { |
|
107 | + if (self::$instance == null) |
|
108 | + self::$instance = new self(); |
|
109 | 109 | |
110 | - if (!self::$instance->pdo) { |
|
111 | - self::$instance->pdo = self::$instance->pdo_connect(); |
|
112 | - } |
|
110 | + if (!self::$instance->pdo) { |
|
111 | + self::$instance->pdo = self::$instance->pdo_connect(); |
|
112 | + } |
|
113 | 113 | |
114 | - return self::$instance->pdo; |
|
115 | - } |
|
114 | + return self::$instance->pdo; |
|
115 | + } |
|
116 | 116 | } |