function country() { $this->template->content = new View('admin/stats/country'); $this->template->content->title = Kohana::lang('ui_admin.statistics'); // Javascript Header $this->themes->js = new View('admin/stats/stats_js'); $this->template->content->failure = ''; // Set the date range (how many days in the past from today?) $range = isset($_GET['range']) ? $_GET['range'] : 30; $this->template->content->range = $range; // Get an arbitrary date range $dp1 = isset($_GET['dp1']) ? $_GET['dp1'] : null; $dp2 = isset($_GET['dp2']) ? $_GET['dp2'] : null; $countries = Stats_Model::get_hit_countries($range, $dp1, $dp2); // If we failed to get country data, fail. if (!$countries) { $this->template->content->countries = array(); $this->template->content->num_countries = 0; $this->template->content->dp1 = $dp1; $this->template->content->dp2 = $dp2; $this->template->content->visitor_map = ''; $this->template->content->uniques = 0; $this->template->content->visits = 0; $this->template->content->pageviews = 0; $this->template->content->active_tab = 'uniques'; $this->template->content->failure = Kohana::lang('ui_admin.stats_collection_error_short'); return false; } //Set up country map and totals $country_total = array(); $countries_reformatted = array(); foreach ($countries as $country) { foreach ($country as $code => $arr) { if (!isset($country_total[$code])) { $country_total[$code] = 0; } $country_total[$code] += $arr['uniques']; $name = $arr['label']; if (!isset($countries_reformatted[$name])) { $countries_reformatted[$name] = array(); } if (!isset($countries_reformatted[$name]['count'])) { $countries_reformatted[$name]['count'] = 0; } $countries_reformatted[$name]['count'] += $arr['uniques']; $countries_reformatted[$name]['icon'] = $arr['logo']; } } arsort($countries_reformatted); $this->template->content->countries = $countries_reformatted; $this->template->content->num_countries = count($countries_reformatted); arsort($country_total); $codes = ''; $values = ''; $i = 0; foreach ($country_total as $code => $uniques) { if ($i == 0) { $highest = $uniques; } if ($i != 0) { $values .= ','; } $values .= $uniques / $highest * 100; $codes .= strtoupper($code); $i++; } $this->template->content->visitor_map = Kohana::config('core.site_protocol') . "://chart.googleapis.com/chart?chs=440x220&chf=bg,s,ffffff&cht=t&chtm=world&chco=cccccc,A07B7B,a20000&chld=" . $codes . "&chd=t:" . $values; // Hit Data $data = Stats_Model::get_hit_stats($range, $dp1, $dp2); $this->template->content->uniques = 0; $this->template->content->visits = 0; $this->template->content->pageviews = 0; $this->template->content->active_tab = 'uniques'; // Lazy tab switcher (not using javascript) if (isset($_GET['active_tab'])) { $this->template->content->active_tab = $_GET['active_tab']; } // If we failed to get hit data, fail. if (!$data) { $this->template->content->dp1 = $dp1; $this->template->content->dp2 = $dp2; return false; } $counts = array(); foreach ($data as $label => $data_array) { if (!isset($this->template->content->{$label})) { $this->template->content->{$label} = 0; } foreach ($data_array as $timestamp => $count) { $this->template->content->{$label} += $count; } } // Set the date reset($data['visits']); $this->template->content->dp1 = date('Y-m-d', key($data['visits']) / 1000); end($data['visits']); $this->template->content->dp2 = date('Y-m-d', key($data['visits']) / 1000); }
function hits() { $this->template->content = new View('admin/stats_hits'); $this->template->content->title = 'Hit Summary'; // Javascript Header $this->template->protochart_enabled = TRUE; // Hit Data $data = Stats_Model::get_hit_stats(); $traffic_chart = new protochart(); $options = array('xaxis' => array('mode' => '"time"'), 'legend' => array('show' => 'true')); $this->template->content->traffic_chart = $traffic_chart->chart('traffic', $data, $options); $this->template->content->raw_data = $data; }