]> git.mxchange.org Git - friendica.git/commitdiff
Move admin/themes/{theme} to src/Module
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 26 Apr 2019 02:25:13 +0000 (22:25 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 2 May 2019 13:52:50 +0000 (09:52 -0400)
- Remove now unused templates/admin/addon_detail.tpl
- Remove references to themes admin in mod/admin.php

mod/admin.php
src/App/Router.php
src/Module/Admin/Themes/Details.php [new file with mode: 0644]
view/templates/admin/addon_details.tpl [deleted file]

index 7f2077bead1baf3b96c8d4bca9fc517909fde864..d2bba6f11d78f2d3eb3fcce72d1018170fb71ce6 100644 (file)
@@ -38,23 +38,6 @@ use Friendica\Util\Strings;
 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
  *
@@ -87,30 +70,6 @@ function admin_post(App $a)
                        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;
@@ -216,9 +175,6 @@ function admin_content(App $a)
                        case 'site':
                                $o = admin_page_site($a);
                                break;
-                       case 'themes':
-                               $o = admin_page_themes($a);
-                               break;
                        case 'logs':
                                $o = admin_page_logs($a);
                                break;
@@ -1082,211 +1038,6 @@ function admin_page_dbsync(App $a)
        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
  *
index 649d347bb9e1f572568c5bb109322168c48c1f0d..b78c58bc45eb9b94cded0d883a7188198d309ea9 100644 (file)
@@ -133,6 +133,7 @@ class Router
                        $collector->addRoute(['GET']        , '/queue[/deferred]'       , Module\Admin\Queue::class);
 
                        $collector->addRoute(['GET', 'POST'], '/themes'                 , Module\Admin\Themes\Index::class);
+                       $collector->addRoute(['GET', 'POST'], '/themes/{theme}'         , Module\Admin\Themes\Details::class);
                        $collector->addRoute(['GET', 'POST'], '/themes/{theme}/embed'   , Module\Admin\Themes\Embed::class);
 
                        $collector->addRoute(['GET', 'POST'], '/tos'                    , Module\Admin\Tos::class);
diff --git a/src/Module/Admin/Themes/Details.php b/src/Module/Admin/Themes/Details.php
new file mode 100644 (file)
index 0000000..540083b
--- /dev/null
@@ -0,0 +1,128 @@
+<?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
diff --git a/view/templates/admin/addon_details.tpl b/view/templates/admin/addon_details.tpl
deleted file mode 100644 (file)
index 7479b13..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-
-<div id='adminpage'>
-       <h1>{{$title}} - {{$page}}</h1>
-
-       <p><span class='toggleaddon icon {{$status}}'></span> {{$info.name}} - {{$info.version}} : <a href="{{$baseurl}}/admin/{{$function}}/{{$addon}}/?a=t&amp;t={{$form_security_token}}">{{$action}}</a></p>
-       <p>{{$info.description nofilter}}</p>
-
-       <p class="author">{{$str_author}}
-       {{foreach $info.author as $a name=authors}}
-               {{if $a.link}}<a href="{{$a.link}}">{{$a.name}}</a>{{else}}{{$a.name}}{{/if}}{{if $smarty.foreach.authors.last}}{{else}}, {{/if}}
-       {{/foreach}}
-       </p>
-
-       <p class="maintainer">{{$str_maintainer}}
-       {{foreach $info.maintainer as $a name=maintainers}}
-               {{if $a.link}}<a href="{{$a.link}}">{{$a.name}}</a>{{else}}{{$a.name}}{{/if}}{{if $smarty.foreach.maintainers.last}}{{else}}, {{/if}}
-       {{/foreach}}
-       </p>
-
-       {{if $screenshot}}
-       <a href="{{$screenshot.0}}" class='screenshot'><img src="{{$screenshot.0}}" alt="{{$screenshot.1}}" /></a>
-       {{/if}}
-
-       {{if $admin_form}}
-       <h3>{{$settings}}</h3>
-       <form method="post" action="{{$baseurl}}/admin/{{$function}}/{{$addon}}">
-               {{$admin_form nofilter}}
-       </form>
-       {{/if}}
-
-       {{if $readme}}
-       <h3>Readme</h3>
-       <div id="addon_readme">
-               {{$readme nofilter}}
-       </div>
-       {{/if}}
-</div>