コード例 #1
0
ファイル: stats.php プロジェクト: Advanture/Online-RolePlay
 /**
  * Display a graph of spam service stats
  *
  * @return	@e void
  */
 public function spamServiceGraph()
 {
     /* Check the to fields */
     if (!checkdate($this->request['to_month'], $this->request['to_day'], $this->request['to_year'])) {
         $this->_safeExit();
     }
     /* Check the from fields */
     if (!checkdate($this->request['from_month'], $this->request['from_day'], $this->request['from_year'])) {
         $this->_safeExit();
     }
     /* Create time stamps */
     $to_time = mktime(12, 0, 0, $this->request['to_month'], $this->request['to_day'], $this->request['to_year']);
     $from_time = mktime(12, 0, 0, $this->request['from_month'], $this->request['from_day'], $this->request['from_year']);
     /* Get Human Dates */
     $human_to_date = getdate($to_time);
     $human_from_date = getdate($from_time);
     /* Setup Timescale */
     switch ($this->request['timescale']) {
         case 'daily':
             $php_date = "F jS - Y";
             break;
         case 'monthly':
             $php_date = "F Y";
             break;
         default:
             $php_date = "W [F Y]";
             break;
     }
     $order = $this->request['sortby'] == 'desc' ? 'desc' : 'asc';
     /* Query Spam Logs */
     $this->DB->build(array('select' => 'log_code, log_date', 'from' => 'spam_service_log', 'where' => 'log_date > ' . $from_time . ' AND log_date < ' . $to_time, 'order' => 'log_date ' . $order));
     $this->DB->execute();
     /* Make sure we have logs */
     if (!$this->DB->getTotalRows()) {
         $this->_safeExit();
     }
     /* Loop through and build data for two graph lines */
     $notSpamData = array();
     $isSpamData = array();
     $labels = array();
     while ($r = $this->DB->fetch()) {
         /* Ignore errors */
         if ($r['log_code'] == 0) {
             continue;
         }
         /* Date */
         $logDate = date($php_date, $r['log_date']);
         if (!in_array($logDate, $labels)) {
             $labels[] = $logDate;
         }
         if (!isset($notSpamData[$logDate])) {
             $notSpamData[$logDate] = 0;
         }
         if (!isset($isSpamData[$logDate])) {
             $isSpamData[$logDate] = 0;
         }
         if ($r['log_code'] == 1) {
             $notSpamData[$logDate]++;
         } else {
             if (in_array($r['log_code'], array(2, 3, 4))) {
                 $isSpamData[$logDate]++;
             }
         }
     }
     if (!count($notSpamData) and !count($isSpamData)) {
         $this->_safeExit();
     }
     /* Table Title */
     $title = $this->lang->words['timescale_' . $this->request['timescale']] . " {$this->lang->words['stats_spam']} ({$human_from_date['mday']} {$this->month_names[$human_from_date['mon']]} {$human_from_date['year']} {$this->lang->words['stats_to']} {$human_to_date['mday']} {$this->month_names[$human_to_date['mon']]} {$human_to_date['year']})";
     /* Get the Graph Class */
     require_once IPS_KERNEL_PATH . 'classGraph.php';
     /*noLibHook*/
     /* Graph Ooptions */
     $graph = new classGraph(false);
     $graph->options['title'] = $title;
     $graph->options['width'] = 800;
     $graph->options['height'] = 480;
     $graph->options['style3D'] = 0;
     $graph->options['charttype'] = 'Line';
     $graph->options['font'] = IPS_PUBLIC_PATH . 'style_captcha/captcha_fonts/DejaVuSans.ttf';
     /* Build Graph */
     $graph->addLabels($labels);
     $graph->addSeries($this->lang->words['statisnotspam'], array_values($notSpamData));
     $graph->addSeries($this->lang->words['statisspam'], array_values($isSpamData));
     $graph->display();
     exit;
 }
コード例 #2
0
ファイル: charts.php プロジェクト: mover5/imobackup
 /**
  * Show chart of registrations over x days
  *
  * @return	@e void [Outputs to screen]
  * @link	http://community.invisionpower.com/tracker/issue-32300-dashboard-registration-chart
  */
 public function showRegistrationChart()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $days = intval($this->request['days']);
     if (!$days) {
         $days = 7;
     }
     $cutoff = time() - $days * 86400;
     $_check = time();
     /* initdata.php sets to GMT, so we need to take into account time offset ourselves */
     $_tzOffset = $this->settings['time_offset'] * 3600;
     $registrations = array();
     $labels = array();
     $_ttl = 0;
     while ($_check > $cutoff) {
         $_day = strftime('%b %d', $_check + $_tzOffset);
         $_key = strftime('%Y-%m-%d', $_check + $_tzOffset);
         $labels[$_key] = $_day;
         $registrations[$_key] = 0;
         $_check -= 86400;
     }
     //-----------------------------------------
     // Get the data
     //-----------------------------------------
     $this->DB->build(array('select' => 'member_id, joined', 'from' => 'members', 'where' => 'joined > ' . $cutoff));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         //$_day	= strftime( '%b %d', $r['joined'] );
         $_key = strftime('%Y-%m-%d', $r['joined'] + $_tzOffset);
         if (isset($registrations[$_key])) {
             $registrations[$_key] += 1;
             $_ttl++;
         }
     }
     ksort($labels);
     ksort($registrations);
     //-----------------------------------------
     // Output chart
     //-----------------------------------------
     require_once IPS_KERNEL_PATH . '/classGraph.php';
     /*noLibHook*/
     $graph = new classGraph();
     $graph->options['title'] = '';
     $graph->options['font'] = DOC_IPS_ROOT_PATH . '/public/style_captcha/captcha_fonts/DejaVuSans.ttf';
     $graph->options['width'] = 1024;
     $graph->options['height'] = 400;
     $graph->options['style3D'] = 1;
     $graph->options['showlegend'] = 0;
     //$graph->options['xaxisskip']		= 5;
     $graph->options['showgridlinesx'] = 0;
     if ($_ttl) {
         //ksort($labels);
         //ksort($registrations);
         $graph->addLabels(array_values($labels));
         $graph->addSeries('test', array_values($registrations));
     } else {
         $graph->options['title'] = sprintf($this->lang->words['no_reg_x_days'], $days);
         $graph->addLabels(array(0));
         $graph->addSeries('test', array(0));
     }
     $graph->options['charttype'] = 'Line';
     $graph->display();
     exit;
 }