cleanup 2021

This commit is contained in:
Jean-Christian Denis 2021-08-27 17:53:07 +02:00
parent 0df4067d6a
commit 5793a5a927
9 changed files with 243 additions and 269 deletions

View file

@ -1,15 +0,0 @@
2020-09-18 - Pierre Van Glabeke
* modif _admin.php (merci à nanart)
2015-03-11 - Pierre Van Glabeke
* ajout mode hors ligne et codage titre widget (widget)
* encodage UNIX (LF)
* modif url de support
* modifs localisation
* suppression icône
2013.11.18 - Jean-Christian Denis
* First hg release
2013.07.22 - Jean-Christian Denis
* First release

20
CHANGELOG.md Normal file
View file

@ -0,0 +1,20 @@
2021.08.27
- cleanup (PSR2,short array, ...)
- enhance widget style
- update license
2020.09.18 - Pierre Van Glabeke
- modif admin.php (merci à nanart)
2015.03.11 - Pierre Van Glabeke
- ajout mode hors ligne et codage titre widget (widget)
- encodage UNIX (LF)
- modif url de support
- modifs localisation
- suppression icône
2013.11.18 - Jean-Christian Denis
- First hg release
2013.07.22 - Jean-Christian Denis
- First release

View file

@ -21,3 +21,14 @@ Dotaddict repository. (See Dotclear's documentation to know how do this)
Add and configure "Dotclear's latest versions" from widgets manager. Add and configure "Dotclear's latest versions" from widgets manager.
You can add a dashboard item by enable it from your dashboard preferences. You can add a dashboard item by enable it from your dashboard preferences.
## MORE
* License : GNU GPL v2
* Source & contribution : [GitHub Page](https://github.com/JcDenis/dcLatestVersions)
* Packages & details: [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/dcLatestVersions)
## CONTRIBUTORS
* Jean-Chirstian Denis
* Pierre Van Glabeke

View file

@ -3,8 +3,7 @@
# #
# This file is part of dcLatestVersions, a plugin for Dotclear 2. # This file is part of dcLatestVersions, a plugin for Dotclear 2.
# #
# Copyright (c) 2009-2015 Jean-Christian Denis and contributors # Copyright (c) 2009-2021 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
# #
# Licensed under the GPL version 2.0 license. # Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at # A copy of this license is available in LICENSE file or at
@ -13,24 +12,23 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null;
return null;
} }
require dirname(__FILE__).'/_widgets.php'; require dirname(__FILE__) . '/_widgets.php';
# Dashboard item and user preference # Dashboard item and user preference
$core->addBehavior( $core->addBehavior(
'adminDashboardItems', 'adminDashboardItems',
array('dcLatestVersionsAdmin', 'adminDashboardItems') ['dcLatestVersionsAdmin', 'adminDashboardItems']
); );
$core->addBehavior( $core->addBehavior(
'adminDashboardOptionsForm', 'adminDashboardOptionsForm',
array('dcLatestVersionsAdmin', 'adminDashboardOptionsForm') ['dcLatestVersionsAdmin', 'adminDashboardOptionsForm']
); );
$core->addBehavior( $core->addBehavior(
'adminAfterDashboardOptionsUpdate', 'adminAfterDashboardOptionsUpdate',
array('dcLatestVersionsAdmin', 'adminAfterDashboardOptionsUpdate') ['dcLatestVersionsAdmin', 'adminAfterDashboardOptionsUpdate']
); );
/** /**
@ -40,98 +38,92 @@ $core->addBehavior(
*/ */
class dcLatestVersionsAdmin class dcLatestVersionsAdmin
{ {
public static function adminDashboardItems(dcCore $core, $__dashboard_items) public static function adminDashboardItems(dcCore $core, $__dashboard_items)
{ {
if (!$core->auth->user_prefs->dashboard->get('dcLatestVersionsItems')) { if (!$core->auth->user_prefs->dashboard->get('dcLatestVersionsItems')) {
return null;
}
return null; $builds = explode(',', (string) $core->blog->settings->dcLatestVersions->builds);
} if (empty($builds)) {
return null;
}
$builds = (string) $core->blog->settings->dcLatestVersions->builds; $text = __('<li><a href="%u" title="Download Dotclear %v">%r</a> : %v</li>');
$builds = explode(',', $builds); $li = [];
if (empty($builds)) {
return null; foreach($builds as $build) {
}
$text = __('<li><a href="%u" title="Download Dotclear %v">%r</a> : %v</li>'); $build = strtolower(trim($build));
$li = array(); if (empty($build)) {
continue;
}
foreach($builds as $build) { $updater = new dcUpdate(
DC_UPDATE_URL,
'dotclear',
$build,
DC_TPL_CACHE . '/versions'
);
$build = strtolower(trim($build)); if (false === $updater->check('0')) {
if (empty($build)) { continue;
continue; }
}
$updater = new dcUpdate( $li[] = str_replace(
DC_UPDATE_URL, [
'dotclear', '%r',
$build, '%v',
DC_TPL_CACHE.'/versions' '%u'
); ],
[
$build,
$updater->getVersion(),
$updater->getFileURL()
],
$text
);
}
if (false === $updater->check('0')) { if (empty($li)) {
return null;
}
# Display
$__dashboard_items[0][] =
'<div class="box small" id="udclatestversionsitems">' .
'<h3>' . html::escapeHTML(__("Dotclear's latest versions")) . '</h3>' .
'<ul>' . implode('', $li) . '</ul>' .
'</div>';
}
//return false; public static function adminDashboardOptionsForm(dcCore $core)
continue; {
} if (!$core->auth->user_prefs->dashboard->prefExists('dcLatestVersionsItems')) {
$core->auth->user_prefs->dashboard->put(
'dcLatestVersionsItems',
false,
'boolean'
);
}
$pref = $core->auth->user_prefs->dashboard->get('dcLatestVersionsItems');
$li[] = str_replace( echo
array( '<div class="fieldset">' .
'%r', '<h4>' . __("Dotclear's latest versions") . '</h4>' .
'%v', '<p><label class="classic" for="dcLatestVersionsItems">' .
'%u' form::checkbox('dcLatestVersionsItems', 1, $pref) . ' ' .
), __("Show Dotclear's latest versions on dashboards.") .
array( '</label></p>' .
$build, '</div>';
$updater->getVersion(), }
$updater->getFileURL()
),
$text
);
}
if (empty($li)) { public static function adminAfterDashboardOptionsUpdate($user_id)
{
return null; $GLOBALS['core']->auth->user_prefs->dashboard->put(
} 'dcLatestVersionsItems',
!empty($_POST['dcLatestVersionsItems']),
# Display 'boolean'
$__dashboard_items[0][] = );
'<div class="box small" id="udclatestversionsitems">'. }
'<h3>'.html::escapeHTML(__("Dotclear's latest versions")).'</h3>'.
'<ul>'.implode('', $li).'</ul>'.
'</div>';
}
public static function adminDashboardOptionsForm(dcCore $core)
{
if (!$core->auth->user_prefs->dashboard->prefExists('dcLatestVersionsItems')) {
$core->auth->user_prefs->dashboard->put(
'dcLatestVersionsItems',
false,
'boolean'
);
}
$pref = $core->auth->user_prefs->dashboard->get('dcLatestVersionsItems');
echo
'<div class="fieldset">'.
'<h4>'.__("Dotclear's latest versions").'</h4>'.
'<p><label class="classic" for="dcLatestVersionsItems">'.
form::checkbox('dcLatestVersionsItems', 1, $pref).' '.
__("Show Dotclear's latest versions on dashboards.").
'</label></p>'.
'</div>';
}
public static function adminAfterDashboardOptionsUpdate($user_id)
{
$GLOBALS['core']->auth->user_prefs->dashboard->put(
'dcLatestVersionsItems',
!empty($_POST['dcLatestVersionsItems']),
'boolean'
);
}
} }

