Passed
Push — master ( 5a5c41...fade3b )
by Cody
04:50 queued 10s
created
classes/rssutils.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -7,11 +7,11 @@  discard block
 block discarded – undo
7 7
 			if ($k != "feed" && isset($v)) {
8 8
 				$x = strip_tags(is_array($v) ? implode(",", $v) : $v);
9 9
 
10
-				$tmp .= sha1("$k:" . sha1($x));
10
+				$tmp .= sha1("$k:".sha1($x));
11 11
 			}
12 12
 		}
13 13
 
14
-		return sha1(implode(",", $pluginhost->get_plugin_names()) . $tmp);
14
+		return sha1(implode(",", $pluginhost->get_plugin_names()).$tmp);
15 15
 	}
16 16
 
17 17
 	// Strips utf8mb4 characters (i.e. emoji) for mysql
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 			//update_rss_feed($line["id"], true);
138 138
 
139 139
 			if ($tline = $usth->fetch()) {
140
-				Debug::log(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]);
140
+				Debug::log(" => ".$tline["last_updated"].", ".$tline["id"]." ".$tline["owner_uid"]);
141 141
 
142 142
 				if (array_search($tline["owner_uid"], $batch_owners) === FALSE)
143 143
 					array_push($batch_owners, $tline["owner_uid"]);
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 
324 324
 		$date_feed_processed = date('Y-m-d H:i');
325 325
 
326
-		$cache_filename = CACHE_DIR . "/feeds/" . sha1($fetch_url) . ".xml";
326
+		$cache_filename = CACHE_DIR."/feeds/".sha1($fetch_url).".xml";
327 327
 
328 328
 		$pluginhost = new PluginHost();
329 329
 		$user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 		Debug::log("running HOOK_FETCH_FEED handlers...", Debug::$LOG_VERBOSE);
341 341
 
342 342
 		foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) {
343
-			Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE);
343
+			Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE);
344 344
 			$start = microtime(true);
345 345
 			$feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, 0, $auth_login, $auth_pass);
346 346
 			Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 			$feed_data = trim($feed_data);
403 403
 
404 404
 			Debug::log("fetch done.", Debug::$LOG_VERBOSE);
405
-			Debug::log("source last modified: " . $fetch_last_modified, Debug::$LOG_VERBOSE);
405
+			Debug::log("source last modified: ".$fetch_last_modified, Debug::$LOG_VERBOSE);
406 406
 
407 407
 			if ($feed_data && $fetch_last_modified != $stored_last_modified) {
408 408
 				$sth = $pdo->prepare("UPDATE ttrss_feeds SET last_modified = ? WHERE id = ?");
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 			}
411 411
 
412 412
 			// cache vanilla feed data for re-use
413
-			if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/feeds")) {
413
+			if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR."/feeds")) {
414 414
 				$new_rss_hash = sha1($feed_data);
415 415
 
416 416
 				if ($new_rss_hash != $rss_hash) {
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 		$feed_data_checksum = md5($feed_data);
446 446
 
447 447
 		foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) {
448
-			Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE);
448
+			Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE);
449 449
 			$start = microtime(true);
450 450
 			$feed_data = $plugin->hook_feed_fetched($feed_data, $fetch_url, $owner_uid, $feed);
451 451
 			Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 			// We use local pluginhost here because we need to load different per-user feed plugins
468 468
 
469 469
 			foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_PARSED) as $plugin) {
470
-				Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE);
470
+				Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE);
471 471
 				$start = microtime(true);
472 472
 				$plugin->hook_feed_parsed($rss);
473 473
 				Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
@@ -499,14 +499,14 @@  discard block
 block discarded – undo
499 499
 			$site_url = mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245);
500 500
 
501 501
 			Debug::log("site_url: $site_url", Debug::$LOG_VERBOSE);
502
-			Debug::log("feed_title: " . clean($rss->get_title()), Debug::$LOG_VERBOSE);
502
+			Debug::log("feed_title: ".clean($rss->get_title()), Debug::$LOG_VERBOSE);
503 503
 
504 504
 			if ($favicon_needs_check || $force_refetch) {
505 505
 
506 506
 				/* terrible hack: if we crash on floicon shit here, we won't check
507 507
 				 * the icon avgcolor again (unless the icon got updated) */
508 508
 
509
-				$favicon_file = ICONS_DIR . "/$feed.ico";
509
+				$favicon_file = ICONS_DIR."/$feed.ico";
510 510
 				$favicon_modified = @filemtime($favicon_file);
511 511
 
512 512
 				Debug::log("checking favicon...", Debug::$LOG_VERBOSE);
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
 
528 528
 					$favicon_color = calculate_avg_color($favicon_file);
529 529
 
530
-					$favicon_colorstring = ",favicon_avg_color = " . $pdo->quote($favicon_color);
530
+					$favicon_colorstring = ",favicon_avg_color = ".$pdo->quote($favicon_color);
531 531
 
532 532
 				} else if ($favicon_avg_color == 'fail') {
533 533
 					Debug::log("floicon failed on this file, not trying to recalculate avg color", Debug::$LOG_VERBOSE);
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
 				print_r($filters);
547 547
 			}
548 548
 
549
-			Debug::log("" . count($filters) . " filters loaded.", Debug::$LOG_VERBOSE);
549
+			Debug::log("".count($filters)." filters loaded.", Debug::$LOG_VERBOSE);
550 550
 
551 551
 			$items = $rss->get_items();
552 552
 
@@ -588,13 +588,13 @@  discard block
 block discarded – undo
588 588
 
589 589
 				$entry_guid = "$owner_uid,$entry_guid";
590 590
 
591
-				$entry_guid_hashed = 'SHA1:' . sha1($entry_guid);
591
+				$entry_guid_hashed = 'SHA1:'.sha1($entry_guid);
592 592
 
593 593
 				Debug::log("guid $entry_guid / $entry_guid_hashed", Debug::$LOG_VERBOSE);
594 594
 
595
-				$entry_timestamp = (int)$item->get_date();
595
+				$entry_timestamp = (int) $item->get_date();
596 596
 
597
-				Debug::log("orig date: " . $item->get_date(), Debug::$LOG_VERBOSE);
597
+				Debug::log("orig date: ".$item->get_date(), Debug::$LOG_VERBOSE);
598 598
 
599 599
 				$entry_title = strip_tags($item->get_title());
600 600
 
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 				Debug::log("link $entry_link", Debug::$LOG_VERBOSE);
607 607
 				Debug::log("language $entry_language", Debug::$LOG_VERBOSE);
608 608
 
609
-				if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);;
609
+				if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp); ;
610 610
 
611 611
 				$entry_content = $item->get_content();
612 612
 				if (!$entry_content) $entry_content = $item->get_description();
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 				Debug::log("looking for tags...", Debug::$LOG_VERBOSE);
628 628
 
629 629
 				$entry_tags = $item->get_categories();
630
-				Debug::log("tags found: " . join(", ", $entry_tags), Debug::$LOG_VERBOSE);
630
+				Debug::log("tags found: ".join(", ", $entry_tags), Debug::$LOG_VERBOSE);
631 631
 
632 632
 				Debug::log("done collecting data.", Debug::$LOG_VERBOSE);
633 633
 
@@ -692,14 +692,14 @@  discard block
 block discarded – undo
692 692
 				Debug::log("hash differs, applying plugin filters:", Debug::$LOG_VERBOSE);
693 693
 
694 694
 				foreach ($pluginhost->get_hooks(PluginHost::HOOK_ARTICLE_FILTER) as $plugin) {
695
-					Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE);
695
+					Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE);
696 696
 
697 697
 					$start = microtime(true);
698 698
 					$article = $plugin->hook_article_filter($article);
699 699
 
700 700
 					Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
701 701
 
702
-					$entry_plugin_data .= mb_strtolower(get_class($plugin)) . ",";
702
+					$entry_plugin_data .= mb_strtolower(get_class($plugin)).",";
703 703
 				}
704 704
 
