diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..fd1294f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +charset = utf-8 +trim_trailing_whitespace = true + +end_of_line = lf +insert_final_newline = true + +indent_style = space +indent_size = 4 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..ab8dec2 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +composer.lock binary +package-lock.json binary diff --git a/.gitignore b/.gitignore index 33dec3a..a589b70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,132 @@ +## Node +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.pnp.* + + +## Composer +composer.phar +/vendor/ + +# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control +# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file +# composer.lock + + +## Custom +dist/ src/main/.death-notifier.db -src/main/config.ini -src/main/mailer +src/main/config.ini.php diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..2bde678 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,132 @@ +const path = require("path"); + +module.exports = grunt => { + grunt.initConfig({ + pkg: grunt.file.readJSON("package.json"), + clean: { + default: ["dist/"], + }, + copy: { + composer: { + files: [{expand: true, cwd: "./", src: "vendor/**", dest: "dist/", flatten: false}] + }, + css: { + files: [{expand: true, cwd: "src/main/", src: "**/*.css", dest: "dist/", flatten: true}] + }, + html: { + files: [{expand: true, cwd: "src/main/", src: "**/*.html", dest: "dist/", flatten: true}] + }, + php: { + files: [{expand: true, cwd: "src/main/", src: "**/*.php", dest: "dist/", flatten: true}] + }, + }, + focus: { + dev: { + include: ["css", "html", "php", "ts"], + }, + }, + replace: { + dev: { + src: ["./dist/**/*.html", "./dist/**/*.js", "./dist/**/*.php"], + replacements: [ + { + from: "%%VERSION_NUMBER%%", + to: "<%= pkg.version %>+" + new Date().toISOString().slice(0, 19).replace(/[-:T]/g, "") + } + ], + overwrite: true + }, + deploy: { + src: ["./dist/**/*.html", "./dist/**/*.js", "./dist/**/*.php"], + replacements: [ + { + from: "%%VERSION_NUMBER%%", + to: "<%= pkg.version %>" + } + ], + overwrite: true + }, + }, + watch: { + css: { + files: ["src/main/**/*.css"], + tasks: ["copy:css"], + }, + html: { + files: ["src/main/**/*.html"], + tasks: ["copy:html"], + }, + php: { + files: ["src/main/**/*.php"], + tasks: ["copy:php"], + }, + ts: { + files: ["src/main/**/*.ts"], + tasks: ["webpack:dev", "replace:dev"], + }, + }, + webpack: { + options: { + entry: "./src/main/js/Main.ts", + module: { + rules: [ + { + test: /\.ts$/, + use: "ts-loader", + exclude: /node_modules/, + }, + ], + }, + resolve: { + extensions: [".ts"], + }, + output: { + filename: "bundle.js", + path: path.resolve(__dirname, "dist/"), + }, + }, + dev: { + mode: "development", + devtool: "inline-source-map", + }, + deploy: { + mode: "production", + }, + }, + }); + + grunt.loadNpmTasks("grunt-contrib-clean"); + grunt.loadNpmTasks("grunt-contrib-copy"); + grunt.loadNpmTasks("grunt-contrib-watch"); + grunt.loadNpmTasks("grunt-focus"); + grunt.loadNpmTasks("grunt-text-replace"); + grunt.loadNpmTasks("grunt-webpack"); + + grunt.registerTask("dev", [ + // Pre + "clean", + // Copy files + "copy:composer", + "copy:css", + "copy:html", + "copy:php", + // Compile JS + "webpack:dev", + "replace:dev", + ]); + grunt.registerTask("dev:server", ["dev", "focus:dev"]); + grunt.registerTask("deploy", [ + // Pre + "clean", + // Copy files + "copy:composer", + "copy:css", + "copy:html", + "copy:php", + // Compile JS + "webpack:deploy", + "replace:deploy", + ]); + + grunt.registerTask("default", ["dev"]); +}; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..361b6f7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Florine W. Dekker + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..9784c67 --- /dev/null +++ b/composer.json @@ -0,0 +1,23 @@ +{ + "name": "fwdekker/death-notifier", + "description": "Get notified when a famous person dies.", + "version": "0.0.1", + "type": "project", + "license": "MIT", + "homepage": "https://git.fwdekker.com/tools/death-notifier", + "support": { + "issues": "https://git.fwdekker.com/tools/death-notifier/issues", + "source": "https://git.fwdekker.com/tools/death-notifier" + }, + "authors": [ + { + "name": "Florine W. Dekker", + "email": "florine@fwdekker.com" + } + ], + "require": { + "ext-sqlite3": "*", + "phpmailer/phpmailer": "^6.5" + }, + "minimum-stability": "stable" +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..061e9d9 Binary files /dev/null and b/composer.lock differ diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..112e3af Binary files /dev/null and b/package-lock.json differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..a72b74d --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "death-notifier", + "version": "0.0.1", + "description": "Get notified when a famous person dies.", + "author": "Florine W. Dekker", + "browser": "dist/bundle.js", + "repository": { + "type": "git", + "url": "git@git.fwdekker.com:tools/death-notifier.git" + }, + "private": true, + "scripts": { + "clean": "grunt clean", + "dev": "grunt dev", + "dev:server": "grunt dev:server", + "deploy": "grunt deploy" + }, + "devDependencies": { + "grunt": "^1.5.3", + "grunt-cli": "^1.4.3", + "grunt-contrib-clean": "^2.0.1", + "grunt-contrib-copy": "^1.0.0", + "grunt-contrib-watch": "^1.1.0", + "grunt-focus": "^1.0.0", + "grunt-text-replace": "^0.4.0", + "grunt-webpack": "^5.0.0", + "ts-loader": "^9.3.1", + "typescript": "^4.7.4", + "webpack": "^5.74.0", + "webpack-cli": "^4.10.0" + } +} diff --git a/src/main/db.php b/src/main/Database.php similarity index 82% rename from src/main/db.php rename to src/main/Database.php index f592425..cf72e33 100644 --- a/src/main/db.php +++ b/src/main/Database.php @@ -1,6 +1,8 @@ db->exec("CREATE TABLE users(uuid text primary key not null, email text not null, password text not null);"); + // TODO: Do email verification stuff: `current_email` and `email_is_verified` and stuff + $this->db->exec("CREATE TABLE trackings(user_uuid text not null, person_name text not null, is_deceased int not null)"); } function add_user($uuid, $email, $password): bool diff --git a/src/main/api.php b/src/main/api.php index 6546d86..c3bec4d 100644 --- a/src/main/api.php +++ b/src/main/api.php @@ -1,40 +1,35 @@ exec("CREATE TABLE users(uuid text primary key not null, email text not null, password text not null);"); - // TODO: Do email verification stuff: `current_email` and `email_is_verified` and stuff - $db->exec("CREATE TABLE trackings(user_uuid text not null, person_name text not null, is_deceased int not null)"); - - $db->close(); -} if (!file_exists($config["database"]["filename"])) { - exit(); + (new SQLite3($config["database"]["filename"]))->close(); + + $db = new Database($config["database"]["filename"], SQLITE3_OPEN_READWRITE); + $db->install(); + $db->close(); } session_start(); diff --git a/src/main/config.default.ini b/src/main/config.default.ini.php similarity index 88% rename from src/main/config.default.ini rename to src/main/config.default.ini.php index 7e4dad6..5720bed 100644 --- a/src/main/config.default.ini +++ b/src/main/config.default.ini.php @@ -1,3 +1,5 @@ +; + [database] filename = .death-notifier.db diff --git a/src/main/index.php b/src/main/index.php index c3f8ba1..3619c10 100644 --- a/src/main/index.php +++ b/src/main/index.php @@ -1,9 +1,58 @@ - - + + + + + + + + + + + + + + Death Notifier | FWDekker + + + + + + + + + +
+ +
+ + + +
+ CONTENTS +
+
+ +
+ + + + + + + diff --git a/src/main/js/Main.ts b/src/main/js/Main.ts new file mode 100644 index 0000000..dde0c1e --- /dev/null +++ b/src/main/js/Main.ts @@ -0,0 +1,17 @@ +// @ts-ignore +const {$, doAfterLoad, footer, header, nav} = window.fwdekker; + + +doAfterLoad(() => { + // Initialize template + $("#nav").appendChild(nav("/Tools/Death-Notifier/")); + $("#header").appendChild(header({ + title: "Death Notifier", + description: "Get notified when a famous person dies" + })); + $("#footer").appendChild(footer({ + vcsURL: "https://git.fwdekker.com/tools/death-notifier/", + version: "v%%VERSION_NUMBER%%" + })); + $("main").classList.remove("hidden"); +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..69c22e6 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "es6", + "strict": true, + "rootDir": "./src/main/js/", + "outDir": "./dist/js/" + }, + "include": [ + "src/main/js/**/*.ts" + ] +}