mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-02 11:26:04 +01:00
Minor code improvements
This commit is contained in:
@@ -221,7 +221,6 @@ class Admin
|
|||||||
|
|
||||||
$path = Grav::instance()['locator']->findResource('plugins://admin/languages');
|
$path = Grav::instance()['locator']->findResource('plugins://admin/languages');
|
||||||
|
|
||||||
/** @var \DirectoryIterator $directory */
|
|
||||||
foreach (new \DirectoryIterator($path) as $file) {
|
foreach (new \DirectoryIterator($path) as $file) {
|
||||||
if ($file->isDir() || $file->isDot() || Utils::startsWith($file->getFilename(), '.')) {
|
if ($file->isDir() || $file->isDot() || Utils::startsWith($file->getFilename(), '.')) {
|
||||||
continue;
|
continue;
|
||||||
@@ -1533,7 +1532,7 @@ class Admin
|
|||||||
user_error(__METHOD__ . '() is deprecated since Admin 1.10, use $grav[\'permissions\']->getInstances() instead', E_USER_DEPRECATED);
|
user_error(__METHOD__ . '() is deprecated since Admin 1.10, use $grav[\'permissions\']->getInstances() instead', E_USER_DEPRECATED);
|
||||||
|
|
||||||
$grav = $this->grav;
|
$grav = $this->grav;
|
||||||
/** @var Permissions $object */
|
/** @var Permissions $permissions */
|
||||||
$permissions = $grav['permissions'];
|
$permissions = $grav['permissions'];
|
||||||
|
|
||||||
return array_fill_keys(array_keys($permissions->getInstances()), 'boolean');
|
return array_fill_keys(array_keys($permissions->getInstances()), 'boolean');
|
||||||
|
|||||||
@@ -1155,7 +1155,6 @@ class AdminBaseController
|
|||||||
*/
|
*/
|
||||||
protected function getRequest(): ServerRequestInterface
|
protected function getRequest(): ServerRequestInterface
|
||||||
{
|
{
|
||||||
/** @var ServerRequestInterface $request */
|
|
||||||
return $this->grav['request'];
|
return $this->grav['request'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,11 +44,11 @@ use Twig\Loader\FilesystemLoader;
|
|||||||
class AdminController extends AdminBaseController
|
class AdminController extends AdminBaseController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param Grav $grav
|
* @param Grav|null $grav
|
||||||
* @param string $view
|
* @param string|null $view
|
||||||
* @param string $task
|
* @param string|null $task
|
||||||
* @param string $route
|
* @param string|null $route
|
||||||
* @param array $post
|
* @param array|null $post
|
||||||
*/
|
*/
|
||||||
public function initialize(Grav $grav = null, $view = null, $task = null, $route = null, $post = null)
|
public function initialize(Grav $grav = null, $view = null, $task = null, $route = null, $post = null)
|
||||||
{
|
{
|
||||||
@@ -73,8 +73,10 @@ class AdminController extends AdminBaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep alive
|
* Keep alive
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function taskKeepAlive()
|
protected function taskKeepAlive(): void
|
||||||
{
|
{
|
||||||
$response = new Response(200);
|
$response = new Response(200);
|
||||||
|
|
||||||
@@ -148,7 +150,9 @@ class AdminController extends AdminBaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function taskSaveDefault()
|
protected function taskSaveDefault()
|
||||||
{
|
{
|
||||||
// Handle standard data types.
|
// Handle standard data types.
|
||||||
@@ -495,8 +499,9 @@ class AdminController extends AdminBaseController
|
|||||||
/**
|
/**
|
||||||
* Get Notifications
|
* Get Notifications
|
||||||
*
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function taskGetNotifications()
|
protected function taskGetNotifications(): void
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('dashboard', ['admin.login', 'admin.super'])) {
|
if (!$this->authorizeTask('dashboard', ['admin.login', 'admin.super'])) {
|
||||||
$this->sendJsonResponse(['status' => 'error', 'message' => 'unauthorized']);
|
$this->sendJsonResponse(['status' => 'error', 'message' => 'unauthorized']);
|
||||||
@@ -568,8 +573,10 @@ class AdminController extends AdminBaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Newsfeeds
|
* Get Newsfeeds
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function taskGetNewsFeed()
|
protected function taskGetNewsFeed(): void
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('dashboard', ['admin.login', 'admin.super'])) {
|
if (!$this->authorizeTask('dashboard', ['admin.login', 'admin.super'])) {
|
||||||
$this->sendJsonResponse(['status' => 'error', 'message' => 'unauthorized']);
|
$this->sendJsonResponse(['status' => 'error', 'message' => 'unauthorized']);
|
||||||
@@ -864,6 +871,8 @@ class AdminController extends AdminBaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle the gpm.releases setting
|
* Toggle the gpm.releases setting
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function taskGpmRelease()
|
protected function taskGpmRelease()
|
||||||
{
|
{
|
||||||
@@ -905,6 +914,8 @@ class AdminController extends AdminBaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get update status from GPM
|
* Get update status from GPM
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function taskGetUpdates()
|
protected function taskGetUpdates()
|
||||||
{
|
{
|
||||||
@@ -992,6 +1003,9 @@ class AdminController extends AdminBaseController
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function taskInstallDependenciesOfPackages()
|
protected function taskInstallDependenciesOfPackages()
|
||||||
{
|
{
|
||||||
$data = $this->post;
|
$data = $this->post;
|
||||||
@@ -1031,6 +1045,10 @@ class AdminController extends AdminBaseController
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool $reinstall
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function taskInstallPackage($reinstall = false)
|
protected function taskInstallPackage($reinstall = false)
|
||||||
{
|
{
|
||||||
$data = $this->post;
|
$data = $this->post;
|
||||||
@@ -1076,8 +1094,10 @@ class AdminController extends AdminBaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle removing a package
|
* Handle removing a package
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function taskRemovePackage()
|
protected function taskRemovePackage(): void
|
||||||
{
|
{
|
||||||
$data = $this->post;
|
$data = $this->post;
|
||||||
$package = $data['package'] ?? '';
|
$package = $data['package'] ?? '';
|
||||||
@@ -1139,6 +1159,8 @@ class AdminController extends AdminBaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle reinstalling a package
|
* Handle reinstalling a package
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function taskReinstallPackage()
|
protected function taskReinstallPackage()
|
||||||
{
|
{
|
||||||
@@ -1178,6 +1200,8 @@ class AdminController extends AdminBaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle direct install.
|
* Handle direct install.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function taskDirectInstall()
|
protected function taskDirectInstall()
|
||||||
{
|
{
|
||||||
@@ -1284,6 +1308,9 @@ class AdminController extends AdminBaseController
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function taskSavePage()
|
protected function taskSavePage()
|
||||||
{
|
{
|
||||||
$reorder = true;
|
$reorder = true;
|
||||||
@@ -1563,6 +1590,8 @@ class AdminController extends AdminBaseController
|
|||||||
* Switch the content language. Optionally redirect to a different page.
|
* Switch the content language. Optionally redirect to a different page.
|
||||||
*
|
*
|
||||||
* Route: /pages
|
* Route: /pages
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function taskSwitchlanguage()
|
protected function taskSwitchlanguage()
|
||||||
{
|
{
|
||||||
@@ -1755,6 +1784,9 @@ class AdminController extends AdminBaseController
|
|||||||
return $this->createJsonResponse($json, 200);
|
return $this->createJsonResponse($json, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function taskGetChildTypes()
|
protected function taskGetChildTypes()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('get childtypes', ['admin.pages', 'admin.super'])) {
|
if (!$this->authorizeTask('get childtypes', ['admin.pages', 'admin.super'])) {
|
||||||
@@ -1795,6 +1827,8 @@ class AdminController extends AdminBaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles filtering the page by modular/visible/routable in the pages list.
|
* Handles filtering the page by modular/visible/routable in the pages list.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function taskFilterPages()
|
protected function taskFilterPages()
|
||||||
{
|
{
|
||||||
@@ -2184,6 +2218,9 @@ class AdminController extends AdminBaseController
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function taskCompileScss()
|
protected function taskCompileScss()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -2217,6 +2254,9 @@ class AdminController extends AdminBaseController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function taskExportScss()
|
protected function taskExportScss()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('compile scss', ['admin.pages', 'admin.super'])) {
|
if (!$this->authorizeTask('compile scss', ['admin.pages', 'admin.super'])) {
|
||||||
@@ -2352,6 +2392,10 @@ class AdminController extends AdminBaseController
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $data
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function getLevelListing($data)
|
protected function getLevelListing($data)
|
||||||
{
|
{
|
||||||
// Valid types are dir|file|link
|
// Valid types are dir|file|link
|
||||||
@@ -2431,7 +2475,6 @@ class AdminController extends AdminBaseController
|
|||||||
|
|
||||||
|
|
||||||
if ($path) {
|
if ($path) {
|
||||||
/** @var \SplFileInfo $fileInfo */
|
|
||||||
$status = 'success';
|
$status = 'success';
|
||||||
$msg = 'PLUGIN_ADMIN.PAGE_ROUTE_FOUND';
|
$msg = 'PLUGIN_ADMIN.PAGE_ROUTE_FOUND';
|
||||||
foreach (new \DirectoryIterator($path) as $fileInfo) {
|
foreach (new \DirectoryIterator($path) as $fileInfo) {
|
||||||
@@ -2584,7 +2627,6 @@ class AdminController extends AdminBaseController
|
|||||||
* Gets the configuration data for a given view & post
|
* Gets the configuration data for a given view & post
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
|
||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
protected function prepareData(array $data)
|
protected function prepareData(array $data)
|
||||||
@@ -2601,8 +2643,9 @@ class AdminController extends AdminBaseController
|
|||||||
* @param PageInterface $page
|
* @param PageInterface $page
|
||||||
* @param bool $clean_header
|
* @param bool $clean_header
|
||||||
* @param string $languageCode
|
* @param string $languageCode
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function preparePage(PageInterface $page, $clean_header = false, $languageCode = '')
|
protected function preparePage(PageInterface $page, $clean_header = false, $languageCode = ''): void
|
||||||
{
|
{
|
||||||
$input = (array)$this->data;
|
$input = (array)$this->data;
|
||||||
|
|
||||||
@@ -2688,7 +2731,6 @@ class AdminController extends AdminBaseController
|
|||||||
*
|
*
|
||||||
* @param string $item
|
* @param string $item
|
||||||
* @param PageInterface $page
|
* @param PageInterface $page
|
||||||
*
|
|
||||||
* @return string The first available slot
|
* @return string The first available slot
|
||||||
*/
|
*/
|
||||||
protected function findFirstAvailable($item, PageInterface $page)
|
protected function findFirstAvailable($item, PageInterface $page)
|
||||||
@@ -2749,7 +2791,6 @@ class AdminController extends AdminBaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $frontmatter
|
* @param string $frontmatter
|
||||||
*
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function checkValidFrontmatter($frontmatter)
|
public function checkValidFrontmatter($frontmatter)
|
||||||
@@ -2768,7 +2809,6 @@ class AdminController extends AdminBaseController
|
|||||||
*
|
*
|
||||||
* @param string $current_filename the current file name, including .md. Example: default.en.md
|
* @param string $current_filename the current file name, including .md. Example: default.en.md
|
||||||
* @param string $language The new language it will be saved as. Example: 'it' or 'en-GB'.
|
* @param string $language The new language it will be saved as. Example: 'it' or 'en-GB'.
|
||||||
*
|
|
||||||
* @return string The new filename. Example: 'default.it'
|
* @return string The new filename. Example: 'default.it'
|
||||||
*/
|
*/
|
||||||
public function determineFilenameIncludingLanguage($current_filename, $language)
|
public function determineFilenameIncludingLanguage($current_filename, $language)
|
||||||
@@ -2795,7 +2835,6 @@ class AdminController extends AdminBaseController
|
|||||||
* Get the next available ordering number in a folder
|
* Get the next available ordering number in a folder
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
*
|
|
||||||
* @return string the correct order string to prepend
|
* @return string the correct order string to prepend
|
||||||
*/
|
*/
|
||||||
public static function getNextOrderInFolder($path)
|
public static function getNextOrderInFolder($path)
|
||||||
@@ -2826,6 +2865,9 @@ class AdminController extends AdminBaseController
|
|||||||
return $orderOfNewFolder;
|
return $orderOfNewFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ResponseInterface
|
||||||
|
*/
|
||||||
protected function taskConvertUrls(): ResponseInterface
|
protected function taskConvertUrls(): ResponseInterface
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Grav\Plugin\Admin;
|
namespace Grav\Plugin\Admin;
|
||||||
|
|
||||||
class ScssList {
|
class ScssList
|
||||||
protected $list= [];
|
{
|
||||||
|
/** @var string[] */
|
||||||
|
protected $list = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ScssList constructor.
|
||||||
|
* @param string|null $item
|
||||||
|
*/
|
||||||
public function __construct($item = null)
|
public function __construct($item = null)
|
||||||
{
|
{
|
||||||
if ($item) {
|
if ($item) {
|
||||||
@@ -11,20 +18,34 @@ class ScssList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function all()
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function all(): array
|
||||||
{
|
{
|
||||||
return $this->list;
|
return $this->list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add($item)
|
/**
|
||||||
|
* @param string $item
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function add($item): void
|
||||||
{
|
{
|
||||||
$this->list[] = $item;
|
if ($item) {
|
||||||
|
$this->list[] = $item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remove($item)
|
/**
|
||||||
|
* @param string $item
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function remove($item): void
|
||||||
{
|
{
|
||||||
if (in_array($item)) {
|
$pos = array_search($item, $this->list, true);
|
||||||
unset($item);
|
if ($pos) {
|
||||||
|
unset($this->list[$pos]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user