Auto lint

This commit is contained in:
Flavio Copes
2017-02-26 19:36:01 +01:00
parent ec2821183a
commit 47beb2d5a6
6 changed files with 115 additions and 96 deletions

View File

@@ -193,6 +193,7 @@ class Admin
{
$tools = [];
$event = Grav::instance()->fireEvent('onAdminTools', new Event(['tools' => &$tools]));
return $tools;
}
@@ -273,6 +274,7 @@ class Admin
} catch (\Exception $e) {
$tmp_dir = Grav::instance()['locator']->findResource('cache://', true, true) . '/tmp';
}
return $tmp_dir;
}
@@ -349,6 +351,7 @@ class Admin
$this->setMessage($this->translate('PLUGIN_ADMIN.LOGIN_LOGGED_IN'), 'info');
$grav->redirect($post['redirect']);
return true; //never reached
}
@@ -1149,7 +1152,8 @@ class Admin
require_once(__DIR__ . '/../twig/AdminTwigExtension.php');
$adminTwigExtension = new AdminTwigExtension();
$filename = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT, true, true);
$filename = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT,
true, true);
$read_notifications = CompiledYamlFile::instance($filename)->content();
$notifications_processed = [];
@@ -1196,6 +1200,7 @@ class Admin
// Process notifications
$notifications_processed = array_map(function ($notification) use ($adminTwigExtension) {
$notification->date = $adminTwigExtension->adminNicetimeFilter($notification->date);
return $notification;
}, $notifications_processed);
@@ -1373,8 +1378,7 @@ class Admin
$type = $parent->childType()
? $parent->childType()
: $parent->blueprints()->get('child_type',
'default')
;
'default');
$page->name($type . CONTENT_EXT);
$page->header();
}
@@ -1409,6 +1413,7 @@ class Admin
$string = strip_tags($content);
$string = htmlspecialchars_decode($string, ENT_QUOTES);
$string = str_replace("\n", ' ', $string);
return trim($string);
}

View File

@@ -105,7 +105,8 @@ class AdminBaseController
$this->admin->setMessage($e->getMessage(), 'error');
}
} else {
$success = $this->grav->fireEvent('onAdminTaskExecute', new Event(['controller' => $this, 'method' => $method]));
$success = $this->grav->fireEvent('onAdminTaskExecute',
new Event(['controller' => $this, 'method' => $method]));
}
// Grab redirect parameter.
@@ -182,6 +183,7 @@ class AdminBaseController
}
}
}
return true;
}
@@ -213,16 +215,13 @@ class AdminBaseController
$config = $this->grav['config'];
$data = $this->view == 'pages' ? $this->admin->page(true) : $this->prepareData([]);
$settings = $data->blueprints()->schema()->getProperty($this->post['name']);
$settings = (object)array_merge(
['avoid_overwriting' => false,
$settings = (object)array_merge([
'avoid_overwriting' => false,
'random_name' => false,
'accept' => ['image/*'],
'limit' => 10,
'filesize' => $config->get('system.media.upload_limit', 5242880) // 5MB
],
(array)$settings,
['name' => $this->post['name']]
);
], (array)$settings, ['name' => $this->post['name']]);
$upload = $this->normalizeFiles($_FILES['data'], $settings->name);
@@ -239,7 +238,8 @@ class AdminBaseController
if ($this->view != 'pages' && in_array($settings->destination, ['@self', 'self@'])) {
$this->admin->json_response = [
'status' => 'error',
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_PREVENT_SELF', null), $settings->destination)
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_PREVENT_SELF', null),
$settings->destination)
];
return false;
@@ -249,8 +249,8 @@ 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), $upload->file->name,
$this->upload_errors[$upload->file->error])
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_UPLOAD', null),
$upload->file->name, $this->upload_errors[$upload->file->error])
];
return false;
@@ -269,7 +269,8 @@ 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), '', $tmp)
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_MOVE', null), '',
$tmp)
];
return false;
@@ -539,6 +540,7 @@ class AdminBaseController
}
$this->admin->json_response = ['status' => 'success'];
return true;
}
@@ -565,8 +567,7 @@ class AdminBaseController
// now the first 4 chars of base contain the lang code.
// if redirect path already contains the lang code, and is != than the base lang code, then use redirect path as-is
if (Utils::pathPrefixedByLangCode($base) && Utils::pathPrefixedByLangCode($this->redirect)
&& substr($base,
if (Utils::pathPrefixedByLangCode($base) && Utils::pathPrefixedByLangCode($this->redirect) && substr($base,
0, 4) != substr($this->redirect, 0, 4)
) {
$redirect = $this->redirect;
@@ -674,8 +675,8 @@ class AdminBaseController
foreach ($queue as $key => $files) {
foreach ($files as $destination => $file) {
if (!rename($file['tmp_name'], $destination)) {
throw new \RuntimeException(sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_MOVE', null),
'"' . $file['tmp_name'] . '"', $destination));
throw new \RuntimeException(sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_MOVE',
null), '"' . $file['tmp_name'] . '"', $destination));
}
unset($files[$destination]['tmp_name']);
@@ -691,7 +692,8 @@ class AdminBaseController
$new_data = $files;
}
if (isset($data['header'][$init_key])) {
$obj->modifyHeader($init_key, array_replace_recursive([], $data['header'][$init_key], $new_data));
$obj->modifyHeader($init_key,
array_replace_recursive([], $data['header'][$init_key], $new_data));
} else {
$obj->modifyHeader($init_key, $new_data);
}
@@ -730,6 +732,7 @@ class AdminBaseController
'status' => 'error',
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_PREVENT_SELF', null), $folder)
];
return false;
}

