Passed
Push — master ( 5a5c41...fade3b )
by Cody
04:50 queued 10s
created
include/functions.php 1 patch
Indentation   +1180 added lines, -1180 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
 
23 23
 date_default_timezone_set('UTC');
24 24
 if (defined('E_DEPRECATED')) {
25
-    error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
25
+	error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
26 26
 } else {
27
-    error_reporting(E_ALL & ~E_NOTICE);
27
+	error_reporting(E_ALL & ~E_NOTICE);
28 28
 }
29 29
 
30 30
 ini_set('display_errors', 0);
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
  * Define a constant if not already defined
37 37
  */
38 38
 function define_default($name, $value) {
39
-    defined($name) or define($name, $value);
39
+	defined($name) or define($name, $value);
40 40
 }
41 41
 
42 42
 /* Some tunables you can override in config.php using define():	*/
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
 /* tunables end here */
76 76
 
77 77
 if (DB_TYPE == "pgsql") {
78
-    define('SUBSTRING_FOR_DATE', 'SUBSTRING_FOR_DATE');
78
+	define('SUBSTRING_FOR_DATE', 'SUBSTRING_FOR_DATE');
79 79
 } else {
80
-    define('SUBSTRING_FOR_DATE', 'SUBSTRING');
80
+	define('SUBSTRING_FOR_DATE', 'SUBSTRING');
81 81
 }
82 82
 
83 83
 /**
@@ -87,38 +87,38 @@  discard block
 block discarded – undo
87 87
  * @return array A array of available translations.
88 88
  */
89 89
 function get_translations() {
90
-    $tr = array(
91
-        "auto"  => __("Detect automatically"),
92
-        "ar_SA" => "العربيّة (Arabic)",
93
-        "bg_BG" => "Bulgarian",
94
-        "da_DA" => "Dansk",
95
-        "ca_CA" => "Català",
96
-        "cs_CZ" => "Česky",
97
-        "en_US" => "English",
98
-        "el_GR" => "Ελληνικά",
99
-        "es_ES" => "Español (España)",
100
-        "es_LA" => "Español",
101
-        "de_DE" => "Deutsch",
102
-        "fr_FR" => "Français",
103
-        "hu_HU" => "Magyar (Hungarian)",
104
-        "it_IT" => "Italiano",
105
-        "ja_JP" => "日本語 (Japanese)",
106
-        "lv_LV" => "Latviešu",
107
-        "nb_NO" => "Norwegian bokmål",
108
-        "nl_NL" => "Dutch",
109
-        "pl_PL" => "Polski",
110
-        "ru_RU" => "Русский",
111
-        "pt_BR" => "Portuguese/Brazil",
112
-        "pt_PT" => "Portuguese/Portugal",
113
-        "zh_CN" => "Simplified Chinese",
114
-        "zh_TW" => "Traditional Chinese",
115
-        "uk_UA" => "Українська",
116
-        "sv_SE" => "Svenska",
117
-        "fi_FI" => "Suomi",
118
-        "tr_TR" => "Türkçe"
119
-    );
120
-
121
-    return $tr;
90
+	$tr = array(
91
+		"auto"  => __("Detect automatically"),
92
+		"ar_SA" => "العربيّة (Arabic)",
93
+		"bg_BG" => "Bulgarian",
94
+		"da_DA" => "Dansk",
95
+		"ca_CA" => "Català",
96
+		"cs_CZ" => "Česky",
97
+		"en_US" => "English",
98
+		"el_GR" => "Ελληνικά",
99
+		"es_ES" => "Español (España)",
100
+		"es_LA" => "Español",
101
+		"de_DE" => "Deutsch",
102
+		"fr_FR" => "Français",
103
+		"hu_HU" => "Magyar (Hungarian)",
104
+		"it_IT" => "Italiano",
105
+		"ja_JP" => "日本語 (Japanese)",
106
+		"lv_LV" => "Latviešu",
107
+		"nb_NO" => "Norwegian bokmål",
108
+		"nl_NL" => "Dutch",
109
+		"pl_PL" => "Polski",
110
+		"ru_RU" => "Русский",
111
+		"pt_BR" => "Portuguese/Brazil",
112
+		"pt_PT" => "Portuguese/Portugal",
113
+		"zh_CN" => "Simplified Chinese",
114
+		"zh_TW" => "Traditional Chinese",
115
+		"uk_UA" => "Українська",
116
+		"sv_SE" => "Svenska",
117
+		"fi_FI" => "Suomi",
118
+		"tr_TR" => "Türkçe"
119
+	);
120
+
121
+	return $tr;
122 122
 }
123 123
 
124 124
 require_once "lib/accept-to-gettext.php";
@@ -126,32 +126,32 @@  discard block
 block discarded – undo
126 126
 
127 127
 function startup_gettext() {
128 128
 
129
-    # Get locale from Accept-Language header
130
-    $lang = al2gt(array_keys(get_translations()), "text/html");
129
+	# Get locale from Accept-Language header
130
+	$lang = al2gt(array_keys(get_translations()), "text/html");
131 131
 
132
-    if (defined('_TRANSLATION_OVERRIDE_DEFAULT')) {
133
-        $lang = _TRANSLATION_OVERRIDE_DEFAULT;
134
-    }
132
+	if (defined('_TRANSLATION_OVERRIDE_DEFAULT')) {
133
+		$lang = _TRANSLATION_OVERRIDE_DEFAULT;
134
+	}
135 135
 
136
-    if ($_SESSION["uid"] && get_schema_version() >= 120) {
137
-        $pref_lang = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
136
+	if ($_SESSION["uid"] && get_schema_version() >= 120) {
137
+		$pref_lang = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
138 138
 
139
-        if ($pref_lang && $pref_lang != 'auto') {
140
-            $lang = $pref_lang;
141
-        }
142
-    }
139
+		if ($pref_lang && $pref_lang != 'auto') {
140
+			$lang = $pref_lang;
141
+		}
142
+	}
143 143
 
144
-    if ($lang) {
145
-        if (defined('LC_MESSAGES')) {
146
-            _setlocale(LC_MESSAGES, $lang);
147
-        } else if (defined('LC_ALL')) {
148
-            _setlocale(LC_ALL, $lang);
149
-        }
144
+	if ($lang) {
145
+		if (defined('LC_MESSAGES')) {
146
+			_setlocale(LC_MESSAGES, $lang);
147
+		} else if (defined('LC_ALL')) {
148
+			_setlocale(LC_ALL, $lang);
149
+		}
150 150
 
151
-        _bindtextdomain("messages", "locale");
152
-        _textdomain("messages");
153
-        _bind_textdomain_codeset("messages", "UTF-8");
154
-    }
151
+		_bindtextdomain("messages", "locale");
152
+		_textdomain("messages");
153
+		_bind_textdomain_codeset("messages", "UTF-8");
154
+	}
155 155
 }
156 156
 
157 157
 require_once 'db-prefs.php';
@@ -164,13 +164,13 @@  discard block
 block discarded – undo
164 164
 
165 165
 // TODO: compat wrapper, remove at some point
166 166
 function _debug($msg) {
167
-    Debug::log($msg);
167
+	Debug::log($msg);
168 168
 }
169 169
 
170 170
 function reset_fetch_domain_quota() {
171
-    global $fetch_domain_hits;
171
+	global $fetch_domain_hits;
172 172
 
173
-    $fetch_domain_hits = [];
173
+	$fetch_domain_hits = [];
174 174
 }
175 175
 
176 176
 // TODO: max_size currently only works for CURL transfers
@@ -178,467 +178,467 @@  discard block
 block discarded – undo
178 178
 function fetch_file_contents($options /* previously: 0: $url , 1: $type = false, 2: $login = false, 3: $pass = false,
179 179
             4: $post_query = false, 5: $timeout = false, 6: $timestamp = 0, 7: $useragent = false*/) {
180 180
 
181
-    global $fetch_last_error;
182
-    global $fetch_last_error_code;
183
-    global $fetch_last_error_content;
184
-    global $fetch_last_content_type;
185
-    global $fetch_last_modified;
186
-    global $fetch_effective_url;
187
-    global $fetch_curl_used;
188
-    global $fetch_domain_hits;
189
-
190
-    $fetch_last_error = false;
191
-    $fetch_last_error_code = -1;
192
-    $fetch_last_error_content = "";
193
-    $fetch_last_content_type = "";
194
-    $fetch_curl_used = false;
195
-    $fetch_last_modified = "";
196
-    $fetch_effective_url = "";
197
-
198
-    if (!is_array($fetch_domain_hits))
199
-        $fetch_domain_hits = [];
200
-
201
-    if (!is_array($options)) {
202
-
203
-        // falling back on compatibility shim
204
-        $option_names = [ "url", "type", "login", "pass", "post_query", "timeout", "last_modified", "useragent" ];
205
-        $tmp = [];
206
-
207
-        for ($i = 0; $i < func_num_args(); $i++) {
208
-            $tmp[$option_names[$i]] = func_get_arg($i);
209
-        }
181
+	global $fetch_last_error;
182
+	global $fetch_last_error_code;
183
+	global $fetch_last_error_content;
184
+	global $fetch_last_content_type;
185
+	global $fetch_last_modified;
186
+	global $fetch_effective_url;
187
+	global $fetch_curl_used;
188
+	global $fetch_domain_hits;
189
+
190
+	$fetch_last_error = false;
191
+	$fetch_last_error_code = -1;
192
+	$fetch_last_error_content = "";
193
+	$fetch_last_content_type = "";
194
+	$fetch_curl_used = false;
195
+	$fetch_last_modified = "";
196
+	$fetch_effective_url = "";
197
+
198
+	if (!is_array($fetch_domain_hits))
199
+		$fetch_domain_hits = [];
200
+
201
+	if (!is_array($options)) {
210 202
 
211
-        $options = $tmp;
212
-    }
203
+		// falling back on compatibility shim
204
+		$option_names = [ "url", "type", "login", "pass", "post_query", "timeout", "last_modified", "useragent" ];
205
+		$tmp = [];
213 206
 
214
-    $url = $options["url"];
215
-    $type = isset($options["type"]) ? $options["type"] : false;
216
-    $login = isset($options["login"]) ? $options["login"] : false;
217
-    $pass = isset($options["pass"]) ? $options["pass"] : false;
218
-    $post_query = isset($options["post_query"]) ? $options["post_query"] : false;
219
-    $timeout = isset($options["timeout"]) ? $options["timeout"] : false;
220
-    $last_modified = isset($options["last_modified"]) ? $options["last_modified"] : "";
221
-    $useragent = isset($options["useragent"]) ? $options["useragent"] : false;
222
-    $followlocation = isset($options["followlocation"]) ? $options["followlocation"] : true;
223
-    $max_size = isset($options["max_size"]) ? $options["max_size"] : MAX_DOWNLOAD_FILE_SIZE; // in bytes
224
-    $http_accept = isset($options["http_accept"]) ? $options["http_accept"] : false;
225
-    $http_referrer = isset($options["http_referrer"]) ? $options["http_referrer"] : false;
207
+		for ($i = 0; $i < func_num_args(); $i++) {
208
+			$tmp[$option_names[$i]] = func_get_arg($i);
209
+		}
226 210
 
227
-    $url = ltrim($url, ' ');
228
-    $url = str_replace(' ', '%20', $url);
211
+		$options = $tmp;
212
+	}
229 213
 
230
-    if (strpos($url, "//") === 0)
231
-        $url = 'http:' . $url;
214
+	$url = $options["url"];
215
+	$type = isset($options["type"]) ? $options["type"] : false;
216
+	$login = isset($options["login"]) ? $options["login"] : false;
217
+	$pass = isset($options["pass"]) ? $options["pass"] : false;
218
+	$post_query = isset($options["post_query"]) ? $options["post_query"] : false;
219
+	$timeout = isset($options["timeout"]) ? $options["timeout"] : false;
220
+	$last_modified = isset($options["last_modified"]) ? $options["last_modified"] : "";
221
+	$useragent = isset($options["useragent"]) ? $options["useragent"] : false;
222
+	$followlocation = isset($options["followlocation"]) ? $options["followlocation"] : true;
223
+	$max_size = isset($options["max_size"]) ? $options["max_size"] : MAX_DOWNLOAD_FILE_SIZE; // in bytes
224
+	$http_accept = isset($options["http_accept"]) ? $options["http_accept"] : false;
225
+	$http_referrer = isset($options["http_referrer"]) ? $options["http_referrer"] : false;
226
+
227
+	$url = ltrim($url, ' ');
228
+	$url = str_replace(' ', '%20', $url);
229
+
230
+	if (strpos($url, "//") === 0)
231
+		$url = 'http:' . $url;
232
+
233
+	$url_host = parse_url($url, PHP_URL_HOST);
234
+	$fetch_domain_hits[$url_host] += 1;
232 235
 
233
-    $url_host = parse_url($url, PHP_URL_HOST);
234
-    $fetch_domain_hits[$url_host] += 1;
236
+	if ($fetch_domain_hits[$url_host] > MAX_FETCH_REQUESTS_PER_HOST) {
237
+		user_error("Exceeded fetch request quota for $url_host: " . $fetch_domain_hits[$url_host], E_USER_WARNING);
238
+		#return false;
239
+	}
235 240
 
236
-    if ($fetch_domain_hits[$url_host] > MAX_FETCH_REQUESTS_PER_HOST) {
237
-        user_error("Exceeded fetch request quota for $url_host: " . $fetch_domain_hits[$url_host], E_USER_WARNING);
238
-        #return false;
239
-    }
241
+	if (!defined('NO_CURL') && function_exists('curl_init') && !ini_get("open_basedir")) {
240 242
 
241
-    if (!defined('NO_CURL') && function_exists('curl_init') && !ini_get("open_basedir")) {
243
+		$fetch_curl_used = true;
242 244
 
243
-        $fetch_curl_used = true;
245
+		$ch = curl_init($url);
244 246
 
245
-        $ch = curl_init($url);
247
+		$curl_http_headers = [];
246 248
 
247
-        $curl_http_headers = [];
249
+		if ($last_modified && !$post_query)
250
+			array_push($curl_http_headers, "If-Modified-Since: $last_modified");
251
+
252
+		if ($http_accept)
253
+			array_push($curl_http_headers, "Accept: " . $http_accept);
248 254
 
249
-        if ($last_modified && !$post_query)
250
-            array_push($curl_http_headers, "If-Modified-Since: $last_modified");
255
+		if (count($curl_http_headers) > 0)
256
+			curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_http_headers);
251 257
 
252
-        if ($http_accept)
253
-            array_push($curl_http_headers, "Accept: " . $http_accept);
258
+		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : FILE_FETCH_CONNECT_TIMEOUT);
259
+		curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : FILE_FETCH_TIMEOUT);
260
+		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir") && $followlocation);
261
+		curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
262
+		curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
263
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
264
+		curl_setopt($ch, CURLOPT_HEADER, true);
265
+		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
266
+		curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent :
267
+			SELF_USER_AGENT);
268
+		curl_setopt($ch, CURLOPT_ENCODING, "");
254 269
 
255
-        if (count($curl_http_headers) > 0)
256
-            curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_http_headers);
270
+		if  ($http_referrer)
271
+			curl_setopt($ch, CURLOPT_REFERER, $http_referrer);
257 272
 
258
-        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : FILE_FETCH_CONNECT_TIMEOUT);
259
-        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : FILE_FETCH_TIMEOUT);
260
-        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir") && $followlocation);
261
-        curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
262
-        curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
263
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
264
-        curl_setopt($ch, CURLOPT_HEADER, true);
265
-        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
266
-        curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent :
267
-            SELF_USER_AGENT);
268
-        curl_setopt($ch, CURLOPT_ENCODING, "");
273
+		if ($max_size) {
274
+			curl_setopt($ch, CURLOPT_NOPROGRESS, false);
275
+			curl_setopt($ch, CURLOPT_BUFFERSIZE, 16384); // needed to get 5 arguments in progress function?
269 276
 
270
-        if  ($http_referrer)
271
-            curl_setopt($ch, CURLOPT_REFERER, $http_referrer);
277
+			// holy shit closures in php
278
+			// download & upload are *expected* sizes respectively, could be zero
279
+			curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curl_handle, $download_size, $downloaded, $upload_size, $uploaded) use( &$max_size) {
280
+				Debug::log("[curl progressfunction] $downloaded $max_size", Debug::$LOG_EXTENDED);
272 281
 
273
-        if ($max_size) {
274
-            curl_setopt($ch, CURLOPT_NOPROGRESS, false);
275
-            curl_setopt($ch, CURLOPT_BUFFERSIZE, 16384); // needed to get 5 arguments in progress function?
282
+				return ($downloaded > $max_size) ? 1 : 0; // if max size is set, abort when exceeding it
283
+			});
276 284
 
277
-            // holy shit closures in php
278
-            // download & upload are *expected* sizes respectively, could be zero
279
-            curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curl_handle, $download_size, $downloaded, $upload_size, $uploaded) use( &$max_size) {
280
-                Debug::log("[curl progressfunction] $downloaded $max_size", Debug::$LOG_EXTENDED);
285
+		}
281 286
 
282
-                return ($downloaded > $max_size) ? 1 : 0; // if max size is set, abort when exceeding it
283
-            });
287
+		if (!ini_get("open_basedir")) {
288
+			curl_setopt($ch, CURLOPT_COOKIEJAR, "/dev/null");
289
+		}
284 290
 
285
-        }
291
+		if (defined('_HTTP_PROXY')) {
292
+			curl_setopt($ch, CURLOPT_PROXY, _HTTP_PROXY);
293
+		}
286 294
 
287
-        if (!ini_get("open_basedir")) {
288
-            curl_setopt($ch, CURLOPT_COOKIEJAR, "/dev/null");
289
-        }
295
+		if ($post_query) {
296
+			curl_setopt($ch, CURLOPT_POST, true);
297
+			curl_setopt($ch, CURLOPT_POSTFIELDS, $post_query);
298
+		}
290 299
 
291
-        if (defined('_HTTP_PROXY')) {
292
-            curl_setopt($ch, CURLOPT_PROXY, _HTTP_PROXY);
293
-        }
300
+		if ($login && $pass)
301
+			curl_setopt($ch, CURLOPT_USERPWD, "$login:$pass");
294 302
 
295
-        if ($post_query) {
296
-            curl_setopt($ch, CURLOPT_POST, true);
297
-            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_query);
298
-        }
303
+		$ret = @curl_exec($ch);
299 304
 
300
-        if ($login && $pass)
301
-            curl_setopt($ch, CURLOPT_USERPWD, "$login:$pass");
305
+		$headers_length = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
306
+		$headers = explode("\r\n", substr($ret, 0, $headers_length));
307
+		$contents = substr($ret, $headers_length);
302 308
 
303
-        $ret = @curl_exec($ch);
309
+		foreach ($headers as $header) {
310
+			if (strstr($header, ": ") !== FALSE) {
311
+				list ($key, $value) = explode(": ", $header);
304 312
 
305
-        $headers_length = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
306
-        $headers = explode("\r\n", substr($ret, 0, $headers_length));
307
-        $contents = substr($ret, $headers_length);
313
+				if (strtolower($key) == "last-modified") {
314
+					$fetch_last_modified = $value;
315
+				}
316
+			}
308 317
 
309
-        foreach ($headers as $header) {
310
-            if (strstr($header, ": ") !== FALSE) {
311
-                list ($key, $value) = explode(": ", $header);
318
+			if (substr(strtolower($header), 0, 7) == 'http/1.') {
319
+				$fetch_last_error_code = (int) substr($header, 9, 3);
320
+				$fetch_last_error = $header;
321
+			}
322
+		}
312 323
 
313
-                if (strtolower($key) == "last-modified") {
314
-                    $fetch_last_modified = $value;
315
-                }
316
-            }
324
+		if (curl_errno($ch) === 23 || curl_errno($ch) === 61) {
325
+			curl_setopt($ch, CURLOPT_ENCODING, 'none');
326
+			$contents = @curl_exec($ch);
327
+		}
317 328
 
318
-            if (substr(strtolower($header), 0, 7) == 'http/1.') {
319
-                $fetch_last_error_code = (int) substr($header, 9, 3);
320
-                $fetch_last_error = $header;
321
-            }
322
-        }
329
+		$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
330
+		$fetch_last_content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
323 331
 
324
-        if (curl_errno($ch) === 23 || curl_errno($ch) === 61) {
325
-            curl_setopt($ch, CURLOPT_ENCODING, 'none');
326
-            $contents = @curl_exec($ch);
327
-        }
332
+		$fetch_effective_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
328 333
 
329
-        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
330
-        $fetch_last_content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
334
+		$fetch_last_error_code = $http_code;
331 335
 
