[ Index ]

MailPress 7.1

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

title

Body

[close]

/mp-content/add-ons/ -> MailPress_newsletter.php (source)

   1  <?php
   2  if ( class_exists( 'MailPress' ) && !class_exists( 'MailPress_newsletter' ) )
   3  {
   4  /*
   5  Plugin Name: MailPress_newsletter
   6  Plugin URI: http://blog.mailpress.org/tutorials/add-ons/newsletter/
   7  Description: Newsletters : for posts
   8  Version: 7.1
   9  */
  10  
  11  class MailPress_newsletter
  12  {
  13      const meta_key = '_MailPress_newsletter';
  14      const log_name = 'newsletter';
  15      const option_post_limits    = 'MailPress_post_limits_newsletter';
  16      const option_name_default   = 'MailPress_default_newsletter';
  17  
  18  	function __construct()
  19      {
  20  // for wordpress hooks
  21  // for plugin
  22          add_action( 'init',     array( __CLASS__, 'init' ), 99 );
  23  
  24  // register form
  25          add_action( 'user_register',             array( __CLASS__, 'user_register' ), 10, 1 );
  26          add_action( 'MailPress_register_form',     array( __CLASS__, 'register_form' ), 10 );
  27  
  28  // for shortcode
  29          add_filter( 'MailPress_form_defaults',     array( __CLASS__, 'form_defaults' ), 8, 1 );
  30          add_filter( 'MailPress_form_options',     array( __CLASS__, 'form_options' ), 8, 1 );
  31          add_filter( 'MailPress_form_submit',         array( __CLASS__, 'form_submit' ), 8, 2 );
  32          add_action( 'MailPress_form',               array( __CLASS__, 'form' ), 1, 2 );
  33  
  34  // for newsletter
  35          add_action( 'MailPress_register_newsletter',array( __CLASS__, 'register' ), 1 );
  36  
  37  // for scheduling and processing newsletters
  38          add_action( 'mp_schedule_newsletters',     array( __CLASS__, 'schedule' ), 8, 1 );
  39          add_action( 'mp_process_newsletter',         array( __CLASS__, 'process' ) );
  40          add_action( 'mp_process_post_newsletter',     array( __CLASS__, 'process' ) );
  41  
  42  // for sending mails
  43          add_filter( 'MailPress_mailinglists_optgroup',     array( __CLASS__, 'mailinglists_optgroup' ), 50, 2 );
  44          add_filter( 'MailPress_mailinglists',             array( __CLASS__, 'mailinglists' ), 50, 1 );
  45          add_filter( 'MailPress_query_mailinglist',         array( __CLASS__, 'query_mailinglist' ), 50, 2 );
  46  
  47  // for sync wordpress user
  48          add_filter( 'MailPress_has_subscriptions', array( __CLASS__, 'has_subscriptions' ), 8, 2 );
  49          add_action( 'MailPress_sync_subscriptions',array( __CLASS__, 'sync_subscriptions' ), 8, 2 );    
  50  
  51  // for wp admin
  52          if ( is_admin() )
  53          {
  54          // install
  55              register_activation_hook(  plugin_basename( __FILE__ ), array( __CLASS__, 'install' ) );
  56              register_deactivation_hook( plugin_basename( __FILE__ ), array( __CLASS__, 'uninstall' ) );
  57          // for link on plugin page
  58              add_filter( 'plugin_action_links',             array( __CLASS__, 'plugin_action_links' ), 10, 2 );
  59          // for role & capabilities
  60              add_filter( 'MailPress_capabilities',         array( __CLASS__, 'capabilities' ), 1, 1 );
  61          // for settings
  62              add_filter( 'MailPress_scripts',                    array( __CLASS__, 'scripts' ), 8, 2 );
  63              add_filter( 'MailPress_settings_tab',         array( __CLASS__, 'settings_tab' ), 10, 1 );
  64          // for settings subscriptions
  65              add_filter( 'MailPress_settings_subscriptions_help',    array( __CLASS__, 'settings_subscriptions_help' ), 20, 1 );
  66              add_action( 'MailPress_settings_subscriptions_form',    array( __CLASS__, 'settings_subscriptions_form'), 20 );
  67          // for settings logs
  68              add_action( 'MailPress_settings_logs_form',         array( __CLASS__, 'settings_logs_form' ), 50 );
  69          // for meta box in user page
  70              if ( current_user_can( 'MailPress_manage_newsletters' ) )
  71              {
  72                  add_action( 'MailPress_add_help_tab_user',        array( __CLASS__, 'add_help_tab_user' ), 20 );
  73                  add_action( 'MailPress_update_meta_boxes_user',    array( __CLASS__, 'update_meta_boxes_user' ) );
  74                  add_action( 'MailPress_add_meta_boxes_user',     array( __CLASS__, 'add_meta_boxes_user' ), 20, 2 );
  75              }
  76          // for meta box in write post
  77              if ( current_user_can( 'MailPress_test_newsletters' ) )
  78                  add_action( 'do_meta_boxes',                 array( __CLASS__, 'add_meta_boxes_post' ), 8, 3 );
  79          }
  80  
  81  // for mp_users list
  82          add_action( 'MailPress_users_restrict',     array( __CLASS__, 'users_restrict' ), 9, 1 );
  83          add_filter( 'MailPress_users_columns',     array( __CLASS__, 'users_columns' ), 10, 1 );
  84          add_action( 'MailPress_users_get_list',     array( __CLASS__, 'users_get_list' ), 10, 2 );
  85          add_filter( 'MailPress_users_get_row',     array( __CLASS__, 'users_get_row' ), 10, 4 );
  86  
  87  // for ajax
  88          add_action( 'mp_action_mp_meta_box_post_test',     array( __CLASS__, 'mp_action_mp_meta_box_post_test' ) );
  89      }
  90  
  91  //// Subscriptions ////
  92  
  93  	public static function get_checklist( $mp_user_id = false, $args = '' ) 
  94      {
  95          global $mp_subscriptions;
  96          if ( !isset( $mp_subscriptions['newsletters'] ) ) return false;
  97          if ( empty( $mp_subscriptions['newsletters'] ) ) return false;
  98  
  99          $checklist = '';
 100          $defaults = array (     'htmlname'     => 'keep_newsletters',
 101                          'admin'         => 0, 
 102                          'selected'     => false, 
 103                          'type'        => 'checkbox',
 104                          'show_option_all'  => false, 
 105                             'htmlstart'    => '', 
 106                          'htmlmiddle'    => '&#160;&#160;', 
 107                          'htmlend'        => "<br />\n"
 108                       );
 109          $r = wp_parse_args( $args, $defaults );
 110          extract( $r );
 111  
 112          $lib_nl = ( $admin ) ? 'admin' : 'blog';
 113  
 114          if ( $mp_user_id )     $in = MP_Newsletter::get_object_terms( $mp_user_id );
 115          else                $in = MP_Newsletter::get_defaults();
 116  
 117          global $mp_registered_newsletters;
 118          $nls = MP_Newsletter::get_active();
 119  
 120          foreach ( $nls as $k => $v )
 121          {
 122              if ( $mp_registered_newsletters[$k]['descriptions'][$lib_nl] )
 123                  switch ( $type )
 124                  {
 125                      case 'checkbox' :
 126                          $checked = checked( isset( $in[$k] ), true, false );
 127                          $_type   = 'checkbox';
 128  
 129                          $v         = $mp_registered_newsletters[$k]['descriptions'][$lib_nl];
 130  
 131                          $tag          = '<input type="' . $_type . '" name="' . $htmlname . '[' . $k . ']" id="' . $htmlname . '_' . $k . '"'. $checked . ' />';
 132                          $htmlstart2  = str_replace( '{{id}}', "{$htmlname}_{$k}", $htmlstart );
 133                          $htmlmiddle2 = $htmlmiddle . str_replace( '&#160;', '', $v );
 134                          $htmlend2    = $htmlend;
 135  
 136                          $checklist .= "$htmlstart2$tag$htmlmiddle2$htmlend2";
 137                      break;
 138                      case 'select' :
 139                          if ( $show_option_all )
 140                          {
 141                              $checklist .= '<option value="">' . $show_option_all . '</option>';
 142                              $show_option_all = false;
 143                          }
 144                          $sel = ( $k == $selected ) ? ' selected="selected"' : '';
 145                          $checklist .= '<option value="' . $k . '"' . $sel . '>' . $mp_registered_newsletters[$k]['descriptions'][$lib_nl] . '</option>';
 146                      break;
 147                  }
 148          }
 149  //        if ( 'select' == $type ) $checklist = $htmlstart . '<select name="' . $htmlname . '">' . $checklist . '</select>' . $htmlend;
 150          $htmlid = ( isset( $htmlid ) ) ? ' id="' . $htmlid . '"' : ''; 
 151          if ( 'select' == $type ) $checklist = $htmlstart . '<select name="' . $htmlname . '"' . $htmlid . '>' . $checklist . '</select>' . $htmlend;
 152  
 153          return $checklist;
 154      }
 155  
 156  	public static function update_checklist( $mp_user_id, $name = 'keep_newsletters' ) 
 157      {
 158          $post_ = filter_input_array( INPUT_POST );
 159  
 160          MP_Newsletter::set_object_terms( $mp_user_id, $post_[$name] );
 161      }
 162  
 163  	public static function get_subscriptions( $id ) 
 164      {
 165          global $mp_subscriptions;
 166          if ( !isset( $mp_subscriptions['newsletters'] ) ) return false;
 167          if ( empty( $mp_subscriptions['newsletters'] ) ) return false;
 168  
 169          $mp_user_nls = MP_Newsletter::get_object_terms( $id );
 170  
 171          if ( empty( $mp_user_nls ) ) return false;
 172  
 173          return $mp_user_nls;
 174      }
 175  
 176  //// Plugin ////
 177  
 178  	public static function init()
 179      {
 180          do_action( 'MailPress_register_newsletter' );
 181          do_action( 'MailPress_registered_newsletters' );
 182  
 183          new MP_Newsletter_schedulers();
 184      }
 185  
 186  //// Register form ////
 187  
 188  	public static function user_register( $wp_user_id )
 189      {
 190          $post_ = filter_input_array( INPUT_POST );
 191  
 192          $user     = get_userdata( $wp_user_id );
 193          $email     = $user->user_email;
 194          $mp_user_id= MP_User::get_id_by_email( $email );
 195                  
 196          if( !isset( $post_['keep_newsletters'] ) ) $post_['keep_newsletters'] = MP_Newsletter::get_defaults();
 197  
 198          self::update_checklist( $mp_user_id );
 199      }
 200  
 201  	public static function register_form()
 202      {
 203          $checklist_newsletters = self::get_checklist();
 204          if ( empty( $checklist_newsletters ) ) return;
 205  
 206          $out  = '    <br />' . "\r\n";
 207          $out .= '    <p>' . "\r\n";
 208          $out .= '        <label>' . "\r\n";
 209          $out .= __( 'Newsletters', 'MailPress' ) . "\r\n";
 210          $out .= '            <br />' . "\r\n";
 211          $out .= '            <span style="color:#777;font-weight:normal;">' . "\r\n";
 212          $out .= $checklist_newsletters . "\r\n";
 213          $out .= '            </span>' . "\r\n";
 214          $out .= '        </label>' . "\r\n";
 215          $out .= '    </p>' . "\r\n";
 216  
 217          echo $out;
 218      }
 219  
 220  //// Shortcode ////
 221  
 222  	public static function form_defaults( $x ) { $x['newsletter'] = false; return $x; }
 223  
 224  	public static function form_options( $x )  { return $x; }
 225  
 226  	public static function form_submit( $shortcode_message, $email )  
 227      {
 228          $post_ = filter_input_array( INPUT_POST );
 229  
 230          if ( !isset( $post_['newsletter'] ) )    return $shortcode_message;
 231          if ( !$post_['newsletter'] )         return $shortcode_message;
 232          $shortcode = 'shortcode_newsletters';
 233  
 234          $mp_user_id = MP_User::get_id_by_email( $email );
 235          $post_[$shortcode] = MP_Newsletter::get_object_terms( $mp_user_id );
 236  
 237          $post_[$shortcode] = array_flip( array_map( trim, explode( ',', $post_['newsletter'] ) ) );
 238  
 239          self::update_checklist( $mp_user_id, $shortcode );
 240  
 241          return $shortcode_message . __( '<br />Newsletters added', 'MailPress' );
 242      }
 243  
 244  	public static function form( $email, $options )  
 245      {
 246          if ( !$options['newsletter'] ) return;
 247  
 248          global $mp_registered_newsletters;
 249          $x = array();
 250          foreach ( array_map( trim, explode( ',', $options['newsletter'] ) ) as $k => $v ) if ( isset( $mp_registered_newsletters[$v] ) && $mp_registered_newsletters[$v]['allowed'] ) $x[] = $v;
 251          if ( empty( $x ) ) return;
 252  
 253          echo '<input type="hidden" name="newsletter" value="' . join( ', ', $x ) . '" />';
 254      }
 255  
 256  ////  Newsletter  ////
 257  
 258  	public static function register() 
 259      {
 260          $advanced_path = 'advanced/' . get_current_blog_id() . '/newsletters/post';
 261          $args = array(     'root'         => MP_UPL_ABSPATH . $advanced_path,
 262                      'root_filter'     => 'MailPress_advanced_newsletters_root',
 263                      'files'        => array( 'post', 'daily', 'weekly', 'monthly' ),
 264  
 265                      'post_type'    => 'post',
 266           );
 267  
 268          MP_Newsletter::register_files( $args );
 269      }
 270  
 271  //// Scheduling & Processing  ////
 272  
 273  	public static function schedule( $args = array() )
 274      {
 275          extract( $args );
 276  
 277          wp_unschedule_hook( 'mp_process_newsletter' );
 278          MP_Newsletter_schedulers::schedule( $event );
 279      }
 280  
 281  	public static function process( $args )
 282      {
 283          extract( $args );
 284  
 285          new MP_Newsletter_processors();
 286  
 287          MP_Newsletter_processors::process( $newsletter );
 288      }
 289  
 290  //// Sending Mails ////
 291  
 292  	public static function mailinglists_optgroup( $label, $optgroup ) 
 293      {
 294          if ( __CLASS__ == $optgroup ) return __( 'Newsletters', 'MailPress' );
 295          return $label;
 296      }
 297  
 298  	public static function mailinglists( $draft_dest = array() )
 299      {
 300          $x = MP_Newsletter::get_active();
 301          foreach ( $x as $k => $v ) $draft_dest[__CLASS__ . '~' . $k] = $v;
 302          return $draft_dest;
 303      }
 304  
 305  	public static function query_mailinglist( $query, $draft_toemail )
 306      {
 307          if ( $query ) return $query;
 308  
 309          $id = str_replace( __CLASS__ . '~', '', $draft_toemail, $count );
 310          if ( 0 == $count ) return $query;
 311          if ( empty( $id ) ) return $query;
 312  
 313          global $mp_registered_newsletters;
 314          if ( !isset( $mp_registered_newsletters[$id] ) ) return $query;
 315  
 316          $in = ( $mp_registered_newsletters[$id]['default'] ) ? 'NOT' : '';
 317  
 318          return MP_Newsletter::get_query_newsletter( $id, $in );
 319      }
 320  
 321  // Sync wordpress user
 322  
 323  	public static function has_subscriptions( $has, $mp_user_id )
 324      {
 325          $x = MP_Newsletter::get_object_terms( $mp_user_id );
 326  
 327          if ( empty( $x ) ) return $has;
 328          return true;
 329      }
 330  
 331  	public static function sync_subscriptions( $oldid, $newid )
 332      {
 333          $old = MP_Newsletter::get_object_terms( $oldid );
 334          if ( empty( $old ) ) return;
 335          $new = MP_Newsletter::get_object_terms( $newid );
 336  
 337          MP_Newsletter::set_object_terms( $newid, array_merge( $old, $new ) );
 338      }
 339  
 340  ////  ADMIN  ////
 341  ////  ADMIN  ////
 342  ////  ADMIN  ////
 343  ////  ADMIN  ////
 344  
 345  // install
 346  	public static function install() 
 347      {
 348          self::uninstall();
 349  
 350          MP_Log::set_option( self::log_name );
 351  
 352          include  ( MP_ABSPATH . 'mp-admin/includes/install/newsletter.php' );
 353  
 354          $now4cron = current_time( 'timestamp', 'gmt' );
 355          wp_schedule_single_event( $now4cron - 1, 'mp_schedule_newsletters', array( 'args' => array( 'event' => '** Install **' ) ) );
 356  
 357          $twicedaily = gmmktime( 0, 0, 0, gmdate( 'n', $now4cron ), gmdate( 'j', $now4cron ), gmdate( 'Y', $now4cron ) ) - get_option( 'gmt_offset' ) * 3600;
 358          wp_schedule_event( $twicedaily, 'twicedaily', 'mp_schedule_newsletters', array( 'args' => array( 'event' => '** Twice daily **' ) ) );
 359      }
 360  
 361  	public static function uninstall() 
 362      {
 363          wp_unschedule_hook( 'mp_process_newsletter' );
 364          wp_unschedule_hook( 'mp_schedule_newsletters' );
 365      }
 366  
 367  // for link on plugin page
 368  	public static function plugin_action_links( $links, $file )
 369      {
 370          return MailPress::plugin_links( $links, $file, plugin_basename( __FILE__ ), 'subscriptions' );
 371      }
 372  
 373  // for role & capabilities
 374  	public static function capabilities( $capabilities ) 
 375      {
 376          $capabilities['MailPress_manage_newsletters'] = array(     'name'  => __( 'Newsletters', 'MailPress' ), 
 377                                                  'group' => 'users'
 378                                           );
 379          $capabilities['MailPress_test_newsletters'] = array(     'name'  => __( 'Post test', 'MailPress' ), 
 380                                                  'group' => 'admin'
 381                                           );
 382          return $capabilities;
 383      }
 384  
 385  // for settings
 386  
 387  	public static function get_post_limits()
 388      {
 389          global $mp_general;
 390  
 391          if ( isset( $mp_general['post_limits'] ) )
 392          {
 393              $pl = $mp_general['post_limits'];
 394              update_option( self::option_post_limits, $mp_general['post_limits'] );
 395              unset( $mp_general['post_limits'] );
 396              update_option( MailPress::option_name_general, $mp_general );
 397              return $pl;
 398          }
 399  
 400          return get_option( self::option_post_limits );
 401      }
 402  
 403  	public static function scripts( $scripts, $screen ) 
 404      {
 405          if ( $screen != MailPress_page_settings ) return $scripts;
 406  
 407          wp_register_script( 'mp-newsletter',     '/' . MP_PATH . 'mp-admin/js/settings_newsletter.js', array(), false, 1 );
 408          $scripts[] = 'mp-newsletter';
 409          return $scripts;
 410      }
 411  
 412  	public static function settings_tab( $tabs )
 413      {
 414          $tabs['subscriptions'] = __( 'Subscriptions', 'MailPress' );
 415          return $tabs;
 416      }
 417  
 418  // for settings subscriptions
 419  	public static function settings_subscriptions_help( $content )
 420      {
 421          include  ( MP_ABSPATH . 'mp-admin/includes/settings/subscriptions/newsletter/help.php' );
 422          return $content;
 423      }
 424  
 425  	public static function settings_subscriptions_form()
 426      {
 427          include  ( MP_ABSPATH . 'mp-admin/includes/settings/subscriptions/newsletter/form.php' );
 428      }
 429  
 430  // for settings logs
 431  	public static function settings_logs_form( $logs )
 432      {
 433          MP_AdminPage::logs_sub_form( self::log_name, $logs, __( 'Newsletter', 'MailPress' ) );
 434      }
 435  
 436  // for meta box in user page
 437  	public static function add_help_tab_user()
 438      {
 439          global $current_screen;
 440  
 441          $content = '';
 442          $content .= '<p><strong>' . __( 'Newsletters :', 'MailPress' ) . '</strong></p>';
 443          $content .= '<p>' . __( 'You can modify newsletters subscriptions for a mp user.', 'MailPress' ) . '</p>';
 444  
 445          $current_screen->add_help_tab( array(     'id'        => 'newsletters',
 446                                          'title'    => __( 'Newsletters', 'MailPress' ),
 447                                          'content'    => $content )
 448          );
 449      }
 450  
 451  	public static function update_meta_boxes_user() 
 452      {
 453          if ( !isset( MP_AdminPage::$pst_['id'] ) ) return;
 454          if ( !isset( MP_AdminPage::$pst_['keep_newsletters'] ) ) MP_AdminPage::$pst_['keep_newsletters'] = array();
 455  
 456          self::update_checklist( MP_AdminPage::$pst_['id'] );
 457      }
 458  
 459  	public static function add_meta_boxes_user( $mp_user_id, $screen )
 460      {
 461          add_meta_box( 'newsletterdiv', __( 'Newsletters', 'MailPress' ), array( __CLASS__, 'meta_box' ), $screen, 'normal', 'core' );
 462      }
 463  
 464  	public static function meta_box( $mp_user )
 465      { 
 466          $check_newsletters = self::get_checklist( $mp_user->id, array( 'admin' => true ) );
 467          echo ( $check_newsletters ) ? $check_newsletters : __( 'Nothing to subscribe for ...', 'MailPress' ) . ' <a href="' . MailPress_settings . '&amp;tab=subscriptions">' . __( 'Settings' ) . '</a>';
 468      }
 469  
 470  // for meta box in write post  ////
 471  	public static function add_meta_boxes_post( $page, $type, $post )
 472      {
 473          if ( 'post' != $page ) return;
 474          if ( 'side' != $type ) return;
 475  
 476          wp_register_style( 'mp-meta-box-post-test',     '/' . MP_PATH . 'mp-admin/css/mp-meta-box-post-test.css' );
 477          wp_enqueue_style( 'mp-meta-box-post-test' );
 478  
 479          wp_register_script( 'mp-meta-box-post-test',     '/' . MP_PATH . 'mp-includes/js/meta_boxes/post/test.js', array( 'wp-ajax-response' ), false, 1 );
 480          wp_enqueue_script( 'mp-meta-box-post-test' );
 481  
 482          wp_register_script( 'mp-thickbox',         '/' . MP_PATH . 'mp-includes/js/mp_thickbox.js', array( 'thickbox' ), false, 1 );
 483          wp_enqueue_script( 'mp-thickbox' );
 484  
 485          add_meta_box( 'MailPress_post_test_div', __( 'MailPress test', 'MailPress' ), array( __CLASS__, 'meta_box_post_test' ), 'post', 'side', 'core' );
 486      }
 487  
 488  	public static function meta_box_post_test( $post ) 
 489      {
 490          include  ( MP_ABSPATH . 'mp-includes/meta_boxes/post/test.php' );
 491      }
 492  
 493  
 494  //// Mp_users list  ////
 495  
 496  	public static function users_restrict( $url_parms )
 497      {
 498          $x = ( isset( $url_parms['newsletter'] ) ) ? $url_parms['newsletter'] : '';
 499          $dropdown_options = array( 'show_option_all' => __( 'View all newsletters', 'MailPress' ), 'selected' => $x );
 500          self::dropdown( $dropdown_options );
 501      }
 502  
 503  	public static function users_columns( $x )
 504      {
 505          $date = array_pop( $x );
 506          $x['newsletters']=  __( 'Newsletters', 'MailPress' );
 507          $x['date']        = $date;
 508          return $x;
 509      }
 510  
 511  	public static function users_get_list( $array, $url_parms )
 512      {
 513          if ( !isset( $url_parms['newsletter'] ) || empty( $url_parms['newsletter'] ) ) return $array;
 514  
 515          global $mp_registered_newsletters;
 516          global $wpdb;
 517  
 518          if ( !isset( $mp_registered_newsletters[$url_parms['newsletter']] ) ) return $array;
 519  
 520          list( $where, $tables ) = $array;
 521  
 522          $newsletter = $mp_registered_newsletters[$url_parms['newsletter']];
 523          $in     = ( $newsletter['default'] ) ? 'NOT' : '';
 524  
 525          $where .= " AND $in EXISTS 	( 
 526                      SELECT DISTINCT z.mp_user_id
 527                      FROM     $wpdb->mp_usermeta z
 528                      WHERE z.meta_key = '" . self::meta_key . "'
 529                      AND     z.meta_value = '" . $newsletter['id'] . "'
 530                      AND     z.mp_user_id = a.id
 531                   ) ";
 532  
 533          return array( $where, $tables, true );
 534      }
 535  
 536  	public static function users_get_row( $out, $column_name, $mp_user, $url_parms )
 537      {
 538          if ( 'newsletters' == $column_name )
 539          {
 540              $o = array();
 541  
 542              $newsletters = MP_Newsletter::get_object_terms( $mp_user->id );
 543              if ( !empty( $newsletters ) )
 544              {
 545                  foreach( $newsletters as $k => $v )
 546                  {
 547                      $o[] = '<a href="' . add_query_arg( 'newsletter', $k, MailPress_users ) . '">' . $v . '</a>';
 548                  }
 549                  $out .= join( ', ', $o );
 550              }
 551              else
 552              {
 553                  $out .= __( 'None ', 'MailPress' );
 554              }
 555          }
 556          return $out;
 557      }
 558  
 559  	public static function dropdown( $args = '' )
 560      {
 561          $defaults = array( 'class'        => 'postform',
 562                      'echo'         => 1,
 563                      'htmlid'        => 'newsletter_dropdown',
 564                      'htmlname'     => 'newsletter',
 565                      'selected'     => 0
 566                       );
 567  
 568          $r = wp_parse_args( $args, $defaults );
 569          extract( $r );
 570  
 571          $x = MP_Newsletter::get_active();
 572  
 573          $output = '';
 574          if ( ! empty( $x ) )
 575          {
 576              if ( $show_option_all ) $list[0] = $show_option_all;
 577              foreach( $x as $k => $v ) $list[$k] = $v;
 578  
 579              $htmlid = ( $htmlid === true ) ? 'id="' . $htmlname . '"' : 'id="' . $htmlid . '"' ;
 580              $output = '<select name="' . $htmlname . '" ' . $htmlid . ' class="' . $class . '">';
 581              $output .= MP_::select_option( $list, $selected, false );
 582              $output .= '</select>' . "\n";
 583          }
 584  
 585          if ( $echo )    echo $output;
 586  
 587          return $output;
 588      }
 589  
 590  // for ajax
 591  	public static function mp_action_mp_meta_box_post_test() 
 592      {
 593          global $mp_registered_newsletters;
 594  
 595          $post_ = filter_input_array( INPUT_POST );
 596  
 597          $post_id = $post_['post_id'];
 598          if ( empty( $post_id ) )            return new WP_Error( 'post', __( 'post not saved', 'MailPress' ) );
 599          $post = get_post( $post_id );
 600          if ( !$post )                    return new WP_Error( 'post', __( 'post not saved', 'MailPress' ) );
 601  
 602          $newsletter = MP_Newsletter::get( $post_['newsletter'] );
 603          if ( !$newsletter )                return new WP_Error( 'newsletter', __( 'unknown newsletter', 'MailPress' ) );
 604  
 605          $theme = $post_['theme'];
 606          if ( empty( $theme ) && isset( $newsletter['mail']['Theme'] ) ) $theme = $newsletter['mail']['Theme'];
 607  
 608          update_user_meta( MP_WP_User::get_id(), "_MailPress_post_$post_id", array( 'toemail' => $post_['toemail'], 'theme' => $theme, 'newsletter' => $post_['newsletter'] ) );    
 609  
 610          $newsletter['mail']['Theme']         = $theme;
 611          $newsletter['mail']['subject']    = __( '(Test)', 'MailPress' ) . ' ' . $newsletter['mail']['subject'];
 612          $newsletter['mail']['the_title']     = apply_filters( 'the_title', $post->post_title );
 613  
 614          $newsletter['query_posts']     = array( 'p'    =>    $post_id );
 615  
 616          $mail            = new stdClass();
 617          $mail->id        = MP_Mail::get_id( 'send_post_ajax' );
 618          $mail->toemail     = $post_['toemail'];
 619  
 620          $rc = MP_Newsletter::send( $newsletter, false, $mail );
 621  
 622          if ( !$rc ) MP_Mail::delete( $mail->id );
 623                  
 624          $args = array( 'id' => $mail->id, 'action' => 'mp_ajax', 'mp_action' => 'iview', 'TB_iframe' => 'true' );
 625          $view_url = esc_url( add_query_arg( $args, admin_url( 'admin-ajax.php' ) ) );
 626  
 627          $x = new WP_Ajax_Response( array    ( 
 628                          'what' => 'mp_post_test', 
 629                          'id' => $mail->id, 
 630                          'data' => !$rc ? __( 'Sending mail failed !', 'MailPress' ) : sprintf( '<span id="mail-%1$s">%2$s</span>', $mail->id , sprintf( __( '%1$sView%2$s sent mail', 'MailPress' ), sprintf( '<a href="%1$s" class="thickbox thickbox-preview">', $view_url ), '</a>' ) )
 631                           )
 632           );
 633          $x->send();
 634      }
 635  }
 636  new MailPress_newsletter();
 637  }


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