*/ class admin_plugin_statistics extends AdminPlugin { /** @var string the currently selected page */ protected $opt = ''; /** @var string from date in YYYY-MM-DD */ protected $from = ''; /** @var string to date in YYYY-MM-DD */ protected $to = ''; /** @var int Offset to use when displaying paged data */ protected $start = 0; /** @var helper_plugin_statistics */ protected $hlp; /** * Available statistic pages */ protected $pages = [ 'dashboard' => 'printDashboard', 'content' => [ 'pages' => 'printTable', 'edits' => 'printTable', 'images' => 'printImages', 'downloads' => 'printDownloads', 'history' => 'printHistory', ], 'users' => [ 'topdomain' => 'printTableAndPieGraph', 'topuser' => 'printTableAndPieGraph', 'topeditor' => 'printTableAndPieGraph', 'topgroup' => 'printTableAndPieGraph', 'topgroupedit' => 'printTableAndPieGraph', 'seenusers' => 'printTable', ], 'links' => [ 'referer' => 'printReferer', 'newreferer' => 'printTable', 'outlinks' => 'printTable' ], 'campaign' => [ 'campaigns' => 'printTableAndPieGraph', 'source' => 'printTableAndPieGraph', 'medium' => 'printTableAndPieGraph', ], 'search' => [ 'searchengines' => 'printTableAndPieGraph', 'internalsearchphrases' => 'printTable', 'internalsearchwords' => 'printTable', ], 'technology' => [ 'browsers' => 'printTableAndPieGraph', 'os' => 'printTableAndPieGraph', 'countries' => 'printTableAndPieGraph', 'resolution' => 'printTableAndScatterGraph', 'viewport' => 'printTableAndScatterGraph', ] ]; /** @var array keeps a list of all real content pages, generated from above array */ protected $allowedpages = []; /** * Initialize the helper */ public function __construct() { $this->hlp = plugin_load('helper', 'statistics'); // remove pages that are not available because logging its data is disabled if ($this->getConf('nolocation')) { $this->pages['technology'] = array_diff($this->pages['technology'], ['countries']); } if ($this->getConf('nousers')) { unset($this->pages['users']); } // build a list of pages foreach ($this->pages as $key => $val) { if (is_array($val)) { $this->allowedpages = array_merge($this->allowedpages, $val); } else { $this->allowedpages[$key] = $val; } } } /** * Access for managers allowed */ public function forAdminOnly() { return false; } /** * return sort order for position in admin menu */ public function getMenuSort() { return 350; } /** * handle user request */ public function handle() { global $INPUT; $this->opt = preg_replace('/[^a-z]+/', '', $INPUT->str('opt')); if (!isset($this->allowedpages[$this->opt])) $this->opt = 'dashboard'; $this->start = $INPUT->int('s'); $this->setTimeframe($INPUT->str('f', date('Y-m-d')), $INPUT->str('t', date('Y-m-d'))); } /** * set limit clause */ public function setTimeframe($from, $to) { // swap if wrong order if ($from > $to) [$from, $to] = [$to, $from]; $this->hlp->getQuery()->setTimeFrame($from, $to); $this->from = $from; $this->to = $to; } /** * Output the Statistics */ public function html() { echo ''; echo ''; echo '
' . $this->getLang('intro_dashboard') . '
'; // general info echo '' . $this->getLang('intro_history') . '
'; $this->html_graph('history_page_count', 600, 200); $this->html_graph('history_page_size', 600, 200); $this->html_graph('history_media_count', 600, 200); $this->html_graph('history_media_size', 600, 200); } public function printTableAndPieGraph($name) { echo '' . $this->getLang("intro_$name") . '
'; $graph = $this->hlp->getGraph($this->from, $this->to, 300, 300); $graph->sumUpPieChart($name); $result = $this->hlp->getQuery()->$name(); $this->html_resulttable($result, '', 150); } public function printTableAndScatterGraph() { echo '' . $this->getLang('intro_resolution') . '
'; $this->html_graph('resolution', 650, 490); $result = $this->hlp->getQuery()->resolution(); $this->html_resulttable($result, '', 150); } public function printTable($name) { echo '' . $this->getLang("intro_$name") . '
'; $result = $this->hlp->getQuery()->$name(); $this->html_resulttable($result, '', 150); } public function printImages() { echo '' . $this->getLang('intro_images') . '
'; $result = $this->hlp->getQuery()->imagessum(); echo ''; echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); echo '
'; $result = $this->hlp->getQuery()->images(); $this->html_resulttable($result, '', 150); } public function printDownloads() { echo '' . $this->getLang('intro_downloads') . '
'; $result = $this->hlp->getQuery()->downloadssum(); echo ''; echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); echo '
'; $result = $this->hlp->getQuery()->downloads(); $this->html_resulttable($result, '', 150); } public function printReferer() { $result = $this->hlp->getQuery()->aggregate(); if ($result['referers']) { printf( '' . $this->getLang('intro_referer') . '
', $result['referers'], $result['direct'], (100 * $result['direct'] / $result['referers']), $result['search'], (100 * $result['search'] / $result['referers']), $result['external'], (100 * $result['external'] / $result['referers']) ); } $result = $this->hlp->getQuery()->referer(); $this->html_resulttable($result, '', 150); } // endregion /** * Display a result in a HTML table */ public function html_resulttable($result, $header = '', $pager = 0) { echo '| ' . hsc($h) . ' | '; } echo '
|---|
| '; if ($k == 'page') { echo ''; echo hsc($v); echo ''; } elseif ($k == 'media') { echo ''; echo hsc($v); echo ''; } elseif ($k == 'filesize') { echo filesize_h($v); } elseif ($k == 'url') { $url = hsc($v); $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url); if (strlen($url) > 45) { $url = substr($url, 0, 30) . ' … ' . substr($url, -15); } echo ''; echo $url; echo ''; } elseif ($k == 'ilookup') { echo 'Search'; } elseif ($k == 'engine') { $name = SearchEngines::getName($v); $url = SearchEngines::getURL($v); if ($url) { echo '' . hsc($name) . ''; } else { echo hsc($name); } } elseif ($k == 'html') { echo $v; } else { echo hsc($v); } echo ' | '; } echo '