dcLatestVersions/_admin.php

129 lines
3.6 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_CONTEXT_ADMIN')) {
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
require __DIR__ . '/_widgets.php';
2015-04-22 15:07:20 +00:00
# Dashboard item and user preference
2022-11-16 22:03:38 +00:00
dcCore::app()->addBehavior(
'adminDashboardItemsV2',
2021-08-27 15:53:07 +00:00
['dcLatestVersionsAdmin', 'adminDashboardItems']
2015-04-22 15:07:20 +00:00
);
2022-11-16 22:03:38 +00:00
dcCore::app()->addBehavior(
'adminDashboardOptionsFormV2',
2021-08-27 15:53:07 +00:00
['dcLatestVersionsAdmin', 'adminDashboardOptionsForm']
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
'adminAfterDashboardOptionsUpdate',
['dcLatestVersionsAdmin', 'adminAfterDashboardOptionsUpdate']
2015-04-22 15:07:20 +00:00
);
/**
* @ingroup DC_PLUGIN_DCLATESTVERSIONS
* @brief Display latest versions of Dotclear - admin methods.
* @since 2.6
*/
class dcLatestVersionsAdmin
{
2022-11-16 22:03:38 +00:00
public static function adminDashboardItems($__dashboard_items)
2021-08-27 15:53:07 +00:00
{
2022-11-16 22:03:38 +00:00
if (!dcCore::app()->auth->user_prefs->dashboard->get('dcLatestVersionsItems')) {
2021-08-27 15:53:07 +00:00
return null;
}
2022-11-16 22:03:38 +00:00
$builds = explode(',', (string) dcCore::app()->blog->settings->dcLatestVersions->builds);
2021-08-27 15:53:07 +00:00
if (empty($builds)) {
return null;
}
$text = __('<li><a href="%u" title="Download Dotclear %v">%r</a> : %v</li>');
2022-11-16 22:03:38 +00:00
$li = [];
2021-08-27 15:53:07 +00:00
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[] = 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
],
$text
);
}
if (empty($li)) {
return null;
}
2022-11-16 22:03:38 +00:00
2021-08-27 15:53:07 +00:00
# Display
2022-11-16 22:03:38 +00:00
$__dashboard_items[0][] = '<div class="box small" id="udclatestversionsitems">' .
2021-08-27 15:53:07 +00:00
'<h3>' . html::escapeHTML(__("Dotclear's latest versions")) . '</h3>' .
'<ul>' . implode('', $li) . '</ul>' .
'</div>';
}
2022-11-16 22:03:38 +00:00
public static function adminDashboardOptionsForm()
2021-08-27 15:53:07 +00:00
{
2022-11-16 22:03:38 +00:00
if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('dcLatestVersionsItems')) {
dcCore::app()->auth->user_prefs->dashboard->put(
2021-08-27 15:53:07 +00:00
'dcLatestVersionsItems',
false,
'boolean'
);
}
2022-11-16 22:03:38 +00:00
$pref = dcCore::app()->auth->user_prefs->dashboard->get('dcLatestVersionsItems');
2021-08-27 15:53:07 +00:00
2022-11-16 22:03:38 +00:00
echo
2021-08-27 15:53:07 +00:00
'<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)
{
2022-11-16 22:03:38 +00:00
dcCore::app()->auth->user_prefs->dashboard->put(
2021-08-27 15:53:07 +00:00
'dcLatestVersionsItems',
!empty($_POST['dcLatestVersionsItems']),
'boolean'
);
}
2022-11-16 22:03:38 +00:00
}