2021-11-05 21:52:46 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @brief improve, a plugin for Dotclear 2
|
|
|
|
*
|
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis and contributors
|
|
|
|
*
|
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2021-11-13 21:57:51 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace plugins\improve;
|
|
|
|
|
2021-11-05 21:52:46 +00:00
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
2021-11-13 21:57:51 +00:00
|
|
|
return;
|
2021-11-05 21:52:46 +00:00
|
|
|
}
|
|
|
|
|
2021-11-13 21:57:51 +00:00
|
|
|
/* dotclear */
|
|
|
|
use dcCore;
|
|
|
|
use dcUtils;
|
|
|
|
|
|
|
|
/* php */
|
|
|
|
use Exception;
|
2021-11-05 21:52:46 +00:00
|
|
|
|
2021-11-13 21:57:51 +00:00
|
|
|
/**
|
|
|
|
* Improve install class
|
|
|
|
*
|
|
|
|
* Set default settings and version
|
|
|
|
* and manage changes on updates.
|
|
|
|
*/
|
|
|
|
class install
|
|
|
|
{
|
|
|
|
/** @var array Improve default settings */
|
|
|
|
private static $default_settings = [[
|
2021-11-05 21:52:46 +00:00
|
|
|
'disabled',
|
|
|
|
'List of hidden action modules',
|
|
|
|
'tab;newline;endoffile',
|
2021-11-13 21:57:51 +00:00
|
|
|
'string',
|
|
|
|
]];
|
2021-11-05 21:52:46 +00:00
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
public static function process(): ?bool
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
2022-11-12 21:58:44 +00:00
|
|
|
if (!self::checkModuleVersion()) {
|
2021-11-13 21:57:51 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-11-12 21:58:44 +00:00
|
|
|
if (!self::checkDotclearVersion()) {
|
2021-11-13 21:57:51 +00:00
|
|
|
throw new Exception(sprintf(
|
|
|
|
'%s requires Dotclear %s',
|
|
|
|
'improve',
|
2022-12-01 09:53:13 +00:00
|
|
|
self::getDotclearVersion()
|
2021-11-13 21:57:51 +00:00
|
|
|
));
|
|
|
|
}
|
2021-11-05 21:52:46 +00:00
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
dcCore::app()->blog->settings->addNamespace('improve');
|
|
|
|
self::update_0_8_0();
|
|
|
|
self::putSettings();
|
|
|
|
self::setVersion();
|
2021-11-05 21:52:46 +00:00
|
|
|
|
2021-11-13 21:57:51 +00:00
|
|
|
return true;
|
2021-11-05 21:52:46 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 09:53:13 +00:00
|
|
|
private static function getDotclearVersion(): string
|
|
|
|
{
|
|
|
|
return dcCore::app()->plugins->moduleInfo('improve', 'requires')[0][1];
|
|
|
|
}
|
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
private static function getInstalledVersion(): string
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
2022-11-12 21:58:44 +00:00
|
|
|
$version = dcCore::app()->getVersion('improve');
|
2021-11-13 21:57:51 +00:00
|
|
|
|
|
|
|
return is_string($version) ? $version : '0';
|
2021-11-05 21:52:46 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
private static function checkModuleVersion(): bool
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
|
|
|
return version_compare(
|
2022-11-12 21:58:44 +00:00
|
|
|
self::getInstalledVersion(),
|
|
|
|
dcCore::app()->plugins->moduleInfo('improve', 'version'),
|
2021-11-13 21:57:51 +00:00
|
|
|
'<'
|
2021-11-05 21:52:46 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
private static function checkDotclearVersion(): bool
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
|
|
|
return method_exists('dcUtils', 'versionsCompare')
|
2022-12-01 09:53:13 +00:00
|
|
|
&& dcUtils::versionsCompare(DC_VERSION, self::getDotclearVersion(), '>=', false);
|
2021-11-13 21:57:51 +00:00
|
|
|
}
|
2021-11-05 21:52:46 +00:00
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
private static function putSettings(): void
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
|
|
|
foreach (self::$default_settings as $v) {
|
2022-11-12 21:58:44 +00:00
|
|
|
dcCore::app()->blog->settings->improve->put(
|
2021-11-13 21:57:51 +00:00
|
|
|
$v[0],
|
|
|
|
$v[2],
|
|
|
|
$v[3],
|
|
|
|
$v[1],
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
private static function setVersion(): void
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
2022-11-12 21:58:44 +00:00
|
|
|
dcCore::app()->setVersion('improve', dcCore::app()->plugins->moduleInfo('improve', 'version'));
|
2021-11-13 21:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Update improve < 0.8 : action modules settings name */
|
2022-11-12 21:58:44 +00:00
|
|
|
private static function update_0_8_0(): void
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
2022-11-12 21:58:44 +00:00
|
|
|
if (version_compare(self::getInstalledVersion(), '0.8', '<')) {
|
|
|
|
foreach (dcCore::app()->blog->settings->improve->dumpGlobalSettings() as $id => $values) {
|
2021-11-13 21:57:51 +00:00
|
|
|
$newId = str_replace('ImproveAction', '', $id);
|
|
|
|
if ($id != $newId) {
|
2022-11-12 21:58:44 +00:00
|
|
|
dcCore::app()->blog->settings->improve->rename($id, strtolower($newId));
|
2021-11-13 21:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process */
|
|
|
|
try {
|
2022-11-12 21:58:44 +00:00
|
|
|
return install::process();
|
2021-11-05 21:52:46 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$core->error->add($e->getMessage());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|