[ Index ]

MailPress 7.1

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

title

Body

[close]

/mp-admin/includes/ -> write.php (source)

   1  <?php
   2  
   3  if ( !( function_exists( 'current_user_can' ) && current_user_can( MP_AdminPage::capability ) ) ) die( 'Access denied' );
   4  
   5  global $draft; 
   6  
   7  $url_parms     = MP_AdminPage::get_url_parms();
   8  
   9  //
  10  // MANAGING RESULTS
  11  //
  12  
  13  if ( isset( MP_AdminPage::$get_['id'] ) )
  14  {
  15      $draft     = MP_Mail::get( MP_AdminPage::$get_['id'] );
  16      $rev_ids     = MP_Mail_revision::get( $draft->id );
  17  }
  18  
  19  $autosave    = true;
  20  $notice     = false;
  21  
  22  //
  23  // MANAGING H1
  24  //
  25  
  26  $h1         = __( 'Add New Mail', 'MailPress' );
  27  
  28  $hidden      = '<input type="hidden" name="id" id="mail_id" value="0" />';
  29  $list_url     = MP_AdminPage::url( MailPress_mails, $url_parms );
  30  
  31  if ( isset( $draft ) )
  32  {
  33      $h1            = sprintf( __( 'Edit Draft # %1$s', 'MailPress' ), $draft->id );
  34      $hidden        = '<input type="hidden" name="id" id="mail_id" value="' . $draft->id . '" />';
  35      $delete_url    = esc_url( add_query_arg( array( 'action' => 'delete', 'id' => $draft->id ), MailPress_write ) );
  36  
  37      $last_user        = get_userdata( $draft->created_user_id );
  38      $lastedited    = sprintf( __( 'Last edited by %1$s on %2$s at %3$s', 'MailPress' ), $last_user->display_name, mysql2date( get_option( 'date_format' ), $draft->created ), mysql2date( get_option( 'time_format' ), $draft->created ) );
  39  
  40  /* revisions */
  41      if ( is_array( $rev_ids ) )
  42      {
  43          foreach ( $rev_ids as $rev_user => $rev_id )
  44          {
  45              global $current_user ;
  46              if ( $current_user->ID == $rev_user )
  47              {
  48                  $revision = MP_Mail::get( $rev_id );
  49                  break;
  50              }
  51              else
  52              {
  53                  $x = MP_Mail::get( $rev_id );
  54                  if ( $x )
  55                  {
  56                      if ( $x->created > $revision->created )
  57                      {
  58                          $revision = $x;
  59                          $revision->not_this_user = true;
  60                      }
  61                  }
  62              }
  63          }
  64      }
  65  
  66      if ( isset( $revision ) )
  67      {
  68          if ( $revision->created > $draft->created )
  69          {
  70              $autosave_data = MP_Mail_revision::autosave_data();
  71  
  72              foreach ( $autosave_data as $k => $v )
  73              {
  74                  if ( wp_text_diff( $revision->$k, $draft->$k ) ) 
  75                  {
  76                      $autosave = false;
  77  
  78                      $notice = sprintf( __( 'There is an autosave of this mail that is more recent than the version below.  <a href="%s">View the autosave</a>.', 'MailPress' ), esc_url( MailPress_revision . "&id=$draft->id&revision=$revision->id" ) );
  79                      break;
  80                  }
  81              }
  82          }
  83      }
  84      else
  85      {
  86          $revision = new stdClass();
  87          $revision->id = '0';
  88      }
  89  
  90      if ( ( isset( $revision->not_this_user ) ) && ( $revision->not_this_user ) ) $revision->id = '0';
  91  
  92      $hidden .= '<input type="hidden" name="revision" id="mail_revision" value="' . $revision->id . '" />';
  93  /* end of revisions */
  94  
  95  /* lock */
  96  
  97      if ( $last = MP_Mail_lock::check( $draft->id ) )
  98      {
  99          $lock_user     = get_userdata( $last );
 100          $lock_user_name = $lock_user ? $lock_user->display_name : __( 'Somebody' );
 101          $lock = sprintf( __( 'Warning: %s is currently editing this mail' ), esc_html( $lock_user_name ) );
 102      }
 103      else
 104      {
 105          MP_Mail_lock::set( $draft->id );
 106      }
 107  /* end of lock */
 108  }
 109  else
 110  {
 111      $draft = new stdClass();
 112      if ( isset( MP_AdminPage::$get_['toemail'] ) ) $draft->toemail = MP_AdminPage::$get_['toemail'];
 113  }
 114  
 115  $draft->_scheduled = ( !isset( $draft->sent ) || '0000-00-00 00:00:00' == $draft->sent ) ? false : true;
 116  
 117  $HTTP_REFERER = filter_input( INPUT_SERVER, 'HTTP_REFERER' );
 118  if ( isset( $HTTP_REFERER ) )
 119      $hidden .= '<input type="hidden" name="referredby" value="' . esc_url( $HTTP_REFERER ) . '" />';
 120  
 121  // what else ?
 122      do_action( 'MailPress_update_meta_boxes_write' );
 123  
 124  // messages
 125  $class = 'fromto';
 126  $message = $view_url = ''; $err = 0;
 127  
 128  if ( isset( $draft->id ) )
 129  {
 130      $args = array( 'id' => $draft->id, 'action' => 'mp_ajax', 'mp_action' => 'iview', 'TB_iframe' => 'true' );
 131      $view_url = esc_url( add_query_arg( $args, admin_url( 'admin-ajax.php' ) ) );
 132  }
 133  
 134  if ( isset( MP_AdminPage::$get_['sched'] ) )     {$err += 0; if ( !empty( $message ) ) $message .= '<br />'; $message .= sprintf( __( 'Mail scheduled for: <strong>%1$s</strong>. <a class="thickbox thickbox-preview" href="%2$s">Preview mail</a>',  'MailPress' ), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $draft->sent ) ), $view_url );}
 135  if ( isset( MP_AdminPage::$get_['saved'] ) )     {$err += 0; if ( !empty( $message ) ) $message .= '<br />'; $message .= __( 'Mail saved', 'MailPress' ); }
 136  if ( isset( MP_AdminPage::$get_['notsent'] ) ){$err += 1; if ( !empty( $message ) ) $message .= '<br />'; $message .= __( 'Mail NOT sent', 'MailPress' ); }
 137  if ( isset( MP_AdminPage::$get_['nomail'] ) )    {$err += 1; if ( !empty( $message ) ) $message .= '<br />'; $message .= __( 'Please, enter a valid email',  'MailPress' ); $class = "TO"; }
 138  if ( isset( MP_AdminPage::$get_['nodest'] ) )    {$err += 1; if ( !empty( $message ) ) $message .= '<br />'; $message .= __( 'Mail NOT sent, no recipient',  'MailPress' ); $class = "TO"; }
 139  if ( isset( $lock ) )            {$err += 1; if ( !empty( $message ) ) $message .= '<br />'; $message .= $lock; }
 140  if ( $notice )                {$err += 1; if ( !empty( $message ) ) $message .= '<br />'; $message .= $notice; }     
 141  if ( isset( MP_AdminPage::$get_['sent'] ) )     {$err += 0; if ( !empty( $message ) ) $message .= '<br />'; $message .= sprintf( _n( __( '%s mail sent', 'MailPress' ), __( '%s mails sent', 'MailPress' ), MP_AdminPage::$get_['sent'] ), MP_AdminPage::$get_['sent'] ); }
 142  if ( isset( MP_AdminPage::$get_['revision'] )){$err += 0; if ( !empty( $message ) ) $message .= '<br />'; $message .= sprintf( __( 'Mail restored to revision from %s', 'MailPress' ), MP_Mail_revision::title(  MP_Mail::get( ( int ) MP_AdminPage::$get_['revision'] ), false ) ); }
 143  $mp_general    = get_option( MailPress::option_name_general );
 144  
 145  // from
 146  if ( empty( $draft->fromemail ) )
 147  {
 148      $draft->fromemail = apply_filters( 'MailPress_write_fromemail', $mp_general['fromemail'] );
 149      $draft->fromname  = apply_filters( 'MailPress_write_fromname',  $mp_general['fromname'] ); 
 150  }
 151  
 152  // to 
 153  if ( isset( $draft->toemail ) )
 154  {
 155      if ( !MailPress::is_email( $draft->toemail ) )
 156      {
 157          $draft->to_list = $draft->toemail;
 158          $draft->toemail = $draft->toname = '';
 159      }
 160      else
 161      {
 162          $draft->toname  = ( isset( $draft->toname ) ) ? esc_attr( $draft->toname ) : '';
 163      }
 164  }
 165  else
 166      $draft->toemail = $draft->toname = '';
 167  
 168  // or to
 169  $draft_dest = MP_User::get_mailinglists();
 170  
 171  // mail formats
 172  $mail_format = ( isset( $draft->id ) ) ? MP_Mail_meta::get( $draft->id, '_MailPress_format' ) : 'standard';
 173  
 174  $all_mail_formats =  array( 
 175                          'standard' => array ( 
 176                              'description'     => __( 'Add a title and use the editor to compose your mail.', 'MailPress' ),
 177                              'part'        => __( 'Html', 'MailPress' )
 178                           ),
 179                          'plaintext' => array ( 
 180                              'description' => __( 'Type plaintext part of mail or generate it automatically using Synchronize button.', 'MailPress' ),
 181                              'part'        => __( 'Plaintext', 'MailPress' )
 182                           )
 183                   );
 184  
 185  $mail_format_options = '';
 186  
 187  foreach( $all_mail_formats as $slug => $attr ) { 
 188      $mf_class= ''; 
 189      if ( $mail_format == $slug ) { $mf_class = 'class="active"'; $mf_tip = sprintf( __( '%s Part', 'MailPress' ), $attr['part'] ); }
 190  
 191      $url    = esc_url( add_query_arg( 'format', $slug, MailPress_write ) );
 192      $mail_format_options .= '<a ' . $mf_class . ' href="' . $url . '" data-description="' . esc_attr( $attr['description'] ) . '" data-mp-format="' . esc_attr( $slug ) . '" title="' . esc_attr( sprintf( __( '%s Part', 'MailPress' ), $attr['part'] ) ) . '"><div class="' . $slug . '"></div></a>';
 193  }
 194  
 195  ?>
 196  <div class="wrap">
 197      <h1>
 198          <?php echo esc_html( $h1 ); ?>
 199      </h1>
 200  <?php if ( $message ) MP_AdminPage::message( $message, ( $err ) ? false : true ); ?>
 201  
 202      <form id="writeform" name="writeform" method="post">
 203  
 204          <input type="hidden" name="action"     value="draft" />
 205  <?php echo $hidden; ?>
 206          <input type="hidden" name="user_ID"     value="<?php echo MP_WP_User::get_id(); ?>" />
 207          <?php wp_nonce_field( 'closedpostboxes',     'closedpostboxesnonce',     false ); ?>
 208  <?php if ( $autosave ) : ?>
 209          <?php wp_nonce_field( 'autosave',         'autosavenonce',         false ); ?>
 210          <?php wp_nonce_field( 'getpreviewlink',     'getpreviewlinknonce',     false ); ?>
 211          <?php wp_nonce_field( 'meta-box-order',     'meta-box-order-nonce',     false ); ?>
 212  <?php endif; ?>
 213  
 214          <div id="poststuff" class="metabox-holder has-right-sidebar">
 215              <div id="side-info-column" class="inner-sidebar">
 216  <?php do_meta_boxes( MP_AdminPage::screen, 'side', $draft ); ?>
 217              </div>
 218  
 219              <div id="post-body">
 220                  <div id="post-body-content">
 221  
 222                      <div class="mail-format-options">
 223                          <span class="mail-format-tip"><?php echo $mf_tip; ?></span>
 224                          <?php echo $mail_format_options; ?>
 225                      </div>
 226  
 227                      <div id="fromtodiv">
 228                              <table class="wp-list-table widefat fixed striped zyxw">
 229                                  <tr>
 230                                      <td class="nobo">
 231                                          <div class="nobo">
 232                                              <select name="to_list" id="to_list"  class="<?php echo $class; ?>">
 233  <?php MP_AdminPage::select_optgroup( $draft_dest, ( isset( $draft->to_list ) ) ? $draft->to_list : '' ) ?>
 234                                      </select>
 235                                  </div>
 236                                  <div id="toemail-toname" class="nobo <?php if ( isset( $draft->to_list ) ) echo ' hidden'; ?>">
 237                                      <label for="toemail" id="toemail-prompt-text" class="hide-if-no-js<?php if ( esc_attr( $draft->toemail ) != '' ) echo ' hidden' ; ?>"><?php _e( 'Enter email here', 'MailPress' ); ?></label>
 238                                      <input type="text" name="toemail" id="toemail" title="<?php echo esc_attr( __( 'Email', 'MailPress' ) ); ?>" class="<?php echo $class; ?>" value="<?php echo esc_attr( $draft->toemail ); ?>" />
 239                                      <label for="toname"  id="toname-prompt-text"  class="hide-if-no-js<?php if ( esc_attr( $draft->toname  ) != '' ) echo ' hidden' ; ?>"><?php _e( 'Enter name here',  'MailPress' ); ?></label>
 240                                      <input type="text" name="toname"  id="toname"  title="<?php echo esc_attr( __( 'Name', 'MailPress' ) ); ?>"  class="<?php echo $class; ?>" value="<?php echo esc_attr( $draft->toname ); ?>" />
 241                                  </div>
 242                              </td></tr></table>
 243  
 244  
 245                      </div>
 246                      <div id="titlediv">
 247                          <div id="titlewrap">
 248                              <label for="title" id="title-prompt-text" class="hide-if-no-js<?php echo ( isset( $draft->subject ) ) ? ' hidden' : ''; ?>"><?php _e( 'Enter subject here', 'MailPress' ); ?></label>
 249                              <input type="text" name="subject" id="title" size="30" tabindex="1" autocomplete="off" value="<?php echo ( isset( $draft->subject ) ) ? esc_attr( $draft->subject ) : ''; ?>" />
 250                          </div>
 251                      </div>
 252  
 253  
 254                      <div class="mail-format-description"></div>
 255                      <div class="mail-formats-fields">
 256                          <input type="hidden" name="mail_format" id="mail_format" value="<?php echo $mail_format; ?>" >
 257                          <div class="<?php if ( 'plaintext' != $mail_format ) echo 'hidden '; ?>field mp-format-plaintext" id="mp-format-plaintext">
 258                              <label for="plaintext"><?php _e( 'Plaintext', 'MailPress' ); ?></label>
 259                              <textarea name="plaintext" id="plaintext" class="widefat"><?php echo ( isset( $draft->plaintext ) ) ? esc_html ( $draft->plaintext ) : ''; ?></textarea>
 260                          </div>
 261                          <div id="div_html2txt" class="hidden">
 262                              <a id="html2txt" class="button hide-if-no-js" onclick="return false;" title="<?php echo esc_attr( __( 'Plaintext from Html', 'MailPress' ) ); ?>" href="#">
 263                                  <span class="mp-media-buttons-icon"></span>
 264                                  <?php _e( 'Synchronize', 'MailPress' ); ?> 
 265                              </a>
 266                              <img id="html2txt_loading" src="images/wpspin_light.gif" alt="" />
 267                          </div>
 268                      </div>
 269  
 270  
 271                      <div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea edit-form-section">
 272  <?php wp_editor( ( isset( $draft->html ) ) ? $draft->html : '', 'content', array( 'media_buttons' => true, 'tabindex' => 5 ) ); ?>
 273                          <div id="post-status-info">
 274                              <span id="wp-word-count" class="alignleft"></span>
 275                              <span class="alignright">
 276                                  <span id="autosave">&#160;</span>
 277                                  <span id="last-edit">
 278  <?php if ( isset( $lastedited ) ) : ?>
 279                                      <?php echo $lastedited; ?>
 280  <?php    endif; ?>
 281                                  </span>
 282                              </span>
 283                              <br class="clear" />
 284                          </div>
 285                      </div>
 286  <?php do_meta_boxes( MP_AdminPage::screen, 'normal', $draft ); ?>
 287                  </div>
 288              </div>
 289          </div>
 290      </form>
 291  </div>
 292  <?php if ( !MP_AdminPage::flash() ) : ?>
 293      <div id="html-upload-iframes"></div>
 294  <?php endif;


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