2019-05-02 00:01:43 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Module\Admin\Themes;
|
|
|
|
|
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\Core\Theme;
|
2019-12-15 22:34:11 +01:00
|
|
|
use Friendica\DI;
|
2019-05-02 00:01:43 -04:00
|
|
|
use Friendica\Module\BaseAdminModule;
|
|
|
|
use Friendica\Util\Strings;
|
|
|
|
|
|
|
|
class Index extends BaseAdminModule
|
|
|
|
{
|
2019-11-05 21:48:54 +00:00
|
|
|
public static function content(array $parameters = [])
|
2019-05-02 00:01:43 -04:00
|
|
|
{
|
2019-11-05 20:22:54 +00:00
|
|
|
parent::content($parameters);
|
2019-05-02 00:01:43 -04:00
|
|
|
|
|
|
|
$allowed_themes = Theme::getAllowedList();
|
|
|
|
|
|
|
|
// reload active themes
|
|
|
|
if (!empty($_GET['action'])) {
|
2019-12-16 01:05:15 +01:00
|
|
|
parent::checkFormSecurityTokenRedirectOnError(DI::baseUrl()->get() . '/admin/themes', 'admin_themes', 't');
|
2019-05-02 00:01:43 -04:00
|
|
|
|
|
|
|
switch ($_GET['action']) {
|
|
|
|
case 'reload':
|
2019-08-17 20:00:11 +02:00
|
|
|
$allowed_themes = array_unique($allowed_themes);
|
2019-05-02 00:01:43 -04:00
|
|
|
foreach ($allowed_themes as $theme) {
|
2019-08-17 19:55:14 +02:00
|
|
|
Theme::uninstall($theme);
|
|
|
|
Theme::install($theme);
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
2019-08-17 20:00:11 +02:00
|
|
|
Theme::setAllowedList($allowed_themes);
|
2019-05-02 00:01:43 -04:00
|
|
|
|
|
|
|
info('Themes reloaded');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'toggle' :
|
2019-10-15 09:20:32 -04:00
|
|
|
$theme = $_GET['addon'] ?? '';
|
2019-05-02 00:01:43 -04:00
|
|
|
if ($theme) {
|
|
|
|
$theme = Strings::sanitizeFilePathItem($theme);
|
|
|
|
if (!is_dir("view/theme/$theme")) {
|
2020-01-18 20:52:34 +01:00
|
|
|
notice(DI::l10n()->t('Item not found.'));
|
2019-05-02 00:01:43 -04:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_array($theme, Theme::getAllowedList())) {
|
|
|
|
Theme::uninstall($theme);
|
2020-01-18 20:52:34 +01:00
|
|
|
info(DI::l10n()->t('Theme %s disabled.', $theme));
|
2019-05-02 00:01:43 -04:00
|
|
|
} elseif (Theme::install($theme)) {
|
2020-01-18 20:52:34 +01:00
|
|
|
info(DI::l10n()->t('Theme %s successfully enabled.', $theme));
|
2019-05-02 00:01:43 -04:00
|
|
|
} else {
|
2020-01-18 20:52:34 +01:00
|
|
|
info(DI::l10n()->t('Theme %s failed to install.', $theme));
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-16 00:28:31 +01:00
|
|
|
DI::baseUrl()->redirect('admin/themes');
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$themes = [];
|
|
|
|
$files = glob('view/theme/*');
|
|
|
|
if (is_array($files)) {
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$theme = basename($file);
|
|
|
|
|
|
|
|
// Is there a style file?
|
|
|
|
$theme_files = glob('view/theme/' . $theme . '/style.*');
|
|
|
|
|
|
|
|
// If not then quit
|
|
|
|
if (count($theme_files) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$is_experimental = intval(file_exists($file . '/experimental'));
|
|
|
|
$is_supported = 1 - (intval(file_exists($file . '/unsupported')));
|
|
|
|
$is_allowed = intval(in_array($theme, $allowed_themes));
|
|
|
|
|
2020-01-19 21:21:13 +01:00
|
|
|
if ($is_allowed || $is_supported || DI::config()->get('system', 'show_unsupported_themes')) {
|
2019-05-02 00:01:43 -04:00
|
|
|
$themes[] = ['name' => $theme, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$addons = [];
|
|
|
|
foreach ($themes as $theme) {
|
|
|
|
$addons[] = [$theme['name'], (($theme['allowed']) ? 'on' : 'off'), Theme::getInfo($theme['name'])];
|
|
|
|
}
|
|
|
|
|
|
|
|
$t = Renderer::getMarkupTemplate('admin/addons/index.tpl');
|
|
|
|
return Renderer::replaceMacros($t, [
|
2020-01-18 20:52:34 +01:00
|
|
|
'$title' => DI::l10n()->t('Administration'),
|
|
|
|
'$page' => DI::l10n()->t('Themes'),
|
|
|
|
'$submit' => DI::l10n()->t('Save Settings'),
|
|
|
|
'$reload' => DI::l10n()->t('Reload active themes'),
|
2019-12-16 01:05:15 +01:00
|
|
|
'$baseurl' => DI::baseUrl()->get(true),
|
2019-05-02 00:01:43 -04:00
|
|
|
'$function' => 'themes',
|
|
|
|
'$addons' => $addons,
|
|
|
|
'$pcount' => count($themes),
|
2020-01-18 20:52:34 +01:00
|
|
|
'$noplugshint' => DI::l10n()->t('No themes found on the system. They should be placed in %1$s', '<code>/view/themes</code>'),
|
|
|
|
'$experimental' => DI::l10n()->t('[Experimental]'),
|
|
|
|
'$unsupported' => DI::l10n()->t('[Unsupported]'),
|
2019-05-02 00:01:43 -04:00
|
|
|
'$form_security_token' => parent::getFormSecurityToken('admin_themes'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|