[ Index ]

MailPress 7.2

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_WP_Admin_page_
   3  {
   4      const screen        = MailPress_page_settings;
   5      const capability    = 'MailPress_manage_options';
   6      const help_url        = 'http://blog.mailpress.org/tutorials/';
   7      const file            = __FILE__;
   8  
   9      public static $first = true;
  10  
  11      public static $err_mess = array();
  12  
  13  //// Help ////
  14  
  15  	public static function add_help_tab() 
  16      {
  17          global $current_screen;
  18  
  19          $_tabs = self::get_tabs();
  20  
  21          foreach( $_tabs as $_tab => $desc )
  22          {
  23              $content = '';
  24  
  25              $file = 'includes/settings/' . $_tab . '/help.php';
  26              include( $file );
  27  
  28              $current_screen->add_help_tab( array( 'id' => $_tab, 'title' => $desc, 'content' => $content ) );
  29          }
  30      }
  31  
  32  ////  Styles  ////
  33  
  34  	public static function print_styles( $s ) 
  35      {
  36          $styles = ( is_array( $s ) ) ? $s : array();
  37  
  38          wp_register_style( self::screen, '/' . MP_PATH . 'mp-admin/css/settings.css' );
  39          $styles[] = self::screen;
  40  
  41          parent::print_styles( $styles );
  42      }
  43  
  44  ////  Scripts  ////
  45  
  46  	public static function print_scripts( $scripts = array() ) 
  47      {
  48          wp_register_script( 'mp-smtp',    '/' . MP_PATH . 'mp-admin/js/settings_smtp.js', array(), false, 1 );
  49  
  50          wp_register_script( self::screen,     '/' . MP_PATH . 'mp-admin/js/settings.js', array( 'jquery-ui-tabs', 'mp-smtp' ), false, 1 );
  51          wp_localize_script( self::screen, 'MP_AdminPageL10n', array( 'requestFile' => admin_url( 'admin-ajax.php' ) ) );
  52          $scripts[] = self::screen;
  53  
  54          wp_register_style( 'mp_icons',         '/' . MP_PATH . 'mp-admin/css/_icons.css' );
  55          $styles[] = 'mp_icons';
  56  
  57          parent::print_scripts( $scripts );
  58      }
  59  
  60  	public static function print_styles_icons( $i = array( 'icon', ) ) 
  61      {
  62          return parent::print_styles_icons( $i );
  63      }
  64  
  65  ////  Misc  ////
  66  
  67  	public static function get_tabs()
  68      {
  69          global $mp_general;
  70  
  71          $_tabs['general'] = __( 'General', 'MailPress' );
  72  
  73          if ( $mp_general || isset( MP_AdminPage::$pst_['general'] ) )
  74          {
  75              if ( has_filter( 'MailPress_Swift_Signer_type' ) )
  76              {
  77                  $t = apply_filters( 'MailPress_Swift_Signer_type', false );
  78                  if ( $t ) $_tabs['signer_' . strtolower( $t )] = $t;
  79              }
  80  
  81              $t = apply_filters( 'MailPress_Swift_Connection_type', 'SMTP' );
  82              $_tabs['connection_' . strtolower( $t )] = $t;
  83              $_tabs = apply_filters( 'MailPress_settings_tab_connection', $_tabs );
  84  
  85              $_tabs['test'] = __( 'Test', 'MailPress' );
  86  
  87              $_tabs = apply_filters( 'MailPress_settings_tab', $_tabs );
  88  
  89              $_tabs['logs'] = __( 'Logs', 'MailPress' );
  90          }
  91  
  92          return $_tabs;
  93      }
  94  
  95  	public static function save_button()
  96      {
  97          $out  = '<p class="submit"><input type="submit" name="Submit" class="button-primary" value="' . esc_attr( __( 'Save Changes' ) ) . '" /></p>' . "\r\n";
  98  
  99          echo $out;
 100      }
 101  
 102  	public static function log_form( $name, $data, $headertext )
 103      {
 104          if ( !isset( $data[$name] ) )
 105          {
 106              $data[$name] = MailPress::$default_option_logs;
 107          }
 108  
 109          $xlevel = MP_Log::get_defined_constants();
 110  
 111          $out = '';
 112  
 113          if ( self::$first )
 114          {
 115              self::$first = false;
 116  
 117              $out .= '<tr>' . "\r\n";
 118              foreach( array( __( 'Logs', 'MailPress' ), __( 'Level', 'MailPress' ), __( 'Days', 'MailPress' ), __( 'Last purge', 'MailPress' ), ) as $th )
 119              {
 120                  $out .= '    <th><strong>' . $th . '</strong></th>' . "\r\n";
 121              }
 122              $out .= '</tr>' . "\r\n";
 123          }
 124  
 125          if ( !isset( $xlevel[$data[$name]['level']] ) ) $data[$name]['level'] = key( array_slice( $xlevel, -1, 1, true) );
 126  
 127          $datepurge = ( empty( $data[$name]['lastpurge'] ) ) ? '' : substr( $data[$name]['lastpurge'],0 , 4 ) . '/' . substr( $data[$name]['lastpurge'],4, 2 ) . '/' . substr( $data[$name]['lastpurge'],6, 2 ); 
 128  
 129          $out .= '<tr class="mp_sep">' . "\r\n";
 130          $out .= '    <th><label for="logs_' . $name . '_level"><strong>' . $headertext . '</strong></label></th>' . "\r\n";
 131          $out .= '    <td><select name="logs[' . $name . '][level]" id="logs_' . $name . '_level">'  . self::select_option( $xlevel, $data[$name]['level']  ?? false,     false ) . '</select></td>' . "\r\n";
 132          $out .= '    <td><select name="logs[' . $name . '][lognbr]">' . self::select_number( 1, 10,   $data[$name]['lognbr'] ?? false, 1, false ) . '</select></td>' . "\r\n";
 133          $out .= '    <td>' . $datepurge . '<input type="hidden" name="logs[' . $name . '][lastpurge]" value="' . esc_attr( $data[$name]['lastpurge'] ) . '" /></td>' . "\r\n";
 134          $out .= '</tr>' . "\r\n";
 135  
 136          echo $out;
 137      }
 138  
 139  	public static function cron_form( $config, $name, $add_on, $every = 's_h' )
 140      {
 141          $xevery = self::cron_every( $every );
 142  
 143          $out = '';
 144  
 145          $out .= '<tr>' . "\r\n";
 146          $out .= '    <th>' . __( 'Submit Batch With', 'MailPress' ) . '</th>' . "\r\n";
 147          $out .= '    <td>' . "\r\n";
 148          $out .= '        <table class="general mp_cron" id="' . $name . '_mp_cron">' . "\r\n";
 149          $out .= '            <tr class="em3">' . "\r\n";
 150          $out .= '                <td class="pr10">' . "\r\n";
 151          $out .= '                    <label for="' . $name . '_wp_cron">' . "\r\n";
 152          $out .= '                        <input type="radio" value="wpcron" name="' . $name . '[batch_mode]" id="' . $name . '_wp_cron"' . checked( 'wpcron', $config['batch_mode'], false ) . ' />' . "\r\n";
 153          $out .= '                        &#160;&#160; ' . __( 'Wp_cron', 'MailPress' ) . "\r\n"; 
 154          $out .= '                    </label>' . "\r\n";
 155          $out .= '                </td>' . "\r\n";
 156          $out .= '                <td class="mp_cron_toggle pr10 every' . ( ( 'wpcron' != $config['batch_mode'] ) ? ' mask' : '' ) . '">' . "\r\n";
 157          $out .= '                    ' . __( 'Every', 'MailPress' ) . '&#160;&#160;' . "\r\n";
 158          $out .= '                    <select name="' . $name . '[every]" id="' . $name . '_every">';
 159          $out .= MP_AdminPage::select_option( $xevery, $config['every'] ?? false, false );
 160          $out .= '</select>' . "\r\n";
 161          $out .= '                    <span class="italic">';
 162  
 163          $out .= ( MP_addons::is_active( 'MailPress_wp_cron' ) ) 
 164              ? sprintf( __('You can check your scheduled jobs, if any, on %1$s', 'MailPress'), sprintf( '<a href="' . MailPress_wp_cron . '" target="_blank">%s</a>', __( 'Tools > Wp_cron', 'MailPress' ) ) ) 
 165              : sprintf( __('Activate add-on %1$s, so you can check your scheduled jobs, if any.', 'MailPress'), sprintf( '<a href="' . MailPress_addons . '#MailPress_wp_cron' . '" target="_blank">%s</a>', __( 'Wp_cron', 'MailPress' ) ) );
 166  
 167          $out .= '</span>' . "\r\n";
 168          $out .= '                </td>' . "\r\n";
 169          $out .= '            </tr>' . "\r\n";
 170          $out .= '            <tr class="em3">' . "\r\n";
 171          $out .= '                <td class="pr10">' . "\r\n";
 172          $out .= '                    <label for="' . $name . '_other">' . "\r\n";
 173          $out .= '                        <input type="radio" value="other" name="' . $name . '[batch_mode]" id="' . $name . '_other"' . checked( 'other', $config['batch_mode'], false ) . ' />' . "\r\n";
 174          $out .= '                        &#160;&#160;' . __( 'Other', 'MailPress' ) . "\r\n";
 175          $out .= '                    </label>' . "\r\n";
 176          $out .= '                </td>' . "\r\n";
 177          $out .= '                <td class="mp_cron_toggle pr10 other' . ( ( 'other' != $config['batch_mode'] ) ? ' mask' : '' ) . '">' . "\r\n";
 178          $out .= '                    <span class="italic">';
 179          $out .= __( "Don't forget to set up a cron job/scheduled task at required frequency (out of WordPress)", 'MailPress' ) . '<br />';
 180          $out .= sprintf( __( 'url for job : "%1$s"', 'MailPress' ), '<code>' . admin_url( 'admin-ajax.php' ) . "?action=mp_cron&hook=" . $add_on::process_name . '</code>' );
 181          $out .= '</span>' . "\r\n";
 182          $out .= '                </td>' . "\r\n";
 183          $out .= '            </tr>' . "\r\n";
 184          $out .= '        </table>' . "\r\n";
 185          $out .= '    </td>' . "\r\n";
 186          $out .= '</tr>' . "\r\n";
 187  
 188          echo $out;
 189      }
 190  
 191  	public static function cron_every( $every = 's_h')
 192      {
 193          $freqs = array(
 194              's_h' => array( /* second to hour */
 195                  30     => sprintf( __( '%1$s seconds', 'MailPress' ), '30' ), 
 196                  45     => sprintf( __( '%1$s seconds', 'MailPress' ), '45' ), 
 197                  60     => sprintf( __( '%1$s minute' , 'MailPress' ) , ''  ), 
 198                  120     => sprintf( __( '%1$s minutes', 'MailPress' ), '2'  ), 
 199                  300     => sprintf( __( '%1$s minutes', 'MailPress' ), '5'  ), 
 200                  600     => sprintf( __( '%1$s minutes', 'MailPress' ), '10' ), 
 201                  900     => sprintf( __( '%1$s minutes', 'MailPress' ), '15' ), 
 202                  1800     => sprintf( __( '%1$s minutes', 'MailPress' ), '30' ), 
 203                  3600     => sprintf( __( '%1$s hour',     'MailPress' ), ''   ),
 204              ),
 205              'h_d' => array(  /* hour to day */
 206                  3600     => sprintf( __( 'hour',     'MailPress' ), ''   ),
 207                  3600*2     => sprintf( __( '%1$s hours',     'MailPress' ), '2'  ),
 208                  3600*6     => sprintf( __( '%1$s hours',     'MailPress' ), '6'  ),
 209                  3600*12 => sprintf( __( '%1$s hours',     'MailPress' ), '12' ),
 210                  3600*24 =>          __( 'day',          'MailPress' ),
 211              ),
 212              'd_y' => array( /* day to year */
 213                  01     => sprintf( __( '%1$s day',  'MailPress' ), '1'   ), 
 214                  05     => sprintf( __( '%1$s days', 'MailPress' ), '5'   ),  
 215                  10     => sprintf( __( '%1$s days', 'MailPress' ), '10'  ), 
 216                  15     => sprintf( __( '%1$s days', 'MailPress' ), '15'  ),  
 217                  30     => sprintf( __( '%1$s days', 'MailPress' ), '30'  ),  
 218                  60     => sprintf( __( '%1$s days', 'MailPress' ), '60'  ), 
 219                  90     => sprintf( __( '%1$s days', 'MailPress' ), '90'  ), 
 220                  120     => sprintf( __( '%1$s days', 'MailPress' ), '120' ), 
 221                  360     => sprintf( __( '%1$s days', 'MailPress' ), '360' ),
 222              ),
 223          );
 224          return ( isset( $freqs[$every] ) ) ? $freqs[$every] : $freqs['s_h'];
 225      }
 226  
 227  	public static function cron_help()
 228      {
 229          $content = '';
 230  
 231          // Submit batch with
 232          $content .= '<tr><th><span>';
 233          $content .= __( 'Submit batch with', 'MailPress' );
 234          $content .= '</span></th><td>';
 235          $content .= '<ul>';
 236          $content .= '<li>' . __('Wp_cron, select frequency.', 'MailPress') . '</li>';
 237          $content .= '<li>' . __('Other, follow guidelines.', 'MailPress') . '</li>';
 238          $content .= '</ul>';
 239          $content .= '</td></tr>';
 240  
 241          return $content;
 242      }
 243  
 244  	public static function pop3_form( $config, $name )
 245      {
 246          $class_srvr = ( isset( MP_AdminPage::$err_mess[$name . '_pop3_server'] ) )   ? ' form-invalid' : '';
 247          $class_port = ( isset( MP_AdminPage::$err_mess[$name . '_pop3_port']   ) )   ? ' form-invalid' : '';
 248          $class_user = ( isset( MP_AdminPage::$err_mess[$name . '_pop3_username'] ) ) ? ' class="form-invalid"' : '';
 249  
 250          $out = '';
 251  
 252          $out .= '<tr class="mp_sep">' . "\r\n";
 253          $out .= '    <th class="thtitle">' . __( 'Pop3', 'MailPress' ) . '</th>' . "\r\n";
 254          $out .= '    <td></td>' . "\r\n";
 255          $out .= '</tr>' . "\r\n";
 256          $out .= '<!-- Pop3 server -->' . "\r\n";
 257          $out .= '<!-- Pop3 port -->' . "\r\n";
 258          $out .= '<tr>' . "\r\n";
 259          $out .= '    <th><label for="' . $name . '_pop3_server">' . __( 'Pop3 Server', 'MailPress' ) . '</label></th>' . "\r\n";
 260          $out .= '    <td class="field">' . "\r\n";
 261          $out .= '        <input type="text" name="' . $name . '[pop3][server]" value="' . ( $config['pop3']['server'] ?? '' ) . '" class="regular-text code' . $class_srvr . '" id="' . $name . '_pop3_server" /> ' . "\r\n";
 262          $out .= __( 'Port', 'MailPress' ) . "\r\n";
 263          $out .= '        <input type="text" name="' . $name . '[pop3][port]" value="'   . ( $config['pop3']['port']   ?? '' ) . '" class="small-text'        . $class_port . '" />' . "\r\n";
 264          $out .= '    </td>' . "\r\n";
 265          $out .= '</tr>' . "\r\n";
 266          $out .= '<!-- Pop3 username -->' . "\r\n";
 267          $out .= '<tr' . $class_user . '>' . "\r\n";
 268          $out .= '    <th><label for="' . $name . '_pop3_username">' . __( 'Login Name', 'MailPress' ) . '</label></th>' . "\r\n";
 269          $out .= '    <td class="field">' . "\r\n";
 270          $out .= '        <input type="text" name="' . $name . '[pop3][username]" value="' . ( $config['pop3']['username'] ?? '' ) . '" class="regular-text ltr" id="' . $name . '_pop3_username" />' . "\r\n";
 271          $out .= '    </td>' . "\r\n";
 272          $out .= '</tr>' . "\r\n";
 273          $out .= '<!-- Pop3 pw -->' . "\r\n";
 274          $out .= '<tr>' . "\r\n";
 275          $out .= '    <th><label for="' . $name . '_pop3_password">' . __( 'Password', 'MailPress' ) . '</label></th>' . "\r\n";
 276          $out .= '    <td>' . "\r\n";
 277          $out .= '        <input type="password" name="' . $name . '[pop3][password]" value="' . ( $config['pop3']['password'] ?? '' ) . '" class="regular-text ltr" id="' . $name . '_pop3_password" />' . "\r\n";
 278          $out .= '    </td>' . "\r\n";
 279          $out .= '</tr>' . "\r\n";
 280  
 281          echo $out;
 282      }
 283  
 284  	public static function pop3_help()
 285      {
 286          $content = '';
 287  
 288          // POP3 settings
 289          $content .= '<tr><th><span>';
 290          $content .= sprintf( '<a href="%1$s" target="_blank">%2$s</a>', 'https://en.wikipedia.org/wiki/Post_Office_Protocol', 'POP3' );
 291          $content .= '</span></th><td>';
 292          $content .= __( 'To enable access to the dedicated privacy mailbox.', 'MailPress' ); 
 293          $content .= __( ' All these informations should be provided by your mail server.', 'MailPress' );
 294          $content .= '</td></tr>';
 295  
 296          return $content;
 297      }
 298  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1