16b6f8822SAndreas Gohr<?php 2a8acb244SAndreas Gohr 3d5ef99ddSAndreas Gohruse dokuwiki\Extension\Plugin; 4d5ef99ddSAndreas Gohruse dokuwiki\plugin\sqlite\SQLiteDB; 5aab59130SAndreas Gohruse dokuwiki\plugin\statistics\Logger; 6b6632b6eSAndreas Gohruse dokuwiki\plugin\statistics\Query; 7*64ba7f66SAnna Dabrowskause dokuwiki\plugin\statistics\StatisticsGraph; 8d5ef99ddSAndreas Gohr 96b6f8822SAndreas Gohr/** 106b6f8822SAndreas Gohr * Statistics Plugin 116b6f8822SAndreas Gohr * 126b6f8822SAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 136b6f8822SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 146b6f8822SAndreas Gohr */ 15d5ef99ddSAndreas Gohrclass helper_plugin_statistics extends Plugin 16a8acb244SAndreas Gohr{ 17aab59130SAndreas Gohr protected $dblink; 186b6f8822SAndreas Gohr public $prefix; 19aab59130SAndreas Gohr protected $oQuery; 20762f4807SAndreas Gohr protected ?Logger $oLogger = null; 21aab59130SAndreas Gohr protected $oGraph; 22762f4807SAndreas Gohr protected ?SQLiteDB $db = null; 236b6f8822SAndreas Gohr 246b6f8822SAndreas Gohr /** 25d5ef99ddSAndreas Gohr * Get SQLiteDB instance 26d5ef99ddSAndreas Gohr * 27d5ef99ddSAndreas Gohr * @return SQLiteDB|null 28483101d3SAndreas Gohr * @throws Exception when SQLite initialization failed 29d5ef99ddSAndreas Gohr */ 30483101d3SAndreas Gohr public function getDB(): ?SQLiteDB 31d5ef99ddSAndreas Gohr { 32d5ef99ddSAndreas Gohr if ($this->db === null) { 33483101d3SAndreas Gohr if (!class_exists(SQLiteDB::class)) throw new \Exception('SQLite Plugin missing'); 34762f4807SAndreas Gohr $this->db = new SQLiteDB('statistics', DOKU_PLUGIN . 'statistics/db/'); 35d5ef99ddSAndreas Gohr } 36d5ef99ddSAndreas Gohr return $this->db; 37d5ef99ddSAndreas Gohr } 38d5ef99ddSAndreas Gohr 39d5ef99ddSAndreas Gohr 40d5ef99ddSAndreas Gohr /** 416b6f8822SAndreas Gohr * Return an instance of the query class 426b6f8822SAndreas Gohr * 43b6632b6eSAndreas Gohr * @return Query 446b6f8822SAndreas Gohr */ 45483101d3SAndreas Gohr public function Query(): Query 46a8acb244SAndreas Gohr { 476b6f8822SAndreas Gohr if (is_null($this->oQuery)) { 48b6632b6eSAndreas Gohr $this->oQuery = new Query($this); 496b6f8822SAndreas Gohr } 506b6f8822SAndreas Gohr return $this->oQuery; 516b6f8822SAndreas Gohr } 526b6f8822SAndreas Gohr 536b6f8822SAndreas Gohr /** 546b6f8822SAndreas Gohr * Return an instance of the logger class 556b6f8822SAndreas Gohr * 56aab59130SAndreas Gohr * @return Logger 576b6f8822SAndreas Gohr */ 58483101d3SAndreas Gohr public function Logger(): ?Logger 59a8acb244SAndreas Gohr { 60b6eece2fSAndreas Gohr $this->prefix = $this->getConf('db_prefix'); 616b6f8822SAndreas Gohr if (is_null($this->oLogger)) { 62aab59130SAndreas Gohr $this->oLogger = new Logger($this); 636b6f8822SAndreas Gohr } 646b6f8822SAndreas Gohr return $this->oLogger; 656b6f8822SAndreas Gohr } 666b6f8822SAndreas Gohr 676b6f8822SAndreas Gohr /** 686b6f8822SAndreas Gohr * Return an instance of the Graph class 696b6f8822SAndreas Gohr * 701664ba1dSAndreas Gohr * @return StatisticsGraph 716b6f8822SAndreas Gohr */ 72f0a4cceeSAnna Dabrowska public function Graph($from, $to, $width, $height) 73a8acb244SAndreas Gohr { 74b6eece2fSAndreas Gohr $this->prefix = $this->getConf('db_prefix'); 756b6f8822SAndreas Gohr if (is_null($this->oGraph)) { 76f0a4cceeSAnna Dabrowska $this->oGraph = new StatisticsGraph($this, $from, $to, $width, $height); 776b6f8822SAndreas Gohr } 786b6f8822SAndreas Gohr return $this->oGraph; 796b6f8822SAndreas Gohr } 806b6f8822SAndreas Gohr 816b6f8822SAndreas Gohr /** 824f41a2ccSAndreas Gohr * Just send a 1x1 pixel blank gif to the browser 834f41a2ccSAndreas Gohr * 844f41a2ccSAndreas Gohr * @called from log.php 854f41a2ccSAndreas Gohr * 864f41a2ccSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 874f41a2ccSAndreas Gohr * @author Harry Fuecks <fuecks@gmail.com> 884f41a2ccSAndreas Gohr */ 89a8acb244SAndreas Gohr public function sendGIF($transparent = true) 90a8acb244SAndreas Gohr { 91259897e1SAndreas Gohr if ($transparent) { 924f41a2ccSAndreas Gohr $img = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7'); 93259897e1SAndreas Gohr } else { 94259897e1SAndreas Gohr $img = base64_decode('R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs='); 95259897e1SAndreas Gohr } 964f41a2ccSAndreas Gohr header('Content-Type: image/gif'); 974f41a2ccSAndreas Gohr header('Content-Length: ' . strlen($img)); 984f41a2ccSAndreas Gohr header('Connection: Close'); 99a8acb244SAndreas Gohr echo $img; 1004f41a2ccSAndreas Gohr flush(); 1014f41a2ccSAndreas Gohr // Browser should drop connection after this 1024f41a2ccSAndreas Gohr // Thinks it's got the whole image 1034f41a2ccSAndreas Gohr } 1046b6f8822SAndreas Gohr} 105