formatting

This commit is contained in:
Shish 2019-12-15 15:31:44 +00:00
parent f09d328b30
commit d705578f79
10 changed files with 120 additions and 88 deletions

View File

@ -834,20 +834,20 @@ function get_class_from_file(string $file): string
return $class; return $class;
} }
function stringer($s) { function stringer($s)
if(is_array($s)) { {
if(isset($s[0])) { if (is_array($s)) {
if (isset($s[0])) {
return "[" . implode(", ", array_map("stringer", $s)) . "]"; return "[" . implode(", ", array_map("stringer", $s)) . "]";
} } else {
else {
$pairs = []; $pairs = [];
foreach($s as $k=>$v) { foreach ($s as $k=>$v) {
$pairs[] = "\"$k\"=>" . stringer($v); $pairs[] = "\"$k\"=>" . stringer($v);
} }
return "[" . implode(", ", $pairs) . "]"; return "[" . implode(", ", $pairs) . "]";
} }
} }
if(is_string($s)) { if (is_string($s)) {
return "\"$s\""; // FIXME: handle escaping quotes return "\"$s\""; // FIXME: handle escaping quotes
} }
return (string)$s; return (string)$s;

View File

@ -242,12 +242,12 @@ class User
public function check_auth_token(): bool public function check_auth_token(): bool
{ {
return (isset($_POST["auth_token"]) && $_POST["auth_token"] == $this->get_auth_token()); return (isset($_POST["auth_token"]) && $_POST["auth_token"] == $this->get_auth_token());
} }
public function ensure_authed(): void public function ensure_authed(): void
{ {
if(!$this->check_auth_token()) { if (!$this->check_auth_token()) {
die("Invalid auth token"); die("Invalid auth token");
} }
} }
} }

View File

