Skip to content

Commit

Permalink
Preparing Release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
noelboss committed Jul 11, 2018
1 parent b3f5343 commit 38d7b65
Show file tree
Hide file tree
Showing 31 changed files with 375 additions and 3,493 deletions.
6 changes: 3 additions & 3 deletions AdminThemeUikit.info.json → AdminThemeBoss.info.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"title": "Admin Theme Boss",
"summary": "A light and clear theme based on Uikit 3",
"summary": "A light and clear theme based on Uikit 3, extending AdminThemeUikit",
"href": "https://github.com/noelboss/AdminThemeBoss",
"version": "0.1.4",
"version": "0.2.0",
"author": "Noël Bossart",
"autoload": "template=admin",
"icon": "diamond",
"requires": "ProcessWire>=3.0.94"
"requires": "ProcessWire>=3.0.94,AdminThemeUikit"
}
184 changes: 184 additions & 0 deletions AdminThemeBoss.module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php

/**
* © ICF Church – <[email protected]>
*
* This source file is subject to the license file that is bundled
* with this source code in the file LICENSE.
*
* File created/changed: 2018-07-11T09:55:17+02:00
*/

namespace ProcessWire;

/**
* AdminThemeBoss.
*
* @property bool $isSuperuser Is current user a superuser?
* @property bool $isEditor Does current user have page-edit permission?
* @property bool $isLoggedIn Is current user logged in?
* @property bool $useOffset Use offset/margin for all Inputfields?
* @property array $noBorderTypes Inputfield class names that should always use the noBorder option (when 100% width).
* @property array $cardTypes Inputfield class names that should always use the card option.
* @property array $offsetTypes Inputfield class names that should always use the offset option.
* @property string $logoURL URL to custom logo, relative to PW installation root.
* @property string $variant URL to custom CSS file, relative to PW installation root.
* @property string $layout Layout type (blank=default, sidenav=multi-pane, sidenav-tree=left-tree, sidenav-tree-alt=right-tree)
* @property int $logoAction Logo click action (0=admin root page list, 1=offcanvas nav)
* @property string $userLabel Text containing user {vars} to use for user label in masthead (default="{Name}")
* @property int $maxWidth Maximum layout width in pixels, or 0 for no max (default=1600).
* @property bool|int $groupNotices Whether or not notices should be grouped by type
*/
class AdminThemeBoss extends WireData implements Module, ConfigurableModule
{
/**
* Development mode, to be used when developing this module’s code.
*/
const dev = false;

/**
* Default logo image file (relative to this dir).
*/
const logo = 'uikit/custom/images/pw-mark.png';

private $adminThemeUikit;

/*******************************************************************************************
* MARKUP RENDERING METHODS
*
*/

/**
* Render a list of breadcrumbs (list items), excluding the containing <ul>.
*
* @return string
*/
public function renderBreadcrumbs(HookEvent $event)
{
if (!$event->return) {
return;
}

$process = $this->wire('page')->process;
if ($process == 'ProcessPageList') {
return '';
}
$breadcrumbs = $this->wire('breadcrumbs');
$out = '';

// don't show breadcrumbs if only one of them (subjective)
if (count($breadcrumbs) < 2 && $process != 'ProcessPageEdit') {
return '';
}

if (strpos($this->layout, 'sidenav') === false) {
$out = '<li>'.$event->object->renderQuickTreeLink().'</li>';
}

foreach ($breadcrumbs as $breadcrumb) {
$title = $breadcrumb->get('titleMarkup');
if (!$title) {
$title = $this->wire('sanitizer')->entities1($this->_($breadcrumb->title));
}

$edit = '';
$icon = $event->object->renderIcon('pencil');
if (strpos($breadcrumb->url, 'open=') > 0) {
$pageid = explode('open=', $breadcrumb->url);
$pageid = end($pageid);
if (wire('pages')->get($pageid)->editable()) {
$edit = "&nbsp;&nbsp;<a href='../edit/?id=$pageid'>$icon</a>";
}
} elseif (strpos($breadcrumb->url, '../') !== false && wire('process')) {
// make sure we're editing a page and not a user
if (method_exists(wire('process'), 'getPage')) {
$pageid = wire('process')->getPage()->parent->id;

if (wire('pages')->get($pageid)->editable()) {
$edit = "&nbsp;&nbsp;<a href='../edit/?id=$pageid'>$icon</a>";
}
// modify open
$breadcrumb->url = "../?open=$pageid";
} else {
bd(wire('process'));
}
}
$out .= "<li><a href='$breadcrumb->url'>$title</a>$edit</li>";
}

if ($out) {
$out = "<ul class='uk-breadcrumb'>$out</ul>";
}

$event->return = $out;
}

/**
* Initialize and attach hooks.
*/
public function init()
{
if (!$this->get('enablemodule')) {
return;
}

if ($this->get('allusers') && $this->user->admin_theme !== 'AdminThemeUikit') {
$this->user->setAndSave('admin_theme', 'AdminThemeUikit');
}

if ($this->get('extendedbreadcrumb')) {
$this->addHookAfter('AdminThemeUikit::renderBreadcrumbs', $this, 'renderBreadcrumbs');
}

$this->addHookAfter('Page::render', $this, 'replaceUikitCSS');

$this->adminThemeUikit = $this->wire('modules')->get('AdminThemeUikit');
}

/**
* Get the primary Uikit CSS file to use.
*
* @return string
*/
public function replaceUikitCSS(HookEvent $event)
{
$page = $event->object;

if ($page->template->name !== 'admin') {
return;
}

$moduleInfo = $this->wire('modules')->getModuleInfo($this);

$themecss = $this->adminThemeUikit->getUikitCSS();

$config = $this->wire('config');
$variant = $this->get('variant');

$version = $moduleInfo['version'];
$url = $config->urls->httpSiteModules.basename(__DIR__);

switch ($variant) {
case 'pw':
case 'black':
case 'vibrant':
$variant = $url.'/uikit/dist/css/uikit.'.$variant.'.min.css';
break;

default:
$variant = $url.'/uikit/dist/css/uikit.pw.min.css';
break;
}

// replace CSS and Logo
$event->return = str_replace($themecss, $variant, $event->return);

if (!$this->get('useuikitlogo')) {
$themelogo = $this->adminThemeUikit->getLogoURL();
$logoURL = $config->urls($this->className()).self::logo;
$event->return = str_replace($themelogo, $logoURL, $event->return);
}

return true;
}
}
106 changes: 106 additions & 0 deletions AdminThemeBossConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

