release 0.9
This commit is contained in:
parent
e775ddecca
commit
1af221b25f
9 changed files with 67 additions and 96 deletions
|
@ -1,6 +1,11 @@
|
|||
dev
|
||||
- [ ] 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
|
||||
- require Dotclear 2.26
|
||||
- require PHP 8.1+
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[![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)
|
||||
[![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)
|
||||
[![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:
|
||||
|
||||
* superadmin permissions
|
||||
* Dotclear 2.26
|
||||
* Dotclear 2.27
|
||||
* PHP 8.1+
|
||||
|
||||
## USAGE
|
||||
|
|
|
@ -18,11 +18,11 @@ $this->registerModule(
|
|||
'Tweak stores',
|
||||
'Helper to manage external repositories',
|
||||
'Jean-Christian Denis and Contributors',
|
||||
'0.8',
|
||||
'0.9',
|
||||
[
|
||||
'requires' => [
|
||||
['php', '8.1'],
|
||||
['core', '2.26'],
|
||||
['core', '2.27'],
|
||||
],
|
||||
'permissions' => null,
|
||||
'type' => 'plugin',
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="tweakStores">
|
||||
<name>Tweak stores</name>
|
||||
<version>0.8</version>
|
||||
<version>0.9</version>
|
||||
<author>Jean-Christian Denis and Contributors</author>
|
||||
<desc>Helper to manage external repositories</desc>
|
||||
<file>https://github.com/JcDenis/tweakStores/releases/download/v0.8/plugin-tweakStores.zip</file>
|
||||
<da:dcmin>2.26</da:dcmin>
|
||||
<file>https://github.com/JcDenis/tweakStores/releases/download/v0.9/plugin-tweakStores.zip</file>
|
||||
<da:dcmin>2.27</da:dcmin>
|
||||
<da:details>https://plugins.dotaddict.org/dc2/details/tweakStores</da:details>
|
||||
<da:support>https://github.com/JcDenis/tweakStores</da:support>
|
||||
</module>
|
||||
|
|
|
@ -15,22 +15,18 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\tweakStores;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
|
||||
class Backend extends dcNsProcess
|
||||
class Backend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& !is_null(dcCore::app()->auth)
|
||||
&& dcCore::app()->auth->isSuperAdmin();
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::BACKEND));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,10 @@ namespace Dotclear\Plugin\tweakStores;
|
|||
use dcCore;
|
||||
use dcModuleDefine;
|
||||
use dcModules;
|
||||
use dcPage;
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
};
|
||||
use Dotclear\Helper\File\Files;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Checkbox,
|
||||
|
@ -48,9 +51,21 @@ class BackendBehaviors
|
|||
/** @var array List of failed messages */
|
||||
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
|
||||
{
|
||||
if (is_null(dcCore::app()->blog) || !dcCore::app()->blog->settings->get(My::id())->get('packman')) {
|
||||
if (self::settings()->packman) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -58,64 +73,54 @@ class BackendBehaviors
|
|||
$modules = $module['type'] == 'theme' ? dcCore::app()->themes : dcCore::app()->plugins;
|
||||
$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
|
||||
{
|
||||
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
//save settings (before page header sent)
|
||||
if (!empty($_POST['tweakstore_save'])) {
|
||||
try {
|
||||
$s = new Settings();
|
||||
foreach ($s->dump() as $key => $value) {
|
||||
$s->set($key, $_POST['ts_' . $key] ?? $value);
|
||||
foreach (self::settings()->dump() as $key => $value) {
|
||||
self::settings()->set($key, $_POST['ts_' . $key] ?? $value);
|
||||
}
|
||||
|
||||
dcPage::addSuccessNotice(
|
||||
Notices::addSuccessNotice(
|
||||
__('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) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
dcPage::jsJson('tweakstore_copied', ['alert' => __('Copied to clipboard')]) .
|
||||
dcPage::jsModuleLoad(My::id() . '/js/backend.js') .
|
||||
Page::jsJson('tweakstore_copied', ['alert' => __('Copied to clipboard')]) .
|
||||
My::jsLoad('backend') .
|
||||
(
|
||||
!dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ? '' :
|
||||
dcPage::jsLoadCodeMirror(dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme')) .
|
||||
dcPage::jsModuleLoad(My::id() . '/js/cms.js')
|
||||
Page::jsLoadCodeMirror(dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme')) .
|
||||
My::jsLoad('cms')
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
if (is_null(dcCore::app()->adminurl) || is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// settings
|
||||
$s = new Settings();
|
||||
$page_url .= '#' . My::id();
|
||||
$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');
|
||||
$file_pattern = $s->file_pattern;
|
||||
$file_pattern = self::settings()->file_pattern;
|
||||
$local_content = $distant_content = '';
|
||||
|
||||
// load module
|
||||
|
@ -153,14 +158,14 @@ class BackendBehaviors
|
|||
}
|
||||
|
||||
// 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
|
||||
if (!empty($_POST['tweakstore_write'])) {
|
||||
if (empty($_POST['your_pwd']) || !dcCore::app()->auth->checkPassword($_POST['your_pwd'])) {
|
||||
dcCore::app()->error->add(__('Password verification failed'));
|
||||
} else {
|
||||
self::writeXML($module, $s->file_pattern);
|
||||
self::writeXML($module, self::settings()->file_pattern);
|
||||
if (!empty(self::$failed)) {
|
||||
dcCore::app()->error->add(implode(' ', self::$failed));
|
||||
}
|
||||
|
@ -207,7 +212,7 @@ class BackendBehaviors
|
|||
'</pre>' .
|
||||
(
|
||||
!$user_ui_colorsyntax ? '' :
|
||||
dcPage::jsRunCodeMirror('editor', 'distant_content', 'dotclear', $user_ui_colorsyntax_theme)
|
||||
Page::jsRunCodeMirror('editor', 'distant_content', 'dotclear', $user_ui_colorsyntax_theme)
|
||||
)
|
||||
) .
|
||||
'</div>';
|
||||
|
@ -243,7 +248,7 @@ class BackendBehaviors
|
|||
'</pre>' .
|
||||
(
|
||||
!$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')
|
||||
|
@ -275,20 +280,20 @@ class BackendBehaviors
|
|||
// settings
|
||||
'<form method="post" action="' . $page_url . '" id="tweakstore_setting">' .
|
||||
'<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([
|
||||
// s_file_pattern
|
||||
(new Para())->items([
|
||||
(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(__('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'),
|
||||
// s_packman
|
||||
(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 Note())->text(__('If enabled, plugin pacKman will (re)generate on the fly dcstore.xml file at root directory of the module.'))->class('form-note'),
|
||||
|
|
28
src/My.php
28
src/My.php
|
@ -15,35 +15,15 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\tweakStores;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Module\MyPlugin;
|
||||
|
||||
/**
|
||||
* This module definitions.
|
||||
*/
|
||||
class My
|
||||
class My extends MyPlugin
|
||||
{
|
||||
/**
|
||||
* This module id.
|
||||
*/
|
||||
public static function id(): string
|
||||
public static function checkCustomContext(int $context): ?bool
|
||||
{
|
||||
return basename(dirname(__DIR__));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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__);
|
||||
return $context === My::BACKEND ? dcCore::app()->auth->isSuperAdmin() : null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\tweakStores;
|
||||
|
||||
use dcCore;
|
||||
use Exception;
|
||||
|
||||
class Settings
|
||||
{
|
||||
// Enable plugin pacKman behavior
|
||||
|
@ -30,14 +27,8 @@ class Settings
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
throw new Exception('blog is not set');
|
||||
}
|
||||
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
|
||||
$this->packman = (bool) ($s->get('packman') ?? false);
|
||||
$this->file_pattern = (string) ($s->get('file_pattern') ?? '');
|
||||
$this->packman = (bool) (My::settings()->get('packman') ?? false);
|
||||
$this->file_pattern = (string) (My::settings()->get('file_pattern') ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,13 +41,9 @@ class Settings
|
|||
*/
|
||||
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) {
|
||||
dcCore::app()->blog->settings->get(My::id())->drop($key);
|
||||
dcCore::app()->blog->settings->get(My::id())->put($key, $value, gettype($this->{$key}), '', true, true);
|
||||
My::settings()->drop($key);
|
||||
My::settings()->put($key, $value, gettype($this->{$key}), '', true, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -15,21 +15,19 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\tweakStores;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Plugin\Uninstaller\Uninstaller;
|
||||
|
||||
class Uninstall extends dcNsProcess
|
||||
class Uninstall extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN');
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::UNINSTALL));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
||||
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue