2019-05-02 04:01:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Module\Admin\Themes;
|
|
|
|
|
|
|
|
use Friendica\Core\L10n;
|
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\Module\BaseAdminModule;
|
|
|
|
use Friendica\Util\Strings;
|
|
|
|
|
|
|
|
class Embed extends BaseAdminModule
|
|
|
|
{
|
2019-11-05 21:48:54 +00:00
|
|
|
public static function init(array $parameters = [])
|
2019-05-02 04:01:43 +00:00
|
|
|
{
|
|
|
|
$a = self::getApp();
|
|
|
|
|
|
|
|
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")) {
|
|
|
|
$a->setCurrentTheme($theme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-05 21:48:54 +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 = self::getApp();
|
|
|
|
|
|
|
|
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")) {
|
|
|
|
self::checkFormSecurityTokenRedirectOnError('/admin/themes/' . $theme . '/embed?mode=minimal', 'admin_theme_settings');
|
|
|
|
|
|
|
|
require_once "view/theme/$theme/config.php";
|
|
|
|
|
|
|
|
if (function_exists('theme_admin_post')) {
|
|
|
|
theme_admin_post($a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
info(L10n::t('Theme settings updated.'));
|
|
|
|
|
|
|
|
if ($a->isAjax()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$a->internalRedirect('admin/themes/' . $theme . '/embed?mode=minimal');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-05 21:48:54 +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 = self::getApp();
|
|
|
|
|
|
|
|
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(L10n::t('Unknown theme.'));
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$admin_form = '';
|
|
|
|
if (is_file("view/theme/$theme/config.php")) {
|
|
|
|
require_once "view/theme/$theme/config.php";
|
|
|
|
|
|
|
|
if (function_exists('theme_admin')) {
|
|
|
|
$admin_form = theme_admin($a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-18 03:25:22 +00:00
|
|
|
// Overrides normal theme style include to strip user param to show embedded theme settings
|
|
|
|
Renderer::$theme['stylesheet'] = 'view/theme/' . $theme . '/style.pcss';
|
|
|
|
|
2019-05-02 04:01:43 +00:00
|
|
|
$t = Renderer::getMarkupTemplate('admin/addons/embed.tpl');
|
|
|
|
return Renderer::replaceMacros($t, [
|
|
|
|
'$action' => '/admin/themes/' . $theme . '/embed?mode=minimal',
|
|
|
|
'$form' => $admin_form,
|
|
|
|
'$form_security_token' => parent::getFormSecurityToken("admin_theme_settings"),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|