332
-        $fetch_effective_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
336
+		if ($http_code != 200 || $type && strpos($fetch_last_content_type, "$type") === false) {
333 337
 
334
-        $fetch_last_error_code = $http_code;
338
+			if (curl_errno($ch) != 0) {
339
+				$fetch_last_error .=  "; " . curl_errno($ch) . " " . curl_error($ch);
340
+			}
335 341
 
336
-        if ($http_code != 200 || $type && strpos($fetch_last_content_type, "$type") === false) {
342
+			$fetch_last_error_content = $contents;
343
+			curl_close($ch);
344
+			return false;
345
+		}
337 346
 
338
-            if (curl_errno($ch) != 0) {
339
-                $fetch_last_error .=  "; " . curl_errno($ch) . " " . curl_error($ch);
340
-            }
347
+		if (!$contents) {
348
+			$fetch_last_error = curl_errno($ch) . " " . curl_error($ch);
349
+			curl_close($ch);
350
+			return false;
351
+		}
341 352
 
342
-            $fetch_last_error_content = $contents;
343
-            curl_close($ch);
344
-            return false;
345
-        }
353
+		curl_close($ch);
346 354
 
347
-        if (!$contents) {
348
-            $fetch_last_error = curl_errno($ch) . " " . curl_error($ch);
349
-            curl_close($ch);
350
-            return false;
351
-        }
355
+		$is_gzipped = RSSUtils::is_gzipped($contents);
352 356
 
353
-        curl_close($ch);
357
+		if ($is_gzipped) {
358
+			$tmp = @gzdecode($contents);
354 359
 
355
-        $is_gzipped = RSSUtils::is_gzipped($contents);
360
+			if ($tmp) $contents = $tmp;
361
+		}
356 362
 
357
-        if ($is_gzipped) {
358
-            $tmp = @gzdecode($contents);
363
+		return $contents;
364
+	} else {
359 365
 
360
-            if ($tmp) $contents = $tmp;
361
-        }
366
+		$fetch_curl_used = false;
362 367
 
363
-        return $contents;
364
-    } else {
368
+		if ($login && $pass){
369
+			$url_parts = array();
365 370
 
366
-        $fetch_curl_used = false;
371
+			preg_match("/(^[^:]*):\/\/(.*)/", $url, $url_parts);
367 372
 
368
-        if ($login && $pass){
369
-            $url_parts = array();
373
+			$pass = urlencode($pass);
370 374
 
371
-            preg_match("/(^[^:]*):\/\/(.*)/", $url, $url_parts);
375
+			if ($url_parts[1] && $url_parts[2]) {
376
+				$url = $url_parts[1] . "://$login:$pass@" . $url_parts[2];
377
+			}
378
+		}
372 379
 
373
-            $pass = urlencode($pass);
380
+		// TODO: should this support POST requests or not? idk
374 381
 
375
-            if ($url_parts[1] && $url_parts[2]) {
376
-                $url = $url_parts[1] . "://$login:$pass@" . $url_parts[2];
377
-            }
378
-        }
382
+		 $context_options = array(
383
+			  'http' => array(
384
+					'header' => array(
385
+						'Connection: close'
386
+					),
387
+					'method' => 'GET',
388
+					'ignore_errors' => true,
389
+					'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
390
+					'protocol_version'=> 1.1)
391
+			  );
379 392
 
380
-        // TODO: should this support POST requests or not? idk
393
+		if (!$post_query && $last_modified)
394
+			array_push($context_options['http']['header'], "If-Modified-Since: $last_modified");
381 395
 
382
-         $context_options = array(
383
-              'http' => array(
384
-                    'header' => array(
385
-                        'Connection: close'
386
-                    ),
387
-                    'method' => 'GET',
388
-                    'ignore_errors' => true,
389
-                    'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
390
-                    'protocol_version'=> 1.1)
391
-              );
396
+		if ($http_accept)
397
+			array_push($context_options['http']['header'], "Accept: $http_accept");
392 398
 
393
-        if (!$post_query && $last_modified)
394
-            array_push($context_options['http']['header'], "If-Modified-Since: $last_modified");
399
+		if ($http_referrer)
400
+			array_push($context_options['http']['header'], "Referer: $http_referrer");
395 401
 
396
-        if ($http_accept)
397
-            array_push($context_options['http']['header'], "Accept: $http_accept");
402
+		if (defined('_HTTP_PROXY')) {
403
+			$context_options['http']['request_fulluri'] = true;
404
+			$context_options['http']['proxy'] = _HTTP_PROXY;
405
+		}
398 406
 
399
-        if ($http_referrer)
400
-            array_push($context_options['http']['header'], "Referer: $http_referrer");
407
+		$context = stream_context_create($context_options);
401 408
 
402
-        if (defined('_HTTP_PROXY')) {
403
-            $context_options['http']['request_fulluri'] = true;
404
-            $context_options['http']['proxy'] = _HTTP_PROXY;
405
-        }
409
+		$old_error = error_get_last();
406 410
 
407
-        $context = stream_context_create($context_options);
411
+		$fetch_effective_url = $url;
408 412
 
409
-        $old_error = error_get_last();
413
+		$data = @file_get_contents($url, false, $context);
410 414
 
411
-        $fetch_effective_url = $url;
415
+		if (isset($http_response_header) && is_array($http_response_header)) {
416
+			foreach ($http_response_header as $header) {
417
+				if (strstr($header, ": ") !== FALSE) {
418
+					list ($key, $value) = explode(": ", $header);
412 419
 
413
-        $data = @file_get_contents($url, false, $context);
420
+					$key = strtolower($key);
414 421
 
415
-        if (isset($http_response_header) && is_array($http_response_header)) {
416
-            foreach ($http_response_header as $header) {
417
-                if (strstr($header, ": ") !== FALSE) {
418
-                    list ($key, $value) = explode(": ", $header);
422
+					if ($key == 'content-type') {
423
+						$fetch_last_content_type = $value;
424
+						// don't abort here b/c there might be more than one
425
+						// e.g. if we were being redirected -- last one is the right one
426
+					} else if ($key == 'last-modified') {
427
+						$fetch_last_modified = $value;
428
+					} else if ($key == 'location') {
429
+						$fetch_effective_url = $value;
430
+					}
431
+				}
419 432
 
420
-                    $key = strtolower($key);
433
+				if (substr(strtolower($header), 0, 7) == 'http/1.') {
434
+					$fetch_last_error_code = (int) substr($header, 9, 3);
435
+					$fetch_last_error = $header;
436
+				}
437
+			}
438
+		}
421 439
 
422
-                    if ($key == 'content-type') {
423
-                        $fetch_last_content_type = $value;
424
-                        // don't abort here b/c there might be more than one
425
-                        // e.g. if we were being redirected -- last one is the right one
426
-                    } else if ($key == 'last-modified') {
427
-                        $fetch_last_modified = $value;
428
-                    } else if ($key == 'location') {
429
-                        $fetch_effective_url = $value;
430
-                    }
431
-                }
440
+		if ($fetch_last_error_code != 200) {
441
+			$error = error_get_last();
432 442
 
433
-                if (substr(strtolower($header), 0, 7) == 'http/1.') {
434
-                    $fetch_last_error_code = (int) substr($header, 9, 3);
435
-                    $fetch_last_error = $header;
436
-                }
437
-            }
438
-        }
443
+			if ($error['message'] != $old_error['message']) {
444
+				$fetch_last_error .= "; " . $error["message"];
445
+			}
439 446
 
440
-        if ($fetch_last_error_code != 200) {
441
-            $error = error_get_last();
447
+			$fetch_last_error_content = $data;
442 448
 
443
-            if ($error['message'] != $old_error['message']) {
444
-                $fetch_last_error .= "; " . $error["message"];
445
-            }
449
+			return false;
450
+		}
446 451
 
447
-            $fetch_last_error_content = $data;
452
+		$is_gzipped = RSSUtils::is_gzipped($data);
448 453
 
449
-            return false;
450
-        }
454
+		if ($is_gzipped) {
455
+			$tmp = @gzdecode($data);
451 456
 
452
-        $is_gzipped = RSSUtils::is_gzipped($data);
457
+			if ($tmp) $data = $tmp;
458
+		}
453 459
 
454
-        if ($is_gzipped) {
455
-            $tmp = @gzdecode($data);
456
-
457
-            if ($tmp) $data = $tmp;
458
-        }
459
-
460
-        return $data;
461
-    }
460
+		return $data;
461
+	}
462 462
 
463 463
 }
464 464
 