705 705
                 if (Debug::get_loglevel() >= 3) {
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
 					Debug::log("applying plugin filter actions...", Debug::$LOG_VERBOSE);
773 773
 
774 774
 					foreach ($plugin_filter_names as $pfn) {
775
-						list($pfclass,$pfaction) = explode(":", $pfn["param"]);
775
+						list($pfclass, $pfaction) = explode(":", $pfn["param"]);
776 776
 
777 777
 						if (isset($plugin_filter_actions[$pfclass])) {
778 778
 							$plugin = $pluginhost->get_plugin($pfclass);
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
 							$entry_current_hash,
868 868
 							$date_feed_processed,
869 869
 							$entry_comments,
870
-							(int)$num_comments,
870
+							(int) $num_comments,
871 871
 							$entry_plugin_data,
872 872
 							"$entry_language",
873 873
 							"$entry_author"]);
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
 						":content" => "$entry_content",
980 980
 						":content_hash" => $entry_current_hash,
981 981
 						":updated" => $entry_timestamp_fmt,
982
-						":num_comments" => (int)$num_comments,
982
+						":num_comments" => (int) $num_comments,
983 983
 						":plugin_data" => $entry_plugin_data,
984 984
 						":author" => "$entry_author",
985 985
 						":lang" => $entry_language,
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
 
988 988
 					if (DB_TYPE == "pgsql") {
989 989
 						$params[":ts_lang"] = $feed_language;
990
-						$params[":ts_content"] = mb_substr(strip_tags($entry_title . " " . $entry_content), 0, 900000);
990
+						$params[":ts_content"] = mb_substr(strip_tags($entry_title." ".$entry_content), 0, 900000);
991 991
 					}
992 992
 
993 993
 					$sth->execute($params);
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
 				foreach ($enclosures as $enc) {
1068 1068
 					$enc_url = $enc[0];
1069 1069
 					$enc_type = $enc[1];
1070
-					$enc_dur = (int)$enc[2];
1070
+					$enc_dur = (int) $enc[2];
1071 1071
 					$enc_title = $enc[3];
1072 1072
 					$enc_width = intval($enc[4]);
1073 1073
 					$enc_height = intval($enc[5]);
@@ -1075,7 +1075,7 @@  discard block
 block discarded – undo
1075 1075
 					$esth->execute([$enc_url, $enc_type, $entry_ref_id]);
1076 1076
 
1077 1077
 					if (!$esth->fetch()) {
1078
-						$usth->execute([$enc_url, $enc_type, (string)$enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]);
1078
+						$usth->execute([$enc_url, $enc_type, (string) $enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]);
1079 1079
 					}
1080 1080
 				}
1081 1081
 
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
 				$filtered_tags = array_unique($filtered_tags);
1110 1110
 
1111 1111
 				if (Debug::get_loglevel() >= Debug::$LOG_VERBOSE) {
1112
-					Debug::log("filtered tags: " . implode(", ", $filtered_tags), Debug::$LOG_VERBOSE);
1112
+					Debug::log("filtered tags: ".implode(", ", $filtered_tags), Debug::$LOG_VERBOSE);
1113 1113
 
1114 1114
 				}
1115 1115
 
@@ -1297,11 +1297,11 @@  discard block
 block discarded – undo
1297 1297
 		$num_deleted = 0;
1298 1298
 
1299 1299
 		if (is_writable(LOCK_DIRECTORY)) {
1300
-			$files = glob(LOCK_DIRECTORY . "/*.lock");
1300
+			$files = glob(LOCK_DIRECTORY."/*.lock");
1301 1301
 
1302 1302
 			if ($files) {
1303 1303
 				foreach ($files as $file) {
1304
-					if (!file_is_locked(basename($file)) && time() - filemtime($file) > 86400*2) {
1304
+					if (!file_is_locked(basename($file)) && time() - filemtime($file) > 86400 * 2) {
1305 1305
 						unlink($file);
1306 1306
 						++$num_deleted;
1307 1307
 					}
@@ -1516,7 +1516,7 @@  discard block
 block discarded – undo
1516 1516
 	public static function check_feed_favicon($site_url, $feed) {
1517 1517
 		#		print "FAVICON [$site_url]: $favicon_url\n";
1518 1518
 
1519
-		$icon_file = ICONS_DIR . "/$feed.ico";
1519
+		$icon_file = ICONS_DIR."/$feed.ico";
1520 1520
 
1521 1521
 		if (!file_exists($icon_file)) {
1522 1522
 			$favicon_url = RSSUtils::get_favicon_url($site_url);
@@ -1570,14 +1570,14 @@  discard block
 block discarded – undo
1570 1570
 
1571 1571
 	public static function is_gzipped($feed_data) {
1572 1572
 		return strpos(substr($feed_data, 0, 3),
1573
-				"\x1f" . "\x8b" . "\x08", 0) === 0;
1573
+				"\x1f"."\x8b"."\x08", 0) === 0;
1574 1574
 	}
1575 1575
 
1576 1576
 	public static function load_filters($feed_id, $owner_uid) {
1577 1577
 		$filters = array();
1578 1578
 
1579 1579
 		$feed_id = (int) $feed_id;
1580
-		$cat_id = (int)Feeds::getFeedCategory($feed_id);
1580
+		$cat_id = (int) Feeds::getFeedCategory($feed_id);
1581 1581
 
1582 1582
 		if ($cat_id == 0)
1583 1583
 			$null_cat_qpart = "cat_id IS NULL OR";
Please login to merge, or discard this patch.
classes/pluginhost.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
 					!is_dir(__DIR__."/../plugins.local/$class_file")) continue;
195 195
 
196 196
 			// try system plugin directory first
197
-			$file = __DIR__ . "/../plugins/$class_file/init.php";
198
-			$vendor_dir = __DIR__ . "/../plugins/$class_file/vendor";
197
+			$file = __DIR__."/../plugins/$class_file/init.php";
198
+			$vendor_dir = __DIR__."/../plugins/$class_file/vendor";
199 199
 
200 200
 			if (!file_exists($file)) {
201
-				$file = __DIR__ . "/../plugins.local/$class_file/init.php";
202
-				$vendor_dir = __DIR__ . "/../plugins.local/$class_file/vendor";
201
+				$file = __DIR__."/../plugins.local/$class_file/init.php";
202
+				$vendor_dir = __DIR__."/../plugins.local/$class_file/vendor";
203 203
 			}
204 204
 
205 205
 			if (!isset($this->plugins[$class])) {
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 								list ($namespace, $class_name) = explode('\\', $class, 2);
218 218
 
219 219
 								if ($namespace && $class_name) {
220
-									$class_file = "$vendor_dir/$namespace/" . str_replace('\\', '/', $class_name) . ".php";
220
+									$class_file = "$vendor_dir/$namespace/".str_replace('\\', '/', $class_name).".php";
221 221
 
222 222
 									if (file_exists($class_file))
223 223
 										require_once $class_file;
@@ -231,12 +231,12 @@  discard block
 block discarded – undo
231 231
 					$plugin_api = $plugin->api_version();
232 232
 
233 233
 					if ($plugin_api < PluginHost::API_VERSION) {
234
-						user_error("Plugin $class is not compatible with current API version (need: " . PluginHost::API_VERSION . ", got: $plugin_api)", E_USER_WARNING);
234
+						user_error("Plugin $class is not compatible with current API version (need: ".PluginHost::API_VERSION.", got: $plugin_api)", E_USER_WARNING);
235 235
 						continue;
236 236
 					}
237 237
 
238
-					if (file_exists(dirname($file) . "/locale")) {
239
-						_bindtextdomain($class, dirname($file) . "/locale");
238
+					if (file_exists(dirname($file)."/locale")) {
239
+						_bindtextdomain($class, dirname($file)."/locale");
240 240
 						_bind_textdomain_codeset($class, "UTF-8");
241 241
 					}
242 242
 
@@ -319,13 +319,13 @@  discard block
 block discarded – undo
319 319
 	}
320 320
 
321 321
 	public function del_command($command) {
322
-		$command = "-" . strtolower($command);
322
+		$command = "-".strtolower($command);
323 323
 
324 324
 		unset($this->commands[$command]);
325 325
 	}
326 326
 
327 327
 	public function lookup_command($command) {
328
-		$command = "-" . strtolower($command);
328
+		$command = "-".strtolower($command);
329 329
 
330 330
 		if (is_array($this->commands[$command])) {
331 331
 			return $this->commands[$command]["class"];
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 	}
349 349
 
350 350
 	public function load_data() {
351
-		if ($this->owner_uid)  {
351
+		if ($this->owner_uid) {
352 352
 			$sth = $this->pdo->prepare("SELECT name, content FROM ttrss_plugin_storage
353 353
 				WHERE owner_uid = ?");
354 354
 			$sth->execute([$this->owner_uid]);
@@ -375,13 +375,13 @@  discard block
 block discarded – undo
375 375
 			if ($sth->fetch()) {
376 376
 				$sth = $this->pdo->prepare("UPDATE ttrss_plugin_storage SET content = ?
377 377
 					WHERE owner_uid= ? AND name = ?");
378
-				$sth->execute([(string)$content, $this->owner_uid, $plugin]);
378
+				$sth->execute([(string) $content, $this->owner_uid, $plugin]);
379 379
 
380 380
 			} else {
381 381
 				$sth = $this->pdo->prepare("INSERT INTO ttrss_plugin_storage
382 382
 					(name,owner_uid,content) VALUES
383 383
 					(?, ?, ?)");
384
-				$sth->execute([$plugin, $this->owner_uid, (string)$content]);
384
+				$sth->execute([$plugin, $this->owner_uid, (string) $content]);
385 385
 			}
386 386
 
387 387
 			$this->pdo->commit();
@@ -495,8 +495,8 @@  discard block
 block discarded – undo
495 495
 	}
496 496
 
497 497
 	// handled by classes/pluginhandler.php, requires valid session
498
-	public function get_method_url($sender, $method, $params)  {
499
-		return get_self_url_prefix() . "/backend.php?" .
498
+	public function get_method_url($sender, $method, $params) {
499
+		return get_self_url_prefix()."/backend.php?".
500 500
 			http_build_query(
501 501
 				array_merge(
502 502
 					[
@@ -508,9 +508,9 @@  discard block
 block discarded – undo
508 508
 	}
509 509
 
510 510
 	// WARNING: endpoint in public.php, exposed to unauthenticated users
511
-	public function get_public_method_url($sender, $method, $params)  {
511
+	public function get_public_method_url($sender, $method, $params) {
512 512
 		if ($sender->is_public_method($method)) {
513
-			return get_self_url_prefix() . "/public.php?" .
513
+			return get_self_url_prefix()."/public.php?".
514 514
 				http_build_query(
515 515
 					array_merge(
516 516
 						[
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 						],
521 521
 						$params));
522 522
 		} else {
523
-			user_error("get_public_method_url: requested method '$method' of '" . get_class($sender) . "' is private.");
523
+			user_error("get_public_method_url: requested method '$method' of '".get_class($sender)."' is private.");
524 524
 		}
525 525
 	}
526 526
 }
Please login to merge, or discard this patch.
Braces   +36 added lines, -17 removed lines patch added patch discarded remove patch
@@ -82,8 +82,9 @@  discard block
 block discarded – undo
82 82
 	}
83 83
 
84 84
 	public static function getInstance() {
85
-		if (self::$instance == null)
86
-			self::$instance = new self();
85
+		if (self::$instance == null) {
86
+					self::$instance = new self();
87
+		}
87 88
 
88 89
 		return self::$instance;
89 90
 	}
@@ -191,7 +192,9 @@  discard block
 block discarded – undo
191 192
 			$class_file = strtolower(clean_filename($class));
192 193
 
193 194
 			if (!is_dir(__DIR__."/../plugins/$class_file") &&
194
-					!is_dir(__DIR__."/../plugins.local/$class_file")) continue;
195
+					!is_dir(__DIR__."/../plugins.local/$class_file")) {
196
+				continue;
197
+			}
195 198
 
196 199
 			// try system plugin directory first
197 200
 			$file = __DIR__ . "/../plugins/$class_file/init.php";
@@ -203,7 +206,9 @@  discard block
 block discarded – undo
203 206
 			}
204 207
 
205 208
 			if (!isset($this->plugins[$class])) {
206
-				if (file_exists($file)) require_once $file;
209
+				if (file_exists($file)) {
210
+					require_once $file;
211
+				}
207 212
 
208 213
 				if (class_exists($class) && is_subclass_of($class, "Plugin")) {
209 214
 
@@ -219,8 +224,9 @@  discard block
 block discarded – undo
219 224
 								if ($namespace && $class_name) {
220 225
 									$class_file = "$vendor_dir/$namespace/" . str_replace('\\', '/', $class_name) . ".php";
221 226
 
222
-									if (file_exists($class_file))
223
-										require_once $class_file;
227
+									if (file_exists($class_file)) {
228
+																			require_once $class_file;
229
+									}
224 230
 								}
225 231
 							}
226 232
 						});
@@ -245,18 +251,24 @@  discard block
 block discarded – undo
245 251
 					switch ($kind) {
246 252
 					case $this::KIND_SYSTEM:
247 253
 						if ($this->is_system($plugin)) {
248
-							if (!$skip_init) $plugin->init($this);
254
+							if (!$skip_init) {
255
+								$plugin->init($this);
256
+							}
249 257
 							$this->register_plugin($class, $plugin);
250 258
 						}
251 259
 						break;
252 260
 					case $this::KIND_USER:
253 261
 						if (!$this->is_system($plugin)) {
254
-							if (!$skip_init) $plugin->init($this);
262
+							if (!$skip_init) {
263
+								$plugin->init($this);
264
+							}
255 265
 							$this->register_plugin($class, $plugin);
256 266
 						}
257 267
 						break;
258 268
 					case $this::KIND_ALL:
259
-						if (!$skip_init) $plugin->init($this);
269
+						if (!$skip_init) {
270
+							$plugin->init($this);
271
+						}
260 272
 						$this->register_plugin($class, $plugin);
261 273
 						break;
262 274
 					}
@@ -367,8 +379,9 @@  discard block
 block discarded – undo
367 379
 				owner_uid= ? AND name = ?");
368 380
 			$sth->execute([$this->owner_uid, $plugin]);
369 381
 
370
-			if (!isset($this->storage[$plugin]))
371
-				$this->storage[$plugin] = array();
382
+			if (!isset($this->storage[$plugin])) {
383
+							$this->storage[$plugin] = array();
384
+			}
372 385
 
373 386
 			$content = serialize($this->storage[$plugin]);
374 387
 
@@ -391,12 +404,15 @@  discard block
 block discarded – undo
391 404
 	public function set($sender, $name, $value, $sync = true) {
392 405
 		$idx = get_class($sender);
393 406
 
394
-		if (!isset($this->storage[$idx]))
395
-			$this->storage[$idx] = array();
407
+		if (!isset($this->storage[$idx])) {
408
+					$this->storage[$idx] = array();
409
+		}
396 410
 
397 411
 		$this->storage[$idx][$name] = $value;
398 412
 
399
-		if ($sync) $this->save_data(get_class($sender));
413
+		if ($sync) {
414
+			$this->save_data(get_class($sender));
415
+		}
400 416
 	}
401 417
 
402 418
 	public function get($sender, $name, $default_value = false) {
@@ -433,7 +449,9 @@  discard block
 block discarded – undo
433 449
 
434 450
 	// cat_id: only -1 is supported (Special)
435 451
 	public function add_feed($cat_id, $title, $icon, $sender) {
436
-		if (!$this->feeds[$cat_id]) $this->feeds[$cat_id] = array();
452
+		if (!$this->feeds[$cat_id]) {
453
+			$this->feeds[$cat_id] = array();
454
+		}
437 455
 
438 456
 		$id = count($this->feeds[$cat_id]);
439 457
 
@@ -479,8 +497,9 @@  discard block
 block discarded – undo
479 497
 	public function add_filter_action($sender, $action_name, $action_desc) {
480 498
 		$sender_class = get_class($sender);
481 499
 
482
-		if (!isset($this->plugin_actions[$sender_class]))
483
-			$this->plugin_actions[$sender_class] = array();
500
+		if (!isset($this->plugin_actions[$sender_class])) {
501
+					$this->plugin_actions[$sender_class] = array();
502
+		}
484 503
 
485 504
 		array_push($this->plugin_actions[$sender_class],
486 505
 			array("action" => $action_name, "description" => $action_desc, "sender" => $sender));
Please login to merge, or discard this patch.
classes/opml.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 			$cat_title = htmlspecialchars($row['title']);
71 71
 
72 72
 			if ($include_settings) {
73
-				$order_id = (int)$row["order_id"];
73
+				$order_id = (int) $row["order_id"];
74 74
 				$ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\"";
75 75
 			}
76 76
 		} else {
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 			$site_url = htmlspecialchars($fline["site_url"]);
104 104
 
105 105
 			if ($include_settings) {
106
-				$update_interval = (int)$fline["update_interval"];
107
-				$order_id = (int)$fline["order_id"];
106
+				$update_interval = (int) $fline["update_interval"];
107
+				$order_id = (int) $fline["order_id"];
108 108
 
109 109
 				$ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\" ttrssUpdateInterval=\"$update_interval\"";
110 110
 			} else {
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 
131 131
 		if (!isset($_REQUEST["debug"])) {
132 132
 			header("Content-type: application/xml+opml");
133
-			header("Content-Disposition: attachment; filename=" . $name );
133
+			header("Content-Disposition: attachment; filename=".$name);
134 134
 		} else {
135 135
 			header("Content-type: text/xml");
136 136
 		}
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 
140 140
 		$out .= "<opml version=\"1.0\">";
141 141
 		$out .= "<head>
142
-			<dateCreated>" . date("r", time()) . "</dateCreated>
142
+			<dateCreated>" . date("r", time())."</dateCreated>
143 143
 			<title>Tiny Tiny RSS Feed Export</title>
144 144
 		</head>";
145 145
 		$out .= "<body>";
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 					    foreach (json_decode($tmp_line["match_on"], true) as $feed_id) {
215 215
 
216 216
                             if (strpos($feed_id, "CAT:") === 0) {
217
-                                $feed_id = (int)substr($feed_id, 4);
217
+                                $feed_id = (int) substr($feed_id, 4);
218 218
                                 if ($feed_id) {
219 219
                                     array_push($match, [Feeds::getCategoryTitle($feed_id), true, false]);
220 220
                                 } else {
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
                                 }
223 223
                             } else {
224 224
                                 if ($feed_id) {
225
-                                    array_push($match, [Feeds::getFeedTitle((int)$feed_id), false, false]);
225
+                                    array_push($match, [Feeds::getFeedTitle((int) $feed_id), false, false]);
226 226
                                 } else {
227 227
                                     array_push($match, [0, false, true]);
228 228
                                 }
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 						        list ($name, $is_cat, $is_id) = $match;
410 410
 
411 411
 						        if ($is_id) {
412
-						            array_push($match_on, ($is_cat ? "CAT:" : "") . $name);
412
+						            array_push($match_on, ($is_cat ? "CAT:" : "").$name);
413 413
                                 } else {
414 414
 
415 415
                                     if (!$is_cat) {
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
                             }
439 439
 
440 440
                             $reg_exp = $rule["reg_exp"];
441
-                            $filter_type = (int)$rule["filter_type"];
441
+                            $filter_type = (int) $rule["filter_type"];
442 442
                             $inverse = bool_to_sql_bool($rule["inverse"]);
443 443
                             $match_on = json_encode($match_on);
444 444
 
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
 
473 473
                             $cat_filter = bool_to_sql_bool($rule["cat_filter"]);
474 474
                             $reg_exp = $rule["reg_exp"];
475
-                            $filter_type = (int)$rule["filter_type"];
475
+                            $filter_type = (int) $rule["filter_type"];
476 476
                             $inverse = bool_to_sql_bool($rule["inverse"]);
477 477
 
478 478
                             $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_rules
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 
486 486
 					foreach ($filter["actions"] as $action) {
487 487
 
488
-						$action_id = (int)$action["action_id"];
488
+						$action_id = (int) $action["action_id"];
489 489
 						$action_param = $action["action_param"];
490 490
 
491 491
 						$usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_actions
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
 		}
586 586
 
587 587
 		if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) {
588
-			$tmp_file = tempnam(CACHE_DIR . '/upload', 'opml');
588
+			$tmp_file = tempnam(CACHE_DIR.'/upload', 'opml');
589 589
 
590 590
 			$result = move_uploaded_file($_FILES['opml_file']['tmp_name'],
591 591
 				$tmp_file);
@@ -623,10 +623,10 @@  discard block
 block discarded – undo
623 623
 		print "$msg<br/>";
624 624
 	}
625 625
 
626
-	public static function opml_publish_url(){
626
+	public static function opml_publish_url() {
627 627
 
628 628
 		$url_path = get_self_url_prefix();
629
-		$url_path .= "/opml.php?op=publish&key=" .
629
+		$url_path .= "/opml.php?op=publish&key=".
630 630
 			Feeds::get_feed_access_key('OPML:Publish', false, $_SESSION["uid"]);
631 631
 
632 632
 		return $url_path;
Please login to merge, or discard this patch.
Braces   +47 added lines, -21 removed lines patch added patch discarded remove patch
@@ -52,10 +52,11 @@  discard block
 block discarded – undo
52 52
 
53 53
 		$cat_id = (int) $cat_id;
54 54
 
55
-		if ($hide_private_feeds)
56
-			$hide_qpart = "(private IS false AND auth_login = '' AND auth_pass = '')";
57
-		else
58
-			$hide_qpart = "true";
55
+		if ($hide_private_feeds) {
56
+					$hide_qpart = "(private IS false AND auth_login = '' AND auth_pass = '')";
57
+		} else {
58
+					$hide_qpart = "true";
59
+		}
59 60
 
60 61
 		$out = "";
61 62
 
@@ -77,7 +78,9 @@  discard block
 block discarded – undo
77 78
 			$cat_title = "";
78 79
 		}
79 80
 
80
-		if ($cat_title) $out .= "<outline text=\"$cat_title\" $ttrss_specific_qpart>\n";
81
+		if ($cat_title) {
82
+			$out .= "<outline text=\"$cat_title\" $ttrss_specific_qpart>\n";
83
+		}
81 84
 
82 85
 		$sth = $this->pdo->prepare("SELECT id,title
83 86
 			FROM ttrss_feed_categories WHERE
@@ -120,13 +123,17 @@  discard block
 block discarded – undo
120 123
 			$out .= "<outline type=\"rss\" text=\"$title\" xmlUrl=\"$url\" $ttrss_specific_qpart $html_url_qpart/>\n";
121 124
 		}
122 125
 
123
-		if ($cat_title) $out .= "</outline>\n";
126
+		if ($cat_title) {
127
+			$out .= "</outline>\n";
128
+		}
124 129
 
125 130
 		return $out;
126 131
 	}
127 132
 
128 133
 	public function opml_export($name, $owner_uid, $hide_private_feeds = false, $include_settings = true) {
129
-		if (!$owner_uid) return;
134
+		if (!$owner_uid) {
135
+			return;
136
+		}
130 137
 
131 138
 		if (!isset($_REQUEST["debug"])) {
132 139
 			header("Content-type: application/xml+opml");
@@ -275,8 +282,9 @@  discard block
 block discarded – undo
275 282
 
276 283
 		// cleanup empty categories
277 284
 		foreach ($outlines as $node) {
278
-			if ($node->getElementsByTagName('outline')->length == 0)
279
-				$node->parentNode->removeChild($node);
285
+			if ($node->getElementsByTagName('outline')->length == 0) {
286
+							$node->parentNode->removeChild($node);
287
+			}
280 288
 		}
281 289
 
282 290
 		$res = $doc->saveXML();
@@ -297,10 +305,14 @@  discard block
 block discarded – undo
297 305
 		$attrs = $node->attributes;
298 306
 
299 307
 		$feed_title = mb_substr($attrs->getNamedItem('text')->nodeValue, 0, 250);
300
-		if (!$feed_title) $feed_title = mb_substr($attrs->getNamedItem('title')->nodeValue, 0, 250);
308
+		if (!$feed_title) {
309
+			$feed_title = mb_substr($attrs->getNamedItem('title')->nodeValue, 0, 250);
310
+		}
301 311
 
302 312
 		$feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue;
303
-		if (!$feed_url) $feed_url = $attrs->getNamedItem('xmlURL')->nodeValue;
313
+		if (!$feed_url) {
314
+			$feed_url = $attrs->getNamedItem('xmlURL')->nodeValue;
315
+		}
304 316
 
305 317
 		$site_url = mb_substr($attrs->getNamedItem('htmlUrl')->nodeValue, 0, 250);
306 318
 
@@ -309,19 +321,27 @@  discard block
 block discarded – undo
309 321
 				feed_url = ? AND owner_uid = ?");
310 322
 			$sth->execute([$feed_url, $owner_uid]);
311 323
 
312
-			if (!$feed_title) $feed_title = '[Unknown]';
324
+			if (!$feed_title) {
325
+				$feed_title = '[Unknown]';
326
+			}
313 327
 
314 328
 			if (!$sth->fetch()) {
315 329
 				#$this->opml_notice("[FEED] [$feed_title/$feed_url] dst_CAT=$cat_id");
316 330
 				$this->opml_notice(T_sprintf("Adding feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title));
317 331
 
318
-				if (!$cat_id) $cat_id = null;
332
+				if (!$cat_id) {
333
+					$cat_id = null;
334
+				}
319 335
 
320 336
 				$update_interval = (int) $attrs->getNamedItem('ttrssUpdateInterval')->nodeValue;
321
-				if (!$update_interval) $update_interval = 0;
337
+				if (!$update_interval) {
338
+					$update_interval = 0;
339
+				}
322 340
 
323 341
 				$order_id = (int) $attrs->getNamedItem('ttrssSortOrder')->nodeValue;
324
-				if (!$order_id) $order_id = 0;
342
+				if (!$order_id) {
343
+					$order_id = 0;
344
+				}
325 345
 
326 346
 				$sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
327 347
 					(title, feed_url, owner_uid, cat_id, site_url, order_id, update_interval) VALUES
@@ -505,15 +525,18 @@  discard block
 block discarded – undo
505 525
 		if ($root_node) {
506 526
 			$cat_title = mb_substr($root_node->attributes->getNamedItem('text')->nodeValue, 0, 250);
507 527
 
508
-			if (!$cat_title)
509
-				$cat_title = mb_substr($root_node->attributes->getNamedItem('title')->nodeValue, 0, 250);
528
+			if (!$cat_title) {
529
+							$cat_title = mb_substr($root_node->attributes->getNamedItem('title')->nodeValue, 0, 250);
530
+			}
510 531
 
511 532
 			if (!in_array($cat_title, array("tt-rss-filters", "tt-rss-labels", "tt-rss-prefs"))) {
512 533
 				$cat_id = $this->get_feed_category($cat_title, $parent_id);
513 534
 
514 535
 				if ($cat_id === false) {
515 536
 					$order_id = (int) $root_node->attributes->getNamedItem('ttrssSortOrder')->nodeValue;
516
-					if (!$order_id) $order_id = 0;
537
+					if (!$order_id) {
538
+						$order_id = 0;
539
+					}
517 540
 
518 541
 					Feeds::add_feed_category($cat_title, $parent_id, $order_id);
519 542
 					$cat_id = $this->get_feed_category($cat_title, $parent_id);
@@ -540,8 +563,9 @@  discard block
 block discarded – undo
540 563
 				$attrs = $node->attributes;
541 564
 				$node_cat_title = $attrs->getNamedItem('text')->nodeValue;
542 565
 
543
-				if (!$node_cat_title)
544
-					$node_cat_title = $attrs->getNamedItem('title')->nodeValue;
566
+				if (!$node_cat_title) {
567
+									$node_cat_title = $attrs->getNamedItem('title')->nodeValue;
568
+				}
545 569
 
546 570
 				$node_feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue;
547 571
 
@@ -574,7 +598,9 @@  discard block
 block discarded – undo
574 598
 	}
575 599
 
576 600
 	public function opml_import($owner_uid) {
577
-		if (!$owner_uid) return;
601
+		if (!$owner_uid) {
602
+			return;
603
+		}
578 604
 
579 605
 		$doc = false;
580 606
 
Please login to merge, or discard this patch.
include/colors.php 3 patches
Indentation   +304 added lines, -304 removed lines patch added patch discarded remove patch
@@ -1,355 +1,355 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (file_exists("lib/floIcon.php")) {
4
-    require_once "lib/floIcon.php";
4
+	require_once "lib/floIcon.php";
5 5
 }
6 6
 
7 7
 function _resolve_htmlcolor($color) {
8
-    $htmlcolors = array(
9
-        "aliceblue" => "#f0f8ff",
10
-        "antiquewhite" => "#faebd7",
11
-        "aqua" => "#00ffff",
12
-        "aquamarine" => "#7fffd4",
13
-        "azure" => "#f0ffff",
14
-        "beige" => "#f5f5dc",
15
-        "bisque" => "#ffe4c4",
16
-        "black" => "#000000",
17
-        "blanchedalmond" => "#ffebcd",
18
-        "blue" => "#0000ff",
19
-        "blueviolet" => "#8a2be2",
20
-        "brown" => "#a52a2a",
21
-        "burlywood" => "#deb887",
22
-        "cadetblue" => "#5f9ea0",
23
-        "chartreuse" => "#7fff00",
24
-        "chocolate" => "#d2691e",
25
-        "coral" => "#ff7f50",
26
-        "cornflowerblue" => "#6495ed",
27
-        "cornsilk" => "#fff8dc",
28
-        "crimson" => "#dc143c",
29
-        "cyan" => "#00ffff",
30
-        "darkblue" => "#00008b",
31
-        "darkcyan" => "#008b8b",
32
-        "darkgoldenrod" => "#b8860b",
33
-        "darkgray" => "#a9a9a9",
34
-        "darkgrey" => "#a9a9a9",
35
-        "darkgreen" => "#006400",
36
-        "darkkhaki" => "#bdb76b",
37
-        "darkmagenta" => "#8b008b",
38
-        "darkolivegreen" => "#556b2f",
39
-        "darkorange" => "#ff8c00",
40
-        "darkorchid" => "#9932cc",
41
-        "darkred" => "#8b0000",
42
-        "darksalmon" => "#e9967a",
43
-        "darkseagreen" => "#8fbc8f",
44
-        "darkslateblue" => "#483d8b",
45
-        "darkslategray" => "#2f4f4f",
46
-        "darkslategrey" => "#2f4f4f",
47
-        "darkturquoise" => "#00ced1",
48
-        "darkviolet" => "#9400d3",
49
-        "deeppink" => "#ff1493",
50
-        "deepskyblue" => "#00bfff",
51
-        "dimgray" => "#696969",
52
-        "dimgrey" => "#696969",
53
-        "dodgerblue" => "#1e90ff",
54
-        "firebrick" => "#b22222",
55
-        "floralwhite" => "#fffaf0",
56
-        "forestgreen" => "#228b22",
57
-        "fuchsia" => "#ff00ff",
58
-        "gainsboro" => "#dcdcdc",
59
-        "ghostwhite" => "#f8f8ff",
60
-        "gold" => "#ffd700",
61
-        "goldenrod" => "#daa520",
62
-        "gray" => "#808080",
63
-        "grey" => "#808080",
64
-        "green" => "#008000",
65
-        "greenyellow" => "#adff2f",
66
-        "honeydew" => "#f0fff0",
67
-        "hotpink" => "#ff69b4",
68
-        "indianred " => "#cd5c5c",
69
-        "indigo " => "#4b0082",
70
-        "ivory" => "#fffff0",
71
-        "khaki" => "#f0e68c",
72
-        "lavender" => "#e6e6fa",
73
-        "lavenderblush" => "#fff0f5",
74
-        "lawngreen" => "#7cfc00",
75
-        "lemonchiffon" => "#fffacd",
76
-        "lightblue" => "#add8e6",
77
-        "lightcoral" => "#f08080",
78
-        "lightcyan" => "#e0ffff",
79
-        "lightgoldenrodyellow" => "#fafad2",
80
-        "lightgray" => "#d3d3d3",
81
-        "lightgrey" => "#d3d3d3",
82
-        "lightgreen" => "#90ee90",
83
-        "lightpink" => "#ffb6c1",
84
-        "lightsalmon" => "#ffa07a",
85
-        "lightseagreen" => "#20b2aa",
86
-        "lightskyblue" => "#87cefa",
87
-        "lightslategray" => "#778899",
88
-        "lightslategrey" => "#778899",
89
-        "lightsteelblue" => "#b0c4de",
90
-        "lightyellow" => "#ffffe0",
91
-        "lime" => "#00ff00",
92
-        "limegreen" => "#32cd32",
93
-        "linen" => "#faf0e6",
94
-        "magenta" => "#ff00ff",
95
-        "maroon" => "#800000",
96
-        "mediumaquamarine" => "#66cdaa",
97
-        "mediumblue" => "#0000cd",
98
-        "mediumorchid" => "#ba55d3",
99
-        "mediumpurple" => "#9370db",
100
-        "mediumseagreen" => "#3cb371",
101
-        "mediumslateblue" => "#7b68ee",
102
-        "mediumspringgreen" => "#00fa9a",
103
-        "mediumturquoise" => "#48d1cc",
104
-        "mediumvioletred" => "#c71585",
105
-        "midnightblue" => "#191970",
106
-        "mintcream" => "#f5fffa",
107
-        "mistyrose" => "#ffe4e1",
108
-        "moccasin" => "#ffe4b5",
109
-        "navajowhite" => "#ffdead",
110
-        "navy" => "#000080",
111
-        "oldlace" => "#fdf5e6",
112
-        "olive" => "#808000",
113
-        "olivedrab" => "#6b8e23",
114
-        "orange" => "#ffa500",
115
-        "orangered" => "#ff4500",
116
-        "orchid" => "#da70d6",
117
-        "palegoldenrod" => "#eee8aa",
118
-        "palegreen" => "#98fb98",
119
-        "paleturquoise" => "#afeeee",
120
-        "palevioletred" => "#db7093",
121
-        "papayawhip" => "#ffefd5",
122
-        "peachpuff" => "#ffdab9",
123
-        "peru" => "#cd853f",
124
-        "pink" => "#ffc0cb",
125
-        "plum" => "#dda0dd",
126
-        "powderblue" => "#b0e0e6",
127
-        "purple" => "#800080",
128
-        "red" => "#ff0000",
129
-        "rosybrown" => "#bc8f8f",
130
-        "royalblue" => "#4169e1",
131
-        "saddlebrown" => "#8b4513",
132
-        "salmon" => "#fa8072",
133
-        "sandybrown" => "#f4a460",
134
-        "seagreen" => "#2e8b57",
135
-        "seashell" => "#fff5ee",
136
-        "sienna" => "#a0522d",
137
-        "silver" => "#c0c0c0",
138
-        "skyblue" => "#87ceeb",
139
-        "slateblue" => "#6a5acd",
140
-        "slategray" => "#708090",
141
-        "slategrey" => "#708090",
142
-        "snow" => "#fffafa",
143
-        "springgreen" => "#00ff7f",
144
-        "steelblue" => "#4682b4",
145
-        "tan" => "#d2b48c",
146
-        "teal" => "#008080",
147
-        "thistle" => "#d8bfd8",
148
-        "tomato" => "#ff6347",
149
-        "turquoise" => "#40e0d0",
150
-        "violet" => "#ee82ee",
151
-        "wheat" => "#f5deb3",
152
-        "white" => "#ffffff",
153
-        "whitesmoke" => "#f5f5f5",
154
-        "yellow" => "#ffff00",
155
-        "yellowgreen" => "#9acd32"
156
-    );
157
-
158
-    $color = strtolower($color);
159
-
160
-    if (isset($htmlcolors[$color]))
161
-        return $htmlcolors[$color];
162
-    else
163
-        return $color;
8
+	$htmlcolors = array(
9
+		"aliceblue" => "#f0f8ff",
10
+		"antiquewhite" => "#faebd7",
11
+		"aqua" => "#00ffff",
12
+		"aquamarine" => "#7fffd4",
13
+		"azure" => "#f0ffff",
14
+		"beige" => "#f5f5dc",
15
+		"bisque" => "#ffe4c4",
16
+		"black" => "#000000",
17
+		"blanchedalmond" => "#ffebcd",
18
+		"blue" => "#0000ff",
19
+		"blueviolet" => "#8a2be2",
20
+		"brown" => "#a52a2a",
21
+		"burlywood" => "#deb887",
22
+		"cadetblue" => "#5f9ea0",
23
+		"chartreuse" => "#7fff00",
24
+		"chocolate" => "#d2691e",
25
+		"coral" => "#ff7f50",
26
+		"cornflowerblue" => "#6495ed",
27
+		"cornsilk" => "#fff8dc",
28
+		"crimson" => "#dc143c",
29
+		"cyan" => "#00ffff",
30
+		"darkblue" => "#00008b",
31
+		"darkcyan" => "#008b8b",
32
+		"darkgoldenrod" => "#b8860b",
33
+		"darkgray" => "#a9a9a9",
34
+		"darkgrey" => "#a9a9a9",
35
+		"darkgreen" => "#006400",
36
+		"darkkhaki" => "#bdb76b",
37
+		"darkmagenta" => "#8b008b",
38
+		"darkolivegreen" => "#556b2f",
39
+		"darkorange" => "#ff8c00",
40
+		"darkorchid" => "#9932cc",
41
+		"darkred" => "#8b0000",
42
+		"darksalmon" => "#e9967a",
43
+		"darkseagreen" => "#8fbc8f",
44
+		"darkslateblue" => "#483d8b",
45
+		"darkslategray" => "#2f4f4f",
46
+		"darkslategrey" => "#2f4f4f",
47
+		"darkturquoise" => "#00ced1",
48
+		"darkviolet" => "#9400d3",
49
+		"deeppink" => "#ff1493",
50
+		"deepskyblue" => "#00bfff",
51
+		"dimgray" => "#696969",
52
+		"dimgrey" => "#696969",
53
+		"dodgerblue" => "#1e90ff",
54
+		"firebrick" => "#b22222",
55
+		"floralwhite" => "#fffaf0",
56
+		"forestgreen" => "#228b22",
57
+		"fuchsia" => "#ff00ff",
58
+		"gainsboro" => "#dcdcdc",
59
+		"ghostwhite" => "#f8f8ff",
60
+		"gold" => "#ffd700",
61
+		"goldenrod" => "#daa520",
62
+		"gray" => "#808080",
63
+		"grey" => "#808080",
64
+		"green" => "#008000",
65
+		"greenyellow" => "#adff2f",
66
+		"honeydew" => "#f0fff0",
67
+		"hotpink" => "#ff69b4",
68
+		"indianred " => "#cd5c5c",
69
+		"indigo " => "#4b0082",
70
+		"ivory" => "#fffff0",
71
+		"khaki" => "#f0e68c",
72
+		"lavender" => "#e6e6fa",
73
+		"lavenderblush" => "#fff0f5",
74
+		"lawngreen" => "#7cfc00",
75
+		"lemonchiffon" => "#fffacd",
76
+		"lightblue" => "#add8e6",
77
+		"lightcoral" => "#f08080",
78
+		"lightcyan" => "#e0ffff",
79
+		"lightgoldenrodyellow" => "#fafad2",
80
+		"lightgray" => "#d3d3d3",
81
+		"lightgrey" => "#d3d3d3",
82
+		"lightgreen" => "#90ee90",
83
+		"lightpink" => "#ffb6c1",
84
+		"lightsalmon" => "#ffa07a",
85
+		"lightseagreen" => "#20b2aa",
86
+		"lightskyblue" => "#87cefa",
87
+		"lightslategray" => "#778899",
88
+		"lightslategrey" => "#778899",
89
+		"lightsteelblue" => "#b0c4de",
90
+		"lightyellow" => "#ffffe0",
91
+		"lime" => "#00ff00",
92
+		"limegreen" => "#32cd32",
93
+		"linen" => "#faf0e6",
94
+		"magenta" => "#ff00ff",
95
+		"maroon" => "#800000",
96
+		"mediumaquamarine" => "#66cdaa",
97
+		"mediumblue" => "#0000cd",
98
+		"mediumorchid" => "#ba55d3",
99
+		"mediumpurple" => "#9370db",
100
+		"mediumseagreen" => "#3cb371",
101
+		"mediumslateblue" => "#7b68ee",
102
+		"mediumspringgreen" => "#00fa9a",
103
+		"mediumturquoise" => "#48d1cc",
104
+		"mediumvioletred" => "#c71585",
105
+		"midnightblue" => "#191970",
106
+		"mintcream" => "#f5fffa",
107
+		"mistyrose" => "#ffe4e1",
108
+		"moccasin" => "#ffe4b5",
109
+		"navajowhite" => "#ffdead",
110
+		"navy" => "#000080",
111
+		"oldlace" => "#fdf5e6",
112
+		"olive" => "#808000",
113
+		"olivedrab" => "#6b8e23",
114
+		"orange" => "#ffa500",
115
+		"orangered" => "#ff4500",
116
+		"orchid" => "#da70d6",
117
+		"palegoldenrod" => "#eee8aa",
118
+		"palegreen" => "#98fb98",
119
+		"paleturquoise" => "#afeeee",
120
+		"palevioletred" => "#db7093",
121
+		"papayawhip" => "#ffefd5",
122
+		"peachpuff" => "#ffdab9",
123
+		"peru" => "#cd853f",
124
+		"pink" => "#ffc0cb",
125
+		"plum" => "#dda0dd",
126
+		"powderblue" => "#b0e0e6",
127
+		"purple" => "#800080",
128
+		"red" => "#ff0000",
129
+		"rosybrown" => "#bc8f8f",
130
+		"royalblue" => "#4169e1",
131
+		"saddlebrown" => "#8b4513",
132
+		"salmon" => "#fa8072",
133
+		"sandybrown" => "#f4a460",
134
+		"seagreen" => "#2e8b57",
135
+		"seashell" => "#fff5ee",
136
+		"sienna" => "#a0522d",
137
+		"silver" => "#c0c0c0",
138
+		"skyblue" => "#87ceeb",
139
+		"slateblue" => "#6a5acd",
140
+		"slategray" => "#708090",
141
+		"slategrey" => "#708090",
142
+		"snow" => "#fffafa",
143
+		"springgreen" => "#00ff7f",
144
+		"steelblue" => "#4682b4",
145
+		"tan" => "#d2b48c",
146
+		"teal" => "#008080",
147
+		"thistle" => "#d8bfd8",
148
+		"tomato" => "#ff6347",
149
+		"turquoise" => "#40e0d0",
150
+		"violet" => "#ee82ee",
151
+		"wheat" => "#f5deb3",
152
+		"white" => "#ffffff",
153
+		"whitesmoke" => "#f5f5f5",
154
+		"yellow" => "#ffff00",
155
+		"yellowgreen" => "#9acd32"
156
+	);
157
+
158
+	$color = strtolower($color);
159
+
160
+	if (isset($htmlcolors[$color]))
161
+		return $htmlcolors[$color];
162
+	else
163
+		return $color;
164 164
 }
165 165
 
166 166
 ### RGB >> HSL
167 167
 function _color_rgb2hsl($rgb) {
168
-    $r = $rgb[0]; $g = $rgb[1]; $b = $rgb[2];
169
-    $min = min($r, min($g, $b)); $max = max($r, max($g, $b));
170
-    $delta = $max - $min; $l = ($min + $max) / 2; $s = 0;
171
-    if ($l > 0 && $l < 1) {
172
-        $s = $delta / ($l < 0.5 ? (2 * $l) : (2 - 2 * $l));
173
-    }
174
-    $h = 0;
175
-    if ($delta > 0) {
176
-        if ($max == $r && $max != $g) $h += ($g - $b) / $delta;
177
-        if ($max == $g && $max != $b) $h += (2 + ($b - $r) / $delta);
178
-        if ($max == $b && $max != $r) $h += (4 + ($r - $g) / $delta);
179
-        $h /= 6;
180
-    } return array($h, $s, $l);
168
+	$r = $rgb[0]; $g = $rgb[1]; $b = $rgb[2];
169
+	$min = min($r, min($g, $b)); $max = max($r, max($g, $b));
170
+	$delta = $max - $min; $l = ($min + $max) / 2; $s = 0;
171
+	if ($l > 0 && $l < 1) {
172
+		$s = $delta / ($l < 0.5 ? (2 * $l) : (2 - 2 * $l));
173
+	}
174
+	$h = 0;
175
+	if ($delta > 0) {
176
+		if ($max == $r && $max != $g) $h += ($g - $b) / $delta;
177
+		if ($max == $g && $max != $b) $h += (2 + ($b - $r) / $delta);
178
+		if ($max == $b && $max != $r) $h += (4 + ($r - $g) / $delta);
179
+		$h /= 6;
180
+	} return array($h, $s, $l);
181 181
 }
182 182
 
183 183
 ### HSL >> RGB
184 184
 function _color_hsl2rgb($hsl) {
185
-    $h = $hsl[0]; $s = $hsl[1]; $l = $hsl[2];
186
-    $m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l*$s;
187
-    $m1 = $l * 2 - $m2;
188
-    return array(_color_hue2rgb($m1, $m2, $h + 0.33333),
189
-        _color_hue2rgb($m1, $m2, $h),
190
-        _color_hue2rgb($m1, $m2, $h - 0.33333));
185
+	$h = $hsl[0]; $s = $hsl[1]; $l = $hsl[2];
186
+	$m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l*$s;
187
+	$m1 = $l * 2 - $m2;
188
+	return array(_color_hue2rgb($m1, $m2, $h + 0.33333),
189
+		_color_hue2rgb($m1, $m2, $h),
190
+		_color_hue2rgb($m1, $m2, $h - 0.33333));
191 191
 }
192 192
 
193 193
 ### Helper function for _color_hsl2rgb().
194 194
 function _color_hue2rgb($m1, $m2, $h) {
195
-    $h = ($h < 0) ? $h + 1 : (($h > 1) ? $h - 1 : $h);
196
-    if ($h * 6 < 1) return $m1 + ($m2 - $m1) * $h * 6;
197
-    if ($h * 2 < 1) return $m2;
198
-    if ($h * 3 < 2) return $m1 + ($m2 - $m1) * (0.66666 - $h) * 6;
199
-    return $m1;
195
+	$h = ($h < 0) ? $h + 1 : (($h > 1) ? $h - 1 : $h);
196
+	if ($h * 6 < 1) return $m1 + ($m2 - $m1) * $h * 6;
197
+	if ($h * 2 < 1) return $m2;
198
+	if ($h * 3 < 2) return $m1 + ($m2 - $m1) * (0.66666 - $h) * 6;
199
+	return $m1;
200 200
 }
201 201
 
202 202
 ### Convert a hex color into an RGB triplet.
203 203
 function _color_unpack($hex, $normalize = false) {
204 204
 
205
-    if (strpos($hex, '#') !== 0)
206
-        $hex = _resolve_htmlcolor($hex);
207
-    else
208
-        $hex = substr($hex, 1);
209
-
210
-    if (strlen($hex) == 4) {
211
-        $hex = $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3];
212
-    }
213
-    $c = hexdec($hex);
214
-    for ($i = 16; $i >= 0; $i -= 8) {
215
-        $out[] = (($c >> $i) & 0xFF) / ($normalize ? 255 : 1);
216
-    } return $out;
205
+	if (strpos($hex, '#') !== 0)
206
+		$hex = _resolve_htmlcolor($hex);
207
+	else
208
+		$hex = substr($hex, 1);
209
+
210
+	if (strlen($hex) == 4) {
211
+		$hex = $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3];
212
+	}
213
+	$c = hexdec($hex);
214
+	for ($i = 16; $i >= 0; $i -= 8) {
215
+		$out[] = (($c >> $i) & 0xFF) / ($normalize ? 255 : 1);
216
+	} return $out;
217 217
 }
218 218
 
219 219
 ### Convert an RGB triplet to a hex color.
220 220
 function _color_pack($rgb, $normalize = false) {
221
-    foreach ($rgb as $k => $v) {
222
-        $out |= (($v * ($normalize ? 255 : 1)) << (16 - $k * 8));
223
-    }return '#'. str_pad(dechex($out), 6, 0, STR_PAD_LEFT);
221
+	foreach ($rgb as $k => $v) {
222
+		$out |= (($v * ($normalize ? 255 : 1)) << (16 - $k * 8));
223
+	}return '#'. str_pad(dechex($out), 6, 0, STR_PAD_LEFT);
224 224
 }
225 225
 
226 226
 function rgb2hsl($arr) {
227
-    $r = $arr[0];
228
-    $g = $arr[1];
229
-    $b = $arr[2];
227
+	$r = $arr[0];
228
+	$g = $arr[1];
229
+	$b = $arr[2];
230 230
 
231
-    $var_R = ($r / 255);
232
-    $var_G = ($g / 255);
233
-    $var_B = ($b / 255);
231
+	$var_R = ($r / 255);
232
+	$var_G = ($g / 255);
233
+	$var_B = ($b / 255);
234 234
 
235
-    $var_Min = min($var_R, $var_G, $var_B);
236
-    $var_Max = max($var_R, $var_G, $var_B);
237
-    $del_Max = $var_Max - $var_Min;
235
+	$var_Min = min($var_R, $var_G, $var_B);
236
+	$var_Max = max($var_R, $var_G, $var_B);
237
+	$del_Max = $var_Max - $var_Min;
238 238
 
239
-    $v = $var_Max;
239
+	$v = $var_Max;
240 240
 
241
-    if ($del_Max == 0) {
242
-        $h = 0;
243
-        $s = 0;
244
-    } else {
245
-        $s = $del_Max / $var_Max;
241
+	if ($del_Max == 0) {
242
+		$h = 0;
243
+		$s = 0;
244
+	} else {
245
+		$s = $del_Max / $var_Max;
246 246
 
247
-        $del_R = ((($var_Max - $var_R ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
248
-        $del_G = ((($var_Max - $var_G ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
249
-        $del_B = ((($var_Max - $var_B ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
247
+		$del_R = ((($var_Max - $var_R ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
248
+		$del_G = ((($var_Max - $var_G ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
249
+		$del_B = ((($var_Max - $var_B ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
250 250
 
251
-        if      ($var_R == $var_Max) $h = $del_B - $del_G;
252
-        else if ($var_G == $var_Max) $h = (1 / 3 ) + $del_R - $del_B;
253
-        else if ($var_B == $var_Max) $h = (2 / 3 ) + $del_G - $del_R;
251
+		if      ($var_R == $var_Max) $h = $del_B - $del_G;
252
+		else if ($var_G == $var_Max) $h = (1 / 3 ) + $del_R - $del_B;
253
+		else if ($var_B == $var_Max) $h = (2 / 3 ) + $del_G - $del_R;
254 254
 
255
-        if ($h < 0) $h++;
256
-        if ($h > 1) $h--;
257
-    }
255
+		if ($h < 0) $h++;
256
+		if ($h > 1) $h--;
257
+	}
258 258
 
259
-    return array($h, $s, $v);
259
+	return array($h, $s, $v);
260 260
 }
261 261
 
262 262
 function hsl2rgb($arr) {
263
-    $h = $arr[0];
264
-    $s = $arr[1];
265
-    $v = $arr[2];
266
-
267
-    if($s == 0) {
268
-        $r = $g = $B = $v * 255;
269
-    } else {
270
-        $var_H = $h * 6;
271
-        $var_i = floor($var_H );
272
-        $var_1 = $v * (1 - $s );
273
-        $var_2 = $v * (1 - $s * ($var_H - $var_i ) );
274
-        $var_3 = $v * (1 - $s * (1 - ($var_H - $var_i ) ) );
275
-
276
-        if       ($var_i == 0) { $var_R = $v     ; $var_G = $var_3  ; $var_B = $var_1 ; }
277
-        else if  ($var_i == 1) { $var_R = $var_2 ; $var_G = $v      ; $var_B = $var_1 ; }
278
-        else if  ($var_i == 2) { $var_R = $var_1 ; $var_G = $v      ; $var_B = $var_3 ; }
279
-        else if  ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2  ; $var_B = $v     ; }
280
-        else if  ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1  ; $var_B = $v     ; }
281
-        else                   { $var_R = $v     ; $var_G = $var_1  ; $var_B = $var_2 ; }
282
-
283
-        $r = $var_R * 255;
284
-        $g = $var_G * 255;
285
-        $B = $var_B * 255;
286
-    }
287
-    return array($r, $g, $B);
263
+	$h = $arr[0];
264
+	$s = $arr[1];
265
+	$v = $arr[2];
266
+
267
+	if($s == 0) {
268
+		$r = $g = $B = $v * 255;
269
+	} else {
270
+		$var_H = $h * 6;
271
+		$var_i = floor($var_H );
272
+		$var_1 = $v * (1 - $s );
273
+		$var_2 = $v * (1 - $s * ($var_H - $var_i ) );
274
+		$var_3 = $v * (1 - $s * (1 - ($var_H - $var_i ) ) );
275
+
276
+		if       ($var_i == 0) { $var_R = $v     ; $var_G = $var_3  ; $var_B = $var_1 ; }
277
+		else if  ($var_i == 1) { $var_R = $var_2 ; $var_G = $v      ; $var_B = $var_1 ; }
278
+		else if  ($var_i == 2) { $var_R = $var_1 ; $var_G = $v      ; $var_B = $var_3 ; }
279
+		else if  ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2  ; $var_B = $v     ; }
280
+		else if  ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1  ; $var_B = $v     ; }
281
+		else                   { $var_R = $v     ; $var_G = $var_1  ; $var_B = $var_2 ; }
282
+
283
+		$r = $var_R * 255;
284
+		$g = $var_G * 255;
285
+		$B = $var_B * 255;
286
+	}
287
+	return array($r, $g, $B);
288 288
 }
289 289
 
290 290
 function colorPalette($imageFile, $numColors, $granularity = 5) {
291
-    $granularity = max(1, abs((int)$granularity));
292
-    $colors = array();
293
-
294
-    $size = @getimagesize($imageFile);
295
-
296
-    // to enable .ico support place floIcon.php into lib/
297
-    if (strtolower($size['mime']) == 'image/vnd.microsoft.icon') {
298
-
299
-        if (class_exists("floIcon")) {
300
-
301
-            $ico = new floIcon();
302
-            @$ico->readICO($imageFile);
303
-
304
-            if(count($ico->images)==0)
305
-                return false;
306
-            else
307
-                $img = @$ico->images[count($ico->images)-1]->getImageResource();
308
-
309
-        } else {
310
-            return false;
311
-        }
312
-
313
-    } else if ($size[0] > 0 && $size[1] > 0) {
314
-        $img = @imagecreatefromstring(file_get_contents($imageFile));
315
-    }
316
-
317
-    if (!$img) return false;
318
-
319
-    for($x = 0; $x < $size[0]; $x += $granularity) {
320
-        for($y = 0; $y < $size[1]; $y += $granularity) {
321
-            $thisColor = imagecolorat($img, $x, $y);
322
-            $rgb = imagecolorsforindex($img, $thisColor);
323
-            $red = round(round(($rgb['red'] / 0x33)) * 0x33);
324
-            $green = round(round(($rgb['green'] / 0x33)) * 0x33);
325
-            $blue = round(round(($rgb['blue'] / 0x33)) * 0x33);
326
-            $thisRGB = sprintf('%02X%02X%02X', $red, $green, $blue);
327
-            if(array_key_exists($thisRGB, $colors)) {
328
-                $colors[$thisRGB]++;
329
-            } else{
330
-                $colors[$thisRGB] = 1;
331
-            }
332
-        }
333
-    }
334
-
335
-    arsort($colors);
336
-    return array_slice(array_keys($colors), 0, $numColors);
291
+	$granularity = max(1, abs((int)$granularity));
292
+	$colors = array();
293
+
294
+	$size = @getimagesize($imageFile);
295
+
296
+	// to enable .ico support place floIcon.php into lib/
297
+	if (strtolower($size['mime']) == 'image/vnd.microsoft.icon') {
298
+
299
+		if (class_exists("floIcon")) {
300
+
301
+			$ico = new floIcon();
302
+			@$ico->readICO($imageFile);
303
+
304
+			if(count($ico->images)==0)
305
+				return false;
306
+			else
307
+				$img = @$ico->images[count($ico->images)-1]->getImageResource();
308
+
309
+		} else {
310
+			return false;
311
+		}
312
+
313
+	} else if ($size[0] > 0 && $size[1] > 0) {
314
+		$img = @imagecreatefromstring(file_get_contents($imageFile));
315
+	}
316
+
317
+	if (!$img) return false;
318
+
319
+	for($x = 0; $x < $size[0]; $x += $granularity) {
320
+		for($y = 0; $y < $size[1]; $y += $granularity) {
321
+			$thisColor = imagecolorat($img, $x, $y);
322
+			$rgb = imagecolorsforindex($img, $thisColor);
323
+			$red = round(round(($rgb['red'] / 0x33)) * 0x33);
324
+			$green = round(round(($rgb['green'] / 0x33)) * 0x33);
325
+			$blue = round(round(($rgb['blue'] / 0x33)) * 0x33);
326
+			$thisRGB = sprintf('%02X%02X%02X', $red, $green, $blue);
327
+			if(array_key_exists($thisRGB, $colors)) {
328
+				$colors[$thisRGB]++;
329
+			} else{
330
+				$colors[$thisRGB] = 1;
331
+			}
332
+		}
333
+	}
334
+
335
+	arsort($colors);
336
+	return array_slice(array_keys($colors), 0, $numColors);
337 337
 }
338 338
 
339 339
 function calculate_avg_color($iconFile) {
340
-    $palette = colorPalette($iconFile, 4, 4);
340
+	$palette = colorPalette($iconFile, 4, 4);
341 341
 
342
-    if (is_array($palette)) {
343
-        foreach ($palette as $p) {
344
-            $hsl = rgb2hsl(_color_unpack("#$p"));
342
+	if (is_array($palette)) {
343
+		foreach ($palette as $p) {
344
+			$hsl = rgb2hsl(_color_unpack("#$p"));
345 345
 
346
-            if ($hsl[1] > 0.25 && $hsl[2] > 0.25 &&
347
-                !($hsl[0] >= 0 && $hsl[0] < 0.01 && $hsl[1] < 0.01) &&
348
-                !($hsl[0] >= 0 && $hsl[0] < 0.01 && $hsl[2] > 0.99)) {
346
+			if ($hsl[1] > 0.25 && $hsl[2] > 0.25 &&
347
+				!($hsl[0] >= 0 && $hsl[0] < 0.01 && $hsl[1] < 0.01) &&
348
+				!($hsl[0] >= 0 && $hsl[0] < 0.01 && $hsl[2] > 0.99)) {
349 349
 
350
-                return _color_pack(hsl2rgb($hsl));
351
-            }
352
-        }
353
-    }
354
-    return '';
350
+				return _color_pack(hsl2rgb($hsl));
351
+			}
352
+		}
353
+	}
354
+	return '';
355 355
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 ### HSL >> RGB
184 184
 function _color_hsl2rgb($hsl) {
185 185
     $h = $hsl[0]; $s = $hsl[1]; $l = $hsl[2];
186
-    $m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l*$s;
186
+    $m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l * $s;
187 187
     $m1 = $l * 2 - $m2;
188 188
     return array(_color_hue2rgb($m1, $m2, $h + 0.33333),
189 189
         _color_hue2rgb($m1, $m2, $h),
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
         $hex = substr($hex, 1);
209 209
 
210 210
     if (strlen($hex) == 4) {
211
-        $hex = $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3];
211
+        $hex = $hex[1].$hex[1].$hex[2].$hex[2].$hex[3].$hex[3];
212 212
     }
213 213
     $c = hexdec($hex);
214 214
     for ($i = 16; $i >= 0; $i -= 8) {
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 function _color_pack($rgb, $normalize = false) {
221 221
     foreach ($rgb as $k => $v) {
222 222
         $out |= (($v * ($normalize ? 255 : 1)) << (16 - $k * 8));
223
-    }return '#'. str_pad(dechex($out), 6, 0, STR_PAD_LEFT);
223
+    }return '#'.str_pad(dechex($out), 6, 0, STR_PAD_LEFT);
224 224
 }
225 225
 
226 226
 function rgb2hsl($arr) {
@@ -244,13 +244,13 @@  discard block
 block discarded – undo
244 244
     } else {
245 245
         $s = $del_Max / $var_Max;
246 246
 
247
-        $del_R = ((($var_Max - $var_R ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
248
-        $del_G = ((($var_Max - $var_G ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
249
-        $del_B = ((($var_Max - $var_B ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
247
+        $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
248
+        $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
249
+        $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
250 250
 
251
-        if      ($var_R == $var_Max) $h = $del_B - $del_G;
252
-        else if ($var_G == $var_Max) $h = (1 / 3 ) + $del_R - $del_B;
253
-        else if ($var_B == $var_Max) $h = (2 / 3 ) + $del_G - $del_R;
251
+        if ($var_R == $var_Max) $h = $del_B - $del_G;
252
+        else if ($var_G == $var_Max) $h = (1 / 3) + $del_R - $del_B;
253
+        else if ($var_B == $var_Max) $h = (2 / 3) + $del_G - $del_R;
254 254
 
255 255
         if ($h < 0) $h++;
256 256
         if ($h > 1) $h--;
@@ -264,21 +264,21 @@  discard block
 block discarded – undo
264 264
     $s = $arr[1];
265 265
     $v = $arr[2];
266 266
 
267
-    if($s == 0) {
267
+    if ($s == 0) {
268 268
         $r = $g = $B = $v * 255;
269 269
     } else {
270 270
         $var_H = $h * 6;
271
-        $var_i = floor($var_H );
272
-        $var_1 = $v * (1 - $s );
273
-        $var_2 = $v * (1 - $s * ($var_H - $var_i ) );
274
-        $var_3 = $v * (1 - $s * (1 - ($var_H - $var_i ) ) );
275
-
276
-        if       ($var_i == 0) { $var_R = $v     ; $var_G = $var_3  ; $var_B = $var_1 ; }
277
-        else if  ($var_i == 1) { $var_R = $var_2 ; $var_G = $v      ; $var_B = $var_1 ; }
278
-        else if  ($var_i == 2) { $var_R = $var_1 ; $var_G = $v      ; $var_B = $var_3 ; }
279
-        else if  ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2  ; $var_B = $v     ; }
280
-        else if  ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1  ; $var_B = $v     ; }
281
-        else                   { $var_R = $v     ; $var_G = $var_1  ; $var_B = $var_2 ; }
271
+        $var_i = floor($var_H);
272
+        $var_1 = $v * (1 - $s);
273
+        $var_2 = $v * (1 - $s * ($var_H - $var_i));
274
+        $var_3 = $v * (1 - $s * (1 - ($var_H - $var_i)));
275
+
276
+        if ($var_i == 0) { $var_R = $v; $var_G = $var_3; $var_B = $var_1; }
277
+        else if ($var_i == 1) { $var_R = $var_2; $var_G = $v; $var_B = $var_1; }
278
+        else if ($var_i == 2) { $var_R = $var_1; $var_G = $v; $var_B = $var_3; }
279
+        else if ($var_i == 3) { $var_R = $var_1; $var_G = $var_2; $var_B = $v; }
280
+        else if ($var_i == 4) { $var_R = $var_3; $var_G = $var_1; $var_B = $v; }
281
+        else { $var_R = $v; $var_G = $var_1; $var_B = $var_2; }
282 282
 
283 283
         $r = $var_R * 255;
284 284
         $g = $var_G * 255;
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 }
289 289
 
290 290
 function colorPalette($imageFile, $numColors, $granularity = 5) {
291
-    $granularity = max(1, abs((int)$granularity));
291
+    $granularity = max(1, abs((int) $granularity));
292 292
     $colors = array();
293 293
 
294 294
     $size = @getimagesize($imageFile);
@@ -301,10 +301,10 @@  discard block
 block discarded – undo
301 301
             $ico = new floIcon();
302 302
             @$ico->readICO($imageFile);
303 303
 
304
-            if(count($ico->images)==0)
304
+            if (count($ico->images) == 0)
305 305
                 return false;
306 306
             else
307
-                $img = @$ico->images[count($ico->images)-1]->getImageResource();
307
+                $img = @$ico->images[count($ico->images) - 1]->getImageResource();
308 308
 
309 309
         } else {
310 310
             return false;
@@ -316,17 +316,17 @@  discard block
 block discarded – undo
316 316
 
317 317
     if (!$img) return false;
318 318
 
319
-    for($x = 0; $x < $size[0]; $x += $granularity) {
320
-        for($y = 0; $y < $size[1]; $y += $granularity) {
319
+    for ($x = 0; $x < $size[0]; $x += $granularity) {
320
+        for ($y = 0; $y < $size[1]; $y += $granularity) {
321 321
             $thisColor = imagecolorat($img, $x, $y);
322 322
             $rgb = imagecolorsforindex($img, $thisColor);
323 323
             $red = round(round(($rgb['red'] / 0x33)) * 0x33);
324 324
             $green = round(round(($rgb['green'] / 0x33)) * 0x33);
325 325
             $blue = round(round(($rgb['blue'] / 0x33)) * 0x33);
326 326
             $thisRGB = sprintf('%02X%02X%02X', $red, $green, $blue);
327
-            if(array_key_exists($thisRGB, $colors)) {
327
+            if (array_key_exists($thisRGB, $colors)) {
328 328
                 $colors[$thisRGB]++;
329
-            } else{
329
+            } else {
330 330
                 $colors[$thisRGB] = 1;
331 331
             }
332 332
         }
Please login to merge, or discard this patch.
Braces   +51 added lines, -31 removed lines patch added patch discarded remove patch
@@ -157,11 +157,12 @@  discard block
 block discarded – undo
157 157
 
158 158
     $color = strtolower($color);
159 159
 
160
-    if (isset($htmlcolors[$color]))
161
-        return $htmlcolors[$color];
162
-    else
163
-        return $color;
164
-}
160
+    if (isset($htmlcolors[$color])) {
161
+            return $htmlcolors[$color];
162
+    } else {
163
+            return $color;
164
+    }
165
+    }
165 166
 
166 167
 ### RGB >> HSL
167 168
 function _color_rgb2hsl($rgb) {
@@ -173,9 +174,15 @@  discard block
 block discarded – undo
173 174
     }
174 175
     $h = 0;
175 176
     if ($delta > 0) {
176
-        if ($max == $r && $max != $g) $h += ($g - $b) / $delta;
177
-        if ($max == $g && $max != $b) $h += (2 + ($b - $r) / $delta);
178
-        if ($max == $b && $max != $r) $h += (4 + ($r - $g) / $delta);
177
+        if ($max == $r && $max != $g) {
178
+        	$h += ($g - $b) / $delta;
179
+        }
180
+        if ($max == $g && $max != $b) {
181
+        	$h += (2 + ($b - $r) / $delta);
182
+        }
183
+        if ($max == $b && $max != $r) {
184
+        	$h += (4 + ($r - $g) / $delta);
185
+        }
179 186
         $h /= 6;
180 187
     } return array($h, $s, $l);
181 188
 }
@@ -193,19 +200,26 @@  discard block
 block discarded – undo
193 200
 ### Helper function for _color_hsl2rgb().
194 201
 function _color_hue2rgb($m1, $m2, $h) {
195 202
     $h = ($h < 0) ? $h + 1 : (($h > 1) ? $h - 1 : $h);
196
-    if ($h * 6 < 1) return $m1 + ($m2 - $m1) * $h * 6;
197
-    if ($h * 2 < 1) return $m2;
198
-    if ($h * 3 < 2) return $m1 + ($m2 - $m1) * (0.66666 - $h) * 6;
203
+    if ($h * 6 < 1) {
204
+    	return $m1 + ($m2 - $m1) * $h * 6;
205
+    }
206
+    if ($h * 2 < 1) {
207
+    	return $m2;
208
+    }
209
+    if ($h * 3 < 2) {
210
+    	return $m1 + ($m2 - $m1) * (0.66666 - $h) * 6;
211
+    }
199 212
     return $m1;
200 213
 }
201 214
 
202 215
 ### Convert a hex color into an RGB triplet.
203 216
 function _color_unpack($hex, $normalize = false) {
204 217
 
205
-    if (strpos($hex, '#') !== 0)
206
-        $hex = _resolve_htmlcolor($hex);
207
-    else
208
-        $hex = substr($hex, 1);
218
+    if (strpos($hex, '#') !== 0) {
219
+            $hex = _resolve_htmlcolor($hex);
220
+    } else {
221
+            $hex = substr($hex, 1);
222
+    }
209 223
 
210 224
     if (strlen($hex) == 4) {
211 225
         $hex = $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3];
@@ -248,12 +262,20 @@  discard block
 block discarded – undo
248 262
         $del_G = ((($var_Max - $var_G ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
249 263
         $del_B = ((($var_Max - $var_B ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
250 264
 
251
-        if      ($var_R == $var_Max) $h = $del_B - $del_G;
252
-        else if ($var_G == $var_Max) $h = (1 / 3 ) + $del_R - $del_B;
253
-        else if ($var_B == $var_Max) $h = (2 / 3 ) + $del_G - $del_R;
265
+        if      ($var_R == $var_Max) {
266
+        	$h = $del_B - $del_G;
267
+        } else if ($var_G == $var_Max) {
268
+        	$h = (1 / 3 ) + $del_R - $del_B;
269
+        } else if ($var_B == $var_Max) {
270
+        	$h = (2 / 3 ) + $del_G - $del_R;
271
+        }
254 272
 
255
-        if ($h < 0) $h++;
256
-        if ($h > 1) $h--;
273
+        if ($h < 0) {
274
+        	$h++;
275
+        }
276
+        if ($h > 1) {
277
+        	$h--;
278
+        }
257 279
     }
258 280
 
259 281
     return array($h, $s, $v);
@@ -273,12 +295,7 @@  discard block
 block discarded – undo
273 295
         $var_2 = $v * (1 - $s * ($var_H - $var_i ) );
274 296
         $var_3 = $v * (1 - $s * (1 - ($var_H - $var_i ) ) );
275 297
 
276
-        if       ($var_i == 0) { $var_R = $v     ; $var_G = $var_3  ; $var_B = $var_1 ; }
277
-        else if  ($var_i == 1) { $var_R = $var_2 ; $var_G = $v      ; $var_B = $var_1 ; }
278
-        else if  ($var_i == 2) { $var_R = $var_1 ; $var_G = $v      ; $var_B = $var_3 ; }
279
-        else if  ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2  ; $var_B = $v     ; }
280
-        else if  ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1  ; $var_B = $v     ; }
281
-        else                   { $var_R = $v     ; $var_G = $var_1  ; $var_B = $var_2 ; }
298
+        if       ($var_i == 0) { $var_R = $v     ; $var_G = $var_3  ; $var_B = $var_1 ; } else if  ($var_i == 1) { $var_R = $var_2 ; $var_G = $v      ; $var_B = $var_1 ; } else if  ($var_i == 2) { $var_R = $var_1 ; $var_G = $v      ; $var_B = $var_3 ; } else if  ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2  ; $var_B = $v     ; } else if  ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1  ; $var_B = $v     ; } else                   { $var_R = $v     ; $var_G = $var_1  ; $var_B = $var_2 ; }
282 299
 
283 300
         $r = $var_R * 255;
284 301
         $g = $var_G * 255;
@@ -301,10 +318,11 @@  discard block
 block discarded – undo
301 318
             $ico = new floIcon();
302 319
             @$ico->readICO($imageFile);
303 320
 
304
-            if(count($ico->images)==0)
305
-                return false;
306
-            else
307
-                $img = @$ico->images[count($ico->images)-1]->getImageResource();
321
+            if(count($ico->images)==0) {
322
+                            return false;
323
+            } else {
324
+                            $img = @$ico->images[count($ico->images)-1]->getImageResource();
325
+            }
308 326
 
309 327
         } else {
310 328
             return false;
@@ -314,7 +332,9 @@  discard block
 block discarded – undo
314 332
         $img = @imagecreatefromstring(file_get_contents($imageFile));
315 333
     }
316 334
 
317
-    if (!$img) return false;
335
+    if (!$img) {
336
+    	return false;
337
+    }
318 338
 
319 339
     for($x = 0; $x < $size[0]; $x += $granularity) {
320 340
         for($y = 0; $y < $size[1]; $y += $granularity) {
Please login to merge, or discard this patch.
include/db-prefs.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,9 +3,9 @@
 block discarded – undo
3 3
 require_once "db.php";
4 4
 
5 5
 function get_pref($pref_name, $user_id = false, $die_on_error = false) {
6
-    return Db_Prefs::get()->read($pref_name, $user_id, $die_on_error);
6
+	return Db_Prefs::get()->read($pref_name, $user_id, $die_on_error);
7 7
 }
8 8
 
9 9
 function set_pref($pref_name, $value, $user_id = false, $strip_tags = true) {
10
-    return Db_Prefs::get()->write($pref_name, $value, $user_id, $strip_tags);
10
+	return Db_Prefs::get()->write($pref_name, $value, $user_id, $strip_tags);
11 11
 }
Please login to merge, or discard this patch.
include/sanity_check.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@
 block discarded – undo
88 88
 			}
89 89
 
90 90
 			if (SINGLE_USER_MODE && class_exists("PDO")) {
91
-			    $pdo = DB::pdo();
91
+				$pdo = DB::pdo();
92 92
 
93 93
 				$res = $pdo->query("SELECT id FROM ttrss_users WHERE id = 1");
94 94
 
Please login to merge, or discard this patch.
include/functions.php 3 patches
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.
Spacing   +53 added lines, -54 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 define('LABEL_BASE_INDEX', -1024);
6 6
 define('PLUGIN_FEED_BASE_INDEX', -128);
7 7
 
8
-define('COOKIE_LIFETIME_LONG', 86400*365);
8
+define('COOKIE_LIFETIME_LONG', 86400 * 365);
9 9
 
10 10
 $fetch_last_error = false;
11 11
 $fetch_last_error_code = false;
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
 // feed limit for one update batch
58 58
 define_default('DAEMON_SLEEP_INTERVAL', 120);
59 59
 // default sleep interval between feed updates (sec)
60
-define_default('MAX_CACHE_FILE_SIZE', 64*1024*1024);
60
+define_default('MAX_CACHE_FILE_SIZE', 64 * 1024 * 1024);
61 61
 // do not cache files larger than that (bytes)
62
-define_default('MAX_DOWNLOAD_FILE_SIZE', 16*1024*1024);
62
+define_default('MAX_DOWNLOAD_FILE_SIZE', 16 * 1024 * 1024);
63 63
 // do not download general files larger than that (bytes)
64 64
 define_default('CACHE_MAX_DAYS', 7);
65 65
 // max age in days for various automatically cached (temporary) files
66
-define_default('MAX_CONDITIONAL_INTERVAL', 3600*12);
66
+define_default('MAX_CONDITIONAL_INTERVAL', 3600 * 12);
67 67
 // max interval between forced unconditional updates for servers
68 68
 // not complying with http if-modified-since (seconds)
69 69
 define_default('MAX_FETCH_REQUESTS_PER_HOST', 25);
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 require_once 'db-prefs.php';
158 158
 require_once 'controls.php';
159 159
 
160
-define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . get_version() . ' (http://tt-rss.org/)');
160
+define('SELF_USER_AGENT', 'Tiny Tiny RSS/'.get_version().' (http://tt-rss.org/)');
161 161
 ini_set('user_agent', SELF_USER_AGENT);
162 162
 
163 163
 $schema_version = false;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     if (!is_array($options)) {
202 202
 
203 203
         // falling back on compatibility shim
204
-        $option_names = [ "url", "type", "login", "pass", "post_query", "timeout", "last_modified", "useragent" ];
204
+        $option_names = ["url", "type", "login", "pass", "post_query", "timeout", "last_modified", "useragent"];
205 205
         $tmp = [];
206 206
 
207 207
         for ($i = 0; $i < func_num_args(); $i++) {
@@ -228,13 +228,13 @@  discard block
 block discarded – undo
228 228
     $url = str_replace(' ', '%20', $url);
229 229
 
230 230
     if (strpos($url, "//") === 0)
231
-        $url = 'http:' . $url;
231
+        $url = 'http:'.$url;
232 232
 
233 233
     $url_host = parse_url($url, PHP_URL_HOST);
234 234
     $fetch_domain_hits[$url_host] += 1;
235 235
 
236 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);
237
+        user_error("Exceeded fetch request quota for $url_host: ".$fetch_domain_hits[$url_host], E_USER_WARNING);
238 238
         #return false;
239 239
     }
240 240
 
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
             array_push($curl_http_headers, "If-Modified-Since: $last_modified");
251 251
 
252 252
         if ($http_accept)
253
-            array_push($curl_http_headers, "Accept: " . $http_accept);
253
+            array_push($curl_http_headers, "Accept: ".$http_accept);
254 254
 
255 255
         if (count($curl_http_headers) > 0)
256 256
             curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_http_headers);
@@ -263,11 +263,10 @@  discard block
 block discarded – undo
263 263
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
264 264
         curl_setopt($ch, CURLOPT_HEADER, true);
265 265
         curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
266
-        curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent :
267
-            SELF_USER_AGENT);
266
+        curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent : SELF_USER_AGENT);
268 267
         curl_setopt($ch, CURLOPT_ENCODING, "");
269 268
 
270
-        if  ($http_referrer)
269
+        if ($http_referrer)
271 270
             curl_setopt($ch, CURLOPT_REFERER, $http_referrer);
272 271
 
273 272
         if ($max_size) {
@@ -276,7 +275,7 @@  discard block
 block discarded – undo
276 275
 
277 276
             // holy shit closures in php
278 277
             // 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) {
278
+            curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curl_handle, $download_size, $downloaded, $upload_size, $uploaded) use(&$max_size) {
280 279
                 Debug::log("[curl progressfunction] $downloaded $max_size", Debug::$LOG_EXTENDED);
281 280
 
282 281
                 return ($downloaded > $max_size) ? 1 : 0; // if max size is set, abort when exceeding it
@@ -336,7 +335,7 @@  discard block
 block discarded – undo
336 335
         if ($http_code != 200 || $type && strpos($fetch_last_content_type, "$type") === false) {
337 336
 
338 337
             if (curl_errno($ch) != 0) {
339
-                $fetch_last_error .=  "; " . curl_errno($ch) . " " . curl_error($ch);
338
+                $fetch_last_error .= "; ".curl_errno($ch)." ".curl_error($ch);
340 339
             }
341 340
 
342 341
             $fetch_last_error_content = $contents;
@@ -345,7 +344,7 @@  discard block
 block discarded – undo
345 344
         }
346 345
 
347 346
         if (!$contents) {
348
-            $fetch_last_error = curl_errno($ch) . " " . curl_error($ch);
347
+            $fetch_last_error = curl_errno($ch)." ".curl_error($ch);
349 348
             curl_close($ch);
350 349
             return false;
351 350
         }
@@ -365,7 +364,7 @@  discard block
 block discarded – undo
365 364
 
366 365
         $fetch_curl_used = false;
367 366
 
368
-        if ($login && $pass){
367
+        if ($login && $pass) {
369 368
             $url_parts = array();
370 369
 
371 370
             preg_match("/(^[^:]*):\/\/(.*)/", $url, $url_parts);
@@ -373,7 +372,7 @@  discard block
 block discarded – undo
373 372
             $pass = urlencode($pass);
374 373
 
375 374
             if ($url_parts[1] && $url_parts[2]) {
376
-                $url = $url_parts[1] . "://$login:$pass@" . $url_parts[2];
375
+                $url = $url_parts[1]."://$login:$pass@".$url_parts[2];
377 376
             }
378 377
         }
379 378
 
@@ -441,7 +440,7 @@  discard block
 block discarded – undo
441 440
             $error = error_get_last();
442 441
 
443 442
             if ($error['message'] != $old_error['message']) {
444
-                $fetch_last_error .= "; " . $error["message"];
443
+                $fetch_last_error .= "; ".$error["message"];
445 444
             }
446 445
 
447 446
             $fetch_last_error_content = $data;
@@ -516,15 +515,15 @@  discard block
 block discarded – undo
516 515
 
517 516
 function get_ssl_certificate_id() {
518 517
     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"] .
518
+        return sha1($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"].
519
+            $_SERVER["REDIRECT_SSL_CLIENT_V_START"].
520
+            $_SERVER["REDIRECT_SSL_CLIENT_V_END"].
522 521
             $_SERVER["REDIRECT_SSL_CLIENT_S_DN"]);
523 522
     }
524 523
     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"] .
524
+        return sha1($_SERVER["SSL_CLIENT_M_SERIAL"].
525
+            $_SERVER["SSL_CLIENT_V_START"].
526
+            $_SERVER["SSL_CLIENT_V_END"].
528 527
             $_SERVER["SSL_CLIENT_S_DN"]);
529 528
     }
530 529
     return "";
@@ -659,7 +658,7 @@  discard block
 block discarded – undo
659 658
 function logout_user() {
660 659
     @session_destroy();
661 660
     if (isset($_COOKIE[session_name()])) {
662
-       setcookie(session_name(), '', time()-42000, '/');
661
+       setcookie(session_name(), '', time() - 42000, '/');
663 662
     }
664 663
     session_commit();
665 664
 }
@@ -743,7 +742,7 @@  discard block
 block discarded – undo
743 742
 
744 743
 function truncate_string($str, $max_len, $suffix = '&hellip;') {
745 744
     if (mb_strlen($str, "utf-8") > $max_len) {
746
-        return mb_substr($str, 0, $max_len, "utf-8") . $suffix;
745
+        return mb_substr($str, 0, $max_len, "utf-8").$suffix;
747 746
     } else {
748 747
         return $str;
749 748
     }
@@ -753,7 +752,7 @@  discard block
 block discarded – undo
753 752
     $startString = mb_substr($original, 0, $position, "UTF-8");
754 753
     $endString = mb_substr($original, $position + $length, mb_strlen($original), "UTF-8");
755 754
 
756
-    $out = $startString . $replacement . $endString;
755
+    $out = $startString.$replacement.$endString;
757 756
 
758 757
     return $out;
759 758
 }
@@ -891,9 +890,9 @@  discard block
 block discarded – undo
891 890
 }
892 891
 
893 892
 function file_is_locked($filename) {
894
-    if (file_exists(LOCK_DIRECTORY . "/$filename")) {
893
+    if (file_exists(LOCK_DIRECTORY."/$filename")) {
895 894
         if (function_exists('flock')) {
896
-            $fp = @fopen(LOCK_DIRECTORY . "/$filename", "r");
895
+            $fp = @fopen(LOCK_DIRECTORY."/$filename", "r");
897 896
             if ($fp) {
898 897
                 if (flock($fp, LOCK_EX | LOCK_NB)) {
899 898
                     flock($fp, LOCK_UN);
@@ -914,11 +913,11 @@  discard block
 block discarded – undo
914 913
 
915 914
 
916 915
 function make_lockfile($filename) {
917
-    $fp = fopen(LOCK_DIRECTORY . "/$filename", "w");
916
+    $fp = fopen(LOCK_DIRECTORY."/$filename", "w");
918 917
 
919 918
     if ($fp && flock($fp, LOCK_EX | LOCK_NB)) {
920 919
         $stat_h = fstat($fp);
921
-        $stat_f = stat(LOCK_DIRECTORY . "/$filename");
920
+        $stat_f = stat(LOCK_DIRECTORY."/$filename");
922 921
 
923 922
         if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
924 923
             if ($stat_h["ino"] != $stat_f["ino"] ||
@@ -929,7 +928,7 @@  discard block
 block discarded – undo
929 928
         }
930 929
 
931 930
         if (function_exists('posix_getpid')) {
932
-            fwrite($fp, posix_getpid() . "\n");
931
+            fwrite($fp, posix_getpid()."\n");
933 932
         }
934 933
         return $fp;
935 934
     } else {
@@ -938,10 +937,10 @@  discard block
 block discarded – undo
938 937
 }
939 938
 
940 939
 function make_stampfile($filename) {
941
-    $fp = fopen(LOCK_DIRECTORY . "/$filename", "w");
940
+    $fp = fopen(LOCK_DIRECTORY."/$filename", "w");
942 941
 
943 942
     if (flock($fp, LOCK_EX | LOCK_NB)) {
944
-        fwrite($fp, time() . "\n");
943
+        fwrite($fp, time()."\n");
945 944
         flock($fp, LOCK_UN);
946 945
         fclose($fp);
947 946
         return true;
@@ -991,7 +990,7 @@  discard block
 block discarded – undo
991 990
     $params["is_default_pw"] = Pref_Prefs::isdefaultpassword();
992 991
     $params["label_base_index"] = (int) LABEL_BASE_INDEX;
993 992
 
994
-    $theme = get_pref( "USER_CSS_THEME", false, false);
993
+    $theme = get_pref("USER_CSS_THEME", false, false);
995 994
     $params["theme"] = theme_exists($theme) ? $theme : "";
996 995
 
997 996
     $params["plugins"] = implode(", ", PluginHost::getInstance()->get_plugin_names());
@@ -1215,13 +1214,13 @@  discard block
 block discarded – undo
1215 1214
         }
1216 1215
     }
1217 1216
 
1218
-    if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
1217
+    if (file_exists(LOCK_DIRECTORY."/update_daemon.lock")) {
1219 1218
 
1220 1219
         $data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock");
1221 1220
 
1222 1221
         if (time() - $_SESSION["daemon_stamp_check"] > 30) {
1223 1222
 
1224
-            $stamp = (int) @file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp");
1223
+            $stamp = (int) @file_get_contents(LOCK_DIRECTORY."/update_daemon.stamp");
1225 1224
 
1226 1225
             if ($stamp) {
1227 1226
                 $stamp_delta = time() - $stamp;
@@ -1264,7 +1263,7 @@  discard block
 block discarded – undo
1264 1263
     $res = trim($str); if (!$res) return '';
1265 1264
 
1266 1265
     $doc = new DOMDocument();
1267
-    $doc->loadHTML('<?xml encoding="UTF-8">' . $res);
1266
+    $doc->loadHTML('<?xml encoding="UTF-8">'.$res);
1268 1267
     $xpath = new DOMXPath($doc);
1269 1268
 
1270 1269
     $rewrite_base_url = $site_url ? $site_url : get_self_url_prefix();
@@ -1363,7 +1362,7 @@  discard block
 block discarded – undo
1363 1362
         'ol', 'p', 'picture', 'pre', 'q', 'ruby', 'rp', 'rt', 's', 'samp', 'section',
1364 1363
         'small', 'source', 'span', 'strike', 'strong', 'sub', 'summary',
1365 1364
         'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time',
1366
-        'tr', 'track', 'tt', 'u', 'ul', 'var', 'wbr', 'video', 'xml:namespace' );
1365
+        'tr', 'track', 'tt', 'u', 'ul', 'var', 'wbr', 'video', 'xml:namespace');
1367 1366
 
1368 1367
     if ($_SESSION['hasSandbox']) $allowed_elements[] = 'iframe';
1369 1368
 
@@ -1498,8 +1497,8 @@  discard block
 block discarded – undo
1498 1497
 
1499 1498
 // this returns SELF_URL_PATH sans ending slash
1500 1499
 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);
1500
+    if (strrpos(SELF_URL_PATH, "/") === strlen(SELF_URL_PATH) - 1) {
1501
+        return substr(SELF_URL_PATH, 0, strlen(SELF_URL_PATH) - 1);
1503 1502
     } else {
1504 1503
         return SELF_URL_PATH;
1505 1504
     }
@@ -1508,11 +1507,11 @@  discard block
 block discarded – undo
1508 1507
 /* TODO: This needs to use bcrypt */
1509 1508
 function encrypt_password($pass, $salt = '', $mode2 = false) {
1510 1509
     if ($salt && $mode2) {
1511
-        return "MODE2:" . hash('sha256', $salt . $pass);
1510
+        return "MODE2:".hash('sha256', $salt.$pass);
1512 1511
     } else if ($salt) {
1513
-        return "SHA1X:" . sha1("$salt:$pass");
1512
+        return "SHA1X:".sha1("$salt:$pass");
1514 1513
     } else {
1515
-        return "SHA1:" . sha1($pass);
1514
+        return "SHA1:".sha1($pass);
1516 1515
     }
1517 1516
 }
1518 1517
 
@@ -1523,7 +1522,7 @@  discard block
 block discarded – undo
1523 1522
 }
1524 1523
 
1525 1524
 function build_url($parts) {
1526
-    return $parts['scheme'] . "://" . $parts['host'] . $parts['path'];
1525
+    return $parts['scheme']."://".$parts['host'].$parts['path'];
1527 1526
 }
1528 1527
 
1529 1528
 function cleanup_url_path($path) {
@@ -1567,7 +1566,7 @@  discard block
 block discarded – undo
1567 1566
             $dir = dirname($parts['path']);
1568 1567
             $dir !== '/' && $dir .= '/';
1569 1568
         }
1570
-        $parts['path'] = $dir . $rel_url;
1569
+        $parts['path'] = $dir.$rel_url;
1571 1570
         $parts['path'] = cleanup_url_path($parts['path']);
1572 1571
 
1573 1572
         return build_url($parts);
@@ -1654,12 +1653,12 @@  discard block
 block discarded – undo
1654 1653
 
1655 1654
         for ($i = 0; $i < $l10n->total; $i++) {
1656 1655
             $orig = $l10n->get_original_string($i);
1657
-            if(strpos($orig, "\000") !== FALSE) { // Plural forms
1656
+            if (strpos($orig, "\000") !== FALSE) { // Plural forms
1658 1657
                 $key = explode(chr(0), $orig);
1659 1658
                 print T_js_decl($key[0], _ngettext($key[0], $key[1], 1)); // Singular
1660 1659
                 print T_js_decl($key[1], _ngettext($key[0], $key[1], 2)); // Plural
1661 1660
             } else {
1662
-                $translation = _dgettext($domain,$orig);
1661
+                $translation = _dgettext($domain, $orig);
1663 1662
                 print T_js_decl($orig, $translation);
1664 1663
             }
1665 1664
         }
@@ -1715,7 +1714,7 @@  discard block
 block discarded – undo
1715 1714
     if (file_exists($filename)) {
1716 1715
         $ext = pathinfo($filename, PATHINFO_EXTENSION);
1717 1716
 
1718
-        return "data:image/$ext;base64," . base64_encode(file_get_contents($filename));
1717
+        return "data:image/$ext;base64,".base64_encode(file_get_contents($filename));
1719 1718
     } else {
1720 1719
         return "";
1721 1720
     }
@@ -1752,7 +1751,7 @@  discard block
 block discarded – undo
1752 1751
 
1753 1752
         header("Content-type: $mimetype");
1754 1753
 
1755
-        $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)) . " GMT";
1754
+        $stamp = gmdate("D, d M Y H:i:s", filemtime($filename))." GMT";
1756 1755
         header("Last-Modified: $stamp", true);
1757 1756
 
1758 1757
         return readfile($filename);
@@ -1762,7 +1761,7 @@  discard block
 block discarded – undo
1762 1761
 }
1763 1762
 
1764 1763
 function arr_qmarks($arr) {
1765
-    return str_repeat('?,', count($arr) - 1) . '?';
1764
+    return str_repeat('?,', count($arr) - 1).'?';
1766 1765
 }
1767 1766
 
1768 1767
 function get_scripts_timestamp() {
@@ -1797,7 +1796,7 @@  discard block
 block discarded – undo
1797 1796
     } else if (PHP_OS === "Darwin") {
1798 1797
         $ttrss_version = "UNKNOWN (Unsupported, Darwin)";
1799 1798
     } else if (file_exists("$root_dir/version_static.txt")) {
1800
-        $ttrss_version = trim(file_get_contents("$root_dir/version_static.txt")) . " (Unsupported)";
1799
+        $ttrss_version = trim(file_get_contents("$root_dir/version_static.txt"))." (Unsupported)";
1801 1800
     } else if (is_dir("$root_dir/.git")) {
1802 1801
         $rc = 0;
1803 1802
         $output = [];
@@ -1815,10 +1814,10 @@  discard block
 block discarded – undo
1815 1814
                 $git_commit = $commit;
1816 1815
                 $git_timestamp = $timestamp;
1817 1816
 
1818
-                $ttrss_version = strftime("%y.%m", $timestamp) . "-$commit";
1817
+                $ttrss_version = strftime("%y.%m", $timestamp)."-$commit";
1819 1818
             }
1820 1819
         } else {
1821
-            user_error("Unable to determine version (using $root_dir): " . implode("\n", $output), E_USER_WARNING);
1820
+            user_error("Unable to determine version (using $root_dir): ".implode("\n", $output), E_USER_WARNING);
1822 1821
         }
1823 1822
     }
1824 1823
 
Please login to merge, or discard this patch.
Braces   +128 added lines, -65 removed lines patch added patch discarded remove patch
@@ -18,7 +18,9 @@  discard block
 block discarded – undo
18 18
 libxml_use_internal_errors(true);
19 19
 
20 20
 // separate test because this is included before sanity checks
21
-if (function_exists("mb_internal_encoding")) mb_internal_encoding("UTF-8");
21
+if (function_exists("mb_internal_encoding")) {
22
+	mb_internal_encoding("UTF-8");
23
+}
22 24
 
23 25
 date_default_timezone_set('UTC');
24 26
 if (defined('E_DEPRECATED')) {
@@ -195,8 +197,9 @@  discard block
 block discarded – undo
195 197
     $fetch_last_modified = "";
196 198
     $fetch_effective_url = "";
197 199
 
198
-    if (!is_array($fetch_domain_hits))
199
-        $fetch_domain_hits = [];
200
+    if (!is_array($fetch_domain_hits)) {
201
+            $fetch_domain_hits = [];
202
+    }
200 203
 
201 204
     if (!is_array($options)) {
202 205
 
@@ -227,8 +230,9 @@  discard block
 block discarded – undo
227 230
     $url = ltrim($url, ' ');
228 231
     $url = str_replace(' ', '%20', $url);
229 232
 
230
-    if (strpos($url, "//") === 0)
231
-        $url = 'http:' . $url;
233
+    if (strpos($url, "//") === 0) {
234
+            $url = 'http:' . $url;
235
+    }
232 236
 
233 237
     $url_host = parse_url($url, PHP_URL_HOST);
234 238
     $fetch_domain_hits[$url_host] += 1;
@@ -246,14 +250,17 @@  discard block
 block discarded – undo
246 250
 
247 251
         $curl_http_headers = [];
248 252
 
249
-        if ($last_modified && !$post_query)
250
-            array_push($curl_http_headers, "If-Modified-Since: $last_modified");
253
+        if ($last_modified && !$post_query) {
254
+                    array_push($curl_http_headers, "If-Modified-Since: $last_modified");
255
+        }
251 256
 
252
-        if ($http_accept)
253
-            array_push($curl_http_headers, "Accept: " . $http_accept);
257
+        if ($http_accept) {
258
+                    array_push($curl_http_headers, "Accept: " . $http_accept);
259
+        }
254 260
 
255
-        if (count($curl_http_headers) > 0)
256
-            curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_http_headers);
261
+        if (count($curl_http_headers) > 0) {
262
+                    curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_http_headers);
263
+        }
257 264
 
258 265
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : FILE_FETCH_CONNECT_TIMEOUT);
259 266
         curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : FILE_FETCH_TIMEOUT);
@@ -267,8 +274,9 @@  discard block
 block discarded – undo
267 274
             SELF_USER_AGENT);
268 275
         curl_setopt($ch, CURLOPT_ENCODING, "");
269 276
 
270
-        if  ($http_referrer)
271
-            curl_setopt($ch, CURLOPT_REFERER, $http_referrer);
277
+        if  ($http_referrer) {
278
+                    curl_setopt($ch, CURLOPT_REFERER, $http_referrer);
279
+        }
272 280
 
273 281
         if ($max_size) {
274 282
             curl_setopt($ch, CURLOPT_NOPROGRESS, false);
@@ -297,8 +305,9 @@  discard block
 block discarded – undo
297 305
             curl_setopt($ch, CURLOPT_POSTFIELDS, $post_query);
298 306
         }
299 307
 
300
-        if ($login && $pass)
301
-            curl_setopt($ch, CURLOPT_USERPWD, "$login:$pass");
308
+        if ($login && $pass) {
309
+                    curl_setopt($ch, CURLOPT_USERPWD, "$login:$pass");
310
+        }
302 311
 
303 312
         $ret = @curl_exec($ch);
304 313
 
@@ -357,7 +366,9 @@  discard block
 block discarded – undo
357 366
         if ($is_gzipped) {
358 367
             $tmp = @gzdecode($contents);
359 368
 
360
-            if ($tmp) $contents = $tmp;
369
+            if ($tmp) {
370
+            	$contents = $tmp;
371
+            }
361 372
         }
362 373
 
363 374
         return $contents;
@@ -390,14 +401,17 @@  discard block
 block discarded – undo
390 401
                     'protocol_version'=> 1.1)
391 402
               );
392 403
 
393
-        if (!$post_query && $last_modified)
394
-            array_push($context_options['http']['header'], "If-Modified-Since: $last_modified");
404
+        if (!$post_query && $last_modified) {
405
+                    array_push($context_options['http']['header'], "If-Modified-Since: $last_modified");
406
+        }
395 407
 
396
-        if ($http_accept)
397
-            array_push($context_options['http']['header'], "Accept: $http_accept");
408
+        if ($http_accept) {
409
+                    array_push($context_options['http']['header'], "Accept: $http_accept");
410
+        }
398 411
 
399
-        if ($http_referrer)
400
-            array_push($context_options['http']['header'], "Referer: $http_referrer");
412
+        if ($http_referrer) {
413
+                    array_push($context_options['http']['header'], "Referer: $http_referrer");
414
+        }
401 415
 
402 416
         if (defined('_HTTP_PROXY')) {
403 417
             $context_options['http']['request_fulluri'] = true;
@@ -454,7 +468,9 @@  discard block
 block discarded – undo
454 468
         if ($is_gzipped) {
455 469
             $tmp = @gzdecode($data);
456 470
 
457
-            if ($tmp) $data = $tmp;
471
+            if ($tmp) {
472
+            	$data = $tmp;
473
+            }
458 474
         }
459 475
 
460 476
         return $data;
@@ -464,7 +480,9 @@  discard block
 block discarded – undo
464 480
 
465 481
 function initialize_user_prefs($uid, $profile = false) {
466 482
 
467
-    if (get_schema_version() < 63) $profile_qpart = "";
483
+    if (get_schema_version() < 63) {
484
+    	$profile_qpart = "";
485
+    }
468 486
 
469 487
     $pdo = DB::pdo();
470 488
     $in_nested_tr = false;
@@ -477,7 +495,9 @@  discard block
 block discarded – undo
477 495
 
478 496
     $sth = $pdo->query("SELECT pref_name,def_value FROM ttrss_prefs");
479 497
 
480
-    if (!is_numeric($profile) || !$profile || get_schema_version() < 63) $profile = null;
498
+    if (!is_numeric($profile) || !$profile || get_schema_version() < 63) {
499
+    	$profile = null;
500
+    }
481 501
 
482 502
     $u_sth = $pdo->prepare("SELECT pref_name
483 503
         FROM ttrss_user_prefs WHERE owner_uid = :uid AND
@@ -510,7 +530,9 @@  discard block
 block discarded – undo
510 530
         }
511 531
     }
512 532
 
513
-    if (!$in_nested_tr) $pdo->commit();
533
+    if (!$in_nested_tr) {
534
+    	$pdo->commit();
535
+    }
514 536
 
515 537
 }
516 538
 
@@ -670,7 +692,9 @@  discard block
 block discarded – undo
670 692
 
671 693
 function load_user_plugins($owner_uid, $pluginhost = false) {
672 694
 
673
-    if (!$pluginhost) $pluginhost = PluginHost::getInstance();
695
+    if (!$pluginhost) {
696
+    	$pluginhost = PluginHost::getInstance();
697
+    }
674 698
 
675 699
     if ($owner_uid && SCHEMA_VERSION >= 100) {
676 700
         $plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
@@ -692,7 +716,9 @@  discard block
 block discarded – undo
692 716
         startup_gettext();
693 717
         load_user_plugins($_SESSION["uid"]);
694 718
     } else {
695
-        if (!validate_session()) $_SESSION["uid"] = false;
719
+        if (!validate_session()) {
720
+        	$_SESSION["uid"] = false;
721
+        }
696 722
 
697 723
         if (!$_SESSION["uid"]) {
698 724
 
@@ -787,13 +813,19 @@  discard block
 block discarded – undo
787 813
 function make_local_datetime($timestamp, $long, $owner_uid = false,
788 814
                 $no_smart_dt = false, $eta_min = false) {
789 815
 
790
-    if (!$owner_uid) $owner_uid = $_SESSION['uid'];
791
-    if (!$timestamp) $timestamp = '1970-01-01 0:00';
816
+    if (!$owner_uid) {
817
+    	$owner_uid = $_SESSION['uid'];
818
+    }
819
+    if (!$timestamp) {
820
+    	$timestamp = '1970-01-01 0:00';
821
+    }
792 822
 
793 823
     global $utc_tz;
794 824
     global $user_tz;
795 825
 
796
-    if (!$utc_tz) $utc_tz = new DateTimeZone('UTC');
826
+    if (!$utc_tz) {
827
+    	$utc_tz = new DateTimeZone('UTC');
828
+    }
797 829
 
798 830
     $timestamp = substr($timestamp, 0, 19);
799 831
 
@@ -805,7 +837,9 @@  discard block
 block discarded – undo
805 837
     if ($user_tz_string != 'Automatic') {
806 838
 
807 839
         try {
808
-            if (!$user_tz) $user_tz = new DateTimeZone($user_tz_string);
840
+            if (!$user_tz) {
841
+            	$user_tz = new DateTimeZone($user_tz_string);
842
+            }
809 843
         } catch (Exception $e) {
810 844
             $user_tz = $utc_tz;
811 845
         }
@@ -821,26 +855,30 @@  discard block
 block discarded – undo
821 855
         return smart_date_time($user_timestamp,
822 856
             $tz_offset, $owner_uid, $eta_min);
823 857
     } else {
824
-        if ($long)
825
-            $format = get_pref('LONG_DATE_FORMAT', $owner_uid);
826
-        else
827
-            $format = get_pref('SHORT_DATE_FORMAT', $owner_uid);
858
+        if ($long) {
859
+                    $format = get_pref('LONG_DATE_FORMAT', $owner_uid);
860
+        } else {
861
+                    $format = get_pref('SHORT_DATE_FORMAT', $owner_uid);
862
+        }
828 863
 
829 864
         return date($format, $user_timestamp);
830 865
     }
831 866
 }
832 867
 
833 868
 function smart_date_time($timestamp, $tz_offset = 0, $owner_uid = false, $eta_min = false) {
834
-    if (!$owner_uid) $owner_uid = $_SESSION['uid'];
869
+    if (!$owner_uid) {
870
+    	$owner_uid = $_SESSION['uid'];
871
+    }
835 872
 
836 873
     if ($eta_min && time() + $tz_offset - $timestamp < 3600) {
837 874
         return T_sprintf("%d min", date("i", time() + $tz_offset - $timestamp));
838 875
     } else if (date("Y.m.d", $timestamp) == date("Y.m.d", time() + $tz_offset)) {
839 876
         $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);
877
+        if (strpos((strtolower($format)), "a") === false) {
878
+                    return date("G:i", $timestamp);
879
+        } else {
880
+                    return date("g:i a", $timestamp);
881
+        }
844 882
     } else if (date("Y", $timestamp) == date("Y", time() + $tz_offset)) {
845 883
         $format = get_pref('SHORT_DATE_FORMAT', $owner_uid);
846 884
         return date($format, $timestamp);
@@ -1250,8 +1288,9 @@  discard block
 block discarded – undo
1250 1288
 
1251 1289
     if ($src) {
1252 1290
         foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_IFRAME_WHITELISTED) as $plugin) {
1253
-            if ($plugin->hook_iframe_whitelisted($src))
1254
-                return true;
1291
+            if ($plugin->hook_iframe_whitelisted($src)) {
1292
+                            return true;
1293
+            }
1255 1294
         }
1256 1295
     }
1257 1296
 
@@ -1259,9 +1298,13 @@  discard block
 block discarded – undo
1259 1298
 }
1260 1299
 
1261 1300
 function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false, $highlight_words = false, $article_id = false) {
1262
-    if (!$owner) $owner = $_SESSION["uid"];
1301
+    if (!$owner) {
1302
+    	$owner = $_SESSION["uid"];
1303
+    }
1263 1304
 
1264
-    $res = trim($str); if (!$res) return '';
1305
+    $res = trim($str); if (!$res) {
1306
+    	return '';
1307
+    }
1265 1308
 
1266 1309
     $doc = new DOMDocument();
1267 1310
     $doc->loadHTML('<?xml encoding="UTF-8">' . $res);
@@ -1323,13 +1366,15 @@  discard block
 block discarded – undo
1323 1366
 
1324 1367
             if ($entry->nodeName == 'source') {
1325 1368
 
1326
-                if ($entry->parentNode && $entry->parentNode->parentNode)
1327
-                    $entry->parentNode->parentNode->replaceChild($p, $entry->parentNode);
1369
+                if ($entry->parentNode && $entry->parentNode->parentNode) {
1370
+                                    $entry->parentNode->parentNode->replaceChild($p, $entry->parentNode);
1371
+                }
1328 1372
 
1329 1373
             } else if ($entry->nodeName == 'img') {
1330 1374
 
1331
-                if ($entry->parentNode)
1332
-                    $entry->parentNode->replaceChild($p, $entry);
1375
+                if ($entry->parentNode) {
1376
+                                    $entry->parentNode->replaceChild($p, $entry);
1377
+                }
1333 1378
 
1334 1379
             }
1335 1380
         }
@@ -1365,7 +1410,9 @@  discard block
 block discarded – undo
1365 1410
         'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time',
1366 1411
         'tr', 'track', 'tt', 'u', 'ul', 'var', 'wbr', 'video', 'xml:namespace' );
1367 1412
 
1368
-    if ($_SESSION['hasSandbox']) $allowed_elements[] = 'iframe';
1413
+    if ($_SESSION['hasSandbox']) {
1414
+    	$allowed_elements[] = 'iframe';
1415
+    }
1369 1416
 
1370 1417
     $disallowed_attributes = array('id', 'style', 'class');
1371 1418
 
@@ -1405,7 +1452,9 @@  discard block
 block discarded – undo
1405 1452
                     $text = mb_substr($text, $pos + mb_strlen($word));
1406 1453
                 }
1407 1454
 
1408
-                if (!empty($text)) $fragment->appendChild(new DomText($text));
1455
+                if (!empty($text)) {
1456
+                	$fragment->appendChild(new DomText($text));
1457
+                }
1409 1458
 
1410 1459
                 $child->parentNode->replaceChild($fragment, $child);
1411 1460
             }
@@ -1596,8 +1645,9 @@  discard block
 block discarded – undo
1596 1645
     } else {
1597 1646
         $output = "";
1598 1647
 
1599
-        for ($i = 0; $i < $length; $i++)
1600
-            $output .= chr(mt_rand(0, 255));
1648
+        for ($i = 0; $i < $length; $i++) {
1649
+                    $output .= chr(mt_rand(0, 255));
1650
+        }
1601 1651
 
1602 1652
         return $output;
1603 1653
     }
@@ -1667,15 +1717,20 @@  discard block
 block discarded – undo
1667 1717
 }
1668 1718
 
1669 1719
 function get_theme_path($theme) {
1670
-    if ($theme == "default.php")
1671
-        return "css/default.css";
1720
+    if ($theme == "default.php") {
1721
+            return "css/default.css";
1722
+    }
1672 1723
 
1673 1724
     $check = "themes/$theme";
1674
-    if (file_exists($check)) return $check;
1725
+    if (file_exists($check)) {
1726
+    	return $check;
1727
+    }
1675 1728
 
1676 1729
     $check = "themes.local/$theme";
1677
-    if (file_exists($check)) return $check;
1678
-}
1730
+    if (file_exists($check)) {
1731
+    	return $check;
1732
+    }
1733
+    }
1679 1734
 
1680 1735
 function theme_exists($theme) {
1681 1736
     return file_exists("themes/$theme") || file_exists("themes.local/$theme");
@@ -1731,7 +1786,9 @@  discard block
 block discarded – undo
1731 1786
 function send_local_file($filename) {
1732 1787
     if (file_exists($filename)) {
1733 1788
 
1734
-        if (is_writable($filename)) touch($filename);
1789
+        if (is_writable($filename)) {
1790
+        	touch($filename);
1791
+        }
1735 1792
 
1736 1793
         $tmppluginhost = new PluginHost();
1737 1794
 
@@ -1739,7 +1796,9 @@  discard block
 block discarded – undo
1739 1796
         $tmppluginhost->load_data();
1740 1797
 
1741 1798
         foreach ($tmppluginhost->get_hooks(PluginHost::HOOK_SEND_LOCAL_FILE) as $plugin) {
1742
-            if ($plugin->hook_send_local_file($filename)) return true;
1799
+            if ($plugin->hook_send_local_file($filename)) {
1800
+            	return true;
1801
+            }
1743 1802
         }
1744 1803
 
1745 1804
         $mimetype = mime_content_type($filename);
@@ -1747,8 +1806,9 @@  discard block
 block discarded – undo
1747 1806
         // this is hardly ideal but 1) only media is cached in images/ and 2) seemingly only mp4
1748 1807
         // video files are detected as octet-stream by mime_content_type()
1749 1808
 
1750
-        if ($mimetype == "application/octet-stream")
1751
-            $mimetype = "video/mp4";
1809
+        if ($mimetype == "application/octet-stream") {
1810
+                    $mimetype = "video/mp4";
1811
+        }
1752 1812
 
1753 1813
         header("Content-type: $mimetype");
1754 1814
 
@@ -1771,7 +1831,9 @@  discard block
 block discarded – undo
1771 1831
 
1772 1832
     foreach ($files as $file) {
1773 1833
         $file_ts = filemtime($file);
1774
-        if ($file_ts > $ts) $ts = $file_ts;
1834
+        if ($file_ts > $ts) {
1835
+        	$ts = $file_ts;
1836
+        }
1775 1837
     }
1776 1838
 
1777 1839
     return $ts;
@@ -1784,8 +1846,9 @@  discard block
 block discarded – undo
1784 1846
 function get_version(&$git_commit = false, &$git_timestamp = false) {
1785 1847
     global $ttrss_version;
1786 1848
 
1787
-    if (isset($ttrss_version))
1788
-        return $ttrss_version;
1849
+    if (isset($ttrss_version)) {
1850
+            return $ttrss_version;
1851
+    }
1789 1852
 
1790 1853
     $ttrss_version = "UNKNOWN (Unsupported)";
1791 1854
 
Please login to merge, or discard this patch.
include/sessions.php 3 patches
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.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
     return true;
79 79
 }
80 80
 
81
-function ttrss_open () {
81
+function ttrss_open() {
82 82
     return true;
83 83
 }
84 84
 
85
-function ttrss_read ($id){
85
+function ttrss_read($id) {
86 86
     global $session_expire;
87 87
 
88 88
     $sth = Db::pdo()->prepare("SELECT data FROM ttrss_sessions WHERE id=?");
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     }
102 102
 }
103 103
 
104
-function ttrss_write ($id, $data) {
104
+function ttrss_write($id, $data) {
105 105
     global $session_expire;
106 106
 
107 107
     $data = base64_encode($data);
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
     return true;
122 122
 }
123 123
 
124
-function ttrss_close () {
124
+function ttrss_close() {
125 125
     return true;
126 126
 }
127 127
 
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
     return true;
133 133
 }
134 134
 
135
-function ttrss_gc () {
136
-    Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time());
135
+function ttrss_gc() {
136
+    Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < ".time());
137 137
 
138 138
     return true;
139 139
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@
 block discarded – undo
35 35
 }
36 36
 
37 37
 function validate_session() {
38
-    if (SINGLE_USER_MODE) return true;
38
+    if (SINGLE_USER_MODE) {
39
+    	return true;
40
+    }
39 41
 
40 42
     if (isset($_SESSION["ref_schema_version"]) && $_SESSION["ref_schema_version"] != session_get_schema_version()) {
41 43
         $_SESSION["login_error_msg"] =
Please login to merge, or discard this patch.
plugins/nsfw/init.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
 	}
20 20
 
21 21
 	public function get_js() {
22
-		return file_get_contents(dirname(__FILE__) . "/init.js");
22
+		return file_get_contents(dirname(__FILE__)."/init.js");
23 23
 	}
24 24
 
25 25
 	public function hook_render_article($article) {
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,9 @@
 block discarded – undo
47 47
 	}
48 48
 
49 49
 	public function hook_prefs_tab($args) {
50
-		if ($args != "prefPrefs") return;
50
+		if ($args != "prefPrefs") {
51
+			return;
52
+		}
51 53
 
52 54
 		print "<div dojoType=\"dijit.layout.AccordionPane\"
53 55
 			title=\"<i class='material-icons'>extension</i> ".__("NSFW Plugin")."\">";
Please login to merge, or discard this patch.