mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
+ add CustomCSS extension
This commit is contained in:
parent
27bdebfde4
commit
01e688b49e
6 changed files with 110 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,5 +3,6 @@ src/db/config.php
|
||||||
src/db/config-*
|
src/db/config-*
|
||||||
src/config.php
|
src/config.php
|
||||||
src/includes/vendor/
|
src/includes/vendor/
|
||||||
|
src/content/theme/custom.css
|
||||||
|
|
||||||
tests/
|
tests/
|
||||||
|
|
|
||||||
1
src/ext/CustomCSS/.htaccess
Normal file
1
src/ext/CustomCSS/.htaccess
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
deny from all
|
||||||
6
src/ext/CustomCSS/extension.json
Normal file
6
src/ext/CustomCSS/extension.json
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"bundleId": "CustomCSS",
|
||||||
|
"name": "Custom CSS",
|
||||||
|
"version": "1.0",
|
||||||
|
"description": "Add you own css rules"
|
||||||
|
}
|
||||||
7
src/ext/CustomCSS/lang/en.json
Normal file
7
src/ext/CustomCSS/lang/en.json
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"ext.CustomCSS.name": "Custom CSS",
|
||||||
|
"customcss.h_css": "CSS",
|
||||||
|
"customcss.d_css": "Write you own CSS rules",
|
||||||
|
"customcss.not_writable": "CSS file is not writable, check permissions for custom.css",
|
||||||
|
"customcss.saved": "Saved"
|
||||||
|
}
|
||||||
7
src/ext/CustomCSS/lang/ru.json
Normal file
7
src/ext/CustomCSS/lang/ru.json
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"ext.CustomCSS.name": "Дополнительные стили",
|
||||||
|
"customcss.h_css": "CSS",
|
||||||
|
"customcss.d_css": "Добавляйте собственные стили CSS",
|
||||||
|
"customcss.not_writable": "Ошибка записи в файл, проверьте права доступа к custom.css",
|
||||||
|
"customcss.saved": "Сохранено"
|
||||||
|
}
|
||||||
88
src/ext/CustomCSS/loader.php
Normal file
88
src/ext/CustomCSS/loader.php
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is a part of myTinyTodo.
|
||||||
|
(C) Copyright 2022 Max Pozdeev <maxpozdeev@gmail.com>
|
||||||
|
Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('MTTPATH')) {
|
||||||
|
die("Unexpected usage.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function mtt_ext_customcss_instance(): MTTExtension
|
||||||
|
{
|
||||||
|
return new CustomCssExtension();
|
||||||
|
}
|
||||||
|
|
||||||
|
class CustomCssExtension extends MTTExtension implements MTTExtensionSettingsInterface
|
||||||
|
{
|
||||||
|
//the same as dir name
|
||||||
|
const bundleId = 'CustomCSS';
|
||||||
|
|
||||||
|
// settings domain
|
||||||
|
const domain = "ext.customcss.json";
|
||||||
|
|
||||||
|
const cssFilename = 'custom.css';
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
$prefs = self::preferences();
|
||||||
|
if (isset($prefs['css'])) {
|
||||||
|
$href = htmlspecialchars( get_unsafe_mttinfo('theme_url'). self::cssFilename. '?v='. ($prefs['edited'] ?? 0) );
|
||||||
|
$cb = function() use ($href) {
|
||||||
|
print "<link rel='stylesheet' type='text/css' href='$href'>\n";
|
||||||
|
};
|
||||||
|
add_action('theme_head_end', $cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function settingsPage(): string
|
||||||
|
{
|
||||||
|
$e = function($s) { return __($s, true); };
|
||||||
|
$prefs = self::preferences();
|
||||||
|
$css = htmlspecialchars($prefs['css'] ?? '');
|
||||||
|
|
||||||
|
return
|
||||||
|
<<<EOD
|
||||||
|
<div class="tr">
|
||||||
|
<div class="th"> {$e('customcss.h_css')}
|
||||||
|
<div class="descr">{$e('customcss.d_css')}</div>
|
||||||
|
</div>
|
||||||
|
<div class="td"> <textarea name="css" class="inmax monospace">$css</textarea> </div>
|
||||||
|
</div>
|
||||||
|
EOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveSettings(array $params, ?string &$outMessage): bool
|
||||||
|
{
|
||||||
|
if (defined('MTT_DEMO')) {
|
||||||
|
$outMessage = "Demo";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$css = $params['css'] ?? '';
|
||||||
|
|
||||||
|
$cssFilename = MTT_THEME_PATH. self::cssFilename;
|
||||||
|
if (!file_exists($cssFilename)) {
|
||||||
|
@touch($cssFilename);
|
||||||
|
}
|
||||||
|
if (!is_writable($cssFilename)) {
|
||||||
|
$outMessage = __('customcss.not_writable');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@file_put_contents($cssFilename, $css);
|
||||||
|
$outMessage = __('customcss.saved');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function preferences(): array
|
||||||
|
{
|
||||||
|
$prefs['cssFilename'] = $cssFilename = MTT_THEME_PATH. self::cssFilename;
|
||||||
|
if (file_exists($prefs['cssFilename'])) {
|
||||||
|
$prefs['edited'] = filemtime($cssFilename) ?? 0;
|
||||||
|
$prefs['css'] = @file_get_contents($cssFilename) ?? '';
|
||||||
|
}
|
||||||
|
return $prefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue