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);
@@ -1222,7 +1227,7 @@ class Admin
public function getPagePathFromToken($path)
{
$path_parts = pathinfo($path);
$page = null;
$page = null;
$basename = '';
if (isset($path_parts['extension'])) {
@@ -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

@@ -77,7 +77,7 @@ class AdminBaseController
8 => "A PHP extension stopped the file upload"
];
/** @var array */
/** @var array */
public $blacklist_views = [];
/**
@@ -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,
'random_name' => false,
'accept' => ['image/*'],
'limit' => 10,
'filesize' => $config->get('system.media.upload_limit', 5242880) // 5MB
],
(array)$settings,
['name' => $this->post['name']]
);
$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']]);
$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;
}
@@ -931,7 +934,7 @@ class AdminBaseController
*/
protected function clearMediaCache()
{
$key = 'media-manager-files';
$key = 'media-manager-files';
$cache = $this->grav['cache'];
$cache->delete(md5($key));

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;
@@ -371,7 +369,7 @@ class AdminController extends AdminBaseController
}
$orderOfNewFolder = $this->getNextOrderInFolder($path);
$new_path = $path . '/' . $orderOfNewFolder . '.' . $data['folder'];
$new_path = $path . '/' . $orderOfNewFolder . '.' . $data['folder'];
Folder::create($new_path);
Cache::clearCache('standard');
@@ -445,7 +443,8 @@ class AdminController extends AdminBaseController
//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');
'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;
}
}
@@ -799,7 +800,7 @@ class AdminController extends AdminBaseController
*/
protected function taskGetUpdates()
{
$data = $this->post;
$data = $this->post;
$flush = isset($data['flush']) && $data['flush'] == true ? true : false;
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')) {
//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);
@@ -1601,12 +1612,12 @@ class AdminController extends AdminBaseController
}
$targetPath = $page->path() . '/' . $filename;
$fileParts = pathinfo($filename);
$fileParts = pathinfo($filename);
$found = false;
if (file_exists($targetPath)) {
$found = true;
$found = true;
$result = unlink($targetPath);
if (!$result) {
@@ -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');

View File

@@ -63,7 +63,7 @@ class Gpm
}
$packages = is_array($packages) ? $packages : [$packages];
$count = count($packages);
$count = count($packages);
$packages = array_filter(array_map(function ($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);
$local = static::download($package, $license);
$local = static::download($package, $license);
Installer::install($local, $options['destination'],
['install_path' => $package->install_path, 'theme' => $options['theme']]);
@@ -145,14 +145,14 @@ class Gpm
$options = array_merge(self::$options, $options);
$packages = is_array($packages) ? $packages : [$packages];
$count = count($packages);
$count = count($packages);
$packages = array_filter(array_map(function ($p) {
if (is_string($p)) {
$p = strtolower($p);
$p = strtolower($p);
$plugin = static::GPM()->getInstalledPlugin($p);
$p = $plugin ?: static::GPM()->getInstalledTheme($p);
$p = $plugin ?: static::GPM()->getInstalledTheme($p);
}
return $p instanceof Package ? $p : false;
@@ -217,7 +217,7 @@ class Gpm
if (file_exists($zip)) {
$tmp_source = $tmp_dir . '/Grav-' . uniqid();
$extracted = Installer::unZip($zip, $tmp_source);
$extracted = Installer::unZip($zip, $tmp_source);
if (!$extracted) {
return Admin::translate('PLUGIN_ADMIN.PACKAGE_EXTRACTION_FAILED');
@@ -244,7 +244,7 @@ class Gpm
}
$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);
if (Installer::lastErrorCode() == Installer::IS_LINK) {
@@ -282,10 +282,10 @@ class Gpm
if ($package->premium) {
$query = \json_encode(array_merge($package->premium, [
'slug' => $package->slug,
'filename' => $package->premium['filename'],
'license_key' => $license
]));
'slug' => $package->slug,
'filename' => $package->premium['filename'],
'license_key' => $license
]));
$query = '?d=' . base64_encode($query);
}
@@ -341,7 +341,7 @@ class Gpm
}
if (method_exists($upgrader, 'meetsRequirements') && !$upgrader->meetsRequirements()) {
$error = [];
$error = [];
$error[] = '<p>Grav has increased the minimum PHP requirement.<br />';
$error[] = 'You are currently running PHP <strong>' . PHP_VERSION . '</strong>';
$error[] = ', but PHP <strong>' . GRAV_PHP_MIN . '</strong> is required.</p>';
@@ -353,8 +353,8 @@ class Gpm
}
$update = $upgrader->getAssets()['grav-update'];
$tmp = Admin::getTempDir() . '/Grav-' . uniqid();
$file = self::_downloadSelfupgrade($update, $tmp);
$tmp = Admin::getTempDir() . '/Grav-' . uniqid();
$file = self::_downloadSelfupgrade($update, $tmp);
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->data_path = Grav::instance()['locator']->findResource('log://popularity', true, true);
$this->daily_file = $this->data_path . '/' . self::DAILY_FILE;
$this->monthly_file = $this->data_path . '/' . self::MONTHLY_FILE;
$this->totals_file = $this->data_path . '/' . self::TOTALS_FILE;
$this->data_path = Grav::instance()['locator']->findResource('log://popularity', true, true);
$this->daily_file = $this->data_path . '/' . self::DAILY_FILE;
$this->monthly_file = $this->data_path . '/' . self::MONTHLY_FILE;
$this->totals_file = $this->data_path . '/' . self::TOTALS_FILE;
$this->visitors_file = $this->data_path . '/' . self::VISITORS_FILE;
}
@@ -52,7 +52,7 @@ class Popularity
}
/** @var Page $page */
$page = Grav::instance()['page'];
$page = Grav::instance()['page'];
$relative_url = str_replace(Grav::instance()['base_url_relative'], '', $page->url());
// 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);
}
$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);
$labels = [];
$data = [];
$data = [];
foreach ($chart_data as $date => $count) {
$labels[] = Grav::instance()['grav']['admin']->translate([
'PLUGIN_ADMIN.' . strtoupper(date('D', strtotime($date)))
]);
$data[] = $count;
$data[] = $count;
}
return ['labels' => $labels, 'data' => $data];
@@ -158,7 +158,7 @@ class Popularity
$this->daily_data = $this->getData($this->daily_file);
}
$day = 0;
$day = 0;
$total = 0;
foreach (array_reverse($this->daily_data) as $daily) {
$total += $daily;
@@ -203,8 +203,8 @@ class Popularity
}
// keep correct number as set by history
$count = intval($this->config->get('plugins.admin.popularity.history.monthly', 12));
$total = count($this->monthly_data);
$count = intval($this->config->get('plugins.admin.popularity.history.monthly', 12));
$total = count($this->monthly_data);
$this->monthly_data = array_slice($this->monthly_data, $total - $count, $count);
@@ -221,11 +221,11 @@ class Popularity
}
$labels = [];
$data = [];
$data = [];
foreach ($this->monthly_data as $date => $count) {
$labels[] = date('M', strtotime($date));
$data[] = $count;
$data[] = $count;
}
return ['labels' => $labels, 'data' => $data];
@@ -261,10 +261,10 @@ class Popularity
// update with current timestamp
$this->visitors_data[$ip] = time();
$visitors = $this->visitors_data;
$visitors = $this->visitors_data;
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);
file_put_contents($this->visitors_file, json_encode($this->visitors_data));

View File

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