From 0d9a3e4bdcc2c12ea72b6ee275cdb56be7a465ce Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Thu, 4 Feb 2016 20:59:08 +0100 Subject: [PATCH] GravTrait changes in Admin --- admin.php | 1 + classes/gpm.php | 8 +++----- classes/popularity.php | 23 +++++++++++------------ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/admin.php b/admin.php index 7a305a34..5ce581a1 100644 --- a/admin.php +++ b/admin.php @@ -552,6 +552,7 @@ class AdminPlugin extends Plugin $this->admin = new Admin($this->grav, $this->base, $this->template, $this->route); + // And store the class into DI container. $this->grav['admin'] = $this->admin; diff --git a/classes/gpm.php b/classes/gpm.php index 17d86742..7e9962e8 100644 --- a/classes/gpm.php +++ b/classes/gpm.php @@ -1,7 +1,7 @@ findResource($package->package_type . '://' . $package->slug); + $location = Grav::instance()['locator']->findResource($package->package_type . '://' . $package->slug); // Check destination Installer::isValidDestination($location); @@ -168,7 +166,7 @@ class Gpm { $contents = Response::get($package->zipball_url, []); - $cache_dir = self::getGrav()['locator']->findResource('cache://', true); + $cache_dir = Grav::instance()['locator']->findResource('cache://', true); $cache_dir = $cache_dir . DS . 'tmp/Grav-' . uniqid(); Folder::mkdir($cache_dir); diff --git a/classes/popularity.php b/classes/popularity.php index e2a583e5..eacf2653 100644 --- a/classes/popularity.php +++ b/classes/popularity.php @@ -3,16 +3,15 @@ namespace Grav\Plugin; use Grav\Common\Config\Config; use Grav\Common\Grav; -use Grav\Common\Plugins; -use Grav\Common\Themes; use Grav\Common\Page\Page; use Grav\Common\Data; -use Grav\Common\GravTrait; +/** + * Class Popularity + * @package Grav\Plugin + */ class Popularity { - use GravTrait; - /** @var Config */ protected $config; protected $data_path; @@ -36,9 +35,9 @@ class Popularity public function __construct() { - $this->config = self::getGrav()['config']; + $this->config = Grav::instance()['config']; - $this->data_path = self::$grav['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->monthly_file = $this->data_path.'/'.self::MONTHLY_FILE; $this->totals_file = $this->data_path.'/'.self::TOTALS_FILE; @@ -49,13 +48,13 @@ class Popularity public function trackHit() { // Don't track bot or crawler requests - if (!self::getGrav()['browser']->isHuman()) { + if (!Grav::instance()['browser']->isHuman()) { return; } /** @var Page $page */ - $page = self::getGrav()['page']; - $relative_url = str_replace(self::getGrav()['base_url_relative'], '', $page->url()); + $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 if ($page->template() == 'error' || !$page->route()) { @@ -79,7 +78,7 @@ class Popularity $this->updateDaily(); $this->updateMonthly(); $this->updateTotals($page->route()); - $this->updateVisitors(self::getGrav()['uri']->ip()); + $this->updateVisitors(Grav::instance()['uri']->ip()); } @@ -126,7 +125,7 @@ class Popularity $data = array(); foreach ($chart_data as $date => $count) { - $labels[] = self::getGrav()['grav']['admin']->translate(['PLUGIN_ADMIN.' . strtoupper(date('D', strtotime($date)))]); + $labels[] = Grav::instance()['grav']['admin']->translate(['PLUGIN_ADMIN.' . strtoupper(date('D', strtotime($date)))]); $data[] = $count; }