View File

@@ -13,8 +13,6 @@ use Grav\Common\Page\Media;
use Grav\Common\Page\Page;
use Grav\Common\Page\Pages;
use Grav\Common\Page\Collection;
use Grav\Common\Plugin;
use Grav\Common\Theme;
use Grav\Common\User\User;
use Grav\Common\Utils;
use Grav\Common\Backup\ZipBackup;
@@ -446,6 +444,7 @@ class AdminController extends AdminBaseController
if ($this->prepareData($data)->username !== $this->grav['user']->username) {
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' save.',
'error');
return false;
}
}
@@ -587,7 +586,9 @@ class AdminController extends AdminBaseController
$topParent = $obj->topParent();
if (isset($topParent)) {
$top_parent_route = (string)$topParent->route();
if ($top_parent_route == $home_route && substr($route, 0, strlen($top_parent_route) + 1) != ($top_parent_route . '/')) {
if ($top_parent_route == $home_route && substr($route, 0,
strlen($top_parent_route) + 1) != ($top_parent_route . '/')
) {
$route = $top_parent_route . $route;
}
}
@@ -776,9 +777,8 @@ class AdminController extends AdminBaseController
foreach ($feed_items as $item) {
$datetime = $adminTwigExtension->adminNicetimeFilter($item->getDate()->getTimestamp());
$feed_data[] =
'<li><span class="date">' . $datetime . '</span> <a href="' . $item->getUrl() . '" target="_blank" title="' . str_replace('"', '″',
$item->getTitle()) . '">' . $item->getTitle() . '</a></li>';
$feed_data[] = '<li><span class="date">' . $datetime . '</span> <a href="' . $item->getUrl() . '" target="_blank" title="' . str_replace('"',
'″', $item->getTitle()) . '">' . $item->getTitle() . '</a></li>';
}
}
@@ -787,6 +787,7 @@ class AdminController extends AdminBaseController
} catch (\Exception $e) {
$this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()];
return;
}
}
@@ -849,6 +850,7 @@ class AdminController extends AdminBaseController
if (!(bool)$this->grav['config']->get('system.cache.enabled') || !$notifications = $cache->fetch('notifications')) {
//No notifications cache (first time)
$this->admin->json_response = ['status' => 'success', 'notifications' => [], 'need_update' => true];
return;
}
@@ -865,10 +867,15 @@ class AdminController extends AdminBaseController
$notifications = $this->admin->processNotifications($notifications);
} catch (\Exception $e) {
$this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()];
return;
}
$this->admin->json_response = ['status' => 'success', 'notifications' => $notifications, 'need_update' => $need_update];
$this->admin->json_response = [
'status' => 'success',
'notifications' => $notifications,
'need_update' => $need_update
];
}
/**
@@ -887,6 +894,7 @@ class AdminController extends AdminBaseController
$notifications = $this->admin->processNotifications($notifications);
} catch (\Exception $e) {
$this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()];
return false;
}
@@ -898,7 +906,12 @@ class AdminController extends AdminBaseController
$cache->save('notifications', $notifications);
$cache->save('notifications_last_checked', time());
$this->admin->json_response = ['status' => 'success', 'notifications' => $notifications, 'show_immediately' => $show_immediately];
$this->admin->json_response = [
'status' => 'success',
'notifications' => $notifications,
'show_immediately' => $show_immediately
];
return true;
}
@@ -992,18 +1005,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' : 'PLUGIN_ADMIN.PACKAGE_X_INSTALLED_SUCCESSFULLY'
, null), $package))
'message' => $this->admin->translate(is_string($result) ? $result : sprintf($this->admin->translate($reinstall ? 'PLUGIN_ADMIN.PACKAGE_X_REINSTALLED_SUCCESSFULLY' : 'PLUGIN_ADMIN.PACKAGE_X_INSTALLED_SUCCESSFULLY',
null), $package))
];
} else {
$this->admin->json_response = [
'status' => 'error',
'message' => $this->admin->translate(
$reinstall ? 'PLUGIN_ADMIN.REINSTALLATION_FAILED' : 'PLUGIN_ADMIN.INSTALLATION_FAILED'
)
'message' => $this->admin->translate($reinstall ? 'PLUGIN_ADMIN.REINSTALLATION_FAILED' : 'PLUGIN_ADMIN.INSTALLATION_FAILED')
];
}
@@ -1026,7 +1034,8 @@ class AdminController extends AdminBaseController
'status' => 'error',
'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')
];
echo json_encode($json_response);exit;
echo json_encode($json_response);
exit;
}
//check if there are packages that have this as a dependency. Abort and show which ones
@@ -1041,7 +1050,8 @@ class AdminController extends AdminBaseController
}
$json_response = ['status' => 'error', 'message' => $message];
echo json_encode($json_response);exit;
echo json_encode($json_response);
exit;
}
try {
@@ -1049,7 +1059,8 @@ class AdminController extends AdminBaseController
$result = Gpm::uninstall($package, []);
} catch (\Exception $e) {
$json_response = ['status' => 'error', 'message' => $e->getMessage()];
echo json_encode($json_response);exit;
echo json_encode($json_response);
exit;
}
if ($result) {
@@ -1058,13 +1069,15 @@ class AdminController extends AdminBaseController
'dependencies' => $dependencies,
'message' => $this->admin->translate(is_string($result) ? $result : 'PLUGIN_ADMIN.UNINSTALL_SUCCESSFUL')
];
echo json_encode($json_response);exit;
echo json_encode($json_response);
exit;
} else {
$json_response = [
'status' => 'error',
'message' => $this->admin->translate('PLUGIN_ADMIN.UNINSTALL_FAILED')
];
echo json_encode($json_response);exit;
echo json_encode($json_response);
exit;
}
return true;
@@ -1127,8 +1140,7 @@ class AdminController extends AdminBaseController
$author = $this->grav['config']->get('site.author.name', '');
$fullname = $user->fullname ?: $username;
$reset_link = rtrim($this->grav['uri']->rootUrl(true), '/') . '/' . trim($this->admin->base,
'/') . '/reset/task' . $param_sep . 'reset/user' . $param_sep . $username . '/token' . $param_sep . $token . '/admin-nonce' . $param_sep
. Utils::getNonce('admin-form');
'/') . '/reset/task' . $param_sep . 'reset/user' . $param_sep . $username . '/token' . $param_sep . $token . '/admin-nonce' . $param_sep . Utils::getNonce('admin-form');
$sitename = $this->grav['config']->get('site.title', 'Website');
$from = $this->grav['config']->get('plugins.email.from');
@@ -1193,8 +1205,7 @@ 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 = [
@@ -1223,10 +1234,12 @@ class AdminController extends AdminBaseController
$this->admin->json_response = [
'status' => 'error'
];
return false;
}
$filename = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT, true, true);
$filename = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT,
true, true);
$file = CompiledYamlFile::instance($filename);
$data = $file->content();
$data[] = $notification_id;
@@ -1290,8 +1303,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,
@@ -1399,8 +1411,7 @@ class AdminController extends AdminBaseController
foreach ($collection as $page) {
foreach ($queries as $query) {
$query = trim($query);
if (stripos($page->getRawContent(), $query) === false
&& stripos($page->title(),
if (stripos($page->getRawContent(), $query) === false && stripos($page->title(),
$query) === false
) {
$collection->remove($page);
@@ -1710,7 +1721,8 @@ class AdminController extends AdminBaseController
$input = (array)$this->data;
if (isset($input['order'])) {
$order = max(0, ((int)isset($input['order']) && $input['order']) ? $input['order'] : $page->value('order'));
$order = max(0,
((int)isset($input['order']) && $input['order']) ? $input['order'] : $page->value('order'));
$ordering = $order ? sprintf('%02d.', $order) : '';
$slug = empty($input['folder']) ? $page->value('folder') : (string)$input['folder'];
$page->folder($ordering . $slug);
@@ -2097,12 +2109,10 @@ class AdminController extends AdminBaseController
*/
protected function taskDirectInstall()
{
$file_path = '';
$file_path = $this->data['file_path'];
if (isset($_FILES['uploaded_file'])) {
$file_path = $_FILES['uploaded_file']['tmp_name'];
} else {
$file_path = $this->data['file_path'];
}
$result = Gpm::directInstall($file_path);
@@ -2110,7 +2120,8 @@ class AdminController extends AdminBaseController
if ($result === true) {
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSTALLATION_SUCCESSFUL'), 'info');
} else {
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED') . ': ' . $result, 'error');
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED') . ': ' . $result,
'error');
}
$this->setRedirect('/tools');