[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_WP_Admin_page_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          $action = parent::redirect();
  14          if ( !$action ) return;
  15  
  16          $url_parms     = self::get_url_parms();
  17          $checked    = ( isset( self::$get_['checked'] ) ) ? self::$get_['checked'] : array();
  18  
  19          $count    = str_replace( 'bulk-', '', $action );
  20          $count     .= 'd';
  21          $$count    = 0;
  22  
  23          $path     = self::get_path();
  24  
  25          switch( $action )
  26          {
  27              case 'bulk-delete' :
  28                                  foreach( $checked as $file ) { if ( @unlink( $path . '/' . $file ) ) $$count++; }
  29              break;
  30          }
  31  
  32          if ( $$count ) $url_parms[$count] = $$count;
  33          self::mp_redirect( self::url( MailPress_view_logs, $url_parms ) );
  34      }
  35  
  36  //// Help ////
  37  
  38  	public static function add_help_tab() 
  39      {
  40          global $current_screen;
  41  
  42          $content = '';
  43          $content .= '<p><strong>' . __( 'View logs :', 'MailPress' ) . '</strong></p>';
  44          $content .= '<p>' . __( 'This screen provides access to all of your mp logs. You can customize the display of this screen to suit your needs.', 'MailPress' ) . '</p>';
  45          $content .= '<p>' . sprintf( __( 'All mp logs are currently stored in %s.', 'MailPress' ), '<code>' .  MP_UPL_PATH . 'log</code>');
  46  
  47          $current_screen->add_help_tab( array(     'id'        => 'overview',
  48                                          'title'    => __( 'Overview' ),
  49                                          'content'    => $content )
  50          );
  51  
  52          $content = '';
  53          $content .= '<p>' . __( 'You can customize the display of this screen&#8217;s contents in a number of ways:', 'MailPress' ) . '</p>';
  54          $content .= '<ul>';
  55          $content .= '<li>' . __( 'You can decide how many logs to list per screen using the Screen Options tab.', 'MailPress' ) . '</li>';
  56          $content .= '<li>' . __( 'Depending on which add on you have activated, you may find an autorefresh option in the Screen Options tab.', 'MailPress' ) . '</li>';
  57          $content .= '</ul>';
  58  
  59  
  60          $current_screen->add_help_tab( array(     'id'        => 'screen-display',
  61                                          'title'    => __( 'Screen Display' ),
  62                                          'content'    => $content )
  63          );
  64  
  65          $content = '';
  66          $content .= '<p>' . __( 'Hovering over a row in the logs list will display action links that allow you to manage your log. You can perform the following actions:', 'MailPress' ) . '</p>';
  67          $content .= '<ul>';
  68          $content .= '<li>' . __( '<strong>View</strong> &mdash; display the content of the log file within WordPress administration.', 'MailPress' ) . '</li>';
  69          $content .= '<li>' . __( '<strong>Browse</strong> &mdash; display the content of the log file inside a new tab in your browser.', 'MailPress' ) . '</li>';
  70          $content .= '</ul>';
  71  
  72          $current_screen->add_help_tab( array(     'id'        => 'action-links',
  73                                          'title'    => __( 'Available Actions' ),
  74                                          'content'    => $content )
  75          );
  76  
  77          $content = '';
  78          $content .= '<p>' . __( 'You can also permanently delete multiple logs at once. Select the logs you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.', 'MailPress' ) . '</p>';
  79  
  80          $current_screen->add_help_tab( array(     'id'        => 'bulk-actions',
  81                                          'title'    => __( 'Bulk Actions' ),
  82                                          'content'    => $content )
  83          );
  84      }
  85  
  86      // for path
  87  	public static function get_path() 
  88      {
  89          return MP_UPL_ABSPATH . 'log';
  90      }
  91  
  92      // for url
  93  	public static function get_url() 
  94      {
  95          return MP_UPL_URL . 'log';
  96      }
  97  
  98      // for file template
  99  	public static function get_file_template()
 100      {
 101          return 'MP_Log_' . get_current_blog_id() . '_';
 102      }
 103  
 104  ////  Columns  ////
 105  
 106  	public static function get_columns() 
 107      {
 108          $columns = array(    'cb'        => '<input type="checkbox" />', 
 109                          'name'    => __( 'Name', 'MailPress' ) );
 110          return $columns;
 111      }
 112  
 113  ////  List  ////
 114  
 115  	public static function get_list( $args )
 116      {
 117          extract( $args );
 118  
 119          $ftmplt    = self::get_file_template();
 120          $path     = self::get_path();
 121          $all        = 0;
 122  
 123          $logs = array();
 124          if ( is_dir( $path ) && ( $l = opendir( $path ) ) ) 
 125          {
 126              while ( ( $file = readdir( $l ) ) !== false ) 
 127              {
 128                    switch ( true )
 129                  {
 130                      case ( $file[0]  == '.' ) :
 131                      break;
 132                      case ( strstr( $file, $ftmplt ) ) :
 133                          $all++;
 134                          if ( isset( $url_parms['s'] ) && ( !strstr( $file, $url_parms['s'] ) ) ) continue;
 135                          $logs[filemtime( "$path/$file" ) . $file] = $file;
 136                      break;
 137                  }
 138              }
 139              closedir( $l );
 140          }
 141          krsort( $logs );
 142  
 143          $total = count( $logs );
 144          $counts = array('all'        => $all, 
 145                      'search'    => 0
 146          );
 147          if ( isset( $url_parms['s'] ) ) $counts['search'] = $total;
 148  
 149          $rows  = array_slice ( $logs, $start, $_per_page );
 150  
 151          $subsubsub_urls = false;
 152  
 153          $libs = array(    'all'            => __( 'All' ), 
 154                      'search'        => __( 'Search Results' )
 155          );
 156  
 157          $out = array();
 158  
 159          foreach( $libs as $k => $lib )
 160          {
 161              if ( !isset( $counts[$k] ) || !$counts[$k] )
 162              {
 163                  continue;
 164              }
 165  
 166              $args = array();
 167              if ( ( 'search' == $k ) && ( isset( $url_parms['s'] ) ) )    $args['s'] = $url_parms['s'];
 168              elseif ( 'all' != $k )                             $args['status'] = $k;
 169              $url    = esc_url( add_query_arg( $args, MailPress_view_logs ) );
 170  
 171              $cls = '';
 172              if ( isset( $url_parms['s'] ) )
 173              {
 174                  if ( 'search' == $k )
 175                  {
 176                      $cls = ' class="current"';
 177                  }
 178              }
 179              elseif ( 'all' == $k )
 180              {
 181                  $cls = ' class="current"';
 182              }
 183  
 184              $out[] = sprintf( '<a%1$s href="%2$s">%3$s <span class="count">( %5$s )</span></a>', $cls, $url, $lib, $k, $counts[$k] );
 185          }
 186  
 187          if ( !empty( $out ) )
 188          {
 189              $subsubsub_urls = '<li>' . join( ' | </li><li>', $out ) . '</li>';
 190          }
 191  
 192          return array( $rows, $total, $subsubsub_urls );
 193      }
 194  
 195  ////  Row  ////
 196  
 197  	public static function get_row( $file, $url_parms )
 198      {
 199          static $row_class = '';
 200  
 201          $f         = substr( $file, strpos( $file, str_replace( ABSPATH, '', WP_CONTENT_DIR ) ) );
 202          $view_url     = esc_url( MailPress_view_log . "&id=$f" );
 203          $browse_url = self::get_url() . '/' . $f;
 204          $actions['view']   = '<a href="' . $view_url   . '" title="' . esc_attr( sprintf( __(   'View &#8220;%1$s&#8221;', 'MailPress' ) , $file ) ) . '">'    . __( 'View', 'MailPress' ) . '</a>';
 205          $actions['browse'] = '<a href="' . $browse_url . '" title="' . esc_attr( sprintf( __( 'Browse &#8220;%1$s&#8221;', 'MailPress' ) , $file ) ) . '" target="_blank">'    . __( 'Browse', 'MailPress' ) . '</a>';
 206  
 207          $row_class = ( ' class="alternate"' == $row_class ) ? '' : ' class="alternate"';
 208          $attributes = 'class="post-title column-title"';
 209  
 210          $out = '';
 211          $out .= '<tr' . $row_class . '>';
 212  
 213          // cb
 214          $out .= '<th class="check-column"> <input type="checkbox" name="checked[]" value="' . $file . '" /></th>';
 215  
 216          // file
 217          $out .= '<td ' . $attributes . '>';
 218          $out .= '<span><strong>';
 219          $out .= '<a class="row-title" href="' . $view_url . '" title="' . esc_attr( __( 'View', 'MailPress' ) ) . '">' . $file . '</a>';
 220          $out .= '</strong></span>';
 221          $out .= self::get_actions( $actions );
 222          $out .= '</td>';
 223  
 224          $out .= "</tr>";
 225  
 226          return $out;
 227      }
 228  }


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1