465 465
 function initialize_user_prefs($uid, $profile = false) {
466 466
 
467
-    if (get_schema_version() < 63) $profile_qpart = "";
467
+	if (get_schema_version() < 63) $profile_qpart = "";
468 468
 
469
-    $pdo = DB::pdo();
470
-    $in_nested_tr = false;
469
+	$pdo = DB::pdo();
470
+	$in_nested_tr = false;
471 471
 
472
-    try {
473
-        $pdo->beginTransaction();
474
-    } catch (Exception $e) {
475
-        $in_nested_tr = true;
476
-    }
472
+	try {
473
+		$pdo->beginTransaction();
474
+	} catch (Exception $e) {
475
+		$in_nested_tr = true;
476
+	}
477 477
 
478
-    $sth = $pdo->query("SELECT pref_name,def_value FROM ttrss_prefs");
478
+	$sth = $pdo->query("SELECT pref_name,def_value FROM ttrss_prefs");
479 479
 
480
-    if (!is_numeric($profile) || !$profile || get_schema_version() < 63) $profile = null;
480
+	if (!is_numeric($profile) || !$profile || get_schema_version() < 63) $profile = null;
481 481
 
482
-    $u_sth = $pdo->prepare("SELECT pref_name
482
+	$u_sth = $pdo->prepare("SELECT pref_name
483 483
         FROM ttrss_user_prefs WHERE owner_uid = :uid AND
484 484
             (profile = :profile OR (:profile IS NULL AND profile IS NULL))");
485
-    $u_sth->execute([':uid' => $uid, ':profile' => $profile]);
485
+	$u_sth->execute([':uid' => $uid, ':profile' => $profile]);
486 486
 
487
-    $active_prefs = array();
487
+	$active_prefs = array();
488 488
 
489
-    while ($line = $u_sth->fetch()) {
490
-        array_push($active_prefs, $line["pref_name"]);
491
-    }
489
+	while ($line = $u_sth->fetch()) {
490
+		array_push($active_prefs, $line["pref_name"]);
491
+	}
492 492
 
493
-    while ($line = $sth->fetch()) {
494
-        if (array_search($line["pref_name"], $active_prefs) === FALSE) {
493
+	while ($line = $sth->fetch()) {
494
+		if (array_search($line["pref_name"], $active_prefs) === FALSE) {
495 495
 //				print "adding " . $line["pref_name"] . "<br>";
496 496
 
497
-            if (get_schema_version() < 63) {
498
-                $i_sth = $pdo->prepare("INSERT INTO ttrss_user_prefs
497
+			if (get_schema_version() < 63) {
498
+				$i_sth = $pdo->prepare("INSERT INTO ttrss_user_prefs
499 499
                     (owner_uid,pref_name,value) VALUES
500 500
                     (?, ?, ?)");
501
-                $i_sth->execute([$uid, $line["pref_name"], $line["def_value"]]);
501
+				$i_sth->execute([$uid, $line["pref_name"], $line["def_value"]]);
502 502
 
503
-            } else {
504
-                $i_sth = $pdo->prepare("INSERT INTO ttrss_user_prefs
503
+			} else {
504
+				$i_sth = $pdo->prepare("INSERT INTO ttrss_user_prefs
505 505
                     (owner_uid,pref_name,value, profile) VALUES
506 506
                     (?, ?, ?, ?)");
507
-                $i_sth->execute([$uid, $line["pref_name"], $line["def_value"], $profile]);
508
-            }
507
+				$i_sth->execute([$uid, $line["pref_name"], $line["def_value"], $profile]);
508
+			}
509 509
 
510
-        }
511
-    }
510
+		}
511
+	}
512 512
 
513
-    if (!$in_nested_tr) $pdo->commit();
513
+	if (!$in_nested_tr) $pdo->commit();
514 514
 
515 515
 }
516 516
 
517 517
 function get_ssl_certificate_id() {
518
-    if ($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"]) {
519
-        return sha1($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"] .
520
-            $_SERVER["REDIRECT_SSL_CLIENT_V_START"] .
521
-            $_SERVER["REDIRECT_SSL_CLIENT_V_END"] .
522
-            $_SERVER["REDIRECT_SSL_CLIENT_S_DN"]);
523
-    }
524
-    if ($_SERVER["SSL_CLIENT_M_SERIAL"]) {
525
-        return sha1($_SERVER["SSL_CLIENT_M_SERIAL"] .
526
-            $_SERVER["SSL_CLIENT_V_START"] .
527
-            $_SERVER["SSL_CLIENT_V_END"] .
528
-            $_SERVER["SSL_CLIENT_S_DN"]);
529
-    }
530
-    return "";
518
+	if ($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"]) {
519
+		return sha1($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"] .
520
+			$_SERVER["REDIRECT_SSL_CLIENT_V_START"] .
521
+			$_SERVER["REDIRECT_SSL_CLIENT_V_END"] .
522
+			$_SERVER["REDIRECT_SSL_CLIENT_S_DN"]);
523
+	}
524
+	if ($_SERVER["SSL_CLIENT_M_SERIAL"]) {
525
+		return sha1($_SERVER["SSL_CLIENT_M_SERIAL"] .
526
+			$_SERVER["SSL_CLIENT_V_START"] .
527
+			$_SERVER["SSL_CLIENT_V_END"] .
528
+			$_SERVER["SSL_CLIENT_S_DN"]);
529
+	}
530
+	return "";
531 531
 }
532 532
 
533 533
 function authenticate_user($login, $password, $check_only = false, $service = false) {
534 534
 
535
-    if (!SINGLE_USER_MODE) {
536
-        $user_id = false;
537
-        $auth_module = false;
535
+	if (!SINGLE_USER_MODE) {
536
+		$user_id = false;
537
+		$auth_module = false;
538 538
 
539
-        foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_AUTH_USER) as $plugin) {
539
+		foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_AUTH_USER) as $plugin) {
540 540
 
541
-            $user_id = (int) $plugin->authenticate($login, $password, $service);
541
+			$user_id = (int) $plugin->authenticate($login, $password, $service);
542 542
 
543
-            if ($user_id) {
544
-                $auth_module = strtolower(get_class($plugin));
545
-                break;
546
-            }
547
-        }
543
+			if ($user_id) {
544
+				$auth_module = strtolower(get_class($plugin));
545
+				break;
546
+			}
547
+		}
548 548
 
549
-        if ($user_id && !$check_only) {
549
+		if ($user_id && !$check_only) {
550 550
 
551
-            session_start();
552
-            session_regenerate_id(true);
551
+			session_start();
552
+			session_regenerate_id(true);
553 553
 
554
-            $_SESSION["uid"] = $user_id;
555
-            $_SESSION["auth_module"] = $auth_module;
554
+			$_SESSION["uid"] = $user_id;
555
+			$_SESSION["auth_module"] = $auth_module;
556 556
 
557
-            $pdo = DB::pdo();
558
-            $sth = $pdo->prepare("SELECT login,access_level,pwd_hash FROM ttrss_users
557
+			$pdo = DB::pdo();
558
+			$sth = $pdo->prepare("SELECT login,access_level,pwd_hash FROM ttrss_users
559 559
                 WHERE id = ?");
560
-            $sth->execute([$user_id]);
561
-            $row = $sth->fetch();
560
+			$sth->execute([$user_id]);
561
+			$row = $sth->fetch();
562 562
 
563
-            $_SESSION["name"] = $row["login"];
564
-            $_SESSION["access_level"] = $row["access_level"];
565
-            $_SESSION["csrf_token"] = uniqid_short();
563
+			$_SESSION["name"] = $row["login"];
564
+			$_SESSION["access_level"] = $row["access_level"];
565
+			$_SESSION["csrf_token"] = uniqid_short();
566 566
 
567
-            $usth = $pdo->prepare("UPDATE ttrss_users SET last_login = NOW() WHERE id = ?");
568
-            $usth->execute([$user_id]);
567
+			$usth = $pdo->prepare("UPDATE ttrss_users SET last_login = NOW() WHERE id = ?");
568
+			$usth->execute([$user_id]);
569 569
 
570
-            $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
571
-            $_SESSION["user_agent"] = sha1($_SERVER['HTTP_USER_AGENT']);
572
-            $_SESSION["pwd_hash"] = $row["pwd_hash"];
570
+			$_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
571
+			$_SESSION["user_agent"] = sha1($_SERVER['HTTP_USER_AGENT']);
572
+			$_SESSION["pwd_hash"] = $row["pwd_hash"];
573 573
 
574
-            initialize_user_prefs($_SESSION["uid"]);
574
+			initialize_user_prefs($_SESSION["uid"]);
575 575
 
576
-            return true;
577
-        }
576
+			return true;
577
+		}
578 578
 
579
-        return false;
579
+		return false;
580 580
 
581
-    } else {
581
+	} else {
582 582
 
583
-        $_SESSION["uid"] = 1;
584
-        $_SESSION["name"] = "admin";
585
-        $_SESSION["access_level"] = 10;
583
+		$_SESSION["uid"] = 1;
584
+		$_SESSION["name"] = "admin";
585
+		$_SESSION["access_level"] = 10;
586 586
 
587
-        $_SESSION["hide_hello"] = true;
588
-        $_SESSION["hide_logout"] = true;
587
+		$_SESSION["hide_hello"] = true;
588
+		$_SESSION["hide_logout"] = true;
589 589
 
590
-        $_SESSION["auth_module"] = false;
590
+		$_SESSION["auth_module"] = false;
591 591
 
592
-        if (!$_SESSION["csrf_token"]) {
593
-            $_SESSION["csrf_token"] = uniqid_short();
594
-        }
592
+		if (!$_SESSION["csrf_token"]) {
593
+			$_SESSION["csrf_token"] = uniqid_short();
594
+		}
595 595
 
596
-        $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
596
+		$_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
597 597
 
598
-        initialize_user_prefs($_SESSION["uid"]);
598
+		initialize_user_prefs($_SESSION["uid"]);
599 599
 
600
-        return true;
601
-    }
600
+		return true;
601
+	}
602 602
 }
603 603
 
604 604
 // this is used for user http parameters unless HTML code is actually needed
605 605
 function clean($param) {
606
-    if (is_array($param)) {
607
-        return array_map("strip_tags", $param);
608
-    } else if (is_string($param)) {
609
-        return strip_tags($param);
610
-    } else {
611
-        return $param;
612
-    }
606
+	if (is_array($param)) {
607
+		return array_map("strip_tags", $param);
608
+	} else if (is_string($param)) {
609
+		return strip_tags($param);
610
+	} else {
611
+		return $param;
612
+	}
613 613
 }
614 614
 
615 615
 function clean_filename($filename) {
616
-    return basename(preg_replace("/\.\.|[\/\\\]/", "", clean($filename)));
616
+	return basename(preg_replace("/\.\.|[\/\\\]/", "", clean($filename)));
617 617
 }
618 618
 
619 619
 function make_password($length = 12) {
620
-    $password = "";
621
-    $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^";
620
+	$password = "";
621
+	$possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^";
622 622
 
623
-    $i = 0;
623
+	$i = 0;
624 624
 
625
-    while ($i < $length) {
625
+	while ($i < $length) {
626 626
 
627
-        try {
628
-            $idx = function_exists("random_int") ? random_int(0, strlen($possible) - 1) : mt_rand(0, strlen($possible) - 1);
629
-        } catch (Exception $e) {
630
-            $idx = mt_rand(0, strlen($possible) - 1);
631
-        }
627
+		try {
628
+			$idx = function_exists("random_int") ? random_int(0, strlen($possible) - 1) : mt_rand(0, strlen($possible) - 1);
629
+		} catch (Exception $e) {
630
+			$idx = mt_rand(0, strlen($possible) - 1);
631
+		}
632 632
 
633
-        $char = substr($possible, $idx, 1);
633
+		$char = substr($possible, $idx, 1);
634 634
 
635
-        if (!strstr($password, $char)) {
636
-            $password .= $char;
637
-            $i++;
638
-        }
639
-    }
635
+		if (!strstr($password, $char)) {
636
+			$password .= $char;
637
+			$i++;
638
+		}
639
+	}
640 640
 
641
-    return $password;
641
+	return $password;
642 642
 }
643 643
 
644 644
 // this is called after user is created to initialize default feeds, labels
@@ -648,889 +648,889 @@  discard block
 block discarded – undo
648 648
 
649 649
 function initialize_user($uid) {
650 650
 
651
-    $pdo = DB::pdo();
651
+	$pdo = DB::pdo();
652 652
 
653
-    $sth = $pdo->prepare("insert into ttrss_feeds (owner_uid,title,feed_url)
653
+	$sth = $pdo->prepare("insert into ttrss_feeds (owner_uid,title,feed_url)
654 654
         values (?, 'Tiny Tiny RSS: Forum',
655 655
             'http://tt-rss.org/forum/rss.php')");
656
-    $sth->execute([$uid]);
656
+	$sth->execute([$uid]);
657 657
 }
658 658
 
659 659
 function logout_user() {
660
-    @session_destroy();
661
-    if (isset($_COOKIE[session_name()])) {
662
-       setcookie(session_name(), '', time()-42000, '/');
663
-    }
664
-    session_commit();
660
+	@session_destroy();
661
+	if (isset($_COOKIE[session_name()])) {
662
+	   setcookie(session_name(), '', time()-42000, '/');
663
+	}
664
+	session_commit();
665 665
 }
666 666
 
667 667
 function validate_csrf($csrf_token) {
668
-    return $csrf_token == $_SESSION['csrf_token'];
668
+	return $csrf_token == $_SESSION['csrf_token'];
669 669
 }
670 670
 
671 671
 function load_user_plugins($owner_uid, $pluginhost = false) {
672 672
 
673
-    if (!$pluginhost) $pluginhost = PluginHost::getInstance();
673
+	if (!$pluginhost) $pluginhost = PluginHost::getInstance();
674 674
 
675
-    if ($owner_uid && SCHEMA_VERSION >= 100) {
676
-        $plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
675
+	if ($owner_uid && SCHEMA_VERSION >= 100) {
676
+		$plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
677 677
 
678
-        $pluginhost->load($plugins, PluginHost::KIND_USER, $owner_uid);
678
+		$pluginhost->load($plugins, PluginHost::KIND_USER, $owner_uid);
679 679
 
680
-        if (get_schema_version() > 100) {
681
-            $pluginhost->load_data();
682
-        }
683
-    }
680
+		if (get_schema_version() > 100) {
681
+			$pluginhost->load_data();
682
+		}
683
+	}
684 684
 }
685 685
 
686 686
 function login_sequence() {
687
-    $pdo = Db::pdo();
687
+	$pdo = Db::pdo();
688 688
 
689
-    if (SINGLE_USER_MODE) {
690
-        @session_start();
691
-        authenticate_user("admin", null);
692
-        startup_gettext();
693
-        load_user_plugins($_SESSION["uid"]);
694
-    } else {
695
-        if (!validate_session()) $_SESSION["uid"] = false;
689
+	if (SINGLE_USER_MODE) {
690
+		@session_start();
691
+		authenticate_user("admin", null);
692
+		startup_gettext();
693
+		load_user_plugins($_SESSION["uid"]);
694
+	} else {
695
+		if (!validate_session()) $_SESSION["uid"] = false;
696 696
 
697
-        if (!$_SESSION["uid"]) {
697
+		if (!$_SESSION["uid"]) {
698 698
 
699
-            if (AUTH_AUTO_LOGIN && authenticate_user(null, null)) {
700
-                $_SESSION["ref_schema_version"] = get_schema_version(true);
701
-            } else {
702
-                 authenticate_user(null, null, true);
703
-            }
699
+			if (AUTH_AUTO_LOGIN && authenticate_user(null, null)) {
700
+				$_SESSION["ref_schema_version"] = get_schema_version(true);
701
+			} else {
702
+				 authenticate_user(null, null, true);
703
+			}
704 704
 
705
-            if (!$_SESSION["uid"]) {
706
-                logout_user();
705
+			if (!$_SESSION["uid"]) {
706
+				logout_user();
707 707
 
708
-                render_login_form();
709
-                exit;
710
-            }
708
+				render_login_form();
709
+				exit;
710
+			}
711 711
 
712
-        } else {
713
-            /* bump login timestamp */
714
-            $sth = $pdo->prepare("UPDATE ttrss_users SET last_login = NOW() WHERE id = ?");
715
-            $sth->execute([$_SESSION['uid']]);
712
+		} else {
713
+			/* bump login timestamp */
714
+			$sth = $pdo->prepare("UPDATE ttrss_users SET last_login = NOW() WHERE id = ?");
715
+			$sth->execute([$_SESSION['uid']]);
716 716
 
717
-            $_SESSION["last_login_update"] = time();
718
-        }
717
+			$_SESSION["last_login_update"] = time();
718
+		}
719 719
 
720
-        if ($_SESSION["uid"]) {
721
-            startup_gettext();
722
-            load_user_plugins($_SESSION["uid"]);
720
+		if ($_SESSION["uid"]) {
721
+			startup_gettext();
722
+			load_user_plugins($_SESSION["uid"]);
723 723
 
724
-            /* cleanup ccache */
724
+			/* cleanup ccache */
725 725
 
726
-            $sth = $pdo->prepare("DELETE FROM ttrss_counters_cache WHERE owner_uid = ?
726
+			$sth = $pdo->prepare("DELETE FROM ttrss_counters_cache WHERE owner_uid = ?
727 727
                 AND
728 728
                     (SELECT COUNT(id) FROM ttrss_feeds WHERE
729 729
                         ttrss_feeds.id = feed_id) = 0");
730 730
 
731
-            $sth->execute([$_SESSION['uid']]);
731
+			$sth->execute([$_SESSION['uid']]);
732 732
 
733
-            $sth = $pdo->prepare("DELETE FROM ttrss_cat_counters_cache WHERE owner_uid = ?
733
+			$sth = $pdo->prepare("DELETE FROM ttrss_cat_counters_cache WHERE owner_uid = ?
734 734
                 AND
735 735
                     (SELECT COUNT(id) FROM ttrss_feed_categories WHERE
736 736
                         ttrss_feed_categories.id = feed_id) = 0");
737 737
 
738
-            $sth->execute([$_SESSION['uid']]);
739
-        }
738
+			$sth->execute([$_SESSION['uid']]);
739
+		}
740 740
 
741
-    }
741
+	}
742 742
 }
743 743
 
744 744
 function truncate_string($str, $max_len, $suffix = '&hellip;') {
745
-    if (mb_strlen($str, "utf-8") > $max_len) {
746
-        return mb_substr($str, 0, $max_len, "utf-8") . $suffix;
747
-    } else {
748
-        return $str;
749
-    }
745
+	if (mb_strlen($str, "utf-8") > $max_len) {
746
+		return mb_substr($str, 0, $max_len, "utf-8") . $suffix;
747
+	} else {
748
+		return $str;
749
+	}
750 750
 }
751 751
 
752 752
 function mb_substr_replace($original, $replacement, $position, $length) {
753
-    $startString = mb_substr($original, 0, $position, "UTF-8");
754
-    $endString = mb_substr($original, $position + $length, mb_strlen($original), "UTF-8");
753
+	$startString = mb_substr($original, 0, $position, "UTF-8");
754
+	$endString = mb_substr($original, $position + $length, mb_strlen($original), "UTF-8");
755 755
 
756
-    $out = $startString . $replacement . $endString;
756
+	$out = $startString . $replacement . $endString;
757 757
 
758
-    return $out;
758
+	return $out;
759 759
 }
760 760
 
761 761
 function truncate_middle($str, $max_len, $suffix = '&hellip;') {
762
-    if (mb_strlen($str) > $max_len) {
763
-        return mb_substr_replace($str, $suffix, $max_len / 2, mb_strlen($str) - $max_len);
764
-    } else {
765
-        return $str;
766
-    }
762
+	if (mb_strlen($str) > $max_len) {
763
+		return mb_substr_replace($str, $suffix, $max_len / 2, mb_strlen($str) - $max_len);
764
+	} else {
765
+		return $str;
766
+	}
767 767
 }
768 768
 
769 769
 function convert_timestamp($timestamp, $source_tz, $dest_tz) {
770 770
 
771
-    try {
772
-        $source_tz = new DateTimeZone($source_tz);
773
-    } catch (Exception $e) {
774
-        $source_tz = new DateTimeZone('UTC');
775
-    }
771
+	try {
772
+		$source_tz = new DateTimeZone($source_tz);
773
+	} catch (Exception $e) {
774
+		$source_tz = new DateTimeZone('UTC');
775
+	}
776 776
 
777
-    try {
778
-        $dest_tz = new DateTimeZone($dest_tz);
779
-    } catch (Exception $e) {
780
-        $dest_tz = new DateTimeZone('UTC');
781
-    }
777
+	try {
778
+		$dest_tz = new DateTimeZone($dest_tz);
779
+	} catch (Exception $e) {
780
+		$dest_tz = new DateTimeZone('UTC');
781
+	}
782 782
 
783
-    $dt = new DateTime(date('Y-m-d H:i:s', $timestamp), $source_tz);
784
-    return $dt->format('U') + $dest_tz->getOffset($dt);
783
+	$dt = new DateTime(date('Y-m-d H:i:s', $timestamp), $source_tz);
784
+	return $dt->format('U') + $dest_tz->getOffset($dt);
785 785
 }
786 786
 
787 787
 function make_local_datetime($timestamp, $long, $owner_uid = false,
788
-                $no_smart_dt = false, $eta_min = false) {
788
+				$no_smart_dt = false, $eta_min = false) {
789 789
 
790
-    if (!$owner_uid) $owner_uid = $_SESSION['uid'];
791
-    if (!$timestamp) $timestamp = '1970-01-01 0:00';
790
+	if (!$owner_uid) $owner_uid = $_SESSION['uid'];
791
+	if (!$timestamp) $timestamp = '1970-01-01 0:00';
792 792
 
793
-    global $utc_tz;
794
-    global $user_tz;
793
+	global $utc_tz;
794
+	global $user_tz;
795 795
 
796
-    if (!$utc_tz) $utc_tz = new DateTimeZone('UTC');
796
+	if (!$utc_tz) $utc_tz = new DateTimeZone('UTC');
797 797
 
798
-    $timestamp = substr($timestamp, 0, 19);
798
+	$timestamp = substr($timestamp, 0, 19);
799 799
 
800
-    # We store date in UTC internally
801
-    $dt = new DateTime($timestamp, $utc_tz);
800
+	# We store date in UTC internally
801
+	$dt = new DateTime($timestamp, $utc_tz);
802 802
 
803
-    $user_tz_string = get_pref('USER_TIMEZONE', $owner_uid);
803
+	$user_tz_string = get_pref('USER_TIMEZONE', $owner_uid);
804 804
 
805
-    if ($user_tz_string != 'Automatic') {
805
+	if ($user_tz_string != 'Automatic') {
806 806
 
807
-        try {
808
-            if (!$user_tz) $user_tz = new DateTimeZone($user_tz_string);
809
-        } catch (Exception $e) {
810
-            $user_tz = $utc_tz;
811
-        }
807
+		try {
808
+			if (!$user_tz) $user_tz = new DateTimeZone($user_tz_string);
809
+		} catch (Exception $e) {
810
+			$user_tz = $utc_tz;
811
+		}
812 812
 
813
-        $tz_offset = $user_tz->getOffset($dt);
814
-    } else {
815
-        $tz_offset = (int) -$_SESSION["clientTzOffset"];
816
-    }
813
+		$tz_offset = $user_tz->getOffset($dt);
814
+	} else {
815
+		$tz_offset = (int) -$_SESSION["clientTzOffset"];
816
+	}
817 817
 
818
-    $user_timestamp = $dt->format('U') + $tz_offset;
818
+	$user_timestamp = $dt->format('U') + $tz_offset;
819 819
 
820
-    if (!$no_smart_dt) {
821
-        return smart_date_time($user_timestamp,
822
-            $tz_offset, $owner_uid, $eta_min);
823
-    } else {
824
-        if ($long)
825
-            $format = get_pref('LONG_DATE_FORMAT', $owner_uid);
826
-        else
827
-            $format = get_pref('SHORT_DATE_FORMAT', $owner_uid);
820
+	if (!$no_smart_dt) {
821
+		return smart_date_time($user_timestamp,
822
+			$tz_offset, $owner_uid, $eta_min);
823
+	} else {
824
+		if ($long)
825
+			$format = get_pref('LONG_DATE_FORMAT', $owner_uid);
826
+		else
827
+			$format = get_pref('SHORT_DATE_FORMAT', $owner_uid);
828 828
 
829
-        return date($format, $user_timestamp);
830
-    }
829
+		return date($format, $user_timestamp);
830
+	}
831 831
 }
832 832
 
833 833
 function smart_date_time($timestamp, $tz_offset = 0, $owner_uid = false, $eta_min = false) {
834
-    if (!$owner_uid) $owner_uid = $_SESSION['uid'];
835
-
836
-    if ($eta_min && time() + $tz_offset - $timestamp < 3600) {
837
-        return T_sprintf("%d min", date("i", time() + $tz_offset - $timestamp));
838
-    } else if (date("Y.m.d", $timestamp) == date("Y.m.d", time() + $tz_offset)) {
839
-        $format = get_pref('SHORT_DATE_FORMAT', $owner_uid);
840
-        if (strpos((strtolower($format)), "a") === false)
841
-            return date("G:i", $timestamp);
842
-        else
843
-            return date("g:i a", $timestamp);
844
-    } else if (date("Y", $timestamp) == date("Y", time() + $tz_offset)) {
845
-        $format = get_pref('SHORT_DATE_FORMAT', $owner_uid);
846
-        return date($format, $timestamp);
847
-    } else {
848
-        $format = get_pref('LONG_DATE_FORMAT', $owner_uid);
849
-        return date($format, $timestamp);
850
-    }
834
+	if (!$owner_uid) $owner_uid = $_SESSION['uid'];
835
+
836
+	if ($eta_min && time() + $tz_offset - $timestamp < 3600) {
837
+		return T_sprintf("%d min", date("i", time() + $tz_offset - $timestamp));
838
+	} else if (date("Y.m.d", $timestamp) == date("Y.m.d", time() + $tz_offset)) {
839
+		$format = get_pref('SHORT_DATE_FORMAT', $owner_uid);
840
+		if (strpos((strtolower($format)), "a") === false)
841
+			return date("G:i", $timestamp);
842
+		else
843
+			return date("g:i a", $timestamp);
844
+	} else if (date("Y", $timestamp) == date("Y", time() + $tz_offset)) {
845
+		$format = get_pref('SHORT_DATE_FORMAT', $owner_uid);
846
+		return date($format, $timestamp);
847
+	} else {
848
+		$format = get_pref('LONG_DATE_FORMAT', $owner_uid);
849
+		return date($format, $timestamp);
850
+	}
851 851
 }
852 852
 
853 853
 function sql_bool_to_bool($s) {
854
-    return $s && ($s !== "f" && $s !== "false"); //no-op for PDO, backwards compat for legacy layer
854
+	return $s && ($s !== "f" && $s !== "false"); //no-op for PDO, backwards compat for legacy layer
855 855
 }
856 856
 
857 857
 function bool_to_sql_bool($s) {
858
-    return $s ? 1 : 0;
858
+	return $s ? 1 : 0;
859 859
 }
860 860
 
861 861
 // Session caching removed due to causing wrong redirects to upgrade
862 862
 // script when get_schema_version() is called on an obsolete session
863 863
 // created on a previous schema version.
864 864
 function get_schema_version($nocache = false) {
865
-    global $schema_version;
865
+	global $schema_version;
866 866
 
867
-    $pdo = DB::pdo();
867
+	$pdo = DB::pdo();
868 868
 
869
-    if (!$schema_version && !$nocache) {
870
-        $row = $pdo->query("SELECT schema_version FROM ttrss_version")->fetch();
871
-        $version = $row["schema_version"];
872
-        $schema_version = $version;
873
-        return $version;
874
-    } else {
875
-        return $schema_version;
876
-    }
869
+	if (!$schema_version && !$nocache) {
870
+		$row = $pdo->query("SELECT schema_version FROM ttrss_version")->fetch();
871
+		$version = $row["schema_version"];
872
+		$schema_version = $version;
873
+		return $version;
874
+	} else {
875
+		return $schema_version;
876
+	}
877 877
 }
878 878
 
879 879
 function sanity_check() {
880
-    require_once 'errors.php';
881
-    global $ERRORS;
880
+	require_once 'errors.php';
881
+	global $ERRORS;
882 882
 
883
-    $error_code = 0;
884
-    $schema_version = get_schema_version(true);
883
+	$error_code = 0;
884
+	$schema_version = get_schema_version(true);
885 885
 
886
-    if ($schema_version != SCHEMA_VERSION) {
887
-        $error_code = 5;
888
-    }
886
+	if ($schema_version != SCHEMA_VERSION) {
887
+		$error_code = 5;
888
+	}
889 889
 
890
-    return array("code" => $error_code, "message" => $ERRORS[$error_code]);
890
+	return array("code" => $error_code, "message" => $ERRORS[$error_code]);
891 891
 }
892 892
 
893 893
 function file_is_locked($filename) {
894
-    if (file_exists(LOCK_DIRECTORY . "/$filename")) {
895
-        if (function_exists('flock')) {
896
-            $fp = @fopen(LOCK_DIRECTORY . "/$filename", "r");
897
-            if ($fp) {
898
-                if (flock($fp, LOCK_EX | LOCK_NB)) {
899
-                    flock($fp, LOCK_UN);
900
-                    fclose($fp);
901
-                    return false;
902
-                }
903
-                fclose($fp);
904
-                return true;
905
-            } else {
906
-                return false;
907
-            }
908
-        }
909
-        return true; // consider the file always locked and skip the test
910
-    } else {
911
-        return false;
912
-    }
894
+	if (file_exists(LOCK_DIRECTORY . "/$filename")) {
895
+		if (function_exists('flock')) {
896
+			$fp = @fopen(LOCK_DIRECTORY . "/$filename", "r");
897
+			if ($fp) {
898
+				if (flock($fp, LOCK_EX | LOCK_NB)) {
899
+					flock($fp, LOCK_UN);
900
+					fclose($fp);
901
+					return false;
902
+				}
903
+				fclose($fp);
904
+				return true;
905
+			} else {
906
+				return false;
907
+			}
908
+		}
909
+		return true; // consider the file always locked and skip the test
910
+	} else {
911
+		return false;
912
+	}
913 913
 }
914 914
 
915 915
 
916 916
 function make_lockfile($filename) {
917
-    $fp = fopen(LOCK_DIRECTORY . "/$filename", "w");
917
+	$fp = fopen(LOCK_DIRECTORY . "/$filename", "w");
918 918
 
919
-    if ($fp && flock($fp, LOCK_EX | LOCK_NB)) {
920
-        $stat_h = fstat($fp);
921
-        $stat_f = stat(LOCK_DIRECTORY . "/$filename");
919
+	if ($fp && flock($fp, LOCK_EX | LOCK_NB)) {
920
+		$stat_h = fstat($fp);
921
+		$stat_f = stat(LOCK_DIRECTORY . "/$filename");
922 922
 
923
-        if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
924
-            if ($stat_h["ino"] != $stat_f["ino"] ||
925
-                    $stat_h["dev"] != $stat_f["dev"]) {
923
+		if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
924
+			if ($stat_h["ino"] != $stat_f["ino"] ||
925
+					$stat_h["dev"] != $stat_f["dev"]) {
926 926
 
927
-                return false;
928
-            }
929
-        }
927
+				return false;
928
+			}
929
+		}
930 930
 
931
-        if (function_exists('posix_getpid')) {
932
-            fwrite($fp, posix_getpid() . "\n");
933
-        }
934
-        return $fp;
935
-    } else {
936
-        return false;
937
-    }
931
+		if (function_exists('posix_getpid')) {
932
+			fwrite($fp, posix_getpid() . "\n");
933
+		}
934
+		return $fp;
935
+	} else {
936
+		return false;
937
+	}
938 938
 }
939 939
 
940 940
 function make_stampfile($filename) {
941
-    $fp = fopen(LOCK_DIRECTORY . "/$filename", "w");
941
+	$fp = fopen(LOCK_DIRECTORY . "/$filename", "w");
942 942
 
943
-    if (flock($fp, LOCK_EX | LOCK_NB)) {
944
-        fwrite($fp, time() . "\n");
945
-        flock($fp, LOCK_UN);
946
-        fclose($fp);
947
-        return true;
948
-    } else {
949
-        return false;
950
-    }
943
+	if (flock($fp, LOCK_EX | LOCK_NB)) {
944
+		fwrite($fp, time() . "\n");
945
+		flock($fp, LOCK_UN);
946
+		fclose($fp);
947
+		return true;
948
+	} else {
949
+		return false;
950
+	}
951 951
 }
952 952
 
953 953
 function sql_random_function() {
954
-    if (DB_TYPE == "mysql") {
955
-        return "RAND()";
956
-    } else {
957
-        return "RANDOM()";
958
-    }
954
+	if (DB_TYPE == "mysql") {
955
+		return "RAND()";
956
+	} else {
957
+		return "RANDOM()";
958
+	}
959 959
 }
960 960
 
961 961
 function getFeedUnread($feed, $is_cat = false) {
962
-    return Feeds::getFeedArticles($feed, $is_cat, true, $_SESSION["uid"]);
962
+	return Feeds::getFeedArticles($feed, $is_cat, true, $_SESSION["uid"]);
963 963
 }
964 964
 
965 965
 function checkbox_to_sql_bool($val) {
966
-    return ($val == "on") ? 1 : 0;
966
+	return ($val == "on") ? 1 : 0;
967 967
 }
968 968
 
969 969
 function uniqid_short() {
970
-    return uniqid(base_convert(rand(), 10, 36));
970
+	return uniqid(base_convert(rand(), 10, 36));
971 971
 }
972 972
 
973 973
 function make_init_params() {
974
-    $params = array();
974
+	$params = array();
975 975
 
976
-    foreach (array("ON_CATCHUP_SHOW_NEXT_FEED", "HIDE_READ_FEEDS",
977
-                 "ENABLE_FEED_CATS", "FEEDS_SORT_BY_UNREAD", "CONFIRM_FEED_CATCHUP",
978
-                 "CDM_AUTO_CATCHUP", "FRESH_ARTICLE_MAX_AGE",
979
-                 "HIDE_READ_SHOWS_SPECIAL", "COMBINED_DISPLAY_MODE") as $param) {
976
+	foreach (array("ON_CATCHUP_SHOW_NEXT_FEED", "HIDE_READ_FEEDS",
977
+				 "ENABLE_FEED_CATS", "FEEDS_SORT_BY_UNREAD", "CONFIRM_FEED_CATCHUP",
978
+				 "CDM_AUTO_CATCHUP", "FRESH_ARTICLE_MAX_AGE",
979
+				 "HIDE_READ_SHOWS_SPECIAL", "COMBINED_DISPLAY_MODE") as $param) {
980 980
 
981
-        $params[strtolower($param)] = (int) get_pref($param);
982
-    }
981
+		$params[strtolower($param)] = (int) get_pref($param);
982
+	}
983 983
 
984
-    $params["check_for_updates"] = CHECK_FOR_UPDATES;
985
-    $params["icons_url"] = ICONS_URL;
986
-    $params["cookie_lifetime"] = SESSION_COOKIE_LIFETIME;
987
-    $params["default_view_mode"] = get_pref("_DEFAULT_VIEW_MODE");
988
-    $params["default_view_limit"] = (int) get_pref("_DEFAULT_VIEW_LIMIT");
989
-    $params["default_view_order_by"] = get_pref("_DEFAULT_VIEW_ORDER_BY");
990
-    $params["bw_limit"] = (int) $_SESSION["bw_limit"];
991
-    $params["is_default_pw"] = Pref_Prefs::isdefaultpassword();
992
-    $params["label_base_index"] = (int) LABEL_BASE_INDEX;
984
+	$params["check_for_updates"] = CHECK_FOR_UPDATES;
985
+	$params["icons_url"] = ICONS_URL;
986
+	$params["cookie_lifetime"] = SESSION_COOKIE_LIFETIME;
987
+	$params["default_view_mode"] = get_pref("_DEFAULT_VIEW_MODE");
988
+	$params["default_view_limit"] = (int) get_pref("_DEFAULT_VIEW_LIMIT");
989
+	$params["default_view_order_by"] = get_pref("_DEFAULT_VIEW_ORDER_BY");
990
+	$params["bw_limit"] = (int) $_SESSION["bw_limit"];
991
+	$params["is_default_pw"] = Pref_Prefs::isdefaultpassword();
992
+	$params["label_base_index"] = (int) LABEL_BASE_INDEX;
993 993
 
994
-    $theme = get_pref( "USER_CSS_THEME", false, false);
995
-    $params["theme"] = theme_exists($theme) ? $theme : "";
994
+	$theme = get_pref( "USER_CSS_THEME", false, false);
995
+	$params["theme"] = theme_exists($theme) ? $theme : "";
996 996
 
997
-    $params["plugins"] = implode(", ", PluginHost::getInstance()->get_plugin_names());
997
+	$params["plugins"] = implode(", ", PluginHost::getInstance()->get_plugin_names());
998 998
 
999
-    $params["php_platform"] = PHP_OS;
1000
-    $params["php_version"] = PHP_VERSION;
999
+	$params["php_platform"] = PHP_OS;
1000
+	$params["php_version"] = PHP_VERSION;
1001 1001
 
1002
-    $params["sanity_checksum"] = sha1(file_get_contents("include/sanity_check.php"));
1002
+	$params["sanity_checksum"] = sha1(file_get_contents("include/sanity_check.php"));
1003 1003
 
1004
-    $pdo = Db::pdo();
1004
+	$pdo = Db::pdo();
1005 1005
 
1006
-    $sth = $pdo->prepare("SELECT MAX(id) AS mid, COUNT(*) AS nf FROM ttrss_feeds WHERE owner_uid = ?");
1007
-    $sth->execute([$_SESSION['uid']]);
1008
-    $row = $sth->fetch();
1006
+	$sth = $pdo->prepare("SELECT MAX(id) AS mid, COUNT(*) AS nf FROM ttrss_feeds WHERE owner_uid = ?");
1007
+	$sth->execute([$_SESSION['uid']]);
1008
+	$row = $sth->fetch();
1009 1009
 
1010
-    $max_feed_id = $row["mid"];
1011
-    $num_feeds = $row["nf"];
1010
+	$max_feed_id = $row["mid"];
1011
+	$num_feeds = $row["nf"];
1012 1012
 
1013
-    $params["max_feed_id"] = (int) $max_feed_id;
1014
-    $params["num_feeds"] = (int) $num_feeds;
1013
+	$params["max_feed_id"] = (int) $max_feed_id;
1014
+	$params["num_feeds"] = (int) $num_feeds;
1015 1015
 
1016
-    $params["hotkeys"] = get_hotkeys_map();
1016
+	$params["hotkeys"] = get_hotkeys_map();
1017 1017
 
1018
-    $params["csrf_token"] = $_SESSION["csrf_token"];
1019
-    $params["widescreen"] = (int) $_COOKIE["ttrss_widescreen"];
1018
+	$params["csrf_token"] = $_SESSION["csrf_token"];
1019
+	$params["widescreen"] = (int) $_COOKIE["ttrss_widescreen"];
1020 1020
 
1021
-    $params['simple_update'] = defined('SIMPLE_UPDATE_MODE') && SIMPLE_UPDATE_MODE;
1021
+	$params['simple_update'] = defined('SIMPLE_UPDATE_MODE') && SIMPLE_UPDATE_MODE;
1022 1022
 
1023
-    $params["icon_indicator_white"] = base64_img("images/indicator_white.gif");
1023
+	$params["icon_indicator_white"] = base64_img("images/indicator_white.gif");
1024 1024
 
1025
-    $params["labels"] = Labels::get_all_labels($_SESSION["uid"]);
1025
+	$params["labels"] = Labels::get_all_labels($_SESSION["uid"]);
1026 1026
 
1027
-    return $params;
1027
+	return $params;
1028 1028
 }
1029 1029
 
1030 1030
 function get_hotkeys_info() {
1031
-    $hotkeys = array(
1032
-        __("Navigation") => array(
1033
-            "next_feed" => __("Open next feed"),
1034
-            "prev_feed" => __("Open previous feed"),
1035
-            "next_article_or_scroll" => __("Open next article (in combined mode, scroll down)"),
1036
-            "prev_article_or_scroll" => __("Open previous article (in combined mode, scroll up)"),
1037
-            "next_article_page" => __("Scroll article by one page down"),
1038
-            "prev_article_page" => __("Scroll article by one page up"),
1039
-            "next_article_noscroll" => __("Open next article"),
1040
-            "prev_article_noscroll" => __("Open previous article"),
1041
-            "next_article_noexpand" => __("Move to next article (don't expand or mark read)"),
1042
-            "prev_article_noexpand" => __("Move to previous article (don't expand or mark read)"),
1043
-            "search_dialog" => __("Show search dialog")),
1044
-        __("Article") => array(
1045
-            "toggle_mark" => __("Toggle starred"),
1046
-            "toggle_publ" => __("Toggle published"),
1047
-            "toggle_unread" => __("Toggle unread"),
1048
-            "edit_tags" => __("Edit tags"),
1049
-            "open_in_new_window" => __("Open in new window"),
1050
-            "catchup_below" => __("Mark below as read"),
1051
-            "catchup_above" => __("Mark above as read"),
1052
-            "article_scroll_down" => __("Scroll down"),
1053
-            "article_scroll_up" => __("Scroll up"),
1054
-            "article_page_down" => __("Scroll down page"),
1055
-            "article_page_up" => __("Scroll up page"),
1056
-            "select_article_cursor" => __("Select article under cursor"),
1057
-            "email_article" => __("Email article"),
1058
-            "close_article" => __("Close/collapse article"),
1059
-            "toggle_expand" => __("Toggle article expansion (combined mode)"),
1060
-            "toggle_widescreen" => __("Toggle widescreen mode"),
1061
-            "toggle_embed_original" => __("Toggle embed original")),
1062
-        __("Article selection") => array(
1063
-            "select_all" => __("Select all articles"),
1064
-            "select_unread" => __("Select unread"),
1065
-            "select_marked" => __("Select starred"),
1066
-            "select_published" => __("Select published"),
1067
-            "select_invert" => __("Invert selection"),
1068
-            "select_none" => __("Deselect everything")),
1069
-        __("Feed") => array(
1070
-            "feed_refresh" => __("Refresh current feed"),
1071
-            "feed_unhide_read" => __("Un/hide read feeds"),
1072
-            "feed_subscribe" => __("Subscribe to feed"),
1073
-            "feed_edit" => __("Edit feed"),
1074
-            "feed_catchup" => __("Mark as read"),
1075
-            "feed_reverse" => __("Reverse headlines"),
1076
-            "feed_toggle_vgroup" => __("Toggle headline grouping"),
1077
-            "feed_debug_update" => __("Debug feed update"),
1078
-            "feed_debug_viewfeed" => __("Debug viewfeed()"),
1079
-            "catchup_all" => __("Mark all feeds as read"),
1080
-            "cat_toggle_collapse" => __("Un/collapse current category"),
1081
-            "toggle_cdm_expanded" => __("Toggle auto expand in combined mode"),
1082
-            "toggle_combined_mode" => __("Toggle combined mode")),
1083
-        __("Go to") => array(
1084
-            "goto_all" => __("All articles"),
1085
-            "goto_fresh" => __("Fresh"),
1086
-            "goto_marked" => __("Starred"),
1087
-            "goto_published" => __("Published"),
1088
-            "goto_read" => __("Recently read"),
1089
-            "goto_tagcloud" => __("Tag cloud"),
1090
-            "goto_prefs" => __("Preferences")),
1091
-        __("Other") => array(
1092
-            "create_label" => __("Create label"),
1093
-            "create_filter" => __("Create filter"),
1094
-            "collapse_sidebar" => __("Un/collapse sidebar"),
1095
-            "help_dialog" => __("Show help dialog"))
1096
-    );
1097
-
1098
-    foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HOTKEY_INFO) as $plugin) {
1099
-        $hotkeys = $plugin->hook_hotkey_info($hotkeys);
1100
-    }
1101
-
1102
-    return $hotkeys;
1031
+	$hotkeys = array(
1032
+		__("Navigation") => array(
1033
+			"next_feed" => __("Open next feed"),
1034
+			"prev_feed" => __("Open previous feed"),
1035
+			"next_article_or_scroll" => __("Open next article (in combined mode, scroll down)"),
1036
+			"prev_article_or_scroll" => __("Open previous article (in combined mode, scroll up)"),
1037
+			"next_article_page" => __("Scroll article by one page down"),
1038
+			"prev_article_page" => __("Scroll article by one page up"),
1039
+			"next_article_noscroll" => __("Open next article"),
1040
+			"prev_article_noscroll" => __("Open previous article"),
1041
+			"next_article_noexpand" => __("Move to next article (don't expand or mark read)"),
1042
+			"prev_article_noexpand" => __("Move to previous article (don't expand or mark read)"),
1043
+			"search_dialog" => __("Show search dialog")),
1044
+		__("Article") => array(
1045
+			"toggle_mark" => __("Toggle starred"),
1046
+			"toggle_publ" => __("Toggle published"),
1047
+			"toggle_unread" => __("Toggle unread"),
1048
+			"edit_tags" => __("Edit tags"),
1049
+			"open_in_new_window" => __("Open in new window"),
1050
+			"catchup_below" => __("Mark below as read"),
1051
+			"catchup_above" => __("Mark above as read"),
1052
+			"article_scroll_down" => __("Scroll down"),
1053
+			"article_scroll_up" => __("Scroll up"),
1054
+			"article_page_down" => __("Scroll down page"),
1055
+			"article_page_up" => __("Scroll up page"),
1056
+			"select_article_cursor" => __("Select article under cursor"),
1057
+			"email_article" => __("Email article"),
1058
+			"close_article" => __("Close/collapse article"),
1059
+			"toggle_expand" => __("Toggle article expansion (combined mode)"),
1060
+			"toggle_widescreen" => __("Toggle widescreen mode"),
1061
+			"toggle_embed_original" => __("Toggle embed original")),
1062
+		__("Article selection") => array(
1063
+			"select_all" => __("Select all articles"),
1064
+			"select_unread" => __("Select unread"),
1065
+			"select_marked" => __("Select starred"),
1066
+			"select_published" => __("Select published"),
1067
+			"select_invert" => __("Invert selection"),
1068
+			"select_none" => __("Deselect everything")),
1069
+		__("Feed") => array(
1070
+			"feed_refresh" => __("Refresh current feed"),
1071
+			"feed_unhide_read" => __("Un/hide read feeds"),
1072
+			"feed_subscribe" => __("Subscribe to feed"),
1073
+			"feed_edit" => __("Edit feed"),
1074
+			"feed_catchup" => __("Mark as read"),
1075
+			"feed_reverse" => __("Reverse headlines"),
1076
+			"feed_toggle_vgroup" => __("Toggle headline grouping"),
1077
+			"feed_debug_update" => __("Debug feed update"),
1078
+			"feed_debug_viewfeed" => __("Debug viewfeed()"),
1079
+			"catchup_all" => __("Mark all feeds as read"),
1080
+			"cat_toggle_collapse" => __("Un/collapse current category"),
1081
+			"toggle_cdm_expanded" => __("Toggle auto expand in combined mode"),
1082
+			"toggle_combined_mode" => __("Toggle combined mode")),
1083
+		__("Go to") => array(
1084
+			"goto_all" => __("All articles"),
1085
+			"goto_fresh" => __("Fresh"),
1086
+			"goto_marked" => __("Starred"),
1087
+			"goto_published" => __("Published"),
1088
+			"goto_read" => __("Recently read"),
1089
+			"goto_tagcloud" => __("Tag cloud"),
1090
+			"goto_prefs" => __("Preferences")),
1091
+		__("Other") => array(
1092
+			"create_label" => __("Create label"),
1093
+			"create_filter" => __("Create filter"),
1094
+			"collapse_sidebar" => __("Un/collapse sidebar"),
1095
+			"help_dialog" => __("Show help dialog"))
1096
+	);
1097
+
1098
+	foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HOTKEY_INFO) as $plugin) {
1099
+		$hotkeys = $plugin->hook_hotkey_info($hotkeys);
1100
+	}
1101
+
1102
+	return $hotkeys;
1103 1103
 }
1104 1104
 
1105 1105
 function get_hotkeys_map() {
1106
-    $hotkeys = array(
1107
-        "k" => "next_feed",
1108
-        "j" => "prev_feed",
1109
-        "n" => "next_article_noscroll",
1110
-        "p" => "prev_article_noscroll",
1111
-        //"(33)|PageUp" => "prev_article_page",
1112
-        //"(34)|PageDown" => "next_article_page",
1113
-        "*(33)|Shift+PgUp" => "article_page_up",
1114
-        "*(34)|Shift+PgDn" => "article_page_down",
1115
-        "(38)|Up" => "prev_article_or_scroll",
1116
-        "(40)|Down" => "next_article_or_scroll",
1117
-        "*(38)|Shift+Up" => "article_scroll_up",
1118
-        "*(40)|Shift+Down" => "article_scroll_down",
1119
-        "^(38)|Ctrl+Up" => "prev_article_noscroll",
1120
-        "^(40)|Ctrl+Down" => "next_article_noscroll",
1121
-        "/" => "search_dialog",
1122
-        "s" => "toggle_mark",
1123
-        "S" => "toggle_publ",
1124
-        "u" => "toggle_unread",
1125
-        "T" => "edit_tags",
1126
-        "o" => "open_in_new_window",
1127
-        "c p" => "catchup_below",
1128
-        "c n" => "catchup_above",
1129
-        "N" => "article_scroll_down",
1130
-        "P" => "article_scroll_up",
1131
-        "a W" => "toggle_widescreen",
1132
-        "a e" => "toggle_embed_original",
1133
-        "e" => "email_article",
1134
-        "a q" => "close_article",
1135
-        "a a" => "select_all",
1136
-        "a u" => "select_unread",
1137
-        "a U" => "select_marked",
1138
-        "a p" => "select_published",
1139
-        "a i" => "select_invert",
1140
-        "a n" => "select_none",
1141
-        "f r" => "feed_refresh",
1142
-        "f a" => "feed_unhide_read",
1143
-        "f s" => "feed_subscribe",
1144
-        "f e" => "feed_edit",
1145
-        "f q" => "feed_catchup",
1146
-        "f x" => "feed_reverse",
1147
-        "f g" => "feed_toggle_vgroup",
1148
-        "f D" => "feed_debug_update",
1149
-        "f G" => "feed_debug_viewfeed",
1150
-        "f C" => "toggle_combined_mode",
1151
-        "f c" => "toggle_cdm_expanded",
1152
-        "Q" => "catchup_all",
1153
-        "x" => "cat_toggle_collapse",
1154
-        "g a" => "goto_all",
1155
-        "g f" => "goto_fresh",
1156
-        "g s" => "goto_marked",
1157
-        "g p" => "goto_published",
1158
-        "g r" => "goto_read",
1159
-        "g t" => "goto_tagcloud",
1160
-        "g P" => "goto_prefs",
1161
-        "r" => "select_article_cursor",
1162
-        "c l" => "create_label",
1163
-        "c f" => "create_filter",
1164
-        "c s" => "collapse_sidebar",
1165
-        "?" => "help_dialog",
1166
-    );
1167
-
1168
-    foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HOTKEY_MAP) as $plugin) {
1169
-        $hotkeys = $plugin->hook_hotkey_map($hotkeys);
1170
-    }
1171
-
1172
-    $prefixes = array();
1173
-
1174
-    foreach (array_keys($hotkeys) as $hotkey) {
1175
-        $pair = explode(" ", $hotkey, 2);
1176
-
1177
-        if (count($pair) > 1 && !in_array($pair[0], $prefixes)) {
1178
-            array_push($prefixes, $pair[0]);
1179
-        }
1180
-    }
1181
-
1182
-    return array($prefixes, $hotkeys);
1106
+	$hotkeys = array(
1107
+		"k" => "next_feed",
1108
+		"j" => "prev_feed",
1109
+		"n" => "next_article_noscroll",
1110
+		"p" => "prev_article_noscroll",
1111
+		//"(33)|PageUp" => "prev_article_page",
1112
+		//"(34)|PageDown" => "next_article_page",
1113
+		"*(33)|Shift+PgUp" => "article_page_up",
1114
+		"*(34)|Shift+PgDn" => "article_page_down",
1115
+		"(38)|Up" => "prev_article_or_scroll",
1116
+		"(40)|Down" => "next_article_or_scroll",
1117
+		"*(38)|Shift+Up" => "article_scroll_up",
1118
+		"*(40)|Shift+Down" => "article_scroll_down",
1119
+		"^(38)|Ctrl+Up" => "prev_article_noscroll",
1120
+		"^(40)|Ctrl+Down" => "next_article_noscroll",
1121
+		"/" => "search_dialog",
1122
+		"s" => "toggle_mark",
1123
+		"S" => "toggle_publ",
1124
+		"u" => "toggle_unread",
1125
+		"T" => "edit_tags",
1126
+		"o" => "open_in_new_window",
1127
+		"c p" => "catchup_below",
1128
+		"c n" => "catchup_above",
1129
+		"N" => "article_scroll_down",
1130
+		"P" => "article_scroll_up",
1131
+		"a W" => "toggle_widescreen",
1132
+		"a e" => "toggle_embed_original",
1133
+		"e" => "email_article",
1134
+		"a q" => "close_article",
1135
+		"a a" => "select_all",
1136
+		"a u" => "select_unread",
1137
+		"a U" => "select_marked",
1138
+		"a p" => "select_published",
1139
+		"a i" => "select_invert",
1140
+		"a n" => "select_none",
1141
+		"f r" => "feed_refresh",
1142
+		"f a" => "feed_unhide_read",
1143
+		"f s" => "feed_subscribe",
1144
+		"f e" => "feed_edit",
1145
+		"f q" => "feed_catchup",
1146
+		"f x" => "feed_reverse",
1147
+		"f g" => "feed_toggle_vgroup",
1148
+		"f D" => "feed_debug_update",
1149
+		"f G" => "feed_debug_viewfeed",
1150
+		"f C" => "toggle_combined_mode",
1151
+		"f c" => "toggle_cdm_expanded",
1152
+		"Q" => "catchup_all",
1153
+		"x" => "cat_toggle_collapse",
1154
+		"g a" => "goto_all",
1155
+		"g f" => "goto_fresh",
1156
+		"g s" => "goto_marked",
1157
+		"g p" => "goto_published",
1158
+		"g r" => "goto_read",
1159
+		"g t" => "goto_tagcloud",
1160
+		"g P" => "goto_prefs",
1161
+		"r" => "select_article_cursor",
1162
+		"c l" => "create_label",
1163
+		"c f" => "create_filter",
1164
+		"c s" => "collapse_sidebar",
1165
+		"?" => "help_dialog",
1166
+	);
1167
+
1168
+	foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HOTKEY_MAP) as $plugin) {
1169
+		$hotkeys = $plugin->hook_hotkey_map($hotkeys);
1170
+	}
1171
+
1172
+	$prefixes = array();
1173
+
1174
+	foreach (array_keys($hotkeys) as $hotkey) {
1175
+		$pair = explode(" ", $hotkey, 2);
1176
+
1177
+		if (count($pair) > 1 && !in_array($pair[0], $prefixes)) {
1178
+			array_push($prefixes, $pair[0]);
1179
+		}
1180
+	}
1181
+
1182
+	return array($prefixes, $hotkeys);
1183 1183
 }
