Skip to content

Commit

Permalink
initital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Scheurich committed Nov 10, 2021
0 parents commit 1c88ca1
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# OS files
.DS_Store
*.cache
.idea
*.map

# files of Composer dependencies that are not needed for the plugin
/vendor/**/.*
/vendor/**/*.json
/vendor/**/*.txt
/vendor/**/*.md
/vendor/**/*.yml
/vendor/**/*.yaml
/vendor/**/*.xml
/vendor/**/*.dist
/vendor/**/readme.php
/vendor/**/LICENSE
/vendor/**/COPYING
/vendor/**/VERSION
/vendor/**/docs/*
/vendor/**/example/*
/vendor/**/examples/*
/vendor/**/test/*
/vendor/**/tests/*
/vendor/**/php4/*
/vendor/getkirby/composer-installer

/node_modules
/.cache
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Michael Scheurich

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.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# A Website logger for Kirby3

![Release](https://flat.badgen.net/packagist/v/michnhokn/kirby3-logger?color=92a9c4)
![Last Commit](https://flat.badgen.net/github/last-commit/michnhokn/kirby3-logger?color=92c496)

## Commercial Usage

This plugin is free but if you use it in a commercial project please consider to

- [buy me a 🍺](https://buymeacoff.ee/michnhokn)

## Installation

- unzip [main.zip](https://github.com/michnhokn/kirby3-logger/archive/main.zip) as
folder `site/plugins/kirby3-logger` or
- `git submodule add https://github.com/michnhokn/kirby3-logger.git site/plugins/kirby3-logger` or
- `composer require michnhokn/kirby3-logger`

## Features


## Setup


## Misc

**License**: `MIT`

**Credits**: [MichnHokn](https://github.com/michnhokn)
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "michnhokn/kirby3-logger",
"description": "Add a logger to your Kirby3 website",
"type": "kirby-plugin",
"version": "0.9.0",
"license": "MIT",
"authors": [
{
"name": "Michael Scheurich",
"email": "[email protected]"
}
],
"keywords": [
"kirby3",
"kirby3-cms",
"kirby3-plugin",
"logger",
"website-log",
"user-log"
],
"config": {
"optimize-autoloader": true
},
"require": {
"getkirby/composer-installer": "^1.1"
}
}
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
panel.plugin('michnhokn/logger', {
components: {
'k-logger-view': {
props: {logs: Array},
template: `
<k-inside>
<k-view class="k-logger-view">
<k-header>Logger</k-header>
<pre>{{logs}}</pre>
</k-view>
</k-inside>`,
},
},
});
65 changes: 65 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

\Kirby\Cms\App::plugin('michnhokn/logger', [
'hooks' => [
'*:before' => function (\Kirby\Cms\Event $event) {
$type = $event->type();
$action = $event->action();
}
],
'routes' => [
[
'pattern' => 'db',
'action' => function () {
$logDir = kirby()->root('logs') . '/kirby3-logger/';
\Kirby\Filesystem\Dir::make($logDir, true);
$database = new \Kirby\Database\Database([
'type' => 'sqlite',
'database' => $logDir . 'logs.sqlite'
]);
$schema = \Kirby\Filesystem\F::read(__DIR__ . '/logs-schema.sql');
$database->execute($schema);
dump(
$database->table('logs')->insert([
'type' => 'test',
'action' => 'action',
'userId' => 'userId',
'oldValue' => 'oldValue',
'currentValue' => 'currentValue',
])
);
die;
}
],
],
'areas' => [
'kirby3-logger' => function ($kirby) {
$logDir = kirby()->root('logs') . '/kirby3-logger/';
$database = new \Kirby\Database\Database([
'type' => 'sqlite',
'database' => $logDir . 'logs.sqlite'
]);

return [
'label' => 'Logger',
'icon' => 'table',
'menu' => true,
'link' => 'logger',
'views' => [
[
'pattern' => 'logger',
'action' => function () use ($database) {
return [
'component' => 'k-logger-view',
'title' => 'Logs',
'props' => [
'logs' => $database->table('logs')->all()
]
];
}
]
]
];
}
]
]);
14 changes: 14 additions & 0 deletions logs-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE TABLE IF NOT EXISTS logs
(
id INTEGER PRIMARY KEY,
type TEXT NOT NULL,
action TEXT NOT NULL,
userId TEXT NULL,
oldValue TEXT NULL,
currentValue TEXT NOT NULL,
timestamp TEXT NOT NULL DEFAULT current_timestamp
);

CREATE INDEX index_users ON logs (userId);
CREATE INDEX index_actions ON logs (action);
CREATE INDEX index_types ON logs (type);

0 comments on commit 1c88ca1

Please sign in to comment.