From 67afe948bdc579aa99aee40ba69ff9c46c0eca6d Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 26 Dec 2019 00:25:18 +0000 Subject: [PATCH 1/6] format --- ext/not_a_tag/main.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/not_a_tag/main.php b/ext/not_a_tag/main.php index d6cc0289..1dece127 100644 --- a/ext/not_a_tag/main.php +++ b/ext/not_a_tag/main.php @@ -114,8 +114,8 @@ 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"); From bafdb1c769364ef660d7204d13678866907f52f1 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 26 Dec 2019 00:36:32 +0000 Subject: [PATCH 2/6] crud update --- composer.lock | 50 +++++++++---------- ext/alias_editor/main.php | 6 ++- ext/image_hash_ban/main.php | 6 ++- ext/ipban/main.php | 6 ++- ext/log_db/main.php | 99 ++++++++++++++++++++++++++++--------- ext/not_a_tag/main.php | 7 ++- ext/user/main.php | 21 +++----- 7 files changed, 124 insertions(+), 71 deletions(-) diff --git a/composer.lock b/composer.lock index b1168239..63b2d4a6 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 5db1d22f..1c540228 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -1,5 +1,6 @@ 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"]; } diff --git a/ext/image_hash_ban/main.php b/ext/image_hash_ban/main.php index be90ab67..4d5820ee 100644 --- a/ext/image_hash_ban/main.php +++ b/ext/image_hash_ban/main.php @@ -1,5 +1,6 @@ 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"); diff --git a/ext/ipban/main.php b/ext/ipban/main.php index e57baa32..7656c393 100644 --- a/ext/ipban/main.php +++ b/ext/ipban/main.php @@ -1,5 +1,6 @@ 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], diff --git a/ext/log_db/main.php b/ext/log_db/main.php index 18c74290..cfb13827 100644 --- a/ext/log_db/main.php +++ b/ext/log_db/main.php @@ -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,55 @@ 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]; +>>>>>>> crud update } public function display($row) @@ -59,23 +105,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 +145,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 +193,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"]; } diff --git a/ext/not_a_tag/main.php b/ext/not_a_tag/main.php index 1dece127..f40a8887 100644 --- a/ext/not_a_tag/main.php +++ b/ext/not_a_tag/main.php @@ -1,5 +1,6 @@ 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"); @@ -116,6 +118,7 @@ class NotATag extends Extension $database->scoreql_to_sql( "DELETE FROM untags WHERE LOWER(tag) = LOWER(:tag)" ), + ["tag"=>$input['d_tag']] ); $page->flash("Image ban removed"); diff --git a/ext/user/main.php b/ext/user/main.php index 0745388c..c7a1cb16 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -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\Table; @@ -16,21 +16,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"); @@ -52,13 +45,13 @@ 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 UserLinksColumn(), - ]; + new UserActionColumn(), + ]); $this->order_by = ["name"]; $this->table_attrs = ["class" => "zebra"]; } From f3cb70a06db401a314bfd80707b1cd98fc52a958 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 26 Dec 2019 16:20:05 +0000 Subject: [PATCH 3/6] Revert "inline some one-use vars" This reverts commit 1c3d4ad5e3fe2a2f454109b8f00c5d200bc6e5b3. --- core/dbengine.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/core/dbengine.php b/core/dbengine.php index 120b56c2..95ded663 100644 --- a/core/dbengine.php +++ b/core/dbengine.php @@ -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, $this->BOOL_Y, $data); + $data = str_replace(SCORE::BOOL_N, $this->BOOL_N, $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; } From 8bc7d5d44597a491edd856f995060fc262364b20 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 26 Dec 2019 16:21:15 +0000 Subject: [PATCH 4/6] pg --- core/dbengine.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/dbengine.php b/core/dbengine.php index 95ded663..375c8a98 100644 --- a/core/dbengine.php +++ b/core/dbengine.php @@ -77,8 +77,8 @@ class PostgreSQL extends DBEngine /** @var string */ public $name = DatabaseDriver::PGSQL; - public $BOOL_Y = 'true'; - public $BOOL_N = 'false'; + public $BOOL_Y = true; + public $BOOL_N = false; public function init(PDO $db) { @@ -94,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, $this->BOOL_Y, $data); - $data = str_replace(SCORE::BOOL_N, $this->BOOL_N, $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; } From 6516e5cc46e36859edc28e97ae0c44d79c5aea89 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 26 Dec 2019 16:23:29 +0000 Subject: [PATCH 5/6] argh --- ext/log_db/main.php | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/log_db/main.php b/ext/log_db/main.php index cfb13827..02c67c26 100644 --- a/ext/log_db/main.php +++ b/ext/log_db/main.php @@ -86,7 +86,6 @@ class ActorColumn extends Column } } return [$un, $ip]; ->>>>>>> crud update } public function display($row) From 51628607d057cc88bc8896e472187df168481411 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 26 Dec 2019 16:33:08 +0000 Subject: [PATCH 6/6] ...? --- core/dbengine.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/dbengine.php b/core/dbengine.php index 375c8a98..e91033b0 100644 --- a/core/dbengine.php +++ b/core/dbengine.php @@ -77,8 +77,8 @@ class PostgreSQL extends DBEngine /** @var string */ public $name = DatabaseDriver::PGSQL; - public $BOOL_Y = true; - public $BOOL_N = false; + public $BOOL_Y = "true"; + public $BOOL_N = "false"; public function init(PDO $db) {