release 0.3 - namespace

This commit is contained in:
Jean-Christian Paul Denis 2023-03-11 20:03:02 +01:00
parent 66fd478a06
commit 45499b0b75
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
13 changed files with 284 additions and 205 deletions

View File

@ -1,4 +1,6 @@
x.x
0.3 - 2023.03.11
- required Dotclear 2.25, up to 2.25.3
- use php namespace
- fix translation
0.2 - 2022.12.03
@ -6,5 +8,5 @@ x.x
- Add Dotclear maximum version compatibility (thanks @Gvx- )
0.1.1 - 2022.12.03
- Required Dotclear 2.19
- Required Dotclear 2.19, up to 2.23.1
- First release

View File

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/checkStoreVersion)](https://github.com/JcDenis/checkStoreVersion/releases)
[![Date](https://img.shields.io/github/release-date/JcDenis/checkStoreVersion)](https://github.com/JcDenis/checkStoreVersion/releases)
[![Issues](https://img.shields.io/github/issues/JcDenis/checkStoreVersion)](https://github.com/JcDenis/checkStoreVersion/issues)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.19-blue.svg)](https://fr.dotclear.org/download)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.25-blue.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/checkStoreVersion)
[![License](https://img.shields.io/github/license/JcDenis/checkStoreVersion)](https://github.com/JcDenis/checkStoreVersion/blob/master/LICENSE)
@ -20,7 +20,7 @@ This plugin check official or third-party repositories of installed plugins or t
_CheckStoreVersion_ requires:
* superadmin permissions
* Dotclear 2.19
* Dotclear 2.25
## USAGE

View File

@ -18,13 +18,13 @@ $this->registerModule(
'Check store version',
'Check plugins and themes available version before update',
'Jean-Christian Denis and Contributors',
'0.2',
'0.3',
[
'requires' => [['core', '2.19']],
'requires' => [['core', '2.25']],
'permissions' => null,
'type' => 'plugin',
'support' => 'https://github.com/JcDenis/checkStoreVersion',
'details' => 'https://plugins.dotaddict.org/dc2/details/checkStoreVersion',
'repository' => 'https://raw.githubusercontent.com/JcDenis/checkStoreVersion/master/dcstore.xml'
'repository' => 'https://raw.githubusercontent.com/JcDenis/checkStoreVersion/master/dcstore.xml',
]
);

View File

@ -1,19 +0,0 @@
<?php
/**
* @brief checkStoreVersion, 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
*/
if (!defined('DC_RC_PATH')) {
return null;
}
$__autoload['csvStore'] = dirname(__FILE__) . '/inc/class.csv.store.php';
$__autoload['csvStoreReader'] = dirname(__FILE__) . '/inc/class.csv.store.reader.php';
$__autoload['csvStoreParser'] = dirname(__FILE__) . '/inc/class.csv.store.parser.php';

View File

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="checkStoreVersion">
<name>Check store version</name>
<version>0.2</version>
<version>0.3</version>
<author>Jean-Christian Denis and Contributors</author>
<desc>Check plugins and themes available version before update</desc>
<file>https://github.com/JcDenis/checkStoreVersion/releases/download/v0.2/plugin-checkStoreVersion.zip</file>
<da:dcmin>2.19</da:dcmin>
<file>https://github.com/JcDenis/checkStoreVersion/releases/download/v0.3/plugin-checkStoreVersion.zip</file>
<da:dcmin>2.25</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/checkStoreVersion</da:details>
<da:support>https://github.com/JcDenis/checkStoreVersion</da:support>
</module>

23
locales/fr/main.lang.php Normal file
View File

@ -0,0 +1,23 @@
<?php
/**
* @package Dotclear
*
* @copyright Olivier Meunier & Association Dotclear
* @copyright GPL-2.0-only
*/
#
# DOT NOT MODIFY THIS FILE !
#
l10n::$locales['Store version'] = 'Version de dépôt';
l10n::$locales['Check stores versions'] = 'Vérifier les version sur les dépôts';
l10n::$locales['This version does not support Dotclear > %s'] = 'Cette version ne supporte pas Dotclear > %s';
l10n::$locales['There is no module to check'] = 'Il n\'y a pas de module à vérifier';
l10n::$locales['Check lastest stores versions'] = 'Vérifier les dernières versions sur les dépôts';
l10n::$locales['Modules list'] = 'Liste des modules';
l10n::$locales['Latest version'] = 'Dernière version';
l10n::$locales['Written for Dotclear'] = 'Ecrit pour Dotclear';
l10n::$locales['No version available'] = 'Aucune version disponible';
l10n::$locales['No update available'] = 'Aucune mise à jour disponible';
l10n::$locales['Newer version available'] = 'Une nouvelle version disponible';
l10n::$locales['No version available on stores'] = 'Aucune version disponible sur les dépôts';

View File

@ -3,7 +3,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: checkStoreVersion 0.2\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2022-12-03T19:31:22+00:00\n"
"PO-Revision-Date: 2023-03-11T18:50:59+00:00\n"
"Last-Translator: Jean-Christian Denis\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"

44
src/Backend.php Normal file
View File

@ -0,0 +1,44 @@
<?php
/**
* @brief checkStoreVersion, 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
*/
declare(strict_types=1);
namespace Dotclear\Plugin\checkStoreVersion;
use dcCore;
use dcNsProcess;
class Backend extends dcNsProcess
{
public static function init(): bool
{
if (defined('DC_CONTEXT_ADMIN')) {
self::$init = dcCore::app()->auth->isSuperAdmin();
}
return self::$init;
}
public static function process(): bool
{
if (!self::$init) {
return false;
}
dcCore::app()->addBehaviors([
'pluginsToolsTabsV2' => [BackendBehaviors::class, 'pluginTabs'],
'themesToolsTabsV2' => [BackendBehaviors::class, 'themesTabs'],
]);
return true;
}
}

View File

@ -10,46 +10,44 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
declare(strict_types=1);
# only superadmin
if (!$core->auth->isSuperAdmin()) {
return null;
}
namespace Dotclear\Plugin\checkStoreVersion;
# admin behaviors
$core->addBehavior('pluginsToolsTabs', ['csvBehaviors', 'pluginsToolsTabs']);
$core->addBehavior('themesToolsTabs', ['csvBehaviors', 'themesToolsTabs']);
use dcAdminHelper;
use dcCore;
use dcModules;
use dcPage;
use dcUtils;
use html;
class csvBehaviors
class BackendBehaviors
{
public const DC_MAX = '2.23.1';
# admin plugins page tab
public static function pluginsToolsTabs(dcCore $core): void
public static function pluginsToolsTabs(): void
{
self::modulesToolsTabs($core, $core->plugins, explode(',', DC_DISTRIB_PLUGINS), $core->adminurl->get('admin.plugins'));
self::modulesToolsTabs(dcCore::app()->plugins, explode(',', DC_DISTRIB_PLUGINS), dcCore::app()->adminurl->get('admin.plugins'));
}
# admin themes page tab
public static function themesToolsTabs(dcCore $core): void
public static function themesToolsTabs(): void
{
self::modulesToolsTabs($core, $core->themes, explode(',', DC_DISTRIB_THEMES), $core->adminurl->get('admin.blog.theme'));
self::modulesToolsTabs(dcCore::app()->themes, explode(',', DC_DISTRIB_THEMES), dcCore::app()->adminurl->get('admin.blog.theme'));
}
# generic page tab
private static function modulesToolsTabs(dcCore $core, dcModules $modules, array $excludes, string $page_url): void
private static function modulesToolsTabs(dcModules $modules, array $excludes, string $page_url): void
{
$repos = empty($_POST['csvcheck']) ? null :
(new CsvStore($modules, (string) dcCore::app()->blog->settings->get('system')->get('store_plugin_url'), true))->get(true);
echo
'<div class="multi-part" id="csv" title="' . __('Store version') . '">' .
'<h3>' . __('Check stores versions') . '</h3>';
if (!method_exists('dcUtils', 'versionsCompare')
|| dcUtils::versionsCompare(DC_VERSION, self::DC_MAX, '>', false)) {
if (dcUtils::versionsCompare(DC_VERSION, My::DC_MAX, '>', false)) {
echo
'<div class="error"><p>' . sprintf(__('This version does not support Dotclear > %s'), self::DC_MAX) . '</p></div>';
'<div class="error"><p>' . sprintf(__('This version does not support Dotclear > %s'), My::DC_MAX) . '</p></div>';
return;
}
@ -72,12 +70,11 @@ class csvBehaviors
echo
'<form method="post" action="' . $page_url . '#csv" id="csvform">' .
'<p><input type="submit" name="csvcheck" value="' . __('Check lastest stores versions') . '" />' .
$core->formNonce() . '</p>' .
dcCore::app()->formNonce() . '</p>' .
'</form>';
if (!empty($_POST['csvcheck'])) {
$store = new csvStore($modules, dcCore::app()->blog->settings->system->store_plugin_url, true);
self::modulesList($list, $store->get(true));
if ($repos !== null) {
self::modulesList($list, $repos);
}
echo
@ -86,7 +83,7 @@ class csvBehaviors
private static function modulesList($modules, $repos)
{
echo
echo
'<div class="table-outer">' .
'<table id="mvmodules" class="modules">' .
'<caption class="hidden">' . html::escapeHTML(__('Modules list')) . '</caption><tr>' .
@ -101,7 +98,6 @@ class csvBehaviors
}
foreach ($modules as $id => $module) {
if (!isset($repos[$id])) {
$img = [__('No version available'), 'check-off.png'];
} elseif (isset($repos[$id]) && dcUtils::versionsCompare(DC_VERSION, $repos[$id]['dc_min'], '>=', false)) {
@ -131,37 +127,37 @@ class csvBehaviors
echo
'<tr class="line' . (isset($repos[$id]) ? '' : ' offline') . '" id="mvmodules_m_' . html::escapeHTML($id) . '">' .
'<td class="module-icon nowrap">' .
'<td class="module-icon nowrap">' .
$img . '</td>' .
'<td class="module-icon nowrap">' .
'<td class="module-icon nowrap">' .
dcAdminHelper::adminIcon($icon, false, html::escapeHTML($id), html::escapeHTML($id)) . '</td>' .
'<th class="module-name nowrap" scope="row">' .
'<th class="module-name nowrap" scope="row">' .
html::escapeHTML($module['name']) . ($id != $module['name'] ? sprintf(__(' (%s)'), $id) : '') .
'</td>';
if (isset($repos[$id])) {
echo
'<td class="module-version nowrap count">' .
'<td class="module-version nowrap count">' .
html::escapeHTML($repos[$id]['current_version']) . '</td>' .
'<td class="module-version nowrap count maximal">' .
'<td class="module-version nowrap count maximal">' .
html::escapeHTML($repos[$id]['version']) . '</td>' .
'<td class="module-version nowrap count">' .
'<td class="module-version nowrap count">' .
html::escapeHTML($repos[$id]['dc_min']) . '</td>';
if (DC_ALLOW_REPOSITORIES) {
echo
'<td class="module-repository nowrap count">' .
'<td class="module-repository nowrap count">' .
(empty($module['repository']) ? __('Official repository') : __('Third-party repository')) . '</td>';
}
} else {
echo
'<td class="module-current-version nowrap count">' .
echo
'<td class="module-current-version nowrap count">' .
html::escapeHTML($module['version']) . '</td>' .
'<td class="module-version nowrap count maximal" colspan="' . (DC_ALLOW_REPOSITORIES ? '3' : '2') . '">' .
'<td class="module-version nowrap count maximal" colspan="' . (DC_ALLOW_REPOSITORIES ? '3' : '2') . '">' .
html::escapeHTML(__('No version available on stores')) . '</td>';
}
echo
echo
'</tr>';
}

View File

@ -10,73 +10,78 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
class csvStore extends dcStore
{
# overwrite dcStore::check to remove cache and use csvStoreReader and check disabled modules
public function check($force = true)
{
if (!$this->xml_url) {
return false;
}
try {
$parser = DC_STORE_NOT_UPDATE ? false : csvStoreReader::quickParse($this->xml_url, DC_TPL_CACHE, $force);
} catch (Exception $e) {
return false;
}
$raw_datas = !$parser ? [] : $parser->getModules();
uasort($raw_datas, fn ($a, $b) => strtolower($a['id']) <=> strtolower($b['id']));
$updates = [];
$current = array_merge($this->modules->getModules(), $this->modules->getDisabledModules());
foreach ($current as $p_id => $p_infos) {
# non privileged user has no info
if (!is_array($p_infos)) {
continue;
}
# main repository
if (isset($raw_datas[$p_id])) {
if (dcUtils::versionsCompare($raw_datas[$p_id]['version'], $p_infos['version'], '>=')) {
$updates[$p_id] = $raw_datas[$p_id];
$updates[$p_id]['root'] = $p_infos['root'];
$updates[$p_id]['root_writable'] = $p_infos['root_writable'];
$updates[$p_id]['current_version'] = $p_infos['version'];
}
unset($raw_datas[$p_id]);
}
# per module third-party repository
if (!empty($p_infos['repository']) && DC_ALLOW_REPOSITORIES) {
try {
$dcs_url = substr($p_infos['repository'], -12, 12) == '/dcstore.xml' ? $p_infos['repository'] : http::concatURL($p_infos['repository'], 'dcstore.xml');
$dcs_parser = csvStoreReader::quickParse($dcs_url, DC_TPL_CACHE, $force);
if ($dcs_parser !== false) {
$dcs_raw_datas = $dcs_parser->getModules();
if (isset($dcs_raw_datas[$p_id]) && dcUtils::versionsCompare($dcs_raw_datas[$p_id]['version'], $p_infos['version'], '>=')) {
if (!isset($updates[$p_id]) || dcUtils::versionsCompare($dcs_raw_datas[$p_id]['version'], $updates[$p_id]['version'], '>=')) {
$dcs_raw_datas[$p_id]['repository'] = true;
$updates[$p_id] = $dcs_raw_datas[$p_id];
$updates[$p_id]['root'] = $p_infos['root'];
$updates[$p_id]['root_writable'] = $p_infos['root_writable'];
$updates[$p_id]['current_version'] = $p_infos['version'];
}
}
}
} catch (Exception $e) {
}
}
}
$this->data = [
'new' => [],
'update' => $updates,
];
return true;
}
}
declare(strict_types=1);
namespace Dotclear\Plugin\checkStoreVersion;
use dcStore;
use dcUtils;
use Exception;
use http;
class CsvStore extends dcStore
{
# overwrite dcStore::check to remove cache and use csvStoreReader and check disabled modules
public function check(bool $force = true): bool
{
if (!$this->xml_url) {
return false;
}
try {
$parser = DC_STORE_NOT_UPDATE ? false : CsvStoreReader::quickParse($this->xml_url, DC_TPL_CACHE, $force);
} catch (Exception $e) {
return false;
}
$raw_datas = !$parser ? [] : $parser->getModules();
uasort($raw_datas, fn ($a, $b) => strtolower($a['id']) <=> strtolower($b['id']));
$updates = [];
$current = array_merge($this->modules->getModules(), $this->modules->getDisabledModules());
foreach ($current as $p_id => $p_infos) {
# non privileged user has no info
if (!is_array($p_infos)) {
continue;
}
# main repository
if (isset($raw_datas[$p_id])) {
if (dcUtils::versionsCompare($raw_datas[$p_id]['version'], $p_infos['version'], '>=')) {
$updates[$p_id] = $raw_datas[$p_id];
$updates[$p_id]['root'] = $p_infos['root'];
$updates[$p_id]['root_writable'] = $p_infos['root_writable'];
$updates[$p_id]['current_version'] = $p_infos['version'];
}
unset($raw_datas[$p_id]);
}
# per module third-party repository
if (!empty($p_infos['repository']) && DC_ALLOW_REPOSITORIES) {
try {
$dcs_url = substr($p_infos['repository'], -12, 12) == '/dcstore.xml' ? $p_infos['repository'] : http::concatURL($p_infos['repository'], 'dcstore.xml');
$dcs_parser = CsvStoreReader::quickParse($dcs_url, DC_TPL_CACHE, $force);
if ($dcs_parser !== false) {
$dcs_raw_datas = $dcs_parser->getModules();
if (isset($dcs_raw_datas[$p_id]) && dcUtils::versionsCompare($dcs_raw_datas[$p_id]['version'], $p_infos['version'], '>=')) {
if (!isset($updates[$p_id]) || dcUtils::versionsCompare($dcs_raw_datas[$p_id]['version'], $updates[$p_id]['version'], '>=')) {
$dcs_raw_datas[$p_id]['repository'] = true;
$updates[$p_id] = $dcs_raw_datas[$p_id];
$updates[$p_id]['root'] = $p_infos['root'];
$updates[$p_id]['root_writable'] = $p_infos['root_writable'];
$updates[$p_id]['current_version'] = $p_infos['version'];
}
}
}
} catch (Exception $e) {
}
}
}
$this->data = [
'new' => [],
'update' => $updates,
];
return true;
}
}

View File

@ -10,48 +10,50 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
class csvStoreParser extends dcStoreParser
{
# overwrite dcStoreParser to bypasse current dotclear version
protected function _parse()
{
if (empty($this->xml->module)) {
return;
}
foreach ($this->xml->module as $i) {
$attrs = $i->attributes();
$item = [];
# DC/DA shared markers
$item['id'] = (string) $attrs['id'];
$item['file'] = (string) $i->file;
$item['label'] = (string) $i->name; // deprecated
$item['name'] = (string) $i->name;
$item['version'] = (string) $i->version;
$item['author'] = (string) $i->author;
$item['desc'] = (string) $i->desc;
# DA specific markers
$item['dc_min'] = (string) $i->children(self::$bloc)->dcmin;
$item['details'] = (string) $i->children(self::$bloc)->details;
$item['section'] = (string) $i->children(self::$bloc)->section;
$item['support'] = (string) $i->children(self::$bloc)->support;
$item['sshot'] = (string) $i->children(self::$bloc)->sshot;
$tags = [];
foreach ($i->children(self::$bloc)->tags as $t) {
$tags[] = (string) $t->tag;
}
$item['tags'] = implode(', ', $tags);
# No more filters here, return all modules
$this->items[$item['id']] = $item;
}
}
}
declare(strict_types=1);
namespace Dotclear\Plugin\checkStoreVersion;
use dcStoreParser;
class CsvStoreParser extends dcStoreParser
{
# overwrite dcStoreParser to bypasse current dotclear version
protected function _parse()
{
if (empty($this->xml->module)) {
return;
}
foreach ($this->xml->module as $i) {
$attrs = $i->attributes();
$item = [];
# DC/DA shared markers
$item['id'] = (string) $attrs['id'];
$item['file'] = (string) $i->file;
$item['label'] = (string) $i->name; // deprecated
$item['name'] = (string) $i->name;
$item['version'] = (string) $i->version;
$item['author'] = (string) $i->author;
$item['desc'] = (string) $i->desc;
# DA specific markers
$item['dc_min'] = (string) $i->children(self::$bloc)->dcmin;
$item['details'] = (string) $i->children(self::$bloc)->details;
$item['section'] = (string) $i->children(self::$bloc)->section;
$item['support'] = (string) $i->children(self::$bloc)->support;
$item['sshot'] = (string) $i->children(self::$bloc)->sshot;
$tags = [];
foreach ($i->children(self::$bloc)->tags as $t) {
$tags[] = (string) $t->tag;
}
$item['tags'] = implode(', ', $tags);
# No more filters here, return all modules
$this->items[$item['id']] = $item;
}
}
}

View File

@ -10,25 +10,31 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class csvStoreReader extends dcStoreReader
{
# overwrite dcStoreReader to remove cache and use mvStoreParser
public function parse($url)
{
$this->validators = [];
if (!$this->getModulesXML($url) || $this->getStatus() != '200') {
return false;
}
return new csvStoreParser($this->getContent());
}
# overwrite dcStoreReader to remove cache and use mvStoreParser
public static function quickParse($url, $cache_dir = null, $force = true)
{
$parser = new self();
return $parser->parse($url);
}
}
declare(strict_types=1);
namespace Dotclear\Plugin\checkStoreVersion;
use dcStoreReader;
class CsvStoreReader extends dcStoreReader
{
# overwrite dcStoreReader to remove cache and use mvStoreParser
public function parse($url)
{
$this->validators = [];
if (!$this->getModulesXML($url) || $this->getStatus() != '200') {
return false;
}
return new CsvStoreParser($this->getContent());
}
# overwrite dcStoreReader to remove cache and use mvStoreParser
public static function quickParse($url, $cache_dir = null, $force = true)
{
$parser = new self();
return $parser->parse($url);
}
}

20
src/My.php Normal file
View File

@ -0,0 +1,20 @@
<?php
/**
* @brief checkStoreVersion, 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
*/
declare(strict_types=1);
namespace Dotclear\Plugin\checkStoreVersion;
class My
{
public const DC_MAX = '2.25.3';
}