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

View File

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

View File

@@ -13,8 +13,6 @@ use Grav\Common\Page\Media;
use Grav\Common\Page\Page; use Grav\Common\Page\Page;
use Grav\Common\Page\Pages; use Grav\Common\Page\Pages;
use Grav\Common\Page\Collection; use Grav\Common\Page\Collection;
use Grav\Common\Plugin;
use Grav\Common\Theme;
use Grav\Common\User\User; use Grav\Common\User\User;
use Grav\Common\Utils; use Grav\Common\Utils;
use Grav\Common\Backup\ZipBackup; use Grav\Common\Backup\ZipBackup;
@@ -371,7 +369,7 @@ class AdminController extends AdminBaseController
} }
$orderOfNewFolder = $this->getNextOrderInFolder($path); $orderOfNewFolder = $this->getNextOrderInFolder($path);
$new_path = $path . '/' . $orderOfNewFolder . '.' . $data['folder']; $new_path = $path . '/' . $orderOfNewFolder . '.' . $data['folder'];
Folder::create($new_path); Folder::create($new_path);
Cache::clearCache('standard'); Cache::clearCache('standard');
@@ -445,7 +443,8 @@ class AdminController extends AdminBaseController
//not admin.super or admin.users //not admin.super or admin.users
if ($this->prepareData($data)->username !== $this->grav['user']->username) { if ($this->prepareData($data)->username !== $this->grav['user']->username) {
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' save.', $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' save.',
'error'); 'error');
return false; return false;
} }
} }
@@ -587,7 +586,9 @@ class AdminController extends AdminBaseController
$topParent = $obj->topParent(); $topParent = $obj->topParent();
if (isset($topParent)) { if (isset($topParent)) {
$top_parent_route = (string)$topParent->route(); $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; $route = $top_parent_route . $route;
} }
} }
@@ -776,9 +777,8 @@ class AdminController extends AdminBaseController
foreach ($feed_items as $item) { foreach ($feed_items as $item) {
$datetime = $adminTwigExtension->adminNicetimeFilter($item->getDate()->getTimestamp()); $datetime = $adminTwigExtension->adminNicetimeFilter($item->getDate()->getTimestamp());
$feed_data[] = $feed_data[] = '<li><span class="date">' . $datetime . '</span> <a href="' . $item->getUrl() . '" target="_blank" title="' . str_replace('"',
'<li><span class="date">' . $datetime . '</span> <a href="' . $item->getUrl() . '" target="_blank" title="' . str_replace('"', '″', '″', $item->getTitle()) . '">' . $item->getTitle() . '</a></li>';
$item->getTitle()) . '">' . $item->getTitle() . '</a></li>';
} }
} }
@@ -787,6 +787,7 @@ class AdminController extends AdminBaseController
} catch (\Exception $e) { } catch (\Exception $e) {
$this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()]; $this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()];
return; return;
} }
} }
@@ -799,7 +800,7 @@ class AdminController extends AdminBaseController
*/ */
protected function taskGetUpdates() protected function taskGetUpdates()
{ {
$data = $this->post; $data = $this->post;
$flush = isset($data['flush']) && $data['flush'] == true ? true : false; $flush = isset($data['flush']) && $data['flush'] == true ? true : false;
if (isset($this->grav['session'])) { if (isset($this->grav['session'])) {
@@ -849,6 +850,7 @@ class AdminController extends AdminBaseController
if (!(bool)$this->grav['config']->get('system.cache.enabled') || !$notifications = $cache->fetch('notifications')) { if (!(bool)$this->grav['config']->get('system.cache.enabled') || !$notifications = $cache->fetch('notifications')) {
//No notifications cache (first time) //No notifications cache (first time)
$this->admin->json_response = ['status' => 'success', 'notifications' => [], 'need_update' => true]; $this->admin->json_response = ['status' => 'success', 'notifications' => [], 'need_update' => true];
return; return;
} }
@@ -865,10 +867,15 @@ class AdminController extends AdminBaseController
$notifications = $this->admin->processNotifications($notifications); $notifications = $this->admin->processNotifications($notifications);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()]; $this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()];
return; 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); $notifications = $this->admin->processNotifications($notifications);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()]; $this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()];
return false; return false;
} }
@@ -898,7 +906,12 @@ class AdminController extends AdminBaseController
$cache->save('notifications', $notifications); $cache->save('notifications', $notifications);
$cache->save('notifications_last_checked', time()); $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; return true;
} }
@@ -992,18 +1005,13 @@ class AdminController extends AdminBaseController
if ($result) { if ($result) {
$this->admin->json_response = [ $this->admin->json_response = [
'status' => 'success', 'status' => 'success',
'message' => $this->admin->translate(is_string($result) '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',
? $result null), $package))
: sprintf($this->admin->translate(
$reinstall ? 'PLUGIN_ADMIN.PACKAGE_X_REINSTALLED_SUCCESSFULLY' : 'PLUGIN_ADMIN.PACKAGE_X_INSTALLED_SUCCESSFULLY'
, null), $package))
]; ];
} else { } else {
$this->admin->json_response = [ $this->admin->json_response = [
'status' => 'error', 'status' => 'error',
'message' => $this->admin->translate( 'message' => $this->admin->translate($reinstall ? 'PLUGIN_ADMIN.REINSTALLATION_FAILED' : 'PLUGIN_ADMIN.INSTALLATION_FAILED')
$reinstall ? 'PLUGIN_ADMIN.REINSTALLATION_FAILED' : 'PLUGIN_ADMIN.INSTALLATION_FAILED'
)
]; ];
} }
@@ -1026,7 +1034,8 @@ class AdminController extends AdminBaseController
'status' => 'error', 'status' => 'error',
'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') '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 //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]; $json_response = ['status' => 'error', 'message' => $message];
echo json_encode($json_response);exit; echo json_encode($json_response);
exit;
} }
try { try {
@@ -1049,7 +1059,8 @@ class AdminController extends AdminBaseController
$result = Gpm::uninstall($package, []); $result = Gpm::uninstall($package, []);
} catch (\Exception $e) { } catch (\Exception $e) {
$json_response = ['status' => 'error', 'message' => $e->getMessage()]; $json_response = ['status' => 'error', 'message' => $e->getMessage()];
echo json_encode($json_response);exit; echo json_encode($json_response);
exit;
} }
if ($result) { if ($result) {
@@ -1058,13 +1069,15 @@ class AdminController extends AdminBaseController
'dependencies' => $dependencies, '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')
]; ];
echo json_encode($json_response);exit; echo json_encode($json_response);
exit;
} else { } else {
$json_response = [ $json_response = [
'status' => 'error', 'status' => 'error',
'message' => $this->admin->translate('PLUGIN_ADMIN.UNINSTALL_FAILED') 'message' => $this->admin->translate('PLUGIN_ADMIN.UNINSTALL_FAILED')
]; ];
echo json_encode($json_response);exit; echo json_encode($json_response);
exit;
} }
return true; return true;
@@ -1127,8 +1140,7 @@ class AdminController extends AdminBaseController
$author = $this->grav['config']->get('site.author.name', ''); $author = $this->grav['config']->get('site.author.name', '');
$fullname = $user->fullname ?: $username; $fullname = $user->fullname ?: $username;
$reset_link = rtrim($this->grav['uri']->rootUrl(true), '/') . '/' . trim($this->admin->base, $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 '/') . '/reset/task' . $param_sep . 'reset/user' . $param_sep . $username . '/token' . $param_sep . $token . '/admin-nonce' . $param_sep . Utils::getNonce('admin-form');
. Utils::getNonce('admin-form');
$sitename = $this->grav['config']->get('site.title', 'Website'); $sitename = $this->grav['config']->get('site.title', 'Website');
$from = $this->grav['config']->get('plugins.email.from'); $from = $this->grav['config']->get('plugins.email.from');
@@ -1193,8 +1205,7 @@ class AdminController extends AdminBaseController
if (count($results) > 0) { if (count($results) > 0) {
$this->admin->json_response = [ $this->admin->json_response = [
'status' => 'success', '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 { } else {
$this->admin->json_response = [ $this->admin->json_response = [
@@ -1223,10 +1234,12 @@ class AdminController extends AdminBaseController
$this->admin->json_response = [ $this->admin->json_response = [
'status' => 'error' 'status' => 'error'
]; ];
return false; 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); $file = CompiledYamlFile::instance($filename);
$data = $file->content(); $data = $file->content();
$data[] = $notification_id; $data[] = $notification_id;
@@ -1290,8 +1303,7 @@ class AdminController extends AdminBaseController
$this->admin->json_response = [ $this->admin->json_response = [
'status' => 'success', 'status' => 'success',
'message' => $this->admin->translate('PLUGIN_ADMIN.YOUR_BACKUP_IS_READY_FOR_DOWNLOAD') . '. <a href="' . $url . '" class="button">' '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>',
. $this->admin->translate('PLUGIN_ADMIN.DOWNLOAD_BACKUP') . '</a>',
'toastr' => [ 'toastr' => [
'timeOut' => 0, 'timeOut' => 0,
'extendedTimeOut' => 0, 'extendedTimeOut' => 0,
@@ -1399,8 +1411,7 @@ class AdminController extends AdminBaseController
foreach ($collection as $page) { foreach ($collection as $page) {
foreach ($queries as $query) { foreach ($queries as $query) {
$query = trim($query); $query = trim($query);
if (stripos($page->getRawContent(), $query) === false if (stripos($page->getRawContent(), $query) === false && stripos($page->title(),
&& stripos($page->title(),
$query) === false $query) === false
) { ) {
$collection->remove($page); $collection->remove($page);
@@ -1601,12 +1612,12 @@ class AdminController extends AdminBaseController
} }
$targetPath = $page->path() . '/' . $filename; $targetPath = $page->path() . '/' . $filename;
$fileParts = pathinfo($filename); $fileParts = pathinfo($filename);
$found = false; $found = false;
if (file_exists($targetPath)) { if (file_exists($targetPath)) {
$found = true; $found = true;
$result = unlink($targetPath); $result = unlink($targetPath);
if (!$result) { if (!$result) {
@@ -1710,7 +1721,8 @@ class AdminController extends AdminBaseController
$input = (array)$this->data; $input = (array)$this->data;
if (isset($input['order'])) { 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) : ''; $ordering = $order ? sprintf('%02d.', $order) : '';
$slug = empty($input['folder']) ? $page->value('folder') : (string)$input['folder']; $slug = empty($input['folder']) ? $page->value('folder') : (string)$input['folder'];
$page->folder($ordering . $slug); $page->folder($ordering . $slug);
@@ -2097,12 +2109,10 @@ class AdminController extends AdminBaseController
*/ */
protected function taskDirectInstall() protected function taskDirectInstall()
{ {
$file_path = ''; $file_path = $this->data['file_path'];
if (isset($_FILES['uploaded_file'])) { if (isset($_FILES['uploaded_file'])) {
$file_path = $_FILES['uploaded_file']['tmp_name']; $file_path = $_FILES['uploaded_file']['tmp_name'];
} else {
$file_path = $this->data['file_path'];
} }
$result = Gpm::directInstall($file_path); $result = Gpm::directInstall($file_path);
@@ -2110,7 +2120,8 @@ class AdminController extends AdminBaseController
if ($result === true) { 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 { } 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'); $this->setRedirect('/tools');

View File

@@ -63,7 +63,7 @@ class Gpm
} }
$packages = is_array($packages) ? $packages : [$packages]; $packages = is_array($packages) ? $packages : [$packages];
$count = count($packages); $count = count($packages);
$packages = array_filter(array_map(function ($p) { $packages = array_filter(array_map(function ($p) {
return !is_string($p) ? $p instanceof Package ? $p : false : self::GPM()->findPackage($p); return !is_string($p) ? $p instanceof Package ? $p : false : self::GPM()->findPackage($p);
@@ -96,7 +96,7 @@ class Gpm
} }
$license = Licenses::get($package->slug); $license = Licenses::get($package->slug);
$local = static::download($package, $license); $local = static::download($package, $license);
Installer::install($local, $options['destination'], Installer::install($local, $options['destination'],
['install_path' => $package->install_path, 'theme' => $options['theme']]); ['install_path' => $package->install_path, 'theme' => $options['theme']]);
@@ -145,14 +145,14 @@ class Gpm
$options = array_merge(self::$options, $options); $options = array_merge(self::$options, $options);
$packages = is_array($packages) ? $packages : [$packages]; $packages = is_array($packages) ? $packages : [$packages];
$count = count($packages); $count = count($packages);
$packages = array_filter(array_map(function ($p) { $packages = array_filter(array_map(function ($p) {
if (is_string($p)) { if (is_string($p)) {
$p = strtolower($p); $p = strtolower($p);
$plugin = static::GPM()->getInstalledPlugin($p); $plugin = static::GPM()->getInstalledPlugin($p);
$p = $plugin ?: static::GPM()->getInstalledTheme($p); $p = $plugin ?: static::GPM()->getInstalledTheme($p);
} }
return $p instanceof Package ? $p : false; return $p instanceof Package ? $p : false;
@@ -217,7 +217,7 @@ class Gpm
if (file_exists($zip)) { if (file_exists($zip)) {
$tmp_source = $tmp_dir . '/Grav-' . uniqid(); $tmp_source = $tmp_dir . '/Grav-' . uniqid();
$extracted = Installer::unZip($zip, $tmp_source); $extracted = Installer::unZip($zip, $tmp_source);
if (!$extracted) { if (!$extracted) {
return Admin::translate('PLUGIN_ADMIN.PACKAGE_EXTRACTION_FAILED'); return Admin::translate('PLUGIN_ADMIN.PACKAGE_EXTRACTION_FAILED');
@@ -244,7 +244,7 @@ class Gpm
} }
$install_path = GravGPM::getInstallPath($type, $name); $install_path = GravGPM::getInstallPath($type, $name);
$is_update = file_exists($install_path); $is_update = file_exists($install_path);
Installer::isValidDestination(GRAV_ROOT . DS . $install_path); Installer::isValidDestination(GRAV_ROOT . DS . $install_path);
if (Installer::lastErrorCode() == Installer::IS_LINK) { if (Installer::lastErrorCode() == Installer::IS_LINK) {
@@ -282,10 +282,10 @@ class Gpm
if ($package->premium) { if ($package->premium) {
$query = \json_encode(array_merge($package->premium, [ $query = \json_encode(array_merge($package->premium, [
'slug' => $package->slug, 'slug' => $package->slug,
'filename' => $package->premium['filename'], 'filename' => $package->premium['filename'],
'license_key' => $license 'license_key' => $license
])); ]));
$query = '?d=' . base64_encode($query); $query = '?d=' . base64_encode($query);
} }
@@ -341,7 +341,7 @@ class Gpm
} }
if (method_exists($upgrader, 'meetsRequirements') && !$upgrader->meetsRequirements()) { if (method_exists($upgrader, 'meetsRequirements') && !$upgrader->meetsRequirements()) {
$error = []; $error = [];
$error[] = '<p>Grav has increased the minimum PHP requirement.<br />'; $error[] = '<p>Grav has increased the minimum PHP requirement.<br />';
$error[] = 'You are currently running PHP <strong>' . PHP_VERSION . '</strong>'; $error[] = 'You are currently running PHP <strong>' . PHP_VERSION . '</strong>';
$error[] = ', but PHP <strong>' . GRAV_PHP_MIN . '</strong> is required.</p>'; $error[] = ', but PHP <strong>' . GRAV_PHP_MIN . '</strong> is required.</p>';
@@ -353,8 +353,8 @@ class Gpm
} }
$update = $upgrader->getAssets()['grav-update']; $update = $upgrader->getAssets()['grav-update'];
$tmp = Admin::getTempDir() . '/Grav-' . uniqid(); $tmp = Admin::getTempDir() . '/Grav-' . uniqid();
$file = self::_downloadSelfupgrade($update, $tmp); $file = self::_downloadSelfupgrade($update, $tmp);
Installer::install($file, GRAV_ROOT, ['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true]); Installer::install($file, GRAV_ROOT, ['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true]);

View File

@@ -36,10 +36,10 @@ class Popularity
{ {
$this->config = Grav::instance()['config']; $this->config = Grav::instance()['config'];
$this->data_path = Grav::instance()['locator']->findResource('log://popularity', true, true); $this->data_path = Grav::instance()['locator']->findResource('log://popularity', true, true);
$this->daily_file = $this->data_path . '/' . self::DAILY_FILE; $this->daily_file = $this->data_path . '/' . self::DAILY_FILE;
$this->monthly_file = $this->data_path . '/' . self::MONTHLY_FILE; $this->monthly_file = $this->data_path . '/' . self::MONTHLY_FILE;
$this->totals_file = $this->data_path . '/' . self::TOTALS_FILE; $this->totals_file = $this->data_path . '/' . self::TOTALS_FILE;
$this->visitors_file = $this->data_path . '/' . self::VISITORS_FILE; $this->visitors_file = $this->data_path . '/' . self::VISITORS_FILE;
} }
@@ -52,7 +52,7 @@ class Popularity
} }
/** @var Page $page */ /** @var Page $page */
$page = Grav::instance()['page']; $page = Grav::instance()['page'];
$relative_url = str_replace(Grav::instance()['base_url_relative'], '', $page->url()); $relative_url = str_replace(Grav::instance()['base_url_relative'], '', $page->url());
// Don't track error pages or pages that have no route // Don't track error pages or pages that have no route
@@ -117,17 +117,17 @@ class Popularity
$this->daily_data = $this->getData($this->daily_file); $this->daily_data = $this->getData($this->daily_file);
} }
$limit = intval($this->config->get('plugins.admin.popularity.dashboard.days_of_stats', 7)); $limit = intval($this->config->get('plugins.admin.popularity.dashboard.days_of_stats', 7));
$chart_data = array_slice($this->daily_data, -$limit, $limit); $chart_data = array_slice($this->daily_data, -$limit, $limit);
$labels = []; $labels = [];
$data = []; $data = [];
foreach ($chart_data as $date => $count) { foreach ($chart_data as $date => $count) {
$labels[] = Grav::instance()['grav']['admin']->translate([ $labels[] = Grav::instance()['grav']['admin']->translate([
'PLUGIN_ADMIN.' . strtoupper(date('D', strtotime($date))) 'PLUGIN_ADMIN.' . strtoupper(date('D', strtotime($date)))
]); ]);
$data[] = $count; $data[] = $count;
} }
return ['labels' => $labels, 'data' => $data]; return ['labels' => $labels, 'data' => $data];
@@ -158,7 +158,7 @@ class Popularity
$this->daily_data = $this->getData($this->daily_file); $this->daily_data = $this->getData($this->daily_file);
} }
$day = 0; $day = 0;
$total = 0; $total = 0;
foreach (array_reverse($this->daily_data) as $daily) { foreach (array_reverse($this->daily_data) as $daily) {
$total += $daily; $total += $daily;
@@ -203,8 +203,8 @@ class Popularity
} }
// keep correct number as set by history // keep correct number as set by history
$count = intval($this->config->get('plugins.admin.popularity.history.monthly', 12)); $count = intval($this->config->get('plugins.admin.popularity.history.monthly', 12));
$total = count($this->monthly_data); $total = count($this->monthly_data);
$this->monthly_data = array_slice($this->monthly_data, $total - $count, $count); $this->monthly_data = array_slice($this->monthly_data, $total - $count, $count);
@@ -221,11 +221,11 @@ class Popularity
} }
$labels = []; $labels = [];
$data = []; $data = [];
foreach ($this->monthly_data as $date => $count) { foreach ($this->monthly_data as $date => $count) {
$labels[] = date('M', strtotime($date)); $labels[] = date('M', strtotime($date));
$data[] = $count; $data[] = $count;
} }
return ['labels' => $labels, 'data' => $data]; return ['labels' => $labels, 'data' => $data];
@@ -261,10 +261,10 @@ class Popularity
// update with current timestamp // update with current timestamp
$this->visitors_data[$ip] = time(); $this->visitors_data[$ip] = time();
$visitors = $this->visitors_data; $visitors = $this->visitors_data;
arsort($visitors); arsort($visitors);
$count = intval($this->config->get('plugins.admin.popularity.history.visitors', 20)); $count = intval($this->config->get('plugins.admin.popularity.history.visitors', 20));
$this->visitors_data = array_slice($visitors, 0, $count, true); $this->visitors_data = array_slice($visitors, 0, $count, true);
file_put_contents($this->visitors_file, json_encode($this->visitors_data)); file_put_contents($this->visitors_file, json_encode($this->visitors_data));

View File

@@ -21,7 +21,7 @@ class Utils
public static function findUserByEmail($email) public static function findUserByEmail($email)
{ {
$account_dir = Grav::instance()['locator']->findResource('account://'); $account_dir = Grav::instance()['locator']->findResource('account://');
$files = array_diff(scandir($account_dir), ['.', '..']); $files = array_diff(scandir($account_dir), ['.', '..']);
foreach ($files as $file) { foreach ($files as $file) {
if (strpos($file, '.yaml') !== false) { if (strpos($file, '.yaml') !== false) {