11878f16fSAndreas Gohr<?php 2a8acb244SAndreas Gohr 3211caa5dSAndreas Gohr// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps 4a8acb244SAndreas Gohruse dokuwiki\Extension\AdminPlugin; 5c4c84f98SAndreas Gohruse dokuwiki\plugin\statistics\SearchEngines; 6a8acb244SAndreas Gohr 71878f16fSAndreas Gohr/** 81878f16fSAndreas Gohr * statistics plugin 91878f16fSAndreas Gohr * 101878f16fSAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 116b6f8822SAndreas Gohr * @author Andreas Gohr <gohr@splitbrain.org> 121878f16fSAndreas Gohr */ 13a8acb244SAndreas Gohrclass admin_plugin_statistics extends AdminPlugin 14a8acb244SAndreas Gohr{ 1533a136e5SAndreas Gohr /** @var string the currently selected page */ 16a901d721SAndreas Gohr protected $opt = ''; 1733a136e5SAndreas Gohr 1833a136e5SAndreas Gohr /** @var string from date in YYYY-MM-DD */ 19a901d721SAndreas Gohr protected $from = ''; 2033a136e5SAndreas Gohr /** @var string to date in YYYY-MM-DD */ 21a901d721SAndreas Gohr protected $to = ''; 2233a136e5SAndreas Gohr /** @var int Offset to use when displaying paged data */ 2333a136e5SAndreas Gohr protected $start = 0; 2433a136e5SAndreas Gohr 2533a136e5SAndreas Gohr /** @var helper_plugin_statistics */ 2633a136e5SAndreas Gohr protected $hlp; 2733a136e5SAndreas Gohr 28a901d721SAndreas Gohr /** 29a901d721SAndreas Gohr * Available statistic pages 30a901d721SAndreas Gohr */ 31483101d3SAndreas Gohr protected $pages = [ 32*444fcd22SAndreas Gohr 'dashboard' => 'printDashboard', 33*444fcd22SAndreas Gohr 'content' => [ 34*444fcd22SAndreas Gohr 'pages' => 'printTable', 35*444fcd22SAndreas Gohr 'edits' => 'printTable', 36*444fcd22SAndreas Gohr 'images' => 'printImages', 37*444fcd22SAndreas Gohr 'downloads' => 'printDownloads', 38*444fcd22SAndreas Gohr 'history' => 'printHistory', 39*444fcd22SAndreas Gohr ], 40*444fcd22SAndreas Gohr 'users' => [ 41*444fcd22SAndreas Gohr 'topdomain' => 'printTableAndPieGraph', 42*444fcd22SAndreas Gohr 'topuser' => 'printTableAndPieGraph', 43*444fcd22SAndreas Gohr 'topeditor' => 'printTableAndPieGraph', 44*444fcd22SAndreas Gohr 'topgroup' => 'printTableAndPieGraph', 45*444fcd22SAndreas Gohr 'topgroupedit' => 'printTableAndPieGraph', 46*444fcd22SAndreas Gohr 'seenusers' => 'printTable', 47*444fcd22SAndreas Gohr ], 48*444fcd22SAndreas Gohr 'links' => [ 49*444fcd22SAndreas Gohr 'referer' => 'printReferer', 50*444fcd22SAndreas Gohr 'newreferer' => 'printTable', 51*444fcd22SAndreas Gohr 'outlinks' => 'printTable' 52*444fcd22SAndreas Gohr ], 53*444fcd22SAndreas Gohr 'search' => [ 54*444fcd22SAndreas Gohr 'searchengines' => 'printTableAndPieGraph', 55*444fcd22SAndreas Gohr 'internalsearchphrases' => 'printTable', 56*444fcd22SAndreas Gohr 'internalsearchwords' => 'printTable', 57*444fcd22SAndreas Gohr ], 58*444fcd22SAndreas Gohr 'technology' => [ 59*444fcd22SAndreas Gohr 'browsers' => 'printTableAndPieGraph', 60*444fcd22SAndreas Gohr 'os' => 'printTableAndPieGraph', 61*444fcd22SAndreas Gohr 'countries' => 'printTableAndPieGraph', 62*444fcd22SAndreas Gohr 'resolution' => 'printTableAndScatterGraph', 63*444fcd22SAndreas Gohr 'viewport' => 'printTableAndScatterGraph', 64*444fcd22SAndreas Gohr ] 65483101d3SAndreas Gohr ]; 661878f16fSAndreas Gohr 6781ff4c3aSAndreas Gohr /** @var array keeps a list of all real content pages, generated from above array */ 68a8acb244SAndreas Gohr protected $allowedpages = []; 6981ff4c3aSAndreas Gohr 701878f16fSAndreas Gohr /** 716b6f8822SAndreas Gohr * Initialize the helper 726b6f8822SAndreas Gohr */ 73a8acb244SAndreas Gohr public function __construct() 74a8acb244SAndreas Gohr { 756b6f8822SAndreas Gohr $this->hlp = plugin_load('helper', 'statistics'); 7681ff4c3aSAndreas Gohr 77ba6b3b10SAndreas Gohr // remove pages that are not available because logging its data is disabled 78ba6b3b10SAndreas Gohr if ($this->getConf('nolocation')) { 79ba6b3b10SAndreas Gohr $this->pages['technology'] = array_diff($this->pages['technology'], ['countries']); 80ba6b3b10SAndreas Gohr } 81d550a4adSAndreas Gohr if ($this->getConf('nousers')) { 82d550a4adSAndreas Gohr unset($this->pages['users']); 83d550a4adSAndreas Gohr } 84ba6b3b10SAndreas Gohr 8581ff4c3aSAndreas Gohr // build a list of pages 8681ff4c3aSAndreas Gohr foreach ($this->pages as $key => $val) { 8781ff4c3aSAndreas Gohr if (is_array($val)) { 8881ff4c3aSAndreas Gohr $this->allowedpages = array_merge($this->allowedpages, $val); 8981ff4c3aSAndreas Gohr } else { 90*444fcd22SAndreas Gohr $this->allowedpages[$key] = $val; 9181ff4c3aSAndreas Gohr } 9281ff4c3aSAndreas Gohr } 936b6f8822SAndreas Gohr } 946b6f8822SAndreas Gohr 956b6f8822SAndreas Gohr /** 961878f16fSAndreas Gohr * Access for managers allowed 971878f16fSAndreas Gohr */ 98a8acb244SAndreas Gohr public function forAdminOnly() 99a8acb244SAndreas Gohr { 1001878f16fSAndreas Gohr return false; 1011878f16fSAndreas Gohr } 1021878f16fSAndreas Gohr 1031878f16fSAndreas Gohr /** 1041878f16fSAndreas Gohr * return sort order for position in admin menu 1051878f16fSAndreas Gohr */ 106a8acb244SAndreas Gohr public function getMenuSort() 107a8acb244SAndreas Gohr { 1086b6f8822SAndreas Gohr return 350; 1091878f16fSAndreas Gohr } 1101878f16fSAndreas Gohr 1111878f16fSAndreas Gohr /** 1121878f16fSAndreas Gohr * handle user request 1131878f16fSAndreas Gohr */ 114a8acb244SAndreas Gohr public function handle() 115a8acb244SAndreas Gohr { 116483101d3SAndreas Gohr global $INPUT; 117483101d3SAndreas Gohr $this->opt = preg_replace('/[^a-z]+/', '', $INPUT->str('opt')); 118*444fcd22SAndreas Gohr if (!isset($this->allowedpages[$this->opt])) $this->opt = 'dashboard'; 119a901d721SAndreas Gohr 120483101d3SAndreas Gohr $this->start = $INPUT->int('s'); 121483101d3SAndreas Gohr $this->setTimeframe($INPUT->str('f', date('Y-m-d')), $INPUT->str('t', date('Y-m-d'))); 122e8699bceSAndreas Gohr } 12395eb68e6SAndreas Gohr 124e8699bceSAndreas Gohr /** 125e8699bceSAndreas Gohr * set limit clause 126e8699bceSAndreas Gohr */ 127a8acb244SAndreas Gohr public function setTimeframe($from, $to) 128a8acb244SAndreas Gohr { 129047fcb0fSAndreas Gohr // swap if wrong order 130a8acb244SAndreas Gohr if ($from > $to) [$from, $to] = [$to, $from]; 131047fcb0fSAndreas Gohr 132211caa5dSAndreas Gohr $this->hlp->getQuery()->setTimeFrame($from, $to); 133e8699bceSAndreas Gohr $this->from = $from; 134e8699bceSAndreas Gohr $this->to = $to; 1351878f16fSAndreas Gohr } 1361878f16fSAndreas Gohr 1371878f16fSAndreas Gohr /** 13879b4a855SAndreas Gohr * Output the Statistics 1391878f16fSAndreas Gohr */ 140a8acb244SAndreas Gohr public function html() 141a8acb244SAndreas Gohr { 142b0cf2118SAnna Dabrowska echo '<script src="' . DOKU_BASE . 'lib/plugins/statistics/lib/chart.js"></script>'; 143b0cf2118SAnna Dabrowska echo '<script src="' . DOKU_BASE . 'lib/plugins/statistics/lib/chartjs-plugin-datalabels.js"></script>'; 144b0cf2118SAnna Dabrowska 1451d2d78ccSAndreas Gohr echo '<div id="plugin__statistics">'; 1460c3b1e44SAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 147264f1744SAndreas Gohr $this->html_timeselect(); 148441bfb8eSAndreas Gohr tpl_flush(); 149264f1744SAndreas Gohr 150*444fcd22SAndreas Gohr 151*444fcd22SAndreas Gohr $method = $this->allowedpages[$this->opt]; 15279b4a855SAndreas Gohr if (method_exists($this, $method)) { 153a901d721SAndreas Gohr echo '<div class="plg_stats_' . $this->opt . '">'; 154a901d721SAndreas Gohr echo '<h2>' . $this->getLang($this->opt) . '</h2>'; 155*444fcd22SAndreas Gohr $this->$method($this->opt); 156a901d721SAndreas Gohr echo '</div>'; 15714d99ec0SAndreas Gohr } 1581d2d78ccSAndreas Gohr echo '</div>'; 15914d99ec0SAndreas Gohr } 16014d99ec0SAndreas Gohr 1616b6f8822SAndreas Gohr /** 1626b6f8822SAndreas Gohr * Return the TOC 1636b6f8822SAndreas Gohr * 1646b6f8822SAndreas Gohr * @return array 1656b6f8822SAndreas Gohr */ 166a8acb244SAndreas Gohr public function getTOC() 167a8acb244SAndreas Gohr { 168a8acb244SAndreas Gohr $toc = []; 16981ff4c3aSAndreas Gohr foreach ($this->pages as $key => $info) { 17081ff4c3aSAndreas Gohr if (is_array($info)) { 17181ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 17281ff4c3aSAndreas Gohr '', 17381ff4c3aSAndreas Gohr $this->getLang($key), 17481ff4c3aSAndreas Gohr 1, 17581ff4c3aSAndreas Gohr '' 17647ffcf7dSAndreas Gohr ); 17781ff4c3aSAndreas Gohr 178*444fcd22SAndreas Gohr foreach (array_keys($info) as $page) { 17981ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 180211caa5dSAndreas Gohr '?do=admin&page=statistics&opt=' . $page . 181211caa5dSAndreas Gohr '&f=' . $this->from . 182211caa5dSAndreas Gohr '&t=' . $this->to, 18381ff4c3aSAndreas Gohr $this->getLang($page), 18481ff4c3aSAndreas Gohr 2, 18581ff4c3aSAndreas Gohr '' 18681ff4c3aSAndreas Gohr ); 18781ff4c3aSAndreas Gohr } 18881ff4c3aSAndreas Gohr } else { 18981ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 190211caa5dSAndreas Gohr '?do=admin&page=statistics&opt=' . $key . 191211caa5dSAndreas Gohr '&f=' . $this->from . 192211caa5dSAndreas Gohr '&t=' . $this->to, 19381ff4c3aSAndreas Gohr $this->getLang($key), 19481ff4c3aSAndreas Gohr 1, 19581ff4c3aSAndreas Gohr '' 19681ff4c3aSAndreas Gohr ); 19781ff4c3aSAndreas Gohr } 19847ffcf7dSAndreas Gohr } 19947ffcf7dSAndreas Gohr return $toc; 2009da6395dSAndreas Gohr } 2019da6395dSAndreas Gohr 202*444fcd22SAndreas Gohr /** 203*444fcd22SAndreas Gohr * @fixme instead of this, I would like the print* methods to call the Graph methods 204*444fcd22SAndreas Gohr */ 205a8acb244SAndreas Gohr public function html_graph($name, $width, $height) 206a8acb244SAndreas Gohr { 207211caa5dSAndreas Gohr $this->hlp->getGraph($this->from, $this->to, $width, $height)->$name(); 208dc7b1e5eSAndreas Gohr } 209dc7b1e5eSAndreas Gohr 2106b6f8822SAndreas Gohr /** 2116b6f8822SAndreas Gohr * Outputs pagination links 2126b6f8822SAndreas Gohr * 21333a136e5SAndreas Gohr * @param int $limit 21433a136e5SAndreas Gohr * @param int $next 2156b6f8822SAndreas Gohr */ 216a8acb244SAndreas Gohr public function html_pager($limit, $next) 217a8acb244SAndreas Gohr { 218211caa5dSAndreas Gohr $params = [ 219211caa5dSAndreas Gohr 'do' => 'admin', 220211caa5dSAndreas Gohr 'page' => 'statistics', 221211caa5dSAndreas Gohr 'opt' => $this->opt, 222211caa5dSAndreas Gohr 'f' => $this->from, 223211caa5dSAndreas Gohr 't' => $this->to, 224211caa5dSAndreas Gohr ]; 2252507f8e0SAndreas Gohr 226211caa5dSAndreas Gohr echo '<div class="plg_stats_pager">'; 2272507f8e0SAndreas Gohr if ($this->start > 0) { 2282507f8e0SAndreas Gohr $go = max($this->start - $limit, 0); 229211caa5dSAndreas Gohr $params['s'] = $go; 230211caa5dSAndreas Gohr echo '<a href="?' . buildURLparams($params) . '" class="prev button">' . $this->getLang('prev') . '</a>'; 2312507f8e0SAndreas Gohr } 2322507f8e0SAndreas Gohr 2332507f8e0SAndreas Gohr if ($next) { 2342507f8e0SAndreas Gohr $go = $this->start + $limit; 235211caa5dSAndreas Gohr $params['s'] = $go; 236211caa5dSAndreas Gohr echo '<a href="?' . buildURLparams($params) . '" class="next button">' . $this->getLang('next') . '</a>'; 2372507f8e0SAndreas Gohr } 2382507f8e0SAndreas Gohr echo '</div>'; 2392507f8e0SAndreas Gohr } 2402507f8e0SAndreas Gohr 241264f1744SAndreas Gohr /** 242264f1744SAndreas Gohr * Print the time selection menu 243264f1744SAndreas Gohr */ 244a8acb244SAndreas Gohr public function html_timeselect() 245a8acb244SAndreas Gohr { 246483101d3SAndreas Gohr $quick = [ 247483101d3SAndreas Gohr 'today' => date('Y-m-d'), 248483101d3SAndreas Gohr 'last1' => date('Y-m-d', time() - (60 * 60 * 24)), 249483101d3SAndreas Gohr 'last7' => date('Y-m-d', time() - (60 * 60 * 24 * 7)), 250483101d3SAndreas Gohr 'last30' => date('Y-m-d', time() - (60 * 60 * 24 * 30)), 251483101d3SAndreas Gohr ]; 252483101d3SAndreas Gohr 25314d99ec0SAndreas Gohr 254264f1744SAndreas Gohr echo '<div class="plg_stats_timeselect">'; 2556985b606SAndreas Gohr echo '<span>' . $this->getLang('time_select') . '</span> '; 256264f1744SAndreas Gohr 257047fcb0fSAndreas Gohr echo '<form action="' . DOKU_SCRIPT . '" method="get">'; 258264f1744SAndreas Gohr echo '<input type="hidden" name="do" value="admin" />'; 259264f1744SAndreas Gohr echo '<input type="hidden" name="page" value="statistics" />'; 260264f1744SAndreas Gohr echo '<input type="hidden" name="opt" value="' . $this->opt . '" />'; 261483101d3SAndreas Gohr echo '<input type="date" name="f" value="' . $this->from . '" class="edit" />'; 262483101d3SAndreas Gohr echo '<input type="date" name="t" value="' . $this->to . '" class="edit" />'; 263264f1744SAndreas Gohr echo '<input type="submit" value="go" class="button" />'; 26414d99ec0SAndreas Gohr echo '</form>'; 265264f1744SAndreas Gohr 2666985b606SAndreas Gohr echo '<ul>'; 267483101d3SAndreas Gohr foreach ($quick as $name => $time) { 268eaa05ffcSAndreas Gohr // today is included only today 269eaa05ffcSAndreas Gohr $to = $name == 'today' ? $quick['today'] : $quick['last1']; 270eaa05ffcSAndreas Gohr 271211caa5dSAndreas Gohr $url = buildURLparams([ 272211caa5dSAndreas Gohr 'do' => 'admin', 273211caa5dSAndreas Gohr 'page' => 'statistics', 274211caa5dSAndreas Gohr 'opt' => $this->opt, 275211caa5dSAndreas Gohr 'f' => $time, 276eaa05ffcSAndreas Gohr 't' => $to, 277211caa5dSAndreas Gohr ]); 278211caa5dSAndreas Gohr 2796985b606SAndreas Gohr echo '<li>'; 280211caa5dSAndreas Gohr echo '<a href="?' . $url . '">'; 281483101d3SAndreas Gohr echo $this->getLang('time_' . $name); 2826985b606SAndreas Gohr echo '</a>'; 2836985b606SAndreas Gohr echo '</li>'; 2846985b606SAndreas Gohr } 2856985b606SAndreas Gohr echo '</ul>'; 2866985b606SAndreas Gohr 287264f1744SAndreas Gohr echo '</div>'; 28814d99ec0SAndreas Gohr } 28914d99ec0SAndreas Gohr 290*444fcd22SAndreas Gohr // region: Print functions for the different statistic pages 291*444fcd22SAndreas Gohr 292f5f32cbfSAndreas Gohr /** 293f5f32cbfSAndreas Gohr * Print an introductionary screen 294f5f32cbfSAndreas Gohr */ 295*444fcd22SAndreas Gohr public function printDashboard() 296a8acb244SAndreas Gohr { 297878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_dashboard') . '</p>'; 2982812a751SAndreas Gohr 2992812a751SAndreas Gohr // general info 3002812a751SAndreas Gohr echo '<div class="plg_stats_top">'; 301211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->aggregate(); 3021d2d78ccSAndreas Gohr 3031fd51258SAndreas Gohr echo '<ul>'; 304a8acb244SAndreas Gohr foreach (['pageviews', 'sessions', 'visitors', 'users', 'logins', 'current'] as $name) { 305eabe0d07SAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 306eabe0d07SAndreas Gohr } 3072812a751SAndreas Gohr echo '</ul>'; 3081d2d78ccSAndreas Gohr 3091fd51258SAndreas Gohr echo '<ul>'; 31044f81330SAndreas Gohr foreach (['bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations', 'last'] as $name) { 3111d2d78ccSAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 3121d2d78ccSAndreas Gohr } 3131d2d78ccSAndreas Gohr echo '</ul>'; 3141d2d78ccSAndreas Gohr 315259897e1SAndreas Gohr $this->html_graph('dashboardviews', 700, 280); 316259897e1SAndreas Gohr $this->html_graph('dashboardwiki', 700, 280); 3172812a751SAndreas Gohr echo '</div>'; 3182812a751SAndreas Gohr 319211caa5dSAndreas Gohr $quickgraphs = [ 320211caa5dSAndreas Gohr ['lbl' => 'dash_mostpopular', 'query' => 'pages', 'opt' => 'page'], 321211caa5dSAndreas Gohr ['lbl' => 'dash_newincoming', 'query' => 'newreferer', 'opt' => 'newreferer'], 322211caa5dSAndreas Gohr ['lbl' => 'dash_topsearch', 'query' => 'searchphrases', 'opt' => 'internalsearchphrases'], 323211caa5dSAndreas Gohr ]; 32487d5e44bSAndreas Gohr 325211caa5dSAndreas Gohr foreach ($quickgraphs as $graph) { 326211caa5dSAndreas Gohr $params = [ 327211caa5dSAndreas Gohr 'do' => 'admin', 328211caa5dSAndreas Gohr 'page' => 'statistics', 329211caa5dSAndreas Gohr 'f' => $this->from, 330211caa5dSAndreas Gohr 't' => $this->to, 331211caa5dSAndreas Gohr 'opt' => $graph['opt'], 332211caa5dSAndreas Gohr ]; 33354f6c432SAndreas Gohr 334264f1744SAndreas Gohr echo '<div>'; 335211caa5dSAndreas Gohr echo '<h2>' . $this->getLang($graph['lbl']) . '</h2>'; 336211caa5dSAndreas Gohr $result = call_user_func([$this->hlp->getQuery(), $graph['query']]); 33729dea504SAndreas Gohr $this->html_resulttable($result); 3381fd51258SAndreas Gohr echo '<p><a href="?' . buildURLparams($params) . '" class="more">' . $this->getLang('more') . '…</a></p>'; 339264f1744SAndreas Gohr echo '</div>'; 34014d99ec0SAndreas Gohr } 341211caa5dSAndreas Gohr } 34214d99ec0SAndreas Gohr 343*444fcd22SAndreas Gohr public function printHistory($name) 344a8acb244SAndreas Gohr { 345cae4a1c5SAndreas Gohr echo '<p>' . $this->getLang('intro_history') . '</p>'; 346338987f5SAndreas Gohr $this->html_graph('history_page_count', 600, 200); 347338987f5SAndreas Gohr $this->html_graph('history_page_size', 600, 200); 348338987f5SAndreas Gohr $this->html_graph('history_media_count', 600, 200); 349338987f5SAndreas Gohr $this->html_graph('history_media_size', 600, 200); 350cae4a1c5SAndreas Gohr } 351cae4a1c5SAndreas Gohr 352*444fcd22SAndreas Gohr 353*444fcd22SAndreas Gohr public function printTableAndPieGraph($name) { 354*444fcd22SAndreas Gohr echo '<p>' . $this->getLang("intro_$name") . '</p>'; 355*444fcd22SAndreas Gohr $this->html_graph($name, 300, 300); 356*444fcd22SAndreas Gohr $result = $this->hlp->getQuery()->$name(); 3572507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3589da6395dSAndreas Gohr } 3599da6395dSAndreas Gohr 360*444fcd22SAndreas Gohr public function printTableAndScatterGraph() 361a8acb244SAndreas Gohr { 362*444fcd22SAndreas Gohr echo '<p>' . $this->getLang('intro_resolution') . '</p>'; 363*444fcd22SAndreas Gohr $this->html_graph('resolution', 650, 490); 364*444fcd22SAndreas Gohr $result = $this->hlp->getQuery()->resolution(); 3652507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3669da6395dSAndreas Gohr } 3679da6395dSAndreas Gohr 368*444fcd22SAndreas Gohr public function printTable($name) 369a8acb244SAndreas Gohr { 370*444fcd22SAndreas Gohr echo '<p>' . $this->getLang("intro_$name") . '</p>'; 371*444fcd22SAndreas Gohr $result = $this->hlp->getQuery()->$name(); 3721664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3731664ba1dSAndreas Gohr } 3741664ba1dSAndreas Gohr 375*444fcd22SAndreas Gohr 376*444fcd22SAndreas Gohr public function printImages() 377a8acb244SAndreas Gohr { 3781664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_images') . '</p>'; 379616c1e8bSAndreas Gohr 380211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->imagessum(); 381616c1e8bSAndreas Gohr echo '<p>'; 382616c1e8bSAndreas Gohr echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); 383616c1e8bSAndreas Gohr echo '</p>'; 384616c1e8bSAndreas Gohr 385211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->images(); 3861664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3871664ba1dSAndreas Gohr } 3881664ba1dSAndreas Gohr 389*444fcd22SAndreas Gohr public function printDownloads() 390a8acb244SAndreas Gohr { 3911664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_downloads') . '</p>'; 392616c1e8bSAndreas Gohr 393211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->downloadssum(); 394616c1e8bSAndreas Gohr echo '<p>'; 395616c1e8bSAndreas Gohr echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); 396616c1e8bSAndreas Gohr echo '</p>'; 397616c1e8bSAndreas Gohr 398211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->downloads(); 3991664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 4001664ba1dSAndreas Gohr } 4011664ba1dSAndreas Gohr 402*444fcd22SAndreas Gohr public function printReferer() 403a8acb244SAndreas Gohr { 404211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->aggregate(); 4052812a751SAndreas Gohr 4062a30f557SAndreas Gohr if ($result['referers']) { 4070863c19cSAndreas Gohr printf( 4080863c19cSAndreas Gohr '<p>' . $this->getLang('intro_referer') . '</p>', 4092a30f557SAndreas Gohr $result['referers'], 410a8acb244SAndreas Gohr $result['direct'], 4112a30f557SAndreas Gohr (100 * $result['direct'] / $result['referers']), 412a8acb244SAndreas Gohr $result['search'], 4132a30f557SAndreas Gohr (100 * $result['search'] / $result['referers']), 414a8acb244SAndreas Gohr $result['external'], 4152a30f557SAndreas Gohr (100 * $result['external'] / $result['referers']) 4160863c19cSAndreas Gohr ); 41794023548SAndreas Gohr } 4182812a751SAndreas Gohr 419211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->referer(); 4202507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 4219da6395dSAndreas Gohr } 4229da6395dSAndreas Gohr 423*444fcd22SAndreas Gohr // endregion 424e7a2f1e0SAndreas Gohr 42533a136e5SAndreas Gohr 42614d99ec0SAndreas Gohr /** 42714d99ec0SAndreas Gohr * Display a result in a HTML table 42814d99ec0SAndreas Gohr */ 429a8acb244SAndreas Gohr public function html_resulttable($result, $header = '', $pager = 0) 430a8acb244SAndreas Gohr { 43156f647ddSAndreas Gohr echo '<table class="inline">'; 4322812a751SAndreas Gohr if (is_array($header)) { 43314d99ec0SAndreas Gohr echo '<tr>'; 43414d99ec0SAndreas Gohr foreach ($header as $h) { 43514d99ec0SAndreas Gohr echo '<th>' . hsc($h) . '</th>'; 43614d99ec0SAndreas Gohr } 43714d99ec0SAndreas Gohr echo '</tr>'; 4382812a751SAndreas Gohr } 43914d99ec0SAndreas Gohr 4402507f8e0SAndreas Gohr $count = 0; 4412ee939eeSAndreas Gohr if (is_array($result)) foreach ($result as $row) { 44214d99ec0SAndreas Gohr echo '<tr>'; 44314d99ec0SAndreas Gohr foreach ($row as $k => $v) { 444f3818071SAndreas Gohr if ($k == 'res_x') continue; 445f3818071SAndreas Gohr if ($k == 'res_y') continue; 446f3818071SAndreas Gohr 4472812a751SAndreas Gohr echo '<td class="plg_stats_X' . $k . '">'; 44814d99ec0SAndreas Gohr if ($k == 'page') { 44914d99ec0SAndreas Gohr echo '<a href="' . wl($v) . '" class="wikilink1">'; 45014d99ec0SAndreas Gohr echo hsc($v); 45114d99ec0SAndreas Gohr echo '</a>'; 4521664ba1dSAndreas Gohr } elseif ($k == 'media') { 4531664ba1dSAndreas Gohr echo '<a href="' . ml($v) . '" class="wikilink1">'; 4541664ba1dSAndreas Gohr echo hsc($v); 4551664ba1dSAndreas Gohr echo '</a>'; 4561664ba1dSAndreas Gohr } elseif ($k == 'filesize') { 4571664ba1dSAndreas Gohr echo filesize_h($v); 45814d99ec0SAndreas Gohr } elseif ($k == 'url') { 45954f6c432SAndreas Gohr $url = hsc($v); 46083b63546SAndreas Gohr $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url); 4612812a751SAndreas Gohr if (strlen($url) > 45) { 4622812a751SAndreas Gohr $url = substr($url, 0, 30) . ' … ' . substr($url, -15); 46354f6c432SAndreas Gohr } 46414d99ec0SAndreas Gohr echo '<a href="' . $v . '" class="urlextern">'; 46554f6c432SAndreas Gohr echo $url; 46614d99ec0SAndreas Gohr echo '</a>'; 4675bccfe87SAndreas Gohr } elseif ($k == 'ilookup') { 468a8acb244SAndreas Gohr echo '<a href="' . wl('', ['id' => $v, 'do' => 'search']) . '">Search</a>'; 46912dcdeccSAndreas Gohr } elseif ($k == 'engine') { 470c4c84f98SAndreas Gohr $name = SearchEngines::getName($v); 471c4c84f98SAndreas Gohr $url = SearchEngines::getURL($v); 472c4c84f98SAndreas Gohr if ($url) { 473c4c84f98SAndreas Gohr echo '<a href="' . $url . '">' . hsc($name) . '</a>'; 47413a86c14SAndreas Gohr } else { 475c4c84f98SAndreas Gohr echo hsc($name); 47613a86c14SAndreas Gohr } 47714d99ec0SAndreas Gohr } elseif ($k == 'html') { 47814d99ec0SAndreas Gohr echo $v; 47914d99ec0SAndreas Gohr } else { 48014d99ec0SAndreas Gohr echo hsc($v); 48114d99ec0SAndreas Gohr } 48214d99ec0SAndreas Gohr echo '</td>'; 48314d99ec0SAndreas Gohr } 48414d99ec0SAndreas Gohr echo '</tr>'; 4852507f8e0SAndreas Gohr 4862507f8e0SAndreas Gohr if ($pager && ($count == $pager)) break; 4872507f8e0SAndreas Gohr $count++; 48814d99ec0SAndreas Gohr } 48914d99ec0SAndreas Gohr echo '</table>'; 4902507f8e0SAndreas Gohr 4912507f8e0SAndreas Gohr if ($pager) $this->html_pager($pager, count($result) > $pager); 4921878f16fSAndreas Gohr } 49313a86c14SAndreas Gohr} 494