diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b20c9d..9ad65ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 4d09fbc..e8dd339 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/_define.php b/_define.php index dc32f18..d0e4390 100644 --- a/_define.php +++ b/_define.php @@ -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', ] ); diff --git a/_prepend.php b/_prepend.php deleted file mode 100644 index ba62bd6..0000000 --- a/_prepend.php +++ /dev/null @@ -1,19 +0,0 @@ - Check store version - 0.2 + 0.3 Jean-Christian Denis and Contributors Check plugins and themes available version before update - https://github.com/JcDenis/checkStoreVersion/releases/download/v0.2/plugin-checkStoreVersion.zip - 2.19 + https://github.com/JcDenis/checkStoreVersion/releases/download/v0.3/plugin-checkStoreVersion.zip + 2.25 https://plugins.dotaddict.org/dc2/details/checkStoreVersion https://github.com/JcDenis/checkStoreVersion diff --git a/locales/fr/main.lang.php b/locales/fr/main.lang.php new file mode 100644 index 0000000..2c292b6 --- /dev/null +++ b/locales/fr/main.lang.php @@ -0,0 +1,23 @@ + %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'; diff --git a/locales/fr/main.po b/locales/fr/main.po index af83689..b0f9c0a 100644 --- a/locales/fr/main.po +++ b/locales/fr/main.po @@ -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" diff --git a/src/Backend.php b/src/Backend.php new file mode 100644 index 0000000..bb5c4ae --- /dev/null +++ b/src/Backend.php @@ -0,0 +1,44 @@ +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; + } +} diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index e0e9801..0effaa9 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -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 '
' . '

' . __('Check stores versions') . '

'; - if (!method_exists('dcUtils', 'versionsCompare') - || dcUtils::versionsCompare(DC_VERSION, self::DC_MAX, '>', false)) { + if (dcUtils::versionsCompare(DC_VERSION, My::DC_MAX, '>', false)) { echo - '

' . sprintf(__('This version does not support Dotclear > %s'), self::DC_MAX) . '

'; + '

' . sprintf(__('This version does not support Dotclear > %s'), My::DC_MAX) . '

'; return; } @@ -72,12 +70,11 @@ class csvBehaviors echo '
' . '

' . - $core->formNonce() . '

' . + dcCore::app()->formNonce() . '

' . '
'; - 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 '
' . '' . '' . @@ -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 '' . - '' . - '' . - '' . - '' . - ''; if (DC_ALLOW_REPOSITORIES) { echo - ''; } } else { - echo - '' . - ''; } - echo + echo ''; } diff --git a/src/CsvStore.php b/src/CsvStore.php index 320dd78..f2e9913 100644 --- a/src/CsvStore.php +++ b/src/CsvStore.php @@ -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; - } -} \ No newline at end of file +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; + } +} diff --git a/src/CsvStoreParser.php b/src/CsvStoreParser.php index 1832722..a45c0a8 100644 --- a/src/CsvStoreParser.php +++ b/src/CsvStoreParser.php @@ -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; - } - } -} \ No newline at end of file +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; + } + } +} diff --git a/src/CsvStoreReader.php b/src/CsvStoreReader.php index a577b7d..b607847 100644 --- a/src/CsvStoreReader.php +++ b/src/CsvStoreReader.php @@ -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); + } +} diff --git a/src/My.php b/src/My.php new file mode 100644 index 0000000..6d0fdaa --- /dev/null +++ b/src/My.php @@ -0,0 +1,20 @@ +
' . + '' . $img . '' . + '' . dcAdminHelper::adminIcon($icon, false, html::escapeHTML($id), html::escapeHTML($id)) . '' . + '' . html::escapeHTML($module['name']) . ($id != $module['name'] ? sprintf(__(' (%s)'), $id) : '') . ''; if (isset($repos[$id])) { echo - '' . + '' . html::escapeHTML($repos[$id]['current_version']) . '' . + '' . html::escapeHTML($repos[$id]['version']) . '' . + '' . html::escapeHTML($repos[$id]['dc_min']) . '' . + '' . (empty($module['repository']) ? __('Official repository') : __('Third-party repository')) . '' . + echo + '' . html::escapeHTML($module['version']) . '' . + '' . html::escapeHTML(__('No version available on stores')) . '