prepare to DC 2.24

master
Jean-Christian Paul Denis 2022-11-16 23:03:38 +01:00
parent 5793a5a927
commit 8b441a2989
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
5 changed files with 111 additions and 99 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- # -- BEGIN LICENSE BLOCK ----------------------------------
# #
# This file is part of dcLatestVersions, a plugin for Dotclear 2. # This file is part of dcLatestVersions, a plugin for Dotclear 2.
@ -15,18 +16,18 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
require dirname(__FILE__) . '/_widgets.php'; require __DIR__ . '/_widgets.php';
# Dashboard item and user preference # Dashboard item and user preference
$core->addBehavior( dcCore::app()->addBehavior(
'adminDashboardItems', 'adminDashboardItemsV2',
['dcLatestVersionsAdmin', 'adminDashboardItems'] ['dcLatestVersionsAdmin', 'adminDashboardItems']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminDashboardOptionsForm', 'adminDashboardOptionsFormV2',
['dcLatestVersionsAdmin', 'adminDashboardOptionsForm'] ['dcLatestVersionsAdmin', 'adminDashboardOptionsForm']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminAfterDashboardOptionsUpdate', 'adminAfterDashboardOptionsUpdate',
['dcLatestVersionsAdmin', 'adminAfterDashboardOptionsUpdate'] ['dcLatestVersionsAdmin', 'adminAfterDashboardOptionsUpdate']
); );
@ -38,13 +39,13 @@ $core->addBehavior(
*/ */
class dcLatestVersionsAdmin class dcLatestVersionsAdmin
{ {
public static function adminDashboardItems(dcCore $core, $__dashboard_items) public static function adminDashboardItems($__dashboard_items)
{ {
if (!$core->auth->user_prefs->dashboard->get('dcLatestVersionsItems')) { if (!dcCore::app()->auth->user_prefs->dashboard->get('dcLatestVersionsItems')) {
return null; return null;
} }
$builds = explode(',', (string) $core->blog->settings->dcLatestVersions->builds); $builds = explode(',', (string) dcCore::app()->blog->settings->dcLatestVersions->builds);
if (empty($builds)) { if (empty($builds)) {
return null; return null;
} }
@ -52,8 +53,7 @@ class dcLatestVersionsAdmin
$text = __('<li><a href="%u" title="Download Dotclear %v">%r</a> : %v</li>'); $text = __('<li><a href="%u" title="Download Dotclear %v">%r</a> : %v</li>');
$li = []; $li = [];
foreach($builds as $build) { foreach ($builds as $build) {
$build = strtolower(trim($build)); $build = strtolower(trim($build));
if (empty($build)) { if (empty($build)) {
continue; continue;
@ -74,12 +74,12 @@ class dcLatestVersionsAdmin
[ [
'%r', '%r',
'%v', '%v',
'%u' '%u',
], ],
[ [
$build, $build,
$updater->getVersion(), $updater->getVersion(),
$updater->getFileURL() $updater->getFileURL(),
], ],
$text $text
); );
@ -90,23 +90,22 @@ class dcLatestVersionsAdmin
} }
# Display # Display
$__dashboard_items[0][] = $__dashboard_items[0][] = '<div class="box small" id="udclatestversionsitems">' .
'<div class="box small" id="udclatestversionsitems">' .
'<h3>' . html::escapeHTML(__("Dotclear's latest versions")) . '</h3>' . '<h3>' . html::escapeHTML(__("Dotclear's latest versions")) . '</h3>' .
'<ul>' . implode('', $li) . '</ul>' . '<ul>' . implode('', $li) . '</ul>' .
'</div>'; '</div>';
} }
public static function adminDashboardOptionsForm(dcCore $core) public static function adminDashboardOptionsForm()
{ {
if (!$core->auth->user_prefs->dashboard->prefExists('dcLatestVersionsItems')) { if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('dcLatestVersionsItems')) {
$core->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'dcLatestVersionsItems', 'dcLatestVersionsItems',
false, false,
'boolean' 'boolean'
); );
} }
$pref = $core->auth->user_prefs->dashboard->get('dcLatestVersionsItems'); $pref = dcCore::app()->auth->user_prefs->dashboard->get('dcLatestVersionsItems');
echo echo
'<div class="fieldset">' . '<div class="fieldset">' .
@ -120,7 +119,7 @@ class dcLatestVersionsAdmin
public static function adminAfterDashboardOptionsUpdate($user_id) public static function adminAfterDashboardOptionsUpdate($user_id)
{ {
$GLOBALS['core']->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'dcLatestVersionsItems', 'dcLatestVersionsItems',
!empty($_POST['dcLatestVersionsItems']), !empty($_POST['dcLatestVersionsItems']),
'boolean' 'boolean'

View File

@ -1,4 +1,5 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- # -- BEGIN LICENSE BLOCK ----------------------------------
# #
# This file is part of dcLatestVersions, a plugin for Dotclear 2. # This file is part of dcLatestVersions, a plugin for Dotclear 2.
@ -19,13 +20,16 @@ $this->registerModule(
'dcLatestVersions', 'dcLatestVersions',
'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',
'2021.08.27', '2022.11.12',
[ [
'permissions' => 'usage,contentadmin', 'requires' => [['core', '2.24']],
'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]),
'type' => 'plugin', 'type' => 'plugin',
'dc_min' => '2.19',
'support' => 'http://forum.dotclear.org/viewforum.php?id=16', 'support' => 'http://forum.dotclear.org/viewforum.php?id=16',
'details' => 'http://plugins.dotaddict.org/dc2/details/dcLatestVersions', 'details' => 'http://plugins.dotaddict.org/dc2/details/dcLatestVersions',
'repository' => 'https://raw.githubusercontent.com/JcDenis/dcLatestVersions/master/dcstore.xml' 'repository' => 'https://raw.githubusercontent.com/JcDenis/dcLatestVersions/master/dcstore.xml',
] ]
); );

View File

@ -1,4 +1,5 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- # -- BEGIN LICENSE BLOCK ----------------------------------
# #
# This file is part of dcLatestVersions, a plugin for Dotclear 2. # This file is part of dcLatestVersions, a plugin for Dotclear 2.
@ -16,46 +17,55 @@ if (!defined('DC_CONTEXT_ADMIN')) {
} }
# -- Module specs -- # -- Module specs --
$dc_min = '2.19'; $dc_min = '2.24';
$mod_id = 'dcLatestVersions'; $mod_id = 'dcLatestVersions';
$mod_conf = [[ $mod_conf = [[
'builds', 'builds',
"List of Dotclear's builds", "List of Dotclear's builds",
'stable,unstable,testing,sexy', 'stable,unstable,testing,sexy',
'string' 'string',
]]; ]];
# -- Nothing to change below -- # -- Nothing to change below --
try { try {
# Check module version # Check module version
if (version_compare( if (version_compare(
$core->getVersion($mod_id), dcCore::app()->getVersion($mod_id),
$core->plugins->moduleInfo($mod_id, 'version'), dcCore::app()->plugins->moduleInfo($mod_id, 'version'),
'>=')) { '>='
)) {
return null; return null;
} }
# Check Dotclear version # Check Dotclear version
if (!method_exists('dcUtils', 'versionsCompare') if (!method_exists('dcUtils', 'versionsCompare')
|| dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) {
throw new Exception(sprintf( throw new Exception(sprintf(
'%s requires Dotclear %s', $mod_id, $dc_min '%s requires Dotclear %s',
$mod_id,
$dc_min
)); ));
} }
# Set module settings # Set module settings
$core->blog->settings->addNamespace($mod_id); dcCore::app()->blog->settings->addNamespace($mod_id);
foreach($mod_conf as $v) { foreach ($mod_conf as $v) {
$core->blog->settings->{$mod_id}->put( dcCore::app()->blog->settings->{$mod_id}->put(
$v[0], $v[2], $v[3], $v[1], false, true $v[0],
$v[2],
$v[3],
$v[1],
false,
true
); );
} }
# Set module version # Set module version
$core->setVersion( dcCore::app()->setVersion(
$mod_id, $mod_id,
$core->plugins->moduleInfo($mod_id, 'version') dcCore::app()->plugins->moduleInfo($mod_id, 'version')
); );
return true; return true;
} } catch (Exception $e) {
catch (Exception $e) { dcCore::app()->error->add($e->getMessage());
$core->error->add($e->getMessage());
return false; return false;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- # -- BEGIN LICENSE BLOCK ----------------------------------
# #
# This file is part of dcLatestVersions, a plugin for Dotclear 2. # This file is part of dcLatestVersions, a plugin for Dotclear 2.

View File

@ -1,4 +1,5 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- # -- BEGIN LICENSE BLOCK ----------------------------------
# #
# This file is part of dcLatestVersions, a plugin for Dotclear 2. # This file is part of dcLatestVersions, a plugin for Dotclear 2.
@ -15,9 +16,9 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$core->blog->settings->addNamespace('dcLatestVersions'); dcCore::app()->blog->settings->addNamespace('dcLatestVersions');
$core->addBehavior( dcCore::app()->addBehavior(
'initWidgets', 'initWidgets',
['dcLatestVersionsWidget', 'adminWidget'] ['dcLatestVersionsWidget', 'adminWidget']
); );
@ -37,7 +38,7 @@ class dcLatestVersionsWidget
__("Dotclear's latest versions"), __("Dotclear's latest versions"),
['dcLatestVersionsWidget','publicWidget'], ['dcLatestVersionsWidget','publicWidget'],
null, null,
__("Show the latest available versions of Dotclear") __('Show the latest available versions of Dotclear')
) )
->addTitle( ->addTitle(
__("Dotclear's latest versions") __("Dotclear's latest versions")
@ -56,30 +57,27 @@ class dcLatestVersionsWidget
public static function publicWidget($w) public static function publicWidget($w)
{ {
global $core; dcCore::app()->blog->settings->addNamespace('dcLatestVersions');
$core->blog->settings->addNamespace('dcLatestVersions');
if ($w->offline) { if ($w->offline) {
return null; return null;
} }
if (($w->homeonly == 1 && !$core->url->isHome($core->url->type)) if (($w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type))
|| ($w->homeonly == 2 && $core->url->isHome($core->url->type)) || ($w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type))
|| $w->text == '') { || $w->text == '') {
return null; return null;
} }
# Builds to check # Builds to check
$builds = (string) $core->blog->settings->dcLatestVersions->builds; $builds = (string) dcCore::app()->blog->settings->dcLatestVersions->builds;
$builds = explode(',', $builds); $builds = explode(',', $builds);
if (empty($builds)) { if (empty($builds)) {
return null; return null;
} }
$li = []; $li = [];
foreach($builds as $build) { foreach ($builds as $build) {
$build = strtolower(trim($build)); $build = strtolower(trim($build));
if (empty($build)) { if (empty($build)) {
continue; continue;
@ -100,12 +98,12 @@ class dcLatestVersionsWidget
[ [
'%r', '%r',
'%v', '%v',
'%u' '%u',
], ],
[ [
$build, $build,
$updater->getVersion(), $updater->getVersion(),
$updater->getFileURL() $updater->getFileURL(),
], ],
$w->text $w->text
)); ));
@ -118,9 +116,9 @@ class dcLatestVersionsWidget
# Display # Display
return $w->renderDiv( return $w->renderDiv(
$w->content_only, $w->content_only,
'dclatestversionswidget '. $w->class, 'dclatestversionswidget ' . $w->class,
'', '',
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . sprintf('<ul>%s</ul>', implode('',$li)) ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . sprintf('<ul>%s</ul>', implode('', $li))
); );
} }
} }