Grav\Plugin\Admin\Popularity::trackHit PHP Метод

trackHit() публичный Метод

public trackHit ( )
    public function trackHit()
    {
        // Don't track bot or crawler requests
        if (!Grav::instance()['browser']->isHuman()) {
            return;
        }
        /** @var Page $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
        if ($page->template() == 'error' || !$page->route()) {
            return;
        }
        // Make sure no 'widcard-style' ignore matches this url
        foreach ((array) $this->config->get('plugins.admin.popularity.ignore') as $ignore) {
            if (fnmatch($ignore, $relative_url)) {
                return;
            }
        }
        // initial creation if it doesn't exist
        if (!file_exists($this->data_path)) {
            mkdir($this->data_path);
            $this->flushPopularity();
        }
        // Update the data we want to track
        $this->updateDaily();
        $this->updateMonthly();
        $this->updateTotals($page->route());
        $this->updateVisitors(Grav::instance()['uri']->ip());
    }

Usage Example

Пример #1
0
 /**
  * Handles the shutdown
  */
 public function onShutdown()
 {
     // Just so we know that we're in this debug mode
     if ($this->config->get('plugins.admin.popularity.enabled')) {
         // Only track non-admin
         if (!$this->active) {
             $this->popularity->trackHit();
         }
     }
 }