formatting
This commit is contained in:
parent
f09d328b30
commit
d705578f79
10 changed files with 120 additions and 88 deletions
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
use function MicroHTML\{FORM,INPUT};
|
||||
use function MicroHTML\FORM;
|
||||
use function MicroHTML\INPUT;
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
||||
* Misc *
|
||||
|
@ -525,27 +526,26 @@ function _fatal_error(Exception $e): void
|
|||
//'.$h_hash.'
|
||||
|
||||
if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') {
|
||||
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("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)) ? "" : "<p><b>Query:</b> " . 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)) ? "" : "<p><b>Query:</b> " . html_escape($e->query);
|
||||
header("HTTP/1.0 500 Internal Error");
|
||||
echo '
|
||||
<html>
|
||||
<head>
|
||||
<title>Internal error - SCore-'.$version.'</title>
|
||||
|
@ -558,7 +558,7 @@ function _fatal_error(Exception $e): void
|
|||
</body>
|
||||
</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;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
<?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
|
||||
{
|
||||
|
|
|
@ -12,9 +12,9 @@ class HashBanTable extends Table
|
|||
parent::__construct($db);
|
||||
$this->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"),
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
<?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\DateTimeColumn;
|
||||
use MicroCRUD\TextColumn;
|
||||
use MicroCRUD\Table;
|
||||
|
||||
|
||||
class ShortDateTimeColumn extends DateTimeColumn {
|
||||
class ShortDateTimeColumn extends DateTimeColumn
|
||||
{
|
||||
public function read_input(array $inputs)
|
||||
{
|
||||
return emptyHTML(
|
||||
|
@ -24,31 +31,32 @@ class ShortDateTimeColumn extends DateTimeColumn {
|
|||
])
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ActorColumn extends Column {
|
||||
class ActorColumn extends Column
|
||||
{
|
||||
public function __construct($name, $title)
|
||||
{
|
||||
parent::__construct($name, $title, "((username LIKE :{$name}) OR (address::text LIKE :{$name}))");
|
||||
$this->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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
Reference in a new issue