/** * Runs this cron task. * * @return null */ public function run() { global $phpbb_root_path, $phpbb_container, $user; $sql = 'SELECT log FROM ' . $this->config_table; $result = $this->db->sql_query($sql); $sconfig['log'] = $this->db->sql_fetchfield('log'); $unique_aray = $module_aray = $browser_aray = $os_aray = $country_aray = $user_aray = $screen_aray = $referer_aray = $search_aray = array(); $sql = 'SELECT MIN(time) AS start_time FROM ' . $this->online_table; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $start_time = $row && $row['start_time'] ? $row['start_time'] : 0; if ($start_time) { $sql = 'SELECT time, uname, agent, ip_addr, module, host, domain, scr_res, page, referer, se_terms FROM ' . $this->online_table . ' WHERE time BETWEEN ' . $start_time . ' AND ' . strtotime("24:00", $start_time) . ' ORDER BY id ASC'; $result = $this->db->sql_query($sql); $starttime = explode(' ', microtime()); $starttime = $starttime[1] + $starttime[0]; $row_count = 0; include $phpbb_root_path . 'ext/forumhulp/statistics/vendor/find_os.' . $this->php_ext; while (still_on_time() && ($row = $this->db->sql_fetchrow($result))) { $module_aray = $row['module'] != '' ? $this->count_array($module_aray, $row['module']) : null; $os = new \find_os(); $os->setUserAgent($row['agent']); $browser_aray = $row['agent'] != '' ? $this->count_array($browser_aray, $os->getBrowser() . ' ' . $os->getVersion()) : null; $os_aray = $row['agent'] != '' ? $this->count_array($os_aray, $os->getPlatform()) : null; $country_aray = $row['domain'] != '' ? $this->count_array($country_aray, $row['domain']) : null; $user_aray = $row['uname'] != '' ? $this->count_array($user_aray, $row['uname']) : null; $screen_aray = $row['scr_res'] != '' ? $this->count_array($screen_aray, $row['scr_res']) : null; $referer_aray = $row['referer'] != '' ? $this->count_array($referer_aray, $this->url_to_domain($row['referer'])) : null; $search_aray = $row['se_terms'] != '' ? $this->split_array($search_aray, $row['se_terms']) : null; $unique_aray = $row['ip_addr'] != '' ? $this->count_array($unique_aray, $row['ip_addr']) : null; $row_count++; } $this->db->sql_freeresult($result); $unique_visiors = array($start_time => count($unique_aray)); $this->store($module_aray, 1); $this->store($browser_aray, 2); $this->store($os_aray, 3); $this->store($country_aray, 4); $this->store($user_aray, 5); $this->store($screen_aray, 6); $this->store($referer_aray, 7); $this->store($search_aray, 8); $this->store_unique_visitors($unique_visiors, 9); unset($module_aray, $browser_aray, $os_aray, $country_aray, $user_aray, $screen_aray, $referer_aray, $search_aray, $unique_visiors, $unique_aray); $sql = 'DELETE FROM ' . $this->online_table . ' WHERE time BETWEEN ' . $start_time . ' AND ' . strtotime("24:00", $start_time); $this->db->sql_query($sql); $sql = 'OPTIMIZE TABLE ' . $this->online_table; $this->db->sql_query($sql); $sql_ary = array('year' => date('Y', $start_time), 'month' => date('n', $start_time), 'day' => date('j', $start_time), 'hits' => $row_count); $sql = 'INSERT INTO ' . $this->stats_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary) . ' ON DUPLICATE KEY UPDATE hits = hits + ' . $sql_ary['hits']; $this->db->sql_query($sql); $mtime = explode(' ', microtime()); $totaltime = $mtime[0] + $mtime[1] - $starttime; $rows_per_second = $row_count / $totaltime; $sconfig['log'] ? add_log('admin', 'LOG_STATISTICS_PRUNED', $totaltime, $rows_per_second) : null; } else { $sconfig['log'] ? add_log('admin', 'LOG_STATISTICS_NO_PRUNE') : null; } $sql = 'SELECT MIN(time) AS start_time FROM ' . $this->online_table; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); if ($row) { $newtime = mktime(0, 0, 0) - $row['start_time'] >= 0 ? time() + 3600 : mktime(0, 0, 0); } else { $newtime = mktime(0, 0, 0); } $this->config->set('delete_statistics_last_gc', $newtime); }
public static function os($start = 0, $uaction = '', $overall = 0) { global $db, $config, $sconfig, $user, $tables, $request, $template, $phpbb_container; // sort keys, direction en sql $sort_key = $request->variable('sk', 'd'); $sort_dir = $request->variable('sd', 'd'); $sort_by_sql = array('d' => $overall ? 'o.name' : 'o.agent', 't' => 'total_per_os', 'p' => 'percent'); $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC'); $template->assign_vars(array('U_ACTION' => $uaction, 'S_SORT_KEY' => $sort_key, 'S_SORT_DIR' => $sort_dir, 'SUB_DISPLAY' => 'graph', 'SUBTITLE' => $user->lang['SYSTEMS'])); $sql = $overall ? 'SELECT COUNT(DISTINCT name) AS total_entries, MIN(first) AS firstdate, MAX(last) AS lastdate FROM ' . $tables['archive'] . ' WHERE cat = 3' : 'SELECT COUNT(DISTINCT agent) AS total_entries FROM ' . $tables['online']; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $total_entries = $row['total_entries']; $db->sql_freeresult($result); $template->assign_vars(array('OVERALLTXT' => $overall ? 'Today' : 'Overall', 'MINMAXDATE' => $overall && $total_entries ? '(' . $user->format_date($row['firstdate'], 'd m \'y') . ' - ' . $user->format_date($row['lastdate'], 'd m \'y') . ')' : '', 'OVERALLSORT' => $overall ? '&overall=1' : '')); $sql = $overall ? 'SELECT o.name, o.hits AS total_per_os, (SELECT SUM(hits) FROM ' . $tables['archive'] . ' WHERE cat = 3) as total, SUM(o.hits) / (SELECT SUM(hits) FROM ' . $tables['archive'] . ' WHERE cat = 3) AS percent FROM ' . $tables['archive'] . ' o WHERE cat = 3 GROUP BY o.name ORDER BY ' . $sql_sort : 'SELECT agent FROM ' . $tables['online']; $result = $overall ? $db->sql_query_limit($sql, $sconfig['statistics_max_os'], $start) : $db->sql_query($sql); $counter = 0; $graphstr = ''; if ($overall) { while ($row = $db->sql_fetchrow($result)) { $counter += 1; $template->assign_block_vars('onlinerow', array('COUNTER' => $start + $counter, 'NAME' => $row['name'], 'MODULECOUNT' => self::roundk($row['total_per_os']), 'TMODULECOUNT' => $row['total_per_os'], 'MODULETOTAL' => round($row['total_per_os'] / $row['total'] * 100, 1) . ' % (' . self::roundk($row['total_per_os']) . ' of ' . self::roundk($row['total']) . ')', 'TMODULETOTAL' => round($row['total_per_os'] / $row['total'] * 100, 1) . ' % (' . $row['total_per_os'] . ' of ' . $row['total'] . ')')); $graphstr .= ($graphstr == '' ? '' : ', ') . '[\'' . html_entity_decode($db->sql_escape($row['name'])) . '\', ' . $row['total_per_os'] . ']'; } } else { include 'find_os.php'; $os = new find_os(); $os_aray = array(); while ($row = $db->sql_fetchrow($result)) { $os->setUserAgent($row['agent']); $os_aray = $row['agent'] != '' ? self::count_array($os_aray, $os->getPlatform()) : null; } $total_entries = sizeof($os_aray); if ($sort_key == 'd') { $sort_dir == 'd' ? krsort($os_aray) : ksort($os_aray); } else { $sort_dir == 'd' ? arsort($os_aray) : asort($os_aray); } $counter = 0; $graphstr = ''; $row['total'] = array_sum($os_aray); foreach (array_slice($os_aray, $start, $sconfig['statistics_max_browsers'], true) as $row['Operating System'] => $row['total_per_os']) { $counter += 1; $template->assign_block_vars('onlinerow', array('COUNTER' => $start + $counter, 'NAME' => $row['Operating System'], 'MODULECOUNT' => $row['total_per_os'], 'MODULETOTAL' => round($row['total_per_os'] / $row['total'] * 100, 1) . ' % (' . $row['total_per_os'] . ' of ' . $row['total'] . ')')); $graphstr .= ($graphstr == '' ? '' : ', ') . '[\'' . html_entity_decode($db->sql_escape($row['Operating System'])) . '\', ' . $row['total_per_os'] . ']'; } } $pagination = $phpbb_container->get('pagination'); $base_url = $uaction . '&screen=os&sk=' . $sort_key . '&sd=' . $sort_dir . ($overall ? '&overall=1' : '&overall=0'); $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_entries, $sconfig['statistics_max_browsers'], $start); $template->assign_vars(array('ROWSPAN' => $total_entries, 'OVERALL' => $overall ? str_replace('&overall=1', '&overall=0', $base_url) : $base_url . '&overall=1', 'GRAPH' => '[' . $graphstr . ']')); }