From 2eb5a432d2229788ce2fdb09f36c6f4bebdea813 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Fri, 7 Feb 2020 09:44:59 +0100 Subject: Initial commit --- .gitignore | 1 + assets/interactive.js | 293 +++++ assets/styles.css | 232 ++++ composer.json | 27 + composer.lock | 1877 ++++++++++++++++++++++++++++++ config.php | 6 + index.php | 25 + src/BoundVal.php | 36 + src/DBError.php | 31 + src/DbQuery.php | 197 ++++ src/Entrypoint.php | 10 + src/Env.php | 80 ++ src/Esc.php | 21 + src/Handler.php | 10 + src/Handlers/ApiTagsHandler.php | 16 + src/Handlers/Index.php | 20 + src/Handlers/JsonAPIHandler.php | 18 + src/Handlers/JsonAPIResult.php | 24 + src/Handlers/MethodNotAllowedHandler.php | 14 + src/Handlers/NewNote.php | 40 + src/Handlers/NotFoundHandler.php | 15 + src/Handlers/NoteHandler.php | 39 + src/Handlers/Search.php | 33 + src/Log.php | 27 + src/Main.php | 58 + src/Models/Note.php | 250 ++++ src/Models/Tag.php | 37 + src/Schema.php | 80 ++ src/Search/AbstractFTSExpr.php | 31 + src/Search/CharSource.php | 33 + src/Search/FTSExpr.php | 30 + src/Search/FTSLogicOp.php | 46 + src/Search/FTSNotExpr.php | 29 + src/Search/LogicOp.php | 78 ++ src/Search/NotOp.php | 32 + src/Search/Pagination.php | 14 + src/Search/ParseError.php | 9 + src/Search/Parser.php | 295 +++++ src/Search/SQLSearchExpr.php | 11 + src/Search/SearchExpr.php | 14 + src/Search/SearchResult.php | 160 +++ src/Search/TagExpr.php | 42 + src/Search/TrueExpr.php | 25 + src/Tools/PopulateDevDb.php | 71 ++ templates/index.twig | 13 + templates/macros.twig | 50 + templates/new_note.twig | 5 + templates/note.twig | 15 + templates/search.twig | 23 + templates/skeleton.twig | 35 + tests/Search/ParserTest.php | 120 ++ 51 files changed, 4698 insertions(+) create mode 100644 .gitignore create mode 100644 assets/interactive.js create mode 100644 assets/styles.css create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 config.php create mode 100644 index.php create mode 100644 src/BoundVal.php create mode 100644 src/DBError.php create mode 100644 src/DbQuery.php create mode 100644 src/Entrypoint.php create mode 100644 src/Env.php create mode 100644 src/Esc.php create mode 100644 src/Handler.php create mode 100644 src/Handlers/ApiTagsHandler.php create mode 100644 src/Handlers/Index.php create mode 100644 src/Handlers/JsonAPIHandler.php create mode 100644 src/Handlers/JsonAPIResult.php create mode 100644 src/Handlers/MethodNotAllowedHandler.php create mode 100644 src/Handlers/NewNote.php create mode 100644 src/Handlers/NotFoundHandler.php create mode 100644 src/Handlers/NoteHandler.php create mode 100644 src/Handlers/Search.php create mode 100644 src/Log.php create mode 100644 src/Main.php create mode 100644 src/Models/Note.php create mode 100644 src/Models/Tag.php create mode 100644 src/Schema.php create mode 100644 src/Search/AbstractFTSExpr.php create mode 100644 src/Search/CharSource.php create mode 100644 src/Search/FTSExpr.php create mode 100644 src/Search/FTSLogicOp.php create mode 100644 src/Search/FTSNotExpr.php create mode 100644 src/Search/LogicOp.php create mode 100644 src/Search/NotOp.php create mode 100644 src/Search/Pagination.php create mode 100644 src/Search/ParseError.php create mode 100644 src/Search/Parser.php create mode 100644 src/Search/SQLSearchExpr.php create mode 100644 src/Search/SearchExpr.php create mode 100644 src/Search/SearchResult.php create mode 100644 src/Search/TagExpr.php create mode 100644 src/Search/TrueExpr.php create mode 100644 src/Tools/PopulateDevDb.php create mode 100644 templates/index.twig create mode 100644 templates/macros.twig create mode 100644 templates/new_note.twig create mode 100644 templates/note.twig create mode 100644 templates/search.twig create mode 100644 templates/skeleton.twig create mode 100644 tests/Search/ParserTest.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..48b8bf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor/ diff --git a/assets/interactive.js b/assets/interactive.js new file mode 100644 index 0000000..05b7556 --- /dev/null +++ b/assets/interactive.js @@ -0,0 +1,293 @@ +$(function () { + function APIError(code, message) { + this.code = code; + this.message = message; + } + + APIError.prototype.toString = function () { + return "APIError " + this.code + ": " + this.message; + }; + + function default_api_error_handler(data, code) { + throw new APIError(code, data); + } + + function add_get_param(url, name, val) { + name = encodeURIComponent(name); + val = encodeURIComponent(val); + + var separator = url.match(/\?/) === null ? "?" : "&"; + return url + separator + name + "=" + val; + } + + function add_get_params(url, params) { + for (var k in params) if (Object.prototype.hasOwnProperty.call(params, k)) + url = add_get_param(url, k, params[k]); + return url; + } + + function query_api(method, url, arguments, handler, error_handler) { + url = add_get_params(url, arguments); + error_handler = error_handler || default_api_error_handler; + + var xhr = new XMLHttpRequest(); + + function wrap_handler(handler) { + return function () { + return handler(xhr.response, xhr.status, xhr); + } + } + + xhr.addEventListener("load", wrap_handler(handler)); + xhr.addEventListener("error", wrap_handler(error_handler)); + xhr.open(method, url); + xhr.responseType = "json"; + xhr.send(); + } + + function Autocomplete() { + var self = this; + + this.root = $("
") + .addClass("autocomplete-root"); + this.input = $("") + .attr("type", "text") + .appendTo(this.root) + .on("keyup", function (ev) { + if (ev.key === "ArrowDown") self.change_selection(1); + if (ev.key === "ArrowUp") self.change_selection(-1); + + self.change_listener(); + }) + .on("keydown", function (ev) { + if (ev.key === "Tab") { + if (self.complete_current()) + ev.preventDefault(); + } + }) + .on("blur", function (ev) { + var visible = false; + if (ev.relatedTarget) { + visible = $(ev.relatedTarget).closest(".autocomplete-root").get(0) === self.root.get(0); + } + self.set_visible(visible); + }); + this.options = $("