dcLatestVersions/_widgets.php

125 lines
3.3 KiB
PHP
Raw Normal View History

2015-04-22 15:07:20 +00:00
<?php
2022-11-16 22:03:38 +00:00
2015-04-22 15:07:20 +00:00
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of dcLatestVersions, a plugin for Dotclear 2.
2022-11-16 22:03:38 +00:00
#
2021-08-27 15:53:07 +00:00
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
2022-11-16 22:03:38 +00:00
#
2015-04-22 15:07:20 +00:00
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) {
2021-08-27 15:53:07 +00:00
return null;
2015-04-22 15:07:20 +00:00
}
2022-11-16 22:03:38 +00:00
dcCore::app()->blog->settings->addNamespace('dcLatestVersions');
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)
{
2022-11-16 22:03:38 +00:00
dcCore::app()->blog->settings->addNamespace('dcLatestVersions');
2021-08-27 15:53:07 +00:00
if ($w->offline) {
return null;
}
2022-11-16 22:03:38 +00:00
if (($w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type))
|| ($w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type))
2021-08-27 15:53:07 +00:00
|| $w->text == '') {
return null;
}
# Builds to check
2022-11-16 22:03:38 +00:00
$builds = (string) dcCore::app()->blog->settings->dcLatestVersions->builds;
2021-08-27 15:53:07 +00:00
$builds = explode(',', $builds);
if (empty($builds)) {
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
}