diff --git a/wire/core/AdminTheme.php b/wire/core/AdminTheme.php index 004b829e..27acef24 100644 --- a/wire/core/AdminTheme.php +++ b/wire/core/AdminTheme.php @@ -10,10 +10,12 @@ * This file is licensed under the MIT license. * https://processwire.com/about/license/mit/ * - * ProcessWire 3.x, Copyright 2018 by Ryan Cramer + * ProcessWire 3.x, Copyright 2021 by Ryan Cramer * https://processwire.com * * @property int|string $version Current admin theme version + * @property string $url URL to admin theme + * @property string $path Disk path to admin theme * * @method void install() * @method void uninstall() @@ -156,14 +158,55 @@ abstract class AdminTheme extends WireData implements Module { if($session->get('hidpi')) $this->addBodyClass('hidpi-device'); if($session->get('touch')) $this->addBodyClass('touch-device'); - + $this->addBodyClass($this->className()); } + /** + * Get property + * + * @param string $key + * @return int|mixed|null|string + * + */ public function get($key) { - if($key == 'version') return $this->version; + if($key === 'version') return $this->version; + if($key === 'url') return $this->url(); + if($key === 'path') return $this->path(); return parent::get($key); } + + /** + * Get URL to this admin theme + * + * @return string + * @since 3.0.171 + * + */ + public function url() { + return $this->wire()->config->urls($this->className()); + } + + /** + * Get disk path to this admin theme + * + * @return string + * @since 3.0.171 + * + */ + public function path() { + $config = $this->wire()->config; + $path = $config->paths($this->className()); + if(empty($path)) { + $class = $this->className(); + $path = $config->paths->modules . "AdminTheme/$class/"; + if(!is_dir($path)) { + $path = $config->paths->siteModules . "$class/"; + if(!is_dir($path)) $path = __DIR__; + } + } + return $path; + } /** * Get predefined translated label by key for labels shared among admin themes @@ -189,7 +232,8 @@ abstract class AdminTheme extends WireData implements Module { * */ public function isCurrent() { - return $this->wire('adminTheme') === $this; + $adminTheme = $this->wire()->adminTheme; + return $adminTheme && $adminTheme->className() === $this->className(); } /** diff --git a/wire/core/AdminThemeFramework.php b/wire/core/AdminThemeFramework.php index 027bab78..7006ccbc 100644 --- a/wire/core/AdminThemeFramework.php +++ b/wire/core/AdminThemeFramework.php @@ -4,7 +4,13 @@ * AdminTheme Framework * * The methods in this class may eventually be merged to AdminTheme.php, - * but are isolated to this class during development. + * but are isolated to this class during development. + * + * This file is licensed under the MIT license. + * https://processwire.com/about/license/mit/ + * + * ProcessWire 3.x, Copyright 2021 by Ryan Cramer + * https://processwire.com * * @property bool $isSuperuser * @property bool $isEditor @@ -65,6 +71,8 @@ abstract class AdminThemeFramework extends AdminTheme { public function wired() { $this->sanitizer = $this->wire('sanitizer'); + $user = $this->wire()->user; + $this->isLoggedIn = $user && $user->isLoggedin(); parent::wired(); } @@ -95,13 +103,12 @@ abstract class AdminThemeFramework extends AdminTheme { public function init() { $user = $this->wire('user'); - if(!$user->isLoggedin() && $this->useAsLogin) $this->setCurrent(); + if(!$this->isLoggedIn && $this->useAsLogin) $this->setCurrent(); parent::init(); // if this is not the current admin theme, exit now so no hooks are attached if(!$this->isCurrent()) return; - $this->isLoggedIn = $user->isLoggedin(); $this->isSuperuser = $this->isLoggedIn && $user->isSuperuser(); $this->isEditor = $this->isLoggedIn && ($this->isSuperuser || $user->hasPermission('page-edit')); $this->includeInitFile(); @@ -119,7 +126,7 @@ abstract class AdminThemeFramework extends AdminTheme { */ public function includeInitFile() { $config = $this->wire('config'); - $initFile = $config->paths->adminTemplates . 'init.php'; + $initFile = $this->path() . 'init.php'; if(file_exists($initFile)) { if(strpos($initFile, $config->paths->site) === 0) { // admin themes in /site/modules/ may be compiled diff --git a/wire/core/Config.php b/wire/core/Config.php index f401f0df..88ddc51a 100644 --- a/wire/core/Config.php +++ b/wire/core/Config.php @@ -163,6 +163,7 @@ * @property string|null $pagerHeadTags Populated at runtime to contain `` tags for document head, after pagination has been rendered by MarkupPagerNav module. #pw-group-runtime * @property array $statusFiles File inclusions for ProcessWire’s runtime statuses/states. #pw-group-system @since 3.0.142 * @property int $status Value of current system status/state corresponding to ProcessWire::status* constants. #pw-internal + * @property null|bool $disableUnknownMethodException Disable the “Method does not exist or is not callable in this context” exception. (default=null) #pw-internal * * @property int $rootPageID Page ID of homepage (usually 1) #pw-group-system-IDs * @property int $adminRootPageID Page ID of admin root page #pw-group-system-IDs diff --git a/wire/core/admin.php b/wire/core/admin.php index 7253bd37..350b4582 100644 --- a/wire/core/admin.php +++ b/wire/core/admin.php @@ -6,7 +6,7 @@ * This file is designed for inclusion by /site/templates/admin.php template and all the variables * it references are from your template namespace. * - * Copyright 2018 by Ryan Cramer + * Copyright 2021 by Ryan Cramer * * @var Config $config * @var User $user @@ -18,6 +18,7 @@ * @var Sanitizer $sanitizer * @var Session $session * @var Notices $notices + * @var AdminTheme $adminTheme * * */ @@ -99,6 +100,12 @@ function _checkForMaxInputVars(WireInput $input) { } } +// fallback theme if one not already present +if(empty($adminTheme)) { + $adminTheme = $modules->get($config->defaultAdminTheme ? $config->defaultAdminTheme : 'AdminThemeUikit'); + if(empty($adminTheme)) $adminTheme = $modules->get('AdminThemeUikit'); + if($adminTheme) $wire->wire('adminTheme', $adminTheme); +} // notify superuser if there is an http host error if($user->isSuperuser()) _checkForHttpHostError($config); @@ -214,7 +221,11 @@ if($controller && $controller->isAjax()) { echo $content; } else { if(!strlen($content)) $content = '

