release 0.9

master
Jean-Christian Paul Denis 2023-07-30 14:53:45 +02:00
parent e775ddecca
commit 1af221b25f
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
9 changed files with 67 additions and 96 deletions

View File

@ -1,6 +1,11 @@
dev dev
- [ ] add update from external repositories - [ ] add update from external repositories
0.9 - 2023.07.30
- require Dotclear 2.27
- require PHP 8.1+
- update to Dotclear 2.27-dev
0.8 - 2023.04.29 0.8 - 2023.04.29
- require Dotclear 2.26 - require Dotclear 2.26
- require PHP 8.1+ - require PHP 8.1+

View File

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/tweakStores)](https://github.com/JcDenis/tweakStores/releases) [![Release](https://img.shields.io/github/v/release/JcDenis/tweakStores)](https://github.com/JcDenis/tweakStores/releases)
[![Date](https://img.shields.io/github/release-date/JcDenis/tweakStores)](https://github.com/JcDenis/tweakStores/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/tweakStores)](https://github.com/JcDenis/tweakStores/releases)
[![Issues](https://img.shields.io/github/issues/JcDenis/tweakStores)](https://github.com/JcDenis/tweakStores/issues) [![Issues](https://img.shields.io/github/issues/JcDenis/tweakStores)](https://github.com/JcDenis/tweakStores/issues)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download) [![Dotclear](https://img.shields.io/badge/dotclear-v2.27-blue.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/tweakStores) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/tweakStores)
[![License](https://img.shields.io/github/license/JcDenis/tweakStores)](https://github.com/JcDenis/tweakStores/blob/master/LICENSE) [![License](https://img.shields.io/github/license/JcDenis/tweakStores)](https://github.com/JcDenis/tweakStores/blob/master/LICENSE)
@ -19,7 +19,7 @@ It helps devs to manage dcstore.xml file.
_tweakStores_ requires: _tweakStores_ requires:
* superadmin permissions * superadmin permissions
* Dotclear 2.26 * Dotclear 2.27
* PHP 8.1+ * PHP 8.1+
## USAGE ## USAGE

View File

@ -18,11 +18,11 @@ $this->registerModule(
'Tweak stores', 'Tweak stores',
'Helper to manage external repositories', 'Helper to manage external repositories',
'Jean-Christian Denis and Contributors', 'Jean-Christian Denis and Contributors',
'0.8', '0.9',
[ [
'requires' => [ 'requires' => [
['php', '8.1'], ['php', '8.1'],
['core', '2.26'], ['core', '2.27'],
], ],
'permissions' => null, 'permissions' => null,
'type' => 'plugin', 'type' => 'plugin',

View File

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="tweakStores"> <module id="tweakStores">
<name>Tweak stores</name> <name>Tweak stores</name>
<version>0.8</version> <version>0.9</version>
<author>Jean-Christian Denis and Contributors</author> <author>Jean-Christian Denis and Contributors</author>
<desc>Helper to manage external repositories</desc> <desc>Helper to manage external repositories</desc>
<file>https://github.com/JcDenis/tweakStores/releases/download/v0.8/plugin-tweakStores.zip</file> <file>https://github.com/JcDenis/tweakStores/releases/download/v0.9/plugin-tweakStores.zip</file>
<da:dcmin>2.26</da:dcmin> <da:dcmin>2.27</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/tweakStores</da:details> <da:details>https://plugins.dotaddict.org/dc2/details/tweakStores</da:details>
<da:support>https://github.com/JcDenis/tweakStores</da:support> <da:support>https://github.com/JcDenis/tweakStores</da:support>
</module> </module>

View File

@ -15,22 +15,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\tweakStores; namespace Dotclear\Plugin\tweakStores;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
class Backend extends dcNsProcess class Backend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::BACKEND));
&& !is_null(dcCore::app()->auth)
&& dcCore::app()->auth->isSuperAdmin();
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }

View File

@ -17,7 +17,10 @@ namespace Dotclear\Plugin\tweakStores;
use dcCore; use dcCore;
use dcModuleDefine; use dcModuleDefine;
use dcModules; use dcModules;
use dcPage; use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Helper\File\Files; use Dotclear\Helper\File\Files;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
@ -48,9 +51,21 @@ class BackendBehaviors
/** @var array List of failed messages */ /** @var array List of failed messages */
private static $failed = []; private static $failed = [];
/** @var Settings Module settings */
private static $settings;
private static function settings(): Settings
{
if (!(self::$settings instanceof Settings)) {
self::$settings = new Settings();
}
return self::$settings;
}
public static function packmanBeforeCreatePackage(array $module): void public static function packmanBeforeCreatePackage(array $module): void
{ {
if (is_null(dcCore::app()->blog) || !dcCore::app()->blog->settings->get(My::id())->get('packman')) { if (self::settings()->packman) {
return; return;
} }
@ -58,64 +73,54 @@ class BackendBehaviors
$modules = $module['type'] == 'theme' ? dcCore::app()->themes : dcCore::app()->plugins; $modules = $module['type'] == 'theme' ? dcCore::app()->themes : dcCore::app()->plugins;
$define = $modules->getDefine($module['id']); $define = $modules->getDefine($module['id']);
self::writeXML($define, dcCore::app()->blog->settings->get(My::id())->get('file_pattern')); self::writeXML($define, self::settings()->file_pattern);
} }
public static function modulesToolsHeaders(bool $is_theme): string public static function modulesToolsHeaders(bool $is_theme): string
{ {
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) {
return '';
}
//save settings (before page header sent) //save settings (before page header sent)
if (!empty($_POST['tweakstore_save'])) { if (!empty($_POST['tweakstore_save'])) {
try { try {
$s = new Settings(); foreach (self::settings()->dump() as $key => $value) {
foreach ($s->dump() as $key => $value) { self::settings()->set($key, $_POST['ts_' . $key] ?? $value);
$s->set($key, $_POST['ts_' . $key] ?? $value);
} }
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Configuration successfully updated') __('Configuration successfully updated')
); );
dcCore::app()->adminurl?->redirect($is_theme ? 'admin.blog.theme' : 'admin.plugins', ['tab' => My::id()]); dcCore::app()->admin->url->redirect($is_theme ? 'admin.blog.theme' : 'admin.plugins', ['tab' => My::id()]);
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
return return
dcPage::jsJson('tweakstore_copied', ['alert' => __('Copied to clipboard')]) . Page::jsJson('tweakstore_copied', ['alert' => __('Copied to clipboard')]) .
dcPage::jsModuleLoad(My::id() . '/js/backend.js') . My::jsLoad('backend') .
( (
!dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ? '' : !dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ? '' :
dcPage::jsLoadCodeMirror(dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme')) . Page::jsLoadCodeMirror(dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme')) .
dcPage::jsModuleLoad(My::id() . '/js/cms.js') My::jsLoad('cms')
); );
} }
public static function pluginsToolsTabsV2(): void public static function pluginsToolsTabsV2(): void
{ {
self::modulesToolsTabs(dcCore::app()->plugins, (string) dcCore::app()->adminurl?->get('admin.plugins')); self::modulesToolsTabs(dcCore::app()->plugins, (string) dcCore::app()->admin->url->get('admin.plugins'));
} }
public static function themesToolsTabsV2(): void public static function themesToolsTabsV2(): void
{ {
self::modulesToolsTabs(dcCore::app()->themes, (string) dcCore::app()->adminurl?->get('admin.blog.theme')); self::modulesToolsTabs(dcCore::app()->themes, (string) dcCore::app()->admin->url->get('admin.blog.theme'));
} }
private static function modulesToolsTabs(dcModules $modules, string $page_url): void private static function modulesToolsTabs(dcModules $modules, string $page_url): void
{ {
if (is_null(dcCore::app()->adminurl) || is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) {
return;
}
// settings // settings
$s = new Settings();
$page_url .= '#' . My::id(); $page_url .= '#' . My::id();
$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax'); $user_ui_colorsyntax = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax');
$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'); $user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme');
$file_pattern = $s->file_pattern; $file_pattern = self::settings()->file_pattern;
$local_content = $distant_content = ''; $local_content = $distant_content = '';
// load module // load module
@ -153,14 +158,14 @@ class BackendBehaviors
} }
// generate local module xml content // generate local module xml content
$local_content = self::generateXML($module, $s->file_pattern); $local_content = self::generateXML($module, self::settings()->file_pattern);
// write dcstore.xml file // write dcstore.xml file
if (!empty($_POST['tweakstore_write'])) { if (!empty($_POST['tweakstore_write'])) {
if (empty($_POST['your_pwd']) || !dcCore::app()->auth->checkPassword($_POST['your_pwd'])) { if (empty($_POST['your_pwd']) || !dcCore::app()->auth->checkPassword($_POST['your_pwd'])) {
dcCore::app()->error->add(__('Password verification failed')); dcCore::app()->error->add(__('Password verification failed'));
} else { } else {
self::writeXML($module, $s->file_pattern); self::writeXML($module, self::settings()->file_pattern);
if (!empty(self::$failed)) { if (!empty(self::$failed)) {
dcCore::app()->error->add(implode(' ', self::$failed)); dcCore::app()->error->add(implode(' ', self::$failed));
} }
@ -207,7 +212,7 @@ class BackendBehaviors
'</pre>' . '</pre>' .
( (
!$user_ui_colorsyntax ? '' : !$user_ui_colorsyntax ? '' :
dcPage::jsRunCodeMirror('editor', 'distant_content', 'dotclear', $user_ui_colorsyntax_theme) Page::jsRunCodeMirror('editor', 'distant_content', 'dotclear', $user_ui_colorsyntax_theme)
) )
) . ) .
'</div>'; '</div>';
@ -243,7 +248,7 @@ class BackendBehaviors
'</pre>' . '</pre>' .
( (
!$user_ui_colorsyntax ? '' : !$user_ui_colorsyntax ? '' :
dcPage::jsRunCodeMirror('editor', 'local_content', 'dotclear', $user_ui_colorsyntax_theme) Page::jsRunCodeMirror('editor', 'local_content', 'dotclear', $user_ui_colorsyntax_theme)
); );
if ($module->get('root_writable') if ($module->get('root_writable')
@ -275,20 +280,20 @@ class BackendBehaviors
// settings // settings
'<form method="post" action="' . $page_url . '" id="tweakstore_setting">' . '<form method="post" action="' . $page_url . '" id="tweakstore_setting">' .
'<div class="fieldset"><h4>' . sprintf(__('%s configuration'), My::name()) . '</h4>' . '<div class="fieldset"><h4>' . sprintf(__('%s configuration'), My::name()) . '</h4>' .
(empty($s->file_pattern) ? '<p class="warning">' . __('You must configure zip file pattern to complete xml code automatically.') . '</p>' : '') . (empty(self::settings()->file_pattern) ? '<p class="warning">' . __('You must configure zip file pattern to complete xml code automatically.') . '</p>' : '') .
(new Div())->items([ (new Div())->items([
// s_file_pattern // s_file_pattern
(new Para())->items([ (new Para())->items([
(new Label(__('Predictable URL to zip file on the external repository')))->for('ts_file_pattern'), (new Label(__('Predictable URL to zip file on the external repository')))->for('ts_file_pattern'),
(new Input('ts_file_pattern'))->size(65)->maxlenght(255)->class('maximal')->value($s->file_pattern), (new Input('ts_file_pattern'))->size(65)->maxlenght(255)->class('maximal')->value(self::settings()->file_pattern),
]), ]),
(new Note())->text(__('You can use widcard like %author%, %type%, %id%, %version%.'))->class('form-note'), (new Note())->text(__('You can use widcard like %author%, %type%, %id%, %version%.'))->class('form-note'),
(new Note())->text(__('For example on github https://github.com/MyGitName/%id%/releases/download/v%version%/%type%-%id%.zip'))->class('form-note'), (new Note())->text(__('For example on github https://github.com/MyGitName/%id%/releases/download/v%version%/%type%-%id%.zip'))->class('form-note'),
(new Note())->text(__('Note: on github, you must create a release and join to it the module zip file.'))->class('form-note'), (new Note())->text(__('Note: on github, you must create a release and join to it the module zip file.'))->class('form-note'),
// s_packman // s_packman
(new Para())->items([ (new Para())->items([
(new Checkbox('ts_packman', $s->packman))->value(1), (new Checkbox('ts_packman', self::settings()->packman))->value(1),
(new Label(__('Enable packman behaviors'), Label::OUTSIDE_LABEL_AFTER))->for('ts_packman')->class('classic'), (new Label(__('Enable packman behaviors'), Label::OUTSIDE_LABEL_AFTER))->for('ts_packman')->class('classic'),
]), ]),
(new Note())->text(__('If enabled, plugin pacKman will (re)generate on the fly dcstore.xml file at root directory of the module.'))->class('form-note'), (new Note())->text(__('If enabled, plugin pacKman will (re)generate on the fly dcstore.xml file at root directory of the module.'))->class('form-note'),

View File

@ -15,35 +15,15 @@ declare(strict_types=1);
namespace Dotclear\Plugin\tweakStores; namespace Dotclear\Plugin\tweakStores;
use dcCore; use dcCore;
use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * This module definitions.
*/ */
class My class My extends MyPlugin
{ {
/** public static function checkCustomContext(int $context): ?bool
* This module id.
*/
public static function id(): string
{ {
return basename(dirname(__DIR__)); return $context === My::BACKEND ? dcCore::app()->auth->isSuperAdmin() : null;
}
/**
* This module name.
*/
public static function name(): string
{
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
return __(is_string($name) ? $name : self::id());
}
/**
* This module path.
*/
public static function path(): string
{
return dirname(__DIR__);
} }
} }

View File

@ -14,9 +14,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\tweakStores; namespace Dotclear\Plugin\tweakStores;
use dcCore;
use Exception;
class Settings class Settings
{ {
// Enable plugin pacKman behavior // Enable plugin pacKman behavior
@ -30,14 +27,8 @@ class Settings
*/ */
public function __construct() public function __construct()
{ {
if (is_null(dcCore::app()->blog)) { $this->packman = (bool) (My::settings()->get('packman') ?? false);
throw new Exception('blog is not set'); $this->file_pattern = (string) (My::settings()->get('file_pattern') ?? '');
}
$s = dcCore::app()->blog->settings->get(My::id());
$this->packman = (bool) ($s->get('packman') ?? false);
$this->file_pattern = (string) ($s->get('file_pattern') ?? '');
} }
/** /**
@ -50,13 +41,9 @@ class Settings
*/ */
public function set(string $key, mixed $value): bool public function set(string $key, mixed $value): bool
{ {
if (is_null(dcCore::app()->blog)) {
throw new Exception('blog is not set');
}
if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) { if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) {
dcCore::app()->blog->settings->get(My::id())->drop($key); My::settings()->drop($key);
dcCore::app()->blog->settings->get(My::id())->put($key, $value, gettype($this->{$key}), '', true, true); My::settings()->put($key, $value, gettype($this->{$key}), '', true, true);
return true; return true;
} }

View File

@ -15,21 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\tweakStores; namespace Dotclear\Plugin\tweakStores;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
class Uninstall extends dcNsProcess class Uninstall extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN'); return self::status(My::checkContext(My::UNINSTALL));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) { if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false; return false;
} }