/**
* © ICF Church – <[email protected]>
*
* This source file is subject to the license file that is bundled
* with this source code in the file LICENSE.
*
* File created/changed: 2018-07-11T09:56:38+02:00
*/

namespace ProcessWire;

if (!defined('PROCESSWIRE')) {
die();
}

/**
* Implementation for Uikit admin theme getConfigInputfields method.
*
* @param AdminTheme|AdminThemeBoss $adminTheme
* @param InputfieldWrapper $inputfields
*/
class AdminThemeBossConfig extends ModuleConfig
{
public function __construct()
{
$this->add([
[
'type' => 'fieldset',
'name' => 'theme-options',
'label' => $this->_('Theme Options'),
'icon' => 'paint-brush',
'children' => [
[
'name' => 'variant',
'type' => 'radios',
'icon' => 'adjust',
'label' => $this->_('Color'),
//'description' => $this->_('If "No" is selected, then upgrades will only be checked manually when you click to Setup > Upgrades.'),
//'notes' => $this->_('Automatic upgrade check requires ProcessWire 2.5.20 or newer.'),
//'optionColumns' => 1,
'value' => $this->get('variant'),
'options' => [
'pw' => $this->_('ProcessWire Blue'),
'vibrant' => $this->_('Vibrant Blue'),
'black' => $this->_('Black'),
],
],
[
'name' => 'extendedbreadcrumb',
'type' => 'checkbox',
'icon' => 'link',
'label' => $this->_('Extended Breadcrumb'),
'description' => $this->_('If set, the default breadcrumb will be extended with edit links.'),
'value' => $this->get('extendedbreadcrumb'),
],
],
],
[
'type' => 'fieldset',
'name' => 'advanced-options',
'label' => $this->_('Advanced Options'),
'icon' => 'cog',
'collapsed' => Inputfield::collapsedYes,
'children' => [
[
'name' => 'enablemodule',
'type' => 'checkbox',
'icon' => 'check',
'label' => $this->_('Enable Module'),
'description' => $this->_('Enable this theme. You can untoggle this option to disable the theme without uninstalling this module.'),
'value' => $this->get('enablemodule'),
],
[
'name' => 'allusers',
'type' => 'checkbox',
'icon' => 'lock',
'label' => $this->_('Enable For All Users'),
'description' => $this->_('If enabled, AdminThemeUikit will be set as theme for all users.'),
'value' => $this->get('allusers'),
],
[
'name' => 'useuikitlogo',
'type' => 'checkbox',
'icon' => 'reply',
'label' => $this->_('Use AdminThemeUikit Logo'),
'description' => $this->_('Instead of a adark logo, use the one specified in the AdminThemeUikit settings.'),
'value' => $this->get('useuikitlogo'),
],
],
],
]);
}

public function getDefaults()
{
return [
'variant' => 'pw',
'extendedbreadcrumb' => true,
'enablemodule' => true,
'allusers' => true,
'useuikitlogo' => false,
];
}
}
Loading

0 comments on commit 38d7b65

Please sign in to comment.