1184 1184
 
1185 1185
 function make_runtime_info() {
1186
-    $data = array();
1186
+	$data = array();
1187 1187
 
1188
-    $pdo = Db::pdo();
1188
+	$pdo = Db::pdo();
1189 1189
 
1190
-    $sth = $pdo->prepare("SELECT MAX(id) AS mid, COUNT(*) AS nf FROM
1190
+	$sth = $pdo->prepare("SELECT MAX(id) AS mid, COUNT(*) AS nf FROM
1191 1191
             ttrss_feeds WHERE owner_uid = ?");
1192
-    $sth->execute([$_SESSION['uid']]);
1193
-    $row = $sth->fetch();
1194
-
1195
-    $max_feed_id = $row['mid'];
1196
-    $num_feeds = $row['nf'];
1197
-
1198
-    $data["max_feed_id"] = (int) $max_feed_id;
1199
-    $data["num_feeds"] = (int) $num_feeds;
1200
-    $data['cdm_expanded'] = get_pref('CDM_EXPANDED');
1201
-    $data["labels"] = Labels::get_all_labels($_SESSION["uid"]);
1202
-
1203
-    if (LOG_DESTINATION == 'sql' && $_SESSION['access_level'] >= 10) {
1204
-        if (DB_TYPE == 'pgsql') {
1205
-            $log_interval = "created_at > NOW() - interval '1 hour'";
1206
-        } else {
1207
-            $log_interval = "created_at > DATE_SUB(NOW(), INTERVAL 1 HOUR)";
1208
-        }
1192
+	$sth->execute([$_SESSION['uid']]);
1193
+	$row = $sth->fetch();
1209 1194
 
1210
-        $sth = $pdo->prepare("SELECT COUNT(id) AS cid FROM ttrss_error_log WHERE $log_interval");
1211
-        $sth->execute();
1195
+	$max_feed_id = $row['mid'];
1196
+	$num_feeds = $row['nf'];
1212 1197
 
1213
-        if ($row = $sth->fetch()) {
1214
-            $data['recent_log_events'] = $row['cid'];
1215
-        }
1216
-    }
1198
+	$data["max_feed_id"] = (int) $max_feed_id;
1199
+	$data["num_feeds"] = (int) $num_feeds;
1200
+	$data['cdm_expanded'] = get_pref('CDM_EXPANDED');
1201
+	$data["labels"] = Labels::get_all_labels($_SESSION["uid"]);
1217 1202
 
1218
-    if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
1203
+	if (LOG_DESTINATION == 'sql' && $_SESSION['access_level'] >= 10) {
1204
+		if (DB_TYPE == 'pgsql') {
1205
+			$log_interval = "created_at > NOW() - interval '1 hour'";
1206
+		} else {
1207
+			$log_interval = "created_at > DATE_SUB(NOW(), INTERVAL 1 HOUR)";
1208
+		}
1219 1209
 
1220
-        $data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock");
1210
+		$sth = $pdo->prepare("SELECT COUNT(id) AS cid FROM ttrss_error_log WHERE $log_interval");
1211
+		$sth->execute();
1221 1212
 
1222
-        if (time() - $_SESSION["daemon_stamp_check"] > 30) {
1213
+		if ($row = $sth->fetch()) {
1214
+			$data['recent_log_events'] = $row['cid'];
1215
+		}
1216
+	}
1223 1217
 
1224
-            $stamp = (int) @file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
1218
+	if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
1225 1219
 
1226
-            if ($stamp) {
1227
-                $stamp_delta = time() - $stamp;
1220
+		$data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock");
1228 1221
 
1229
-                if ($stamp_delta > 1800) {
1230
-                    $stamp_check = 0;
1231
-                } else {
1232
-                    $stamp_check = 1;
1233
-                    $_SESSION["daemon_stamp_check"] = time();
1234
-                }
1222
+		if (time() - $_SESSION["daemon_stamp_check"] > 30) {
1235 1223
 
1236
-                $data['daemon_stamp_ok'] = $stamp_check;
1224
+			$stamp = (int) @file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
1237 1225
 
1238
-                $stamp_fmt = date("Y.m.d, G:i", $stamp);
1226
+			if ($stamp) {
1227
+				$stamp_delta = time() - $stamp;
1239 1228
 
1240
-                $data['daemon_stamp'] = $stamp_fmt;
1241
-            }
1242
-        }
1243
-    }
1229
+				if ($stamp_delta > 1800) {
1230
+					$stamp_check = 0;
1231
+				} else {
1232
+					$stamp_check = 1;
1233
+					$_SESSION["daemon_stamp_check"] = time();
1234
+				}
1235
+
1236
+				$data['daemon_stamp_ok'] = $stamp_check;
1244 1237
 
1245
-    return $data;
1238
+				$stamp_fmt = date("Y.m.d, G:i", $stamp);
1239
+
1240
+				$data['daemon_stamp'] = $stamp_fmt;
1241
+			}
1242
+		}
1243
+	}
1244
+
1245
+	return $data;
1246 1246
 }
