This commit is contained in:
Shish 2019-12-26 16:37:37 +00:00
commit 057ccd65c3
8 changed files with 144 additions and 79 deletions

50
composer.lock generated
View File

@ -11,7 +11,7 @@
"version": "1.12.4",
"source": {
"type": "git",
"url": "https://github.com/jquery/jquery-dist.git",
"url": "git@github.com:jquery/jquery-dist.git",
"reference": "5e89585e0121e72ff47de177c5ef604f3089a53d"
},
"dist": {
@ -388,12 +388,12 @@
"source": {
"type": "git",
"url": "https://github.com/shish/microcrud.git",
"reference": "f64681c605922909d57e9c17c0b63311f3c8a5d6"
"reference": "1f9d64bf0ff8c035b0709273a86f4ff9b791fe6e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/shish/microcrud/zipball/f64681c605922909d57e9c17c0b63311f3c8a5d6",
"reference": "f64681c605922909d57e9c17c0b63311f3c8a5d6",
"url": "https://api.github.com/repos/shish/microcrud/zipball/1f9d64bf0ff8c035b0709273a86f4ff9b791fe6e",
"reference": "1f9d64bf0ff8c035b0709273a86f4ff9b791fe6e",
"shasum": ""
},
"require": {
@ -429,7 +429,7 @@
"crud",
"generator"
],
"time": "2019-12-16T00:07:35+00:00"
"time": "2019-12-25T17:02:45+00:00"
},
{
"name": "shish/microhtml",
@ -485,12 +485,12 @@
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
"reference": "eca6c638ef64433b2e36a9221826e75e39c65eb9"
"reference": "6a1471ddbf2f448b35f3a8e390c903435e6dd5de"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/eca6c638ef64433b2e36a9221826e75e39c65eb9",
"reference": "eca6c638ef64433b2e36a9221826e75e39c65eb9",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/6a1471ddbf2f448b35f3a8e390c903435e6dd5de",
"reference": "6a1471ddbf2f448b35f3a8e390c903435e6dd5de",
"shasum": ""
},
"require": {
@ -533,7 +533,7 @@
"constructor",
"instantiate"
],
"time": "2019-12-06T20:47:21+00:00"
"time": "2019-12-23T19:18:31+00:00"
},
{
"name": "myclabs/deep-copy",
@ -695,12 +695,12 @@
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionCommon.git",
"reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a"
"reference": "b0843c8cbcc2dc5eda5158e583c7199a5e44c86d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a",
"reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/b0843c8cbcc2dc5eda5158e583c7199a5e44c86d",
"reference": "b0843c8cbcc2dc5eda5158e583c7199a5e44c86d",
"shasum": ""
},
"require": {
@ -739,7 +739,7 @@
"reflection",
"static analysis"
],
"time": "2018-08-07T13:53:10+00:00"
"time": "2019-12-20T12:45:35+00:00"
},
{
"name": "phpdocumentor/reflection-docblock",
@ -747,12 +747,12 @@
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "1aef412299c8901c2a80c384f026574557975894"
"reference": "c19ab7ef57e75b5790aa912fd1cd14708e811970"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/1aef412299c8901c2a80c384f026574557975894",
"reference": "1aef412299c8901c2a80c384f026574557975894",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/c19ab7ef57e75b5790aa912fd1cd14708e811970",
"reference": "c19ab7ef57e75b5790aa912fd1cd14708e811970",
"shasum": ""
},
"require": {
@ -792,7 +792,7 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"time": "2019-12-13T15:12:00+00:00"
"time": "2019-12-20T13:36:14+00:00"
},
{
"name": "phpdocumentor/type-resolver",
@ -842,33 +842,33 @@
},
{
"name": "phpspec/prophecy",
"version": "1.9.0",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
"reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203"
"reference": "cbe1df668b3fe136bcc909126a0f529a78d4cbbc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203",
"reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/cbe1df668b3fe136bcc909126a0f529a78d4cbbc",
"reference": "cbe1df668b3fe136bcc909126a0f529a78d4cbbc",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.0.2",
"php": "^5.3|^7.0",
"phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0",
"sebastian/comparator": "^1.1|^2.0|^3.0",
"sebastian/comparator": "^1.2.3|^2.0|^3.0",
"sebastian/recursion-context": "^1.0|^2.0|^3.0"
},
"require-dev": {
"phpspec/phpspec": "^2.5|^3.2",
"phpspec/phpspec": "^2.5 || ^3.2",
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.8.x-dev"
"dev-master": "1.10.x-dev"
}
},
"autoload": {
@ -901,7 +901,7 @@
"spy",
"stub"
],
"time": "2019-10-03T11:07:50+00:00"
"time": "2019-12-22T21:05:45+00:00"
},
{
"name": "phpunit/php-code-coverage",

View File

@ -13,6 +13,9 @@ abstract class DBEngine
/** @var null|string */
public $name = null;
public $BOOL_Y = null;
public $BOOL_N = null;
public function init(PDO $db)
{
}
@ -35,6 +38,9 @@ class MySQL extends DBEngine
/** @var string */
public $name = DatabaseDriver::MYSQL;
public $BOOL_Y = 'Y';
public $BOOL_N = 'N';
public function init(PDO $db)
{
$db->exec("SET NAMES utf8;");
@ -44,8 +50,8 @@ class MySQL extends DBEngine
{
$data = str_replace(SCORE::AIPK, "INTEGER PRIMARY KEY auto_increment", $data);
$data = str_replace(SCORE::INET, "VARCHAR(45)", $data);
$data = str_replace(SCORE::BOOL_Y, "'Y'", $data);
$data = str_replace(SCORE::BOOL_N, "'N'", $data);
$data = str_replace(SCORE::BOOL_Y, "'$this->BOOL_Y'", $data);
$data = str_replace(SCORE::BOOL_N, "'$this->BOOL_N'", $data);
$data = str_replace(SCORE::BOOL, "ENUM('Y', 'N')", $data);
return $data;
}
@ -71,6 +77,9 @@ class PostgreSQL extends DBEngine
/** @var string */
public $name = DatabaseDriver::PGSQL;
public $BOOL_Y = "true";
public $BOOL_N = "false";
public function init(PDO $db)
{
if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
@ -85,8 +94,8 @@ class PostgreSQL extends DBEngine
{
$data = str_replace(SCORE::AIPK, "INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY", $data);
$data = str_replace(SCORE::INET, "INET", $data);
$data = str_replace(SCORE::BOOL_Y, 'true', $data);
$data = str_replace(SCORE::BOOL_N, 'false', $data);
$data = str_replace(SCORE::BOOL_Y, "true", $data);
$data = str_replace(SCORE::BOOL_N, "false", $data);
$data = str_replace(SCORE::BOOL, "BOOL", $data);
return $data;
}
@ -154,6 +163,10 @@ class SQLite extends DBEngine
/** @var string */
public $name = DatabaseDriver::SQLITE;
public $BOOL_Y = 'Y';
public $BOOL_N = 'N';
public function init(PDO $db)
{
ini_set('sqlite.assoc_case', 0);
@ -174,8 +187,8 @@ class SQLite extends DBEngine
{
$data = str_replace(SCORE::AIPK, "INTEGER PRIMARY KEY", $data);
$data = str_replace(SCORE::INET, "VARCHAR(45)", $data);
$data = str_replace(SCORE::BOOL_Y, "'Y'", $data);
$data = str_replace(SCORE::BOOL_N, "'N'", $data);
$data = str_replace(SCORE::BOOL_Y, "'$this->BOOL_Y'", $data);
$data = str_replace(SCORE::BOOL_N, "'$this->BOOL_N'", $data);
$data = str_replace(SCORE::BOOL, "CHAR(1)", $data);
return $data;
}

View File

@ -1,5 +1,6 @@
<?php
use MicroCRUD\ActionColumn;
use MicroCRUD\TextColumn;
use MicroCRUD\Table;
@ -13,10 +14,11 @@ class AliasTable extends Table
$this->primary_key = "oldtag";
$this->size = 100;
$this->limit = 1000000;
$this->columns = [
$this->set_columns([
new TextColumn("oldtag", "Old Tag"),
new TextColumn("newtag", "New Tag"),
];
new ActionColumn("oldtag"),
]);
$this->order_by = ["oldtag"];
$this->table_attrs = ["class" => "zebra"];
}

View File

@ -1,5 +1,6 @@
<?php
use MicroCRUD\ActionColumn;
use MicroCRUD\StringColumn;
use MicroCRUD\DateColumn;
use MicroCRUD\TextColumn;
@ -15,11 +16,12 @@ class HashBanTable extends Table
$this->primary_key = "hash";
$this->size = 100;
$this->limit = 1000000;
$this->columns = [
$this->set_columns([
new StringColumn("hash", "Hash"),
new TextColumn("reason", "Reason"),
new DateColumn("date", "Date"),
];
new ActionColumn("id"),
]);
$this->order_by = ["date DESC", "id"];
$this->create_url = make_link("image_hash_ban/add");
$this->delete_url = make_link("image_hash_ban/remove");

View File

@ -1,5 +1,6 @@
<?php
use MicroCRUD\ActionColumn;
use MicroCRUD\InetColumn;
use MicroCRUD\StringColumn;
use MicroCRUD\DateColumn;
@ -21,7 +22,7 @@ class IPBanTable extends Table
";
$this->size = 100;
$this->limit = 1000000;
$this->columns = [
$this->set_columns([
new InetColumn("ip", "IP"),
new EnumColumn("mode", "Mode", [
"Block"=>"block",
@ -33,7 +34,8 @@ class IPBanTable extends Table
new StringColumn("banner", "Banner"),
new DateColumn("added", "Added"),
new DateColumn("expires", "Expires"),
];
new ActionColumn("id"),
]);
$this->order_by = ["expires", "id"];
$this->flags = [
"all" => ["((expires > CURRENT_TIMESTAMP) OR (expires IS NULL))", null],

View File

@ -8,6 +8,7 @@ use function MicroHTML\BR;
use function MicroHTML\SELECT;
use function MicroHTML\OPTION;
use function MicroHTML\rawHTML;
use MicroCRUD\ActionColumn;
use MicroCRUD\Column;
use MicroCRUD\DateTimeColumn;
use MicroCRUD\TextColumn;
@ -37,10 +38,54 @@ class ActorColumn extends Column
{
public function __construct($name, $title)
{
parent::__construct($name, $title, "((LOWER(username) LIKE LOWER(:{$name})) OR (address::text LIKE :{$name}))");
$this->input_mod = function ($var) {
return "%$var%";
};
parent::__construct($name, $title);
$this->sortable = false;
}
public function get_sql_filter(): string
{
$driver = $this->table->db->getAttribute(\PDO::ATTR_DRIVER_NAME);
switch ($driver) {
case "pgsql":
return "((username = :{$this->name}_0) OR (address && inet :{$this->name}_1))";
default:
return "((username = :{$this->name}_0) OR (address = :{$this->name}_1))";
}
}
public function read_input($inputs)
{
return emptyHTML(
INPUT([
"type" => "text",
"name" => "r_{$this->name}[]",
"placeholder" => "Username",
"value" => @$inputs["r_{$this->name}"][0]
]),
BR(),
INPUT([
"type" => "text",
"name" => "r_{$this->name}[]",
"placeholder" => "IP Address",
"value" => @$inputs["r_{$this->name}"][1]
])
);
}
public function modify_input_for_read($input)
{
list($un, $ip) = $input;
if (empty($un)) {
$un = null;
}
if (empty($ip)) {
$driver = $this->table->db->getAttribute(\PDO::ATTR_DRIVER_NAME);
switch ($driver) {
case "pgsql": $ip = "0.0.0.0/0"; break;
default: $ip = null; break;
}
}
return [$un, $ip];
}
public function display($row)
@ -59,23 +104,13 @@ class MessageColumn extends Column
{
public function __construct($name, $title)
{
parent::__construct(
$name,
$title,
"($name LIKE :{$name}_0 AND priority >= :{$name}_1)"
);
$this->input_mod = function ($var) {
list($m, $l) = $var;
if (empty($m)) {
$m = "%";
} else {
$m = "%$m%";
}
if (empty($l)) {
$l = 0;
}
return [$m, $l];
};
parent::__construct($name, $title);
$this->sortable = false;
}
public function get_sql_filter(): string
{
return "({$this->name} LIKE :{$this->name}_0 AND priority >= :{$this->name}_1)";
}
public function read_input($inputs)
@ -109,6 +144,20 @@ class MessageColumn extends Column
return $ret;
}
public function modify_input_for_read($input)
{
list($m, $l) = $input;
if (empty($m)) {
$m = "%";
} else {
$m = "%$m%";
}
if (empty($l)) {
$l = 0;
}
return [$m, $l];
}
public function display($row)
{
$c = "#000";
@ -143,12 +192,13 @@ class LogTable extends Table
$this->base_query = "SELECT * FROM score_log";
$this->size = 100;
$this->limit = 1000000;
$this->columns = [
$this->set_columns([
new ShortDateTimeColumn("date_sent", "Time"),
new TextColumn("section", "Module"),
new ActorColumn("username_or_address", "User"),
new MessageColumn("message", "Message")
];
new MessageColumn("message", "Message"),
new ActionColumn("id"),
]);
$this->order_by = ["date_sent DESC"];
$this->table_attrs = ["class" => "zebra"];
}

View File

@ -1,5 +1,6 @@
<?php
use MicroCRUD\ActionColumn;
use MicroCRUD\TextColumn;
use MicroCRUD\Table;
@ -13,10 +14,11 @@ class NotATagTable extends Table
$this->primary_key = "tag";
$this->size = 100;
$this->limit = 1000000;
$this->columns = [
$this->set_columns([
new TextColumn("tag", "Tag"),
new TextColumn("redirect", "Redirect"),
];
new ActionColumn("id"),
]);
$this->order_by = ["tag", "redirect"];
$this->create_url = make_link("untag/add");
$this->delete_url = make_link("untag/remove");
@ -114,8 +116,9 @@ class NotATag extends Extension
$input = validate_input(["d_tag"=>"string"]);
$database->execute(
$database->scoreql_to_sql(
"DELETE FROM untags WHERE LOWER(tag) = LOWER(:tag)"
),
"DELETE FROM untags WHERE LOWER(tag) = LOWER(:tag)"
),
["tag"=>$input['d_tag']]
);
$page->flash("Image ban removed");

View File

@ -3,7 +3,7 @@
require_once "events.php";
use function MicroHTML\A;
use MicroCRUD\Column;
use MicroCRUD\ActionColumn;
use MicroCRUD\EnumColumn;
use MicroCRUD\TextColumn;
use MicroCRUD\DateColumn;
@ -17,21 +17,14 @@ class UserNameColumn extends TextColumn
}
}
class UserLinksColumn extends Column
class UserActionColumn extends ActionColumn
{
public function __construct()
{
parent::__construct("links", "User Links", "(1=1)");
parent::__construct("id", "User Links");
$this->sortable = false;
}
public function create_input(array $inputs)
{
return "";
}
public function read_input(array $inputs)
{
return "";
}
public function display(array $row)
{
return A(["href"=>make_link("post/list/user={$row['name']}/1")], "Posts");
@ -53,14 +46,14 @@ class UserTable extends Table
$this->base_query = "SELECT * FROM users";
$this->size = 100;
$this->limit = 1000000;
$this->columns = [
$this->set_columns([
new UserNameColumn("name", "Name"),
new EnumColumn("class", "Class", $classes),
// Added later, for admins only
// new TextColumn("email", "Email"),
new DateColumn("joindate", "Join Date"),
new UserLinksColumn(),
];
new UserActionColumn(),
]);
$this->order_by = ["name"];
$this->table_attrs = ["class" => "zebra"];
}