diff --git a/admin.php b/admin.php index 53b41434..4d0896f4 100644 --- a/admin.php +++ b/admin.php @@ -75,12 +75,13 @@ class AdminPlugin extends Plugin { if (!Grav::instance()['config']->get('plugins.admin-pro.enabled')) { return [ - 'onPluginsInitialized' => [['setup', 100000], ['onPluginsInitialized', 1001]], - 'onShutdown' => ['onShutdown', 1000], - 'onFormProcessed' => ['onFormProcessed', 0], - 'onAdminDashboard' => ['onAdminDashboard', 0], + 'onPluginsInitialized' => [['setup', 100000], ['onPluginsInitialized', 1001]], + 'onShutdown' => ['onShutdown', 1000], + 'onFormProcessed' => ['onFormProcessed', 0], + 'onAdminDashboard' => ['onAdminDashboard', 0], ]; } + return []; } @@ -123,9 +124,9 @@ class AdminPlugin extends Plugin * - 'password1' for password format * - 'password2' for equality to password1 * - * @param string $type The field type - * @param string $value The field value - * @param string $extra Any extra value required + * @param string $type The field type + * @param string $value The field value + * @param string $extra Any extra value required * * @return bool */ @@ -136,18 +137,21 @@ class AdminPlugin extends Plugin if (!preg_match('/^[a-z0-9_-]{3,16}$/', $value)) { return false; } + return true; case 'password1': if (!preg_match('/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/', $value)) { return false; } + return true; case 'password2': if (strcmp($value, $extra)) { return false; } + return true; } @@ -176,12 +180,12 @@ class AdminPlugin extends Plugin $username = $form->value('username'); if ($form->value('password1') != $form->value('password2')) { - $this->grav->fireEvent('onFormValidationError', - new Event([ - 'form' => $form, + $this->grav->fireEvent('onFormValidationError', new Event([ + 'form' => $form, 'message' => $this->grav['language']->translate('PLUGIN_LOGIN.PASSWORDS_DO_NOT_MATCH') ])); $event->stopPropagation(); + return; } @@ -193,7 +197,7 @@ class AdminPlugin extends Plugin 'title' ]; - foreach($fields as $field) { + foreach ($fields as $field) { // Process value of field if set in the page process.register_user if (!isset($data[$field]) && $form->value($field)) { $data[$field] = $form->value($field); @@ -216,9 +220,10 @@ class AdminPlugin extends Plugin $data['state'] = 'enabled'; $data['access'] = ['admin' => ['login' => true, 'super' => true], 'site' => ['login' => true]]; - // Create user object and save it + // Create user object and save it $user = new User($data); - $file = CompiledYamlFile::instance($this->grav['locator']->findResource('user://accounts/' . $username . YAML_EXT, true, true)); + $file = CompiledYamlFile::instance($this->grav['locator']->findResource('user://accounts/' . $username . YAML_EXT, + true, true)); $user->file($file); $user->save(); $user = User::load($username); @@ -255,11 +260,12 @@ class AdminPlugin extends Plugin // Test for correct Grav 1.1 version if (version_compare(GRAV_VERSION, '1.1.0-beta.1', '<')) { $messages = $this->grav['messages']; - $messages->add($this->grav['language']->translate(['PLUGIN_ADMIN.NEEDS_GRAV_1_1', GRAV_VERSION]), 'error'); + $messages->add($this->grav['language']->translate(['PLUGIN_ADMIN.NEEDS_GRAV_1_1', GRAV_VERSION]), + 'error'); } // Have a unique Admin-only Cache key - if (method_exists($this->grav['cache'], 'setKey')){ + if (method_exists($this->grav['cache'], 'setKey')) { $cache = $this->grav['cache']; $cache_key = $cache->getKey(); $cache->setKey($cache_key . '$'); @@ -272,13 +278,14 @@ class AdminPlugin extends Plugin if (php_sapi_name() == 'cli-server') { - throw new \RuntimeException('The Admin Plugin cannot run on the PHP built-in webserver. It needs Apache, Nginx or another full-featured web server.', 500); + throw new \RuntimeException('The Admin Plugin cannot run on the PHP built-in webserver. It needs Apache, Nginx or another full-featured web server.', + 500); } $this->grav['debugger']->addMessage("Admin Basic"); $this->initializeAdmin(); // Disable Asset pipelining (old method - remove this after Grav is updated) - if (!method_exists($this->grav['assets'],'setJsPipeline')) { + if (!method_exists($this->grav['assets'], 'setJsPipeline')) { $this->config->set('system.assets.css_pipeline', false); $this->config->set('system.assets.js_pipeline', false); } @@ -286,6 +293,7 @@ class AdminPlugin extends Plugin // Replace themes service with admin. $this->grav['themes'] = function () { require_once __DIR__ . '/classes/themes.php'; + return new Themes($this->grav); }; } @@ -298,7 +306,8 @@ class AdminPlugin extends Plugin $this->grav->fireEvent('onAdminRegisterPermissions', new Event(['admin' => $this->admin])); } - protected function initializeController($task, $post) { + protected function initializeController($task, $post) + { require_once __DIR__ . '/classes/controller.php'; $controller = new AdminController($this->grav, $this->template, $task, $this->route, $post); $controller->execute(); @@ -343,7 +352,7 @@ class AdminPlugin extends Plugin } // Make local copy of POST. - $post = !empty($_POST) ? $_POST : array(); + $post = !empty($_POST) ? $_POST : []; // Handle tasks. $this->admin->task = $task = !empty($post['task']) ? $post['task'] : $this->uri->param('task'); @@ -370,6 +379,7 @@ class AdminPlugin extends Plugin if (file_exists(__DIR__ . "/pages/admin/{$self->template}.md")) { $page->init(new \SplFileInfo(__DIR__ . "/pages/admin/{$self->template}.md")); $page->slug(basename($self->template)); + return $page; } @@ -377,13 +387,13 @@ class AdminPlugin extends Plugin $plugins = $this->grav['plugins']; $locator = $this->grav['locator']; - foreach($plugins as $plugin) { - $path = $locator->findResource( - "user://plugins/{$plugin->name}/admin/pages/{$self->template}.md"); + foreach ($plugins as $plugin) { + $path = $locator->findResource("user://plugins/{$plugin->name}/admin/pages/{$self->template}.md"); if ($path) { $page->init(new \SplFileInfo($path)); $page->slug(basename($self->template)); + return $page; } } @@ -407,7 +417,7 @@ class AdminPlugin extends Plugin } // Explicitly set a timestamp on assets - $this->grav['assets']->setTimestamp(substr(md5(GRAV_VERSION . $this->grav['config']->checksum()),0,10)); + $this->grav['assets']->setTimestamp(substr(md5(GRAV_VERSION . $this->grav['config']->checksum()), 0, 10)); } /** @@ -445,9 +455,9 @@ class AdminPlugin extends Plugin $twig->twig_vars['location'] = $this->template; $twig->twig_vars['base_url_relative_frontend'] = $twig->twig_vars['base_url_relative'] ?: '/'; $twig->twig_vars['admin_route'] = trim($this->config->get('plugins.admin.route'), '/'); - $twig->twig_vars['base_url_relative'] = - $twig->twig_vars['base_url_simple'] . '/' . $twig->twig_vars['admin_route']; - $twig->twig_vars['theme_url'] = $this->grav['locator']->findResource('plugin://admin/themes/' . $this->theme, false); + $twig->twig_vars['base_url_relative'] = $twig->twig_vars['base_url_simple'] . '/' . $twig->twig_vars['admin_route']; + $twig->twig_vars['theme_url'] = $this->grav['locator']->findResource('plugin://admin/themes/' . $this->theme, + false); $twig->twig_vars['base_url'] = $twig->twig_vars['base_url_relative']; $twig->twig_vars['base_path'] = GRAV_ROOT; $twig->twig_vars['admin'] = $this->admin; @@ -498,7 +508,7 @@ class AdminPlugin extends Plugin } $action = $_POST['action']; // getUpdatable | getUpdatablePlugins | getUpdatableThemes | gravUpdates - $flush = isset($_POST['flush']) && $_POST['flush'] == true ? true : false; + $flush = isset($_POST['flush']) && $_POST['flush'] == true ? true : false; if (isset($this->grav['session'])) { $this->grav['session']->close(); @@ -521,8 +531,13 @@ class AdminPlugin extends Plugin ]; echo json_encode([ - "status" => "success", - "payload" => ["resources" => $resources_updates, "grav" => $grav_updates, "installed" => $gpm->countInstalled(), 'flushed' => $flush] + "status" => "success", + "payload" => [ + "resources" => $resources_updates, + "grav" => $grav_updates, + "installed" => $gpm->countInstalled(), + 'flushed' => $flush + ] ]); } else { echo json_encode(["status" => "error", "message" => "Cannot connect to the GPM"]); @@ -544,28 +559,28 @@ class AdminPlugin extends Plugin public function getFormFieldTypes() { return [ - 'column' => [ + 'column' => [ 'input@' => false ], - 'columns' => [ + 'columns' => [ 'input@' => false ], 'fieldset' => [ 'input@' => false ], - 'section' => [ + 'section' => [ 'input@' => false ], - 'tab' => [ + 'tab' => [ 'input@' => false ], - 'tabs' => [ + 'tabs' => [ 'input@' => false ], - 'key' => [ + 'key' => [ 'input@' => false ], - 'list' => [ + 'list' => [ 'array' => true ] ]; @@ -579,12 +594,12 @@ class AdminPlugin extends Plugin protected function initializeAdmin() { $this->enable([ - 'onTwigExtensions' => ['onTwigExtensions', 1000], - 'onPagesInitialized' => ['onPagesInitialized', 1000], - 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 1000], - 'onTwigSiteVariables' => ['onTwigSiteVariables', 1000], - 'onAssetsInitialized' => ['onAssetsInitialized', 1000], - 'onTask.GPM' => ['onTaskGPM', 0], + 'onTwigExtensions' => ['onTwigExtensions', 1000], + 'onPagesInitialized' => ['onPagesInitialized', 1000], + 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 1000], + 'onTwigSiteVariables' => ['onTwigSiteVariables', 1000], + 'onAssetsInitialized' => ['onAssetsInitialized', 1000], + 'onTask.GPM' => ['onTaskGPM', 0], 'onAdminRegisterPermissions' => ['onAdminRegisterPermissions', 0], ]); @@ -592,9 +607,7 @@ class AdminPlugin extends Plugin require_once __DIR__ . '/classes/admin.php'; // Check for required plugins - if (!$this->grav['config']->get('plugins.login.enabled') || - !$this->grav['config']->get('plugins.form.enabled') || - !$this->grav['config']->get('plugins.email.enabled')) { + if (!$this->grav['config']->get('plugins.login.enabled') || !$this->grav['config']->get('plugins.form.enabled') || !$this->grav['config']->get('plugins.email.enabled')) { throw new \RuntimeException('One of the required plugins is missing or not enabled'); } @@ -638,13 +651,14 @@ class AdminPlugin extends Plugin $this->theme = $this->config->get('plugins.admin.theme', 'grav'); $assets = $this->grav['assets']; - $translations = 'this.GravAdmin = this.GravAdmin || {}; if (!this.GravAdmin.translations) this.GravAdmin.translations = {}; ' . PHP_EOL . 'this.GravAdmin.translations.PLUGIN_ADMIN = {'; + $translations = 'this.GravAdmin = this.GravAdmin || {}; if (!this.GravAdmin.translations) this.GravAdmin.translations = {}; ' . PHP_EOL . 'this.GravAdmin.translations.PLUGIN_ADMIN = {'; // Enable language translations $translations_actual_state = $this->config->get('system.languages.translations'); $this->config->set('system.languages.translations', true); - $strings = ['EVERYTHING_UP_TO_DATE', + $strings = [ + 'EVERYTHING_UP_TO_DATE', 'UPDATES_ARE_AVAILABLE', 'IS_AVAILABLE_FOR_UPDATE', 'AND', @@ -703,9 +717,9 @@ class AdminPlugin extends Plugin 'TO' ]; - foreach($strings as $string) { + foreach ($strings as $string) { $separator = (end($strings) === $string) ? '' : ','; - $translations .= '"' . $string .'": "' . $this->admin->translate('PLUGIN_ADMIN.' . $string) . '"' . $separator; + $translations .= '"' . $string . '": "' . $this->admin->translate('PLUGIN_ADMIN.' . $string) . '"' . $separator; } $translations .= '};'; @@ -720,7 +734,7 @@ class AdminPlugin extends Plugin */ public function onTwigExtensions() { - require_once(__DIR__.'/twig/AdminTwigExtension.php'); + require_once(__DIR__ . '/twig/AdminTwigExtension.php'); $this->grav['twig']->twig->addExtension(new AdminTwigExtension()); } @@ -731,10 +745,12 @@ class AdminPlugin extends Plugin */ public function isAdminPath() { - if ($this->uri->route() == $this->base || - substr($this->uri->route(), 0, strlen($this->base) + 1) == $this->base . '/') { + if ($this->uri->route() == $this->base || substr($this->uri->route(), 0, + strlen($this->base) + 1) == $this->base . '/' + ) { return true; } + return false; } @@ -754,17 +770,17 @@ class AdminPlugin extends Plugin { $admin = $e['admin']; $permissions = [ - 'admin.super'=> 'boolean', - 'admin.login' => 'boolean', - 'admin.cache' => 'boolean', - 'admin.configuration' => 'boolean', - 'admin.settings' => 'boolean', - 'admin.pages' => 'boolean', - 'admin.maintenance' => 'boolean', - 'admin.statistics' => 'boolean', - 'admin.plugins' => 'boolean', - 'admin.themes' => 'boolean', - 'admin.users' => 'boolean', + 'admin.super' => 'boolean', + 'admin.login' => 'boolean', + 'admin.cache' => 'boolean', + 'admin.configuration' => 'boolean', + 'admin.settings' => 'boolean', + 'admin.pages' => 'boolean', + 'admin.maintenance' => 'boolean', + 'admin.statistics' => 'boolean', + 'admin.plugins' => 'boolean', + 'admin.themes' => 'boolean', + 'admin.users' => 'boolean', ]; $admin->addPermissions($permissions); } diff --git a/classes/admin.php b/classes/admin.php index 0a1e29e0..44e118c6 100644 --- a/classes/admin.php +++ b/classes/admin.php @@ -40,7 +40,7 @@ class Admin /** * @var array */ - protected $pages = array(); + protected $pages = []; /** * @var Session @@ -106,7 +106,7 @@ class Admin $this->user = $this->grav['user']; $this->permissions = []; $language = $this->grav['language']; - + // Load utility class require_once __DIR__ . '/utils.php'; @@ -306,7 +306,9 @@ class Admin $plugins = $this->grav['plugins']; $obj = $plugins->get(preg_replace('|plugins/|', '', $type)); - if (!$obj) { return []; } + if (!$obj) { + return []; + } $obj->merge($post); $obj->file($file); @@ -317,7 +319,9 @@ class Admin $themes = $this->grav['themes']; $obj = $themes->get(preg_replace('|themes/|', '', $type)); - if (!$obj) { return []; } + if (!$obj) { + return []; + } $obj->merge($post); $obj->file($file); @@ -363,7 +367,8 @@ class Admin if (!$this->gpm) { try { $this->gpm = new GPM(); - } catch (\Exception $e) {} + } catch (\Exception $e) { + } } return $this->gpm; @@ -400,6 +405,7 @@ class Admin } else { $routes = $pages->routes(); } + return $routes; } @@ -488,7 +494,7 @@ class Admin * Generate an array of dependencies for a package, used to generate a list of * packages that can be removed when removing a package. * - * @param string $slug The package slug + * @param string $slug The package slug * * @return array|bool */ @@ -525,7 +531,7 @@ class Admin /** * Get list of packages that depend on the passed package slug * - * @param string $slug The package slug + * @param string $slug The package slug * * @return array|bool */ @@ -615,9 +621,9 @@ class Admin /** @var Pages $pages */ $pages = $this->grav['pages']; - $latest = array(); + $latest = []; - if(is_null($pages->routes())){ + if (is_null($pages->routes())) { return null; } @@ -638,7 +644,7 @@ class Admin }); // build new array with just pages in it - $list = array(); + $list = []; foreach ($latest as $item) { $list[] = $item['page']; } @@ -715,7 +721,7 @@ class Admin return null; } - $ppath = str_replace('\\', '/' , dirname($path)); + $ppath = str_replace('\\', '/', dirname($path)); // Find or create parent(s). $parent = $this->getPage($ppath != '/' ? $ppath : ''); @@ -799,6 +805,7 @@ class Admin $languages[$lang] = LanguageCodes::getNativeName($lang); } + return $languages; } @@ -837,6 +844,7 @@ class Admin foreach ($lang_data as $index => $lang) { $languages[$lang] = LanguageCodes::getNativeName($lang); } + return $languages; } @@ -869,6 +877,7 @@ class Admin public static function getNonce() { $action = 'admin-form'; + return Utils::getNonce($action); } @@ -922,6 +931,7 @@ class Admin ob_end_clean(); $pinfo = preg_replace('%^.*
(.*).*$%ms', '$1', $pinfo); + return $pinfo; } else { return 'phpinfo() method is not available on this server.'; @@ -933,7 +943,8 @@ class Admin * * @param array|mixed $args * - * @param mixed $languages + * @param mixed $languages + * * @return string */ public function translate($args, $languages = null) @@ -948,7 +959,7 @@ class Admin if (!$languages) { $languages = [$this->grav['user']->authenticated ? $this->grav['user']->language : 'en']; } else { - $languages = (array) $languages; + $languages = (array)$languages; } @@ -991,6 +1002,7 @@ class Admin * Guest date format based on euro/US * * @param $date + * * @return string */ public function guessDateFormat($date) @@ -1045,16 +1057,18 @@ class Admin public function validateDate($date, $format) { $d = DateTime::createFromFormat($format, $date); + return $d && $d->format($format) == $date; } /** * @param string $php_format + * * @return string */ public function dateformatToMomentJS($php_format) { - $SYMBOLS_MATCHING = array( + $SYMBOLS_MATCHING = [ // Day 'd' => 'DD', 'D' => 'ddd', @@ -1099,28 +1113,33 @@ class Admin 'c' => '', 'r' => 'llll ZZ', 'U' => 'X' - ); + ]; $js_format = ""; $escaping = false; - for($i = 0; $i < strlen($php_format); $i++) - { + for ($i = 0; $i < strlen($php_format); $i++) { $char = $php_format[$i]; - if($char === '\\') // PHP date format escaping character + if ($char === '\\') // PHP date format escaping character { $i++; - if($escaping) $js_format .= $php_format[$i]; - else $js_format .= '\'' . $php_format[$i]; + if ($escaping) { + $js_format .= $php_format[$i]; + } else { + $js_format .= '\'' . $php_format[$i]; + } $escaping = true; - } - else - { - if($escaping) { $js_format .= "'"; $escaping = false; } - if(isset($SYMBOLS_MATCHING[$char])) + } else { + if ($escaping) { + $js_format .= "'"; + $escaping = false; + } + if (isset($SYMBOLS_MATCHING[$char])) { $js_format .= $SYMBOLS_MATCHING[$char]; - else + } else { $js_format .= $char; + } } } + return $js_format; } @@ -1167,6 +1186,7 @@ class Admin } } } + return $found_fields; } @@ -1176,7 +1196,7 @@ class Admin $basename = ''; if (isset($path_parts['extension'])) { - $basename = '/'.$path_parts['basename']; + $basename = '/' . $path_parts['basename']; $path = $path_parts['dirname']; } @@ -1196,7 +1216,8 @@ class Admin // theme@ $parts = explode(':', $path); $route = $parts[1]; - $theme = str_replace(ROOT_DIR, '', $this->grav['locator']->findResource("theme://")); + $theme = str_replace(ROOT_DIR, '', $this->grav['locator']->findResource("theme://")); + return $theme . $route . $basename; } } else { diff --git a/classes/controller.php b/classes/controller.php index d2363a85..6d8e6462 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -85,11 +85,11 @@ class AdminController ]; /** - * @param Grav $grav + * @param Grav $grav * @param string $view * @param string $task * @param string $route - * @param array $post + * @param array $post */ public function __construct(Grav $grav, $view, $task, $route, $post) { @@ -126,11 +126,12 @@ class AdminController if (!$nonce || !Utils::verifyNonce($nonce, 'admin-form')) { if ($this->task == 'addmedia') { - $message = sprintf($this->admin->translate('PLUGIN_ADMIN.FILE_TOO_LARGE', null, true), ini_get('post_max_size')); + $message = sprintf($this->admin->translate('PLUGIN_ADMIN.FILE_TOO_LARGE', null, true), + ini_get('post_max_size')); //In this case it's more likely that the image is too big than POST can handle. Show message $this->admin->json_response = [ - 'status' => 'error', + 'status' => 'error', 'message' => $message ]; @@ -139,7 +140,7 @@ class AdminController $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'), 'error'); $this->admin->json_response = [ - 'status' => 'error', + 'status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN') ]; @@ -153,7 +154,7 @@ class AdminController $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'), 'error'); $this->admin->json_response = [ - 'status' => 'error', + 'status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN') ]; @@ -165,7 +166,7 @@ class AdminController $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'), 'error'); $this->admin->json_response = [ - 'status' => 'error', + 'status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN') ]; @@ -324,6 +325,7 @@ class AdminController } $this->admin->json_response = ['status' => 'success', 'reload' => $reload]; + return true; } @@ -350,10 +352,12 @@ class AdminController $dependencies = $this->admin->getDependenciesNeededToInstall($packages); } catch (\Exception $e) { $this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()]; + return; } $this->admin->json_response = ['status' => 'success', 'dependencies' => $dependencies]; + return true; } @@ -366,7 +370,11 @@ class AdminController $type = isset($data['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')]; + $this->admin->json_response = [ + 'status' => 'error', + 'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') + ]; + return false; } @@ -376,6 +384,7 @@ class AdminController $dependencies = $this->admin->getDependenciesNeededToInstall($packages); } catch (\Exception $e) { $this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()]; + return; } @@ -384,7 +393,10 @@ class AdminController if ($result) { $this->admin->json_response = ['status' => 'success', 'message' => 'Dependencies installed successfully']; } else { - $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED')]; + $this->admin->json_response = [ + 'status' => 'error', + 'message' => $this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED') + ]; } return true; @@ -397,7 +409,11 @@ class AdminController $type = isset($data['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')]; + $this->admin->json_response = [ + 'status' => 'error', + 'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') + ]; + return false; } @@ -409,13 +425,21 @@ class AdminController $result = \Grav\Plugin\Admin\Gpm::install($package, ['theme' => ($type == 'theme')]); } catch (\Exception $e) { $this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()]; + return; } if ($result) { - $this->admin->json_response = ['status' => 'success', 'message' => $this->admin->translate(is_string($result) ? $result : sprintf($this->admin->translate('PLUGIN_ADMIN.PACKAGE_X_INSTALLED_SUCCESSFULLY', null, true), $package))]; + $this->admin->json_response = [ + 'status' => 'success', + 'message' => $this->admin->translate(is_string($result) ? $result : sprintf($this->admin->translate('PLUGIN_ADMIN.PACKAGE_X_INSTALLED_SUCCESSFULLY', + null, true), $package)) + ]; } else { - $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED')]; + $this->admin->json_response = [ + 'status' => 'error', + 'message' => $this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED') + ]; } return true; @@ -433,7 +457,11 @@ class AdminController $type = isset($data['type']) ? $data['type'] : ''; if (!$this->authorizeTask('uninstall ' . $type, ['admin.' . $type, 'admin.super'])) { - $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')]; + $this->admin->json_response = [ + 'status' => 'error', + 'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') + ]; + return false; } @@ -443,12 +471,15 @@ class AdminController $dependent_packages = $this->admin->getPackagesThatDependOnPackage($package); if (count($dependent_packages) > 0) { if (count($dependent_packages) > 1) { - $message = "The installed packagesGrav has increased the minimum PHP requirement.
';
- $error[] = 'You are currently running PHP ' . PHP_VERSION .'';
- $error[] = ', but PHP ' . GRAV_PHP_MIN .' is required.