1247 1247
 
1248 1248
 function iframe_whitelisted($entry) {
1249
-    @$src = parse_url($entry->getAttribute("src"), PHP_URL_HOST);
1249
+	@$src = parse_url($entry->getAttribute("src"), PHP_URL_HOST);
1250 1250
 
1251
-    if ($src) {
1252
-        foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_IFRAME_WHITELISTED) as $plugin) {
1253
-            if ($plugin->hook_iframe_whitelisted($src))
1254
-                return true;
1255
-        }
1256
-    }
1251
+	if ($src) {
1252
+		foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_IFRAME_WHITELISTED) as $plugin) {
1253
+			if ($plugin->hook_iframe_whitelisted($src))
1254
+				return true;
1255
+		}
1256
+	}
1257 1257
 
1258
-    return false;
1258
+	return false;
1259 1259
 }
1260 1260
 
1261 1261
 function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false, $highlight_words = false, $article_id = false) {
1262
-    if (!$owner) $owner = $_SESSION["uid"];
1262
+	if (!$owner) $owner = $_SESSION["uid"];
1263 1263
 
1264
-    $res = trim($str); if (!$res) return '';
1264
+	$res = trim($str); if (!$res) return '';
1265 1265
 
1266
-    $doc = new DOMDocument();
1267
-    $doc->loadHTML('<?xml encoding="UTF-8">' . $res);
1268
-    $xpath = new DOMXPath($doc);
1266
+	$doc = new DOMDocument();
1267
+	$doc->loadHTML('<?xml encoding="UTF-8">' . $res);
1268
+	$xpath = new DOMXPath($doc);
1269 1269
 
1270
-    $rewrite_base_url = $site_url ? $site_url : get_self_url_prefix();
1270
+	$rewrite_base_url = $site_url ? $site_url : get_self_url_prefix();
1271 1271
 
1272
-    $entries = $xpath->query('(//a[@href]|//img[@src]|//video/source[@src]|//audio/source[@src]|//picture/source[@src])');
1272
+	$entries = $xpath->query('(//a[@href]|//img[@src]|//video/source[@src]|//audio/source[@src]|//picture/source[@src])');
1273 1273
 
1274
-    foreach ($entries as $entry) {
1274
+	foreach ($entries as $entry) {
1275 1275
 
1276
-        if ($entry->hasAttribute('href')) {
1277
-            $entry->setAttribute('href',
1278
-                rewrite_relative_url($rewrite_base_url, $entry->getAttribute('href')));
1276
+		if ($entry->hasAttribute('href')) {
1277
+			$entry->setAttribute('href',
1278
+				rewrite_relative_url($rewrite_base_url, $entry->getAttribute('href')));
1279 1279
 
1280
-            $entry->setAttribute('rel', 'noopener noreferrer');
1281
-        }
1280
+			$entry->setAttribute('rel', 'noopener noreferrer');
1281
+		}
1282 1282
 
1283
-        if ($entry->hasAttribute('src')) {
1284
-            $src = rewrite_relative_url($rewrite_base_url, $entry->getAttribute('src'));
1285
-            $entry->setAttribute('src', $src);
1286
-        }
1283
+		if ($entry->hasAttribute('src')) {
1284
+			$src = rewrite_relative_url($rewrite_base_url, $entry->getAttribute('src'));
1285
+			$entry->setAttribute('src', $src);
1286
+		}
1287 1287
 
1288
-        if ($entry->nodeName == 'img') {
1289
-            $entry->setAttribute('referrerpolicy', 'no-referrer');
1288
+		if ($entry->nodeName == 'img') {
1289
+			$entry->setAttribute('referrerpolicy', 'no-referrer');
1290 1290
 
1291
-            $entry->removeAttribute('width');
1292
-            $entry->removeAttribute('height');
1291
+			$entry->removeAttribute('width');
1292
+			$entry->removeAttribute('height');
1293 1293
 
1294
-            if ($entry->hasAttribute('src')) {
1295
-                $is_https_url = parse_url($entry->getAttribute('src'), PHP_URL_SCHEME) === 'https';
1294
+			if ($entry->hasAttribute('src')) {
1295
+				$is_https_url = parse_url($entry->getAttribute('src'), PHP_URL_SCHEME) === 'https';
1296 1296
 
1297
-                if (is_prefix_https() && !$is_https_url) {
1297
+				if (is_prefix_https() && !$is_https_url) {
1298 1298
 
1299
-                    if ($entry->hasAttribute('srcset')) {
1300
-                        $entry->removeAttribute('srcset');
1301
-                    }
1299
+					if ($entry->hasAttribute('srcset')) {
1300
+						$entry->removeAttribute('srcset');
1301
+					}
1302 1302
 
1303
-                    if ($entry->hasAttribute('sizes')) {
1304
-                        $entry->removeAttribute('sizes');
1305
-                    }
1306
-                }
1307
-            }
1308
-        }
1303
+					if ($entry->hasAttribute('sizes')) {
1304
+						$entry->removeAttribute('sizes');
1305
+					}
1306
+				}
1307
+			}
1308
+		}
1309 1309
 
1310
-        if ($entry->hasAttribute('src') &&
1311
-                ($owner && get_pref("STRIP_IMAGES", $owner)) || $force_remove_images || $_SESSION["bw_limit"]) {
1310
+		if ($entry->hasAttribute('src') &&
1311
+				($owner && get_pref("STRIP_IMAGES", $owner)) || $force_remove_images || $_SESSION["bw_limit"]) {
1312 1312
 
1313
-            $p = $doc->createElement('p');
1313
+			$p = $doc->createElement('p');
1314 1314
 
1315
-            $a = $doc->createElement('a');
1316
-            $a->setAttribute('href', $entry->getAttribute('src'));
1315
+			$a = $doc->createElement('a');
1316
+			$a->setAttribute('href', $entry->getAttribute('src'));
1317 1317
 
1318
-            $a->appendChild(new DOMText($entry->getAttribute('src')));
1319
-            $a->setAttribute('target', '_blank');
1320
-            $a->setAttribute('rel', 'noopener noreferrer');
1318
+			$a->appendChild(new DOMText($entry->getAttribute('src')));
1319
+			$a->setAttribute('target', '_blank');
1320
+			$a->setAttribute('rel', 'noopener noreferrer');
1321 1321
 
1322
-            $p->appendChild($a);
1322
+			$p->appendChild($a);
1323 1323
 
1324
-            if ($entry->nodeName == 'source') {
1324
+			if ($entry->nodeName == 'source') {
1325 1325
 
1326
-                if ($entry->parentNode && $entry->parentNode->parentNode)
1327
-                    $entry->parentNode->parentNode->replaceChild($p, $entry->parentNode);
1326
+				if ($entry->parentNode && $entry->parentNode->parentNode)
1327
+					$entry->parentNode->parentNode->replaceChild($p, $entry->parentNode);
1328 1328
 
1329
-            } else if ($entry->nodeName == 'img') {
1329
+			} else if ($entry->nodeName == 'img') {
1330 1330
 
1331
-                if ($entry->parentNode)
1332
-                    $entry->parentNode->replaceChild($p, $entry);
1331
+				if ($entry->parentNode)
1332
+					$entry->parentNode->replaceChild($p, $entry);
1333 1333
 
1334
-            }
1335
-        }
1334
+			}
1335
+		}
1336 1336
 
1337
-        if (strtolower($entry->nodeName) == "a") {
1338
-            $entry->setAttribute("target", "_blank");
1339
-            $entry->setAttribute("rel", "noopener noreferrer");
1340
-        }
1341
-    }
1342
-
1343
-    $entries = $xpath->query('//iframe');
1344
-    foreach ($entries as $entry) {
1345
-        if (!iframe_whitelisted($entry)) {
1346
-            $entry->setAttribute('sandbox', 'allow-scripts');
1347
-        } else {
1348
-            if (is_prefix_https()) {
1349
-                $entry->setAttribute("src",
1350
-                    str_replace("http://", "https://",
1351
-                        $entry->getAttribute("src")));
1352
-            }
1353
-        }
1354
-    }
1355
-
1356
-    $allowed_elements = array('a', 'abbr', 'address', 'acronym', 'audio', 'article', 'aside',
1357
-        'b', 'bdi', 'bdo', 'big', 'blockquote', 'body', 'br',
1358
-        'caption', 'cite', 'center', 'code', 'col', 'colgroup',
1359
-        'data', 'dd', 'del', 'details', 'description', 'dfn', 'div', 'dl', 'font',
1360
-        'dt', 'em', 'footer', 'figure', 'figcaption',
1361
-        'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'html', 'i',
1362
-        'img', 'ins', 'kbd', 'li', 'main', 'mark', 'nav', 'noscript',
1363
-        'ol', 'p', 'picture', 'pre', 'q', 'ruby', 'rp', 'rt', 's', 'samp', 'section',
1364
-        'small', 'source', 'span', 'strike', 'strong', 'sub', 'summary',
1365
-        'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time',
1366
-        'tr', 'track', 'tt', 'u', 'ul', 'var', 'wbr', 'video', 'xml:namespace' );
1367
-
1368
-    if ($_SESSION['hasSandbox']) $allowed_elements[] = 'iframe';
1369
-
1370
-    $disallowed_attributes = array('id', 'style', 'class');
1371
-
1372
-    foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SANITIZE) as $plugin) {
1373
-        $retval = $plugin->hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id);
1374
-        if (is_array($retval)) {
1375
-            $doc = $retval[0];
1376
-            $allowed_elements = $retval[1];
1377
-            $disallowed_attributes = $retval[2];
1378
-        } else {
1379
-            $doc = $retval;
1380
-        }
1381
-    }
1337
+		if (strtolower($entry->nodeName) == "a") {
1338
+			$entry->setAttribute("target", "_blank");
1339
+			$entry->setAttribute("rel", "noopener noreferrer");
1340
+		}
1341
+	}
1382 1342
 
1383
-    $doc->removeChild($doc->firstChild); //remove doctype
1384
-    $doc = strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes);
1343
+	$entries = $xpath->query('//iframe');
1344
+	foreach ($entries as $entry) {
1345
+		if (!iframe_whitelisted($entry)) {
1346
+			$entry->setAttribute('sandbox', 'allow-scripts');
1347
+		} else {
1348
+			if (is_prefix_https()) {
1349
+				$entry->setAttribute("src",
1350
+					str_replace("http://", "https://",
1351
+						$entry->getAttribute("src")));
1352
+			}
1353
+		}
1354
+	}
1385 1355
 
1386
-    if ($highlight_words) {
1387
-        foreach ($highlight_words as $word) {
1356
+	$allowed_elements = array('a', 'abbr', 'address', 'acronym', 'audio', 'article', 'aside',
1357
+		'b', 'bdi', 'bdo', 'big', 'blockquote', 'body', 'br',
1358
+		'caption', 'cite', 'center', 'code', 'col', 'colgroup',
1359
+		'data', 'dd', 'del', 'details', 'description', 'dfn', 'div', 'dl', 'font',
1360
+		'dt', 'em', 'footer', 'figure', 'figcaption',
1361
+		'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'html', 'i',
1362
+		'img', 'ins', 'kbd', 'li', 'main', 'mark', 'nav', 'noscript',
1363
+		'ol', 'p', 'picture', 'pre', 'q', 'ruby', 'rp', 'rt', 's', 'samp', 'section',
1364
+		'small', 'source', 'span', 'strike', 'strong', 'sub', 'summary',
1365
+		'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time',
1366
+		'tr', 'track', 'tt', 'u', 'ul', 'var', 'wbr', 'video', 'xml:namespace' );
1388 1367
 
1389
-            // http://stackoverflow.com/questions/4081372/highlight-keywords-in-a-paragraph
1368
+	if ($_SESSION['hasSandbox']) $allowed_elements[] = 'iframe';
1390 1369
 
1391
-            $elements = $xpath->query("//*/text()");
1370
+	$disallowed_attributes = array('id', 'style', 'class');
1392 1371
 
1393
-            foreach ($elements as $child) {
1372
+	foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SANITIZE) as $plugin) {
1373
+		$retval = $plugin->hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id);
1374
+		if (is_array($retval)) {
1375
+			$doc = $retval[0];
1376
+			$allowed_elements = $retval[1];
1377
+			$disallowed_attributes = $retval[2];
1378
+		} else {
1379
+			$doc = $retval;
1380
+		}
1381
+	}
1394 1382
 
1395
-                $fragment = $doc->createDocumentFragment();
1396
-                $text = $child->textContent;
1383
+	$doc->removeChild($doc->firstChild); //remove doctype
1384
+	$doc = strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes);
1397 1385
 
