[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_WP_Admin_page_
   3  {
   4      const screen        = MailPress_page_write;
   5      const capability    = 'MailPress_edit_mails';
   6      const help_url        = 'http://blog.mailpress.org/tutorials/';
   7      const file            = __FILE__;
   8  
   9  ////  Redirect  ////
  10  
  11  	public static function redirect() 
  12      {
  13          $action = parent::redirect();
  14          if ( !$action ) return;
  15  
  16          if ( isset( self::$get_['id'] ) )
  17          {
  18              $id = self::$get_['id'];
  19          }
  20  
  21          $list_url = self::url( MailPress_mails, self::get_url_parms() );
  22  
  23          switch( $action ) 
  24          {
  25              case 'pause' :
  26                  if ( MP_Mail::set_status( $id, 'paused' ) )
  27                  {
  28                      $list_url .= '&paused=1';
  29                  }
  30                  self::mp_redirect( $list_url );
  31              break;
  32              case 'restart' :
  33                  if ( MP_Mail::set_status( $id, 'unsent' ) )
  34                  {
  35                      $list_url .= '&restartd=1';
  36                  }
  37                  self::mp_redirect( $list_url );
  38              break;
  39              case 'archive' :
  40                  if ( MP_Mail::set_status( $id, 'archived' ) )
  41                  {
  42                      $list_url .= '&archived=1';
  43                  }
  44                  self::mp_redirect( $list_url );
  45              break;
  46              case 'unarchive' :
  47                  if ( MP_Mail::set_status( $id, 'sent' ) )
  48                  {
  49                      $list_url .= '&unarchived=1';
  50                  }
  51                  self::mp_redirect( $list_url );
  52              break;
  53              case 'send' :
  54                  if ( 'draft' != MP_Mail::get_status( $id ) )
  55                  {
  56                      break;
  57                  }
  58                  $x = MP_Mail_draft::send( $id );
  59                  $list_url .= ( is_numeric( $x ) )    ? '&sent=' . $x : '&notsent=1';
  60                  self::mp_redirect( $list_url );
  61              break;
  62              case 'delete' :
  63                  if ( MP_Mail::set_status( $id, 'delete' ) )
  64                  {
  65                      $list_url .= '&deleted=1';
  66                  }
  67                  self::mp_redirect( $list_url );
  68              break;
  69  
  70              case 'draft' :
  71                  $id = ( empty( self::$pst_['id'] ) ) ? MP_Mail::get_id( __CLASS__ . ' ' . __METHOD__ . ' ' . self::screen ) : ( int ) self::$pst_['id'];
  72  
  73                  switch ( true )
  74                  {
  75                  // process attachments
  76                      case isset( self::$pst_['addmeta'] ) :
  77                          MP_Mail_meta::add_meta( $id );
  78                          $parm = "&cfsaved=1";
  79                      break;
  80                      case isset( self::$pst_['updatemailmeta'] ) :
  81                          $cfsaved = 0;
  82                          foreach ( self::$pst_['meta'] as $meta_id => $meta )
  83                          {
  84                              $meta_key = $meta['key'];
  85                              $meta_value = $meta['value'];
  86                              MP_Mail_meta::update_by_id( $meta_id , $meta_key, $meta_value );
  87                              $cfsaved++;
  88                          }
  89                          $parm = "&cfsaved=$cfsaved";
  90                      break;
  91                      case isset( self::$pst_['deletemailmeta'] ) :
  92                          $cfdeleted = 0;
  93                          foreach ( self::$pst_['deletemailmeta'] as $meta_id => $x )
  94                          {
  95                              MP_Mail_meta::delete_by_id( $meta_id );
  96                              $cfdeleted++;
  97                          }
  98                          $parm = "&cfdeleted=$cfdeleted";
  99                      break;
 100                  // process mail
 101                      default :
 102                          $id = ( empty( self::$pst_['id'] ) ) ? MP_Mail::get_id( __CLASS__ . ' ' . __METHOD__ . ' ' . self::screen ) : self::$pst_['id'];
 103  
 104                          $scheduled = MP_Mail_draft::update( $id );
 105  
 106                      // what else ?
 107                          do_action( 'MailPress_update_meta_boxes_write' );
 108                          $parm = ( $scheduled ) ? "&sched=1" : "&saved=1";
 109  
 110                          if ( !$scheduled && isset( self::$pst_['send'] ) )
 111                          {
 112                              wp_cache_delete( $id, 'mp_mail' );
 113                              $x = MP_Mail_draft::send( $id );
 114                              if ( is_numeric( $x ) )
 115                              {
 116                                  if ( 0 == $x )
 117                                  {
 118                                      $parm = "&sent=0";
 119                                  }
 120                                  else
 121                                  {
 122                                      $parm = "&sent=$x";
 123                                  }
 124                              }
 125                              else
 126                              {
 127                                  $parm = "&nodest=0";
 128                              }
 129                          }
 130                      break;
 131                  }
 132                  $HTTP_REFERER = filter_input( INPUT_SERVER, 'HTTP_REFERER' );
 133                  $url = ( strstr( $HTTP_REFERER, MailPress_edit ) ) ? MailPress_edit : MailPress_write;
 134                  $url .= "$parm&id=$id";
 135                  self::mp_redirect( $url );
 136              break;
 137          }
 138      }
 139  
 140  ////  Title  ////
 141  
 142  	public static function title() 
 143      { 
 144          global $title; 
 145          $title = ( isset( self::$get_['file'] ) && ( 'write' == self::$get_['file'] ) ) ? __( 'Edit Mail', 'MailPress' ) : __( 'Add New Mail', 'MailPress' );
 146  
 147          add_filter( 'tiny_mce_before_init', array( __CLASS__, 'tiny_mce_before_init' ) );
 148      }
 149  
 150  	public static function tiny_mce_before_init( $initArray )
 151      {
 152  // previously MailPress_fix_TinyMCE
 153          // Viper video quicktags
 154          global $VipersVideoQuicktags; 
 155      
 156          if ( isset( $VipersVideoQuicktags ) )
 157          {
 158              $Viper_mce_buttons = ( 1 == $VipersVideoQuicktags->settings['tinymceline'] ) ? 'mce_buttons' : 'mce_buttons_' . $VipersVideoQuicktags->settings['tinymceline'];
 159              remove_filter( $Viper_mce_buttons,         array( &$VipersVideoQuicktags, 'mce_buttons' ) );
 160              remove_filter( 'mce_external_plugins',     array( &$VipersVideoQuicktags, 'mce_external_plugins' ) );
 161              remove_filter( 'tiny_mce_version',         array( &$VipersVideoQuicktags, 'tiny_mce_version' ) );
 162              remove_action( 'edit_form_advanced',         array( &$VipersVideoQuicktags, 'AddQuicktagsAndFunctions' ) );
 163              remove_action( 'edit_page_form',         array( &$VipersVideoQuicktags, 'AddQuicktagsAndFunctions' ) );
 164          }
 165  
 166          // Cforms
 167          remove_filter( 'mce_buttons',             'cforms_button' );
 168          remove_filter( 'mce_external_plugins',     'cforms_plugin' );
 169  // previously MailPress_fix_TinyMCE
 170  
 171          $x = array(     'theme_advanced_buttons1'    => 'fullscreen',
 172                      'plugins'                => 'wpfullscreen',
 173           );
 174  
 175          foreach( $x as $k => $v )
 176          {
 177              if ( isset( $initArray[$k] ) )
 178              {
 179                  $initArray[$k] = str_replace( array( $v, ',,' ) , array( '', ',' ) , $initArray[$k] );
 180              }
 181          }
 182          return $initArray;
 183      }
 184  
 185  //// Help ////
 186  
 187  	public static function add_help_tab() 
 188      {
 189          global $current_screen;
 190  
 191          $content = '';
 192          $content .= '<p><strong>' . __( 'New Mail :', 'MailPress' ) . '</strong>' . __( 'This screen is divided in two parts:', 'MailPress' ) . '</p>';
 193          $content .= '<ul>';
 194          $content .= '<li>' . __( '<strong>Fixed</strong>', 'MailPress' );
 195          $content .= '<ul>';
 196          $content .= '<li>' . __( '<strong>Buttons</strong> &mdash; Two buttons to hide/display the plaintext part of your mail.', 'MailPress' ) . '</li>';
 197          $content .= '<li>' . __( '<strong>Recipient(s)</strong> &mdash; select a list or enter a mail + name.', 'MailPress' ) . '</li>';
 198          $content .= '<li>' . __( '<strong>Subject</strong> &mdash; subject of your mail (You can use replacement text here).', 'MailPress' ) . '</li>';
 199          $content .= '<li>' . __( '<strong>Plaintext editor</strong> &mdash; that you can display or hide using the two buttons above.', 'MailPress' ) . '</li>';
 200          $content .= '<li>' . __( '<strong>Html Editor</strong> &mdash; on top of this editor, Add Media to insert photos, Synchronize to convert your content and fill the plaintext editor from your Html text.', 'MailPress' ) . '</li>';
 201  
 202          $content .= '</ul>';
 203          $content .= '</li>';
 204          $content .= '<li>' . __( '<strong>Boxes</strong> &mdash; under the fixed part or in the sidebar.', 'MailPress' ) . '</li>';
 205          $content .= '</ul>';
 206  
 207          $current_screen->add_help_tab( array(     'id'        => 'overview',
 208                                          'title'    => __( 'Overview' ),
 209                                          'content'    => $content )
 210          );
 211  
 212          $content = '';
 213          $content .= '<p>' . __( 'While you are typing your mail, an autosave process will work in the background to save your work.', 'MailPress' ) . '</p>';
 214          $content .= '<p>' . __( 'On first autosave, or save draft, the preview button will appear in the Send box as well as the Attachments box.', 'MailPress' ) . '</p>';
 215          $content .= '<p>' . __( 'In Send box, you can:', 'MailPress' ) . '</p>';                
 216          $content .= '<ul>';
 217          $content .= '<li>' . __( '<strong>From</strong> &mdash; change the General settings for this mail.', 'MailPress' ) . '</li>';
 218          $content .= '<li>' . __( '<strong>Theme</strong> &mdash; change the default Theme.', 'MailPress' ) . '</li>';
 219          $content .= '<li>' . __( '<strong>Schedule</strong> &mdash; your mail at another date, based on Wp_cron (see more explanations on your Wp_cron help).', 'MailPress' ) . '</li>';
 220          $content .= '</ul>';
 221  
 222          $current_screen->add_help_tab( array(     'id'        => 'autosave-and-send',
 223                                          'title'        => __( 'Autosave and Send', 'MailPress' ),
 224                                          'content'    => $content )
 225          );
 226  
 227  
 228          $content = '';
 229          $content .= '<p>' . __( '<strong>Custom Fields</strong> &mdash; is only used for text replacement in mails.', 'MailPress' ) . '</p>';
 230          $content .= '<p>' . __( 'Let us say you want to manage honorific (e.g. : Mr, Miss, Sir ...) for all mp users. Create a custom field with name "honorific" and the appropriate value for each mp user. When creating a new Mail, you can write to a set of mp users starting your mail with the following "Dear {{honorific}}" (double opening and closing curly brackets inspired by <code>{{mustache}}</code> ). At the mail level, you can also create a default custom field "honorific" that will be the value if it was missing at the mp user level.', 'MailPress' ) . '</p>';
 231          $content .= '<p>' . __( 'Custom fields can also be populated when importing mp users (import add-on).', 'MailPress' ) . '</p>';
 232  
 233          $current_screen->add_help_tab( array(     'id'        => 'customfields',
 234                                          'title'    => __( 'Custom Fields', 'MailPress' ),
 235                                          'content'    => $content )
 236          );
 237  
 238          $content = '';
 239          $content .= '<p>' . __( 'You can add attachments to your mail.', 'MailPress' ) . '</p>';
 240          $content .= '<p>' . __( 'WordPress supports uploading the most common file types, not all file types.', 'MailPress' ) . '</p>';
 241          $content .= '<p>' . __( 'Not all webhosts permit these files to be uploaded. Also, they may not permit large file uploads. If you are having issues, please check with your host first. .', 'MailPress' ) . '</p>';                
 242          $content .= '<p>' . sprintf( __( 'Draft mail with attachments can be quickly identified in %1$s with a little clip icon : %2$s', 'MailPress' ), sprintf( '<a href="' . MailPress_mails . '" target="_blank">%s</a>', __( 'Mails list', 'MailPress' ) ) , '<span class="mp_icon mp_icon_attachment" title="' . __('Attachments', 'MailPress' ) . '" ></span>' ) . '</p>';
 243  
 244          $current_screen->add_help_tab( array(     'id'        => 'attachments',
 245                                          'title'    => __( 'Attachments', 'MailPress' ),
 246                                          'content'    => $content )
 247          );
 248  
 249  
 250          do_action( 'MailPress_add_help_tab_write' );
 251      }
 252  
 253  ////  Styles  ////
 254  
 255  	public static function print_styles( $s ) 
 256      {
 257          $styles = ( is_array( $s ) ) ? $s : array();
 258  
 259          wp_register_style( self::screen,         '/' . MP_PATH . 'mp-admin/css/write.css',     array( 'thickbox' ) );
 260          $styles[] = self::screen;
 261  
 262          parent::print_styles( $styles );
 263      }
 264  
 265  	public static function print_styles_icons( $i = array( 'ext', 'icon', ) ) 
 266      {
 267          return parent::print_styles_icons( $i );
 268      }
 269  
 270  ////  Scripts  ////
 271  
 272  	public static function print_scripts( $scripts = array() ) 
 273      {
 274          wp_register_script( 'mp-ajax-response',     '/' . MP_PATH . 'mp-includes/js/mp_ajax_response.js', array( 'jquery' ), false, 1 );
 275          wp_localize_script( 'mp-ajax-response', 'wpAjax', array( 
 276              'noPerm' => __( 'Email was not sent AND/OR Update database failed', 'MailPress' ), 
 277              'broken' => __( 'An unidentified error has occurred.' ), 
 278              'l10n_print_after' => 'try{convertEntities( wpAjax );}catch( e ){};' 
 279           ) );
 280  
 281          wp_register_script( 'mp-autosave',         '/' . MP_PATH . 'mp-includes/js/autosave.js', array( 'schedule', 'mp-ajax-response' ), false, 1 );
 282          wp_localize_script( 'mp-autosave', 'autosaveL10n', array    (     
 283              'autosaveInterval'=> '60', 
 284              'previewMailText'    =>  __( 'Preview' ), 
 285              'requestFile'     => admin_url( 'admin-ajax.php' ), 
 286              'savingText'    => __( 'Saving draft...', 'MailPress' )
 287           ) );
 288  
 289          wp_register_script( 'mp_customfields',    '/' . MP_PATH . 'mp-includes/js/mp_customfields.js',false, false, 1 );
 290          wp_localize_script( 'mp_customfields',     'MP_CustomFieldsL10n',  array( 
 291              'object_id'     => 'mail_id',
 292           ) );
 293  
 294          wp_register_script( 'mp-lists',         '/' . MP_PATH . 'mp-includes/js/mp_lists.js', array( 'mp-ajax-response', 'mp_customfields' ), false, 1 );
 295  
 296          wp_register_script( 'mp_html_sifiles',     '/' . MP_PATH . 'mp-includes/js/fileupload/si.files.js', array(), false, 1 );
 297          wp_register_script( 'mp_html_upload',     '/' . MP_PATH . 'mp-includes/js/fileupload/htm.js', array( 'mp_html_sifiles' ), false, 1 );
 298          wp_localize_script( 'mp_html_upload', 'htmuploadL10n', array( 
 299              'img' => 'images/wpspin_light.gif',
 300              'iframeurl'     => admin_url( 'admin-ajax.php' ), 
 301              'uploading'     => __( 'Uploading ...', 'MailPress' ), 
 302              'attachfirst'     => __( 'Attach a file', 'MailPress' ), 
 303              'attachseveral'     => __( 'Attach another file', 'MailPress' ), 
 304              'l10n_print_after'=> 'try{convertEntities( htmuploadL10n );}catch( e ){};' 
 305           ) );
 306  
 307          wp_register_script( 'mp-thickbox',         '/' . MP_PATH . 'mp-includes/js/mp_thickbox.js', array( 'thickbox' ), false, 1 );
 308  
 309          $deps = array( 'quicktags', 'mp-autosave', 'mp-lists', 'postbox' );
 310          if ( user_can_richedit() )    $deps[] = 'editor';
 311          $deps[] = 'thickbox';
 312          $deps[] = 'mp-thickbox';
 313  //        $deps[] = ( self::flash() ) ? 'mp_swf_upload' : 'mp_html_upload';
 314          $deps[] = 'mp_html_upload';
 315  
 316          wp_register_script( self::screen,         '/' . MP_PATH . 'mp-admin/js/write.js', $deps, false, 1 );
 317          wp_localize_script( self::screen, 'MP_AdminPageL10n', array( 
 318              'screen'         => self::screen,
 319  
 320              'errmess'         => __( 'Enter a valid email !', 'MailPress' ), 
 321  
 322              'sendImmediately'    => __( 'Send <b>immediately</b>', 'MailPress' ),
 323              'sendOnFuture'     => __( 'Schedule for:' ),
 324  
 325              'name_send'     => 'send',
 326              'schedule'         => __( 'Schedule' ),
 327              'send'         => __( 'Send',  'MailPress' ),
 328  
 329              'name_save'     => 'save',
 330              'save'         => __( 'Save',  'MailPress' ),
 331              'update'         => __( 'Update',  'MailPress' ),
 332  
 333              'html2txt'        => __( "You are about to replace the content of plaintext area.\n 'Cancel' to stop, 'OK' to replace.",  'MailPress' ),
 334  
 335              'l10n_print_after' => 'try{convertEntities( MP_AdminPageL10n );}catch( e ){};' 
 336           ) );
 337  
 338          $scripts[] = self::screen;
 339          parent::print_scripts( $scripts );
 340  
 341          if ( !parent::$is_footer )
 342          {
 343              return;
 344          }
 345      }
 346  
 347  	public static function flash() 
 348      {
 349          return false;
 350      }
 351  
 352  ////  Metaboxes  ////
 353  
 354  	public static function admin_head() 
 355      {
 356          $id = ( isset( self::$get_['id'] ) ) ? self::$get_['id'] : 0;
 357          add_meta_box( 'submitdiv',         __( 'Send', 'MailPress' ),            array( __CLASS__, 'meta_box_submit' ),         self::screen, 'side', 'core' );
 358          add_meta_box( 'attachmentsdiv',     __( 'Attachments', 'MailPress' ),    array( __CLASS__, 'meta_box_attachments' ),     self::screen, 'side', 'core' );
 359  
 360          if ( current_user_can( 'MailPress_mail_custom_fields' ) )
 361          {
 362              add_meta_box( 'customfieldsdiv',     __( 'Custom Fields' ),        array( __CLASS__, 'meta_box_customfields' ),     self::screen, 'normal', 'core' );
 363          }
 364          else
 365          {
 366              if ( $id )
 367              {
 368                  $metas = MP_Mail_meta::get( $id );
 369                  if ( $metas ) 
 370                  {
 371                      if ( !is_array( $metas ) )
 372                      {
 373                          $metas = array( $metas );
 374                      }
 375                      foreach ( $metas as $meta )
 376                      {
 377                          if ( $meta->meta_key[0] == '_' )
 378                          {
 379                              continue;
 380                          }
 381                          add_meta_box( 'customfieldsdiv',     __( 'Custom Fields' ),     array( __CLASS__, 'meta_box_browse_customfields' ), self::screen, 'normal', 'core' );
 382                          break;
 383                      }
 384                  }
 385              }
 386          }
 387  
 388          if ( $id )
 389          {
 390              $rev_ids     = MP_Mail_revision::get( $id );
 391  
 392              if ( isset( $rev_ids ) && $rev_ids )
 393              {
 394                  add_meta_box( 'revisionbox',     __( 'Mail Revisions', 'MailPress' ),    array( __CLASS__, 'meta_box_revision' ),         self::screen, 'normal', 'high' );
 395              }
 396  
 397          }
 398  
 399          do_action( 'MailPress_add_meta_boxes_write', $id, self::screen );
 400  
 401          parent::admin_head();
 402      }
 403  /**/
 404  	public static function meta_box_submit( $draft )
 405      {
 406          global $mp_general;
 407  
 408  
 409          $fromname = $draft->fromname;
 410          $fromemail= $draft->fromemail;
 411          $from = "<b>{$fromname}</b> &lt;{$fromemail}&gt;";
 412  
 413  
 414             $datef          = __( 'M j, Y @ G:i' );
 415  
 416          $stamp = __( 'Send <b>immediately</b>', 'MailPress' );
 417          $date = date_i18n( $datef, strtotime( current_time( 'mysql' ) ) );
 418  
 419          $save_post_class = '';
 420          $publish_name    = 'send';
 421          $publish_value   = __( 'Send', 'MailPress' );
 422  
 423          if ( $draft && isset( $draft->id ) )
 424          {
 425  
 426              $args            = array();
 427              $args['id']    = $draft->id;
 428  
 429  // url's
 430              if ( current_user_can( 'MailPress_delete_mails' ) )
 431              {
 432                  $args['action']    = 'delete';
 433                  $delete_url = esc_url( self::url( MailPress_write, $args ) );
 434              }
 435                          
 436              $args = array( 'id' => $draft->id, 'action' => 'mp_ajax', 'mp_action' => 'iview', 'TB_iframe' => 'true' );
 437              $view_url = esc_url( self::url( admin_url( 'admin-ajax.php'), $args ) );
 438  
 439  // actions
 440              $actions        = array();
 441  
 442              if ( isset( $delete_url ) )
 443              {
 444                  $onclick = "onclick=\"return (confirm('" . esc_js(sprintf( __("You are about to delete this draft '%s'\n  'Cancel' to stop, 'OK' to unbounce.", 'MailPress' ), $draft->id ) ) . "'));\"";
 445                  $actions['delete'] = '<a class="submitdelete" href="' . $delete_url . '" ' . $onclick . '>' . __( 'Delete', 'MailPress' ) . '</a>';
 446              }
 447  
 448              $actions['view'] = '<a class="preview button" href="' . $view_url . '" target="_blank">' . __( 'Preview', 'MailPress' ) . '</a>';
 449  
 450              if ( $draft->_scheduled )
 451              {
 452                  $stamp = __( 'Scheduled for: <b>%1$s</b>', 'MailPress' );
 453                      $date = date_i18n( $datef, strtotime( $draft->sent ) );
 454  
 455                  $save_post_class = ' hidden';
 456                  $publish_name    = 'save';
 457                  $publish_value   = __( 'Update', 'MailPress' );
 458                  }
 459          } 
 460  
 461          $publish = ( current_user_can( 'MailPress_send_mails' ) ) ? '<input type="submit" name="' . $publish_name . '" id="publish" class="button-primary" value="' . esc_attr( $publish_value ) . '" />' : '';
 462  
 463  
 464          $out = '';
 465          $out .= '<div class="submitbox" id="submitpost">' . "\r\n";
 466          $out .= '<div id="minor-publishing"><div class="hidden"></div>' . "\r\n";
 467  
 468          $out .= '<div id="minor-publishing-actions">';
 469          $out .= '<div id="save-action"><input type="submit" name="save" id="save-post" class="button button-highlighted' . $save_post_class . '" value="' . esc_attr( __( 'Save Draft', 'MailPress' ) ) . '"  /></div>';
 470          $out .= '<div id="preview-action"><span id="preview-button">' . ( ( isset( $actions['view'] ) ) ? $actions['view'] : '' ) . '</span></div>';
 471          $out .= '<div class="clear"></div></div>' . "\r\n";
 472  
 473          $out .= '<div id="misc-publishing-actions">';
 474          $out .= '<div class="misc-pub-section mp_theme">';
 475          $out .= '<label>' . __( 'From: ', 'MailPress' ) . '</label><b><span id="span_from">' . $from . '</span></b>';
 476          if ( current_user_can( 'MailPress_write_edit_fromemail' ) )
 477          {
 478              $out .= '<a href="#edit_from" class="edit-from hide-if-no-js">' . __( 'Edit' ) . '</a>';
 479              $out .= '<div id="fromdiv" class="hide-if-js">';
 480              $out .= '<input type="hidden" name="hidden_fromname"  id="hidden_fromname"  value="' . esc_attr( $fromname ) . '" />';
 481              $out .= '<input type="hidden" name="hidden_fromemail" id="hidden_fromemail" value="' . esc_attr( $fromemail ) . '" />';
 482              $out .= __( 'Name: ', 'MailPress' )  . '<input type="text" name="fromname"  id="fromname"  size="25" value="' . esc_attr( $fromname )  . '" /><br />';
 483              $out .= __( 'Email: ', 'MailPress' ) . '<input type="text" name="fromemail" id="fromemail" size="25" value="' . esc_attr( $fromemail ) . '" /><br />';
 484              $out .= '<a href="#edit_from" class="save-from hide-if-no-js button">' . __( 'OK' ) . '</a>';
 485              $out .= '<a href="#edit_from" class="cancel-from hide-if-no-js">' . __( 'Cancel'  ) . '</a>';
 486              $out .= '</div>';
 487          }
 488          else
 489          {
 490              $out .= '<input type="hidden" name="fromname"  id="fromname"  value="' . esc_attr( $fromname  ) . '" />';
 491              $out .= '<input type="hidden" name="fromemail" id="fromemail" value="' . esc_attr( $fromemail ) . '" />';
 492          }
 493          $out .= '</div>' . "\r\n";
 494  
 495          $xthemes = array();
 496          $th = new MP_Themes();
 497          $themes = $th->themes;
 498  
 499          foreach( $themes as $key => $theme )
 500          {
 501              if ( 'plaintext' == $theme['Stylesheet'] )
 502              {
 503                  unset( $themes[$key] );
 504              }
 505              if ( '_' == $theme['Stylesheet'][0] )
 506              {
 507                  unset( $themes[$key] );
 508              }
 509          }
 510  
 511          $xthemes = array( '' => __( 'current', 'MailPress' ) );
 512          foreach ( $themes as $theme )
 513          {
 514              $xthemes[$theme['Stylesheet']] = $theme['Stylesheet'];
 515          }
 516  
 517          $current_theme = $themes[$th->current_theme]['Stylesheet'];
 518          $theme = ( isset( $draft->theme ) ) ? $draft->theme : '';
 519  
 520          $out .= '<div class="misc-pub-section mp_theme">';
 521          $out .= '<label>' . __( 'Theme: ', 'MailPress' ) . '</label><b><span id="span_theme">' . $xthemes[$theme] . '</span></b>';
 522          $out .= '<a href="#edit_theme" class="edit-theme hide-if-no-js">' . __( 'Edit' ) . '</a>';
 523          $out .= '<div id="themediv" class="hide-if-js">';
 524          $out .= '<input type="hidden" name="hidden_theme" id="hidden_theme" value="' . esc_attr( $theme ) . '" />';
 525          $out .= '<select name="Theme" id="theme">' . self::select_option( $xthemes, $theme, false ) . '</select>';
 526          $out .= '<a href="#edit_theme" class="save-theme hide-if-no-js button">' . __( 'OK' ) . '</a>';
 527          $out .= '<a href="#edit_theme" class="cancel-theme hide-if-no-js">' . __( 'Cancel'  ) . '</a>';
 528          $out .= '</div></div>' . "\r\n";
 529  
 530          $out .= '<div class="misc-pub-section curtime misc-pub-section-last">';
 531          $out .= '<span id="timestamp">' . sprintf( $stamp, $date ) . '</span>';
 532          $out .= '<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex="4">' . __( 'Edit' ) . '</a>';
 533          $out .= '<div id="timestampdiv" class="hide-if-js">' . self::touch_time( 4 ) . '</div>';
 534          $out .= '</div>' . "\r\n";
 535  
 536          $out .= '</div><div class="clear"><br /><br /></div></div>' . "\r\n";
 537  
 538          $out .= '<div id="major-publishing-actions">';
 539          $out .= '<div id="delete-action">' . ( ( isset( $actions['delete'] ) ) ? $actions['delete'] : '' ) . '</div>';
 540          $out .= '<div id="publishing-action">' . $publish . '</div>';
 541          $out .= '<div class="clear"></div>' . "\r\n";
 542  
 543          $out .= '</div></div>' . "\r\n";
 544  
 545          echo $out;
 546      }
 547  
 548  	public static function touch_time( $tab_index = 0, $edit = 1, $multi = 0 ) 
 549      {
 550          global $wp_locale, $draft;
 551  
 552          $tab_index_attribute = '';
 553          if ( ( int ) $tab_index > 0 )
 554          {
 555              $tab_index_attribute = " tabindex=\"$tab_index\"";
 556          }
 557  
 558          $time_adj = current_time( 'timestamp' );
 559  
 560          $draft_date = ( $draft->_scheduled ) ? $draft->sent : date_i18n( 'Y-m-d H:i' );
 561  
 562          $jj = ( $edit ) ? mysql2date( 'd', $draft_date, false ) : gmdate( 'd', $time_adj );
 563          $mm = ( $edit ) ? mysql2date( 'm', $draft_date, false ) : gmdate( 'm', $time_adj );
 564          $aa = ( $edit ) ? mysql2date( 'Y', $draft_date, false ) : gmdate( 'Y', $time_adj );
 565          $hh = ( $edit ) ? mysql2date( 'H', $draft_date, false ) : gmdate( 'H', $time_adj );
 566          $mn = ( $edit ) ? mysql2date( 'i', $draft_date, false ) : gmdate( 'i', $time_adj );
 567          $ss = ( $edit ) ? mysql2date( 's', $draft_date, false ) : gmdate( 's', $time_adj );
 568  
 569          $cur_jj = gmdate( 'd', $time_adj );
 570          $cur_mm = gmdate( 'm', $time_adj );
 571          $cur_aa = gmdate( 'Y', $time_adj );
 572          $cur_hh = gmdate( 'H', $time_adj );
 573          $cur_mn = gmdate( 'i', $time_adj );
 574  
 575          $month = '<select name="mm" id="mm" ' . $tab_index_attribute . ' >';
 576          for ( $i = 1; $i < 13; $i = $i +1 )
 577          {
 578              $month .= '<option value="' . zeroise( $i, 2 ) . ( ( $i == $mm ) ? '" selected="selected"' : '"' ) . '>' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . '</option>' . "\n";
 579          }
 580          $month .= '</select>';
 581  
 582          $day    = '<input type="text" name="jj" id="jj" size="2" maxlength="2" ' . $tab_index_attribute . ' autocomplete="off" value="' . $jj . '" />';
 583          $year   = '<input type="text" name="aa" id="aa" size="4" maxlength="4" ' . $tab_index_attribute . ' autocomplete="off" value="' . $aa . '" />';
 584          $hour   = '<input type="text" name="hh" id="hh" size="2" maxlength="2" ' . $tab_index_attribute . ' autocomplete="off" value="' . $hh . '" />';
 585          $minute = '<input type="text" name="mn" id="mn" size="2" maxlength="2" ' . $tab_index_attribute . ' autocomplete="off" value="' . $mn . '" />';
 586  
 587          $out = '';
 588          $out .= '<div class="timestamp-wrap">';    /* translators: 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */
 589          $out .= sprintf( __( '%1$s%2$s, %3$s @ %4$s : %5$s' ), $month, $day, $year, $hour, $minute );
 590          $out .= '</div><input type="hidden" name="ss" id="ss" value="' . $ss . '" />';
 591          $out .= "\n\n";
 592          foreach ( array( 'mm', 'jj', 'aa', 'hh', 'mn' ) as $timeunit ) 
 593          {
 594                 $cur_timeunit = 'cur_' . $timeunit;
 595  
 596              $out .= '<input type="hidden" name="hidden_' . $timeunit . '" id="hidden_' . $timeunit . '" value="' . $$timeunit     . '" />' . "\n";
 597              $out .= '<input type="hidden" name="cur_'    . $timeunit . '" id="cur_'    . $timeunit . '" value="' . $$cur_timeunit . '" />' . "\n";
 598          }
 599          $out .= '<p>';
 600          $out .= '<a href="#edit_timestamp" class="save-timestamp hide-if-no-js button">' . __( 'OK' )     . '</a>';
 601          $out .= '<a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js">'      . __( 'Cancel' ) . '</a>';
 602          $out .= '</p>';
 603  
 604          return $out;
 605      }
 606  
 607  /**/
 608  	public static function meta_box_plaintext( $draft )
 609      {
 610          $out = '';
 611          $out .= '<textarea name="plaintext" id="plaintext" rows="1" cols="40">' . ( ( isset( $draft->plaintext ) ) ? str_replace( '&', '&amp;', $draft->plaintext ) : '' ) . '</textarea>' . "\r\n";
 612          $out .= '<div id="div_html2txt" class="hidden">';
 613          $out .= '<a id="html2txt" class="button hide-if-no-js" onclick="return false;" title="' . esc_attr( __( 'Plaintext from Html', 'MailPress' ) ) . '" href="#"><span class="mp-media-buttons-icon"></span>' . __( 'Synchronize', 'MailPress' ) . '</a>';
 614          $out .= '</div>';
 615  
 616          echo $out;
 617      }
 618  /**/
 619  	public static function meta_box_revision( $draft )
 620      {
 621          MP_Mail_revision::listing( $draft->id );
 622      }
 623  /**/
 624  	public static function meta_box_attachments( $draft ) 
 625      {
 626          if ( $draft )
 627          {
 628              $draft_id = ( isset( $draft->id ) ) ? $draft->id : 0;
 629          }
 630  
 631          $divid = 'html-upload-ui';
 632          $divs  = '<div class="mp_fileupload_txt"><span class="mp_fileupload_txt"></span></div><div class="mp_fileupload_file" id="mp_fileupload_file_div"></div>';
 633  
 634          $out = '';
 635  
 636          $out .= '<script type="text/javascript">' . "\r\n";
 637          $out .= '/* <![CDATA[ */' . "\r\n";
 638          $out .= 'var draft_id = ' . $draft_id . ';' . "\r\n";
 639          $out .= '/* ]]> */' . "\r\n";
 640          $out .= '</script>' . "\r\n";
 641  
 642          $out .= '<div id="attachment-items">' . "\r\n";
 643          $out .= self::get_attachments_list( $draft_id );
 644          $out .= '</div>' . "\r\n";
 645  
 646          $out .= '<div><span id="attachment-errors"></span></div>' . "\r\n";
 647  
 648          $out .= '<div id="html-upload-ui">';
 649          $out .= '<div class="mp_fileupload_txt"><span class="mp_fileupload_txt button-secondary"></span></div>';
 650          $out .= '<div class="mp_fileupload_file" id="mp_fileupload_file_div"></div>';
 651          $out .= '<br class="clear" />';
 652          $out .= '<input type="hidden" name="type_of_upload" value="html-upload-ui" />';
 653          $out .= '</div>' . "\r\n";
 654  
 655          echo $out;
 656      }
 657  
 658  	public static function get_attachments_list( $draft_id )
 659      {
 660          $out = '';
 661          $metas = MP_Mail_meta::has( $draft_id, '_MailPress_attached_file' );
 662          if ( $metas )
 663          {
 664              foreach( $metas as $meta )
 665              {
 666                  $out .= self::get_attachment_row( $meta );
 667              }
 668          }
 669          return $out;
 670      }
 671  
 672  	public static function get_attachment_row( $meta )
 673      {
 674          $meta_value = maybe_unserialize( $meta['meta_value'] );
 675          if ( !is_file( $meta_value['file_fullpath'] ) )
 676          {
 677              return;
 678          }
 679  
 680          if ( !class_exists( 'MP_Tracking_files', false ) ) new MP_Tracking_files();
 681          $fe = apply_filters( 'MailPress_tracking_files_ext_get', pathinfo( $meta_value['file_fullpath'], PATHINFO_EXTENSION ) );
 682          $class = ( isset( $fe->classes ) ) ? $fe->classes : 'mp_ext mp_ext_unknown';
 683  
 684          //$fname = ( strlen( $meta_value['name'] ) > 33 ) ? substr( $meta_value['name'], 0, 30 ) . '...' : $meta_value['name'];
 685  
 686          $href = esc_url( add_query_arg( array( 'action' => 'mp_ajax', 'mp_action' => 'attach_download', 'id' => $meta['meta_id'] ), admin_url( 'admin-ajax.php' ) ) );
 687  
 688          $out = '';
 689          $out .= '<div id="attachment-item-' . $meta['meta_id'] . '" class="attachment-item child-of-' . $meta['mp_mail_id'] . '">';
 690          $out .= '<table>';
 691          $out .= '<tr>';
 692          $out .= '<td><input type="checkbox" name="Files[' . $meta['meta_id'] . ']" value="' . esc_attr( $meta['meta_id'] ) . '" class="mp_fileupload_cb" checked="checked" />    </td>';
 693          $out .= '<td><div class="' . $class . '"></div><div><a href="' . $href . '" class="attachme" title="' . esc_attr( $meta_value['name'] ) . '">' . $meta_value['name'] . '</a></div></td>';
 694          $out .= '</tr>';
 695          $out .= '</table>';
 696          $out .= '</div>' . "\r\n";
 697  
 698          return $out;
 699      }
 700  
 701  	public static function select_optgroup( $list, $selected, $echo = true )
 702      {
 703          foreach( $list as $value => $label )
 704          {
 705              $_selected = ( !is_array( $selected ) ) ? $selected : ( ( in_array( $value, $selected ) ) ? $value : null );
 706              $list[$value] = '<option ' . self::selected( ( string ) $value, ( string ) $_selected, false, false ) . ' value="' . esc_attr( $value ) . '">' . esc_html( $label ) . '</option>';
 707          }
 708  
 709          $opened = false;
 710  
 711          foreach( $list as $value => $html )
 712          {
 713              if ( empty( $value ) )
 714              {
 715                  continue;
 716              }
 717              switch ( true )
 718              {
 719                  case ( in_array( $value , array( '2', '3' ) ) ) :
 720                      $optgroup = 'MailPress_comment';
 721                  break;
 722                  case ( is_numeric( $value ) ) :
 723                      $optgroup = 'MP_User';
 724                  break;
 725                  default :
 726                      $optgroup = ( $pos = strpos( $value, '~' ) ) ? substr( $value, 0, $pos ) : null;
 727                  break;
 728              }
 729              if ( isset( $$optgroup ) )
 730              {
 731                  continue;
 732              }
 733              $list[$value] = ( ( $opened ) ? '</optgroup>' : '' ) . '<optgroup label="' . esc_attr( apply_filters( 'MailPress_mailinglists_optgroup', __( '(unknown)', 'MailPress' ), $optgroup ) ) . '">' . $html;
 734              $opened = $$optgroup = true;
 735          }
 736  
 737          $x = implode( '', $list ) . ( ( $opened ) ? '</optgroup>' : '' );
 738  
 739          if ( !$echo )
 740          {
 741              return "\n$x\n";
 742          }
 743          echo "\n$x\n";
 744      }
 745  /**/
 746  	public static function meta_box_browse_customfields( $draft )
 747      {
 748          MP_Mail_customfields::meta_box_browse_customfields( $draft );
 749      }
 750  
 751  	public static function meta_box_customfields( $draft )
 752      {
 753          MP_Mail_customfields::meta_box_customfields( $draft );
 754      }
 755  }


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