[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/options/dashboard/widgets/ -> users_activity.php (source)

   1  <?php
   2  class MP_Dashboard_users_activity extends MP_dashboard_widget_
   3  {
   4      var $id = 'mp_users_activity';
   5  
   6  	function widget()
   7      {
   8          global $wpdb, $wp_locale;
   9          $empty = 0;
  10  
  11          // Subscriber activity
  12  
  13          $_Item_ids = $_Items = array();
  14  
  15          $dend    = date('Y-m-d');                         $y = substr($dend,0,4); $m = substr($dend,5,2); $d = substr($dend,8,2);
  16          $dbeg = date('Y-m-d',mktime(0, 0, 0, $m, $d-66, $y)); $y = substr($dbeg,0,4);    $m = substr($dbeg,5,2); $d = substr($dbeg,8,2);
  17  
  18          // get all in one query
  19          $query = "    SELECT sdate, '1', slib, sum(scount) as scount FROM $wpdb->mp_stats WHERE stype = 'u' AND sdate BETWEEN '%s' AND '%s' GROUP BY 1,2,3
  20                  UNION
  21                  SELECT '%s',  '0', slib, sum(scount)           FROM $wpdb->mp_stats WHERE stype = 'u' AND sdate < '%s' GROUP BY 1,2,3
  22                   ORDER BY 1,2,3;";
  23          $items = $wpdb->get_results( $wpdb->prepare( $query, $dbeg, $dend, $dbeg, $dbeg ) );
  24  
  25          foreach ($items as $item)
  26          {
  27              if (isset($_Items[$item->sdate][$item->slib]))     $_Items[$item->sdate][$item->slib] += $item->scount;
  28              else                                $_Items[$item->sdate][$item->slib]  = $item->scount;
  29              $_Item_ids[$item->slib] = $_Items[$item->sdate][$item->slib];
  30  
  31              if ('active' == $item->slib)
  32              {
  33                  $_Item_ids['comment'] = $_Item_ids[$item->slib];
  34                  if (isset($_Items[$item->sdate]['comment']))     $_Items[$item->sdate]['comment'] += $item->scount;
  35                  else                                $_Items[$item->sdate]['comment']  = $item->scount;
  36              }
  37          }
  38  
  39          // clean up //
  40          foreach($_Item_ids as $item_id => $x)
  41          {
  42              $vide = true;
  43              foreach ($_Items as $date => $item)
  44              {
  45                  foreach ($item as $status_id => $scount)
  46                  {
  47                      if ($item_id == $status_id && $scount > 0)
  48                      {
  49                          $vide = false;
  50                          break 2;
  51                      }
  52                  }
  53              }
  54              if ($vide) unset($_Item_ids[$item_id]);
  55          }
  56  
  57          if (!class_exists('MailPress_comment')) unset($_Item_ids['comment']);
  58  
  59          // clean up //
  60          foreach ($_Items as $date => $item)
  61          {
  62              foreach ($item as $status_id => $scount)
  63                  if (!isset($_Item_ids[$status_id])) unset($_Items[$date][$status_id]);
  64              if (empty($_Items[$date])) unset($_Items[$date]);
  65          }
  66  
  67          $chxl_y = 0;
  68          $chxl_day = $chxl_month = $chxl_year = $chds = $prev_chds = $colors = $item_ids = $values = $lines = array();
  69  
  70          $time = $dbeg; $wy = $y; $wm = $m; $wd = $d;
  71  
  72          do {
  73          // data
  74              $chds['fake'][] = $empty;
  75              foreach($_Item_ids as $item_id => $v)
  76              {
  77                  if (isset($_Items[$time][$item_id]))     
  78                  {
  79                      $total = (isset($prev_chds[$item_id]) && is_numeric($prev_chds[$item_id]) && ($prev_chds[$item_id] > -1)) ? $prev_chds[$item_id] + $_Items[$time][$item_id] : $_Items[$time][$item_id];
  80                      if ($total < 0) $total = $empty;
  81                      $chds[$item_id][] = $prev_chds[$item_id] = $total;
  82                  }
  83                  elseif (isset($prev_chds[$item_id]) && ($prev_chds[$item_id] != ''))
  84                  {
  85                      $chds[$item_id][] = $prev_chds[$item_id];
  86                  }
  87                  else    $chds[$item_id][] = $prev_chds[$item_id] = $empty;
  88  
  89                  // y
  90                  $chxl_y = max($prev_chds[$item_id], $chxl_y);
  91              }
  92  
  93          // axis
  94              // x
  95              if     (empty($chxl_year))                         $chxl_year[] = $wy;
  96              elseif ('0101' == substr($time,5,2) . substr($time,8,2))     $chxl_year[] = substr($time,0,4);
  97              else                                         $chxl_year[] = '';
  98  
  99              $chxl_month[] = ('15' == substr($time,8,2)) ? $wp_locale->get_month_abbrev($wp_locale->get_month(substr($time,5,2))) : '';
 100  
 101              if         ('01' == substr($time,8,2))     $chxl_day[] = '01';
 102              elseif     ('15' == substr($time,8,2))     $chxl_day[] = '15';
 103              else                             $chxl_day[] = '';
 104  
 105              $time = date('Y-m-d',mktime(0, 0, 0, $m, ++$d, $y));
 106          } while ($time <= $dend);
 107  
 108          $datas = array('waiting' => '224499', 'comment' => 'FF0000', 'active' => '80C65A', 'fake' => '000000');
 109          $libs  = array('waiting' => __('waiting', MP_TXTDOM),  'comment' => __('comment%20only', MP_TXTDOM), 'active' => __('active', MP_TXTDOM),);
 110  
 111          $x = 0;
 112          foreach($datas as $item_id => $color)
 113          {
 114              if (!isset($chds[$item_id])) continue;
 115  
 116              if (isset($libs[$item_id])) 
 117              {
 118                  $item_ids[] = $libs[$item_id];
 119                  $lines[]  = "b,$color," . $x++ . ",$x,0";
 120              }
 121              $values[]     = join(',', $chds[$item_id]);
 122              $colors[]     = $color;
 123          }
 124  
 125          $args = array();
 126          $args['cht']  = 'lc';
 127          $args['chs']  = $this->widget_size('570x330');
 128          $args['chxt'] = 'x,y,x,x';
 129          $args['chxtc']= '0,3';
 130          $args['chxl'] = '0:|' . join('|', $chxl_day) . '|1:||' . $chxl_y . '|2:|' . join('|', $chxl_month) . '|3:|' . join('|', $chxl_year);
 131          $args['chds'] = "0,{$chxl_y}";
 132          $args['chdlp']= 'b';
 133          $args['chdl'] = join('|', $item_ids);
 134          $args['chm']  = join('|', $lines);
 135          $args['chco'] = join(',', $colors);
 136          $args['chd']  = 't:' . join('|', $values);
 137          $url = esc_url(add_query_arg($args, $this->url));
 138  
 139  ?>
 140  <div style='text-align:center;'><img style='width:100%;' src="<?php echo $url; ?>" alt="<?php _e( 'Subscribers - Activity', MP_TXTDOM ); ?>" />
 141  </div>
 142  <?php
 143      }
 144  }
 145  new MP_Dashboard_users_activity(__( 'MailPress - Subscribers activity', MP_TXTDOM ));


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1