public function days($days = 30) { //hits $hits = Hit::factory()->fetch(time() - 3600 * 24 * $days)->cnt(); $hitsflow = Hit::timeflow(time() - 3600 * 24 * $days, null, 30, false); $unique = Hit::factory()->fetch(time() - 3600 * 24 * $days)->unique()->cnt(); $uniqueflow = Hit::timeflow(time() - 3600 * 24 * $days, null, 30, true); $this->templatemanager->assign('hits', $hits); $this->templatemanager->assign('hitsflow', $hitsflow); $this->templatemanager->assign('unique', $unique); $this->templatemanager->assign('uniqueflow', $uniqueflow); $this->templatemanager->assign('days', $days); //pages $pagehits = Hit::factory()->select('*')->select_func('COUNT', '@id', 'cnt')->include_related('page', null, TRUE, TRUE)->where('page_id >', 0)->fetch(time() - 3600 * 24 * $days)->unique('page_id')->limit(100)->get(); for ($i = 0; $i < count($pagehits->all); $i++) { $pagehits->all[$i]->timeflow = Hit::timeflow(time() - 3600 * 24 * $days, null, 30, false, $pagehits->all[$i]->page_id); } $this->templatemanager->assign('pagehits', $pagehits); //sasa $returning = Hit::factory()->fetch(time() - 3600 * 24 * $days)->unique()->where('returning', true)->cnt(); $returningflow = Hit::timeflow(time() - 3600 * 24 * $days, null, 30, true, null, true); $this->templatemanager->assign('returning', $returning); $this->templatemanager->assign('returningflow', $returningflow); //contents edited $cnt_edits = ContentRevision::factory()->where('created >=', time() - 3600 * 24 * $days)->get()->result_count(); $new_users = User::factory()->where('created >=', time() - 3600 * 24 * $days)->get(); $new_users = $new_users->result_count(); $new_pages = Page::factory()->where('created >=', time() - 3600 * 24 * $days)->get()->result_count(); $repeats = RepeatableItem::factory()->where('timestamp >=', time() - 3600 * 24 * $days)->get()->result_count(); $this->templatemanager->assign('cnt_edits', $cnt_edits); $this->templatemanager->assign('new_users', $new_users); $this->templatemanager->assign('new_pages', $new_pages); $this->templatemanager->assign('repeatables', $repeats); //get stats for browsers $browsers = Hit::factory()->select('browser')->select_func('COUNT', '@id', 'cnt')->fetch(time() - 3600 * 24 * $days)->unique('browser')->order_by('cnt DESC')->get(); $browsersarr = array(); $browsers->iu_total = 0; foreach ($browsers as $bro) { $browsers->iu_total += $bro->cnt; } $limit = $browsers->result_count() > 10 ? 10 : $browsers->result_count(); for ($i = 0; $i < $limit; $i++) { $br = $browsers->all[$i]; $obj = new stdClass(); $obj->label = str_replace("'", "\\'", $br->browser) . ' (' . percent($br->cnt, $browsers->iu_total) . '%)'; $obj->data = (int) $br->cnt; $browsersarr[] = $obj; } //usort($browsersarr, array($this, 'compare_series')); $this->templatemanager->assign('browsers', $browsers); $this->templatemanager->assign('browsers_series', $browsersarr); //get stats for operating systems $oses = Hit::factory()->select('os')->select_func('COUNT', '@id', 'cnt')->fetch(time() - 3600 * 24 * $days)->unique('os')->order_by('cnt DESC')->get(); $osarr = array(); $oses->iu_total = 0; foreach ($oses as $osi) { $oses->iu_total += $osi->cnt; } $limit = $oses->result_count() > 10 ? 10 : $oses->result_count(); for ($i = 0; $i < $limit; $i++) { $os = $oses->all[$i]; $obj = new stdClass(); $obj->label = str_replace("'", "\\'", $os->os) . ' (' . percent($os->cnt, $oses->iu_total) . '%)'; $obj->data = (int) $os->cnt; $osarr[] = $obj; } //usort($osarr, array($this, 'compare_series')); $this->templatemanager->assign('oses', $oses); $this->templatemanager->assign('oses_series', $osarr); //get stats for countries $geoip_db_filename = './iu-resources/geoip/GeoIP.dat'; if (is_file($geoip_db_filename)) { $countries = Hit::factory()->select('country')->select_func('COUNT', '@id', 'cnt')->fetch(time() - 3600 * 24 * $days)->unique('country')->order_by('cnt DESC')->get(); $conarr = array(); $countries->iu_total = 0; foreach ($countries as $cou) { $countries->iu_total += $cou->cnt; } //var_dump(percent(20,100)); $limit = $countries->result_count() > 10 ? 10 : $countries->result_count(); for ($i = 0; $i < $limit; $i++) { $c = $countries->all[$i]; $obj = new stdClass(); $obj->label = str_replace("'", "\\'", empty($c->country) ? __("(unknown)") : $c->country) . ' (' . percent($c->cnt, $countries->iu_total) . '%)'; $obj->data = (int) $c->cnt; $conarr[] = $obj; } //usort($conarr, array($this, 'compare_series')); $this->templatemanager->assign('countries', $countries); $this->templatemanager->assign('countries_series', $conarr); } $this->templatemanager->show_template('statistics'); }
public function index() { //get stats $last15 = Hit::factory()->fetch(time() - 60 * 15)->unique()->cnt(); $last15bymin = Hit::timeflow(time() - 60 * 15, null, 15); $last4hrs = Hit::factory()->fetch(time() - 3600 * 4)->unique()->cnt(); $last4hrsbymin = Hit::timeflow(time() - 3600 * 4, null, 16); $today = Hit::factory()->fetch(mktime(0, 0, 0))->unique()->cnt(); $todaybymin = Hit::timeflow(mktime(0, 0, 0), null, 24); $yesterday = Hit::factory()->fetch(mktime(0, 0, 0) - 3600 * 24, mktime(0, 0, 0))->unique()->cnt(); $yesterdaybymin = Hit::timeflow(mktime(0, 0, 0) - 3600 * 24, mktime(0, 0, 0), 24); $lastweek = Hit::factory()->fetch(mktime(0, 0, 0) - 3600 * 24 * 7)->unique()->cnt(); $lastweekbymin = Hit::timeflow(mktime(0, 0, 0) - 3600 * 24 * 7, null, 14); $lastmonth = Hit::factory()->fetch(mktime(0, 0, 0) - 3600 * 24 * 30)->unique()->cnt(); $lastmonthbymin = Hit::timeflow(mktime(0, 0, 0) - 3600 * 24 * 7, null, 30); $returning = Hit::factory()->fetch(time() - 3600 * 24 * 30)->unique()->where('returning', true)->cnt(); $new_pages = Page::factory()->where('created >=', time() - 3600 * 24 * 30)->get()->result_count(); $countries = Hit::factory()->fetch(time() - 3600 * 24 * 30)->group_by('country')->cnt(); $pagehits = Hit::factory()->select('*,count(page_id) as cnt')->include_related('page', null, TRUE, TRUE)->where('page_id >', 0)->fetch(time() - 3600 * 24 * 7)->group_by('page_id')->limit(1)->get(); $this->templatemanager->assign('pagehits', $pagehits); $ping = false; $pingset = Setting::factory('last_ping'); $lastping = (int) $pingset->value; if (time() - $lastping > 3600 * 24 * 7) { $ping = true; } $pingset->value = time(); $pingset->save(); $this->templatemanager->assign('last15', $last15); $this->templatemanager->assign('last15bymin', $last15bymin); $this->templatemanager->assign('last4hrs', $last4hrs); $this->templatemanager->assign('last4hrsbymin', $last4hrsbymin); $this->templatemanager->assign('today', $today); $this->templatemanager->assign('todaybymin', $todaybymin); $this->templatemanager->assign('yesterday', $yesterday); $this->templatemanager->assign('yesterdaybymin', $yesterdaybymin); $this->templatemanager->assign('lastweek', $lastweek); $this->templatemanager->assign('lastweekbymin', $lastweekbymin); $this->templatemanager->assign('lastmonth', $lastmonth); $this->templatemanager->assign('lastmonthbymin', $lastmonthbymin); $this->templatemanager->assign('returning', $returning); $this->templatemanager->assign('new_pages', $new_pages); $this->templatemanager->assign('countries', $countries); $this->templatemanager->assign('ping', $ping); //latest repeatables $last_repeatables = RepeatableItem::factory()->order_by('timestamp DESC')->limit(5)->get(); $this->templatemanager->assign('last_repeatables', $last_repeatables); //latest contents updated $last_contents = Content::factory()->where_related_contenttype('classname', 'Html')->order_by('updated DESC, created DESC')->limit(10)->get(); $this->templatemanager->assign('last_contents', $last_contents); //count content updates (revisions) $revs = ContentRevision::factory()->count(); $this->templatemanager->assign('revisions', $revs); //if geoip is old, notify $geoip_db_filename = './iu-resources/geoip/GeoIP.dat'; if (is_file($geoip_db_filename)) { $month_earlier = time() - 3600 * 24 * 30; $filemtime = filemtime($geoip_db_filename); if ($this->user->can('edit_settings') && $filemtime <= $month_earlier) { $lnk = site_url('administration/maintenance'); $this->templatemanager->notify(__("Your GeoIP database is now older than one month! Consider <a href='{$lnk}'>updating it</a>!"), 'information'); } } //get latest users $users = User::factory()->order_by('created DESC')->limit(5)->get(); $this->templatemanager->assign('users', $users); $this->templatemanager->show_template("dashboard"); }