mirror of
https://github.com/processwire/processwire.git
synced 2025-08-14 18:55:56 +02:00
Updates to make AdminThemeUikit easier to extend with an AdminThemeUikit descending module
This commit is contained in:
@@ -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()
|
||||
@@ -160,11 +162,52 @@ abstract class AdminTheme extends WireData implements Module {
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -6,6 +6,12 @@
|
||||
* The methods in this class may eventually be merged to AdminTheme.php,
|
||||
* 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
|
||||
* @property bool $isLoggedIn
|
||||
@@ -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
|
||||
|
@@ -163,6 +163,7 @@
|
||||
* @property string|null $pagerHeadTags Populated at runtime to contain `<link rel=prev|next />` 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
|
||||
|
@@ -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 = '<p>' . __('The process returned no content.') . '</p>';
|
||||
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);
|
||||
|
@@ -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);
|
||||
@@ -1022,6 +1026,28 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
</script>
|
||||
|
||||
<?php
|
||||
foreach($config->styles as $file) {
|
||||
foreach($styles as $file) {
|
||||
echo "\n\t<link type='text/css' href='$file' rel='stylesheet' />";
|
||||
}
|
||||
if($adminTheme->maxWidth && strpos($layout, 'sidenav') === false) {
|
||||
echo "\n\t<style type='text/css'>.pw-container { max-width: {$adminTheme->maxWidth}px; }</style>";
|
||||
}
|
||||
foreach($config->scripts as $file) {
|
||||
foreach($scripts as $file) {
|
||||
echo "\n\t<script type='text/javascript' src='$file'></script>";
|
||||
}
|
||||
?>
|
||||
|
@@ -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 */ ?>">
|
||||
<head>
|
||||
<?php
|
||||
include($config->paths->adminTemplates . '_head.php');
|
||||
include(__DIR__ . '/_head.php');
|
||||
echo $adminTheme->renderExtraMarkup('head');
|
||||
?>
|
||||
</head>
|
||||
|
@@ -20,7 +20,7 @@ if(!defined("PROCESSWIRE")) die();
|
||||
<a id="offcanvas-nav-close" href='#offcanvas-nav' class='uk-text-muted' onclick='return false;' data-uk-toggle>
|
||||
<i class='fa fa-times uk-float-right uk-margin-small-top'></i>
|
||||
</a>
|
||||
<img class='pw-logo' width='200' style='margin-left:-5px' src='<?php echo $config->urls($adminTheme->className()); ?>uikit/custom/images/logo.png' />
|
||||
<img class='pw-logo' width='200' style='margin-left:-5px' src='<?php echo $adminTheme->url(); ?>uikit/custom/images/logo.png' />
|
||||
</p>
|
||||
<?php include(__DIR__ . '/_search-form.php'); ?>
|
||||
<ul class='pw-sidebar-nav uk-nav uk-nav-parent-icon uk-margin-small-top' data-uk-nav='animation: false; multiple: true;'>
|
||||
|
@@ -25,6 +25,7 @@ if(strpos($mainURL, 'layout=')) {
|
||||
$mainURL .= (strpos($mainURL, '?') ? '&' : '?') . 'layout=sidenav-main';
|
||||
}
|
||||
$mainURL = $sanitizer->entities($mainURL);
|
||||
$themeURL = $adminTheme->url();
|
||||
|
||||
// pane definition iframes
|
||||
$panes = array(
|
||||
@@ -49,7 +50,7 @@ $panes = array(
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<link rel="stylesheet" href="<?php echo $config->urls->adminTemplates; ?>layout/source/stable/layout-default.css">
|
||||
<link rel="stylesheet" href="<?php echo $themeURL; ?>layout/source/stable/layout-default.css">
|
||||
|
||||
<?php require(__DIR__ . '/_head.php'); ?>
|
||||
|
||||
@@ -76,8 +77,8 @@ $panes = array(
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="<?php echo $config->urls->adminTemplates; ?>layout/source/stable/jquery.layout.js"></script>
|
||||
<script src="<?php echo $config->urls->adminTemplates; ?>layout/source/stable/plugins/jquery.layout.state.js"></script>
|
||||
<script src="<?php echo $themeURL; ?>layout/source/stable/jquery.layout.js"></script>
|
||||
<script src="<?php echo $themeURL; ?>layout/source/stable/plugins/jquery.layout.state.js"></script>
|
||||
</head>
|
||||
<body class='pw-layout-sidenav-init'>
|
||||
|
||||
|
@@ -24,7 +24,7 @@ if(!defined("PROCESSWIRE")) die();
|
||||
<html class="pw pw-sidebar-frame" lang="<?php echo $adminTheme->_('en');
|
||||
/* this intentionally on a separate line */ ?>">
|
||||
<head>
|
||||
<?php include($config->paths->adminTemplates . '_head.php'); ?>
|
||||
<?php include(__DIR__ . '/_head.php'); ?>
|
||||
<style type='text/css'>
|
||||
#pw-sidenav-bar .pw-search-form .uk-inline,
|
||||
#pw-sidenav-bar .pw-search-input {
|
||||
|
@@ -17,7 +17,7 @@ if(!isset($content)) $content = '';
|
||||
<html class="pw pw-sidebar-frame" lang="<?php echo $adminTheme->_('en');
|
||||
/* this intentionally on a separate line */ ?>">
|
||||
<head>
|
||||
<?php include($config->paths->adminTemplates . '_head.php'); ?>
|
||||
<?php include(__DIR__ . '/_head.php'); ?>
|
||||
<script>
|
||||
var pageListRefresh = {
|
||||
refreshPage: function(id) {
|
||||
|
@@ -11,5 +11,5 @@ if(!defined("PROCESSWIRE")) die();
|
||||
* This file need not be present in new admin themes, and will eventually be removed from this theme.
|
||||
*
|
||||
*/
|
||||
|
||||
/** @var Config $config */
|
||||
require($config->paths->core . "admin.php");
|
||||
|
@@ -30,17 +30,17 @@ if($adminTheme->isModal) {
|
||||
|
||||
if($layout === 'sidenav-init' || $layout === 'sidenav-tree-init') {
|
||||
// sidenav main loader
|
||||
include($config->paths->adminTemplates . "_sidenav-init.php");
|
||||
include(__DIR__ . "/_sidenav-init.php");
|
||||
|
||||
} else if($layout === 'sidenav-side') {
|
||||
// sidenav sidebar pane
|
||||
$adminTheme->addBodyClass("pw-layout-sidenav-side");
|
||||
include($config->paths->adminTemplates . "_sidenav-side.php");
|
||||
include(__DIR__ . "/_sidenav-side.php");
|
||||
|
||||
} else if($layout === 'sidenav-tree') {
|
||||
// sidenav tree pane
|
||||
$adminTheme->addBodyClass("pw-layout-sidenav-tree");
|
||||
include($config->paths->adminTemplates . "_sidenav-tree.php");
|
||||
include(__DIR__ . "/_sidenav-tree.php");
|
||||
|
||||
} else {
|
||||
// main markup file
|
||||
@@ -50,6 +50,6 @@ if($layout === 'sidenav-init' || $layout === 'sidenav-tree-init') {
|
||||
} else if($layout != 'modal') {
|
||||
$layout = '';
|
||||
}
|
||||
include($config->paths->adminTemplates . "_main.php");
|
||||
include(__DIR__ . "/_main.php");
|
||||
}
|
||||
|
||||
|
@@ -139,7 +139,7 @@ $config->set('SystemNotifications', array(
|
||||
*/
|
||||
|
||||
$classes = InputfieldWrapper::getClasses();
|
||||
$classes['form'] = 'InputfieldFormNoWidths InputfieldFormVertical uk-form-vertical';
|
||||
$classes['form'] = 'InputfieldFormVertical uk-form-vertical' . ($adminTheme->ukGrid ? ' InputfieldFormNoWidths' : '');
|
||||
$classes['list'] = 'Inputfields uk-grid uk-grid-collapse uk-grid-match';
|
||||
$classes['list_clearfix'] = 'uk-clearfix';
|
||||
$classes['item_column_width_first'] = 'InputfieldColumnWidthFirst uk-first-column';
|
||||
|
@@ -437,17 +437,17 @@ var ProcessWireAdminTheme = {
|
||||
var $li = $("<li></li>").addClass('pw-nav-dup').append($a2);
|
||||
$ul.append($li);
|
||||
if(data.add) {
|
||||
var $li = $(
|
||||
var $li2 = $(
|
||||
"<li class='pw-nav-add'>" +
|
||||
"<a href='" + data.url + data.add.url + "'>" +
|
||||
"<i class='fa fa-fw fa-" + data.add.icon + " pw-nav-icon'></i>" +
|
||||
data.add.label + "</a>" +
|
||||
"</li>"
|
||||
);
|
||||
$ul.append($li);
|
||||
$ul.append($li2);
|
||||
}
|
||||
// populate the retrieved items
|
||||
$.each(data.list, function(n) {
|
||||
$.each(data.list, function(i) {
|
||||
if(this.label.indexOf('<span') > -1) {
|
||||
// Uikit beta 34 does not like span elements in the label for some reason
|
||||
this.label = this.label.replace(/<\/?span[^>]*>/g, '');
|
||||
|
File diff suppressed because one or more lines are too long
@@ -32,7 +32,6 @@ class FieldtypeFileConfiguration extends Wire {
|
||||
*
|
||||
* @param Field $field
|
||||
* @param InputfieldWrapper $inputfields
|
||||
*
|
||||
* @return InputfieldWrapper
|
||||
*
|
||||
*/
|
||||
@@ -57,7 +56,7 @@ class FieldtypeFileConfiguration extends Wire {
|
||||
$f = $modules->get('InputfieldTextarea');
|
||||
$f->attr('name', 'extensions');
|
||||
$value = $field->get('extensions');
|
||||
if(!$value) $value = $fieldtype->get('defaultFileExtensions');
|
||||
if(!$value) $value = $this->fieldtype->get('defaultFileExtensions');
|
||||
$f->attr('value', $value);
|
||||
$f->attr('rows', 3);
|
||||
$f->label = $this->_('Allowed file extensions');
|
||||
|
Reference in New Issue
Block a user