Esempio n. 1
0
 /**
  * Create a pie chart of the ratios of the specified statistic for the specified page. The chart is saved as an SVG image in /data_custom/admin_stats/, and the tempcode for display of the graph and results table is returned
  *
  * @param  PATH		The page path
  * @param  string		The statistic to use
  * @param  string		Language identifier for the graph title
  * @param  string		Language identifier for the graph description
  * @param  string		Language identifier for the list title
  * @return array		A linear array containing the graph and list tempcode objects, respectively
  */
 function page_x_share($page, $type, $graph_title, $graph_description, $list_title)
 {
     //Return a pie chart with the $type used to view this page
     $start = get_param_integer('start_' . $type, 0);
     $max = get_param_integer('max_' . $type, 25);
     $sortables = array('views' => do_lang_tempcode('_VIEWS'));
     list($sortable, $sort_order) = explode(' ', get_param('sort', 'views DESC'), 2);
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $where = db_string_equal_to('the_page', $page);
     if (substr($page, 0, 6) == 'pages/') {
         $where .= ' OR ' . db_string_equal_to('the_page', '/' . $page);
     }
     // Legacy compatibility
     $ip_filter = $GLOBALS['DEBUG_MODE'] ? '' : ' AND ' . db_string_not_equal_to('ip', get_ip_address());
     $rows = $GLOBALS['SITE_DB']->query('SELECT id,' . $type . ' FROM ' . get_table_prefix() . 'stats WHERE (' . $where . ')' . $ip_filter, 5000);
     if (count($rows) < 1) {
         $list = new ocp_tempcode();
         $graph = new ocp_tempcode();
         return array($graph, $list);
     }
     $data1 = array();
     $degrees = 360 / count($rows);
     foreach ($rows as $value) {
         //if($value[$type]==0) $value[$type]=do_lang('_UNKNOWN');
         if (!array_key_exists($value[$type], $data1)) {
             $data1[$value[$type]] = $degrees;
         } else {
             $data1[$value[$type]] = ($data1[$value[$type]] / $degrees + 1) * $degrees;
         }
     }
     require_code('templates_results_table');
     $fields_title = results_field_title(array(do_lang_tempcode($list_title), do_lang_tempcode('COUNT_VIEWS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     $data = array();
     $done_total = 0;
     //$done=0;
     $i = 0;
     foreach ($data1 as $key => $value) {
         if ($i < $start) {
             $i++;
             continue;
         } elseif ($i >= $start + $max) {
             break;
         }
         if ($key == '') {
             $link = do_lang('_UNKNOWN');
         } else {
             $link = escape_html($key);
         }
         $fields->attach(results_entry(array($link, escape_html(integer_format($value)))));
         //if ($done<20)
         //{
         $data[$key] = $value * $degrees;
         //$done++;
         $done_total += $value;
         //}
         $i++;
     }
     if (count($rows) > $done_total) {
         $data[do_lang('OTHER')] = 360.0 - $done_total * $degrees;
         $fields->attach(results_entry(array(do_lang('OTHER'), integer_format(count($rows) - $done_total)), true));
     }
     if ($sortable == 'views') {
         asort($data1);
         if ($sort_order == 'DESC') {
             $data1 = array_reverse($data1);
         }
     }
     $list = results_table(do_lang_tempcode('PAGES_STATISTICS', escape_html($page)), $start, 'start_' . $type, $max, 'max_' . $type, $i, $fields_title, $fields, $sortables, $sortable, $sort_order, 'sort_' . $type);
     $output = create_pie_chart($data);
     $this->save_graph(strval($rows[0]['id']) . '-' . $type, $output);
     $graph = do_template('STATS_GRAPH', array('GRAPH' => get_custom_base_url() . '/data_custom/modules/admin_stats/' . strval($rows[0]['id']) . '-' . $type . '.xml', 'TITLE' => do_lang_tempcode($graph_title), 'TEXT' => do_lang_tempcode($graph_description)));
     return array($graph, $list);
 }
Esempio n. 2
0
 /**
  * The UI to show top search keywords.
  *
  * @param  object			The stats module object
  * @param  string			The screen type
  * @return tempcode		The UI
  */
 function search($ob, $type)
 {
     // Handle time range
     if (get_param_integer('dated', 0) == 0) {
         $title = get_page_title('SEARCH_STATISTICS');
         return $ob->get_between($title);
     }
     $time_start = get_input_date('time_start', true);
     $time_end = get_input_date('time_end', true);
     if (!is_null($time_end)) {
         $time_end += 60 * 60 * 24 - 1;
     }
     // So it is end of day not start
     if (is_null($time_start)) {
         $time_start = 0;
     }
     if (is_null($time_end)) {
         $time_end = time();
     }
     $title = get_page_title('SEARCH_STATISTICS_RANGE', true, array(escape_html(get_timezoned_date($time_start, false)), escape_html(get_timezoned_date($time_end, false))));
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 20);
     $sortables = array('s_primary' => do_lang_tempcode('SEARCH_STATISTICS'));
     $test = explode(' ', get_param('sort', 's_primary DESC'), 2);
     if (count($test) == 1) {
         $test[1] = 'DESC';
     }
     list($sortable, $sort_order) = $test;
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $rows = $GLOBALS['SITE_DB']->query('SELECT s_primary,COUNT(*) AS cnt FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'searches_logged WHERE s_time>' . strval((int) $time_start) . ' AND s_time<' . strval((int) $time_end) . ' GROUP BY s_primary ORDER BY ' . $sortable . ' ' . $sort_order);
     if (count($rows) < 1) {
         return warn_screen($title, do_lang_tempcode('NO_DATA'));
     }
     $keywords = array();
     $total = 0;
     foreach ($rows as $value) {
         $keywords[$value['s_primary']] = $value['cnt'];
         $total += $value['cnt'];
     }
     if ($sort_order == 'ASC') {
         asort($keywords);
     } else {
         arsort($keywords);
     }
     require_code('templates_results_table');
     $fields_title = results_field_title(array(do_lang_tempcode('KEYWORD'), do_lang_tempcode('COUNT_VIEWS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     $degrees = 360 / $total;
     $done_total = 0;
     //$done=0;
     $data = array();
     $i = 0;
     foreach ($keywords as $keyword => $views) {
         if ($i < $start) {
             $i++;
             continue;
         } elseif ($i >= $start + $max) {
             break;
         }
         if ($keyword == '') {
             $link = do_lang_tempcode('SEARCH_STATS_ADVANCED');
         } else {
             $link = protect_from_escaping(escape_html($keyword));
         }
         $fields->attach(results_entry(array($link, integer_format($views)), true));
         //if ($done<20)
         //{
         $data[$keyword] = $keywords[$keyword] * $degrees;
         //$done++;
         $done_total += $data[$keyword];
         //}
         $i++;
     }
     if (360 - $done_total > 0) {
         $data[do_lang('OTHER')] = 360 - $done_total;
         $fields->attach(results_entry(array(do_lang('OTHER'), float_format((360 - $done_total) / $degrees))));
     }
     $list = results_table(do_lang_tempcode('SEARCH_STATISTICS'), $start, 'start', $max, 'max', count($keywords), $fields_title, $fields, $sortables, $sortable, $sort_order, 'sort', new ocp_tempcode());
     $output = create_pie_chart($data);
     $ob->save_graph('Global-Search', $output);
     $graph = do_template('STATS_GRAPH', array('GRAPH' => get_custom_base_url() . '/data_custom/modules/admin_stats/Global-Search.xml', 'TITLE' => do_lang_tempcode('SEARCH_STATISTICS'), 'TEXT' => do_lang_tempcode('DESCRIPTION_SEARCH_STATISTICS')));
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('SITE_STATISTICS'))));
     return do_template('STATS_SCREEN', array('_GUID' => '727a59e061727c4a1e24345cecb769aa', 'TITLE' => $title, 'GRAPH' => $graph, 'STATS' => $list));
 }