1398
-                while (($pos = mb_stripos($text, $word)) !== false) {
1399
-                    $fragment->appendChild(new DomText(mb_substr($text, 0, $pos)));
1400
-                    $word = mb_substr($text, $pos, mb_strlen($word));
1401
-                    $highlight = $doc->createElement('span');
1402
-                    $highlight->appendChild(new DomText($word));
1403
-                    $highlight->setAttribute('class', 'highlight');
1404
-                    $fragment->appendChild($highlight);
1405
-                    $text = mb_substr($text, $pos + mb_strlen($word));
1406
-                }
1386
+	if ($highlight_words) {
1387
+		foreach ($highlight_words as $word) {
1407 1388
 
1408
-                if (!empty($text)) $fragment->appendChild(new DomText($text));
1389
+			// http://stackoverflow.com/questions/4081372/highlight-keywords-in-a-paragraph
1409 1390
 
1410
-                $child->parentNode->replaceChild($fragment, $child);
1411
-            }
1412
-        }
1413
-    }
1391
+			$elements = $xpath->query("//*/text()");
1392
+
1393
+			foreach ($elements as $child) {
1394
+
1395
+				$fragment = $doc->createDocumentFragment();
1396
+				$text = $child->textContent;
1414 1397
 
1415
-    $res = $doc->saveHTML();
1398
+				while (($pos = mb_stripos($text, $word)) !== false) {
1399
+					$fragment->appendChild(new DomText(mb_substr($text, 0, $pos)));
1400
+					$word = mb_substr($text, $pos, mb_strlen($word));
1401
+					$highlight = $doc->createElement('span');
1402
+					$highlight->appendChild(new DomText($word));
1403
+					$highlight->setAttribute('class', 'highlight');
1404
+					$fragment->appendChild($highlight);
1405
+					$text = mb_substr($text, $pos + mb_strlen($word));
1406
+				}
1416 1407
 
1417
-    /* strip everything outside of <body>...</body> */
1408
+				if (!empty($text)) $fragment->appendChild(new DomText($text));
1418 1409
 
1419
-    $res_frag = array();
1420
-    if (preg_match('/<body>(.*)<\/body>/is', $res, $res_frag)) {
1421
-        return $res_frag[1];
1422
-    } else {
1423
-        return $res;
1424
-    }
1410
+				$child->parentNode->replaceChild($fragment, $child);
1411
+			}
1412
+		}
1413
+	}
1414
+
1415
+	$res = $doc->saveHTML();
1416
+
1417
+	/* strip everything outside of <body>...</body> */
1418
+
1419
+	$res_frag = array();
1420
+	if (preg_match('/<body>(.*)<\/body>/is', $res, $res_frag)) {
1421
+		return $res_frag[1];
1422
+	} else {
1423
+		return $res;
1424
+	}
1425 1425
 }
1426 1426
 
1427 1427
 function strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes) {
1428
-    $xpath = new DOMXPath($doc);
1429
-    $entries = $xpath->query('//*');
1428
+	$xpath = new DOMXPath($doc);
1429
+	$entries = $xpath->query('//*');
1430 1430
 
1431
-    foreach ($entries as $entry) {
1432
-        if (!in_array($entry->nodeName, $allowed_elements)) {
1433
-            $entry->parentNode->removeChild($entry);
1434
-        }
1431
+	foreach ($entries as $entry) {
1432
+		if (!in_array($entry->nodeName, $allowed_elements)) {
1433
+			$entry->parentNode->removeChild($entry);
1434
+		}
1435 1435
 
1436
-        if ($entry->hasAttributes()) {
1437
-            $attrs_to_remove = array();
1436
+		if ($entry->hasAttributes()) {
1437
+			$attrs_to_remove = array();
1438 1438
 
1439
-            foreach ($entry->attributes as $attr) {
1439
+			foreach ($entry->attributes as $attr) {
1440 1440
 
1441
-                if (strpos($attr->nodeName, 'on') === 0) {
1442
-                    array_push($attrs_to_remove, $attr);
1443
-                }
1441
+				if (strpos($attr->nodeName, 'on') === 0) {
1442
+					array_push($attrs_to_remove, $attr);
1443
+				}
1444 1444
 
1445
-                if (strpos($attr->nodeName, "data-") === 0) {
1446
-                    array_push($attrs_to_remove, $attr);
1447
-                }
1445
+				if (strpos($attr->nodeName, "data-") === 0) {
1446
+					array_push($attrs_to_remove, $attr);
1447
+				}
1448 1448
 
1449
-                if ($attr->nodeName == 'href' && stripos($attr->value, 'javascript:') === 0) {
1450
-                    array_push($attrs_to_remove, $attr);
1451
-                }
1449
+				if ($attr->nodeName == 'href' && stripos($attr->value, 'javascript:') === 0) {
1450
+					array_push($attrs_to_remove, $attr);
1451
+				}
1452 1452
 
1453
-                if (in_array($attr->nodeName, $disallowed_attributes)) {
1454
-                    array_push($attrs_to_remove, $attr);
1455
-                }
1456
-            }
1453
+				if (in_array($attr->nodeName, $disallowed_attributes)) {
1454
+					array_push($attrs_to_remove, $attr);
1455
+				}
1456
+			}
1457 1457
 
1458
-            foreach ($attrs_to_remove as $attr) {
1459
-                $entry->removeAttributeNode($attr);
1460
-            }
1461
-        }
1462
-    }
1458
+			foreach ($attrs_to_remove as $attr) {
1459
+				$entry->removeAttributeNode($attr);
1460
+			}
1461
+		}
1462
+	}
1463 1463
 
1464
-    return $doc;
1464
+	return $doc;
1465 1465
 }
1466 1466
 
1467 1467
 function trim_array($array) {
1468
-    $tmp = $array;
1469
-    array_walk($tmp, 'trim');
1470
-    return $tmp;
1468
+	$tmp = $array;
1469
+	array_walk($tmp, 'trim');
1470
+	return $tmp;
1471 1471
 }
1472 1472
 
1473 1473
 function render_login_form() {
1474
-    header('Cache-Control: public');
1474
+	header('Cache-Control: public');
1475 1475
 
1476
-    require_once "login_form.php";
1477
-    exit;
1476
+	require_once "login_form.php";
1477
+	exit;
1478 1478
 }
1479 1479
 
1480 1480
 function T_sprintf() {
1481
-    $args = func_get_args();
1482
-    return vsprintf(__(array_shift($args)), $args);
1481
+	$args = func_get_args();
1482
+	return vsprintf(__(array_shift($args)), $args);
1483 1483
 }
1484 1484
 
1485 1485
 function print_checkpoint($n, $s) {
1486
-    $ts = microtime(true);
1487
-    echo sprintf("<!-- CP[$n] %.4f seconds -->\n", $ts - $s);
1488
-    return $ts;
1486
+	$ts = microtime(true);
1487
+	echo sprintf("<!-- CP[$n] %.4f seconds -->\n", $ts - $s);
1488
+	return $ts;
1489 1489
 }
1490 1490
 
1491 1491
 function is_server_https() {
1492
-    return (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')) || $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
1492
+	return (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')) || $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
1493 1493
 }
1494 1494
 
1495 1495
 function is_prefix_https() {
1496
-    return parse_url(SELF_URL_PATH, PHP_URL_SCHEME) == 'https';
1496
+	return parse_url(SELF_URL_PATH, PHP_URL_SCHEME) == 'https';
1497 1497
 }
1498 1498
 
1499 1499
 // this returns SELF_URL_PATH sans ending slash
1500 1500
 function get_self_url_prefix() {
1501
-    if (strrpos(SELF_URL_PATH, "/") === strlen(SELF_URL_PATH)-1) {
1502
-        return substr(SELF_URL_PATH, 0, strlen(SELF_URL_PATH)-1);
1503
-    } else {
1504
-        return SELF_URL_PATH;
1505
-    }
1501
+	if (strrpos(SELF_URL_PATH, "/") === strlen(SELF_URL_PATH)-1) {
1502
+		return substr(SELF_URL_PATH, 0, strlen(SELF_URL_PATH)-1);
1503
+	} else {
1504
+		return SELF_URL_PATH;
1505
+	}
1506 1506
 }
1507 1507
 
1508 1508
 /* TODO: This needs to use bcrypt */
1509 1509
 function encrypt_password($pass, $salt = '', $mode2 = false) {
1510
-    if ($salt && $mode2) {
1511
-        return "MODE2:" . hash('sha256', $salt . $pass);
1512
-    } else if ($salt) {
1513
-        return "SHA1X:" . sha1("$salt:$pass");
1514
-    } else {
1515
-        return "SHA1:" . sha1($pass);
1516
-    }
1510
+	if ($salt && $mode2) {
1511
+		return "MODE2:" . hash('sha256', $salt . $pass);
1512
+	} else if ($salt) {
1513
+		return "SHA1X:" . sha1("$salt:$pass");
1514
+	} else {
1515
+		return "SHA1:" . sha1($pass);
1516
+	}
1517 1517
 }
1518 1518
 
1519 1519
 function init_plugins() {
1520
-    PluginHost::getInstance()->load(PLUGINS, PluginHost::KIND_ALL);
1520
+	PluginHost::getInstance()->load(PLUGINS, PluginHost::KIND_ALL);
1521 1521
 
1522
-    return true;
1522
+	return true;
1523 1523
 }
1524 1524
 
1525 1525
 function build_url($parts) {
1526
-    return $parts['scheme'] . "://" . $parts['host'] . $parts['path'];
1526
+	return $parts['scheme'] . "://" . $parts['host'] . $parts['path'];
1527 1527
 }
1528 1528
 
1529 1529
 function cleanup_url_path($path) {
1530
-    $path = str_replace("/./", "/", $path);
1531
-    $path = str_replace("//", "/", $path);
1530
+	$path = str_replace("/./", "/", $path);
1531
+	$path = str_replace("//", "/", $path);
1532 1532
 
1533
-    return $path;
1533
+	return $path;
1534 1534
 }
1535 1535
 
1536 1536
 /**
@@ -1542,98 +1542,98 @@  discard block
 block discarded – undo
1542 1542
  * @return string Absolute URL
1543 1543
  */
1544 1544
 function rewrite_relative_url($url, $rel_url) {
1545
-    if (strpos($rel_url, "://") !== false) {
1546
-        return $rel_url;
1547
-    } else if (strpos($rel_url, "//") === 0) {
1548
-        # protocol-relative URL (rare but they exist)
1549
-        return $rel_url;
1550
-    } else if (preg_match("/^[a-z]+:/i", $rel_url)) {
1551
-        # magnet:, feed:, etc
1552
-        return $rel_url;
1553
-    } else if (strpos($rel_url, "/") === 0) {
1554
-        $parts = parse_url($url);
1555
-        $parts['path'] = $rel_url;
1556
-        $parts['path'] = cleanup_url_path($parts['path']);
1557
-
1558
-        return build_url($parts);
1559
-
1560
-    } else {
1561
-        $parts = parse_url($url);
1562
-        if (!isset($parts['path'])) {
1563
-            $parts['path'] = '/';
1564
-        }
1565
-        $dir = $parts['path'];
1566
-        if (substr($dir, -1) !== '/') {
1567
-            $dir = dirname($parts['path']);
1568
-            $dir !== '/' && $dir .= '/';
1569
-        }
1570
-        $parts['path'] = $dir . $rel_url;
1571
-        $parts['path'] = cleanup_url_path($parts['path']);
1572
-
1573
-        return build_url($parts);
1574
-    }
1545
+	if (strpos($rel_url, "://") !== false) {
1546
+		return $rel_url;
1547
+	} else if (strpos($rel_url, "//") === 0) {
1548
+		# protocol-relative URL (rare but they exist)
1549
+		return $rel_url;
1550
+	} else if (preg_match("/^[a-z]+:/i", $rel_url)) {
1551
+		# magnet:, feed:, etc
1552
+		return $rel_url;
1553
+	} else if (strpos($rel_url, "/") === 0) {
1554
+		$parts = parse_url($url);
1555
+		$parts['path'] = $rel_url;
1556
+		$parts['path'] = cleanup_url_path($parts['path']);
1557
+
1558
+		return build_url($parts);
1559
+
1560
+	} else {
1561
+		$parts = parse_url($url);
1562
+		if (!isset($parts['path'])) {
1563
+			$parts['path'] = '/';
1564
+		}
1565
+		$dir = $parts['path'];
1566
+		if (substr($dir, -1) !== '/') {
1567
+			$dir = dirname($parts['path']);
1568
+			$dir !== '/' && $dir .= '/';
1569
+		}
1570
+		$parts['path'] = $dir . $rel_url;
1571
+		$parts['path'] = cleanup_url_path($parts['path']);
1572
+
1573
+		return build_url($parts);
1574
+	}
1575 1575
 }
1576 1576
 
1577 1577
 function print_user_stylesheet() {
1578
-    $value = get_pref('USER_STYLESHEET');
1578
+	$value = get_pref('USER_STYLESHEET');
1579 1579
 
1580
-    if ($value) {
1581
-        print "<style type='text/css' id='user_css_style'>";
1582
-        print str_replace("<br/>", "\n", $value);
1583
-        print "</style>";
1584
-    }
1580
+	if ($value) {
1581
+		print "<style type='text/css' id='user_css_style'>";
1582
+		print str_replace("<br/>", "\n", $value);
1583
+		print "</style>";
1584
+	}
1585 1585
 }
1586 1586
 
1587 1587
 if (!function_exists('gzdecode')) {
1588
-    function gzdecode($string) {
1589
-        return file_get_contents('compress.zlib://data:who/cares;base64,'.base64_encode($string));
1590
-    }
1588
+	function gzdecode($string) {
1589
+		return file_get_contents('compress.zlib://data:who/cares;base64,'.base64_encode($string));
1590
+	}
1591 1591
 }
1592 1592
 
1593 1593
 function get_random_bytes($length) {
1594
-    if (function_exists('openssl_random_pseudo_bytes')) {
1595
-        return openssl_random_pseudo_bytes($length);
1596
-    } else {
1597
-        $output = "";
1594
+	if (function_exists('openssl_random_pseudo_bytes')) {
1595
+		return openssl_random_pseudo_bytes($length);
1596
+	} else {
1597
+		$output = "";
1598 1598
 
1599
-        for ($i = 0; $i < $length; $i++)
1600
-            $output .= chr(mt_rand(0, 255));
1599
+		for ($i = 0; $i < $length; $i++)
1600
+			$output .= chr(mt_rand(0, 255));
1601 1601
 
1602
-        return $output;
1603
-    }
1602
+		return $output;
1603
+	}
1604 1604
 }
1605 1605
 
1606 1606
 function read_stdin() {
1607
-    $fp = fopen("php://stdin", "r");
1607
+	$fp = fopen("php://stdin", "r");
1608 1608
 
1609
-    if ($fp) {
1610
-        $line = trim(fgets($fp));
1611
-        fclose($fp);
1612
-        return $line;
1613
-    }
1609
+	if ($fp) {
1610
+		$line = trim(fgets($fp));
1611
+		fclose($fp);
1612
+		return $line;
1613
+	}
1614 1614
 
1615
-    return null;
1615
+	return null;
1616 1616
 }
1617 1617
 
1618 1618
 function implements_interface($class, $interface) {
1619
-    return in_array($interface, class_implements($class));
1619
+	return in_array($interface, class_implements($class));
1620 1620
 }
1621 1621
 
1622 1622
 function T_js_decl($s1, $s2) {
1623
-    if ($s1 && $s2) {
1624
-        $s1 = preg_replace("/\n/", "", $s1);
1625
-        $s2 = preg_replace("/\n/", "", $s2);
1623
+	if ($s1 && $s2) {
1624
+		$s1 = preg_replace("/\n/", "", $s1);
1625
+		$s2 = preg_replace("/\n/", "", $s2);
1626 1626
 
1627
-        $s1 = preg_replace("/\"/", "\\\"", $s1);
1628
-        $s2 = preg_replace("/\"/", "\\\"", $s2);
1627
+		$s1 = preg_replace("/\"/", "\\\"", $s1);
1628
+		$s2 = preg_replace("/\"/", "\\\"", $s2);
1629 1629
 
1630
-        return "T_messages[\"$s1\"] = \"$s2\";\n";
1631
-    }
1630
+		return "T_messages[\"$s1\"] = \"$s2\";\n";
1631
+	}
1632 1632
 }
1633 1633
 
1634 1634
 function init_js_translations() {
1635 1635
 
1636
-    print 'var T_messages = new Object();
1636
+	print 'var T_messages = new Object();
1637 1637
 
1638 1638
         public function __(msg) {
1639 1639
             if (T_messages[msg]) {
@@ -1647,78 +1647,78 @@  discard block
 block discarded – undo
1647 1647
             return __((parseInt(n) > 1) ? msg2 : msg1);
1648 1648
         }';
1649 1649
 
1650
-    global $text_domains;
1650
+	global $text_domains;
1651 1651
 
1652
-    foreach (array_keys($text_domains) as $domain) {
1653
-        $l10n = _get_reader($domain);
1652
+	foreach (array_keys($text_domains) as $domain) {
1653
+		$l10n = _get_reader($domain);
1654 1654
 
1655
-        for ($i = 0; $i < $l10n->total; $i++) {
1656
-            $orig = $l10n->get_original_string($i);
1657
-            if(strpos($orig, "\000") !== FALSE) { // Plural forms
1658
-                $key = explode(chr(0), $orig);
1659
-                print T_js_decl($key[0], _ngettext($key[0], $key[1], 1)); // Singular
1660
-                print T_js_decl($key[1], _ngettext($key[0], $key[1], 2)); // Plural
1661
-            } else {
1662
-                $translation = _dgettext($domain,$orig);
1663
-                print T_js_decl($orig, $translation);
1664
-            }
1665
-        }
1666
-    }
1655
+		for ($i = 0; $i < $l10n->total; $i++) {
1656
+			$orig = $l10n->get_original_string($i);
1657
+			if(strpos($orig, "\000") !== FALSE) { // Plural forms
1658
+				$key = explode(chr(0), $orig);
1659
+				print T_js_decl($key[0], _ngettext($key[0], $key[1], 1)); // Singular
1660
+				print T_js_decl($key[1], _ngettext($key[0], $key[1], 2)); // Plural
1661
+			} else {
1662
+				$translation = _dgettext($domain,$orig);
1663
+				print T_js_decl($orig, $translation);
1664
+			}
1665
+		}
1666
+	}
1667 1667
 }
1668 1668
 
1669 1669
 function get_theme_path($theme) {
1670
-    if ($theme == "default.php")
1671
-        return "css/default.css";
1670
+	if ($theme == "default.php")
1671
+		return "css/default.css";
1672 1672
 
1673
-    $check = "themes/$theme";
1674
-    if (file_exists($check)) return $check;
1673
+	$check = "themes/$theme";
1674
+	if (file_exists($check)) return $check;
1675 1675
 
1676
-    $check = "themes.local/$theme";
1677
-    if (file_exists($check)) return $check;
1676
+	$check = "themes.local/$theme";
1677
+	if (file_exists($check)) return $check;
1678 1678
 }
1679 1679
 
1680 1680
 function theme_exists($theme) {
1681
-    return file_exists("themes/$theme") || file_exists("themes.local/$theme");
1681
+	return file_exists("themes/$theme") || file_exists("themes.local/$theme");
1682 1682
 }
1683 1683
 
1684 1684
 function error_json($code) {
1685
-    require_once "errors.php";
1685
+	require_once "errors.php";
1686 1686
 
1687
-    @$message = $ERRORS[$code];
1687
+	@$message = $ERRORS[$code];
1688 1688
 
1689
-    return json_encode(
1690
-        array(
1691
-            "error" => array(
1692
-                "code" => $code,
1693
-                "message" => $message
1694
-            )
1695
-        )
1696
-    );
1689
+	return json_encode(
1690
+		array(
1691
+			"error" => array(
1692
+				"code" => $code,
1693
+				"message" => $message
1694
+			)
1695
+		)
1696
+	);
1697 1697
 }
1698 1698
 
1699 1699
 function get_upload_error_message($code) {
1700
-    $errors = array(
1701
-        0 => __('There is no error, the file uploaded with success'),
1702
-        1 => __('The uploaded file exceeds the upload_max_filesize directive in php.ini'),
1703
-        2 => __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'),
1704
-        3 => __('The uploaded file was only partially uploaded'),
1705
-        4 => __('No file was uploaded'),
1706
-        6 => __('Missing a temporary folder'),
1707
-        7 => __('Failed to write file to disk.'),
1708
-        8 => __('A PHP extension stopped the file upload.'),
1709
-    );
1700
+	$errors = array(
1701
+		0 => __('There is no error, the file uploaded with success'),
1702
+		1 => __('The uploaded file exceeds the upload_max_filesize directive in php.ini'),
1703
+		2 => __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'),
1704
+		3 => __('The uploaded file was only partially uploaded'),
1705
+		4 => __('No file was uploaded'),
1706
+		6 => __('Missing a temporary folder'),
1707
+		7 => __('Failed to write file to disk.'),
1708
+		8 => __('A PHP extension stopped the file upload.'),
1709
+	);
1710 1710
 
1711
-    return $errors[$code];
1711
+	return $errors[$code];
1712 1712
 }
1713 1713
 
1714 1714
 function base64_img($filename) {
1715
-    if (file_exists($filename)) {
1716
-        $ext = pathinfo($filename, PATHINFO_EXTENSION);
1715
+	if (file_exists($filename)) {
1716
+		$ext = pathinfo($filename, PATHINFO_EXTENSION);
1717 1717
 
1718
-        return "data:image/$ext;base64," . base64_encode(file_get_contents($filename));
1719
-    } else {
1720
-        return "";
1721
-    }
1718
+		return "data:image/$ext;base64," . base64_encode(file_get_contents($filename));
1719
+	} else {
1720
+		return "";
1721
+	}
1722 1722
 }
1723 1723
 
1724 1724
 /*	this is essentially a wrapper for readfile() which allows plugins to hook
@@ -1729,52 +1729,52 @@  discard block
 block discarded – undo
1729 1729
     note that this can be called without user context so the plugin to handle this
1730 1730
     should be loaded systemwide in config.php */
1731 1731
 function send_local_file($filename) {
1732
-    if (file_exists($filename)) {
1732
+	if (file_exists($filename)) {
1733 1733
 
1734
-        if (is_writable($filename)) touch($filename);
1734
+		if (is_writable($filename)) touch($filename);
1735 1735
 
1736
-        $tmppluginhost = new PluginHost();
1736
+		$tmppluginhost = new PluginHost();
1737 1737
 
1738
-        $tmppluginhost->load(PLUGINS, PluginHost::KIND_SYSTEM);
1739
-        $tmppluginhost->load_data();
1738
+		$tmppluginhost->load(PLUGINS, PluginHost::KIND_SYSTEM);
1739
+		$tmppluginhost->load_data();
1740 1740
 
1741
-        foreach ($tmppluginhost->get_hooks(PluginHost::HOOK_SEND_LOCAL_FILE) as $plugin) {
1742
-            if ($plugin->hook_send_local_file($filename)) return true;
1743
-        }
1741
+		foreach ($tmppluginhost->get_hooks(PluginHost::HOOK_SEND_LOCAL_FILE) as $plugin) {
1742
+			if ($plugin->hook_send_local_file($filename)) return true;
1743
+		}
1744 1744
 
1745
-        $mimetype = mime_content_type($filename);
1745
+		$mimetype = mime_content_type($filename);
1746 1746
 
1747
-        // this is hardly ideal but 1) only media is cached in images/ and 2) seemingly only mp4
1748
-        // video files are detected as octet-stream by mime_content_type()
1747
+		// this is hardly ideal but 1) only media is cached in images/ and 2) seemingly only mp4
1748
+		// video files are detected as octet-stream by mime_content_type()
1749 1749
 
1750
-        if ($mimetype == "application/octet-stream")
1751
-            $mimetype = "video/mp4";
1750
+		if ($mimetype == "application/octet-stream")
1751
+			$mimetype = "video/mp4";
1752 1752
 
1753
-        header("Content-type: $mimetype");
1753
+		header("Content-type: $mimetype");
1754 1754
 
1755
-        $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)) . " GMT";
1756
-        header("Last-Modified: $stamp", true);
1755
+		$stamp = gmdate("D, d M Y H:i:s", filemtime($filename)) . " GMT";
1756
+		header("Last-Modified: $stamp", true);
1757 1757
 
1758
-        return readfile($filename);
1759
-    } else {
1760
-        return false;
1761
-    }
1758
+		return readfile($filename);
1759
+	} else {
1760
+		return false;
1761
+	}
1762 1762
 }
1763 1763
 
1764 1764
 function arr_qmarks($arr) {
1765
-    return str_repeat('?,', count($arr) - 1) . '?';
1765
+	return str_repeat('?,', count($arr) - 1) . '?';
1766 1766
 }
1767 1767
 
1768 1768
 function get_scripts_timestamp() {
1769
-    $files = glob("js/*.js");
1770
-    $ts = 0;
1769
+	$files = glob("js/*.js");
1770
+	$ts = 0;
1771 1771
 
1772
-    foreach ($files as $file) {
1773
-        $file_ts = filemtime($file);
1774
-        if ($file_ts > $ts) $ts = $file_ts;
1775
-    }
1772
+	foreach ($files as $file) {
1773
+		$file_ts = filemtime($file);
1774
+		if ($file_ts > $ts) $ts = $file_ts;
1775
+	}
1776 1776
 
1777
-    return $ts;
1777
+	return $ts;
1778 1778
 }
1779 1779
 
1780 1780
 /* for package maintainers who don't use git: if version_static.txt exists in tt-rss root
@@ -1782,45 +1782,45 @@  discard block
 block discarded – undo
1782 1782
     based on source git tree commit used when creating the package */
1783 1783
 
1784 1784
 function get_version(&$git_commit = false, &$git_timestamp = false) {
1785
-    global $ttrss_version;
1785
+	global $ttrss_version;
1786 1786
 
1787
-    if (isset($ttrss_version))
1788
-        return $ttrss_version;
1787
+	if (isset($ttrss_version))
1788
+		return $ttrss_version;
1789 1789
 
1790
-    $ttrss_version = "UNKNOWN (Unsupported)";
1790
+	$ttrss_version = "UNKNOWN (Unsupported)";
1791 1791
 
1792
-    date_default_timezone_set('UTC');
1793
-    $root_dir = dirname(dirname(__FILE__));
1792
+	date_default_timezone_set('UTC');
1793
+	$root_dir = dirname(dirname(__FILE__));
1794 1794
 
1795
-    if ('\\' === DIRECTORY_SEPARATOR) {
1796
-        $ttrss_version = "UNKNOWN (Unsupported, Windows)";
1797
-    } else if (PHP_OS === "Darwin") {
1798
-        $ttrss_version = "UNKNOWN (Unsupported, Darwin)";
1799
-    } else if (file_exists("$root_dir/version_static.txt")) {
1800
-        $ttrss_version = trim(file_get_contents("$root_dir/version_static.txt")) . " (Unsupported)";
1801
-    } else if (is_dir("$root_dir/.git")) {
1802
-        $rc = 0;
1803
-        $output = [];
1795
+	if ('\\' === DIRECTORY_SEPARATOR) {
1796
+		$ttrss_version = "UNKNOWN (Unsupported, Windows)";
1797
+	} else if (PHP_OS === "Darwin") {
1798
+		$ttrss_version = "UNKNOWN (Unsupported, Darwin)";
1799
+	} else if (file_exists("$root_dir/version_static.txt")) {
1800
+		$ttrss_version = trim(file_get_contents("$root_dir/version_static.txt")) . " (Unsupported)";
1801
+	} else if (is_dir("$root_dir/.git")) {
1802
+		$rc = 0;
1803
+		$output = [];
1804 1804
 
1805
-        $cwd = getcwd();
1805
+		$cwd = getcwd();
1806 1806
 
1807
-        chdir($root_dir);
1808
-        exec('git log --pretty='.escapeshellarg('%ct %h').' -n1 HEAD 2>&1', $output, $rc);
1809
-        chdir($cwd);
1807
+		chdir($root_dir);
1808
+		exec('git log --pretty='.escapeshellarg('%ct %h').' -n1 HEAD 2>&1', $output, $rc);
1809
+		chdir($cwd);
1810 1810
 
1811
-        if ($rc == 0) {
1812
-            if (is_array($output) && count($output) > 0) {
1813
-                list ($timestamp, $commit) = explode(" ", $output[0], 2);
1811
+		if ($rc == 0) {
1812
+			if (is_array($output) && count($output) > 0) {
1813
+				list ($timestamp, $commit) = explode(" ", $output[0], 2);
1814 1814
 
1815
-                $git_commit = $commit;
1816
-                $git_timestamp = $timestamp;
1815
+				$git_commit = $commit;
1816
+				$git_timestamp = $timestamp;
1817 1817
 
1818
-                $ttrss_version = strftime("%y.%m", $timestamp) . "-$commit";
1819
-            }
1820
-        } else {
1821
-            user_error("Unable to determine version (using $root_dir): " . implode("\n", $output), E_USER_WARNING);
1822
-        }
1823
-    }
1818
+				$ttrss_version = strftime("%y.%m", $timestamp) . "-$commit";
1819
+			}
1820
+		} else {
1821
+			user_error("Unable to determine version (using $root_dir): " . implode("\n", $output), E_USER_WARNING);
1822
+		}
1823
+	}
1824 1824
 
1825
-    return $ttrss_version;
1825
+	return $ttrss_version;
1826 1826
 }
Please login to merge, or discard this patch.
include/sessions.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 $session_name = (!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid" : TTRSS_SESSION_NAME;
12 12
 
13 13
 if (is_server_https()) {
14
-    ini_set("session.cookie_secure", true);
14
+	ini_set("session.cookie_secure", true);
15 15
 }
16 16
 
17 17
 ini_set("session.gc_probability", 75);
@@ -21,132 +21,132 @@  discard block
 block discarded – undo
21 21
 ini_set("session.cookie_lifetime", min(0, SESSION_COOKIE_LIFETIME));
22 22
 
23 23
 function session_get_schema_version() {
24
-    global $schema_version;
24
+	global $schema_version;
25 25
 
26
-    if (!$schema_version) {
27
-        $row = Db::pdo()->query("SELECT schema_version FROM ttrss_version")->fetch();
26
+	if (!$schema_version) {
27
+		$row = Db::pdo()->query("SELECT schema_version FROM ttrss_version")->fetch();
28 28
 
29
-        $version = $row["schema_version"];
30
-        $schema_version = $version;
31
-        return $version;
32
-    }
29
+		$version = $row["schema_version"];
30
+		$schema_version = $version;
31
+		return $version;
32
+	}
33 33
 
34
-    return $schema_version;
34
+	return $schema_version;
35 35
 }
36 36
 
37 37
 function validate_session() {
38
-    if (SINGLE_USER_MODE) return true;
38
+	if (SINGLE_USER_MODE) return true;
39 39
 
40
-    if (isset($_SESSION["ref_schema_version"]) && $_SESSION["ref_schema_version"] != session_get_schema_version()) {
41
-        $_SESSION["login_error_msg"] =
42
-            __("Session failed to validate (schema version changed)");
43
-        return false;
44
-    }
45
-      $pdo = Db::pdo();
40
+	if (isset($_SESSION["ref_schema_version"]) && $_SESSION["ref_schema_version"] != session_get_schema_version()) {
41
+		$_SESSION["login_error_msg"] =
42
+			__("Session failed to validate (schema version changed)");
43
+		return false;
44
+	}
45
+	  $pdo = Db::pdo();
46 46
 
47
-    if ($_SESSION["uid"]) {
47
+	if ($_SESSION["uid"]) {
48 48
 
49
-        if (!defined('_SESSION_SKIP_UA_CHECKS') && $_SESSION["user_agent"] != sha1($_SERVER['HTTP_USER_AGENT'])) {
50
-            $_SESSION["login_error_msg"] = __("Session failed to validate (UA changed).");
51
-            return false;
52
-        }
49
+		if (!defined('_SESSION_SKIP_UA_CHECKS') && $_SESSION["user_agent"] != sha1($_SERVER['HTTP_USER_AGENT'])) {
50
+			$_SESSION["login_error_msg"] = __("Session failed to validate (UA changed).");
51
+			return false;
52
+		}
53 53
 
54
-        $sth = $pdo->prepare("SELECT pwd_hash FROM ttrss_users WHERE id = ?");
55
-        $sth->execute([$_SESSION['uid']]);
54
+		$sth = $pdo->prepare("SELECT pwd_hash FROM ttrss_users WHERE id = ?");
55
+		$sth->execute([$_SESSION['uid']]);
56 56
 
57
-        // user not found
58
-        if ($row = $sth->fetch()) {
59
-                 $pwd_hash = $row["pwd_hash"];
57
+		// user not found
58
+		if ($row = $sth->fetch()) {
59
+				 $pwd_hash = $row["pwd_hash"];
60 60
 
61
-                 if ($pwd_hash != $_SESSION["pwd_hash"]) {
61
+				 if ($pwd_hash != $_SESSION["pwd_hash"]) {
62 62
 
63
-                      $_SESSION["login_error_msg"] =
64
-                            __("Session failed to validate (password changed)");
63
+					  $_SESSION["login_error_msg"] =
64
+							__("Session failed to validate (password changed)");
65 65
 
66
-                      return false;
67
-                 }
68
-        } else {
66
+					  return false;
67
+				 }
68
+		} else {
69 69
 
70
-                 $_SESSION["login_error_msg"] =
71
-                      __("Session failed to validate (user not found)");
70
+				 $_SESSION["login_error_msg"] =
71
+					  __("Session failed to validate (user not found)");
72 72
 
73
-                 return false;
73
+				 return false;
74 74
 
75
-        }
76
-    }
75
+		}
76
+	}
77 77
 
78
-    return true;
78
+	return true;
79 79
 }
80 80
 
81 81
 function ttrss_open () {
82
-    return true;
82
+	return true;
83 83
 }
84 84
 
85 85
 function ttrss_read ($id){
86
-    global $session_expire;
86
+	global $session_expire;
87 87
 
88
-    $sth = Db::pdo()->prepare("SELECT data FROM ttrss_sessions WHERE id=?");
89
-    $sth->execute([$id]);
88
+	$sth = Db::pdo()->prepare("SELECT data FROM ttrss_sessions WHERE id=?");
89
+	$sth->execute([$id]);
90 90
 
91
-    if ($row = $sth->fetch()) {
92
-        return base64_decode($row["data"]);
91
+	if ($row = $sth->fetch()) {
92
+		return base64_decode($row["data"]);
93 93
 
94
-    } else {
95
-        $expire = time() + $session_expire;
94
+	} else {
95
+		$expire = time() + $session_expire;
96 96
 
97
-        $sth = Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire) VALUES (?, '', ?)");
98
-        $sth->execute([$id, $expire]);
97
+		$sth = Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire) VALUES (?, '', ?)");
98
+		$sth->execute([$id, $expire]);
99 99
 
100
-        return "";
101
-    }
100
+		return "";
101
+	}
102 102
 }
