]> git.mxchange.org Git - friendica.git/commitdiff
Add admin/themes/{theme}/embed module
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 26 Apr 2019 02:20:20 +0000 (22:20 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 2 May 2019 13:52:49 +0000 (09:52 -0400)
- This module allows editing the site settings for a theme with a different user theme

src/App/Router.php
src/Module/Admin/Themes/Embed.php [new file with mode: 0644]
view/templates/admin/addons/embed.tpl [new file with mode: 0644]

index 0fbb78b8bc7c217dc733eef75b36e32d32b23b69..649d347bb9e1f572568c5bb109322168c48c1f0d 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}/embed'   , Module\Admin\Themes\Embed::class);
 
                        $collector->addRoute(['GET', 'POST'], '/tos'                    , Module\Admin\Tos::class);
 
diff --git a/src/Module/Admin/Themes/Embed.php b/src/Module/Admin/Themes/Embed.php
new file mode 100644 (file)
index 0000000..0a309e2
--- /dev/null
@@ -0,0 +1,92 @@
+<?php\r
+\r
+namespace Friendica\Module\Admin\Themes;\r
+\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 Embed extends BaseAdminModule\r
+{\r
+       public static function init()\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
+                               $a->setCurrentTheme($theme);\r
+                       }\r
+               }\r
+       }\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
+                               self::checkFormSecurityTokenRedirectOnError('/admin/themes/' . $theme . '/embed?mode=minimal', 'admin_theme_settings');\r
+\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 . '/embed?mode=minimal');\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('Unknown theme.'));\r
+                               return '';\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 = theme_admin($a);\r
+                               }\r
+                       }\r
+\r
+                       $t = Renderer::getMarkupTemplate('admin/addons/embed.tpl');\r
+                       return Renderer::replaceMacros($t, [\r
+                               '$action' => '/admin/themes/' . $theme . '/embed?mode=minimal',\r
+                               '$form' => $admin_form,\r
+                               '$form_security_token' => parent::getFormSecurityToken("admin_theme_settings"),\r
+                       ]);\r
+               }\r
+\r
+               return '';\r
+       }\r
+}
\ No newline at end of file
diff --git a/view/templates/admin/addons/embed.tpl b/view/templates/admin/addons/embed.tpl
new file mode 100644 (file)
index 0000000..71fb12d
--- /dev/null
@@ -0,0 +1,5 @@
+
+<form method="post" action="{{$action}}">
+    <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
+       {{$form nofilter}}
+</form>