' . __('The process returned no content.') . '

'; - $adminThemeFile = $config->paths->adminTemplates . 'default.php'; + if($adminTheme) { + $adminThemeFile = $adminTheme->path() . 'default.php'; + } else { + $adminThemeFile = $config->paths->adminTemplates . 'default.php'; + } if(strpos($adminThemeFile, $config->paths->site) === 0) { // @todo determine if compilation needed $adminThemeFile = $wire->files->compile($adminThemeFile); diff --git a/wire/modules/AdminTheme/AdminThemeUikit/AdminThemeUikit.module b/wire/modules/AdminTheme/AdminThemeUikit/AdminThemeUikit.module index bbaa4dcf..d121a3c5 100644 --- a/wire/modules/AdminTheme/AdminThemeUikit/AdminThemeUikit.module +++ b/wire/modules/AdminTheme/AdminThemeUikit/AdminThemeUikit.module @@ -153,6 +153,10 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl $this->addClass('body', 'AdminThemeUikitNoGrid'); } + if($this->className() !== 'AdminThemeUikit') { + $this->addBodyClass('AdminThemeUikit'); + } + $session->removeFor('Page', 'appendEditUrl'); /** @var JqueryUI $jqueryUI */ $jqueryUI = $modules->get('JqueryUI'); @@ -990,7 +994,7 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl if(empty($logoURL) || $options['getNative'] || strpos($logoURL, '//') !== false) { $native = true; - $logoURL = $config->urls($this->className()) . self::logo; + $logoURL = $this->url() . self::logo; } else { $logoURL = $config->urls->root . ltrim($logoURL, '/'); $logoURL = $sanitizer->entities($logoURL); @@ -1021,6 +1025,28 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl public function getLogoURL() { return $this->getLogo(array('getURL' => true)); } + + /** + * Get URL to this admin theme + * + * @return string + * @since 3.0.171 + * + */ + public function url() { + return $this->wire()->config->urls->modules . 'AdminTheme/AdminThemeUikit/'; + } + + /** + * Get disk path to this admin theme + * + * @return string + * @since 3.0.171 + * + */ + public function path() { + return __DIR__ . '/'; + } /** * Get the primary Uikit CSS file to use @@ -1037,9 +1063,9 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl if(strpos($cssURL, '//') === false) $cssURL = $config->urls->root . ltrim($cssURL, '/'); return $this->wire('sanitizer')->entities($cssURL); } else if(self::dev && strpos(__FILE__, '/wire/modules/') === false) { - return $config->urls->adminTemplates . 'uikit/custom/pw.css?v=' . $version; + return $this->url() . 'uikit/custom/pw.css?v=' . $version; } else { - return $config->urls->adminTemplates . 'uikit/dist/css/uikit.pw.min.css?v=' . $version; + return $this->url() . 'uikit/dist/css/uikit.pw.min.css?v=' . $version; } } diff --git a/wire/modules/AdminTheme/AdminThemeUikit/_head.php b/wire/modules/AdminTheme/AdminThemeUikit/_head.php index 02a06d0c..444100ac 100644 --- a/wire/modules/AdminTheme/AdminThemeUikit/_head.php +++ b/wire/modules/AdminTheme/AdminThemeUikit/_head.php @@ -15,17 +15,21 @@ if(!defined("PROCESSWIRE")) die(); /** @var string $layout */ $version = $adminTheme->version . 'e'; +$rootUrl = $config->urls->root; +$themeUrl = $adminTheme->url(); +$styles = $config->styles; +$scripts = $config->scripts; -$config->styles->prepend($config->urls->root . "wire/templates-admin/styles/AdminTheme.css?v=$version"); -$config->styles->prepend($adminTheme->getUikitCSS()); -$config->styles->append($config->urls->root . "wire/templates-admin/styles/font-awesome/css/font-awesome.min.css?v=$version"); +$styles->prepend($rootUrl . "wire/templates-admin/styles/AdminTheme.css?v=$version"); +$styles->prepend($adminTheme->getUikitCSS()); +$styles->append($rootUrl . "wire/templates-admin/styles/font-awesome/css/font-awesome.min.css?v=$version"); $ext = $config->debug ? "js" : "min.js"; -$config->scripts->append($config->urls->root . "wire/templates-admin/scripts/inputfields.$ext?v=$version"); -$config->scripts->append($config->urls->root . "wire/templates-admin/scripts/main.$ext?v=$version"); -$config->scripts->append($config->urls->adminTemplates . "uikit/dist/js/uikit.min.js?v=$version"); -$config->scripts->append($config->urls->adminTemplates . "uikit/dist/js/uikit-icons.min.js?v=$version"); -$config->scripts->append($config->urls->adminTemplates . "scripts/main.js?v=$version"); +$scripts->append($rootUrl . "wire/templates-admin/scripts/inputfields.$ext?v=$version"); +$scripts->append($rootUrl . "wire/templates-admin/scripts/main.$ext?v=$version"); +$scripts->append($themeUrl . "uikit/dist/js/uikit.min.js?v=$version"); +$scripts->append($themeUrl . "uikit/dist/js/uikit-icons.min.js?v=$version"); +$scripts->append($themeUrl . "scripts/main.js?v=$version"); ?> @@ -42,13 +46,13 @@ $config->scripts->append($config->urls->adminTemplates . "scripts/main.js?v=$ver styles as $file) { + foreach($styles as $file) { echo "\n\t"; } if($adminTheme->maxWidth && strpos($layout, 'sidenav') === false) { echo "\n\t"; } - foreach($config->scripts as $file) { + foreach($scripts as $file) { echo "\n\t"; } ?> diff --git a/wire/modules/AdminTheme/AdminThemeUikit/_main.php b/wire/modules/AdminTheme/AdminThemeUikit/_main.php index 89e81fb4..89dc7fab 100644 --- a/wire/modules/AdminTheme/AdminThemeUikit/_main.php +++ b/wire/modules/AdminTheme/AdminThemeUikit/_main.php @@ -13,7 +13,7 @@ /** @var Modules $modules */ /** @var Notices $notices */ /** @var Page $page */ -/** @var Process $process */ +/** @var Process $proc;ess */ /** @var Sanitizer $sanitizer */ /** @var WireInput $input */ /** @var Paths $urls */ @@ -29,7 +29,7 @@ if(!isset($content)) $content = ''; /* this intentionally on a separate line */ ?>"> paths->adminTemplates . '_head.php'); + include(__DIR__ . '/_head.php'); echo $adminTheme->renderExtraMarkup('head'); ?> diff --git a/wire/modules/AdminTheme/AdminThemeUikit/_offcanvas.php b/wire/modules/AdminTheme/AdminThemeUikit/_offcanvas.php index c802bd13..06f7a50b 100644 --- a/wire/modules/AdminTheme/AdminThemeUikit/_offcanvas.php +++ b/wire/modules/AdminTheme/AdminThemeUikit/_offcanvas.php @@ -20,7 +20,7 @@ if(!defined("PROCESSWIRE")) die(); - +