Merge pull request #314 from getgrav/feature/integrate-with-admin-pro

Feature/integrate with admin pro
This commit is contained in:
Andy Miller
2015-12-01 11:02:37 -07:00
15 changed files with 117 additions and 60 deletions

View File

@@ -64,10 +64,14 @@ class AdminPlugin extends Plugin
*/
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => [['login', 100000], ['onPluginsInitialized', 1000]],
'onShutdown' => ['onShutdown', 1000]
];
if (!Grav::instance()['config']->get('plugins.admin-pro.enabled')) {
return [
'onPluginsInitialized' => [['login', 100000], ['onPluginsInitialized', 1000]],
'onShutdown' => ['onShutdown', 1000]
];
} else {
return [];
}
}
/**
@@ -76,19 +80,11 @@ class AdminPlugin extends Plugin
*/
public function login()
{
// Check for Pro version is enabled
if ($this->config->get('plugins.admin-pro.enabled')) {
$this->active = false;
return;
}
$route = $this->config->get('plugins.admin.route');
if (!$route) {
return;
}
$this->grav['debugger']->addMessage("Admin Basic");
$this->base = '/' . trim($route, '/');
$this->uri = $this->grav['uri'];
@@ -106,6 +102,7 @@ class AdminPlugin extends Plugin
{
// Only activate admin if we're inside the admin path.
if ($this->active) {
$this->grav['debugger']->addMessage("Admin Basic");
$this->initializeAdmin();
// Disable Asset pipelining
@@ -124,6 +121,13 @@ class AdminPlugin extends Plugin
$this->popularity = new Popularity();
}
protected function initializeController($task, $post) {
require_once __DIR__ . '/classes/controller.php';
$controller = new AdminController($this->grav, $this->template, $task, $this->route, $post);
$controller->execute();
$controller->redirect();
}
/**
* Sets longer path to the home page allowing us to have list of pages when we enter to pages section.
*/
@@ -174,10 +178,7 @@ class AdminPlugin extends Plugin
// Handle tasks.
$this->admin->task = $task = !empty($post['task']) ? $post['task'] : $this->uri->param('task');
if ($task) {
require_once __DIR__ . '/classes/controller.php';
$controller = new AdminController($this->grav, $this->template, $task, $this->route, $post);
$controller->execute();
$controller->redirect();
$this->initializeController($task, $post);
} elseif ($this->template == 'logs' && $this->route) {
// Display RAW error message.
echo $this->admin->logEntry();
@@ -420,7 +421,11 @@ class AdminPlugin extends Plugin
'UPDATE_AVAILABLE',
'UPDATES_AVAILABLE',
'FULLY_UPDATED',
'DAYS'];
'DAYS',
'PAGE_MODES',
'PAGE_TYPES',
'ACCESS_LEVELS'
];
foreach($strings as $string) {
$translations .= 'translations.PLUGIN_ADMIN.' . $string .' = "' . $this->admin->translate('PLUGIN_ADMIN.' . $string) . '"; ' . PHP_EOL;;

View File

@@ -406,7 +406,7 @@ class Admin
}
/**
* Get All template types
* Get all template types
*
* @return array
*/
@@ -416,7 +416,7 @@ class Admin
}
/**
* Get All modular template types
* Get all modular template types
*
* @return array
*/
@@ -425,6 +425,20 @@ class Admin
return Pages::modularTypes();
}
/**
* Get all access levels
*
* @return array
*/
public function accessLevels()
{
if (method_exists($this->grav['pages'], 'accessLevels')) {
return $this->grav['pages']->accessLevels();
} else {
return [];
}
}
/**
* Get all plugins.
*
@@ -573,6 +587,16 @@ class Admin
];
}
/**
* Returns the list of available backups
*
* @return array Array containing the latest backups
*/
public function backups()
{
return [];
}
/**
* Returns the page creating it if it does not exist.
*

View File

@@ -9,6 +9,7 @@ use Grav\Common\Grav;
use Grav\Common\Uri;
use Grav\Common\Data;
use Grav\Common\Page;
use Grav\Common\Page\Pages;
use Grav\Common\Page\Collection;
use Grav\Common\User\User;
use Grav\Common\Utils;
@@ -487,8 +488,25 @@ class AdminController
// Filter by page type
if (count($flags)) {
$types = $flags;
$collection = $collection->ofOneOfTheseTypes($types);
$types = [];
$pageTypes = Pages::pageTypes();
foreach ($pageTypes as $pageType) {
if (($pageType = array_search($pageType, $flags)) !== false) {
$types[] = $pageType;
unset($flags[$pageType]);
}
}
if (count($types)) {
$collection = $collection->ofOneOfTheseTypes($types);
}
}
// Filter by page type
if (count($flags)) {
$accessLevels = $flags;
$collection = $collection->ofOneOfTheseAccessLevels($accessLevels);
}
}
@@ -496,8 +514,6 @@ class AdminController
foreach ($collection as $page) {
foreach ($queries as $query) {
$query = trim($query);
// $page->content();
if (stripos($page->getRawContent(), $query) === false && stripos($page->title(), $query) === false) {
$collection->remove($page);
}
@@ -798,7 +814,7 @@ class AdminController
/**
* Handles installing plugins and themes
*
* @return bool True is the action was performed
* @return bool True if the action was performed
*/
public function taskInstall()
{
@@ -827,7 +843,7 @@ class AdminController
/**
* Handles updating Grav
*
* @return bool True is the action was performed
* @return bool True if the action was performed
*/
public function taskUpdategrav()
{
@@ -851,7 +867,7 @@ class AdminController
/**
* Handles updating plugins and themes
*
* @return bool True is the action was performed
* @return bool True if the action was performed
*/
public function taskUpdate()
{
@@ -909,7 +925,7 @@ class AdminController
/**
* Handles uninstalling plugins and themes
*
* @return bool True is the action was performed
* @return bool True if the action was performed
*/
public function taskUninstall()
{
@@ -1046,6 +1062,11 @@ class AdminController
return true;
}
if ($this->view == 'groups') {
$this->setRedirect("{$this->view}/{$this->post['groupname']}");
return true;
}
if ($this->view != 'pages') {
return false;
}

View File

@@ -447,6 +447,13 @@ en:
INLINE_TYPES_HELP: "A list of file types that should be displayed inline rather than downloaded"
APPEND_URL_EXT: "Append URL extension"
APPEND_URL_EXT_HELP: "Will add a custom extension to the Page's URL. Note, this will mean Grav will look for `<template>.<extension>.twig` template"
PAGE_MODES: "Page Modes"
PAGE_TYPES: "Page Types"
ACCESS_LEVELS: "Access Levels"
GROUPS: "Groups"
GROUPS_HELP: "List of groups the user is part of"
ADMIN_ACCESS: "Admin Access"
SITE_ACCESS: "Site Access"
fr:
PLUGIN_ADMIN:
@@ -1725,6 +1732,9 @@ it:
UPDATE_AVAILABLE: "Aggiornamento disponibile"
METADATA_KEY: "Key (e.g. 'Keywords')"
METADATA_VALUE: "Value (e.g. 'Blog, Grav')"
PLUGIN_STATUS: "Stato plugin"
INCLUDE_DEFAULT_LANG: "Include la lingua predefinita"
INCLUDE_DEFAULT_LANG_HELP: "Include l'identificatore della lingua in tutti gli URL nella lingua predefinita e.g. `/en/blog/my-post`"
USERNAME_HELP: "Il nome utente deve essere compreso tra 3 e 16 caratteri, composti da lettere minuscole, numeri, trattini o il carattere di sottolineatura. Lettere maiuscole, spazi e caratteri speciali non sono consentiti"
FULLY_UPDATED: "Tutto aggiornato"
SAVE_LOCATION: "Salvato in"
@@ -1746,9 +1756,6 @@ it:
OVERRIDE_LOCALE_HELP: "Sovrascrivi l'impostazione locale in PHP basato sulla tua lingua corrente"
REDIRECT: "Pagina di reindirizzamento"
REDIRECT_HELP: "Inserisci la route alla pagina oppure un URL esterno per questa pagina. Esempio: `/some/route` or `http://somesite.com`"
PLUGIN_STATUS: "Stato plugin"
INCLUDE_DEFAULT_LANG: "Includi la lingua predefinita"
INCLUDE_DEFAULT_LANG_HELP: "Inserisce la lingua predefinita in tutti gli URL appartenenti alla lingua predefinita. Es. `/it/blog/il-mio-post`"
ALLOW_URL_TAXONOMY_FILTERS: "Abilita Filtri di Tassonomia via URL"
ALLOW_URL_TAXONOMY_FILTERS_HELP: "Abilita la possibilità di filtrare le pagine attraverso URL di tipo `/taxonomy:value`."
REDIRECT_DEFAULT_CODE: "Codice redirect predefinito"
@@ -1763,6 +1770,10 @@ it:
INLINE_TYPES_HELP: "Lista di tipi di file che devono essere visualizzati anzichè scaricati"
APPEND_URL_EXT: "Appendi l'estensione all'URL"
APPEND_URL_EXT_HELP: "Aggiunge una estensione customizzata all'URL della pagina. Nota, questo significa che Grav cercherà il template `<template>.<extension>.twig`"
GROUPS: "Gruppi"
GROUPS_HELP: "Lista dei gruppi a cui appartiene l'utente"
ADMIN_ACCESS: "Accesso Amministrazione"
SITE_ACCESS: "Accesso Sito"
de:
PLUGIN_ADMIN:

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -322,7 +322,8 @@
if (!ajax) {
var form = $('<form>').attr({ method: method, action: action });
for (var name in values) { if (values.hasOwnProperty(name)) {
for (var name in values) {
if (values.hasOwnProperty(name)) {
$('<input>').attr({ type: 'hidden', name: name, value: values[name] }).appendTo(form);
}
}

View File

@@ -9,6 +9,7 @@ $(function(){
// selectize
var pageFilter = $('input.page-filter'),
pageTypes = pageFilter.data('template-types'),
accessLevels = pageFilter.data('template-access-levels'),
options = [
{flag: 'Modular', key: 'Modular', cat: 'mode'},
{flag: 'Visible', key: 'Visible', cat: 'mode'},
@@ -25,6 +26,10 @@ $(function(){
options.push({flag: name, key: key, cat: 'type'});
})
jQuery.each(accessLevels, function(key, name){
options.push({flag: name, key: name, cat: 'access'});
})
pageFilter.selectize({
maxItems: null,
valueField: 'key',
@@ -32,13 +37,14 @@ $(function(){
searchField: ['flag', 'key'],
options: options,
optgroups: [
{id: 'mode', name: 'Page Modes'},
{id: 'type', name: 'Page Types'},
{id: 'mode', name: translations.PLUGIN_ADMIN.PAGE_MODES},
{id: 'type', name: translations.PLUGIN_ADMIN.PAGE_TYPES},
{id: 'access', name: translations.PLUGIN_ADMIN.ACCESS_LEVELS},
],
optgroupField: 'cat',
optgroupLabelField: 'name',
optgroupValueField: 'id',
optgroupOrder: ['mode', 'type'],
optgroupOrder: ['mode', 'type', 'access'],
plugins: ['optgroup_columns']
});
}

View File

@@ -46,7 +46,7 @@ $update-height: 3rem;
}
}
#admin-user-details {
#admin-user-details, .admin-user-details {
padding: $sidebar-padding;
border-bottom: 1px solid $darker-accent-bg;
overflow: hidden;

View File

@@ -45,7 +45,7 @@
<input data-grav-array-type="key" type="text" value="{{ key }}" placeholder="{{ field.placeholder_key|e|tu }}" />
{% endif %}
<input data-grav-array-type="value" type="text" name="{{ (field.name|fieldName) ~ '[' ~ key ~ ']' }}" value="{{ text|join(', ')|e }}" placeholder="{{ field.placeholder_value|e|tu }}" />
<input data-grav-array-type="value" type="text" name="{{ (field.name|fieldName) ~ '[' ~ key ~ ']' }}" value={% if text == 'true' %}true{% elseif text == 'false' %}false{% else %}"{{ text|join(', ')|e }}"{% endif %} placeholder="{{ field.placeholder_value|e|tu }}" />
<span data-grav-array-action="rem" class="fa fa-minus"></span>
<span data-grav-array-action="add" class="fa fa-plus"></span>

View File

@@ -255,7 +255,7 @@
{% else %}
<form id="page-filtering">
<div class="page-filters">
<input type="text" data-template-types="{{ admin.types|merge(admin.modularTypes)|json_encode|e('html_attr') }}" placeholder="{{ "PLUGIN_ADMIN.ADD_FILTERS"|tu }}" class="page-filter" name="page-filter" />
<input type="text" data-template-types="{{ admin.types|merge(admin.modularTypes)|json_encode|e('html_attr') }}" data-template-access-levels="{{ admin.accessLevels|json_encode|e('html_attr') }}" placeholder="{{ "PLUGIN_ADMIN.ADD_FILTERS"|tu }}" class="page-filter" name="page-filter" />
</div>
<div class="page-search">
<input type="text" placeholder="{{ "PLUGIN_ADMIN.SEARCH_PAGES"|tu }}" name="page-search" />

View File

@@ -5,6 +5,12 @@
param_sep: '{{ config.system.param_sep }}',
enable_auto_updates_check: '{{ config.plugins.admin.enable_auto_updates_check }}',
admin_timeout: '{{ config.plugins.admin.session.timeout ?: 1800 }}',
admin_nonce: '{{ admin.getNonce }}'
admin_nonce: '{{ admin.getNonce }}',
pro_enabled: '{{ config.plugins["admin-pro"].enabled }}'
};
window.GravAdmin.uri_params = {};
{% for param, value in grav.uri.params(null, true) %}
window.GravAdmin.uri_params.{{param}} = "{{value|replace({'\\': '/'})}}";
{% endfor %}
</script>

View File

@@ -1,19 +1,8 @@
{% if user.exists %}
<div class="user-details">
<img src="https://www.gravatar.com/avatar/{{ user.email|md5 }}?s=128" />
<p class="gravatar">{{ "PLUGIN_ADMIN.AVATAR_BY"|tu }} <a href="http://gravatar.com" target="_blank">gravatar.com</a></p>
<h2>{{ user.fullname }}</h2>
{% if user.title %}<h5>{{ user.title }}</h5>{% endif %}
</div>
{% else %}
<h1>{{ "PLUGIN_ADMIN.CREATE_NEW_USER"|tu }}</h1>
{% endif %}
{% include 'partials/blueprints.html.twig' with { data: user, blueprints: user.blueprints } %}
{% if user.exists and admin.user.username != user.username %}
<div class="button-bar danger">
<span class="danger-zone"></span>
<a class="button" href="#"><i class="fa fa-fw fa-warning"></i>{{ "PLUGIN_ADMIN.REMOVE_USER"|tu }}</a>
</div>
{% endif %}

View File

@@ -1,6 +0,0 @@
<div class="users card-row grid fixed-blocks pure-g">
{% for user in admin.users %}
<div class="theme card-item pure-u-1-3">
</div>
{% endfor %}
</div>

View File

@@ -14,10 +14,10 @@
<div class="button-bar">
<a class="button" href="#modal" data-remodal-target="modal"><i class="fa fa-plus"></i> {{ "PLUGIN_ADMIN.ADD_ACCOUNT"|tu }}</a>
</div>
<h1><i class="fa fa-fw fa-child"></i> Users</h1>
<h1><i class="fa fa-fw fa-users"></i> {{ "PLUGIN_ADMIN.USERS"|tu }}</h1>
{% else %}
<div class="button-bar">
<a class="button" href="{{ base_url }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a>
<a class="button" href="{{ base_url }}/users"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a>
<button class="button" type="submit" name="task" value="save" form="blueprints"><i class="fa fa-check"></i> {{ "PLUGIN_ADMIN.SAVE"|tu }}</button>
</div>
<h1><i class="fa fa-fw fa-user"></i> {{ "PLUGIN_ADMIN.USER"|tu }}: {{ user.username|e }}</h1>
@@ -29,7 +29,7 @@
{% include 'partials/messages.html.twig' %}
{% if not admin.route %}
{% include 'partials/users-list.html.twig' %}
{% include 'partials/users-list.html.twig' %}
<div class="remodal" data-remodal-id="modal" data-remodal-options="hashTracking: false">
{% include 'partials/blueprints-new.html.twig' with { blueprints: admin.blueprints('user/account_new') } %}