[ Index ]

MailPress 544

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

title

Body

[close]

/mp-admin/ -> view_logs.php (source)

   1  <?php
   2  class MP_AdminPage extends MP_adminpage_list_
   3  {
   4      const screen         = MailPress_page_view_logs;
   5      const capability    = 'MailPress_view_logs';
   6      const help_url        = 'http://blog.mailpress.org/tutorials/add-ons/view_logs/';
   7      const file            = __FILE__;
   8  
   9  ////  Redirect  ////
  10  
  11  	public static function redirect() 
  12      {
  13          if     ( !empty($_REQUEST['action'])  && ($_REQUEST['action']  != -1))    $action = $_REQUEST['action'];
  14          elseif ( !empty($_REQUEST['action2']) && ($_REQUEST['action2'] != -1) )    $action = $_REQUEST['action2'];
  15          if (!isset($action)) return;
  16  
  17          $path     = '../' . self::get_path();
  18  
  19          $url_parms     = self::get_url_parms();
  20          $checked    = (isset($_GET['checked'])) ? $_GET['checked'] : array();
  21  
  22          $count    = str_replace('bulk-', '', $action);
  23          $count     .= 'd';
  24          $$count    = 0;
  25  
  26          switch($action)
  27          {
  28              case 'bulk-delete' :
  29                  foreach($checked as $file) if (@unlink($path . '/' . $file)) $$count++;
  30              break;
  31          }
  32  
  33          if ($$count) $url_parms[$count] = $$count;
  34          self::mp_redirect( self::url(MailPress_view_logs, $url_parms) );
  35      }
  36  
  37      // for path
  38  	public static function get_path() 
  39      {
  40          return MP_PATH . 'tmp';
  41      }
  42  
  43      // for file template
  44  	public static function get_file_template()
  45      {
  46          global $wpdb;
  47          return 'MP_Log_' . $wpdb->blogid . '_';
  48      }
  49  
  50  ////  Columns  ////
  51  
  52  	public static function get_columns() 
  53      {
  54          $columns = array(    'cb'        => "<input type='checkbox' />", 
  55                      'name'    => __('Name', MP_TXTDOM));
  56          return $columns;
  57      }
  58  
  59  ////  List  ////
  60  
  61  	public static function get_list($args)
  62      {
  63          extract($args);
  64  
  65          $ftmplt    = self::get_file_template();
  66          $path     = '../' . self::get_path();
  67          $all        = 0;
  68  
  69          $logs = array();
  70          if (is_dir($path) && ($l = opendir($path))) 
  71          {
  72              while (($file = readdir($l)) !== false) 
  73              {
  74                    switch (true)
  75                  {
  76                      case ($file[0]  == '.') :
  77                      break;
  78                      case (strstr($file, $ftmplt)) :
  79                          $all++;
  80                          if (isset($url_parms['s']) && (!strstr($file, $url_parms['s']))) continue;
  81                          $logs[filemtime("$path/$file") . $file] = $file;
  82                      break;
  83                  }
  84              }
  85              closedir($l);
  86          }
  87          krsort($logs);
  88  
  89          $total = count($logs);
  90          $rows  = array_slice ($logs, $start, $_per_page);
  91  
  92      // subsubsub
  93          $subsubsub_urls = false;
  94  
  95          $libs = array( 'all' => __('All'), 'search' => __('Search Results') );
  96  
  97          $status_links_url  = MailPress_view_logs ;
  98  
  99          $counts['all'] = $all;
 100          if (isset($url_parms['s'])) $counts['search'] = $total;
 101          $out = array();
 102  
 103          foreach($libs as $k => $lib)
 104          {
 105              if (!isset($counts[$k]) || !$counts[$k]) continue;
 106              $cls = '';
 107              if (isset($url_parms['s']))            { if ('search' == $k)             $cls = " class='current'"; }
 108              elseif ('all' == $k)                                    $cls = " class='current'"; 
 109              $url = $status_links_url . ( ('search' == $k) ? '&s=' . $url_parms['s'] : ( ('all' == $k) ? '' : "&amp;status=$k" ) );
 110  
 111              $sum = $counts[$k];
 112              $out[] = "<a$cls href='$url'>$lib <span class='count'>($sum)</span></a>";
 113          }
 114  
 115          if (!empty($out)) $subsubsub_urls = '<li>' . join( ' | </li><li>', $out ) . '</li>';
 116  
 117          return array($rows, $total, $subsubsub_urls);
 118      }
 119  
 120  ////  Row  ////
 121  
 122  	public static function get_row($file, $url_parms)
 123      {
 124          static $row_class = '';
 125  
 126          $f         = substr($file, strpos($file, str_replace( ABSPATH, '', WP_CONTENT_DIR )));
 127          $view_url     = esc_url(MailPress_view_log . "&id=$f");
 128          $browse_url = '../' . self::get_path() . '/' . $f;
 129          $actions['view']   = "<a href='$view_url' title='" . sprintf( __('View "%1$s"', MP_TXTDOM) , $file ) . "'>"    . __('View', MP_TXTDOM) . '</a>';
 130          $actions['browse'] = "<a href='$browse_url' target='_blank' title='" . sprintf( __('Browse "%1$s"', MP_TXTDOM) , $file ) . "'>"    . __('Browse', MP_TXTDOM) . '</a>';
 131  
 132          $row_class = (" class='alternate'" == $row_class) ? '' : " class='alternate'";
 133          $attributes = "class='post-title column-title'";
 134  ?>
 135      <tr<?php echo $row_class; ?>>
 136          <th class="check-column">
 137              <input type="checkbox" value="<?php echo $file; ?>" name="checked[]" />
 138          </th>
 139          <td  <?php echo $attributes ?>>
 140              <span style='display:block;'>
 141                  <strong style='display:inline;'>
 142                      <a class='row-title' href='<?php echo $view_url; ?>' title='<?php printf( __('View "%1$s"', MP_TXTDOM) , $file ); ?>'>
 143                          <?php echo $file; ?>
 144                      </a>
 145                  </strong>
 146              </span>
 147  <?php echo self::get_actions($actions); ?>
 148          </td>
 149      </tr>
 150  <?php
 151      }
 152  }


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