data_path = LOG_DIR . 'popularity'; $this->data_file = date('W-Y') . '.json'; } public function trackHit() { $data_filepath = $this->data_path.'/'.$this->data_file; $url = self::$grav['uri']->url(); \Tracy\Debugger::log($data_filepath); // initial creation if it doesn't exist if (!file_exists($this->data_path)) { mkdir($this->data_path); file_put_contents($data_filepath, array()); } // Get the JSON data $data = (array) @json_decode(file_get_contents($data_filepath), true); if (array_key_exists($url, $data)) { $data[$url] = intval($data[$url]) + 1; } else { $data[$url] = 1; } // Store the JSON data again file_put_contents($data_filepath, json_encode($data)); } function flushData($weeks = 52) { // flush data older than 1 year } }