use Friendica\Util\Temporal;
use Psr\Log\LogLevel;
-/**
- * Sets the current theme for theme settings pages.
- *
- * This needs to be done before the post() or content() methods are called.
- *
- * @param App $a
- */
-function admin_init(App $a)
-{
- if ($a->argc > 2 && $a->argv[1] == 'themes') {
- $theme = $a->argv[2];
- if (is_file("view/theme/$theme/config.php")) {
- $a->setCurrentTheme($theme);
- }
- }
-}
-
/**
* @brief Process send data from the admin panels subpages
*
case 'site':
admin_page_site_post($a);
break;
- case 'themes':
- if ($a->argc < 2) {
- if ($a->isAjax()) {
- return;
- }
- $a->internalRedirect('admin/');
- return;
- }
-
- $theme = $a->argv[2];
- 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(L10n::t('Theme settings updated.'));
- if ($a->isAjax()) {
- return;
- }
- $return_path = 'admin/themes/' . $theme . (!empty($_GET['mode']) ? '?mode=' . $_GET['mode'] : '');
- break;
case 'logs':
admin_page_logs_post($a);
break;
case 'site':
$o = admin_page_site($a);
break;
- case 'themes':
- $o = admin_page_themes($a);
- break;
case 'logs':
$o = admin_page_logs($a);
break;
return $o;
}
-/**
- * @param array $themes
- * @param string $th
- * @param int $result
- */
-function toggle_theme(&$themes, $th, &$result)
-{
- $count = count($themes);
- for ($x = 0; $x < $count; $x++) {
- if ($themes[$x]['name'] === $th) {
- if ($themes[$x]['allowed']) {
- $themes[$x]['allowed'] = 0;
- $result = 0;
- } else {
- $themes[$x]['allowed'] = 1;
- $result = 1;
- }
- }
- }
-}
-
-/**
- * @param array $themes
- * @param string $th
- * @return int
- */
-function theme_status($themes, $th)
-{
- $count = count($themes);
- for ($x = 0; $x < $count; $x++) {
- if ($themes[$x]['name'] === $th) {
- if ($themes[$x]['allowed']) {
- return 1;
- } else {
- return 0;
- }
- }
- }
- return 0;
-}
-
-/**
- * @param array $themes
- * @return string
- */
-function rebuild_theme_table($themes)
-{
- $o = '';
- if (count($themes)) {
- foreach ($themes as $th) {
- if ($th['allowed']) {
- if (strlen($o)) {
- $o .= ',';
- }
- $o .= $th['name'];
- }
- }
- }
- return $o;
-}
-
-/**
- * @brief Themes admin page
- *
- * This function generates the admin panel page to control the themes available
- * on the friendica node. If the name of a theme is given as parameter a page
- * with the details for the theme is shown. Otherwise a list of available
- * themes is generated.
- *
- * The template used for displaying the list of themes and the details of the
- * themes are the same as used for the addons.
- *
- * The returned string contains the HTML code of the admin panel page.
- *
- * @param App $a
- * @return string
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
-function admin_page_themes(App $a)
-{
- $allowed_themes_str = Config::get('system', 'allowed_themes');
- $allowed_themes_raw = explode(',', $allowed_themes_str);
- $allowed_themes = [];
- if (count($allowed_themes_raw)) {
- foreach ($allowed_themes_raw as $x) {
- if (strlen(trim($x))) {
- $allowed_themes[] = trim($x);
- }
- }
- }
-
- $themes = [];
- $files = glob('view/theme/*');
- if (is_array($files)) {
- foreach ($files as $file) {
- $f = basename($file);
-
- // Is there a style file?
- $theme_files = glob('view/theme/' . $f . '/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($f, $allowed_themes));
-
- if ($is_allowed || $is_supported || Config::get("system", "show_unsupported_themes")) {
- $themes[] = ['name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed];
- }
- }
- }
-
- if (!count($themes)) {
- notice(L10n::t('No themes found.'));
- return '';
- }
-
- /*
- * Single theme
- */
-
- if ($a->argc == 3) {
- $theme = $a->argv[2];
- if (!is_dir("view/theme/$theme")) {
- notice(L10n::t("Item not found."));
- return '';
- }
-
- if (!empty($_GET['a']) && $_GET['a'] == "t") {
- BaseModule::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't');
-
- // Toggle theme status
-
- toggle_theme($themes, $theme, $result);
- $s = rebuild_theme_table($themes);
- if ($result) {
- Theme::install($theme);
- info(sprintf('Theme %s enabled.', $theme));
- } else {
- Theme::uninstall($theme);
- info(sprintf('Theme %s disabled.', $theme));
- }
-
- Config::set('system', 'allowed_themes', $s);
- $a->internalRedirect('admin/themes');
- return ''; // NOTREACHED
- }
-
- // display theme details
- if (theme_status($themes, $theme)) {
- $status = "on";
- $action = L10n::t("Disable");
- } else {
- $status = "off";
- $action = L10n::t("Enable");
- }
-
- $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 = theme_admin($a);
- }
- }
-
- $screenshot = [Theme::getScreenshot($theme), L10n::t('Screenshot')];
- if (!stristr($screenshot[0], $theme)) {
- $screenshot = null;
- }
-
- $t = Renderer::getMarkupTemplate('admin/addon_details.tpl');
- return Renderer::replaceMacros($t, [
- '$title' => L10n::t('Administration'),
- '$page' => L10n::t('Themes'),
- '$toggle' => L10n::t('Toggle'),
- '$settings' => L10n::t('Settings'),
- '$baseurl' => System::baseUrl(true),
- '$addon' => $theme . (!empty($_GET['mode']) ? '?mode=' . $_GET['mode'] : ''),
- '$status' => $status,
- '$action' => $action,
- '$info' => Theme::getInfo($theme),
- '$function' => 'themes',
- '$admin_form' => $admin_form,
- '$str_author' => L10n::t('Author: '),
- '$str_maintainer' => L10n::t('Maintainer: '),
- '$screenshot' => $screenshot,
- '$readme' => $readme,
-
- '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"),
- ]);
- }
-}
-
/**
* @brief Prosesses data send by Logs admin page
*
--- /dev/null
+<?php\r
+\r
+namespace Friendica\Module\Admin\Themes;\r
+\r
+use Friendica\Content\Text\Markdown;\r
+use Friendica\Core\Config;\r
+use Friendica\Core\L10n;\r
+use Friendica\Core\Renderer;\r
+use Friendica\Core\System;\r
+use Friendica\Core\Theme;\r
+use Friendica\Module\BaseAdminModule;\r
+use Friendica\Util\Strings;\r
+\r
+class Details extends BaseAdminModule\r
+{\r
+ public static function post()\r
+ {\r
+ parent::post();\r
+\r
+ $a = self::getApp();\r
+\r
+ if ($a->argc > 2) {\r
+ // @TODO: Replace with parameter from router\r
+ $theme = $a->argv[2];\r
+ $theme = Strings::sanitizeFilePathItem($theme);\r
+ if (is_file("view/theme/$theme/config.php")) {\r
+ require_once "view/theme/$theme/config.php";\r
+\r
+ if (function_exists('theme_admin_post')) {\r
+ theme_admin_post($a);\r
+ }\r
+ }\r
+\r
+ info(L10n::t('Theme settings updated.'));\r
+\r
+ if ($a->isAjax()) {\r
+ return;\r
+ }\r
+\r
+ $a->internalRedirect('admin/themes/' . $theme);\r
+ }\r
+ }\r
+\r
+ public static function content()\r
+ {\r
+ parent::content();\r
+\r
+ $a = self::getApp();\r
+\r
+ if ($a->argc > 2) {\r
+ // @TODO: Replace with parameter from router\r
+ $theme = $a->argv[2];\r
+ $theme = Strings::sanitizeFilePathItem($theme);\r
+ if (!is_dir("view/theme/$theme")) {\r
+ notice(L10n::t("Item not found."));\r
+ return '';\r
+ }\r
+\r
+ $isEnabled = in_array($theme, Theme::getAllowedList());\r
+ if ($isEnabled) {\r
+ $status = "on";\r
+ $action = L10n::t("Disable");\r
+ } else {\r
+ $status = "off";\r
+ $action = L10n::t("Enable");\r
+ }\r
+\r
+ if (!empty($_GET['action']) && $_GET['action'] == 'toggle') {\r
+ parent::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't');\r
+\r
+ if ($isEnabled) {\r
+ Theme::uninstall($theme);\r
+ info(L10n::t('Theme %s disabled.', $theme));\r
+ } elseif (Theme::install($theme)) {\r
+ info(L10n::t('Theme %s successfully enabled.', $theme));\r
+ } else {\r
+ info(L10n::t('Theme %s failed to install.', $theme));\r
+ }\r
+\r
+ $a->internalRedirect('admin/themes/' . $theme);\r
+ }\r
+\r
+ $readme = null;\r
+ if (is_file("view/theme/$theme/README.md")) {\r
+ $readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false);\r
+ } elseif (is_file("view/theme/$theme/README")) {\r
+ $readme = "<pre>" . file_get_contents("view/theme/$theme/README") . "</pre>";\r
+ }\r
+\r
+ $admin_form = '';\r
+ if (is_file("view/theme/$theme/config.php")) {\r
+ require_once "view/theme/$theme/config.php";\r
+\r
+ if (function_exists('theme_admin')) {\r
+ $admin_form = '<iframe onload="resizeIframe(this);" src="/admin/themes/' . $theme . '/embed?mode=minimal" width="100%" height="600px" frameborder="no"></iframe>';\r
+ }\r
+ }\r
+\r
+ $screenshot = [Theme::getScreenshot($theme), L10n::t('Screenshot')];\r
+ if (!stristr($screenshot[0], $theme)) {\r
+ $screenshot = null;\r
+ }\r
+\r
+ $t = Renderer::getMarkupTemplate('admin/addons/details.tpl');\r
+ return Renderer::replaceMacros($t, [\r
+ '$title' => L10n::t('Administration'),\r
+ '$page' => L10n::t('Themes'),\r
+ '$toggle' => L10n::t('Toggle'),\r
+ '$settings' => L10n::t('Settings'),\r
+ '$baseurl' => System::baseUrl(true),\r
+ '$addon' => $theme,\r
+ '$status' => $status,\r
+ '$action' => $action,\r
+ '$info' => Theme::getInfo($theme),\r
+ '$function' => 'themes',\r
+ '$admin_form' => $admin_form,\r
+ '$str_author' => L10n::t('Author: '),\r
+ '$str_maintainer' => L10n::t('Maintainer: '),\r
+ '$screenshot' => $screenshot,\r
+ '$readme' => $readme,\r
+\r
+ '$form_security_token' => parent::getFormSecurityToken("admin_themes"),\r
+ ]);\r
+ }\r
+\r
+ $a->internalRedirect('admin/themes');\r
+ }\r
+}
\ No newline at end of file