View file

@ -3,8 +3,7 @@
# #
# This file is part of dcLatestVersions, a plugin for Dotclear 2. # This file is part of dcLatestVersions, a plugin for Dotclear 2.
# #
# Copyright (c) 2009-2015 Jean-Christian Denis and contributors # Copyright (c) 2009-2021 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
# #
# Licensed under the GPL version 2.0 license. # Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at # A copy of this license is available in LICENSE file or at
@ -13,25 +12,20 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null;
return null;
} }
$this->registerModule( $this->registerModule(
/* Name */ 'dcLatestVersions',
"dcLatestVersions", 'Show the latest available versions of Dotclear',
/* Description*/ 'Jean-Christian Denis, Pierre Van Glabeke',
"Show the latest available versions of Dotclear", '2021.08.27',
/* Author */ [
"Jean-Christian Denis, Pierre Van Glabeke", 'permissions' => 'usage,contentadmin',
/* Version */ 'type' => 'plugin',
'2020-09-18', 'dc_min' => '2.19',
/* Properies */ 'support' => 'http://forum.dotclear.org/viewforum.php?id=16',
array( 'details' => 'http://plugins.dotaddict.org/dc2/details/dcLatestVersions',
'permissions' => 'usage,contentadmin', 'repository' => 'https://raw.githubusercontent.com/JcDenis/dcLatestVersions/master/dcstore.xml'
'type' => 'plugin', ]
'dc_min' => '2.6',
'support' => 'http://forum.dotclear.org/viewforum.php?id=16',
'details' => 'http://plugins.dotaddict.org/dc2/details/dcLatestVersions'
)
); );

