[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_WP_Admin_page_
   3  {
   4      const screen        = 'mailpress_revision';
   5      const capability    = 'MailPress_edit_mails';
   6      const help_url        = false;
   7      const file            = __FILE__;
   8  
   9  ////  Redirect  ////
  10  
  11  	public static function redirect() 
  12      {
  13          $redirect = MailPress_edit;
  14  
  15          $action    = ( isset( self::$get_['action'] ) )     ? self::$get_['action'] : false;
  16          $rev_id    = ( isset( self::$get_['revision'] ) )? absint( self::$get_['revision'] ) : false;
  17          $id        = ( isset( self::$get_['id'] ) )     ? absint( self::$get_['id'] ) : false;
  18  
  19          switch ( $action )
  20          {
  21              case 'restore' :
  22                  if ( !$revision = MP_Mail::get( $rev_id ) )
  23                  {
  24                      break;
  25                  }
  26                  if ( !$mail = MP_Mail::get( $id ) )
  27                  {
  28                      break;
  29                  }
  30  
  31                  check_admin_referer( "restore-mail_{$revision->id}" );
  32  
  33                  MP_Mail_revision::restore( $mail, $revision );
  34                  $redirect = add_query_arg( array( 'id' => $id , 'revision' => $rev_id, 'message' => 5 ), MailPress_edit );
  35              break;
  36              case 'view' :
  37              case 'edit' :
  38              default :
  39                   if ( !$revision = MP_Mail::get( $rev_id ) )
  40                  {
  41                      break;
  42                  }
  43                  if ( !$mail = MP_Mail::get( $id ) )
  44                  {
  45                      break;
  46                  }
  47  
  48                  $redirect = false;
  49              break;
  50          }
  51          if ( $redirect )
  52          {
  53              self::mp_redirect( $redirect );
  54          }
  55      }
  56  
  57  ////  Title  ////
  58  
  59  	public static function title()
  60      {
  61          global $title;
  62          $title = __( 'Mail Revisions', 'MailPress' );
  63      }
  64  
  65  //// Help ////
  66  
  67  	public static function add_help_tab() 
  68      {
  69          global $current_screen;
  70  
  71          $content = '';
  72          $content .= '<p><strong>' . __( 'Revision :', 'MailPress' ) . '</strong></p>';
  73  
  74          $content .= '<p>' . __( 'This screen is used for managing your content revisions.', 'MailPress' ) . '</p>';
  75          $content .= '<p>' . __( 'Revisions are saved copies of your draft mail (one copy autosaved per WP user per draft), which is created as you update your content. The red text on the left shows the content that was removed. The green text on the right shows the content that was added.', 'MailPress' ) . '</p>';
  76          $content .= '<p>' . __( 'From this screen you can review, compare, and restore revisions:', 'MailPress' ) . '</p>';
  77          $content .=  '<ul><li>' . __( 'To navigate between revisions, <strong>drag the slider handle left or right</strong> or <strong>use the Previous or Next buttons</strong>.', 'MailPress' ) . '</li>';
  78          $content .=  '<li>' . __( 'Compare two different revisions by <strong>selecting the &#8220;Compare any two revisions&#8221; box</strong> to the side.', 'MailPress' ) . '</li>';
  79          $content .=  '<li>' . __( 'To restore a revision, <strong>click Restore This Revision</strong>. The content of the revision becomes the content of the mail and vice versa.', 'MailPress' ) . '</li></ul>';
  80  
  81          $current_screen->add_help_tab( array(     'id'        => 'overview',
  82                                          'title'        => __( 'Overview' ),
  83                                          'content'    => $content )
  84          );
  85      }
  86  
  87  ////  Styles  ////
  88  
  89  	public static function print_styles( $s ) 
  90      {
  91          $styles = ( is_array( $s ) ) ? $s : array();
  92  
  93          wp_register_style( self::screen, '/' . MP_PATH . 'mp-admin/css/write.css', array( 'revisions', 'thickbox' ) );
  94  
  95          $styles[] = self::screen;
  96          parent::print_styles( $styles );
  97      }
  98  
  99  ////  Scripts  ////
 100  
 101  	public static function print_scripts( $scripts = array() ) 
 102      {
 103          $rev_id    = ( isset( self::$get_['revision'] ) ) ? absint( self::$get_['revision'] ) : false;
 104          $id        = absint( self::$get_['id'] );
 105  
 106          wp_register_script ( self::screen, '/' . MP_PATH . 'mp-admin/js/revisions.js', array( 'wp-backbone', 'jquery-ui-slider', 'hoverIntent', 'thickbox' ), false, 1 );
 107          wp_localize_script( self::screen, '_wpRevisionsSettings', self::prepare_js( $id, $rev_id, null ) );
 108  
 109          $scripts[] = self::screen;
 110          parent::print_scripts( $scripts );
 111      }
 112  
 113  	public static function prepare_js( $id, $selected_revision_id, $from = null ) 
 114          {
 115          $revisions = $authors = array();
 116  
 117          $now_gmt = time();
 118          $revisions = MP_Mail_revision::get_all( $id, false );
 119          $mail      = $revisions[$id];
 120          unset( $revisions[$id] );
 121          $show_avatars = get_option( 'show_avatars' );
 122      
 123          //cache_users( wp_list_pluck( $revisions, 'mail_author' ) );
 124          $i = 0; $r = count( $revisions );
 125          foreach ( $revisions as $revision )
 126          {
 127              $i++;
 128              $modified = strtotime( $revision->created );
 129              $restore_link = str_replace( '&amp;', '&', wp_nonce_url( add_query_arg( array(     'page'    => MailPress_page_mails ,
 130                                                                          'file'    => 'revision',
 131                                                                          'action'    => 'restore',
 132                                                                          'id'        => $mail->id ,
 133                                                                          'revision'    => $revision->id
 134                                                                          ), admin_url( 'admin.php' ) ), "restore-mail_{$revision->id}" )
 135              );
 136  
 137              if ( ! isset( $authors[ $revision->created_user_id ] ) )
 138              {
 139                  $authors[ $revision->created_user_id ] = array( 
 140                      'id'         => ( int ) $revision->created_user_id,
 141                      'avatar'    => $show_avatars ? get_avatar( $revision->created_user_id, 32 ) : '',
 142                      'name'    => get_the_author_meta( 'display_name', $revision->created_user_id ),
 143                   );
 144              }
 145      
 146              $autosave = ( bool ) ( '' == $revision->status ) ;
 147              $current = ( $r == $i );
 148              $current_id = ( $current ) ? $revision->id : false;
 149      
 150              $revisions_data = array( 
 151                  'id'         => $revision->id,
 152                  'title'      => $revision->subject,
 153                  'author'     => $authors[ $revision->created_user_id ],
 154                  'date'       => date_i18n( __( 'M j, Y @ H:i' ), $modified ),
 155                  'dateShort'  => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ),
 156                  'timeAgo'    => sprintf( __( '%s ago' ), human_time_diff( $modified, $now_gmt ) ),
 157                  'autosave'   => $autosave,
 158                  'current'    => $current,
 159                  'restoreUrl' => $restore_link,
 160              );
 161              $revisions[ $revision->id ] = apply_filters( 'mp_prepare_revision_for_js', $revisions_data, $revision, $mail );
 162          }
 163  
 164          /**
 165           * If we only have one revision, the initial revision is missing; This happens
 166           * when we have an autsosave and the user has clicked 'View the Autosave'
 167           */
 168          if ( 1 === sizeof( $revisions ) )
 169          {
 170              $revisions[ $mail->id ] = array(
 171                  'id'         => $mail->id,
 172                  'title'      => $mail->subject,
 173                  'author'     => $authors[ $mail->created_user_id ],
 174                  'date'       => date_i18n( __( 'M j, Y @ H:i' ), strtotime( $mail->created ) ),
 175                  'dateShort'  => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), strtotime( $mail->created ) ),
 176                  'timeAgo'    => sprintf( __( '%s ago' ), human_time_diff( strtotime( $mail->created ), $now_gmt ) ),
 177                  'autosave'   => false,
 178                  'current'    => true,
 179                  'restoreUrl' => false,
 180               );
 181              $current_id = $mail->id;
 182          }
 183  
 184          // Now, grab the initial diff.
 185          $compare_two_mode = is_numeric( $from );
 186          if ( ! $compare_two_mode )
 187          {
 188              $found = array_search( $selected_revision_id, array_keys( $revisions ) );
 189              if ( $found )
 190              {
 191                  $from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
 192                  $from = reset( $from );
 193              }
 194              else
 195              {
 196                  $from = 0;
 197              }
 198          }
 199      
 200          $from = absint( $from );
 201      
 202          $diffs = array( array(    'id'        => $from . ':' . $selected_revision_id,
 203                              'fields'    => MP_Mail_revision::get_ui_diff( $mail->id, $from, $selected_revision_id ),
 204          ) );
 205      
 206          $js = array( 
 207              'mailId'           => $mail->id,
 208              'nonce'            => wp_create_nonce( 'revisions-ajax-nonce' ),
 209              'revisionData'     => array_values( $revisions ),
 210              'to'               => $selected_revision_id,
 211              'from'             => $from,
 212              'diffData'         => $diffs,
 213              'baseUrl'          => add_query_arg(     array( 'page' => MailPress_page_mails , 'file' => 'revision', 'id' => $mail->id ), parse_url( admin_url( 'admin.php' ), PHP_URL_PATH ) ),
 214              'compareTwoMode'   => absint( $compare_two_mode ), // Apparently booleans are not allowed
 215              'revisionIds'      => array_keys( $revisions ),
 216           );
 217  
 218          return $js;
 219      }
 220  }


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