1<?php 2 3use dokuwiki\Extension\Plugin; 4use dokuwiki\plugin\sqlite\SQLiteDB; 5use dokuwiki\plugin\statistics\Logger; 6use dokuwiki\plugin\statistics\Query; 7use dokuwiki\plugin\statistics\StatisticsGraph; 8 9/** 10 * Statistics Plugin 11 * 12 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 13 * @author Andreas Gohr <andi@splitbrain.org> 14 */ 15class helper_plugin_statistics extends Plugin 16{ 17 protected $dblink; 18 public $prefix; 19 protected $oQuery; 20 protected ?Logger $oLogger = null; 21 protected $oGraph; 22 protected ?SQLiteDB $db = null; 23 24 /** 25 * Get SQLiteDB instance 26 * 27 * @return SQLiteDB|null 28 * @throws Exception when SQLite initialization failed 29 */ 30 public function getDB(): ?SQLiteDB 31 { 32 if (!$this->db instanceof SQLiteDB) { 33 if (!class_exists(SQLiteDB::class)) throw new \Exception('SQLite Plugin missing'); 34 $this->db = new SQLiteDB('statistics', DOKU_PLUGIN . 'statistics/db/'); 35 } 36 return $this->db; 37 } 38 39 40 /** 41 * Return an instance of the query class 42 * 43 * @return Query 44 */ 45 public function Query(): Query 46 { 47 if (is_null($this->oQuery)) { 48 $this->oQuery = new Query($this); 49 } 50 return $this->oQuery; 51 } 52 53 /** 54 * Return an instance of the logger class 55 * 56 * @return Logger 57 */ 58 public function Logger(): ?Logger 59 { 60 $this->prefix = $this->getConf('db_prefix'); 61 if (is_null($this->oLogger)) { 62 $this->oLogger = new Logger($this); 63 } 64 return $this->oLogger; 65 } 66 67 /** 68 * Return an instance of the Graph class 69 * 70 * @return StatisticsGraph 71 */ 72 public function Graph($from, $to, $width, $height) 73 { 74 $this->prefix = $this->getConf('db_prefix'); 75 if (is_null($this->oGraph)) { 76 $this->oGraph = new StatisticsGraph($this, $from, $to, $width, $height); 77 } 78 return $this->oGraph; 79 } 80 81 /** 82 * Just send a 1x1 pixel blank gif to the browser 83 * 84 * @called from log.php 85 * 86 * @author Andreas Gohr <andi@splitbrain.org> 87 * @author Harry Fuecks <fuecks@gmail.com> 88 */ 89 public function sendGIF($transparent = true) 90 { 91 if ($transparent) { 92 $img = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7'); 93 } else { 94 $img = base64_decode('R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs='); 95 } 96 header('Content-Type: image/gif'); 97 header('Content-Length: ' . strlen($img)); 98 header('Connection: Close'); 99 echo $img; 100 flush(); 101 // Browser should drop connection after this 102 // Thinks it's got the whole image 103 } 104} 105