Compare commits

...

10 Commits

9 changed files with 160 additions and 25 deletions

View File

@ -1,3 +1,14 @@
2023.05.13
- require dotclear 2.26
- release for dotclear 2.26 stable
2023.04.23
- require dotclear 2.26
- use latest dotclear namespace
- add plugin Uninstaller features
- remove magic
- fix nullsafe warnings
2023.03.26 2023.03.26
- require dotclear 2.26 - require dotclear 2.26
- use namespace - use namespace

View File

@ -10,7 +10,7 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH') || is_null(dcCore::app()->auth)) {
return null; return null;
} }
@ -18,12 +18,12 @@ $this->registerModule(
"Dotclear's latest versions", "Dotclear's latest versions",
'Show the latest available versions of Dotclear', 'Show the latest available versions of Dotclear',
'Jean-Christian Denis, Pierre Van Glabeke', 'Jean-Christian Denis, Pierre Van Glabeke',
'2023.03.26', '2023.05.13',
[ [
'requires' => [['core', '2.26']], 'requires' => [['core', '2.26']],
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_USAGE, dcCore::app()->auth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), ]),
'type' => 'plugin', 'type' => 'plugin',
'support' => 'http://forum.dotclear.org/viewforum.php?id=16', 'support' => 'http://forum.dotclear.org/viewforum.php?id=16',

View File

@ -2,10 +2,10 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="dcLatestVersions"> <module id="dcLatestVersions">
<name>Dotclear's latest versions</name> <name>Dotclear's latest versions</name>
<version>2023.03.26</version> <version>2023.05.13</version>
<author>Jean-Christian Denis, Pierre Van Glabeke</author> <author>Jean-Christian Denis, Pierre Van Glabeke</author>
<desc>Show the latest available versions of Dotclear</desc> <desc>Show the latest available versions of Dotclear</desc>
<file>https://github.com/JcDenis/dcLatestVersions/releases/download/v2023.03.26/plugin-dcLatestVersions.zip</file> <file>https://github.com/JcDenis/dcLatestVersions/releases/download/v2023.05.13/plugin-dcLatestVersions.zip</file>
<da:dcmin>2.26</da:dcmin> <da:dcmin>2.26</da:dcmin>
<da:details>http://plugins.dotaddict.org/dc2/details/dcLatestVersions</da:details> <da:details>http://plugins.dotaddict.org/dc2/details/dcLatestVersions</da:details>
<da:support>http://forum.dotclear.org/viewforum.php?id=16</da:support> <da:support>http://forum.dotclear.org/viewforum.php?id=16</da:support>

View File

@ -9,9 +9,11 @@
# DOT NOT MODIFY THIS FILE ! # DOT NOT MODIFY THIS FILE !
# #
l10n::$locales['Download Dotclear %s'] = 'Télécharger Dotclear %s'; use Dotclear\Helper\L10n;
l10n::$locales['Dotclear\'s latest versions'] = 'Dernières versions de Dotclear';
l10n::$locales['Show Dotclear\'s latest versions on dashboards.'] = 'Afficher les dernières versions de Dotclear sur le tableau de bord'; L10n::$locales['Download Dotclear %s'] = 'Télécharger Dotclear %s';
l10n::$locales['Show the latest available versions of Dotclear'] = 'Afficher les dernières versions disponibles de Dotclear'; L10n::$locales['Dotclear\'s latest versions'] = 'Dernières versions de Dotclear';
l10n::$locales['Text (%r = release, %v = version, %u = url):'] = 'Texte (%r = type, %v = version, %u = url) :'; L10n::$locales['Show Dotclear\'s latest versions on dashboards.'] = 'Afficher les dernières versions de Dotclear sur le tableau de bord';
l10n::$locales['<strong>%r: </strong> <a href="%u" title="Download Dotclear %v">%v</a>'] = '<strong>%r : </strong> <a href="%u" title="Télécharger Dotclear %v">%v</a>'; L10n::$locales['Show the latest available versions of Dotclear'] = 'Afficher les dernières versions disponibles de Dotclear';
L10n::$locales['Text (%r = release, %v = version, %u = url):'] = 'Texte (%r = type, %v = version, %u = url) :';
L10n::$locales['<strong>%r: </strong> <a href="%u" title="Download Dotclear %v">%v</a>'] = '<strong>%r : </strong> <a href="%u" title="Télécharger Dotclear %v">%v</a>';

View File

