Compare commits

...

10 Commits

13 changed files with 320 additions and 215 deletions

View File

@ -1,4 +1,11 @@
x.x
0.3.1 - 2003.03.19
- fix init check
- fix missing closing div
- fix tab methods names
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 +13,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.1',
[
'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.1</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.1/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>

View File

@ -0,0 +1,25 @@
<?php
/**
* @package Dotclear
*
* @copyright Olivier Meunier & Association Dotclear
* @copyright GPL-2.0-only
*/
#
# DOT NOT MODIFY THIS FILE !
#
use Dotclear\Helper\L10n;
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 100644
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
{
static::$init = defined('DC_CONTEXT_ADMIN')
&& !is_null(dcCore::app()->auth) // nullsafe PHP < 8.0
&& dcCore::app()->auth->isSuperAdmin();
return static::$init;
}
public static function process(): bool
{
if (!static::$init) {
return false;
}
dcCore::app()->addBehaviors([
'pluginsToolsTabsV2' => [BackendBehaviors::class, 'pluginsTabs'],
'themesToolsTabsV2' => [BackendBehaviors::class, 'themesTabs'],
]);
return true;
}
}

View File

@ -10,46 +10,60 @@
* @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 Dotclear\Helper\Html\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 pluginsTabs(): void
{
self::modulesToolsTabs($core, $core->plugins, explode(',', DC_DISTRIB_PLUGINS), $core->adminurl->get('admin.plugins'));
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->adminurl)) {
return;
}
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 themesTabs(): void
{
self::modulesToolsTabs($core, $core->themes, explode(',', DC_DISTRIB_THEMES), $core->adminurl->get('admin.blog.theme'));
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->adminurl)) {
return;
}
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
{
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->blog)) {
return;
}
$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>' .
'</div>';
return;
}
@ -72,24 +86,23 @@ 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
'</div>';
}
private static function modulesList($modules, $repos)
private static function modulesList(array $modules, array $repos): void
{
echo
'<div class="table-outer">' .
'<table id="mvmodules" class="modules">' .
'<caption class="hidden">' . html::escapeHTML(__('Modules list')) . '</caption><tr>' .
'<caption class="hidden">' . Html::escapeHTML(__('Modules list')) . '</caption><tr>' .
'<th class="first nowrap" colspan="3">' . __('Name') . '</th>' .
'<th class="nowrap count" scope="col">' . __('Current version') . '</th>' .
'<th class="nowrap count" scope="col">' . __('Latest version') . '</th>' .
@ -101,7 +114,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)) {
@ -130,23 +142,23 @@ class csvBehaviors
}
echo
'<tr class="line' . (isset($repos[$id]) ? '' : ' offline') . '" id="mvmodules_m_' . html::escapeHTML($id) . '">' .
'<tr class="line' . (isset($repos[$id]) ? '' : ' offline') . '" id="mvmodules_m_' . Html::escapeHTML($id) . '">' .
'<td class="module-icon nowrap">' .
$img . '</td>' .
'<td class="module-icon nowrap">' .
dcAdminHelper::adminIcon($icon, false, html::escapeHTML($id), html::escapeHTML($id)) . '</td>' .
dcAdminHelper::adminIcon($icon, false, Html::escapeHTML($id), Html::escapeHTML($id)) . '</td>' .
'<th class="module-name nowrap" scope="row">' .
html::escapeHTML($module['name']) . ($id != $module['name'] ? sprintf(__(' (%s)'), $id) : '') .
Html::escapeHTML($module['name']) . ($id != $module['name'] ? sprintf(__(' (%s)'), $id) : '') .
'</td>';
if (isset($repos[$id])) {
echo
'<td class="module-version nowrap count">' .
html::escapeHTML($repos[$id]['current_version']) . '</td>' .
Html::escapeHTML($repos[$id]['current_version']) . '</td>' .
'<td class="module-version nowrap count maximal">' .
html::escapeHTML($repos[$id]['version']) . '</td>' .
Html::escapeHTML($repos[$id]['version']) . '</td>' .
'<td class="module-version nowrap count">' .
html::escapeHTML($repos[$id]['dc_min']) . '</td>';
Html::escapeHTML($repos[$id]['dc_min']) . '</td>';
if (DC_ALLOW_REPOSITORIES) {
echo
@ -156,9 +168,9 @@ class csvBehaviors
} else {
echo
'<td class="module-current-version nowrap count">' .
html::escapeHTML($module['version']) . '</td>' .
Html::escapeHTML($module['version']) . '</td>' .
'<td class="module-version nowrap count maximal" colspan="' . (DC_ALLOW_REPOSITORIES ? '3' : '2') . '">' .
html::escapeHTML(__('No version available on stores')) . '</td>';
Html::escapeHTML(__('No version available on stores')) . '</td>';
}
echo

View File

@ -10,21 +10,26 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
declare(strict_types=1);
class csvStore extends dcStore
namespace Dotclear\Plugin\checkStoreVersion;
use dcStore;
use dcUtils;
use Dotclear\Helper\Network\Http;
use Exception;
class CsvStore extends dcStore
{
# overwrite dcStore::check to remove cache and use csvStoreReader and check disabled modules
public function check($force = true)
# 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);
$parser = DC_STORE_NOT_UPDATE ? false : CsvStoreReader::quickParse($this->xml_url, DC_TPL_CACHE, $force);
} catch (Exception $e) {
return false;
}
@ -53,8 +58,8 @@ class csvStore extends dcStore
# 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);
$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'], '>=')) {

View File

@ -10,14 +10,16 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
declare(strict_types=1);
class csvStoreParser extends dcStoreParser
namespace Dotclear\Plugin\checkStoreVersion;
use dcStoreParser;
class CsvStoreParser extends dcStoreParser
{
# overwrite dcStoreParser to bypasse current dotclear version
protected function _parse()
# overwrite dcStoreParser to bypasse current dotclear version
protected function _parse(): void
{
if (empty($this->xml->module)) {
return;
@ -25,6 +27,9 @@ class csvStoreParser extends dcStoreParser
foreach ($this->xml->module as $i) {
$attrs = $i->attributes();
if (!isset($attrs['id'])) {
continue;
}
$item = [];

View File

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

20
src/My.php 100644
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.26';
}