friendica/src/Module/Admin/Themes/Details.php

146 lines
4.2 KiB
PHP
Raw Normal View History

2019-05-02 04:01:43 +00:00
<?php
2020-02-09 14:45:36 +00:00
/**
* @copyright Copyright (C) 2020, Friendica
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
2019-05-02 04:01:43 +00:00
namespace Friendica\Module\Admin\Themes;
use Friendica\Content\Text\Markdown;
use Friendica\Core\Renderer;
use Friendica\Core\Theme;
use Friendica\DI;
2020-01-23 04:14:14 +00:00
use Friendica\Module\BaseAdmin;
2019-05-02 04:01:43 +00:00
use Friendica\Util\Strings;
2020-01-23 04:14:14 +00:00
class Details extends BaseAdmin
2019-05-02 04:01:43 +00:00
{
public static function post(array $parameters = [])
2019-05-02 04:01:43 +00:00
{
2019-11-05 20:22:54 +00:00
parent::post($parameters);
2019-05-02 04:01:43 +00:00
$a = DI::app();
2019-05-02 04:01:43 +00:00
if ($a->argc > 2) {
// @TODO: Replace with parameter from router
$theme = $a->argv[2];
$theme = Strings::sanitizeFilePathItem($theme);
if (is_file("view/theme/$theme/config.php")) {
require_once "view/theme/$theme/config.php";
if (function_exists('theme_admin_post')) {
theme_admin_post($a);
}
}
info(DI::l10n()->t('Theme settings updated.'));
2019-05-02 04:01:43 +00:00
if (DI::mode()->isAjax()) {
2019-05-02 04:01:43 +00:00
return;
}
DI::baseUrl()->redirect('admin/themes/' . $theme);
2019-05-02 04:01:43 +00:00
}
}
public static function content(array $parameters = [])
2019-05-02 04:01:43 +00:00
{
2019-11-05 20:22:54 +00:00
parent::content($parameters);
2019-05-02 04:01:43 +00:00
$a = DI::app();
2019-05-02 04:01:43 +00:00
if ($a->argc > 2) {
// @TODO: Replace with parameter from router
$theme = $a->argv[2];
$theme = Strings::sanitizeFilePathItem($theme);
if (!is_dir("view/theme/$theme")) {
notice(DI::l10n()->t("Item not found."));
2019-05-02 04:01:43 +00:00
return '';
}
$isEnabled = in_array($theme, Theme::getAllowedList());
if ($isEnabled) {
$status = "on";
$action = DI::l10n()->t("Disable");
2019-05-02 04:01:43 +00:00
} else {
$status = "off";
$action = DI::l10n()->t("Enable");
2019-05-02 04:01:43 +00:00
}
if (!empty($_GET['action']) && $_GET['action'] == 'toggle') {
parent::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't');
if ($isEnabled) {
Theme::uninstall($theme);
info(DI::l10n()->t('Theme %s disabled.', $theme));
2019-05-02 04:01:43 +00:00
} elseif (Theme::install($theme)) {
info(DI::l10n()->t('Theme %s successfully enabled.', $theme));
2019-05-02 04:01:43 +00:00
} else {
info(DI::l10n()->t('Theme %s failed to install.', $theme));
2019-05-02 04:01:43 +00:00
}
DI::baseUrl()->redirect('admin/themes/' . $theme);
2019-05-02 04:01:43 +00:00
}
$readme = null;
if (is_file("view/theme/$theme/README.md")) {
$readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false);
} elseif (is_file("view/theme/$theme/README")) {
$readme = "<pre>" . file_get_contents("view/theme/$theme/README") . "</pre>";
}
$admin_form = '';
if (is_file("view/theme/$theme/config.php")) {
require_once "view/theme/$theme/config.php";
if (function_exists('theme_admin')) {
$admin_form = '<iframe onload="resizeIframe(this);" src="/admin/themes/' . $theme . '/embed?mode=minimal" width="100%" height="600px" frameborder="no"></iframe>';
}
}
$screenshot = [Theme::getScreenshot($theme), DI::l10n()->t('Screenshot')];
2019-05-02 04:01:43 +00:00
if (!stristr($screenshot[0], $theme)) {
$screenshot = null;
}
$t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
return Renderer::replaceMacros($t, [
'$title' => DI::l10n()->t('Administration'),
'$page' => DI::l10n()->t('Themes'),
'$toggle' => DI::l10n()->t('Toggle'),
'$settings' => DI::l10n()->t('Settings'),
'$baseurl' => DI::baseUrl()->get(true),
2019-05-02 04:01:43 +00:00
'$addon' => $theme,
'$status' => $status,
'$action' => $action,
'$info' => Theme::getInfo($theme),
'$function' => 'themes',
'$admin_form' => $admin_form,
'$str_author' => DI::l10n()->t('Author: '),
'$str_maintainer' => DI::l10n()->t('Maintainer: '),
2019-05-02 04:01:43 +00:00
'$screenshot' => $screenshot,
'$readme' => $readme,
'$form_security_token' => parent::getFormSecurityToken("admin_themes"),
]);
}
DI::baseUrl()->redirect('admin/themes');
2019-05-02 04:01:43 +00:00
}
}