dcLatestVersions/_widgets.php

118 lines
3 KiB
PHP
Raw Normal View History

2015-04-22 15:07:20 +00:00
<?php
2022-11-20 17:33:02 +00:00
/**
* @brief dcLatestVersions, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
2022-11-20 17:33:02 +00:00
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2015-04-22 15:07:20 +00:00
if (!defined('DC_RC_PATH')) {
2021-08-27 15:53:07 +00:00
return null;
2015-04-22 15:07:20 +00:00
}
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
2015-04-22 15:07:20 +00:00
2022-11-16 22:03:38 +00:00
dcCore::app()->addBehavior(
2021-08-27 15:53:07 +00:00
'initWidgets',
['dcLatestVersionsWidget', 'adminWidget']
2015-04-22 15:07:20 +00:00
);
/**
* @ingroup DC_PLUGIN_DCLATESTVERSIONS
* @brief Display latest versions of Dotclear - widget methods.
* @since 2.6
*/
class dcLatestVersionsWidget
{
2021-08-27 15:53:07 +00:00
public static function adminWidget($w)
{
$w
->create(
'dclatestversionswidget',
__("Dotclear's latest versions"),
['dcLatestVersionsWidget','publicWidget'],
null,
2022-11-16 22:03:38 +00:00
__('Show the latest available versions of Dotclear')
2021-08-27 15:53:07 +00:00
)
->addTitle(
__("Dotclear's latest versions")
)
->setting(
'text',
__('Text (%r = release, %v = version, %u = url):'),
__('<strong>%r: </strong> <a href="%u" title="Download Dotclear %v">%v</a>'),
'text'
)
->addHomeOnly()
->addContentOnly()
->addClass()
->addOffline();
}
public static function publicWidget($w)
{
if ($w->offline) {
return null;
}
2022-12-08 21:54:16 +00:00
if (!$w->checkHomeOnly(dcCore::app()->url->type) || $w->text == '') {
2021-08-27 15:53:07 +00:00
return null;
}
# Builds to check
$builds = explode(',', (string) dcCore::app()->blog->settings->get(basename(__DIR__))->get('builds'));
if (empty($builds[0])) {
2021-08-27 15:53:07 +00:00
return null;
}
$li = [];
2022-11-16 22:03:38 +00:00
foreach ($builds as $build) {
2021-08-27 15:53:07 +00:00
$build = strtolower(trim($build));
if (empty($build)) {
continue;
}
$updater = new dcUpdate(
DC_UPDATE_URL,
'dotclear',
$build,
DC_TPL_CACHE . '/versions'
);
if (false === $updater->check('0')) {
continue;
}
$li[] = sprintf('<li>%s</li>', str_replace(
[
'%r',
'%v',
2022-11-16 22:03:38 +00:00
'%u',
2021-08-27 15:53:07 +00:00
],
[
$build,
$updater->getVersion(),
2022-11-16 22:03:38 +00:00
$updater->getFileURL(),
2021-08-27 15:53:07 +00:00
],
$w->text
));
}
if (empty($li)) {
return null;
}
# Display
return $w->renderDiv(
2022-11-16 22:03:38 +00:00
$w->content_only,
'dclatestversionswidget ' . $w->class,
'',
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . sprintf('<ul>%s</ul>', implode('', $li))
2021-08-27 15:53:07 +00:00
);
}
2022-11-16 22:03:38 +00:00
}