diff --git a/admin.php b/admin.php index 428ca014..aebfdbf2 100644 --- a/admin.php +++ b/admin.php @@ -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;; diff --git a/classes/admin.php b/classes/admin.php index 3bbe45e4..7bbc062b 100644 --- a/classes/admin.php +++ b/classes/admin.php @@ -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. * diff --git a/classes/controller.php b/classes/controller.php index 01e8c500..0f6e0f22 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -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; } diff --git a/languages.yaml b/languages.yaml index eb5e5fec..bb9276b5 100644 --- a/languages.yaml +++ b/languages.yaml @@ -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 `