friendica-github/src/Module/Admin/Themes/Embed.php

89 lines
2.6 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\Core\Renderer;
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 Embed extends BaseAdmin
2019-05-02 04:01:43 +00:00
{
public static function init(array $parameters = [])
2019-05-02 04:01:43 +00:00
{
$theme = Strings::sanitizeFilePathItem($parameters['theme']);
if (is_file("view/theme/$theme/config.php")) {
DI::app()->setCurrentTheme($theme);
2019-05-02 04:01:43 +00:00
}
}
public static function post(array $parameters = [])
2019-05-02 04:01:43 +00:00
{
self::checkAdminAccess();
2019-05-02 04:01:43 +00:00
$theme = Strings::sanitizeFilePathItem($parameters['theme']);
if (is_file("view/theme/$theme/config.php")) {
require_once "view/theme/$theme/config.php";
if (function_exists('theme_admin_post')) {
2019-05-02 04:01:43 +00:00
self::checkFormSecurityTokenRedirectOnError('/admin/themes/' . $theme . '/embed?mode=minimal', 'admin_theme_settings');
theme_admin_post(DI::app());
2019-05-02 04:01:43 +00:00
}
}
2019-05-02 04:01:43 +00:00
if (DI::mode()->isAjax()) {
return;
2019-05-02 04:01:43 +00:00
}
DI::baseUrl()->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
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
$theme = Strings::sanitizeFilePathItem($parameters['theme']);
if (!is_dir("view/theme/$theme")) {
notice(DI::l10n()->t('Unknown theme.'));
return '';
}
2019-05-02 04:01:43 +00:00
$admin_form = '';
if (is_file("view/theme/$theme/config.php")) {
require_once "view/theme/$theme/config.php";
2019-05-02 04:01:43 +00:00
if (function_exists('theme_admin')) {
$admin_form = theme_admin(DI::app());
2019-05-02 04:01:43 +00:00
}
}
// Overrides normal theme style include to strip user param to show embedded theme settings
Renderer::$theme['stylesheet'] = 'view/theme/' . $theme . '/style.pcss';
$t = Renderer::getMarkupTemplate('admin/addons/embed.tpl');
return Renderer::replaceMacros($t, [
'$action' => '/admin/themes/' . $theme . '/embed?mode=minimal',
'$form' => $admin_form,
'$form_security_token' => self::getFormSecurityToken("admin_theme_settings"),
]);
2019-05-02 04:01:43 +00:00
}
}