[ Index ]

MailPress 544

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_adminpage_
   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          if (!empty($_REQUEST['action'])) $action = $_REQUEST['action'];
  14          if (!isset($action)) return;
  15  
  16          if (isset($_GET['id'])) $id = $_GET['id'];
  17  
  18          $list_url = self::url(MailPress_mails, self::get_url_parms());
  19  
  20          switch($action) 
  21          {
  22              case 'pause' :
  23                  if (MP_Mail::set_status($id, 'paused'))    $list_url .= '&paused=1';
  24                  self::mp_redirect($list_url);
  25              break;
  26              case 'restart' :
  27                  if (MP_Mail::set_status($id, 'unsent'))    $list_url .= '&restartd=1';
  28                  self::mp_redirect($list_url);
  29              break;
  30              case 'archive' :
  31                  if (MP_Mail::set_status($id, 'archived'))    $list_url .= '&archived=1';
  32                  self::mp_redirect($list_url);
  33              break;
  34              case 'unarchive' :
  35                  if (MP_Mail::set_status($id, 'sent'))        $list_url .= '&unarchived=1';
  36                  self::mp_redirect($list_url);
  37              break;
  38              case 'send' :
  39                  if ('draft' != MP_Mail::get_status($id)) break;
  40                  $x = MP_Mail_draft::send($id);
  41                  $list_url .= (is_numeric($x))    ? '&sent=' . $x : '&notsent=1';
  42                  self::mp_redirect($list_url);
  43              break;
  44              case 'delete' :
  45                  if (MP_Mail::set_status($id, 'delete'))        $list_url .= '&deleted=1';
  46                  self::mp_redirect($list_url);
  47              break;
  48  
  49              case 'draft' :
  50                  $id = (0 == $_POST['id']) ? MP_Mail::get_id(__CLASS__ . ' ' . __METHOD__ . ' ' . self::screen) : (int) $_POST['id'];
  51  
  52                  switch (true)
  53                  {
  54                  // process attachements
  55                      case isset($_POST['addmeta']) :
  56                          MP_Mail_meta::add_meta($id);
  57                          $parm = "&cfsaved=1";
  58                      break;
  59                      case isset($_POST['updatemailmeta']) :
  60                          $cfsaved = 0;
  61                          foreach ($_POST['meta'] as $meta_id => $meta)
  62                          {
  63                              $meta_key = $meta['key'];
  64                              $meta_value = $meta['value'];
  65                              MP_Mail_meta::update_by_id($meta_id , $meta_key, $meta_value);
  66                              $cfsaved++;
  67                          }
  68                          $parm = "&cfsaved=$cfsaved";
  69                      break;
  70                      case isset($_POST['deletemailmeta']) :
  71                          $cfdeleted = 0;
  72                          foreach ($_POST['deletemailmeta'] as $meta_id => $x)
  73                          {
  74                              MP_Mail_meta::delete_by_id( $meta_id );
  75                              $cfdeleted++;
  76                          }
  77                          $parm = "&cfdeleted=$cfdeleted";
  78                      break;
  79                  // process mail
  80                      default :
  81                          $id = (0 == $_POST['id']) ? MP_Mail::get_id(__CLASS__ . ' ' . __METHOD__ . ' ' . self::screen) : $_POST['id'];
  82  
  83                          $scheduled = MP_Mail_draft::update($id);
  84  
  85                      // what else ?
  86                          do_action('MailPress_update_meta_boxes_write');
  87                          $parm = ($scheduled) ? "&sched=1" : "&saved=1";
  88  
  89                          if (!$scheduled && isset($_POST['send']))
  90                          {
  91                              wp_cache_delete($id, 'mp_mail');
  92                              $x = MP_Mail_draft::send($id);
  93                              if (is_numeric($x))
  94                                  if (0 == $x)    $parm = "&sent=0";
  95                                  else            $parm = "&sent=$x";
  96                              else                $parm = "&nodest=0";
  97                          }
  98                      break;
  99                  }
 100                  $url = (strstr($_SERVER['HTTP_REFERER'], MailPress_edit)) ? MailPress_edit : MailPress_write;
 101                  $url .= "$parm&id=$id";
 102                  self::mp_redirect($url);
 103              break;
 104          }
 105      }
 106  
 107  ////  Title  ////
 108  
 109  	public static function title() 
 110      { 
 111          global $title; 
 112          $title = (isset($_GET['file']) && ('write' == $_GET['file'])) ? __('Edit Mail', MP_TXTDOM) : __('Add New Mail', MP_TXTDOM);
 113  
 114          add_filter('tiny_mce_before_init', array(__CLASS__, 'tiny_mce_before_init'));
 115      }
 116  
 117  	public static function tiny_mce_before_init($initArray)
 118      {
 119          $x = array(    'theme_advanced_buttons1'    => 'fullscreen',
 120                      'plugins'                => 'wpfullscreen',
 121          );
 122  
 123          foreach($x as $k => $v) if (isset($initArray[$k])) $initArray[$k] = str_replace( array($v, ',,') , array('', ',') , $initArray[$k] );
 124          return $initArray;
 125      }
 126  
 127  ////  Styles  ////
 128  
 129  	public static function print_styles($styles = array()) 
 130      {
 131          wp_register_style ( self::screen,         '/' . MP_PATH . 'mp-admin/css/write.css',     array('thickbox') );
 132  
 133          $styles[] = self::screen;
 134          parent::print_styles($styles);
 135      }
 136  
 137  ////  Scripts  ////
 138  
 139  	public static function print_scripts($scripts, $is_footer) 
 140      {
 141          wp_register_script( 'mp-ajax-response',     '/' . MP_PATH . 'mp-includes/js/mp_ajax_response.js', array('jquery'), false, 1);
 142          wp_localize_script( 'mp-ajax-response', 'wpAjax', array( 
 143              'noPerm' => __('Email was not sent AND/OR Update database failed', MP_TXTDOM), 
 144              'broken' => __('An unidentified error has occurred.'), 
 145              'l10n_print_after' => 'try{convertEntities(wpAjax);}catch(e){};' 
 146          ) );
 147  
 148          wp_register_script( 'mp-autosave',         '/' . MP_PATH . 'mp-includes/js/autosave.js', array('schedule', 'mp-ajax-response'), false, 1);
 149          wp_localize_script( 'mp-autosave', 'autosaveL10n', array    (     
 150              'autosaveInterval'=> '60', 
 151              'previewMailText'    =>  __('Preview'), 
 152              'requestFile'     => MP_Action_url, 
 153              'savingText'    => __('Saving draft...', MP_TXTDOM)
 154          ) );
 155  
 156          wp_register_script( 'mp-lists',         '/' . MP_PATH . 'mp-includes/js/mp_lists.js', array('mp-ajax-response'), false, 1);
 157          wp_localize_script( 'mp-lists', 'wpListL10n', array( 
 158              'url' => MP_Action_url
 159          ) );
 160  
 161          wp_register_script( 'mp_swf_upload',     '/' . MP_PATH . 'mp-includes/js/fileupload/swf.js', array('swfupload'), false, 1);
 162      // these error messages came from the sample swfupload js, they might need changing.
 163          wp_localize_script( 'mp_swf_upload', 'swfuploadL10n', array(
 164              'queue_limit_exceeded'         => __('You have attempted to queue too many files.'), 
 165              'file_exceeds_size_limit'     => sprintf(__('This file is too big. Your php.ini upload_max_filesize is %s.'), @ini_get('upload_max_filesize')), 
 166              'zero_byte_file'             => __('This file is empty. Please try another.'), 
 167              'invalid_filetype'         => __('This file type is not allowed. Please try another.'), 
 168              'default_error'             => __('An error occurred in the upload. Please try again later.'), 
 169              'missing_upload_url'         => __('There was a configuration error. Please contact the server administrator.'), 
 170              'upload_limit_exceeded'     => __('You may only upload 1 file.'), 
 171              'http_error'             => __('HTTP error.'), 
 172              'upload_failed'             => __('Upload failed.'), 
 173              'io_error'                 => __('IO error.'), 
 174              'security_error'             => __('Security error.'), 
 175              'file_cancelled'             => __('File cancelled.'), 
 176              'upload_stopped'             => __('Upload stopped.'), 
 177              'dismiss'                 => __('Dismiss'), 
 178              'crunching'             => __('Crunching&hellip;'), 
 179              'deleted'                 => __('Deleted'), 
 180              'l10n_print_after'         => 'try{convertEntities(swfuploadL10n);}catch(e){};'
 181          ) );
 182  
 183          wp_register_script( 'mp_html_sifiles',     '/' . MP_PATH . 'mp-includes/js/fileupload/si.files.js', array(), false, 1);
 184          wp_register_script( 'mp_html_upload',     '/' . MP_PATH . 'mp-includes/js/fileupload/htm.js', array('mp_html_sifiles'), false, 1);
 185          wp_localize_script( 'mp_html_upload', 'htmuploadL10n', array(
 186              'img' => 'images/wpspin_light.gif',
 187              'iframeurl'     => MP_Action_url, 
 188              'uploading'     => __('Uploading ...', MP_TXTDOM), 
 189              'attachfirst'     => __('Attach a file', MP_TXTDOM), 
 190              'attachseveral'     => __('Attach another file', MP_TXTDOM), 
 191              'l10n_print_after'=> 'try{convertEntities(htmuploadL10n);}catch(e){};' 
 192          ) );
 193  
 194          wp_register_script( 'mp-thickbox',         '/' . MP_PATH . 'mp-includes/js/mp_thickbox.js', array('thickbox'), false, 1);
 195  
 196          $deps = array('quicktags', 'mp-autosave', 'mp-lists', 'postbox');
 197          if ( user_can_richedit() )    $deps[] = 'editor';
 198          $deps[] = 'thickbox';
 199          $deps[] = 'mp-thickbox';
 200          $deps[] = (self::flash()) ? 'mp_swf_upload' : 'mp_html_upload';
 201  
 202          wp_register_script( self::screen,         '/' . MP_PATH . 'mp-admin/js/write.js', $deps, false, 1);
 203          wp_localize_script( self::screen, 'MP_AdminPageL10n', array(     
 204              'errmess'         => __('Enter a valid email !', MP_TXTDOM), 
 205              'screen'         => self::screen, 
 206  
 207              'sendImmediately'    => __('Send <b>immediately</b>', MP_TXTDOM),
 208              'sendOnFuture'     => __('Schedule for:'),
 209  
 210              'name_send'     => 'send',
 211              'schedule'         => __('Schedule'),
 212              'send'         => __('Send',  MP_TXTDOM),
 213  
 214              'name_save'     => 'save',
 215              'save'         => __('Save',  MP_TXTDOM),
 216              'update'         => __('Update',  MP_TXTDOM),
 217  
 218              'html2txt'        => __("You are about to replace the content of plaintext area.\n 'Cancel' to stop, 'OK' to replace.",  MP_TXTDOM),
 219  
 220              'l10n_print_after' => 'try{convertEntities(MP_AdminPageL10n);}catch(e){};' 
 221          ) );
 222  
 223          $scripts[] = self::screen;
 224          parent::print_scripts($scripts);
 225  
 226          if (!$is_footer) return;
 227  
 228          global $hook_suffix;
 229          if (self::flash()) add_action("admin_footer-$hook_suffix", array('MP_AdminPage', 'swfupload'));
 230      }
 231  
 232  	public static function flash() 
 233      {
 234          // If Mac and mod_security, no Flash. :(
 235          $flash = (isset($_GET['flash'])) ? $_GET['flash'] : true;
 236          $flash = ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mac') && apache_mod_loaded('mod_security') ) ? false : $flash;
 237          return $flash;
 238      }
 239  
 240      // swfupload
 241  	public static function swfupload() 
 242      {
 243          $m = array('mp_swfupload' => array(
 244                  'flash_url'             => includes_url('js/swfupload/swfupload.swf'), 
 245  
 246                  'button_text'             => esc_js(__('Attach a file', MP_TXTDOM)), 
 247                  'button_text_style'         => '.mp_button { text-align: left; color: #21759B; text-decoration: underline; font-family:Verdana, Arial, "Bitstream Vera Sans", sans-serif; } .mp_button:hover {cursor:pointer;}', 
 248                  'another_button_text'        => "<span class='mp_button'>" .  esc_js(__('Attach another file', MP_TXTDOM)) . "</span>", 
 249  
 250  
 251                  'button_height'            => '24', 
 252                  'button_width'            => '132', 
 253                  'button_image_url'        => site_url() . '/' . MP_PATH . 'mp-includes/images/upload.png', 
 254                  'button_placeholder_id'        => 'flash-browse-button', 
 255  
 256                  'upload_url'             => MP_Action_url, 
 257  
 258                  'file_post_name'            => 'async-upload', 
 259                  'file_types'            => '*.*', 
 260                  'file_size_limit'            => wp_max_upload_size() . 'b', 
 261  
 262                  'post_params'            => array (
 263                                          'action'        => 'swfu_mail_attachement', 
 264                                          'auth_cookie'    => (is_ssl()) ? $_COOKIE[SECURE_AUTH_COOKIE] : $_COOKIE[AUTH_COOKIE], 
 265                                          '_wpnonce'        => wp_create_nonce('mp_attachement')
 266                                      ), 
 267  
 268                  'custom_settings'            => array (
 269                                          'degraded_element_id' => 'html-upload-ui', // id of the element displayed when swfupload is unavailable
 270                                          'swfupload_element_id'=> 'flash-upload-ui' // id of the element displayed when swfupload is available
 271                                      ), 
 272  
 273                  'debug'                => false
 274              ));
 275          echo "<script type='text/javascript'>\n/* <![CDATA[ */\n";
 276          $eol = "";
 277          foreach ( $m as $var => $val ) {
 278              echo "var $var = " . self::print_scripts_l10n_val($val);
 279              $eol = ", \n\t\t";
 280          }
 281          echo ";\n";
 282          echo "/* ]]> */\n</script>";
 283      }
 284  
 285  ////  Metaboxes  ////
 286  
 287  	public static function screen_meta() 
 288      {
 289          $id = (isset($_GET['id'])) ? $_GET['id'] : 0;
 290          add_meta_box('submitdiv',         __('Send', MP_TXTDOM),             array('MP_AdminPage', 'meta_box_submit'),         self::screen, 'side', 'core');
 291          add_meta_box('attachementsdiv',     __('Attachments', MP_TXTDOM),        array('MP_AdminPage', 'meta_box_attachements'),     self::screen, 'side', 'core');
 292  
 293          if ( current_user_can('MailPress_mail_custom_fields') )
 294              add_meta_box('customfieldsdiv',     __('Custom Fields'),         array('MP_AdminPage', 'meta_box_customfields'),     self::screen, 'normal', 'core');
 295  
 296          if ($id)
 297          {
 298              $rev_ids     = MP_Mail_meta::get($id, '_MailPress_mail_revisions');
 299          }
 300          if (isset($rev_ids) && $rev_ids)
 301              add_meta_box('revisionbox',     __('Mail Revisions', MP_TXTDOM),     array('MP_AdminPage', 'meta_box_revision'),         self::screen, 'normal', 'high');
 302  
 303          do_action('MailPress_add_meta_boxes_write', $id, self::screen);
 304  
 305          parent::screen_meta();
 306      }
 307  /**/
 308  	public static function meta_box_submit($draft) 
 309      {
 310             $datef = __( 'M j, Y @ G:i' );
 311  
 312          global $mp_general;
 313  
 314          $fromname = $draft->fromname;
 315          $fromemail= $draft->fromemail;
 316          $from = "<b>{$fromname}</b> &lt;{$fromemail}&gt;";
 317  
 318          $stamp = __('Send <b>immediately</b>', MP_TXTDOM);
 319          $date = date_i18n( $datef, strtotime( current_time('mysql') ) );
 320  
 321          $save_post_class = '';
 322          $publish_name    = 'send';
 323          $publish_value   = esc_attr(__('Send', MP_TXTDOM));
 324  
 325          if ($draft && isset($draft->id))
 326          {
 327              if (current_user_can('MailPress_delete_mails')) $delete_url = esc_url(MailPress_write  ."&amp;action=delete&amp;id=$draft->id");
 328              $preview_url= esc_url(add_query_arg( array('action' => 'iview', 'id' => $draft->id, 'preview_iframe' => 1, 'TB_iframe' => 'true'), MP_Action_url ));
 329              $preview    = "<a class='preview button' target='_blank' href='$preview_url'>" . __('Preview') . "</a>";
 330  
 331                  if ($draft->_scheduled)
 332                  {
 333                      $stamp = __('Scheduled for: <b>%1$s</b>');
 334                      $date = date_i18n( $datef, strtotime( $draft->sent ) );
 335  
 336                  $save_post_class = ' hidden';
 337                  $publish_name    = 'save';
 338                  $publish_value   = esc_attr(__('Update', MP_TXTDOM));
 339                  }
 340          } 
 341  
 342          $publish = (current_user_can('MailPress_send_mails')) ? "<input id='publish' type='submit' name='$publish_name' class='button-primary' value=\"$publish_value\" />" : '';
 343  ?>
 344  <div class="submitbox" id="submitpost">
 345      <div id="minor-publishing">
 346          <div style='display:none'></div>
 347          <div id="minor-publishing-actions">
 348              <div id='save-action'>
 349                  <input id='save-post' type='submit' name='save' class='button button-highlighted<?php echo $save_post_class; ?>' value="<?php _e('Save Draft', MP_TXTDOM); ?>"  />
 350              </div>
 351              <div id='preview-action'>
 352                  <span id='preview-button'><?php if (isset($preview)) echo $preview; ?></span>
 353              </div>
 354              <div class="clear"></div>
 355          </div>
 356  
 357          <div id="misc-publishing-actions">
 358              <div class="misc-pub-section mp_theme">
 359                  <label><?php _e('From: ', MP_TXTDOM); ?></label>
 360                  <b><span id='span_from'><?php echo $from; ?></span></b>
 361  <?php 
 362          if (current_user_can('MailPress_write_edit_fromemail'))
 363          {
 364  ?>
 365                  <a href='#edit_from' class="edit-from hide-if-no-js"><?php _e('Edit') ?></a>
 366                  <div id='fromdiv' class='hide-if-js'>
 367                      <input id='hidden_fromname'  name='hidden_fromname'  type='hidden' value="<?php echo esc_attr($fromname); ?>" />
 368                      <input id='hidden_fromemail' name='hidden_fromemail' type='hidden' value='<?php echo $fromemail; ?>' />
 369                      <?php _e('Name: ', MP_TXTDOM); ?><input type='text' size='25' id='fromname'  name='fromname'  value="<?php echo esc_attr($fromname);  ?>" /><br />
 370                      <?php _e('Email: ', MP_TXTDOM); ?><input type='text' size='25' id='fromemail' name='fromemail' value="<?php echo $fromemail; ?>" /><br />
 371                      <a href="#edit_from" class="save-from hide-if-no-js button"><?php _e('OK'); ?></a>
 372                      <a href="#edit_from" class="cancel-from hide-if-no-js"><?php _e('Cancel'); ?></a>
 373                  </div>
 374  <?php
 375          }
 376          else
 377          {
 378  ?>
 379                      <input id='fromname'  name='fromname'  type='hidden' value="<?php echo esc_attr($fromname); ?>" />
 380                      <input id='fromemail' name='fromemail' type='hidden' value='<?php echo $fromemail; ?>' />
 381  <?php
 382          }
 383  ?>
 384              </div>
 385  <?php
 386          $xthemes = array();
 387          $th = new MP_Themes();
 388          $themes = $th->themes;
 389  
 390          foreach($themes as $key => $theme)
 391          {
 392              if ( 'plaintext' == $theme['Stylesheet']) unset($themes[$key]);
 393              if ( '_' == $theme['Stylesheet'][0] )     unset($themes[$key]);
 394          }
 395  
 396          $xthemes = array('' => __('current', MP_TXTDOM));
 397          foreach ($themes as $theme) $xthemes[$theme['Stylesheet']] = $theme['Stylesheet'];
 398  
 399          $current_theme = $themes[$th->current_theme]['Stylesheet'];
 400          $theme = (isset($draft->theme)) ? $draft->theme : '';
 401  ?>
 402              <div class="misc-pub-section mp_theme">
 403                  <label><?php _e('Theme: ', MP_TXTDOM); ?></label>
 404                  <b><span id='span_theme'><?php echo $xthemes[$theme]; ?></span></b>
 405                  <a href='#edit_theme' class="edit-theme hide-if-no-js"><?php _e('Edit') ?></a>
 406                  <div id='themediv' class='hide-if-js'>
 407                      <input id='hidden_theme' name='hidden_theme' type='hidden' value='<?php echo $theme; ?>' />
 408                      <select id='theme' name='Theme'>
 409  <?php self::select_option($xthemes, $theme);?>
 410                      </select>
 411                      <a href="#edit_theme" class="save-theme hide-if-no-js button"><?php _e('OK'); ?></a>
 412                      <a href="#edit_theme" class="cancel-theme hide-if-no-js"><?php _e('Cancel'); ?></a>
 413                  </div>
 414              </div>
 415  
 416              <div class="misc-pub-section curtime misc-pub-section-last">
 417                  <span id="timestamp"><?php printf($stamp, $date); ?></span>
 418                  <a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e('Edit') ?></a>
 419                  <div id="timestampdiv" class="hide-if-js"><?php self::touch_time(4); ?></div>
 420              </div>
 421          </div>
 422  
 423          <div class="clear"><br /><br /></div>
 424      </div>
 425      <div id="major-publishing-actions">
 426          <div id="delete-action">
 427  <?php     if (isset($delete_url)) : ?>
 428              <a class='submitdelete' href='<?php echo $delete_url ?>' onclick="if (confirm('<?php echo(esc_js(sprintf( __("You are about to delete this draft '%s'\n  'Cancel' to stop, 'OK' to delete."), $draft->id ))); ?>')) return true; return false;">
 429                  <?php _e('Delete', MP_TXTDOM); ?>
 430              </a>
 431  <?php        endif; ?>
 432          </div>
 433          <div id="publishing-action">
 434              <?php echo $publish; ?>
 435          </div>
 436          <div class="clear"></div>
 437      </div>
 438  </div>
 439  <?php
 440      }
 441  
 442  	public static function touch_time( $tab_index = 0, $edit = 1, $multi = 0 ) 
 443      {
 444          global $wp_locale, $draft;
 445  
 446          $tab_index_attribute = '';
 447          if ( (int) $tab_index > 0 ) $tab_index_attribute = " tabindex=\"$tab_index\"";
 448  
 449          $time_adj = current_time('timestamp');
 450  
 451          $draft_date = ($draft->_scheduled) ? $draft->sent : date_i18n('Y-m-d H:i');
 452  
 453          $jj = ($edit) ? mysql2date( 'd', $draft_date, false ) : gmdate( 'd', $time_adj );
 454          $mm = ($edit) ? mysql2date( 'm', $draft_date, false ) : gmdate( 'm', $time_adj );
 455          $aa = ($edit) ? mysql2date( 'Y', $draft_date, false ) : gmdate( 'Y', $time_adj );
 456          $hh = ($edit) ? mysql2date( 'H', $draft_date, false ) : gmdate( 'H', $time_adj );
 457          $mn = ($edit) ? mysql2date( 'i', $draft_date, false ) : gmdate( 'i', $time_adj );
 458          $ss = ($edit) ? mysql2date( 's', $draft_date, false ) : gmdate( 's', $time_adj );
 459  
 460          $cur_jj = gmdate( 'd', $time_adj );
 461          $cur_mm = gmdate( 'm', $time_adj );
 462          $cur_aa = gmdate( 'Y', $time_adj );
 463          $cur_hh = gmdate( 'H', $time_adj );
 464          $cur_mn = gmdate( 'i', $time_adj );
 465  
 466          $month = "<select id='mm' name='mm' $tab_index_attribute >\n";
 467          for ( $i = 1; $i < 13; $i = $i +1 ) $month .= "<option value='" . zeroise($i, 2) . (( $i == $mm ) ? "' selected='selected'" : "'") . '>' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
 468          $month .= '</select>';
 469  
 470          $day    = "<input type='text' id='jj' name='jj' value='$jj' size='2' maxlength='2' $tab_index_attribute autocomplete='off' />";
 471          $year   = "<input type='text' id='aa' name='aa' value='$aa' size='4' maxlength='4' $tab_index_attribute autocomplete='off' />";
 472          $hour   = "<input type='text' id='hh' name='hh' value='$hh' size='2' maxlength='2' $tab_index_attribute autocomplete='off' />";
 473          $minute = "<input type='text' id='mn' name='mn' value='$mn' size='2' maxlength='2' $tab_index_attribute autocomplete='off' />";
 474  
 475          echo "<div class='timestamp-wrap'>";    /* translators: 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */
 476          printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute);
 477  
 478          echo "</div><input type='hidden' id='ss' name='ss' value='$ss' />";
 479  
 480          echo "\n\n";
 481          foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) 
 482          {
 483              echo "<input type='hidden' id='hidden_$timeunit' name='hidden_$timeunit' value='" . $$timeunit . "'    />\n";
 484                 $cur_timeunit = 'cur_' . $timeunit;
 485              echo "<input type='hidden' id='cur_$timeunit'    name='cur_$timeunit'    value='" . $$cur_timeunit . "' />\n";
 486          }
 487  ?>
 488  <p>
 489      <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
 490      <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js"><?php _e('Cancel'); ?></a>
 491  </p>
 492  <?php
 493  }
 494  
 495  
 496  /**/
 497  	public static function meta_box_plaintext($draft)
 498      {
 499  ?>
 500  <textarea id='plaintext' name='plaintext' cols='40' rows='1'><?php echo (isset($draft->plaintext)) ? str_replace('&', '&amp;', $draft->plaintext) : ''; ?></textarea>
 501  <div id='div_html2txt' class='hidden'>
 502      <a id='html2txt' class='button hide-if-no-js' onclick="return false;" title="<?php echo esc_attr(__('Plaintext from Html', MP_TXTDOM)); ?>" href="#">
 503          <span class="mp-media-buttons-icon"></span>
 504          <?php _e('Synchronize', MP_TXTDOM); ?> 
 505      </a>
 506  </div>
 507  <?php
 508      }
 509  /**/
 510  	public static function meta_box_revision($draft)
 511      {
 512          MP_Mail_revision::listing($draft->id);
 513      }
 514  /**/
 515  	public static function meta_box_attachements($draft) 
 516      {
 517          if ($draft) $draft_id = (isset($draft->id)) ? $draft->id : 0;
 518          if (self::flash()) 
 519          {
 520              $divid = 'flash-upload-ui';
 521              $divs  = "<div><div id='flash-browse-button'></div></div>";
 522              $url   = esc_url(add_query_arg('flash', 0));
 523              $txt   = __('homemade uploader', MP_TXTDOM);
 524          }
 525          else
 526          {
 527              $divid = 'html-upload-ui';
 528              $divs  = "<div class='mp_fileupload_txt'><span class='mp_fileupload_txt'></span></div><div class='mp_fileupload_file' id='mp_fileupload_file_div'></div>";
 529              $url   = esc_url(remove_query_arg('flash'));
 530              $txt   = __('Flash uploader', MP_TXTDOM);
 531          }
 532  ?>
 533  <script type="text/javascript">
 534  <!--
 535  var draft_id = <?php echo $draft_id; ?>;
 536  //-->
 537  </script>
 538  <div id="attachement-items">
 539  <?php     self::get_attachements_list($draft_id); ?>
 540  </div>
 541  <div><span id='attachement-errors'></span></div>
 542  
 543  <div id='<?php echo $divid; ?>'><?php echo $divs; ?>
 544      <br class="clear" />
 545      <p>
 546          <input type='hidden' name='type_of_upload' value="<?php echo $divid; ?>" />
 547          <?php printf(__('Problems?  Try the %s.', MP_TXTDOM), sprintf ("<a id='mp_loader_link' href='%1s'>%2s</a>", $url , $txt )); ?>
 548      </p>
 549  </div>
 550  <?php
 551      }
 552  
 553  	public static function get_attachements_list($draft_id)
 554      {
 555          $metas = MP_Mail_meta::has( $draft_id, '_MailPress_attached_file');
 556          if ($metas) foreach($metas as $meta) self::get_attachement_row($meta);
 557      }
 558  
 559  	public static function get_attachement_row($meta)
 560      {
 561          $meta_value = maybe_unserialize( $meta['meta_value'] );
 562          if (!is_file($meta_value['file_fullpath'])) return;
 563          $href = esc_url(add_query_arg( array('action' => 'attach_download', 'id' => $meta['meta_id']), MP_Action_url ));
 564  
 565  ?>
 566      <div id='attachement-item-<?php echo $meta['meta_id']; ?>' class='attachement-item child-of-<?php echo $meta['mp_mail_id']; ?>'>
 567          <table>
 568              <tr>
 569                  <td>
 570                      <input type='checkbox' class='mp_fileupload_cb' checked='checked' name='Files[<?php echo $meta['meta_id']; ?>]' value='<?php echo $meta['meta_id']; ?>' />
 571                  </td>
 572                  <td>&#160;<a href='<?php echo $href; ?>' style='text-decoration:none;'><?php echo $meta_value['name']; ?></a></td>
 573              </tr>
 574          </table>
 575      </div>
 576  
 577  <?php
 578      }
 579  /**/
 580  	public static function meta_box_customfields($draft)
 581      {
 582  ?>
 583  <div id='postcustomstuff'>
 584      <div id='ajax-response'></div>
 585  <?php
 586          $id = (isset($draft->id)) ? $draft->id : '';
 587          $metadata = MP_Mail_meta::has($id);
 588          $count = 0;
 589          if ( !$metadata ) : $metadata = array(); 
 590  ?>
 591      <table id='list-table' style='display: none;'>
 592          <thead>
 593              <tr>
 594                  <th class='left'><?php _e( 'Name' ); ?></th>
 595                  <th><?php _e( 'Value' ); ?></th>
 596              </tr>
 597          </thead>
 598          <tbody id='the-list' class='list:mailmeta'>
 599              <tr><td></td><td></td></tr>
 600          </tbody>
 601      </table>
 602  <?php else : ?>
 603      <table id='list-table'>
 604          <thead>
 605              <tr>
 606                  <th class='left'><?php _e( 'Name' ) ?></th>
 607                  <th><?php _e( 'Value' ) ?></th>
 608              </tr>
 609          </thead>
 610          <tbody id='the-list' class='list:mailmeta'>
 611  <?php foreach ( $metadata as $entry ) echo self::meta_box_customfield_row( $entry, $count ); ?>
 612          </tbody>
 613      </table>
 614  <?php endif; ?>
 615  <?php
 616          global $wpdb;
 617          $keys = $wpdb->get_col( "SELECT meta_key FROM $wpdb->mp_mailmeta GROUP BY meta_key ORDER BY meta_key ASC LIMIT 30" );
 618          foreach ($keys as $k => $v)
 619          {
 620              if ($keys[$k][0] == '_') unset($keys[$k]);
 621              if ('batch_send' == $v)  unset($keys[$k]);
 622          }
 623  ?>
 624      <p>
 625          <strong>
 626              <?php _e( 'Add New Custom Field:' ) ?>
 627          </strong>
 628      </p>
 629      <table id='newmeta'>
 630          <thead>
 631              <tr>
 632                  <th class='left'>
 633                      <label>
 634                          <?php _e( 'Name' ) ?>
 635                      </label>
 636                  </th>
 637                  <th>
 638                      <label>
 639                          <?php _e( 'Value' ) ?>
 640                      </label>
 641                  </th>
 642              </tr>
 643          </thead>
 644          <tbody>
 645              <tr>
 646                  <td id='newmetaleft' class='left'>
 647  <?php 
 648          if ( $keys ) 
 649          { 
 650  ?>
 651                      <select id='metakeyselect' name='metakeyselect' tabindex='7'>
 652                          <option value="#NONE#"><?php _e( '- Select -' ); ?></option>
 653  <?php
 654              foreach ( $keys as $key ) 
 655              {
 656                  $key = esc_attr($key);
 657                  echo "\n<option value=\"$key\">$key</option>";
 658              }
 659  ?>
 660                      </select>
 661                      <input class='hide-if-js' type='text' id='metakeyinput' name='metakeyinput' tabindex='7' value='' />
 662                      <a href='#postcustomstuff' class='hide-if-no-js' onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
 663                      <span id='enternew'><?php _e('Enter new'); ?></span>
 664                      <span id='cancelnew' class='hidden'><?php _e('Cancel'); ?></span></a>
 665  <?php 
 666          } 
 667          else 
 668          { 
 669  ?>
 670                      <input type='text' id='metakeyinput' name='metakeyinput' tabindex='7' value='' />
 671  <?php 
 672          } 
 673  ?>
 674                  </td>
 675                  <td>
 676                      <textarea id='metavalue' name='metavalue' rows='2' cols='25' tabindex='8'></textarea>
 677                  </td>
 678              </tr>
 679              <tr>
 680                  <td colspan='2'>
 681                      <div class='submit'>
 682                          <input type='submit' id='addmetasub' name='addmailmeta' class='add:the-list:newmeta button' tabindex='9' value="<?php _e( 'Add Custom Field' ) ?>" />
 683                          <?php wp_nonce_field( 'add-mailmeta', '_ajax_nonce', false ); ?>
 684                      </div>
 685                  </td>
 686              </tr>
 687          </tbody>
 688      </table>
 689  </div>
 690  <p><?php _e('Custom fields can be used to add extra metadata to a mail that you can <a href="http://www.mailpress.org" target="_blank">use in your mail</a>.', MP_TXTDOM); ?></p>
 691  <?php
 692      }
 693  
 694  	public static function meta_box_customfield_row( $entry, &$count )
 695      {
 696          if ('_' == $entry['meta_key'] { 0 } ) return;
 697  
 698          static $update_nonce = false;
 699          if ( !$update_nonce ) $update_nonce = wp_create_nonce( 'add-mailmeta' );
 700  
 701          $r = '';
 702          ++ $count;
 703  
 704          if ( $count % 2 )    $style = 'alternate';
 705          else            $style = '';
 706      
 707          $entry['meta_key']     = esc_attr($entry['meta_key']);
 708          $entry['meta_value']     = esc_attr($entry['meta_value']); // using a <textarea />
 709          $entry['meta_id']     = (int) $entry['meta_id'];
 710  
 711          $delete_nonce         = wp_create_nonce( 'delete-mailmeta_' . $entry['meta_id'] );
 712  
 713          $r .= "
 714              <tr id='mailmeta-{$entry['meta_id']}' class='$style'>
 715                  <td class='left'>
 716                      <label class='hidden' for='mailmeta[{$entry['meta_id']}][key]'>
 717  " . __( 'Key' ) . "
 718                      </label>
 719                      <input name='mailmeta[{$entry['meta_id']}][key]' id='mailmeta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value=\"" . esc_attr($entry['meta_key']) . "\" />
 720                      <div class='submit'>
 721                          <input name='deletemailmeta[{$entry['meta_id']}]' type='submit' class='delete:the-list:mailmeta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemailmeta button' tabindex='6' value='" . esc_attr(__( 'Delete' )) . "' />
 722                          <input name='updatemailmeta' type='submit' tabindex='6' value='" . esc_attr(__( 'Update' )) . "' class='add:the-list:mailmeta-{$entry['meta_id']}::_ajax_nonce=$update_nonce updatemailmeta button' />
 723                      </div>
 724  " . wp_nonce_field( 'change-mailmeta', '_ajax_nonce', false, false ) . "
 725                  </td>
 726                  <td>
 727                      <label class='hidden' for='mailmeta[{$entry['meta_id']}][value]'>
 728  " . __( 'Value' ) . "
 729                      </label>
 730                      <textarea name='mailmeta[{$entry['meta_id']}][value]' id='mailmeta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>" . esc_attr($entry['meta_value']) . "</textarea>
 731                  </td>
 732              </tr>
 733              ";
 734      return $r;
 735      }
 736  
 737  	public static function select_optgroup($list, $selected, $echo = true)
 738      {
 739          foreach( $list as $value => $label )
 740          {
 741              $_selected = (!is_array($selected)) ? $selected : ( (in_array($value, $selected)) ? $value : null );
 742              $list[$value] = "<option " . self::selected( (string) $value, (string) $_selected, false, false ) . " value=\"" . esc_attr($value) . "\">$label</option>";
 743          }
 744  
 745          $opened = false;
 746  
 747          foreach( $list as $value => $html )
 748          {
 749              if (empty($value)) continue;
 750              switch (true)
 751              {
 752                  case (in_array($value , array('2', '3'))) :
 753                      $optgroup = 'MailPress_comment';
 754                  break;
 755                  case (is_numeric($value)) :
 756                      $optgroup = 'MP_User';
 757                  break;
 758                  default :
 759                      $optgroup = ($pos = strpos($value, '~')) ? substr($value, 0, $pos) : null;
 760                  break;
 761              }
 762              if (isset($$optgroup)) continue;
 763              $list[$value] = (($opened) ? '</optgroup>' : '') . '<optgroup label=\'' . apply_filters('MailPress_mailinglists_optgroup', __('(unknown)', MP_TXTDOM), $optgroup) . '\'>' . $html;
 764              $opened = $$optgroup = true;
 765          }
 766  
 767          $x = implode('', $list) . (($opened) ? '</optgroup>' : '');
 768  
 769          if (!$echo) return "\n$x\n";
 770          echo "\n$x\n";
 771      }
 772  }


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