mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-01 10:56:08 +01:00
Code cleanup
This commit is contained in:
23
admin.php
23
admin.php
@@ -8,6 +8,7 @@ use Grav\Common\Language\Language;
|
||||
use Grav\Common\Page\Page;
|
||||
use Grav\Common\Page\Pages;
|
||||
use Grav\Common\Plugin;
|
||||
use Grav\Common\Session;
|
||||
use Grav\Common\Uri;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Common\User\User;
|
||||
@@ -19,7 +20,6 @@ use Grav\Plugin\Admin\Twig\AdminTwigExtension;
|
||||
use Grav\Plugin\Form\Form;
|
||||
use Grav\Plugin\Login\Login;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use RocketTheme\Toolbox\Session\Session;
|
||||
|
||||
class AdminPlugin extends Plugin
|
||||
{
|
||||
@@ -232,8 +232,8 @@ class AdminPlugin extends Plugin
|
||||
|
||||
$inflector = new Inflector();
|
||||
|
||||
$data['fullname'] = isset($data['fullname']) ? $data['fullname'] : $inflector->titleize($username);
|
||||
$data['title'] = isset($data['title']) ? $data['title'] : 'Administrator';
|
||||
$data['fullname'] = $data['fullname'] ?? $inflector->titleize($username);
|
||||
$data['title'] = $data['title'] ?? 'Administrator';
|
||||
$data['state'] = 'enabled';
|
||||
$data['access'] = ['admin' => ['login' => true, 'super' => true], 'site' => ['login' => true]];
|
||||
|
||||
@@ -332,14 +332,14 @@ class AdminPlugin extends Plugin
|
||||
// Set original route for the home page.
|
||||
$home = '/' . trim($this->config->get('system.home.alias'), '/');
|
||||
|
||||
// set the default if not set before
|
||||
$this->session->expert = $this->session->expert ?: false;
|
||||
|
||||
// set session variable if it's passed via the url
|
||||
if ($this->uri->param('mode') === 'expert') {
|
||||
$this->session->expert = true;
|
||||
} elseif ($this->uri->param('mode') === 'normal') {
|
||||
$this->session->expert = false;
|
||||
} else {
|
||||
// set the default if not set before
|
||||
$this->session->expert = $this->session->expert ?? false;
|
||||
}
|
||||
|
||||
/** @var Pages $pages */
|
||||
@@ -366,7 +366,7 @@ class AdminPlugin extends Plugin
|
||||
Pages::types();
|
||||
|
||||
// Handle tasks.
|
||||
$this->admin->task = $task = !empty($post['task']) ? $post['task'] : $this->uri->param('task');
|
||||
$this->admin->task = $task = $this->grav['task'];
|
||||
if ($task) {
|
||||
$this->initializeController($task, $post);
|
||||
} elseif ($this->template === 'logs' && $this->route) {
|
||||
@@ -654,7 +654,7 @@ class AdminPlugin extends Plugin
|
||||
|
||||
// Double check we have system.yaml, site.yaml etc
|
||||
$config_path = $this->grav['locator']->findResource('user://config');
|
||||
foreach ($this->admin->configurations() as $config_file) {
|
||||
foreach ($this->admin::configurations() as $config_file) {
|
||||
$config_file = "{$config_path}/{$config_file}.yaml";
|
||||
if (!file_exists($config_file)) {
|
||||
touch($config_file);
|
||||
@@ -745,7 +745,7 @@ class AdminPlugin extends Plugin
|
||||
|
||||
foreach ($strings as $string) {
|
||||
$separator = (end($strings) === $string) ? '' : ',';
|
||||
$translations .= '"' . $string . '": "' . htmlspecialchars($this->admin->translate('PLUGIN_ADMIN.' . $string)) . '"' . $separator;
|
||||
$translations .= '"' . $string . '": "' . htmlspecialchars($this->admin::translate('PLUGIN_ADMIN.' . $string)) . '"' . $separator;
|
||||
}
|
||||
|
||||
$translations .= '};';
|
||||
@@ -754,7 +754,7 @@ class AdminPlugin extends Plugin
|
||||
$strings = ['RESOLUTION_MIN', 'RESOLUTION_MAX'];
|
||||
foreach ($strings as $string) {
|
||||
$separator = (end($strings) === $string) ? '' : ',';
|
||||
$translations .= '"' . $string . '": "' . $this->admin->translate('PLUGIN_FORM.' . $string) . '"' . $separator;
|
||||
$translations .= '"' . $string . '": "' . $this->admin::translate('PLUGIN_FORM.' . $string) . '"' . $separator;
|
||||
}
|
||||
$translations .= '};';
|
||||
|
||||
@@ -788,7 +788,7 @@ class AdminPlugin extends Plugin
|
||||
];
|
||||
foreach ($strings as $string) {
|
||||
$separator = (end($strings) === $string) ? '' : ',';
|
||||
$translations .= '"' . $string . '": ' . json_encode($this->admin->translate('GRAV.'.$string)) . $separator;
|
||||
$translations .= '"' . $string . '": ' . json_encode($this->admin::translate('GRAV.'.$string)) . $separator;
|
||||
}
|
||||
$translations .= '};';
|
||||
|
||||
@@ -888,6 +888,7 @@ class AdminPlugin extends Plugin
|
||||
if ($this->admin->task !== 'save' && empty($this->uri->extension())) {
|
||||
// Discard any previously uploaded files session.
|
||||
// and if there were any uploaded file, remove them from the filesystem
|
||||
// FIXME:
|
||||
if ($flash = $this->session->getFlashObject('files-upload')) {
|
||||
$flash = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($flash));
|
||||
foreach ($flash as $key => $value) {
|
||||
|
||||
@@ -368,9 +368,9 @@ class Admin
|
||||
|
||||
$rateLimiter = $login->getRateLimiter('login_attempts');
|
||||
|
||||
$userKey = isset($credentials['username']) ? (string)$credentials['username'] : '';
|
||||
$userKey = (string)($credentials['username'] ?? '');
|
||||
$ipKey = Uri::ip();
|
||||
$redirect = isset($post['redirect']) ? $post['redirect'] : $this->base . $this->route;
|
||||
$redirect = $post['redirect'] ?? $this->base . $this->route;
|
||||
|
||||
// Check if the current IP has been used in failed login attempts.
|
||||
$attempts = count($rateLimiter->getAttempts($ipKey, 'ip'));
|
||||
@@ -379,7 +379,7 @@ class Admin
|
||||
|
||||
// Check rate limit for both IP and user, but allow each IP a single try even if user is already rate limited.
|
||||
if ($rateLimiter->isRateLimited($ipKey, 'ip') || ($attempts && $rateLimiter->isRateLimited($userKey))) {
|
||||
$this->setMessage($this->translate(['PLUGIN_LOGIN.TOO_MANY_LOGIN_ATTEMPTS', $rateLimiter->getInterval()]), 'error');
|
||||
$this->setMessage(static::translate(['PLUGIN_LOGIN.TOO_MANY_LOGIN_ATTEMPTS', $rateLimiter->getInterval()]), 'error');
|
||||
|
||||
$this->grav->redirect('/');
|
||||
}
|
||||
@@ -397,7 +397,7 @@ class Admin
|
||||
if ($user->authorized) {
|
||||
$event->defMessage('PLUGIN_ADMIN.LOGIN_LOGGED_IN', 'info');
|
||||
|
||||
$event->defRedirect(isset($post['redirect']) ? $post['redirect'] : $redirect);
|
||||
$event->defRedirect($post['redirect'] ?? $redirect);
|
||||
} else {
|
||||
$this->session->redirect = $redirect;
|
||||
}
|
||||
@@ -413,7 +413,7 @@ class Admin
|
||||
|
||||
$message = $event->getMessage();
|
||||
if ($message) {
|
||||
$this->setMessage($this->translate($message), $event->getMessageType());
|
||||
$this->setMessage(static::translate($message), $event->getMessageType());
|
||||
}
|
||||
|
||||
$redirect = $event->getRedirect();
|
||||
@@ -433,9 +433,9 @@ class Admin
|
||||
$twoFa = $login->twoFactorAuth();
|
||||
$user = $this->grav['user'];
|
||||
|
||||
$code = isset($data['2fa_code']) ? $data['2fa_code'] : null;
|
||||
$code = $data['2fa_code'] ?? null;
|
||||
|
||||
$secret = isset($user->twofa_secret) ? $user->twofa_secret : null;
|
||||
$secret = $user->twofa_secret ?? null;
|
||||
|
||||
if (!$code || !$secret || !$twoFa->verifyCode($secret, $code)) {
|
||||
$login->logout(['admin' => true]);
|
||||
@@ -455,7 +455,7 @@ class Admin
|
||||
/**
|
||||
* Logout from admin.
|
||||
*/
|
||||
public function Logout($data, $post)
|
||||
public function logout($data, $post)
|
||||
{
|
||||
/** @var Login $login */
|
||||
$login = $this->grav['login'];
|
||||
@@ -601,7 +601,7 @@ class Admin
|
||||
|
||||
if (!$post) {
|
||||
$post = $this->grav['uri']->post();
|
||||
$post = isset($post['data']) ? $post['data'] : [];
|
||||
$post = $post['data'] ?? [];
|
||||
}
|
||||
|
||||
// Check to see if a data type is plugin-provided, before looking into core ones
|
||||
@@ -609,7 +609,9 @@ class Admin
|
||||
if ($event) {
|
||||
if (isset($event['data_type'])) {
|
||||
return $event['data_type'];
|
||||
} elseif (is_string($event['type'])) {
|
||||
}
|
||||
|
||||
if (is_string($event['type'])) {
|
||||
$type = $event['type'];
|
||||
}
|
||||
}
|
||||
@@ -1058,7 +1060,7 @@ class Admin
|
||||
*/
|
||||
public function lastBackup()
|
||||
{
|
||||
$file = JsonFile::instance($this->grav['locator']->findResource("log://backup.log"));
|
||||
$file = JsonFile::instance($this->grav['locator']->findResource('log://backup.log'));
|
||||
$content = $file->content();
|
||||
if (empty($content)) {
|
||||
return [
|
||||
@@ -1454,7 +1456,7 @@ class Admin
|
||||
$pages->addPage($page, $path);
|
||||
|
||||
// Set if Modular
|
||||
$page->modularTwig($slug[0] === '_');
|
||||
$page->modularTwig($slug[0] ?? '' === '_');
|
||||
|
||||
// Determine page type.
|
||||
if (isset($this->session->{$page->route()})) {
|
||||
@@ -1477,7 +1479,7 @@ class Admin
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($data['visible'] == 1 && !$page->order()) {
|
||||
if ((int)$data['visible'] === 1 && !$page->order()) {
|
||||
$header['visible'] = $data['visible'];
|
||||
}
|
||||
|
||||
@@ -1498,14 +1500,11 @@ class Admin
|
||||
$page->frontmatter(Yaml::dump((array)$page->header(), 20));
|
||||
} else {
|
||||
// Find out the type by looking at the parent.
|
||||
$type = $parent->childType()
|
||||
? $parent->childType()
|
||||
: $parent->blueprints()->get('child_type',
|
||||
'default');
|
||||
$type = $parent->childType() ?: $parent->blueprints()->get('child_type', 'default');
|
||||
$page->name($type . CONTENT_EXT);
|
||||
$page->header();
|
||||
}
|
||||
$page->modularTwig($slug[0] === '_');
|
||||
$page->modularTwig($slug[0] ?? '' === '_');
|
||||
}
|
||||
|
||||
return $page;
|
||||
@@ -1554,8 +1553,10 @@ class Admin
|
||||
/**
|
||||
* Get the files list
|
||||
*
|
||||
* @param bool $filtered
|
||||
* @param int $page_index
|
||||
* @return array|null
|
||||
* @todo allow pagination
|
||||
* @return array
|
||||
*/
|
||||
public function files($filtered = true, $page_index = 0)
|
||||
{
|
||||
@@ -1672,7 +1673,7 @@ class Admin
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getMediaOfType($type, Page $page = null, array $files)
|
||||
private function getMediaOfType($type, ?Page $page, array $files)
|
||||
{
|
||||
if ($page) {
|
||||
$media = $page->media();
|
||||
@@ -1815,6 +1816,6 @@ class Admin
|
||||
*/
|
||||
public function getReferrer()
|
||||
{
|
||||
return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
||||
return $_SERVER['HTTP_REFERER'] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ class AdminBaseController
|
||||
}
|
||||
|
||||
// Grab redirect parameter.
|
||||
$redirect = isset($this->post['_redirect']) ? $this->post['_redirect'] : null;
|
||||
$redirect = $this->post['_redirect'] ?? null;
|
||||
unset($this->post['_redirect']);
|
||||
|
||||
// Redirect if requested.
|
||||
@@ -138,7 +138,7 @@ class AdminBaseController
|
||||
if (!$nonce || !Utils::verifyNonce($nonce, 'admin-form')) {
|
||||
if ($this->task === 'addmedia') {
|
||||
|
||||
$message = sprintf($this->admin->translate('PLUGIN_ADMIN.FILE_TOO_LARGE', null),
|
||||
$message = sprintf($this->admin::translate('PLUGIN_ADMIN.FILE_TOO_LARGE', null),
|
||||
ini_get('post_max_size'));
|
||||
|
||||
//In this case it's more likely that the image is too big than POST can handle. Show message
|
||||
@@ -150,10 +150,10 @@ class AdminBaseController
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'), 'error');
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -163,11 +163,11 @@ class AdminBaseController
|
||||
if ($this->task === 'logout') {
|
||||
$nonce = $this->grav['uri']->param('logout-nonce');
|
||||
if (null === $nonce || !Utils::verifyNonce($nonce, 'logout-form')) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'),
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'),
|
||||
'error');
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -175,11 +175,11 @@ class AdminBaseController
|
||||
} else {
|
||||
$nonce = $this->grav['uri']->param('admin-nonce');
|
||||
if (null === $nonce || !Utils::verifyNonce($nonce, 'admin-form')) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'),
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'),
|
||||
'error');
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -257,7 +257,7 @@ class AdminBaseController
|
||||
if (!Utils::checkFilename($filename)) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_UPLOAD', null),
|
||||
'message' => sprintf($this->admin::translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_UPLOAD', null),
|
||||
$filename, 'Bad filename')
|
||||
];
|
||||
|
||||
@@ -267,7 +267,7 @@ class AdminBaseController
|
||||
if (!isset($settings->destination)) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.DESTINATION_NOT_SPECIFIED', null)
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.DESTINATION_NOT_SPECIFIED', null)
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -277,7 +277,7 @@ class AdminBaseController
|
||||
if ($this->view !== 'pages' && in_array($settings->destination, ['@self', 'self@', '@self@'])) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_PREVENT_SELF', null),
|
||||
'message' => sprintf($this->admin::translate('PLUGIN_ADMIN.FILEUPLOAD_PREVENT_SELF', null),
|
||||
$settings->destination)
|
||||
];
|
||||
|
||||
@@ -288,7 +288,7 @@ class AdminBaseController
|
||||
if ($upload->file->error !== UPLOAD_ERR_OK) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_UPLOAD', null),
|
||||
'message' => sprintf($this->admin::translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_UPLOAD', null),
|
||||
$upload->file->name, $this->upload_errors[$upload->file->error])
|
||||
];
|
||||
|
||||
@@ -300,7 +300,7 @@ class AdminBaseController
|
||||
if ($settings->filesize > 0 && $upload->file->size > $settings->filesize) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.EXCEEDED_GRAV_FILESIZE_LIMIT')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.EXCEEDED_GRAV_FILESIZE_LIMIT')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -366,7 +366,7 @@ class AdminBaseController
|
||||
if (!move_uploaded_file($tmp_file, $tmp)) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_MOVE', null), '',
|
||||
'message' => sprintf($this->admin::translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_MOVE', null), '',
|
||||
$tmp)
|
||||
];
|
||||
|
||||
@@ -377,6 +377,7 @@ class AdminBaseController
|
||||
|
||||
// Retrieve the current session of the uploaded files for the field
|
||||
// and initialize it if it doesn't exist
|
||||
// FIXME:
|
||||
$sessionField = base64_encode($this->grav['uri']->url());
|
||||
$flash = $this->admin->session()->getFlashObject('files-upload');
|
||||
if (!$flash) {
|
||||
@@ -566,6 +567,7 @@ class AdminBaseController
|
||||
}
|
||||
|
||||
// Retrieve the flash object and remove the requested file from it
|
||||
// FIXME:
|
||||
$flash = $this->admin->session()->getFlashObject('files-upload');
|
||||
$endpoint = $flash[$request->sessionField][$request->field][$request->path];
|
||||
|
||||
@@ -840,6 +842,7 @@ class AdminBaseController
|
||||
|
||||
// Peak in the flashObject for optimistic filepicker updates
|
||||
$pending_files = [];
|
||||
// FIXME:
|
||||
$sessionField = base64_encode($this->grav['uri']->url());
|
||||
$flash = $this->admin->session()->getFlashObject('files-upload');
|
||||
|
||||
@@ -985,7 +988,7 @@ class AdminBaseController
|
||||
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL')
|
||||
];
|
||||
|
||||
return true;
|
||||
@@ -1002,7 +1005,7 @@ class AdminBaseController
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null($filename)) {
|
||||
if (null === $filename) {
|
||||
$filename = base64_decode($this->grav['uri']->param('route'));
|
||||
if (!$filename) {
|
||||
$filename = base64_decode($this->route);
|
||||
@@ -1031,10 +1034,10 @@ class AdminBaseController
|
||||
if ($this->grav['uri']->extension() === 'json') {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL')
|
||||
];
|
||||
} else {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL'), 'info');
|
||||
$this->clearMediaCache();
|
||||
$this->setRedirect('/media-manager');
|
||||
}
|
||||
@@ -1045,10 +1048,10 @@ class AdminBaseController
|
||||
if ($this->grav['uri']->extension() === 'json') {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.REMOVE_FAILED')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.REMOVE_FAILED')
|
||||
];
|
||||
} else {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.REMOVE_FAILED'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.REMOVE_FAILED'), 'error');
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -34,67 +34,6 @@ use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
*/
|
||||
class AdminController extends AdminBaseController
|
||||
{
|
||||
/**
|
||||
* @var Grav
|
||||
*/
|
||||
public $grav;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $view;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $task;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $route;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* @var Admin
|
||||
*/
|
||||
protected $admin;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $redirect;
|
||||
|
||||
/**
|
||||
* @var \Grav\Common\Uri $uri
|
||||
*/
|
||||
protected $uri;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $redirectCode;
|
||||
|
||||
protected $upload_errors = [
|
||||
0 => "There is no error, the file uploaded with success",
|
||||
1 => "The uploaded file exceeds the max upload size",
|
||||
2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML",
|
||||
3 => "The uploaded file was only partially uploaded",
|
||||
4 => "No file was uploaded",
|
||||
6 => "Missing a temporary folder",
|
||||
7 => "Failed to write file to disk",
|
||||
8 => "A PHP extension stopped the file upload"
|
||||
];
|
||||
|
||||
/**
|
||||
* @param Grav $grav
|
||||
* @param string $view
|
||||
@@ -106,7 +45,7 @@ class AdminController extends AdminBaseController
|
||||
{
|
||||
$this->grav = $grav;
|
||||
$this->view = $view;
|
||||
$this->task = $task ? $task : 'display';
|
||||
$this->task = $task ?: 'display';
|
||||
if (isset($post['data'])) {
|
||||
$this->data = $this->getPost($post['data']);
|
||||
unset($post['data']);
|
||||
@@ -207,15 +146,15 @@ class AdminController extends AdminBaseController
|
||||
if (isset($data['password'])) {
|
||||
$username = isset($data['username']) ? strip_tags(strtolower($data['username'])) : null;
|
||||
$user = $username ? User::load($username) : null;
|
||||
$password = isset($data['password']) ? $data['password'] : null;
|
||||
$token = isset($data['token']) ? $data['token'] : null;
|
||||
$password = $data['password'] ?? null;
|
||||
$token = $data['token'] ?? null;
|
||||
|
||||
if ($user && $user->exists() && !empty($user->reset)) {
|
||||
list($good_token, $expire) = explode('::', $user->reset);
|
||||
|
||||
if ($good_token === $token) {
|
||||
if (time() > $expire) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.RESET_LINK_EXPIRED'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.RESET_LINK_EXPIRED'), 'error');
|
||||
$this->setRedirect('/forgot');
|
||||
|
||||
return true;
|
||||
@@ -228,14 +167,14 @@ class AdminController extends AdminBaseController
|
||||
$user->filter();
|
||||
$user->save();
|
||||
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.RESET_PASSWORD_RESET'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.RESET_PASSWORD_RESET'), 'info');
|
||||
$this->setRedirect('/');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.RESET_INVALID_LINK'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.RESET_INVALID_LINK'), 'error');
|
||||
$this->setRedirect('/forgot');
|
||||
|
||||
return true;
|
||||
@@ -246,13 +185,13 @@ class AdminController extends AdminBaseController
|
||||
$token = $this->grav['uri']->param('token');
|
||||
|
||||
if (empty($user) || empty($token)) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.RESET_INVALID_LINK'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.RESET_INVALID_LINK'), 'error');
|
||||
$this->setRedirect('/forgot');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.RESET_NEW_PASSWORD'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.RESET_NEW_PASSWORD'), 'info');
|
||||
|
||||
$this->admin->forgot = ['username' => $user, 'token' => $token];
|
||||
|
||||
@@ -263,7 +202,6 @@ class AdminController extends AdminBaseController
|
||||
* Handle the email password recovery procedure.
|
||||
*
|
||||
* @return bool True if the action was performed.
|
||||
* @todo LOGIN
|
||||
*/
|
||||
protected function taskForgot()
|
||||
{
|
||||
@@ -276,14 +214,14 @@ class AdminController extends AdminBaseController
|
||||
$user = !empty($username) ? User::load($username) : null;
|
||||
|
||||
if (!isset($this->grav['Email'])) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.FORGOT_EMAIL_NOT_CONFIGURED'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.FORGOT_EMAIL_NOT_CONFIGURED'), 'error');
|
||||
$this->setRedirect($post['redirect']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$user || !$user->exists()) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.FORGOT_INSTRUCTIONS_SENT_VIA_EMAIL'),
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.FORGOT_INSTRUCTIONS_SENT_VIA_EMAIL'),
|
||||
'info');
|
||||
$this->setRedirect($post['redirect']);
|
||||
|
||||
@@ -291,7 +229,7 @@ class AdminController extends AdminBaseController
|
||||
}
|
||||
|
||||
if (empty($user->email)) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.FORGOT_INSTRUCTIONS_SENT_VIA_EMAIL'),
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.FORGOT_INSTRUCTIONS_SENT_VIA_EMAIL'),
|
||||
'info');
|
||||
$this->setRedirect($post['redirect']);
|
||||
|
||||
@@ -302,7 +240,7 @@ class AdminController extends AdminBaseController
|
||||
$interval =$this->grav['config']->get('plugins.login.max_pw_resets_interval', 2);
|
||||
|
||||
if ($login->isUserRateLimited($user, 'pw_resets', $count, $interval)) {
|
||||
$this->admin->setMessage($this->admin->translate(['PLUGIN_LOGIN.FORGOT_CANNOT_RESET_IT_IS_BLOCKED', $user->email, $interval]), 'error');
|
||||
$this->admin->setMessage($this->admin::translate(['PLUGIN_LOGIN.FORGOT_CANNOT_RESET_IT_IS_BLOCKED', $user->email, $interval]), 'error');
|
||||
$this->setRedirect($post['redirect']);
|
||||
|
||||
return true;
|
||||
@@ -323,7 +261,7 @@ class AdminController extends AdminBaseController
|
||||
$from = $this->grav['config']->get('plugins.email.from');
|
||||
|
||||
if (empty($from)) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.FORGOT_EMAIL_NOT_CONFIGURED'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.FORGOT_EMAIL_NOT_CONFIGURED'), 'error');
|
||||
$this->setRedirect($post['redirect']);
|
||||
|
||||
return true;
|
||||
@@ -331,8 +269,8 @@ class AdminController extends AdminBaseController
|
||||
|
||||
$to = $user->email;
|
||||
|
||||
$subject = $this->admin->translate(['PLUGIN_ADMIN.FORGOT_EMAIL_SUBJECT', $sitename]);
|
||||
$content = $this->admin->translate([
|
||||
$subject = $this->admin::translate(['PLUGIN_ADMIN.FORGOT_EMAIL_SUBJECT', $sitename]);
|
||||
$content = $this->admin::translate([
|
||||
'PLUGIN_ADMIN.FORGOT_EMAIL_BODY',
|
||||
$fullname,
|
||||
$reset_link,
|
||||
@@ -347,9 +285,9 @@ class AdminController extends AdminBaseController
|
||||
$sent = $this->grav['Email']->send($message);
|
||||
|
||||
if ($sent < 1) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.FORGOT_FAILED_TO_EMAIL'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.FORGOT_FAILED_TO_EMAIL'), 'error');
|
||||
} else {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.FORGOT_INSTRUCTIONS_SENT_VIA_EMAIL'),
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.FORGOT_INSTRUCTIONS_SENT_VIA_EMAIL'),
|
||||
'info');
|
||||
}
|
||||
|
||||
@@ -379,7 +317,7 @@ class AdminController extends AdminBaseController
|
||||
$obj->save();
|
||||
|
||||
$this->post = ['_redirect' => 'plugins'];
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_ENABLED_PLUGIN'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_ENABLED_PLUGIN'), 'info');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -420,7 +358,7 @@ class AdminController extends AdminBaseController
|
||||
$obj->save();
|
||||
|
||||
$this->post = ['_redirect' => 'plugins'];
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_DISABLED_PLUGIN'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_DISABLED_PLUGIN'), 'info');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -458,7 +396,7 @@ class AdminController extends AdminBaseController
|
||||
|
||||
$config->set('system.pages.theme', $name);
|
||||
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_CHANGED_THEME'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_CHANGED_THEME'), 'info');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -483,14 +421,14 @@ class AdminController extends AdminBaseController
|
||||
'status' => 'success',
|
||||
'type' => 'updategrav',
|
||||
'version' => $version,
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.GRAV_WAS_SUCCESSFULLY_UPDATED_TO') . ' ' . $version
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.GRAV_WAS_SUCCESSFULLY_UPDATED_TO') . ' ' . $version
|
||||
];
|
||||
} else {
|
||||
$json_response = [
|
||||
'status' => 'error',
|
||||
'type' => 'updategrav',
|
||||
'version' => GRAV_VERSION,
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.GRAV_UPDATE_FAILED') . ' <br>' . Installer::lastErrorMsg()
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.GRAV_UPDATE_FAILED') . ' <br>' . Installer::lastErrorMsg()
|
||||
];
|
||||
}
|
||||
|
||||
@@ -516,9 +454,9 @@ class AdminController extends AdminBaseController
|
||||
$result = Gpm::uninstall($package, []);
|
||||
|
||||
if ($result) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.UNINSTALL_SUCCESSFUL'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.UNINSTALL_SUCCESSFUL'), 'info');
|
||||
} else {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.UNINSTALL_FAILED'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.UNINSTALL_FAILED'), 'error');
|
||||
}
|
||||
|
||||
$this->post = ['_redirect' => $this->view];
|
||||
@@ -545,7 +483,7 @@ class AdminController extends AdminBaseController
|
||||
$path = $this->grav['page']->find($data['route'])->path();
|
||||
}
|
||||
|
||||
$orderOfNewFolder = $this->getNextOrderInFolder($path);
|
||||
$orderOfNewFolder = static::getNextOrderInFolder($path);
|
||||
$new_path = $path . '/' . $orderOfNewFolder . '.' . $data['folder'];
|
||||
|
||||
Folder::create($new_path);
|
||||
@@ -553,7 +491,7 @@ class AdminController extends AdminBaseController
|
||||
|
||||
$this->grav->fireEvent('onAdminAfterSaveAs', new Event(['path' => $new_path]));
|
||||
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_SAVED'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_SAVED'), 'info');
|
||||
|
||||
$multilang = $this->isMultilang();
|
||||
$admin_route = $this->admin->base;
|
||||
@@ -617,13 +555,13 @@ class AdminController extends AdminBaseController
|
||||
// Special handler for user data.
|
||||
if ($this->view === 'user') {
|
||||
if (!$this->grav['user']->exists()) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.NO_USER_EXISTS'),'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.NO_USER_EXISTS'),'error');
|
||||
return false;
|
||||
}
|
||||
if (!$this->admin->authorize(['admin.super', 'admin.users'])) {
|
||||
// no user file or not admin.super or admin.users
|
||||
if ($this->prepareData($data)->username !== $this->grav['user']->username) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' save.','error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' save.','error');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -650,7 +588,7 @@ class AdminController extends AdminBaseController
|
||||
|
||||
// Check for valid frontmatter
|
||||
if (isset($data['frontmatter']) && !$this->checkValidFrontmatter($data['frontmatter'])) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INVALID_FRONTMATTER_COULD_NOT_SAVE'),
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.INVALID_FRONTMATTER_COULD_NOT_SAVE'),
|
||||
'error');
|
||||
return false;
|
||||
}
|
||||
@@ -658,10 +596,10 @@ class AdminController extends AdminBaseController
|
||||
// XSS Checks for page content
|
||||
$xss_whitelist = $this->grav['config']->get('security.xss_whitelist', 'admin.super');
|
||||
if (!$this->admin->authorize($xss_whitelist)) {
|
||||
$check_what = ['header' => isset($data['header']) ? $data['header'] : '', 'frontmatter' => isset($data['frontmatter']) ? $data['frontmatter'] : '', 'content' => isset($data['content']) ? $data['content'] : ''];
|
||||
$check_what = ['header' => $data['header'] ?? '', 'frontmatter' => $data['frontmatter'] ?? '', 'content' => $data['content'] ?? ''];
|
||||
$results = Security::detectXssFromArray($check_what);
|
||||
if (!empty($results)) {
|
||||
$this->admin->setMessage('<i class="fa fa-ban"></i> ' . $this->admin->translate('PLUGIN_ADMIN.XSS_ONSAVE_ISSUE'),
|
||||
$this->admin->setMessage('<i class="fa fa-ban"></i> ' . $this->admin::translate('PLUGIN_ADMIN.XSS_ONSAVE_ISSUE'),
|
||||
'error');
|
||||
return false;
|
||||
}
|
||||
@@ -697,7 +635,7 @@ class AdminController extends AdminBaseController
|
||||
// add or remove numeric prefix based on ordering value
|
||||
if (isset($data['ordering'])) {
|
||||
if ($data['ordering'] && !$obj->order()) {
|
||||
$obj->order($this->getNextOrderInFolder($obj->parent()->path()));
|
||||
$obj->order(static::getNextOrderInFolder($obj->parent()->path()));
|
||||
$reorder = false;
|
||||
} elseif (!$data['ordering'] && $obj->order()) {
|
||||
$obj->folder($obj->slug());
|
||||
@@ -725,7 +663,7 @@ class AdminController extends AdminBaseController
|
||||
// Event to manipulate data before saving the object
|
||||
$this->grav->fireEvent('onAdminSave', new Event(['object' => &$obj]));
|
||||
$obj->save($reorder);
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_SAVED'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_SAVED'), 'info');
|
||||
$this->grav->fireEvent('onAdminAfterSave', new Event(['object' => $obj]));
|
||||
}
|
||||
|
||||
@@ -942,7 +880,7 @@ class AdminController extends AdminBaseController
|
||||
}
|
||||
|
||||
$data = $this->post;
|
||||
$flush = (isset($data['flush']) && $data['flush'] == true) ? true : false;
|
||||
$flush = !empty($data['flush']);
|
||||
|
||||
if (isset($this->grav['session'])) {
|
||||
$this->grav['session']->close();
|
||||
@@ -952,7 +890,7 @@ class AdminController extends AdminBaseController
|
||||
$gpm = new GravGPM($flush);
|
||||
|
||||
$resources_updates = $gpm->getUpdatable();
|
||||
if ($gpm->grav != null) {
|
||||
if ($gpm->grav !== null) {
|
||||
$grav_updates = [
|
||||
'isUpdatable' => $gpm->grav->isUpdatable(),
|
||||
'assets' => $gpm->grav->getAssets(),
|
||||
@@ -1102,12 +1040,12 @@ class AdminController extends AdminBaseController
|
||||
$packages = isset($data['packages']) ? explode(',', $data['packages']) : '';
|
||||
$packages = (array)$packages;
|
||||
|
||||
$type = isset($data['type']) ? $data['type'] : '';
|
||||
$type = $data['type'] ?? '';
|
||||
|
||||
if (!$this->authorizeTask('install ' . $type, ['admin.' . $type, 'admin.super'])) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1128,7 +1066,7 @@ class AdminController extends AdminBaseController
|
||||
} else {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.INSTALLATION_FAILED')
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1138,13 +1076,13 @@ class AdminController extends AdminBaseController
|
||||
protected function taskInstallPackage($reinstall = false)
|
||||
{
|
||||
$data = $this->post;
|
||||
$package = isset($data['package']) ? $data['package'] : '';
|
||||
$type = isset($data['type']) ? $data['type'] : '';
|
||||
$package = $data['package'] ?? '';
|
||||
$type = $data['type'] ?? '';
|
||||
|
||||
if (!$this->authorizeTask('install ' . $type, ['admin.' . $type, 'admin.super'])) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1161,13 +1099,13 @@ class AdminController extends AdminBaseController
|
||||
if ($result) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'message' => $this->admin->translate(is_string($result) ? $result : sprintf($this->admin->translate($reinstall ?: 'PLUGIN_ADMIN.PACKAGE_X_REINSTALLED_SUCCESSFULLY',
|
||||
'message' => $this->admin::translate(is_string($result) ? $result : sprintf($this->admin::translate($reinstall ?: 'PLUGIN_ADMIN.PACKAGE_X_REINSTALLED_SUCCESSFULLY',
|
||||
null), $package))
|
||||
];
|
||||
} else {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate($reinstall ?: 'PLUGIN_ADMIN.INSTALLATION_FAILED')
|
||||
'message' => $this->admin::translate($reinstall ?: 'PLUGIN_ADMIN.INSTALLATION_FAILED')
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1182,13 +1120,13 @@ class AdminController extends AdminBaseController
|
||||
protected function taskRemovePackage()
|
||||
{
|
||||
$data = $this->post;
|
||||
$package = isset($data['package']) ? $data['package'] : '';
|
||||
$type = isset($data['type']) ? $data['type'] : '';
|
||||
$package = $data['package'] ?? '';
|
||||
$type = $data['type'] ?? '';
|
||||
|
||||
if (!$this->authorizeTask('uninstall ' . $type, ['admin.' . $type, 'admin.super'])) {
|
||||
$json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')
|
||||
];
|
||||
|
||||
return $this->sendJsonResponse($json_response, 403);
|
||||
@@ -1223,7 +1161,7 @@ class AdminController extends AdminBaseController
|
||||
$json_response = [
|
||||
'status' => 'success',
|
||||
'dependencies' => $dependencies,
|
||||
'message' => $this->admin->translate(is_string($result) ? $result : 'PLUGIN_ADMIN.UNINSTALL_SUCCESSFUL')
|
||||
'message' => $this->admin::translate(is_string($result) ? $result : 'PLUGIN_ADMIN.UNINSTALL_SUCCESSFUL')
|
||||
];
|
||||
|
||||
return $this->sendJsonResponse($json_response, 200);
|
||||
@@ -1231,7 +1169,7 @@ class AdminController extends AdminBaseController
|
||||
|
||||
$json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.UNINSTALL_FAILED')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.UNINSTALL_FAILED')
|
||||
];
|
||||
|
||||
return $this->sendJsonResponse($json_response, 200);
|
||||
@@ -1244,15 +1182,15 @@ class AdminController extends AdminBaseController
|
||||
{
|
||||
$data = $this->post;
|
||||
|
||||
$slug = isset($data['slug']) ? $data['slug'] : '';
|
||||
$type = isset($data['type']) ? $data['type'] : '';
|
||||
$package_name = isset($data['package_name']) ? $data['package_name'] : '';
|
||||
$current_version = isset($data['current_version']) ? $data['current_version'] : '';
|
||||
$slug = $data['slug'] ?? '';
|
||||
$type = $data['type'] ?? '';
|
||||
$package_name = $data['package_name'] ?? '';
|
||||
$current_version = $data['current_version'] ?? '';
|
||||
|
||||
if (!$this->authorizeTask('install ' . $type, ['admin.' . $type, 'admin.super'])) {
|
||||
$json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')
|
||||
];
|
||||
|
||||
$this->sendJsonResponse($json_response, 403);
|
||||
@@ -1265,13 +1203,13 @@ class AdminController extends AdminBaseController
|
||||
if ($result === true) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'message' => $this->admin->translate(sprintf($this->admin->translate('PLUGIN_ADMIN.PACKAGE_X_REINSTALLED_SUCCESSFULLY',
|
||||
'message' => $this->admin::translate(sprintf($this->admin::translate('PLUGIN_ADMIN.PACKAGE_X_REINSTALLED_SUCCESSFULLY',
|
||||
null), $package_name))
|
||||
];
|
||||
} else {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.REINSTALLATION_FAILED')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.REINSTALLATION_FAILED')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1307,12 +1245,12 @@ class AdminController extends AdminBaseController
|
||||
if (count($results) > 0) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.CACHE_CLEARED') . ' <br />' . $this->admin->translate('PLUGIN_ADMIN.METHOD') . ': ' . $clear . ''
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.CACHE_CLEARED') . ' <br />' . $this->admin::translate('PLUGIN_ADMIN.METHOD') . ': ' . $clear . ''
|
||||
];
|
||||
} else {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.ERROR_CLEARING_CACHE')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.ERROR_CLEARING_CACHE')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1346,7 +1284,7 @@ class AdminController extends AdminBaseController
|
||||
$filename = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT,
|
||||
true, true);
|
||||
$file = CompiledYamlFile::instance($filename);
|
||||
$data = $file->content();
|
||||
$data = (array)$file->content();
|
||||
$data[] = $notification_id;
|
||||
$file->save($data);
|
||||
|
||||
@@ -1390,7 +1328,7 @@ class AdminController extends AdminBaseController
|
||||
} catch (\Exception $e) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.AN_ERROR_OCCURRED') . '. ' . $e->getMessage()
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.AN_ERROR_OCCURRED') . '. ' . $e->getMessage()
|
||||
];
|
||||
|
||||
return true;
|
||||
@@ -1408,7 +1346,7 @@ class AdminController extends AdminBaseController
|
||||
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.YOUR_BACKUP_IS_READY_FOR_DOWNLOAD') . '. <a href="' . $url . '" class="button">' . $this->admin->translate('PLUGIN_ADMIN.DOWNLOAD_BACKUP') . '</a>',
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.YOUR_BACKUP_IS_READY_FOR_DOWNLOAD') . '. <a href="' . $url . '" class="button">' . $this->admin::translate('PLUGIN_ADMIN.DOWNLOAD_BACKUP') . '</a>',
|
||||
'toastr' => [
|
||||
'timeOut' => 0,
|
||||
'extendedTimeOut' => 0,
|
||||
@@ -1433,7 +1371,7 @@ class AdminController extends AdminBaseController
|
||||
|
||||
$backup = $this->grav['uri']->param('backup', null);
|
||||
|
||||
if (!is_null($backup)) {
|
||||
if (null !== $backup) {
|
||||
$file = base64_decode(urldecode($backup));
|
||||
$backups_root_dir = $this->grav['locator']->findResource('backup://', true);
|
||||
|
||||
@@ -1444,7 +1382,7 @@ class AdminController extends AdminBaseController
|
||||
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.BACKUP_DELETED'),
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.BACKUP_DELETED'),
|
||||
'toastr' => [
|
||||
'closeButton' => true
|
||||
]
|
||||
@@ -1452,7 +1390,7 @@ class AdminController extends AdminBaseController
|
||||
} else {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.BACKUP_NOT_FOUND'),
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.BACKUP_NOT_FOUND'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1467,7 +1405,7 @@ class AdminController extends AdminBaseController
|
||||
|
||||
$data = $this->post;
|
||||
|
||||
$rawroute = !empty($data['rawroute']) ? $data['rawroute'] : null;
|
||||
$rawroute = $data['rawroute'] ?? null;
|
||||
|
||||
if ($rawroute) {
|
||||
/** @var Page $page */
|
||||
@@ -1489,7 +1427,7 @@ class AdminController extends AdminBaseController
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'child_type' => '',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.NO_CHILD_TYPE')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.NO_CHILD_TYPE')
|
||||
];
|
||||
|
||||
return true;
|
||||
@@ -1570,7 +1508,7 @@ class AdminController extends AdminBaseController
|
||||
|
||||
$pageTypes = array_keys(Pages::pageTypes());
|
||||
foreach ($pageTypes as $pageType) {
|
||||
if (($pageKey = array_search($pageType, $flags)) !== false) {
|
||||
if (($pageKey = array_search($pageType, $flags, true)) !== false) {
|
||||
$types[] = $pageType;
|
||||
unset($flags[$pageKey]);
|
||||
}
|
||||
@@ -1592,9 +1530,10 @@ class AdminController extends AdminBaseController
|
||||
foreach ($collection as $page) {
|
||||
foreach ($queries as $query) {
|
||||
$query = trim($query);
|
||||
if (stripos($page->getRawContent(), $query) === false && stripos($page->title(),
|
||||
$query) === false && stripos($page->slug(), \Grav\Plugin\Admin\Utils::slug($query)) === false && stripos($page->folder(),
|
||||
$query) === false
|
||||
if (stripos($page->getRawContent(), $query) === false
|
||||
&& stripos($page->title(), $query) === false
|
||||
&& stripos($page->folder(), $query) === false
|
||||
&& stripos($page->slug(), \Grav\Plugin\Admin\Utils::slug($query)) === false
|
||||
) {
|
||||
$collection->remove($page);
|
||||
}
|
||||
@@ -1609,7 +1548,7 @@ class AdminController extends AdminBaseController
|
||||
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.PAGES_FILTERED'),
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.PAGES_FILTERED'),
|
||||
'results' => $results
|
||||
];
|
||||
$this->admin->collection = $collection;
|
||||
@@ -1630,7 +1569,7 @@ class AdminController extends AdminBaseController
|
||||
if (!$media) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.NO_PAGE_FOUND')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.NO_PAGE_FOUND')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1652,7 +1591,12 @@ class AdminController extends AdminBaseController
|
||||
// Get original name
|
||||
$source = $medium->higherQualityAlternative();
|
||||
|
||||
$media_list[$name] = ['url' => $medium->display($medium->get('extension') === 'svg' ? 'source' : 'thumbnail')->cropZoom(400, 300)->url(), 'size' => $medium->get('size'), 'metadata' => $metadata, 'original' => $source->get('filename')];
|
||||
$media_list[$name] = [
|
||||
'url' => $medium->display($medium->get('extension') === 'svg' ? 'source' : 'thumbnail')->cropZoom(400, 300)->url(),
|
||||
'size' => $medium->get('size'),
|
||||
'metadata' => $metadata,
|
||||
'original' => $source->get('filename')
|
||||
];
|
||||
}
|
||||
|
||||
$this->admin->json_response = ['status' => 'success', 'results' => $media_list];
|
||||
@@ -1665,7 +1609,7 @@ class AdminController extends AdminBaseController
|
||||
*/
|
||||
protected function getMedia()
|
||||
{
|
||||
$this->uri = $this->uri ?: $this->grav['uri'];
|
||||
$this->uri = $this->uri ?? $this->grav['uri'];
|
||||
$uri = $this->uri->post('uri');
|
||||
$order = $this->uri->post('order') ?: null;
|
||||
|
||||
@@ -1703,7 +1647,7 @@ class AdminController extends AdminBaseController
|
||||
if (!isset($_FILES['file']['error']) || is_array($_FILES['file']['error'])) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.INVALID_PARAMETERS')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.INVALID_PARAMETERS')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1716,7 +1660,7 @@ class AdminController extends AdminBaseController
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.NO_FILES_SENT')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.NO_FILES_SENT')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1724,21 +1668,21 @@ class AdminController extends AdminBaseController
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.EXCEEDED_FILESIZE_LIMIT')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.EXCEEDED_FILESIZE_LIMIT')
|
||||
];
|
||||
|
||||
return false;
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.UPLOAD_ERR_NO_TMP_DIR')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.UPLOAD_ERR_NO_TMP_DIR')
|
||||
];
|
||||
|
||||
return false;
|
||||
default:
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.UNKNOWN_ERRORS')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.UNKNOWN_ERRORS')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1750,7 +1694,7 @@ class AdminController extends AdminBaseController
|
||||
if (!Utils::checkFilename($filename)) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_UPLOAD'),
|
||||
'message' => sprintf($this->admin::translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_UPLOAD'),
|
||||
$filename, 'Bad filename')
|
||||
];
|
||||
|
||||
@@ -1762,7 +1706,7 @@ class AdminController extends AdminBaseController
|
||||
if ($grav_limit > 0 && $_FILES['file']['size'] > $grav_limit) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.EXCEEDED_GRAV_FILESIZE_LIMIT')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.EXCEEDED_GRAV_FILESIZE_LIMIT')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1776,7 +1720,7 @@ class AdminController extends AdminBaseController
|
||||
if (!$extension || !$config->get("media.types.{$extension}")) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.UNSUPPORTED_FILE_TYPE') . ': ' . $extension
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.UNSUPPORTED_FILE_TYPE') . ': ' . $extension
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1787,7 +1731,7 @@ class AdminController extends AdminBaseController
|
||||
if (!$media) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.NO_PAGE_FOUND')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.NO_PAGE_FOUND')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1801,12 +1745,10 @@ class AdminController extends AdminBaseController
|
||||
}
|
||||
|
||||
// Upload it
|
||||
if (!move_uploaded_file($_FILES['file']['tmp_name'],
|
||||
sprintf('%s/%s', $path, $filename))
|
||||
) {
|
||||
if (!move_uploaded_file($_FILES['file']['tmp_name'], sprintf('%s/%s', $path, $filename))) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.FAILED_TO_MOVE_UPLOADED_FILE')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.FAILED_TO_MOVE_UPLOADED_FILE')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1832,7 +1774,7 @@ class AdminController extends AdminBaseController
|
||||
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_UPLOADED_SUCCESSFULLY'),
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.FILE_UPLOADED_SUCCESSFULLY'),
|
||||
'metadata' => $metadata,
|
||||
];
|
||||
|
||||
@@ -1854,7 +1796,7 @@ class AdminController extends AdminBaseController
|
||||
if (!$media) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.NO_PAGE_FOUND')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.NO_PAGE_FOUND')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1870,7 +1812,7 @@ class AdminController extends AdminBaseController
|
||||
if (!$filename) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.NO_FILE_FOUND')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.NO_FILE_FOUND')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1894,7 +1836,7 @@ class AdminController extends AdminBaseController
|
||||
if (!$result) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_COULD_NOT_BE_DELETED') . ': ' . $filename
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.FILE_COULD_NOT_BE_DELETED') . ': ' . $filename
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1915,7 +1857,7 @@ class AdminController extends AdminBaseController
|
||||
if (!$result) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_COULD_NOT_BE_DELETED') . ': ' . $filename
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.FILE_COULD_NOT_BE_DELETED') . ': ' . $filename
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1928,7 +1870,7 @@ class AdminController extends AdminBaseController
|
||||
if (!$found) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_NOT_FOUND') . ': ' . $filename
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.FILE_NOT_FOUND') . ': ' . $filename
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -1941,7 +1883,7 @@ class AdminController extends AdminBaseController
|
||||
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_DELETED') . ': ' . $filename
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.FILE_DELETED') . ': ' . $filename
|
||||
];
|
||||
|
||||
return true;
|
||||
@@ -1964,7 +1906,7 @@ class AdminController extends AdminBaseController
|
||||
if (!$page) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.NO_PAGE_FOUND')
|
||||
'message' => $this::admin->translate('PLUGIN_ADMIN.NO_PAGE_FOUND')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -2040,7 +1982,7 @@ class AdminController extends AdminBaseController
|
||||
}
|
||||
} elseif ($key === 'taxonomy' && is_array($header[$key])) {
|
||||
foreach ($header[$key] as $taxkey => $taxonomy) {
|
||||
if (is_array($taxonomy) && count($taxonomy) == 1 && trim($taxonomy[0]) == '') {
|
||||
if (is_array($taxonomy) && \count($taxonomy) === 1 && trim($taxonomy[0]) === '') {
|
||||
unset($header[$key][$taxkey]);
|
||||
}
|
||||
}
|
||||
@@ -2139,7 +2081,7 @@ class AdminController extends AdminBaseController
|
||||
$this->grav->fireEvent('onAdminAfterSave', new Event(['page' => $page]));
|
||||
|
||||
// Enqueue message and redirect to new location.
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_COPIED'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_COPIED'), 'info');
|
||||
$this->setRedirect($redirect);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
@@ -2161,13 +2103,13 @@ class AdminController extends AdminBaseController
|
||||
protected function findFirstAvailable($item, $page)
|
||||
{
|
||||
if (!$page->parent()->children()) {
|
||||
return $page->$item();
|
||||
return $page->{$item}();
|
||||
}
|
||||
|
||||
$withoutPrefix = function ($string) {
|
||||
$match = preg_split('/^[0-9]+\./u', $string, 2, PREG_SPLIT_DELIM_CAPTURE);
|
||||
|
||||
return isset($match[1]) ? $match[1] : $match[0];
|
||||
return $match[1] ?? $match[0];
|
||||
};
|
||||
|
||||
$withoutPostfix = function ($string) {
|
||||
@@ -2191,7 +2133,7 @@ class AdminController extends AdminBaseController
|
||||
&$withoutPrefix
|
||||
) {
|
||||
foreach ($siblings as $sibling) {
|
||||
if ($withoutPrefix($sibling->$item()) == ($highest === 1 ? $page_item : $page_item . '-' . $highest)) {
|
||||
if ($withoutPrefix($sibling->{$item}()) == ($highest === 1 ? $page_item : $page_item . '-' . $highest)) {
|
||||
$highest = $findCorrectAppendedNumber($item, $page_item, $highest + 1);
|
||||
|
||||
return $highest;
|
||||
@@ -2229,7 +2171,7 @@ class AdminController extends AdminBaseController
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.REORDERING_WAS_SUCCESSFUL'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.REORDERING_WAS_SUCCESSFUL'), 'info');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -2267,7 +2209,7 @@ class AdminController extends AdminBaseController
|
||||
// Set redirect to either referrer or pages list.
|
||||
$redirect = 'pages';
|
||||
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_DELETED'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_DELETED'), 'info');
|
||||
$this->setRedirect($redirect);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
@@ -2306,7 +2248,7 @@ class AdminController extends AdminBaseController
|
||||
$this->grav['session']->admin_lang = $language ?: 'en';
|
||||
}
|
||||
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_SWITCHED_LANGUAGE'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_SWITCHED_LANGUAGE'), 'info');
|
||||
|
||||
$admin_route = $this->admin->base;
|
||||
$this->setRedirect('/' . $language . $admin_route . '/' . $redirect);
|
||||
@@ -2323,7 +2265,7 @@ class AdminController extends AdminBaseController
|
||||
return false;
|
||||
}
|
||||
|
||||
$file_path = isset($this->data['file_path']) ? $this->data['file_path'] : null ;
|
||||
$file_path = $this->data['file_path'] ?? null;
|
||||
|
||||
if (isset($_FILES['uploaded_file'])) {
|
||||
|
||||
@@ -2332,17 +2274,17 @@ class AdminController extends AdminBaseController
|
||||
case UPLOAD_ERR_OK:
|
||||
break;
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.NO_FILES_SENT'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.NO_FILES_SENT'), 'error');
|
||||
return false;
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.EXCEEDED_FILESIZE_LIMIT'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.EXCEEDED_FILESIZE_LIMIT'), 'error');
|
||||
return false;
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.UPLOAD_ERR_NO_TMP_DIR'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.UPLOAD_ERR_NO_TMP_DIR'), 'error');
|
||||
return false;
|
||||
default:
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.UNKNOWN_ERRORS'), 'error');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.UNKNOWN_ERRORS'), 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2353,7 +2295,7 @@ class AdminController extends AdminBaseController
|
||||
if (!Utils::checkFilename($file_name)) {
|
||||
$this->admin->json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.UNKNOWN_ERRORS')
|
||||
'message' => $this->admin::translate('PLUGIN_ADMIN.UNKNOWN_ERRORS')
|
||||
];
|
||||
|
||||
return false;
|
||||
@@ -2364,9 +2306,9 @@ class AdminController extends AdminBaseController
|
||||
$result = Gpm::directInstall($file_path);
|
||||
|
||||
if ($result === true) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSTALLATION_SUCCESSFUL'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.INSTALLATION_SUCCESSFUL'), 'info');
|
||||
} else {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED') . ': ' . $result,
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.INSTALLATION_FAILED') . ': ' . $result,
|
||||
'error');
|
||||
}
|
||||
|
||||
@@ -2417,7 +2359,7 @@ class AdminController extends AdminBaseController
|
||||
$this->grav->fireEvent('onAdminAfterSave', new Event(['page' => $obj]));
|
||||
}
|
||||
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_SWITCHED_LANGUAGE'), 'info');
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_SWITCHED_LANGUAGE'), 'info');
|
||||
$this->setRedirect('/' . $language . $uri->route());
|
||||
|
||||
return true;
|
||||
|
||||
@@ -10,7 +10,6 @@ use Grav\Common\GPM\Response;
|
||||
use Grav\Common\GPM\Upgrader;
|
||||
use Grav\Common\Filesystem\Folder;
|
||||
use Grav\Common\GPM\Common\Package;
|
||||
use Grav\Plugin\Admin\Admin;
|
||||
|
||||
/**
|
||||
* Class Gpm
|
||||
@@ -90,11 +89,11 @@ class Gpm
|
||||
// Check destination
|
||||
Installer::isValidDestination($options['destination'] . DS . $package->install_path);
|
||||
|
||||
if (Installer::lastErrorCode() === Installer::EXISTS && !$options['overwrite']) {
|
||||
if (!$options['overwrite'] && Installer::lastErrorCode() === Installer::EXISTS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Installer::lastErrorCode() === Installer::IS_LINK && !$options['ignore_symlinks']) {
|
||||
if (!$options['ignore_symlinks'] && Installer::lastErrorCode() === Installer::IS_LINK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -147,7 +146,7 @@ class Gpm
|
||||
{
|
||||
$options = array_merge(self::$options, $options);
|
||||
|
||||
$packages = is_array($packages) ? $packages : [$packages];
|
||||
$packages = (array)$packages;
|
||||
$count = count($packages);
|
||||
|
||||
$packages = array_filter(array_map(function ($p) {
|
||||
@@ -312,10 +311,10 @@ class Gpm
|
||||
$tmp_dir = Admin::getTempDir() . '/Grav-' . uniqid();
|
||||
Folder::mkdir($tmp_dir);
|
||||
|
||||
$bad_chars = array_merge(array_map('chr', range(0, 31)), ["<", ">", ":", '"', "/", "\\", "|", "?", "*"]);
|
||||
$bad_chars = array_merge(array_map('chr', range(0, 31)), ['<', '>', ':', '"', '/', '\\', '|', '?', '*']);
|
||||
|
||||
$filename = $package->slug . str_replace($bad_chars, "", basename($package->zipball_url));
|
||||
$filename = preg_replace('/[\\\\\/:"*?&<>|]+/mi', '-', $filename);
|
||||
$filename = $package->slug . str_replace($bad_chars, '', basename($package->zipball_url));
|
||||
$filename = preg_replace('/[\\\\\/:"*?&<>|]+/m', '-', $filename);
|
||||
|
||||
file_put_contents($tmp_dir . DS . $filename . '.zip', $contents);
|
||||
|
||||
|
||||
@@ -123,8 +123,10 @@ class Popularity
|
||||
$labels = [];
|
||||
$data = [];
|
||||
|
||||
/** @var Admin $admin */
|
||||
$admin = Grav::instance()['admin'];
|
||||
foreach ($chart_data as $date => $count) {
|
||||
$labels[] = Grav::instance()['grav']['admin']->translate([
|
||||
$labels[] = $admin::translate([
|
||||
'PLUGIN_ADMIN.' . strtoupper(date('D', strtotime($date)))]) .
|
||||
'<br>' . date('M d', strtotime($date));
|
||||
$data[] = $count;
|
||||
|
||||
Reference in New Issue
Block a user