View file

@ -3,8 +3,7 @@
# #
# This file is part of dcLatestVersions, a plugin for Dotclear 2. # This file is part of dcLatestVersions, a plugin for Dotclear 2.
# #
# Copyright (c) 2009-2015 Jean-Christian Denis and contributors # Copyright (c) 2009-2021 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
# #
# Licensed under the GPL version 2.0 license. # Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at # A copy of this license is available in LICENSE file or at
@ -13,37 +12,28 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
# -- Module specs -- # -- Module specs --
$dc_min = '2.19';
$dc_min = '2.6';
$mod_id = 'dcLatestVersions'; $mod_id = 'dcLatestVersions';
$mod_conf = array( $mod_conf = [[
array( '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), $core->getVersion($mod_id),
$core->plugins->moduleInfo($mod_id, 'version'), $core->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)) {
@ -51,7 +41,6 @@ try {
'%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); $core->blog->settings->addNamespace($mod_id);
foreach($mod_conf as $v) { foreach($mod_conf as $v) {
@ -59,17 +48,14 @@ try {
$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( $core->setVersion(
$mod_id, $mod_id,
$core->plugins->moduleInfo($mod_id, 'version') $core->plugins->moduleInfo($mod_id, 'version')
); );
return true; return true;
} }
catch (Exception $e) { catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
return false; return false;
} }

View file

@ -3,8 +3,7 @@
# #
# This file is part of dcLatestVersions, a plugin for Dotclear 2. # This file is part of dcLatestVersions, a plugin for Dotclear 2.
# #
# Copyright (c) 2009-2015 Jean-Christian Denis and contributors # Copyright (c) 2009-2021 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
# #
# Licensed under the GPL version 2.0 license. # Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at # A copy of this license is available in LICENSE file or at
@ -13,8 +12,7 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null;
return null;
} }
require dirname(__FILE__).'/_widgets.php'; require dirname(__FILE__) . '/_widgets.php';

View file

@ -3,8 +3,7 @@
# #
# This file is part of dcLatestVersions, a plugin for Dotclear 2. # This file is part of dcLatestVersions, a plugin for Dotclear 2.
# #
# Copyright (c) 2009-2015 Jean-Christian Denis and contributors # Copyright (c) 2009-2021 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
# #
# Licensed under the GPL version 2.0 license. # Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at # A copy of this license is available in LICENSE file or at
@ -13,15 +12,14 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null;
return null;
} }
$core->blog->settings->addNamespace('dcLatestVersions'); $core->blog->settings->addNamespace('dcLatestVersions');
$core->addBehavior( $core->addBehavior(
'initWidgets', 'initWidgets',
array('dcLatestVersionsWidget', 'adminWidget') ['dcLatestVersionsWidget', 'adminWidget']
); );
/** /**
@ -31,121 +29,98 @@ $core->addBehavior(
*/ */
class dcLatestVersionsWidget class dcLatestVersionsWidget
{ {
public static function adminWidget($w) public static function adminWidget($w)
{ {
$w->create( $w
'dclatestversionswidget', ->create(
__("Dotclear's latest versions"), 'dclatestversionswidget',
array('dcLatestVersionsWidget','publicWidget'), __("Dotclear's latest versions"),
null, ['dcLatestVersionsWidget','publicWidget'],
__("Show the latest available versions of Dotclear") null,
); __("Show the latest available versions of Dotclear")
$w->dclatestversionswidget->setting( )
'title', ->addTitle(
__('Title:'), __("Dotclear's latest versions")
__("Dotclear's latest versions"), )
'text' ->setting(
); 'text',
$w->dclatestversionswidget->setting( __('Text (%r = release, %v = version, %u = url):'),
'text', __('<strong>%r: </strong> <a href="%u" title="Download Dotclear %v">%v</a>'),
__('Text (%r = release, %v = version, %u = url):'), 'text'
__('<strong>%r: </strong> <a href="%u" title="Download Dotclear %v">%v</a>'), )
'text' ->addHomeOnly()
); ->addContentOnly()
$w->dclatestversionswidget->setting( ->addClass()
'homeonly', ->addOffline();
__('Display on:'), }
0,
'combo',
array(
__('All pages') => 0,
__('Home page only') => 1,
__('Except on home page') => 2
)
);
$w->dclatestversionswidget->setting(
'content_only',
__('Content only'),
0,
'check'
);
$w->dclatestversionswidget->setting(
'class',
__('CSS class:'),
''
);
$w->dclatestversionswidget->setting('offline',__('Offline'),0,'check');
}
public static function publicWidget($w) public static function publicWidget($w)
{ {
global $core; global $core;
$core->blog->settings->addNamespace('dcLatestVersions'); $core->blog->settings->addNamespace('dcLatestVersions');
if ($w->offline) if ($w->offline) {
return; return null;
}
# Nothing to display if (($w->homeonly == 1 && !$core->url->isHome($core->url->type))
if ($w->homeonly == 1 && $core->url->type != 'default' || ($w->homeonly == 2 && $core->url->isHome($core->url->type))
|| $w->homeonly == 2 && $core->url->type == 'default' || $w->text == '') {
|| $w->text == '' return null;
) { }
return null;
}
# Builds to check # Builds to check
$builds = (string) $core->blog->settings->dcLatestVersions->builds; $builds = (string) $core->blog->settings->dcLatestVersions->builds;
$builds = explode(',', $builds); $builds = explode(',', $builds);
if (empty($builds)) { if (empty($builds)) {
return null;
}
return null; $li = [];
} foreach($builds as $build) {
$li = array(); $build = strtolower(trim($build));
foreach($builds as $build) { if (empty($build)) {
continue;
}
$build = strtolower(trim($build)); $updater = new dcUpdate(
if (empty($build)) { DC_UPDATE_URL,
continue; 'dotclear',
} $build,
DC_TPL_CACHE . '/versions'
);
$updater = new dcUpdate( if (false === $updater->check('0')) {
DC_UPDATE_URL, continue;
'dotclear', }
$build,
DC_TPL_CACHE.'/versions'
);
if (false === $updater->check('0')) { $li[] = sprintf('<li>%s</li>', str_replace(
continue; [
} '%r',
'%v',
'%u'
],
[
$build,
$updater->getVersion(),
$updater->getFileURL()
],
$w->text
));
}
$li[] = '<li>'.str_replace( if (empty($li)) {
array( return null;
'%r', }
'%v',
'%u'
),
array(
$build,
$updater->getVersion(),
$updater->getFileURL()
),
$w->text
).'</li>';
}
if (empty($li)) { # Display
return $w->renderDiv(
return null; $w->content_only,
} 'dclatestversionswidget '. $w->class,
'',
# Display ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . sprintf('<ul>%s</ul>', implode('',$li))
$res = );
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : ''). }
'<ul>'.implode('',$li).'</ul>';
return $w->renderDiv($w->content_only,'dclatestversionswidget '.$w->class,'',$res);
}
} }

13
dcstore.xml Normal file
View file

@ -0,0 +1,13 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="dcLatestVersions">
<name>dcLatestVersions</name>
<version>2021.08.27</version>
<author>Jean-Christian Denis, Pierre Van Glabeke</author>
<desc>Show the latest available versions of Dotclear</desc>
<file>https://github.com/JcDenis/dcLatestVersions/releases/download/v2021.08.27/plugin-dcLatestVersions.zip</file>
<da:dcmin>2.19</da:dcmin>
<da:details>http://plugins.dotaddict.org/dc2/details/dcLatestVersions</da:details>
<da:section></da:section>
<da:support>http://forum.dotclear.org/viewforum.php?id=16</da:support>
</module>
</modules>