103 103
 
104 104
 function ttrss_write ($id, $data) {
105
-    global $session_expire;
105
+	global $session_expire;
106 106
 
107
-    $data = base64_encode($data);
108
-    $expire = time() + $session_expire;
107
+	$data = base64_encode($data);
108
+	$expire = time() + $session_expire;
109 109
 
110
-    $sth = Db::pdo()->prepare("SELECT id FROM ttrss_sessions WHERE id=?");
111
-    $sth->execute([$id]);
110
+	$sth = Db::pdo()->prepare("SELECT id FROM ttrss_sessions WHERE id=?");
111
+	$sth->execute([$id]);
112 112
 
113
-    if ($sth->fetch()) {
114
-        $sth = Db::pdo()->prepare("UPDATE ttrss_sessions SET data=?, expire=? WHERE id=?");
115
-        $sth->execute([$data, $expire, $id]);
116
-    } else {
117
-        $sth = Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire) VALUES (?, ?, ?)");
118
-        $sth->execute([$id, $data, $expire]);
119
-    }
113
+	if ($sth->fetch()) {
114
+		$sth = Db::pdo()->prepare("UPDATE ttrss_sessions SET data=?, expire=? WHERE id=?");
115
+		$sth->execute([$data, $expire, $id]);
116
+	} else {
117
+		$sth = Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire) VALUES (?, ?, ?)");
118
+		$sth->execute([$id, $data, $expire]);
119
+	}
120 120
 
121
-    return true;
121
+	return true;
122 122
 }
123 123
 
124 124
 function ttrss_close () {
125
-    return true;
125
+	return true;
126 126
 }
127 127
 
128 128
 function ttrss_destroy($id) {
129
-    $sth = Db::pdo()->prepare("DELETE FROM ttrss_sessions WHERE id = ?");
130
-    $sth->execute([$id]);
129
+	$sth = Db::pdo()->prepare("DELETE FROM ttrss_sessions WHERE id = ?");
130
+	$sth->execute([$id]);
131 131
 
132
-    return true;
132
+	return true;
133 133
 }
134 134
 
135 135
 function ttrss_gc () {
136
-    Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time());
136
+	Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time());
137 137
 
138
-    return true;
138
+	return true;
139 139
 }
140 140
 
141 141
 if (!SINGLE_USER_MODE) {
142
-    session_set_save_handler("ttrss_open",
143
-        "ttrss_close", "ttrss_read", "ttrss_write",
144
-        "ttrss_destroy", "ttrss_gc");
145
-    register_shutdown_function('session_write_close');
142
+	session_set_save_handler("ttrss_open",
143
+		"ttrss_close", "ttrss_read", "ttrss_write",
144
+		"ttrss_destroy", "ttrss_gc");
145
+	register_shutdown_function('session_write_close');
146 146
 }
147 147
 
148 148
 if (!defined('NO_SESSION_AUTOSTART')) {
149
-    if (isset($_COOKIE[session_name()])) {
150
-        @session_start();
151
-    }
149
+	if (isset($_COOKIE[session_name()])) {
150
+		@session_start();
151
+	}
152 152
 }
Please login to merge, or discard this patch.
plugins/bookmarklets/init.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -3,21 +3,21 @@
 block discarded – undo
3 3
   private $host;
4 4
 
