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 = [ 32444fcd22SAndreas Gohr 'dashboard' => 'printDashboard', 33444fcd22SAndreas Gohr 'content' => [ 34444fcd22SAndreas Gohr 'pages' => 'printTable', 35444fcd22SAndreas Gohr 'edits' => 'printTable', 36444fcd22SAndreas Gohr 'images' => 'printImages', 37444fcd22SAndreas Gohr 'downloads' => 'printDownloads', 38444fcd22SAndreas Gohr 'history' => 'printHistory', 39444fcd22SAndreas Gohr ], 40444fcd22SAndreas Gohr 'users' => [ 41444fcd22SAndreas Gohr 'topdomain' => 'printTableAndPieGraph', 42444fcd22SAndreas Gohr 'topuser' => 'printTableAndPieGraph', 43444fcd22SAndreas Gohr 'topeditor' => 'printTableAndPieGraph', 44444fcd22SAndreas Gohr 'topgroup' => 'printTableAndPieGraph', 45444fcd22SAndreas Gohr 'topgroupedit' => 'printTableAndPieGraph', 46444fcd22SAndreas Gohr 'seenusers' => 'printTable', 47444fcd22SAndreas Gohr ], 48444fcd22SAndreas Gohr 'links' => [ 49444fcd22SAndreas Gohr 'referer' => 'printReferer', 50444fcd22SAndreas Gohr 'newreferer' => 'printTable', 51444fcd22SAndreas Gohr 'outlinks' => 'printTable' 52444fcd22SAndreas Gohr ], 53f666296fSAndreas Gohr 'campaign' => [ 54f666296fSAndreas Gohr 'campaigns' => 'printTableAndPieGraph', 55c65a3a20SAndreas Gohr 'source' => 'printTableAndPieGraph', 56c65a3a20SAndreas Gohr 'medium' => 'printTableAndPieGraph', 57c65a3a20SAndreas Gohr ], 58444fcd22SAndreas Gohr 'search' => [ 59444fcd22SAndreas Gohr 'searchengines' => 'printTableAndPieGraph', 60444fcd22SAndreas Gohr 'internalsearchphrases' => 'printTable', 61444fcd22SAndreas Gohr 'internalsearchwords' => 'printTable', 62444fcd22SAndreas Gohr ], 63444fcd22SAndreas Gohr 'technology' => [ 64444fcd22SAndreas Gohr 'browsers' => 'printTableAndPieGraph', 65444fcd22SAndreas Gohr 'os' => 'printTableAndPieGraph', 66444fcd22SAndreas Gohr 'countries' => 'printTableAndPieGraph', 67444fcd22SAndreas Gohr 'resolution' => 'printTableAndScatterGraph', 68444fcd22SAndreas Gohr 'viewport' => 'printTableAndScatterGraph', 69444fcd22SAndreas Gohr ] 70483101d3SAndreas Gohr ]; 711878f16fSAndreas Gohr 7281ff4c3aSAndreas Gohr /** @var array keeps a list of all real content pages, generated from above array */ 73a8acb244SAndreas Gohr protected $allowedpages = []; 7481ff4c3aSAndreas Gohr 751878f16fSAndreas Gohr /** 766b6f8822SAndreas Gohr * Initialize the helper 776b6f8822SAndreas Gohr */ 78a8acb244SAndreas Gohr public function __construct() 79a8acb244SAndreas Gohr { 806b6f8822SAndreas Gohr $this->hlp = plugin_load('helper', 'statistics'); 8181ff4c3aSAndreas Gohr 82ba6b3b10SAndreas Gohr // remove pages that are not available because logging its data is disabled 83ba6b3b10SAndreas Gohr if ($this->getConf('nolocation')) { 84ba6b3b10SAndreas Gohr $this->pages['technology'] = array_diff($this->pages['technology'], ['countries']); 85ba6b3b10SAndreas Gohr } 86d550a4adSAndreas Gohr if ($this->getConf('nousers')) { 87d550a4adSAndreas Gohr unset($this->pages['users']); 88d550a4adSAndreas Gohr } 89ba6b3b10SAndreas Gohr 9081ff4c3aSAndreas Gohr // build a list of pages 9181ff4c3aSAndreas Gohr foreach ($this->pages as $key => $val) { 9281ff4c3aSAndreas Gohr if (is_array($val)) { 9381ff4c3aSAndreas Gohr $this->allowedpages = array_merge($this->allowedpages, $val); 9481ff4c3aSAndreas Gohr } else { 95444fcd22SAndreas Gohr $this->allowedpages[$key] = $val; 9681ff4c3aSAndreas Gohr } 9781ff4c3aSAndreas Gohr } 986b6f8822SAndreas Gohr } 996b6f8822SAndreas Gohr 1006b6f8822SAndreas Gohr /** 1011878f16fSAndreas Gohr * Access for managers allowed 1021878f16fSAndreas Gohr */ 103a8acb244SAndreas Gohr public function forAdminOnly() 104a8acb244SAndreas Gohr { 1051878f16fSAndreas Gohr return false; 1061878f16fSAndreas Gohr } 1071878f16fSAndreas Gohr 1081878f16fSAndreas Gohr /** 1091878f16fSAndreas Gohr * return sort order for position in admin menu 1101878f16fSAndreas Gohr */ 111a8acb244SAndreas Gohr public function getMenuSort() 112a8acb244SAndreas Gohr { 1136b6f8822SAndreas Gohr return 350; 1141878f16fSAndreas Gohr } 1151878f16fSAndreas Gohr 1161878f16fSAndreas Gohr /** 1171878f16fSAndreas Gohr * handle user request 1181878f16fSAndreas Gohr */ 119a8acb244SAndreas Gohr public function handle() 120a8acb244SAndreas Gohr { 121483101d3SAndreas Gohr global $INPUT; 122483101d3SAndreas Gohr $this->opt = preg_replace('/[^a-z]+/', '', $INPUT->str('opt')); 123444fcd22SAndreas Gohr if (!isset($this->allowedpages[$this->opt])) $this->opt = 'dashboard'; 124a901d721SAndreas Gohr 125483101d3SAndreas Gohr $this->start = $INPUT->int('s'); 126483101d3SAndreas Gohr $this->setTimeframe($INPUT->str('f', date('Y-m-d')), $INPUT->str('t', date('Y-m-d'))); 127e8699bceSAndreas Gohr } 12895eb68e6SAndreas Gohr 129e8699bceSAndreas Gohr /** 130e8699bceSAndreas Gohr * set limit clause 131e8699bceSAndreas Gohr */ 132a8acb244SAndreas Gohr public function setTimeframe($from, $to) 133a8acb244SAndreas Gohr { 134047fcb0fSAndreas Gohr // swap if wrong order 135a8acb244SAndreas Gohr if ($from > $to) [$from, $to] = [$to, $from]; 136047fcb0fSAndreas Gohr 137211caa5dSAndreas Gohr $this->hlp->getQuery()->setTimeFrame($from, $to); 138e8699bceSAndreas Gohr $this->from = $from; 139e8699bceSAndreas Gohr $this->to = $to; 1401878f16fSAndreas Gohr } 1411878f16fSAndreas Gohr 1421878f16fSAndreas Gohr /** 14379b4a855SAndreas Gohr * Output the Statistics 1441878f16fSAndreas Gohr */ 145a8acb244SAndreas Gohr public function html() 146a8acb244SAndreas Gohr { 147b0cf2118SAnna Dabrowska echo '<script src="' . DOKU_BASE . 'lib/plugins/statistics/lib/chart.js"></script>'; 148b0cf2118SAnna Dabrowska echo '<script src="' . DOKU_BASE . 'lib/plugins/statistics/lib/chartjs-plugin-datalabels.js"></script>'; 149b0cf2118SAnna Dabrowska 1501d2d78ccSAndreas Gohr echo '<div id="plugin__statistics">'; 1510c3b1e44SAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 152264f1744SAndreas Gohr $this->html_timeselect(); 153441bfb8eSAndreas Gohr tpl_flush(); 154264f1744SAndreas Gohr 155444fcd22SAndreas Gohr 156444fcd22SAndreas Gohr $method = $this->allowedpages[$this->opt]; 15779b4a855SAndreas Gohr if (method_exists($this, $method)) { 158a901d721SAndreas Gohr echo '<div class="plg_stats_' . $this->opt . '">'; 159a901d721SAndreas Gohr echo '<h2>' . $this->getLang($this->opt) . '</h2>'; 160444fcd22SAndreas Gohr $this->$method($this->opt); 161a901d721SAndreas Gohr echo '</div>'; 16214d99ec0SAndreas Gohr } 1631d2d78ccSAndreas Gohr echo '</div>'; 16414d99ec0SAndreas Gohr } 16514d99ec0SAndreas Gohr 1666b6f8822SAndreas Gohr /** 1676b6f8822SAndreas Gohr * Return the TOC 1686b6f8822SAndreas Gohr * 1696b6f8822SAndreas Gohr * @return array 1706b6f8822SAndreas Gohr */ 171a8acb244SAndreas Gohr public function getTOC() 172a8acb244SAndreas Gohr { 173a8acb244SAndreas Gohr $toc = []; 17481ff4c3aSAndreas Gohr foreach ($this->pages as $key => $info) { 17581ff4c3aSAndreas Gohr if (is_array($info)) { 17681ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 17781ff4c3aSAndreas Gohr '', 17881ff4c3aSAndreas Gohr $this->getLang($key), 17981ff4c3aSAndreas Gohr 1, 18081ff4c3aSAndreas Gohr '' 18147ffcf7dSAndreas Gohr ); 18281ff4c3aSAndreas Gohr 183444fcd22SAndreas Gohr foreach (array_keys($info) as $page) { 18481ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 185211caa5dSAndreas Gohr '?do=admin&page=statistics&opt=' . $page . 186211caa5dSAndreas Gohr '&f=' . $this->from . 187211caa5dSAndreas Gohr '&t=' . $this->to, 18881ff4c3aSAndreas Gohr $this->getLang($page), 18981ff4c3aSAndreas Gohr 2, 19081ff4c3aSAndreas Gohr '' 19181ff4c3aSAndreas Gohr ); 19281ff4c3aSAndreas Gohr } 19381ff4c3aSAndreas Gohr } else { 19481ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 195211caa5dSAndreas Gohr '?do=admin&page=statistics&opt=' . $key . 196211caa5dSAndreas Gohr '&f=' . $this->from . 197211caa5dSAndreas Gohr '&t=' . $this->to, 19881ff4c3aSAndreas Gohr $this->getLang($key), 19981ff4c3aSAndreas Gohr 1, 20081ff4c3aSAndreas Gohr '' 20181ff4c3aSAndreas Gohr ); 20281ff4c3aSAndreas Gohr } 20347ffcf7dSAndreas Gohr } 20447ffcf7dSAndreas Gohr return $toc; 2059da6395dSAndreas Gohr } 2069da6395dSAndreas Gohr 207444fcd22SAndreas Gohr /** 208444fcd22SAndreas Gohr * @fixme instead of this, I would like the print* methods to call the Graph methods 209444fcd22SAndreas Gohr */ 210a8acb244SAndreas Gohr public function html_graph($name, $width, $height) 211a8acb244SAndreas Gohr { 212211caa5dSAndreas Gohr $this->hlp->getGraph($this->from, $this->to, $width, $height)->$name(); 213dc7b1e5eSAndreas Gohr } 214dc7b1e5eSAndreas Gohr 2156b6f8822SAndreas Gohr /** 2166b6f8822SAndreas Gohr * Outputs pagination links 2176b6f8822SAndreas Gohr * 21833a136e5SAndreas Gohr * @param int $limit 21933a136e5SAndreas Gohr * @param int $next 2206b6f8822SAndreas Gohr */ 221a8acb244SAndreas Gohr public function html_pager($limit, $next) 222a8acb244SAndreas Gohr { 223211caa5dSAndreas Gohr $params = [ 224211caa5dSAndreas Gohr 'do' => 'admin', 225211caa5dSAndreas Gohr 'page' => 'statistics', 226211caa5dSAndreas Gohr 'opt' => $this->opt, 227211caa5dSAndreas Gohr 'f' => $this->from, 228211caa5dSAndreas Gohr 't' => $this->to, 229211caa5dSAndreas Gohr ]; 2302507f8e0SAndreas Gohr 231211caa5dSAndreas Gohr echo '<div class="plg_stats_pager">'; 2322507f8e0SAndreas Gohr if ($this->start > 0) { 2332507f8e0SAndreas Gohr $go = max($this->start - $limit, 0); 234211caa5dSAndreas Gohr $params['s'] = $go; 235211caa5dSAndreas Gohr echo '<a href="?' . buildURLparams($params) . '" class="prev button">' . $this->getLang('prev') . '</a>'; 2362507f8e0SAndreas Gohr } 2372507f8e0SAndreas Gohr 2382507f8e0SAndreas Gohr if ($next) { 2392507f8e0SAndreas Gohr $go = $this->start + $limit; 240211caa5dSAndreas Gohr $params['s'] = $go; 241211caa5dSAndreas Gohr echo '<a href="?' . buildURLparams($params) . '" class="next button">' . $this->getLang('next') . '</a>'; 2422507f8e0SAndreas Gohr } 2432507f8e0SAndreas Gohr echo '</div>'; 2442507f8e0SAndreas Gohr } 2452507f8e0SAndreas Gohr 246264f1744SAndreas Gohr /** 247264f1744SAndreas Gohr * Print the time selection menu 248264f1744SAndreas Gohr */ 249a8acb244SAndreas Gohr public function html_timeselect() 250a8acb244SAndreas Gohr { 251483101d3SAndreas Gohr $quick = [ 252483101d3SAndreas Gohr 'today' => date('Y-m-d'), 253483101d3SAndreas Gohr 'last1' => date('Y-m-d', time() - (60 * 60 * 24)), 254483101d3SAndreas Gohr 'last7' => date('Y-m-d', time() - (60 * 60 * 24 * 7)), 255483101d3SAndreas Gohr 'last30' => date('Y-m-d', time() - (60 * 60 * 24 * 30)), 256483101d3SAndreas Gohr ]; 257483101d3SAndreas Gohr 25814d99ec0SAndreas Gohr 259264f1744SAndreas Gohr echo '<div class="plg_stats_timeselect">'; 2606985b606SAndreas Gohr echo '<span>' . $this->getLang('time_select') . '</span> '; 261264f1744SAndreas Gohr 262047fcb0fSAndreas Gohr echo '<form action="' . DOKU_SCRIPT . '" method="get">'; 263264f1744SAndreas Gohr echo '<input type="hidden" name="do" value="admin" />'; 264264f1744SAndreas Gohr echo '<input type="hidden" name="page" value="statistics" />'; 265264f1744SAndreas Gohr echo '<input type="hidden" name="opt" value="' . $this->opt . '" />'; 266483101d3SAndreas Gohr echo '<input type="date" name="f" value="' . $this->from . '" class="edit" />'; 267483101d3SAndreas Gohr echo '<input type="date" name="t" value="' . $this->to . '" class="edit" />'; 268264f1744SAndreas Gohr echo '<input type="submit" value="go" class="button" />'; 26914d99ec0SAndreas Gohr echo '</form>'; 270264f1744SAndreas Gohr 2716985b606SAndreas Gohr echo '<ul>'; 272483101d3SAndreas Gohr foreach ($quick as $name => $time) { 273eaa05ffcSAndreas Gohr // today is included only today 274eaa05ffcSAndreas Gohr $to = $name == 'today' ? $quick['today'] : $quick['last1']; 275eaa05ffcSAndreas Gohr 276211caa5dSAndreas Gohr $url = buildURLparams([ 277211caa5dSAndreas Gohr 'do' => 'admin', 278211caa5dSAndreas Gohr 'page' => 'statistics', 279211caa5dSAndreas Gohr 'opt' => $this->opt, 280211caa5dSAndreas Gohr 'f' => $time, 281eaa05ffcSAndreas Gohr 't' => $to, 282211caa5dSAndreas Gohr ]); 283211caa5dSAndreas Gohr 2846985b606SAndreas Gohr echo '<li>'; 285211caa5dSAndreas Gohr echo '<a href="?' . $url . '">'; 286483101d3SAndreas Gohr echo $this->getLang('time_' . $name); 2876985b606SAndreas Gohr echo '</a>'; 2886985b606SAndreas Gohr echo '</li>'; 2896985b606SAndreas Gohr } 2906985b606SAndreas Gohr echo '</ul>'; 2916985b606SAndreas Gohr 292264f1744SAndreas Gohr echo '</div>'; 29314d99ec0SAndreas Gohr } 29414d99ec0SAndreas Gohr 295444fcd22SAndreas Gohr // region: Print functions for the different statistic pages 296444fcd22SAndreas Gohr 297f5f32cbfSAndreas Gohr /** 298f5f32cbfSAndreas Gohr * Print an introductionary screen 299f5f32cbfSAndreas Gohr */ 300444fcd22SAndreas Gohr public function printDashboard() 301a8acb244SAndreas Gohr { 302878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_dashboard') . '</p>'; 3032812a751SAndreas Gohr 3042812a751SAndreas Gohr // general info 3052812a751SAndreas Gohr echo '<div class="plg_stats_top">'; 306211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->aggregate(); 3071d2d78ccSAndreas Gohr 3081fd51258SAndreas Gohr echo '<ul>'; 309a8acb244SAndreas Gohr foreach (['pageviews', 'sessions', 'visitors', 'users', 'logins', 'current'] as $name) { 310eabe0d07SAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 311eabe0d07SAndreas Gohr } 3122812a751SAndreas Gohr echo '</ul>'; 3131d2d78ccSAndreas Gohr 3141fd51258SAndreas Gohr echo '<ul>'; 31544f81330SAndreas Gohr foreach (['bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations', 'last'] as $name) { 3161d2d78ccSAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 3171d2d78ccSAndreas Gohr } 3181d2d78ccSAndreas Gohr echo '</ul>'; 3191d2d78ccSAndreas Gohr 320259897e1SAndreas Gohr $this->html_graph('dashboardviews', 700, 280); 321259897e1SAndreas Gohr $this->html_graph('dashboardwiki', 700, 280); 3222812a751SAndreas Gohr echo '</div>'; 3232812a751SAndreas Gohr 324211caa5dSAndreas Gohr $quickgraphs = [ 325211caa5dSAndreas Gohr ['lbl' => 'dash_mostpopular', 'query' => 'pages', 'opt' => 'page'], 326211caa5dSAndreas Gohr ['lbl' => 'dash_newincoming', 'query' => 'newreferer', 'opt' => 'newreferer'], 327*3f5b75e7SAndreas Gohr ['lbl' => 'dash_topsearch', 'query' => 'internalsearchphrases', 'opt' => 'internalsearchphrases'], 328211caa5dSAndreas Gohr ]; 32987d5e44bSAndreas Gohr 330211caa5dSAndreas Gohr foreach ($quickgraphs as $graph) { 331211caa5dSAndreas Gohr $params = [ 332211caa5dSAndreas Gohr 'do' => 'admin', 333211caa5dSAndreas Gohr 'page' => 'statistics', 334211caa5dSAndreas Gohr 'f' => $this->from, 335211caa5dSAndreas Gohr 't' => $this->to, 336211caa5dSAndreas Gohr 'opt' => $graph['opt'], 337211caa5dSAndreas Gohr ]; 33854f6c432SAndreas Gohr 339264f1744SAndreas Gohr echo '<div>'; 340211caa5dSAndreas Gohr echo '<h2>' . $this->getLang($graph['lbl']) . '</h2>'; 341211caa5dSAndreas Gohr $result = call_user_func([$this->hlp->getQuery(), $graph['query']]); 34229dea504SAndreas Gohr $this->html_resulttable($result); 3431fd51258SAndreas Gohr echo '<p><a href="?' . buildURLparams($params) . '" class="more">' . $this->getLang('more') . '…</a></p>'; 344264f1744SAndreas Gohr echo '</div>'; 34514d99ec0SAndreas Gohr } 346211caa5dSAndreas Gohr } 34714d99ec0SAndreas Gohr 348444fcd22SAndreas Gohr public function printHistory($name) 349a8acb244SAndreas Gohr { 350cae4a1c5SAndreas Gohr echo '<p>' . $this->getLang('intro_history') . '</p>'; 351338987f5SAndreas Gohr $this->html_graph('history_page_count', 600, 200); 352338987f5SAndreas Gohr $this->html_graph('history_page_size', 600, 200); 353338987f5SAndreas Gohr $this->html_graph('history_media_count', 600, 200); 354338987f5SAndreas Gohr $this->html_graph('history_media_size', 600, 200); 355cae4a1c5SAndreas Gohr } 356cae4a1c5SAndreas Gohr 357444fcd22SAndreas Gohr 358444fcd22SAndreas Gohr public function printTableAndPieGraph($name) { 359444fcd22SAndreas Gohr echo '<p>' . $this->getLang("intro_$name") . '</p>'; 360f666296fSAndreas Gohr 361f666296fSAndreas Gohr 362f666296fSAndreas Gohr $graph = $this->hlp->getGraph($this->from, $this->to, 300, 300); 363f666296fSAndreas Gohr $graph->sumUpPieChart($name); 364f666296fSAndreas Gohr 365444fcd22SAndreas Gohr $result = $this->hlp->getQuery()->$name(); 3662507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3679da6395dSAndreas Gohr } 3689da6395dSAndreas Gohr 369444fcd22SAndreas Gohr public function printTableAndScatterGraph() 370a8acb244SAndreas Gohr { 371444fcd22SAndreas Gohr echo '<p>' . $this->getLang('intro_resolution') . '</p>'; 372444fcd22SAndreas Gohr $this->html_graph('resolution', 650, 490); 373444fcd22SAndreas Gohr $result = $this->hlp->getQuery()->resolution(); 3742507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3759da6395dSAndreas Gohr } 3769da6395dSAndreas Gohr 377444fcd22SAndreas Gohr public function printTable($name) 378a8acb244SAndreas Gohr { 379444fcd22SAndreas Gohr echo '<p>' . $this->getLang("intro_$name") . '</p>'; 380444fcd22SAndreas Gohr $result = $this->hlp->getQuery()->$name(); 3811664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3821664ba1dSAndreas Gohr } 3831664ba1dSAndreas Gohr 384444fcd22SAndreas Gohr 385444fcd22SAndreas Gohr public function printImages() 386a8acb244SAndreas Gohr { 3871664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_images') . '</p>'; 388616c1e8bSAndreas Gohr 389211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->imagessum(); 390616c1e8bSAndreas Gohr echo '<p>'; 391616c1e8bSAndreas Gohr echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); 392616c1e8bSAndreas Gohr echo '</p>'; 393616c1e8bSAndreas Gohr 394211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->images(); 3951664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3961664ba1dSAndreas Gohr } 3971664ba1dSAndreas Gohr 398444fcd22SAndreas Gohr public function printDownloads() 399a8acb244SAndreas Gohr { 4001664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_downloads') . '</p>'; 401616c1e8bSAndreas Gohr 402211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->downloadssum(); 403616c1e8bSAndreas Gohr echo '<p>'; 404616c1e8bSAndreas Gohr echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); 405616c1e8bSAndreas Gohr echo '</p>'; 406616c1e8bSAndreas Gohr 407211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->downloads(); 4081664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 4091664ba1dSAndreas Gohr } 4101664ba1dSAndreas Gohr 411444fcd22SAndreas Gohr public function printReferer() 412a8acb244SAndreas Gohr { 413211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->aggregate(); 4142812a751SAndreas Gohr 4152a30f557SAndreas Gohr if ($result['referers']) { 4160863c19cSAndreas Gohr printf( 4170863c19cSAndreas Gohr '<p>' . $this->getLang('intro_referer') . '</p>', 4182a30f557SAndreas Gohr $result['referers'], 419a8acb244SAndreas Gohr $result['direct'], 4202a30f557SAndreas Gohr (100 * $result['direct'] / $result['referers']), 421a8acb244SAndreas Gohr $result['search'], 4222a30f557SAndreas Gohr (100 * $result['search'] / $result['referers']), 423a8acb244SAndreas Gohr $result['external'], 4242a30f557SAndreas Gohr (100 * $result['external'] / $result['referers']) 4250863c19cSAndreas Gohr ); 42694023548SAndreas Gohr } 4272812a751SAndreas Gohr 428211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->referer(); 4292507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 4309da6395dSAndreas Gohr } 4319da6395dSAndreas Gohr 432444fcd22SAndreas Gohr // endregion 433e7a2f1e0SAndreas Gohr 43433a136e5SAndreas Gohr 43514d99ec0SAndreas Gohr /** 43614d99ec0SAndreas Gohr * Display a result in a HTML table 43714d99ec0SAndreas Gohr */ 438a8acb244SAndreas Gohr public function html_resulttable($result, $header = '', $pager = 0) 439a8acb244SAndreas Gohr { 44056f647ddSAndreas Gohr echo '<table class="inline">'; 4412812a751SAndreas Gohr if (is_array($header)) { 44214d99ec0SAndreas Gohr echo '<tr>'; 44314d99ec0SAndreas Gohr foreach ($header as $h) { 44414d99ec0SAndreas Gohr echo '<th>' . hsc($h) . '</th>'; 44514d99ec0SAndreas Gohr } 44614d99ec0SAndreas Gohr echo '</tr>'; 4472812a751SAndreas Gohr } 44814d99ec0SAndreas Gohr 4492507f8e0SAndreas Gohr $count = 0; 4502ee939eeSAndreas Gohr if (is_array($result)) foreach ($result as $row) { 45114d99ec0SAndreas Gohr echo '<tr>'; 45214d99ec0SAndreas Gohr foreach ($row as $k => $v) { 453f3818071SAndreas Gohr if ($k == 'res_x') continue; 454f3818071SAndreas Gohr if ($k == 'res_y') continue; 455f3818071SAndreas Gohr 4562812a751SAndreas Gohr echo '<td class="plg_stats_X' . $k . '">'; 45714d99ec0SAndreas Gohr if ($k == 'page') { 45814d99ec0SAndreas Gohr echo '<a href="' . wl($v) . '" class="wikilink1">'; 45914d99ec0SAndreas Gohr echo hsc($v); 46014d99ec0SAndreas Gohr echo '</a>'; 4611664ba1dSAndreas Gohr } elseif ($k == 'media') { 4621664ba1dSAndreas Gohr echo '<a href="' . ml($v) . '" class="wikilink1">'; 4631664ba1dSAndreas Gohr echo hsc($v); 4641664ba1dSAndreas Gohr echo '</a>'; 4651664ba1dSAndreas Gohr } elseif ($k == 'filesize') { 4661664ba1dSAndreas Gohr echo filesize_h($v); 46714d99ec0SAndreas Gohr } elseif ($k == 'url') { 46854f6c432SAndreas Gohr $url = hsc($v); 46983b63546SAndreas Gohr $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url); 4702812a751SAndreas Gohr if (strlen($url) > 45) { 4712812a751SAndreas Gohr $url = substr($url, 0, 30) . ' … ' . substr($url, -15); 47254f6c432SAndreas Gohr } 47314d99ec0SAndreas Gohr echo '<a href="' . $v . '" class="urlextern">'; 47454f6c432SAndreas Gohr echo $url; 47514d99ec0SAndreas Gohr echo '</a>'; 4765bccfe87SAndreas Gohr } elseif ($k == 'ilookup') { 477a8acb244SAndreas Gohr echo '<a href="' . wl('', ['id' => $v, 'do' => 'search']) . '">Search</a>'; 47812dcdeccSAndreas Gohr } elseif ($k == 'engine') { 479c4c84f98SAndreas Gohr $name = SearchEngines::getName($v); 480c4c84f98SAndreas Gohr $url = SearchEngines::getURL($v); 481c4c84f98SAndreas Gohr if ($url) { 482c4c84f98SAndreas Gohr echo '<a href="' . $url . '">' . hsc($name) . '</a>'; 48313a86c14SAndreas Gohr } else { 484c4c84f98SAndreas Gohr echo hsc($name); 48513a86c14SAndreas Gohr } 48614d99ec0SAndreas Gohr } elseif ($k == 'html') { 48714d99ec0SAndreas Gohr echo $v; 48814d99ec0SAndreas Gohr } else { 48914d99ec0SAndreas Gohr echo hsc($v); 49014d99ec0SAndreas Gohr } 49114d99ec0SAndreas Gohr echo '</td>'; 49214d99ec0SAndreas Gohr } 49314d99ec0SAndreas Gohr echo '</tr>'; 4942507f8e0SAndreas Gohr 4952507f8e0SAndreas Gohr if ($pager && ($count == $pager)) break; 4962507f8e0SAndreas Gohr $count++; 49714d99ec0SAndreas Gohr } 49814d99ec0SAndreas Gohr echo '</table>'; 4992507f8e0SAndreas Gohr 5002507f8e0SAndreas Gohr if ($pager) $this->html_pager($pager, count($result) > $pager); 5011878f16fSAndreas Gohr } 50213a86c14SAndreas Gohr} 503