diff --git a/get-sql.sh b/get-sql.sh new file mode 100755 index 0000000..dabd435 --- /dev/null +++ b/get-sql.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +mysqldump -d -h 192.168.0.3 -u dosThing -p dosThing > schema.sql diff --git a/kanga.world/site/plugins/download-kirbytag/composer.json b/kanga.world/site/plugins/download-kirbytag/composer.json new file mode 100644 index 0000000..895a2c4 --- /dev/null +++ b/kanga.world/site/plugins/download-kirbytag/composer.json @@ -0,0 +1,15 @@ +{ + "name": "kangaroopunch/download-kirbytag", + "type": "kirby-plugin", + "version": "1.0", + "license": "GPL3", + "authors": [ + { + "name": "Scott Duensing", + "email": "scott@kangaroopunch.com" + } + ], + "require": { + "getkirby/composer-installer": "^1.2" + } +} diff --git a/kanga.world/site/plugins/image-kirbytag/composer.json b/kanga.world/site/plugins/image-kirbytag/composer.json new file mode 100644 index 0000000..3b4d9b0 --- /dev/null +++ b/kanga.world/site/plugins/image-kirbytag/composer.json @@ -0,0 +1,15 @@ +{ + "name": "kangaroopunch/image-kirbytag", + "type": "kirby-plugin", + "version": "1.0", + "license": "GPL3", + "authors": [ + { + "name": "Scott Duensing", + "email": "scott@kangaroopunch.com" + } + ], + "require": { + "getkirby/composer-installer": "^1.2" + } +} diff --git a/kanga.world/site/plugins/kangaworld-integration/api/config.php b/kanga.world/site/plugins/kangaworld-integration/api/config.php index 3f25ec6..4331e4a 100644 --- a/kanga.world/site/plugins/kangaworld-integration/api/config.php +++ b/kanga.world/site/plugins/kangaworld-integration/api/config.php @@ -1,23 +1,23 @@ filterBy('type', 'config'); - $response['result'] = 'true'; - $response['reason'] = 'Configuration entries returned.'; + $response['payload'] = collection('kwconfig'); + $response['result'] = 'true'; + $response['reason'] = 'Configuration entries returned.'; } function kpApiConfigGetNumbers(&$response) { - $response['config'] = collection('kwconfig')->filterBy('type', 'number'); - $response['result'] = 'true'; - $response['reason'] = 'Number entries returned.'; + $response['payload'] = collection('kwnumbers'); + $response['result'] = 'true'; + $response['reason'] = 'Number entries returned.'; } function kpApiConfigGetStrings(&$response) { - $response['config'] = collection('kwconfig')->filterBy('type', 'string'); - $response['result'] = 'true'; - $response['reason'] = 'String entries returned.'; + $response['payload'] = collection('kwstrings'); + $response['result'] = 'true'; + $response['reason'] = 'String entries returned.'; } ?> diff --git a/kanga.world/site/plugins/kangaworld-integration/classes/KPunch.php b/kanga.world/site/plugins/kangaworld-integration/classes/KPunch.php index 8119569..70a7c02 100644 --- a/kanga.world/site/plugins/kangaworld-integration/classes/KPunch.php +++ b/kanga.world/site/plugins/kangaworld-integration/classes/KPunch.php @@ -2,6 +2,10 @@ namespace KangarooPunch; + +use \PDO; + + class KPunch { public static function databaseGet() { diff --git a/kanga.world/site/plugins/kangaworld-integration/classes/KwConfig.php b/kanga.world/site/plugins/kangaworld-integration/classes/KwConfig.php index fc3885d..124bebd 100644 --- a/kanga.world/site/plugins/kangaworld-integration/classes/KwConfig.php +++ b/kanga.world/site/plugins/kangaworld-integration/classes/KwConfig.php @@ -2,140 +2,88 @@ namespace KangarooPunch; -use Kirby\Data\Data; + +use KangarooPunch\KPunch; use Kirby\Exception\InvalidArgumentException; use Kirby\Exception\NotFoundException; use Kirby\Toolkit\V; -class KwConfig -{ - /** - * Creates a new entry with the given $input - * data and adds it to the json file - * - * @return bool - */ - public static function create(array $input): bool - { - // reuse the update method to create a new - // entry. If you need different logic - // here, you can easily extend it - return static::update($input); - } +class KwConfig { - /** - * Deletes a entry by product id - * - * @return bool - */ - public static function delete(string $id): bool - { - // get all entry - $kwconfig = static::list(); + public static function create(array $input): bool { + validate($input); + $db = KPunch::databaseGet(); + KPunch::databaseQueryToJSON($db, + 'INSERT INTO config (name, data, description) VALUES (?, ?, ?)', + array( + $input['name'], + $input['data'], + $input['description'] + ) + ); + return true; + } - // remove the entry from the list - unset($kwconfig[$id]); - // write the update list to the file - return Data::write(static::file(), $kwconfig); - } + public static function delete(string $id): bool { + $db = KPunch::databaseGet(); + KPunch::databaseQueryToJSON($db, 'DELETE FROM config WHERE id = ?', array($id)); + return true; + } - /** - * Returns the absolute path to the settings.json - * This is the place to modify if you don't want to - * store the entries in your plugin folder - * – which you probably really don't want to do. - * - * @return string - */ - public static function file(): string - { - return __DIR__ . '/../settings.json'; - } - /** - * Finds an entry by id and throws an exception - * if the entry cannot be found - * - * @param string $id - * @return array - */ - public static function find(string $id): array - { - $kwconfig = static::list()[$id] ?? null; + public static function find(string $id): array { + $db = KPunch::databaseGet(); + $result = KPunch::databaseQueryToJSON($db, 'SELECT * FROM config WHERE id = ?', array($id)); + if ($result == null) { + throw new NotFoundException('The entry could not be found'); + } + return json_decode($result); + } - if (empty($kwconfig) === true) { - throw new NotFoundException('The entry could not be found'); - } - return $kwconfig; - } + public static function list(): array { + $db = KPunch::databaseGet(); + return json_decode(KPunch::databaseQueryToJSON($db, 'SELECT * FROM config')); + } - /** - * Lists all entries from the settings.json - * - * @return array - */ - public static function list(): array - { - return Data::read(static::file()); - } - /** - * Lists all available entry types - * - * @return array - */ - public static function types(): array - { - return [ - 'config', - 'number', - 'string' - ]; - } + public static function update(array $input): bool { + validate($input); + $db = KPunch::databaseGet(); + KPunch::databaseQueryToJSON($db, + 'UPDATE config SET name = ?, data = ?, description = ? WHERE id = ?', + array( + $input['name'], + $input['data'], + $input['description'], + $input['id'] + ) + ); + return true; + } - /** - * Updates a entries by id with the given input - * It throws an exception in case of validation issues - * - * @param string $id - * @param array $input - * @return boolean - */ - public static function update(array $input): bool - { - $kwconfig = [ - 'title' => $input['title'] ?? null, - 'type' => $input['type'] ?? null, - 'description' => $input['description'] ?? null, - 'data' => $input['data'] ?? null - ]; - // require a title - if (V::minlength($kwconfig['title'], 1) === false) { - throw new InvalidArgumentException('The title must not be empty'); - } + private static function validate($input) { + if (V::minlength($input['name'], 1) === false) { + throw new InvalidArgumentException('The name must not be empty'); + } + if (V::maxlength($input['name'], 32) === false) { + throw new InvalidArgumentException('The name must not be longer than 32 characters'); + } - // make sure the title is not longer than expected - if (V::maxlength($kwconfig['title'], 255) === false) { - throw new InvalidArgumentException('The title must not be longer than 255 characters'); - } + if (V::minlength($input['data'], 1) === false) { + throw new InvalidArgumentException('The data must not be empty'); + } + if (V::maxlength($input['data'], 4096) === false) { + throw new InvalidArgumentException('The data must not be longer than 4096 characters'); + } - // validate the category - if (V::in($kwconfig['type'], static::types()) === false) { - throw new InvalidArgumentException('Please select a valid category'); - } - - // load all products - $kwconfig = static::list(); - - // set/overwrite the data - $kwconfig[$id] = $kwconfig; - - return Data::write(static::file(), $kwconfig); - } + if (V::maxlength($input['description'], 255) === false) { + throw new InvalidArgumentException('The description must not be longer than 255 characters'); + } + } } diff --git a/kanga.world/site/plugins/kangaworld-integration/classes/KwNumbers.php b/kanga.world/site/plugins/kangaworld-integration/classes/KwNumbers.php new file mode 100644 index 0000000..b255bbe --- /dev/null +++ b/kanga.world/site/plugins/kangaworld-integration/classes/KwNumbers.php @@ -0,0 +1,83 @@ + diff --git a/kanga.world/site/plugins/kangaworld-integration/features/collections.php b/kanga.world/site/plugins/kangaworld-integration/features/collections.php index 091f932..fccbfa4 100644 --- a/kanga.world/site/plugins/kangaworld-integration/features/collections.php +++ b/kanga.world/site/plugins/kangaworld-integration/features/collections.php @@ -1,6 +1,7 @@ function($site) { + return new Collection(KwNumbers::list()); + }, + 'kwstrings' => function($site) { return new Collection(KwStrings::list()); } diff --git a/kanga.world/site/plugins/kangaworld-integration/index.php b/kanga.world/site/plugins/kangaworld-integration/index.php index ac69637..28aba97 100644 --- a/kanga.world/site/plugins/kangaworld-integration/index.php +++ b/kanga.world/site/plugins/kangaworld-integration/index.php @@ -1,17 +1,10 @@ __DIR__ . '/classes/KPunch.php', - 'KangarooPunch\KwConfig' => __DIR__ . '/classes/KwConfig.php', - 'KangarooPunch\KwStrings' => __DIR__ . '/classes/KwStrings.php' -]); -*/ - -load([ - 'KangarooPunch\KPunch ' => 'KPunch.php', 'KangarooPunch\KwConfig' => 'KwConfig.php', - 'KangarooPunch\KwStrings' => 'KwStrings.php' + 'KangarooPunch\KwNumbers' => 'KwNumbers.php', + 'KangarooPunch\KwStrings' => 'KwStrings.php', + 'KangarooPunch\KPunch' => 'KPunch.php' ], __DIR__ . '/classes'); diff --git a/kanga.world/site/plugins/kangaworld-integration/settings.json.example b/kanga.world/site/plugins/kangaworld-integration/settings.json.example deleted file mode 100644 index 688aa24..0000000 --- a/kanga.world/site/plugins/kangaworld-integration/settings.json.example +++ /dev/null @@ -1,20 +0,0 @@ -{ - "configItem": { - "name": "configItem", - "type": "config", - "data": "2048", - "description": "Sample CONFIG item." - }, - "numberItem": { - "name": "numberItem", - "type": "number", - "data": "16550", - "description": "Sample NUMBER item." - }, - "stringItem": { - "name": "stringItem", - "type": "string", - "data": "aValue", - "description": "Sample STRING item." - } -} diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000..276de42 --- /dev/null +++ b/schema.sql @@ -0,0 +1,97 @@ +-- MySQL dump 10.19 Distrib 10.3.32-MariaDB, for debian-linux-gnu (x86_64) +-- +-- Host: 192.168.0.3 Database: dosThing +-- ------------------------------------------------------ +-- Server version 10.5.13-MariaDB-log + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `config` +-- + +DROP TABLE IF EXISTS `config`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `config` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(32) NOT NULL, + `data` varchar(4096) NOT NULL, + `description` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `nameIDX` (`name`), + KEY `descriptionIDX` (`description`) +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `numbers` +-- + +DROP TABLE IF EXISTS `numbers`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `numbers` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(32) NOT NULL, + `data` int(11) NOT NULL, + `description` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `nameIDX` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `strings` +-- + +DROP TABLE IF EXISTS `strings`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `strings` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(32) NOT NULL, + `data` varchar(4096) NOT NULL, + `description` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `nameIDX` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `users` +-- + +DROP TABLE IF EXISTS `users`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user` varchar(256) NOT NULL, + `pass` varchar(256) NOT NULL, + `email` varchar(256) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `emailIDX` (`email`), + UNIQUE KEY `userIDX` (`user`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2022-01-12 19:05:55