*/ 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' => 1, 'content' => ['page', 'edits', 'images', 'downloads', 'history'], 'users' => ['topdomain', 'topuser', 'topeditor', 'topgroup', 'topgroupedit', 'seenusers'], 'links' => ['referer', 'newreferer', 'outlinks'], 'search' => ['searchengines', 'internalsearchphrases', 'internalsearchwords'], 'technology' => ['browsers', 'os', 'countries', 'resolution', 'viewport'] ]; /** @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; } } } /** * 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 (!in_array($this->opt, $this->allowedpages)) $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 html_countries() { echo '' . $this->getLang('intro_countries') . '
'; $this->html_graph('countries', 300, 300); $result = $this->hlp->getQuery()->countries(); $this->html_resulttable($result, '', 150); } public function html_page() { echo '' . $this->getLang('intro_page') . '
'; $result = $this->hlp->getQuery()->pages(); $this->html_resulttable($result, '', 150); } public function html_edits() { echo '' . $this->getLang('intro_edits') . '
'; $result = $this->hlp->getQuery()->edits(); $this->html_resulttable($result, '', 150); } public function html_images() { 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 html_downloads() { 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 html_browsers() { echo '' . $this->getLang('intro_browsers') . '
'; $this->html_graph('browsers', 300, 300); $result = $this->hlp->getQuery()->browsers(false); $this->html_resulttable($result, '', 150); } public function html_topdomain() { echo '' . $this->getLang('intro_topdomain') . '
'; $this->html_graph('topdomain', 300, 300); $result = $this->hlp->getQuery()->topdomain(); $this->html_resulttable($result, '', 150); } public function html_topuser() { echo '' . $this->getLang('intro_topuser') . '
'; $this->html_graph('topuser', 300, 300); $result = $this->hlp->getQuery()->topuser(); $this->html_resulttable($result, '', 150); } public function html_topeditor() { echo '' . $this->getLang('intro_topeditor') . '
'; $this->html_graph('topeditor', 300, 300); $result = $this->hlp->getQuery()->topeditor(); $this->html_resulttable($result, '', 150); } public function html_topgroup() { echo '' . $this->getLang('intro_topgroup') . '
'; $this->html_graph('topgroup', 300, 300); $result = $this->hlp->getQuery()->topgroup(); $this->html_resulttable($result, '', 150); } public function html_topgroupedit() { echo '' . $this->getLang('intro_topgroupedit') . '
'; $this->html_graph('topgroupedit', 300, 300); $result = $this->hlp->getQuery()->topgroupedit(); $this->html_resulttable($result, '', 150); } public function html_os() { echo '' . $this->getLang('intro_os') . '
'; $this->html_graph('os', 300, 300); $result = $this->hlp->getQuery()->os(); $this->html_resulttable($result, '', 150); } public function html_referer() { $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); } public function html_newreferer() { echo '' . $this->getLang('intro_newreferer') . '
'; $result = $this->hlp->getQuery()->newreferer(); $this->html_resulttable($result, '', 150); } public function html_outlinks() { echo '' . $this->getLang('intro_outlinks') . '
'; $result = $this->hlp->getQuery()->outlinks(); $this->html_resulttable($result, '', 150); } public function html_searchphrases() { echo '' . $this->getLang('intro_searchphrases') . '
'; $result = $this->hlp->getQuery()->searchphrases(true); $this->html_resulttable($result, '', 150); } public function html_searchwords() { echo '' . $this->getLang('intro_searchwords') . '
'; $result = $this->hlp->getQuery()->searchwords(true); $this->html_resulttable($result, '', 150); } public function html_internalsearchphrases() { echo '' . $this->getLang('intro_internalsearchphrases') . '
'; $result = $this->hlp->getQuery()->searchphrases(false); $this->html_resulttable($result, '', 150); } public function html_internalsearchwords() { echo '' . $this->getLang('intro_internalsearchwords') . '
'; $result = $this->hlp->getQuery()->searchwords(false); $this->html_resulttable($result, '', 150); } public function html_searchengines() { echo '' . $this->getLang('intro_searchengines') . '
'; $this->html_graph('searchengines', 400, 200); $result = $this->hlp->getQuery()->searchengines(); $this->html_resulttable($result, '', 150); } public function html_resolution() { echo '' . $this->getLang('intro_resolution') . '
'; $this->html_graph('resolution', 650, 490); $result = $this->hlp->getQuery()->resolution(); $this->html_resulttable($result, '', 150); } public function html_viewport() { echo '' . $this->getLang('intro_viewport') . '
'; $this->html_graph('viewport', 650, 490); $result = $this->hlp->getQuery()->viewport(); $this->html_resulttable($result, '', 150); } public function html_seenusers() { echo '' . $this->getLang('intro_seenusers') . '
'; $result = $this->hlp->getQuery()->seenusers(); $this->html_resulttable($result, '', 150); } /** * 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 == 'lookup') {
echo '';
echo ' ';
echo ' ';
echo '';
echo ' ';
echo ' ';
echo '';
echo ' ';
echo ' ';
} 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 '