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

@ -246,7 +246,7 @@ class User
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 *
@ -527,7 +528,7 @@ function _fatal_error(Exception $e): void
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']));
@ -536,13 +537,12 @@ function _fatal_error(Exception $e): void
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 '
@ -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,7 +72,7 @@ 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]));
@ -81,7 +81,7 @@ class AdminPage extends Extension
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]));

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

@ -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,10 +31,10 @@ 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}))");
@ -48,7 +55,8 @@ class ActorColumn extends Column {
} }
} }
class MessageColumn extends Column { class MessageColumn extends Column
{
public function __construct($name, $title) public function __construct($name, $title)
{ {
parent::__construct( parent::__construct(
@ -60,8 +68,7 @@ class MessageColumn extends Column {
list($m, $l) = $var; list($m, $l) = $var;
if (empty($m)) { if (empty($m)) {
$m = "%"; $m = "%";
} } else {
else {
$m = "%$m%"; $m = "%$m%";
} }
if (empty($l)) { if (empty($l)) {

View File

@ -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);