diff --git a/core/polyfills.php b/core/polyfills.php index ad62b2ec..50831343 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -834,20 +834,20 @@ function get_class_from_file(string $file): string return $class; } -function stringer($s) { - if(is_array($s)) { - if(isset($s[0])) { +function stringer($s) +{ + if (is_array($s)) { + if (isset($s[0])) { return "[" . implode(", ", array_map("stringer", $s)) . "]"; - } - else { + } else { $pairs = []; - foreach($s as $k=>$v) { + foreach ($s as $k=>$v) { $pairs[] = "\"$k\"=>" . stringer($v); } return "[" . implode(", ", $pairs) . "]"; } } - if(is_string($s)) { + if (is_string($s)) { return "\"$s\""; // FIXME: handle escaping quotes } return (string)$s; diff --git a/core/user.php b/core/user.php index 26080466..e1976cca 100644 --- a/core/user.php +++ b/core/user.php @@ -242,12 +242,12 @@ class User public function check_auth_token(): bool { return (isset($_POST["auth_token"]) && $_POST["auth_token"] == $this->get_auth_token()); - } + } - public function ensure_authed(): void - { - if(!$this->check_auth_token()) { - die("Invalid auth token"); - } + public function ensure_authed(): void + { + if (!$this->check_auth_token()) { + die("Invalid auth token"); + } } } diff --git a/core/util.php b/core/util.php index 3719c4a1..d19c68f8 100644 --- a/core/util.php +++ b/core/util.php @@ -1,5 +1,6 @@ getTrace()); - foreach($t as $n => $f) { - $c = $f['class'] ?? ''; - $t = $f['type'] ?? ''; - $a = implode(", ", array_map("stringer", $f['args'])); - print("$n: {$f['file']}({$f['line']}): {$c}{$t}{$f['function']}({$a})\n"); - } + print("Trace: "); + $t = array_reverse($e->getTrace()); + foreach ($t as $n => $f) { + $c = $f['class'] ?? ''; + $t = $f['type'] ?? ''; + $a = implode(", ", array_map("stringer", $f['args'])); + print("$n: {$f['file']}({$f['line']}): {$c}{$t}{$f['function']}({$a})\n"); + } - print("Message: $message\n"); + print("Message: $message\n"); - if(isset($e->query)) { - print("Query: {$e->query}\n"); - } + if (isset($e->query)) { + print("Query: {$e->query}\n"); + } - print("Version: $version (on $phpver)\n"); - } - else { - $q = (!isset($e->query) || is_null($e->query)) ? "" : "

Query: " . html_escape($e->query); - header("HTTP/1.0 500 Internal Error"); - echo ' + print("Version: $version (on $phpver)\n"); + } else { + $q = (!isset($e->query) || is_null($e->query)) ? "" : "

Query: " . html_escape($e->query); + header("HTTP/1.0 500 Internal Error"); + echo ' Internal error - SCore-'.$version.' @@ -558,7 +558,7 @@ function _fatal_error(Exception $e): void '; - } + } } /** @@ -688,7 +688,8 @@ function make_form(string $target, string $method="POST", bool $multipart=false, return '

'.$extra_inputs; } -function SHM_FORM(string $target, string $method="POST", bool $multipart=false, string $form_id="", string $onsubmit="") { +function SHM_FORM(string $target, string $method="POST", bool $multipart=false, string $form_id="", string $onsubmit="") +{ global $user; $attrs = [ @@ -696,7 +697,7 @@ function SHM_FORM(string $target, string $method="POST", bool $multipart=false, "method"=>$method ]; - if($form_id) { + if ($form_id) { $attrs["id"] = $form_id; } if ($multipart) { diff --git a/ext/admin/main.php b/ext/admin/main.php index 50781f28..e65ed8a2 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -72,18 +72,18 @@ class AdminPage extends Extension } if ($event->cmd == "get-page") { global $page; - if(isset($event->args[1])) { - parse_str($event->args[1], $_GET); - } + if (isset($event->args[1])) { + parse_str($event->args[1], $_GET); + } send_event(new PageRequestEvent($event->args[0])); $page->display(); } if ($event->cmd == "post-page") { global $page; $_SERVER['REQUEST_METHOD'] = "POST"; - if(isset($event->args[1])) { - parse_str($event->args[1], $_POST); - } + if (isset($event->args[1])) { + parse_str($event->args[1], $_POST); + } send_event(new PageRequestEvent($event->args[0])); $page->display(); } diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 8fadfd66..ed512eda 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -74,7 +74,7 @@ class AliasEditor extends Extension $t->token = $user->get_auth_token(); $t->inputs = $_GET; $t->size = $config->get_int('alias_items_per_page', 30); - if($user->can(Permissions::MANAGE_ALIAS_LIST)) { + if ($user->can(Permissions::MANAGE_ALIAS_LIST)) { $t->create_url = make_link("alias/add"); $t->delete_url = make_link("alias/remove"); } diff --git a/ext/ext_manager/theme.php b/ext/ext_manager/theme.php index 628163a0..e1b935a1 100644 --- a/ext/ext_manager/theme.php +++ b/ext/ext_manager/theme.php @@ -1,6 +1,21 @@ table = "image_bans"; $this->base_query = "SELECT * FROM image_bans"; - $this->primary_key = "hash"; + $this->primary_key = "hash"; $this->size = 100; - $this->limit = 1000000; + $this->limit = 1000000; $this->columns = [ new StringColumn("hash", "Hash"), new TextColumn("reason", "Reason"), diff --git a/ext/log_db/main.php b/ext/log_db/main.php index ee1bfb84..d49825db 100644 --- a/ext/log_db/main.php +++ b/ext/log_db/main.php @@ -1,13 +1,20 @@ input_mod = function ($var) { - return "%$var%"; - }; + return "%$var%"; + }; } public function display($row) { - $ret = emptyHTML(); + $ret = emptyHTML(); if ($row['username'] != "Anonymous") { $ret->appendChild(A(["href"=>make_link("user/{$row['username']}"), "title"=>$row['address']], $row['username'])); - $ret->appendChild(BR()); + $ret->appendChild(BR()); } - $ret->appendChild($row['address']); + $ret->appendChild($row['address']); return $ret; } } -class MessageColumn extends Column { +class MessageColumn extends Column +{ public function __construct($name, $title) { parent::__construct( @@ -60,10 +68,9 @@ class MessageColumn extends Column { list($m, $l) = $var; if (empty($m)) { $m = "%"; + } else { + $m = "%$m%"; } - else { - $m = "%$m%"; - } if (empty($l)) { $l = 0; } @@ -74,21 +81,21 @@ class MessageColumn extends Column { public function read_input($inputs) { $ret = emptyHTML( - INPUT([ - "type"=>"text", - "name"=>"r_{$this->name}[]", - "placeholder"=>$this->title, - "value"=>@$inputs["r_{$this->name}"][0] - ]) - ); + INPUT([ + "type"=>"text", + "name"=>"r_{$this->name}[]", + "placeholder"=>$this->title, + "value"=>@$inputs["r_{$this->name}"][0] + ]) + ); - $options = [ - "Debug" => SCORE_LOG_DEBUG, - "Info" => SCORE_LOG_INFO, - "Warning" => SCORE_LOG_WARNING, - "Error" => SCORE_LOG_ERROR, - "Critical" => SCORE_LOG_CRITICAL, - ]; + $options = [ + "Debug" => SCORE_LOG_DEBUG, + "Info" => SCORE_LOG_INFO, + "Warning" => SCORE_LOG_WARNING, + "Error" => SCORE_LOG_ERROR, + "Critical" => SCORE_LOG_CRITICAL, + ]; $s = SELECT(["name"=>"r_{$this->name}[]"]); $s->appendChild(OPTION(["value"=>""], '-')); foreach ($options as $k => $v) { @@ -98,7 +105,7 @@ class MessageColumn extends Column { } $s->appendChild(OPTION($attrs, $k)); } - $ret->appendChild($s); + $ret->appendChild($s); return $ret; } @@ -192,8 +199,8 @@ class LogDatabase extends Extension global $cache, $database, $user; if ($event->page_matches("log/view")) { if ($user->can(Permissions::VIEW_EVENTLOG)) { - $t = new LogTable($database->raw_db()); - $t->inputs = $_GET; + $t = new LogTable($database->raw_db()); + $t->inputs = $_GET; $this->theme->display_events($t->table($t->query()), $t->paginator()); } } diff --git a/ext/not_a_tag/main.php b/ext/not_a_tag/main.php index 20d5682b..4274c831 100644 --- a/ext/not_a_tag/main.php +++ b/ext/not_a_tag/main.php @@ -10,7 +10,7 @@ class NotATagTable extends Table parent::__construct($db); $this->table = "untags"; $this->base_query = "SELECT * FROM untags"; - $this->primary_key = "tag"; + $this->primary_key = "tag"; $this->size = 100; $this->limit = 1000000; $this->columns = [ @@ -112,8 +112,10 @@ class NotATag extends Extension } elseif ($event->get_arg(0) == "remove") { $user->ensure_authed(); $input = validate_input(["d_tag"=>"string"]); - $database->execute($database->scoreql_to_sql( - "DELETE FROM untags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"), + $database->execute( + $database->scoreql_to_sql( + "DELETE FROM untags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)" + ), ["tag"=>$input['d_tag']] ); flash_message("Image ban removed"); diff --git a/ext/user/main.php b/ext/user/main.php index e690d148..041fe975 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -8,24 +8,31 @@ use MicroCRUD\EnumColumn; use MicroCRUD\TextColumn; use MicroCRUD\Table; -class UserNameColumn extends TextColumn { - public function display(array $row) { +class UserNameColumn extends TextColumn +{ + public function display(array $row) + { return A(["href"=>make_link("user/{$row[$this->name]}")], $row[$this->name]); } } -class UserLinksColumn extends Column { - public function __construct() { +class UserLinksColumn extends Column +{ + public function __construct() + { parent::__construct("links", "User Links", "(1=1)"); $this->sortable = false; } - public function create_input(array $inputs) { + public function create_input(array $inputs) + { return ""; } - public function read_input(array $inputs) { + public function read_input(array $inputs) + { return ""; } - public function display(array $row) { + public function display(array $row) + { return A(["href"=>make_link("post/list/user_id={$row['id']}/1")], "Posts"); } } @@ -36,7 +43,7 @@ class UserTable extends Table { global $_shm_user_classes; $classes = []; - foreach($_shm_user_classes as $cls) { + foreach ($_shm_user_classes as $cls) { $classes[$cls->name] = $cls->name; } ksort($classes); @@ -190,7 +197,7 @@ class UserPage extends Extension } $event->add_stats("Joined: $h_join_date", 10); - if($user->name == $event->display_user->name) { + if ($user->name == $event->display_user->name) { $event->add_stats("Current IP: {$_SERVER['REMOTE_ADDR']}", 80); } $event->add_stats("Class: $h_class", 90);