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; 7d5ef99ddSAndreas Gohr 86b6f8822SAndreas Gohr/** 96b6f8822SAndreas Gohr * Statistics Plugin 106b6f8822SAndreas Gohr * 116b6f8822SAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 126b6f8822SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 136b6f8822SAndreas Gohr */ 14d5ef99ddSAndreas Gohrclass helper_plugin_statistics extends Plugin 15a8acb244SAndreas Gohr{ 16aab59130SAndreas Gohr protected $dblink; 176b6f8822SAndreas Gohr public $prefix; 18aab59130SAndreas Gohr protected $oQuery; 19762f4807SAndreas Gohr protected ?Logger $oLogger = null; 20aab59130SAndreas Gohr protected $oGraph; 21762f4807SAndreas Gohr protected ?SQLiteDB $db = null; 226b6f8822SAndreas Gohr 236b6f8822SAndreas Gohr /** 24d5ef99ddSAndreas Gohr * Get SQLiteDB instance 25d5ef99ddSAndreas Gohr * 26d5ef99ddSAndreas Gohr * @return SQLiteDB|null 27*483101d3SAndreas Gohr * @throws Exception when SQLite initialization failed 28d5ef99ddSAndreas Gohr */ 29*483101d3SAndreas Gohr public function getDB(): ?SQLiteDB 30d5ef99ddSAndreas Gohr { 31d5ef99ddSAndreas Gohr if ($this->db === null) { 32*483101d3SAndreas Gohr if (!class_exists(SQLiteDB::class)) throw new \Exception('SQLite Plugin missing'); 33762f4807SAndreas Gohr $this->db = new SQLiteDB('statistics', DOKU_PLUGIN . 'statistics/db/'); 34d5ef99ddSAndreas Gohr } 35d5ef99ddSAndreas Gohr return $this->db; 36d5ef99ddSAndreas Gohr } 37d5ef99ddSAndreas Gohr 38d5ef99ddSAndreas Gohr 39d5ef99ddSAndreas Gohr /** 406b6f8822SAndreas Gohr * Return an instance of the query class 416b6f8822SAndreas Gohr * 42b6632b6eSAndreas Gohr * @return Query 436b6f8822SAndreas Gohr */ 44*483101d3SAndreas Gohr public function Query(): Query 45a8acb244SAndreas Gohr { 466b6f8822SAndreas Gohr if (is_null($this->oQuery)) { 47b6632b6eSAndreas Gohr $this->oQuery = new Query($this); 486b6f8822SAndreas Gohr } 496b6f8822SAndreas Gohr return $this->oQuery; 506b6f8822SAndreas Gohr } 516b6f8822SAndreas Gohr 526b6f8822SAndreas Gohr /** 536b6f8822SAndreas Gohr * Return an instance of the logger class 546b6f8822SAndreas Gohr * 55aab59130SAndreas Gohr * @return Logger 566b6f8822SAndreas Gohr */ 57*483101d3SAndreas Gohr public function Logger(): ?Logger 58a8acb244SAndreas Gohr { 59b6eece2fSAndreas Gohr $this->prefix = $this->getConf('db_prefix'); 606b6f8822SAndreas Gohr if (is_null($this->oLogger)) { 61aab59130SAndreas Gohr $this->oLogger = new Logger($this); 626b6f8822SAndreas Gohr } 636b6f8822SAndreas Gohr return $this->oLogger; 646b6f8822SAndreas Gohr } 656b6f8822SAndreas Gohr 666b6f8822SAndreas Gohr /** 676b6f8822SAndreas Gohr * Return an instance of the Graph class 686b6f8822SAndreas Gohr * 691664ba1dSAndreas Gohr * @return StatisticsGraph 706b6f8822SAndreas Gohr */ 71a8acb244SAndreas Gohr public function Graph() 72a8acb244SAndreas Gohr { 73b6eece2fSAndreas Gohr $this->prefix = $this->getConf('db_prefix'); 746b6f8822SAndreas Gohr if (is_null($this->oGraph)) { 75a8acb244SAndreas Gohr require __DIR__ . '/inc/StatisticsGraph.class.php'; 766b6f8822SAndreas Gohr $this->oGraph = new StatisticsGraph($this); 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