@ -1,5 +1,6 @@
<?php <?php
use function MicroHTML\{FORM,INPUT}; use function MicroHTML\FORM;
use function MicroHTML\INPUT;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Misc * * Misc *
@ -525,27 +526,26 @@ function _fatal_error(Exception $e): void
//'.$h_hash.' //'.$h_hash.'
if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') { if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') {
print("Trace: "); print("Trace: ");
$t = array_reverse($e->getTrace()); $t = array_reverse($e->getTrace());
foreach($t as $n => $f) { foreach ($t as $n => $f) {
$c = $f['class'] ?? ''; $c = $f['class'] ?? '';
$t = $f['type'] ?? ''; $t = $f['type'] ?? '';
$a = implode(", ", array_map("stringer", $f['args'])); $a = implode(", ", array_map("stringer", $f['args']));
print("$n: {$f['file']}({$f['line']}): {$c}{$t}{$f['function']}({$a})\n"); print("$n: {$f['file']}({$f['line']}): {$c}{$t}{$f['function']}({$a})\n");
} }
print("Message: $message\n"); print("Message: $message\n");
if(isset($e->query)) { if (isset($e->query)) {
print("Query: {$e->query}\n"); print("Query: {$e->query}\n");
} }
print("Version: $version (on $phpver)\n"); print("Version: $version (on $phpver)\n");
} } else {
else { $q = (!isset($e->query) || is_null($e->query)) ? "" : "<p><b>Query:</b> " . html_escape($e->query);
$q = (!isset($e->query) || is_null($e->query)) ? "" : "<p><b>Query:</b> " . html_escape($e->query); header("HTTP/1.0 500 Internal Error");
header("HTTP/1.0 500 Internal Error"); echo '
echo '
<html> <html>
<head> <head>
<title>Internal error - SCore-'.$version.'</title> <title>Internal error - SCore-'.$version.'</title>
@ -558,7 +558,7 @@ function _fatal_error(Exception $e): void
</body> </body>
</html> </html>
'; ';
} }
} }
/** /**
@ -688,7 +688,8 @@ function make_form(string $target, string $method="POST", bool $multipart=false,
return '<form action="'.$target.'" method="'.$method.'" '.$extra.'>'.$extra_inputs; return '<form action="'.$target.'" method="'.$method.'" '.$extra.'>'.$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; global $user;
$attrs = [ $attrs = [
@ -696,7 +697,7 @@ function SHM_FORM(string $target, string $method="POST", bool $multipart=false,
"method"=>$method "method"=>$method
]; ];
if($form_id) { if ($form_id) {
$attrs["id"] = $form_id; $attrs["id"] = $form_id;
} }
if ($multipart) { if ($multipart) {

View File

@ -72,18 +72,18 @@ class AdminPage extends Extension
} }
if ($event->cmd == "get-page") { if ($event->cmd == "get-page") {
global $page; global $page;
if(isset($event->args[1])) { if (isset($event->args[1])) {
parse_str($event->args[1], $_GET); parse_str($event->args[1], $_GET);
} }
send_event(new PageRequestEvent($event->args[0])); send_event(new PageRequestEvent($event->args[0]));
$page->display(); $page->display();
} }
if ($event->cmd == "post-page") { if ($event->cmd == "post-page") {
global $page; global $page;
$_SERVER['REQUEST_METHOD'] = "POST"; $_SERVER['REQUEST_METHOD'] = "POST";
if(isset($event->args[1])) { if (isset($event->args[1])) {
parse_str($event->args[1], $_POST); parse_str($event->args[1], $_POST);
} }
send_event(new PageRequestEvent($event->args[0])); send_event(new PageRequestEvent($event->args[0]));
$page->display(); $page->display();
} }

View File

@ -74,7 +74,7 @@ class AliasEditor extends Extension
$t->token = $user->get_auth_token(); $t->token = $user->get_auth_token();
$t->inputs = $_GET; $t->inputs = $_GET;
$t->size = $config->get_int('alias_items_per_page', 30); $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->create_url = make_link("alias/add");
$t->delete_url = make_link("alias/remove"); $t->delete_url = make_link("alias/remove");
} }

View File

@ -1,6 +1,21 @@
<?php <?php
use function MicroHTML\{LABEL,A,B,IMG,TABLE,THEAD,TFOOT,TBODY,TH,TR,TD,INPUT,DIV,P,BR,emptyHTML}; use function MicroHTML\LABEL;
use function MicroHTML\A;
use function MicroHTML\B;
use function MicroHTML\IMG;
use function MicroHTML\TABLE;
use function MicroHTML\THEAD;
use function MicroHTML\TFOOT;
use function MicroHTML\TBODY;
use function MicroHTML\TH;
use function MicroHTML\TR;
use function MicroHTML\TD;
use function MicroHTML\INPUT;
use function MicroHTML\DIV;
use function MicroHTML\P;
use function MicroHTML\BR;
use function MicroHTML\emptyHTML;
class ExtManagerTheme extends Themelet class ExtManagerTheme extends Themelet
{ {

View File

@ -12,9 +12,9 @@ class HashBanTable extends Table
parent::__construct($db); parent::__construct($db);
$this->table = "image_bans"; $this->table = "image_bans";
$this->base_query = "SELECT * FROM image_bans"; $this->base_query = "SELECT * FROM image_bans";
$this->primary_key = "hash"; $this->primary_key = "hash";
$this->size = 100; $this->size = 100;
$this->limit = 1000000; $this->limit = 1000000;
$this->columns = [ $this->columns = [
new StringColumn("hash", "Hash"), new StringColumn("hash", "Hash"),
new TextColumn("reason", "Reason"), new TextColumn("reason", "Reason"),

View File

@ -1,13 +1,20 @@
<?php <?php
use function MicroHTML\{A,SPAN,emptyHTML,INPUT,BR,SELECT,OPTION,rawHTML}; use function MicroHTML\A;
use function MicroHTML\SPAN;
use function MicroHTML\emptyHTML;
use function MicroHTML\INPUT;
use function MicroHTML\BR;
use function MicroHTML\SELECT;
use function MicroHTML\OPTION;
use function MicroHTML\rawHTML;
use MicroCRUD\Column; use MicroCRUD\Column;
use MicroCRUD\DateTimeColumn; use MicroCRUD\DateTimeColumn;
use MicroCRUD\TextColumn; use MicroCRUD\TextColumn;
use MicroCRUD\Table; use MicroCRUD\Table;
class ShortDateTimeColumn extends DateTimeColumn
class ShortDateTimeColumn extends DateTimeColumn { {
public function read_input(array $inputs) public function read_input(array $inputs)
{ {
return emptyHTML( return emptyHTML(
@ -24,31 +31,32 @@ class ShortDateTimeColumn extends DateTimeColumn {
]) ])
); );
} }
} }
class ActorColumn extends Column { class ActorColumn extends Column
{
public function __construct($name, $title) public function __construct($name, $title)
{ {
parent::__construct($name, $title, "((username LIKE :{$name}) OR (address::text LIKE :{$name}))"); parent::__construct($name, $title, "((username LIKE :{$name}) OR (address::text LIKE :{$name}))");
$this->input_mod = function ($var) { $this->input_mod = function ($var) {
return "%$var%"; return "%$var%";
}; };
} }
public function display($row) public function display($row)
{ {
$ret = emptyHTML(); $ret = emptyHTML();
if ($row['username'] != "Anonymous") { if ($row['username'] != "Anonymous") {
$ret->appendChild(A(["href"=>make_link("user/{$row['username']}"), "title"=>$row['address']], $row['username'])); $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; return $ret;
} }
} }
class MessageColumn extends Column { class MessageColumn extends Column
{
public function __construct($name, $title) public function __construct($name, $title)
{ {
parent::__construct( parent::__construct(
@ -60,10 +68,9 @@ class MessageColumn extends Column {
list($m, $l) = $var; list($m, $l) = $var;
if (empty($m)) { if (empty($m)) {
$m = "%"; $m = "%";
} else {
$m = "%$m%";
} }
else {
$m = "%$m%";
}
if (empty($l)) { if (empty($l)) {
$l = 0; $l = 0;
} }
@ -74,21 +81,21 @@ class MessageColumn extends Column {
public function read_input($inputs) public function read_input($inputs)
{ {
$ret = emptyHTML( $ret = emptyHTML(
INPUT([ INPUT([
"type"=>"text", "type"=>"text",
"name"=>"r_{$this->name}[]", "name"=>"r_{$this->name}[]",
"placeholder"=>$this->title, "placeholder"=>$this->title,
"value"=>@$inputs["r_{$this->name}"][0] "value"=>@$inputs["r_{$this->name}"][0]
]) ])
); );
$options = [ $options = [
"Debug" => SCORE_LOG_DEBUG, "Debug" => SCORE_LOG_DEBUG,
"Info" => SCORE_LOG_INFO, "Info" => SCORE_LOG_INFO,
"Warning" => SCORE_LOG_WARNING, "Warning" => SCORE_LOG_WARNING,
"Error" => SCORE_LOG_ERROR, "Error" => SCORE_LOG_ERROR,
"Critical" => SCORE_LOG_CRITICAL, "Critical" => SCORE_LOG_CRITICAL,
]; ];
$s = SELECT(["name"=>"r_{$this->name}[]"]); $s = SELECT(["name"=>"r_{$this->name}[]"]);
$s->appendChild(OPTION(["value"=>""], '-')); $s->appendChild(OPTION(["value"=>""], '-'));
foreach ($options as $k => $v) { foreach ($options as $k => $v) {
@ -98,7 +105,7 @@ class MessageColumn extends Column {
} }
$s->appendChild(OPTION($attrs, $k)); $s->appendChild(OPTION($attrs, $k));
} }
$ret->appendChild($s); $ret->appendChild($s);
return $ret; return $ret;
} }
@ -192,8 +199,8 @@ class LogDatabase extends Extension
global $cache, $database, $user; global $cache, $database, $user;
if ($event->page_matches("log/view")) { if ($event->page_matches("log/view")) {
if ($user->can(Permissions::VIEW_EVENTLOG)) { if ($user->can(Permissions::VIEW_EVENTLOG)) {
$t = new LogTable($database->raw_db()); $t = new LogTable($database->raw_db());
$t->inputs = $_GET; $t->inputs = $_GET;
$this->theme->display_events($t->table($t->query()), $t->paginator()); $this->theme->display_events($t->table($t->query()), $t->paginator());
} }
} }

View File

@ -10,7 +10,7 @@ class NotATagTable extends Table
parent::__construct($db); parent::__construct($db);
$this->table = "untags"; $this->table = "untags";
$this->base_query = "SELECT * FROM untags"; $this->base_query = "SELECT * FROM untags";
$this->primary_key = "tag"; $this->primary_key = "tag";
$this->size = 100; $this->size = 100;
$this->limit = 1000000; $this->limit = 1000000;
$this->columns = [ $this->columns = [
@ -112,8 +112,10 @@ class NotATag extends Extension
} elseif ($event->get_arg(0) == "remove") { } elseif ($event->get_arg(0) == "remove") {
$user->ensure_authed(); $user->ensure_authed();
$input = validate_input(["d_tag"=>"string"]); $input = validate_input(["d_tag"=>"string"]);
$database->execute($database->scoreql_to_sql( $database->execute(
"DELETE FROM untags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"), $database->scoreql_to_sql(
"DELETE FROM untags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"
),
["tag"=>$input['d_tag']] ["tag"=>$input['d_tag']]
); );
flash_message("Image ban removed"); flash_message("Image ban removed");

View File

@ -8,24 +8,31 @@ use MicroCRUD\EnumColumn;
use MicroCRUD\TextColumn; use MicroCRUD\TextColumn;
use MicroCRUD\Table; use MicroCRUD\Table;
class UserNameColumn extends TextColumn { class UserNameColumn extends TextColumn
public function display(array $row) { {
public function display(array $row)
{
return A(["href"=>make_link("user/{$row[$this->name]}")], $row[$this->name]); return A(["href"=>make_link("user/{$row[$this->name]}")], $row[$this->name]);
} }
} }
class UserLinksColumn extends Column { class UserLinksColumn extends Column
public function __construct() { {
public function __construct()
{
parent::__construct("links", "User Links", "(1=1)"); parent::__construct("links", "User Links", "(1=1)");
$this->sortable = false; $this->sortable = false;
} }
public function create_input(array $inputs) { public function create_input(array $inputs)
{
return ""; return "";
} }
public function read_input(array $inputs) { public function read_input(array $inputs)
{
return ""; return "";
} }
public function display(array $row) { public function display(array $row)
{
return A(["href"=>make_link("post/list/user_id={$row['id']}/1")], "Posts"); 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; global $_shm_user_classes;
$classes = []; $classes = [];
foreach($_shm_user_classes as $cls) { foreach ($_shm_user_classes as $cls) {
$classes[$cls->name] = $cls->name; $classes[$cls->name] = $cls->name;
} }
ksort($classes); ksort($classes);
@ -190,7 +197,7 @@ class UserPage extends Extension
} }
$event->add_stats("Joined: $h_join_date", 10); $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("Current IP: {$_SERVER['REMOTE_ADDR']}", 80);
} }
$event->add_stats("Class: $h_class", 90); $event->add_stats("Class: $h_class", 90);