5 5
   function about() {
6
-    return array(1.0,
6
+	return array(1.0,
7 7
 		 "Easy feed subscription and web page sharing using bookmarklets",
8 8
 		 "fox",
9
-	     false,
9
+		 false,
10 10
 		 "https://git.tt-rss.org/fox/tt-rss/wiki/ShareAnything");
11 11
   }
12 12
 
13 13
   function init($host) {
14
-    $this->host = $host;
14
+	$this->host = $host;
15 15
 
16
-    $host->add_hook($host::HOOK_PREFS_TAB, $this);
16
+	$host->add_hook($host::HOOK_PREFS_TAB, $this);
17 17
   }
18 18
 
19 19
   function hook_prefs_tab($args) {
20
-    if ($args == "prefFeeds") {
20
+	if ($args == "prefFeeds") {
21 21
 
22 22
 		print "<div dojoType=\"dijit.layout.AccordionPane\"
23 23
 			title=\"<i class='material-icons'>bookmark</i> ".__('Bookmarklets')."\">";
Please login to merge, or discard this patch.
plugins/cache_starred_images/init.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 	private $host;
6 6
 	/* @var DiskCache $cache */
7 7
 	private $cache;
8
-    private $max_cache_attempts = 5; // per-article
8
+	private $max_cache_attempts = 5; // per-article
9 9
 
10 10
 	public function about() {
11 11
 		return array(1.0,
@@ -158,30 +158,30 @@  discard block
 block discarded – undo
158 158
 
159 159
 		Debug::log("status: $status_filename", Debug::$LOG_VERBOSE);
160 160
 
161
-        if ($this->cache->exists($status_filename))
162
-            $status = json_decode($this->cache->get($status_filename), true);
163
-        else
164
-            $status = [];
161
+		if ($this->cache->exists($status_filename))
162
+			$status = json_decode($this->cache->get($status_filename), true);
163
+		else
164
+			$status = [];
165 165
 
166
-        $status["attempt"] += 1;
166
+		$status["attempt"] += 1;
167 167
 
168
-        // only allow several download attempts for article
169
-        if ($status["attempt"] > $this->max_cache_attempts) {
170
-            Debug::log("too many attempts for $site_url", Debug::$LOG_VERBOSE);
171
-            return false;
172
-        }
168
+		// only allow several download attempts for article
169
+		if ($status["attempt"] > $this->max_cache_attempts) {
170
+			Debug::log("too many attempts for $site_url", Debug::$LOG_VERBOSE);
171
+			return false;
172
+		}
173 173
 
174
-        if (!$this->cache->put($status_filename, json_encode($status))) {
175
-            user_error("unable to write status file: $status_filename", E_USER_WARNING);
176
-            return false;
177
-        }
174
+		if (!$this->cache->put($status_filename, json_encode($status))) {
175
+			user_error("unable to write status file: $status_filename", E_USER_WARNING);
176
+			return false;
177
+		}
178 178
 
179 179
 		$doc = new DOMDocument();
180 180
 
181 181
 		$has_images = false;
182 182
 		$success = false;
183 183
 
184
-        if ($doc->loadHTML('<?xml encoding="UTF-8">' . $content)) {
184
+		if ($doc->loadHTML('<?xml encoding="UTF-8">' . $content)) {
185 185
 			$xpath = new DOMXPath($doc);
186 186
 			$entries = $xpath->query('(//img[@src])|(//video/source[@src])');
187 187
 
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 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
-        if ($esth->execute([$article_id])) {
207
-        	while ($enc = $esth->fetch()) {
206
+		if ($esth->execute([$article_id])) {
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 212
 				if ($this->cache_url($article_id, $url)) {
213 213
 					$success = true;
Please login to merge, or discard this patch.
plugins/af_comics/filters/af_comics_tfd.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
 
8 8
 	public function process(&$article) {
9 9
 		if (strpos($article["link"], "toothpastefordinner.com") !== FALSE ||
10
-		    strpos($article["link"], "marriedtothesea.com") !== FALSE) {
10
+			strpos($article["link"], "marriedtothesea.com") !== FALSE) {
11 11
 			$res = fetch_file_contents($article["link"], false, false, false,
12 12
 				false, false, 0,
13 13
 				"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
Please login to merge, or discard this patch.
plugins/search_sphinx/sphinxapi.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 			$this->_mbenc = mb_internal_encoding();
545 545
 			mb_internal_encoding ( "latin1" );
546 546
 		}
547
-    }
547
+	}
548 548
 
549 549
 	/// leave mbstring workaround mode
550 550
 	public function _MBPop ()
@@ -938,9 +938,9 @@  discard block
 block discarded – undo
938 938
 
939 939
 	/// clear all attribute value overrides (for multi-queries)
940 940
 	public function ResetOverrides ()
941
-    {
942
-    	$this->_overrides = array ();
943
-    }
941
+	{
942
+		$this->_overrides = array ();
943
+	}
944 944
 
945 945
 	//////////////////////////////////////////////////////////////////////////////
946 946
 
Please login to merge, or discard this patch.
api/index.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@  discard block
 block discarded – undo
5 5
 require_once "..".DIRECTORY_SEPARATOR."config.php";
6 6
 
7 7
 set_include_path(dirname(__FILE__).PATH_SEPARATOR.
8
-    dirname(dirname(__FILE__)).PATH_SEPARATOR.
9
-    dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."include".PATH_SEPARATOR.
10
-    get_include_path());
8
+	dirname(dirname(__FILE__)).PATH_SEPARATOR.
9
+	dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."include".PATH_SEPARATOR.
10
+	get_include_path());
11 11
 
12 12
 chdir("..");
13 13
 
@@ -24,33 +24,33 @@  discard block
 block discarded – undo
24 24
 ini_set("session.gc_maxlifetime", 86400);
25 25
 
26 26
 if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
27
-        function_exists("ob_gzhandler")) {
27
+		function_exists("ob_gzhandler")) {
28 28
 
29
-    ob_start("ob_gzhandler");
29
+	ob_start("ob_gzhandler");
30 30
 } else {
31
-    ob_start();
31
+	ob_start();
32 32
 }
33 33
 
34 34
 $input = file_get_contents("php://input");
35 35
 
36 36
 if (defined('_API_DEBUG_HTTP_ENABLED') && _API_DEBUG_HTTP_ENABLED) {
37
-    // Override $_REQUEST with JSON-encoded data if available
38
-    // fallback on HTTP parameters
39
-    if ($input) {
40
-        $input = json_decode($input, true);
41
-        if ($input) $_REQUEST = $input;
42
-    }
37
+	// Override $_REQUEST with JSON-encoded data if available
38
+	// fallback on HTTP parameters
39
+	if ($input) {
40
+		$input = json_decode($input, true);
41
+		if ($input) $_REQUEST = $input;
42
+	}
43 43
 } else {
44
-    // Accept JSON only
45
-    $input = json_decode($input, true);
46
-    $_REQUEST = $input;
44
+	// Accept JSON only
45
+	$input = json_decode($input, true);
46
+	$_REQUEST = $input;
47 47
 }
48 48
 
49 49
 if ($_REQUEST["sid"]) {
50
-    session_id($_REQUEST["sid"]);
51
-    @session_start();
50
+	session_id($_REQUEST["sid"]);
51
+	@session_start();
52 52
 } else if (defined('_API_DEBUG_HTTP_ENABLED')) {
53
-    @session_start();
53
+	@session_start();
54 54
 }
55 55
 
56 56
 startup_gettext();
@@ -58,17 +58,17 @@  discard block
 block discarded – undo
58 58
 if (!init_plugins()) return;
59 59
 
60 60
 if ($_SESSION["uid"]) {
61
-    if (!validate_session()) {
62
-        header("Content-Type: text/json");
61
+	if (!validate_session()) {
62
+		header("Content-Type: text/json");
63 63
 
64
-        print json_encode(array("seq" => -1,
65
-            "status" => 1,
66
-            "content" => array("error" => "NOT_LOGGED_IN")));
64
+		print json_encode(array("seq" => -1,
65
+			"status" => 1,
66
+			"content" => array("error" => "NOT_LOGGED_IN")));
67 67
 
68
-        return;
69
-    }
68
+		return;
69
+	}
70 70
 
71
-    load_user_plugins( $_SESSION["uid"]);
71
+	load_user_plugins( $_SESSION["uid"]);
72 72
 }
73 73
 
74 74
 $method = strtolower($_REQUEST["op"]);
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 $handler = new API($_REQUEST);
77 77
 
78 78
 if ($handler->before($method)) {
79
-    if ($method && method_exists($handler, $method)) {
80
-        $handler->$method();
81
-    } else if (method_exists($handler, 'index')) {
82
-        $handler->index($method);
83
-    }
84
-    $handler->after();
79
+	if ($method && method_exists($handler, $method)) {
80
+		$handler->$method();
81
+	} else if (method_exists($handler, 'index')) {
82
+		$handler->index($method);
83
+	}
84
+	$handler->after();
85 85
 }
86 86
 
87 87
 header("Api-Content-Length: " . ob_get_length());
Please login to merge, or discard this patch.
update_daemon2.php 1 patch
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 #!/usr/bin/env php
2 2
 <?php
3 3
 set_include_path(dirname(__FILE__) .DIRECTORY_SEPARATOR."include" . PATH_SEPARATOR .
4
-    get_include_path());
4
+	get_include_path());
5 5
 
6 6
 declare(ticks = 1);
7 7
 chdir(dirname(__FILE__));
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
 require_once "db-prefs.php";
24 24
 
25 25
 if (!function_exists('pcntl_fork')) {
26
-    die("error: This script requires PHP compiled with PCNTL module.\n");
26
+	die("error: This script requires PHP compiled with PCNTL module.\n");
27 27
 }
28 28
 
29 29
 $options = getopt("");
30 30
 
31 31
 if (!is_array($options)) {
32
-    die("error: getopt() failed. ".
33
-        "Most probably you are using PHP CGI to run this script ".
34
-        "instead of required PHP CLI. Check tt-rss wiki page on updating feeds for ".
35
-        "additional information.\n");
32
+	die("error: getopt() failed. ".
33
+		"Most probably you are using PHP CGI to run this script ".
34
+		"instead of required PHP CLI. Check tt-rss wiki page on updating feeds for ".
35
+		"additional information.\n");
36 36
 }
37 37
 
38 38
 
@@ -44,137 +44,137 @@  discard block
 block discarded – undo
44 44
 $last_checkpoint = -1;
45 45
 
46 46
 function reap_children() {
47
-    global $children;
48
-    global $ctimes;
47
+	global $children;
48
+	global $ctimes;
49 49
 
50
-    $tmp = array();
50
+	$tmp = array();
51 51
 
52
-    foreach ($children as $pid) {
53
-        if (pcntl_waitpid($pid, $status, WNOHANG) != $pid) {
52
+	foreach ($children as $pid) {
53
+		if (pcntl_waitpid($pid, $status, WNOHANG) != $pid) {
54 54
 
55
-            if (file_is_locked("update_daemon-$pid.lock")) {
56
-                array_push($tmp, $pid);
57
-            } else {
58
-                Debug::log("[reap_children] child $pid seems active but lockfile is unlocked.");
59
-                unset($ctimes[$pid]);
55
+			if (file_is_locked("update_daemon-$pid.lock")) {
56
+				array_push($tmp, $pid);
57
+			} else {
58
+				Debug::log("[reap_children] child $pid seems active but lockfile is unlocked.");
59
+				unset($ctimes[$pid]);
60 60
 
61
-            }
62
-        } else {
63
-            Debug::log("[reap_children] child $pid reaped.");
64
-            unset($ctimes[$pid]);
65
-        }
66
-    }
61
+			}
62
+		} else {
63
+			Debug::log("[reap_children] child $pid reaped.");
64
+			unset($ctimes[$pid]);
65
+		}
66
+	}
67 67
 
68
-    $children = $tmp;
68
+	$children = $tmp;
69 69
 
70
-    return count($tmp);
70
+	return count($tmp);
71 71
 }
72 72
 
73 73
 function check_ctimes() {
74
-    global $ctimes;
74
+	global $ctimes;
75 75
 
76
-    foreach (array_keys($ctimes) as $pid) {
77
-        $started = $ctimes[$pid];
76
+	foreach (array_keys($ctimes) as $pid) {
77
+		$started = $ctimes[$pid];
78 78
 
79
-        if (time() - $started > MAX_CHILD_RUNTIME) {
80
-            Debug::log("[MASTER] child process $pid seems to be stuck, aborting...");
81
-            posix_kill($pid, SIGKILL);
82
-        }
83
-    }
79
+		if (time() - $started > MAX_CHILD_RUNTIME) {
80
+			Debug::log("[MASTER] child process $pid seems to be stuck, aborting...");
81
+			posix_kill($pid, SIGKILL);
82
+		}
83
+	}
84 84
 }
85 85
 
86 86
 function sigchld_handler($signal) {
87
-    $running_jobs = reap_children();
87
+	$running_jobs = reap_children();
88 88
 
89
-    Debug::log("[SIGCHLD] jobs left: $running_jobs");
89
+	Debug::log("[SIGCHLD] jobs left: $running_jobs");
90 90
 
91
-    pcntl_waitpid(-1, $status, WNOHANG);
91
+	pcntl_waitpid(-1, $status, WNOHANG);
92 92
 }
93 93
 
94 94
 function shutdown($caller_pid) {
95
-    if ($caller_pid == posix_getpid()) {
96
-        if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
97
-            Debug::log("removing lockfile (master)...");
98
-            unlink(LOCK_DIRECTORY . "/update_daemon.lock");
99
-        }
100
-    }
95
+	if ($caller_pid == posix_getpid()) {
96
+		if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
97
+			Debug::log("removing lockfile (master)...");
98
+			unlink(LOCK_DIRECTORY . "/update_daemon.lock");
99
+		}
100
+	}
101 101
 }
102 102
 
103 103
 function task_shutdown() {
104
-    $pid = posix_getpid();
104
+	$pid = posix_getpid();
105 105
 
106
-    if (file_exists(LOCK_DIRECTORY . "/update_daemon-$pid.lock")) {
107
-        Debug::log("removing lockfile ($pid)...");
108
-        unlink(LOCK_DIRECTORY . "/update_daemon-$pid.lock");
109
-    }
106
+	if (file_exists(LOCK_DIRECTORY . "/update_daemon-$pid.lock")) {
107
+		Debug::log("removing lockfile ($pid)...");
108
+		unlink(LOCK_DIRECTORY . "/update_daemon-$pid.lock");
109
+	}
110 110
 }
111 111
 
112 112
 function sigint_handler() {
113
-    Debug::log("[MASTER] SIG_INT received.\n");
114
-    shutdown(posix_getpid());
115
-    die;
113
+	Debug::log("[MASTER] SIG_INT received.\n");
114
+	shutdown(posix_getpid());
115
+	die;
116 116
 }
117 117
 
118 118
 function task_sigint_handler() {
119
-    Debug::log("[TASK] SIG_INT received.\n");
120
-    task_shutdown();
121
-    die;
119
+	Debug::log("[TASK] SIG_INT received.\n");
120
+	task_shutdown();
121
+	die;
122 122
 }
123 123
 
124 124
 pcntl_signal(SIGCHLD, 'sigchld_handler');
125 125
 
126 126
 $longopts = array(
127
-    "log:",
128
-    "log-level:",
129
-    "tasks:",
130
-    "interval:",
131
-    "quiet",
132
-    "help"
127
+	"log:",
128
+	"log-level:",
129
+	"tasks:",
130
+	"interval:",
131
+	"quiet",
132
+	"help"
133 133
 );
134 134
 
135 135
 $options = getopt("", $longopts);
136 136
 
137 137
 if (isset($options["help"]) ) {
138
-    print "Tiny Tiny RSS update daemon.\n\n";
139
-    print "Options:\n";
140
-    print "  --log FILE           - log messages to FILE\n";
141
-    print "  --log-level N        - log verbosity level\n";
142
-    print "  --tasks N            - amount of update tasks to spawn\n";
143
-    print "                         default: " . MAX_JOBS . "\n";
144
-    print "  --interval N         - task spawn interval\n";
145
-    print "                         default: " . SPAWN_INTERVAL . " seconds.\n";
146
-    print "  --quiet              - don't output messages to stdout\n";
147
-    return;
138
+	print "Tiny Tiny RSS update daemon.\n\n";
139
+	print "Options:\n";
140
+	print "  --log FILE           - log messages to FILE\n";
141
+	print "  --log-level N        - log verbosity level\n";
142
+	print "  --tasks N            - amount of update tasks to spawn\n";
143
+	print "                         default: " . MAX_JOBS . "\n";
144
+	print "  --interval N         - task spawn interval\n";
145
+	print "                         default: " . SPAWN_INTERVAL . " seconds.\n";
146
+	print "  --quiet              - don't output messages to stdout\n";
147
+	return;
148 148
 }
149 149
 
150 150
 Debug::set_enabled(true);
151 151
 
152 152
 if (isset($options["log-level"])) {
153
-    Debug::set_loglevel((int)$options["log-level"]);
153
+	Debug::set_loglevel((int)$options["log-level"]);
154 154
 }
155 155
 
156 156
 if (isset($options["log"])) {
157
-    Debug::set_quiet(isset($options['quiet']));
158
-    Debug::set_logfile($options["log"]);
159
-    Debug::log("Logging to " . $options["log"]);
157
+	Debug::set_quiet(isset($options['quiet']));
158
+	Debug::set_logfile($options["log"]);
159
+	Debug::log("Logging to " . $options["log"]);
160 160
 } else {
161
-    if (isset($options['quiet'])) {
162
-        Debug::set_loglevel(Debug::$LOG_DISABLED);
163
-    }
161
+	if (isset($options['quiet'])) {
162
+		Debug::set_loglevel(Debug::$LOG_DISABLED);
163
+	}
164 164
 }
165 165
 
166 166
 if (isset($options["tasks"])) {
167
-    Debug::log("Set to spawn " . $options["tasks"] . " children.");
168
-    $max_jobs = $options["tasks"];
167
+	Debug::log("Set to spawn " . $options["tasks"] . " children.");
168
+	$max_jobs = $options["tasks"];
169 169
 } else {
170
-    $max_jobs = MAX_JOBS;
170
+	$max_jobs = MAX_JOBS;
171 171
 }
172 172
 
173 173
 if (isset($options["interval"])) {
174
-    Debug::log("Spawn interval: " . $options["interval"] . " seconds.");
175
-    $spawn_interval = $options["interval"];
174
+	Debug::log("Spawn interval: " . $options["interval"] . " seconds.");
175
+	$spawn_interval = $options["interval"];
176 176
 } else {
177
-    $spawn_interval = SPAWN_INTERVAL;
177
+	$spawn_interval = SPAWN_INTERVAL;
178 178
 }
179 179
 
180 180
 // let's enforce a minimum spawn interval as to not forkbomb the host
@@ -182,22 +182,22 @@  discard block
 block discarded – undo
182 182
 Debug::log("Spawn interval: $spawn_interval sec");
183 183
 
184 184
 if (file_is_locked("update_daemon.lock")) {
185
-    die("error: Can't create lockfile. ".
186
-        "Maybe another daemon is already running.\n");
185
+	die("error: Can't create lockfile. ".
186
+		"Maybe another daemon is already running.\n");
187 187
 }
188 188
 
189 189
 // Try to lock a file in order to avoid concurrent update.
190 190
 $lock_handle = make_lockfile("update_daemon.lock");
191 191
 
192 192
 if (!$lock_handle) {
193
-    die("error: Can't create lockfile. ".
194
-        "Maybe another daemon is already running.\n");
193
+	die("error: Can't create lockfile. ".
194
+		"Maybe another daemon is already running.\n");
195 195
 }
196 196
 
197 197
 $schema_version = get_schema_version();
198 198
 
199 199
 if ($schema_version != SCHEMA_VERSION) {
200
-    die("Schema version is wrong, please upgrade the database.\n");
200
+	die("Schema version is wrong, please upgrade the database.\n");
201 201
 }
202 202
 
203 203
 // Protip: children close shared database handle when terminating, it's a bad idea to
@@ -205,56 +205,56 @@  discard block
 block discarded – undo
205 205
 
206 206
 while (true) {
207 207
 
208
-    // Since sleep is interupted by SIGCHLD, we need another way to
209
-    // respect the spawn interval
210
-    $next_spawn = $last_checkpoint + $spawn_interval - time();
211
-
212
-    if ($next_spawn % 60 == 0) {
213
-        $running_jobs = count($children);
214
-        Debug::log("[MASTER] active jobs: $running_jobs, next spawn at $next_spawn sec.");
215
-    }
216
-
217
-    if ($last_checkpoint + $spawn_interval < time()) {
218
-        check_ctimes();
219
-        reap_children();
220
-
221
-        for ($j = count($children); $j < $max_jobs; $j++) {
222
-            $pid = pcntl_fork();
223
-            if ($pid == -1) {
224
-                die("fork failed!\n");
225
-            } else if ($pid) {
226
-
227
-                if (!$master_handlers_installed) {
228
-                    Debug::log("[MASTER] installing shutdown handlers");
229
-                    pcntl_signal(SIGINT, 'sigint_handler');
230
-                    pcntl_signal(SIGTERM, 'sigint_handler');
231
-                    register_shutdown_function('shutdown', posix_getpid());
232
-                    $master_handlers_installed = true;
233
-                }
234
-
235
-                Debug::log("[MASTER] spawned client $j [PID:$pid]...");
236
-                array_push($children, $pid);
237
-                $ctimes[$pid] = time();
238
-            } else {
239
-                pcntl_signal(SIGCHLD, SIG_IGN);
240
-                pcntl_signal(SIGINT, 'task_sigint_handler');
241
-
242
-                register_shutdown_function('task_shutdown');
243
-
244
-                $quiet = (isset($options["quiet"])) ? "--quiet" : "";
245
-                $log = function_exists("flock") && isset($options['log']) ? '--log '.$options['log'] : '';
246
-
247
-                $my_pid = posix_getpid();
248
-
249
-                passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid");
250
-
251
-                sleep(1);
252
-
253
-                // We exit in order to avoid fork bombing.
254
-                exit(0);
255
-            }
256
-        }
257
-        $last_checkpoint = time();
258
-    }
259
-    sleep(1);
208
+	// Since sleep is interupted by SIGCHLD, we need another way to
209
+	// respect the spawn interval
210
+	$next_spawn = $last_checkpoint + $spawn_interval - time();
211
+
212
+	if ($next_spawn % 60 == 0) {
213
+		$running_jobs = count($children);
214
+		Debug::log("[MASTER] active jobs: $running_jobs, next spawn at $next_spawn sec.");
215
+	}
216
+
217
+	if ($last_checkpoint + $spawn_interval < time()) {
218
+		check_ctimes();
219
+		reap_children();
220
+
221
+		for ($j = count($children); $j < $max_jobs; $j++) {
222
+			$pid = pcntl_fork();
223
+			if ($pid == -1) {
224
+				die("fork failed!\n");
225
+			} else if ($pid) {
226
+
227
+				if (!$master_handlers_installed) {
228
+					Debug::log("[MASTER] installing shutdown handlers");
229
+					pcntl_signal(SIGINT, 'sigint_handler');
230
+					pcntl_signal(SIGTERM, 'sigint_handler');
231
+					register_shutdown_function('shutdown', posix_getpid());
232
+					$master_handlers_installed = true;
233
+				}
234
+
235
+				Debug::log("[MASTER] spawned client $j [PID:$pid]...");
236
+				array_push($children, $pid);
237
+				$ctimes[$pid] = time();
238
+			} else {
239
+				pcntl_signal(SIGCHLD, SIG_IGN);
240
+				pcntl_signal(SIGINT, 'task_sigint_handler');
241
+
242
+				register_shutdown_function('task_shutdown');
243
+
244
+				$quiet = (isset($options["quiet"])) ? "--quiet" : "";
245
+				$log = function_exists("flock") && isset($options['log']) ? '--log '.$options['log'] : '';
246
+
247
+				$my_pid = posix_getpid();
248
+
249
+				passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid");
250
+
251
+				sleep(1);
252
+
253
+				// We exit in order to avoid fork bombing.
254
+				exit(0);
255
+			}
256
+		}
257
+		$last_checkpoint = time();
258
+	}
259
+	sleep(1);
260 260
 }
Please login to merge, or discard this patch.