@ -43,6 +43,11 @@ class Backend extends dcNsProcess
dcCore::app()->addBehaviors([ dcCore::app()->addBehaviors([
'initWidgets' => [Widgets::class, 'initWidgets'], 'initWidgets' => [Widgets::class, 'initWidgets'],
'adminDashboardItemsV2' => function (ArrayObject $__dashboard_items): void { 'adminDashboardItemsV2' => function (ArrayObject $__dashboard_items): void {
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs) || is_null(dcCore::app()->blog)) {
return;
}
if (!dcCore::app()->auth->user_prefs->get('dashboard')->get('dcLatestVersionsItems')) { if (!dcCore::app()->auth->user_prefs->get('dashboard')->get('dcLatestVersionsItems')) {
return; return;
} }
@ -92,6 +97,11 @@ class Backend extends dcNsProcess
}, },
'adminDashboardOptionsFormV2' => function (): void { 'adminDashboardOptionsFormV2' => function (): void {
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) {
return;
}
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('dcLatestVersionsItems')) { if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('dcLatestVersionsItems')) {
dcCore::app()->auth->user_prefs->get('dashboard')->put( dcCore::app()->auth->user_prefs->get('dashboard')->put(
'dcLatestVersionsItems', 'dcLatestVersionsItems',
@ -103,14 +113,24 @@ class Backend extends dcNsProcess
echo echo
'<div class="fieldset">' . '<div class="fieldset">' .
'<h4>' . Html::escapeHTML(My::name()) . '</h4>' . '<h4>' . Html::escapeHTML(My::name()) . '</h4>' .
(new Para())->items([ (new Para())
(new Checkbox('dcLatestVersionsItems', (bool) dcCore::app()->auth->user_prefs->get('dashboard')->get('dcLatestVersionsItems')))->value(1), ->__call('items', [[
(new Label(__("Show Dotclear's latest versions on dashboards."), Label::OUTSIDE_LABEL_AFTER))->for('dcLatestVersionsItems')->class('classic'), (new Checkbox('dcLatestVersionsItems', (bool) dcCore::app()->auth->user_prefs->get('dashboard')->get('dcLatestVersionsItems')))
])->render() . ->__call('value', [1]),
(new Label(__("Show Dotclear's latest versions on dashboards."), Label::OUTSIDE_LABEL_AFTER))
->__call('for', ['dcLatestVersionsItems'])
->__call('class', ['classic']),
]])
->render() .
'</div>'; '</div>';
}, },
'adminAfterDashboardOptionsUpdate' => function (?string $user_id): void { 'adminAfterDashboardOptionsUpdate' => function (?string $user_id): void {
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) {
return;
}
dcCore::app()->auth->user_prefs->get('dashboard')->put( dcCore::app()->auth->user_prefs->get('dashboard')->put(
'dcLatestVersionsItems', 'dcLatestVersionsItems',
!empty($_POST['dcLatestVersionsItems']), !empty($_POST['dcLatestVersionsItems']),

View File

@ -33,6 +33,11 @@ class Install extends dcNsProcess
return false; return false;
} }
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->blog)) {
return false;
}
dcCore::app()->blog->settings->get(My::id())->put( dcCore::app()->blog->settings->get(My::id())->put(
'builds', 'builds',
'stable,unstable,testing', 'stable,unstable,testing',

View File

@ -17,12 +17,12 @@ namespace Dotclear\Plugin\dcLatestVersions;
use dcCore; use dcCore;
/** /**
* Plugin definitions * This module definitions.
*/ */
class My class My
{ {
/** /**
* This module id * This module id.
*/ */
public static function id(): string public static function id(): string
{ {
@ -30,10 +30,20 @@ class My
} }
/** /**
* This module name * This module name.
*/ */
public static function name(): string public static function name(): string
{ {
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name')); $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__);
} }
} }

82
src/Uninstall.php 100644
View File

@ -0,0 +1,82 @@
<?php
/**
* @brief dcLatestVersions, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\dcLatestVersions;
use dcCore;
use dcNsProcess;
use Dotclear\Plugin\Uninstaller\Uninstaller;
class Uninstall extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN');
return static::$init;
}
public static function process(): bool
{
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false;
}
Uninstaller::instance()
->addUserAction(
'settings',
'delete_all',
My::id()
)
->addUserAction(
'preferences',
'delete_related',
'dashboard:dcLatestVersionsItems'
)
->addUserAction(
'plugins',
'delete',
My::id()
)
->addUserAction(
'versions',
'delete',
My::id()
)
->addDirectAction(
'settings',
'delete_all',
My::id()
)
->addDirectAction(
'preferences',
'delete_related',
'dashboard:dcLatestVersionsItems'
)
->addDirectAction(
'plugins',
'delete',
My::id()
)
->addDirectAction(
'versions',
'delete',
My::id()
)
;
// no custom action
return false;
}
}

View File

@ -49,7 +49,12 @@ class Widgets
public static function parseWidget(WidgetsElement $w): string public static function parseWidget(WidgetsElement $w): string
{ {
if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type) || $w->text == '') { if ($w->__get('offline') || !$w->checkHomeOnly(dcCore::app()->url->type) || $w->__get('text') == '') {
return '';
}
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->blog)) {
return ''; return '';
} }
@ -88,7 +93,7 @@ class Widgets
$updater->getVersion(), $updater->getVersion(),
$updater->getFileURL(), $updater->getFileURL(),
], ],
$w->text $w->__get('text')
)); ));
} }
@ -98,10 +103,10 @@ class Widgets
# Display # Display
return $w->renderDiv( return $w->renderDiv(
(bool) $w->content_only, (bool) $w->__get('content_only'),
'dclatestversionswidget ' . $w->class, 'dclatestversionswidget ' . $w->__get('class'),
'', '',
($w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : '') . sprintf('<ul>%s</ul>', implode('', $li)) ($w->__get('title') ? $w->renderTitle(Html::escapeHTML($w->__get('title'))) : '') . sprintf('<ul>%s</ul>', implode('', $li))
); );
} }
} }