[ Index ]

MailPress 7.1

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

title

Body

[close]

/ -> MailPress.php (source)

   1  <?php
   2  /*
   3  Plugin Name: MailPress
   4  Plugin URI: http://www.mailpress.org
   5  Description: The WordPress mailing platform.
   6  
   7  Version: 7.1
   8  
   9  Author: Andre Renaut
  10  Author URI: http://www.mailpress.org
  11  License: WTFPL license
  12  
  13  Text Domain: MailPress
  14  Domain Path: /mp-content/languages
  15  */
  16  
  17  /** Absolute path to the MailPress directory. */
  18  define ( 'MP_ABSPATH',    __DIR__ . '/' );
  19  
  20  /** Folder name of MailPress plugin. */
  21  define ( 'MP_FOLDER',     basename( MP_ABSPATH ) );
  22  
  23  /** Relative path to the MailPress directory. */
  24  define ( 'MP_PATH',         PLUGINDIR . '/' . MP_FOLDER . '/' );
  25  
  26  
  27  /** for admin plugin pages */
  28  define ( 'MailPress_page_mails',    'mailpress_mails' );
  29  define ( 'MailPress_page_write',    'mailpress_write' );
  30  define ( 'MailPress_page_edit',        MailPress_page_mails . '&file=write' );
  31  define ( 'MailPress_page_revision',    MailPress_page_mails . '&file=revision' );
  32  define ( 'MailPress_page_themes',    'mailpress_themes' );
  33  define ( 'MailPress_page_settings',    'mailpress_settings' );
  34  define ( 'MailPress_page_users',    'mailpress_users' );
  35  define ( 'MailPress_page_user',        MailPress_page_users . '&file=uzer' );
  36  define ( 'MailPress_page_addons',    'mailpress_addons' );
  37  
  38  /** for admin plugin urls */
  39  $mp_file = 'admin.php';
  40                              
  41  define ( 'MailPress_mails',        add_query_arg( 'page', MailPress_page_mails,     $mp_file ) );
  42  define ( 'MailPress_write',        add_query_arg( 'page', MailPress_page_write,     $mp_file ) );
  43  define ( 'MailPress_edit',            add_query_arg( 'page', MailPress_page_edit,     $mp_file ) );
  44  define ( 'MailPress_revision',        add_query_arg( 'page', MailPress_page_revision, $mp_file ) );
  45  define ( 'MailPress_themes',        add_query_arg( 'page', MailPress_page_themes,     $mp_file ) );
  46  define ( 'MailPress_settings',        add_query_arg( 'page', MailPress_page_settings, 'options-general.php' ) );
  47  define ( 'MailPress_users',        add_query_arg( 'page', MailPress_page_users,     $mp_file ) );
  48  define ( 'MailPress_user',            add_query_arg( 'page', MailPress_page_user,     $mp_file ) );
  49  define ( 'MailPress_addons',        add_query_arg( 'page', MailPress_page_addons,     'plugins.php' ) );
  50  
  51  /** for mysql */
  52  global $wpdb;
  53  $wpdb->mp_mails     = $wpdb->prefix . 'mailpress_mails';
  54  $wpdb->mp_mailmeta  = $wpdb->prefix . 'mailpress_mailmeta';
  55  $wpdb->mp_users     = $wpdb->prefix . 'mailpress_users';
  56  $wpdb->mp_usermeta  = $wpdb->prefix . 'mailpress_usermeta';
  57  $wpdb->mp_stats     = $wpdb->prefix . 'mailpress_stats';
  58  
  59  class MailPress
  60  {
  61      const option_name_general             = 'MailPress_general';
  62      const option_name_test                = 'MailPress_test';
  63      const option_name_logs                = 'MailPress_logs';
  64      const option_name_subscriptions     = 'MailPress_subscriptions';
  65      const option_name_smtp                = 'MailPress_smtp_config';
  66      const option_name_sendmail            = 'MailPress_connection_sendmail';
  67  //    php mail() not supported since swiftmailer 6.x
  68  
  69      public static $default_option_logs = array( 'level' => E_ALL, 'lognbr' => 10, 'lastpurge' => '' );
  70  
  71      public static $validator = null;
  72  
  73  	function __construct() 
  74      {
  75          require_once ( 'mp-load.php' );
  76  
  77          spl_autoload_register( array( __CLASS__, 'autoload' ) );                            // for class loader
  78  
  79          if ( defined( 'MP_DEBUG_LOG' ) )
  80          {
  81              global $mp_debug_log; 
  82              $mp_debug_log = new MP_Log( 'debug_mailpress', array( 'option_name' => 'debug' ) );
  83              // Slow heartbeat
  84              add_filter( 'heartbeat_settings', array(__CLASS__, 'heartbeat_settings'));
  85          }
  86  
  87          add_action( 'plugins_loaded',            array( __CLASS__, 'plugins_loaded' ) );        // for add-ons & gettext
  88          add_action( 'init',                    array( __CLASS__, 'init' ) );                // for init
  89          add_action( 'widgets_init',            array( __CLASS__, 'widgets_init' ) );            // for widget
  90          add_action( 'shutdown',                array( __CLASS__, 'shutdown' ), 999 );        // for shutdown
  91          add_action( 'mp_process_send_draft',        array( __CLASS__, 'process' ) );            // for scheduled draft
  92  
  93          add_action( 'wp_ajax_mp_ajax',            array( __CLASS__, 'wp_ajax_mp_ajax' ) );        // for ajax
  94          add_action( 'wp_ajax_mp_mlinks',        array( __CLASS__, 'mail_link' ) );
  95          add_action( 'wp_ajax_nopriv_mp_mlinks',    array( __CLASS__, 'mail_link' ) );
  96  
  97          add_action( 'wp_ajax_mp_cron',            array( __CLASS__, 'mp_cron' ) );
  98          add_action( 'wp_ajax_nopriv_mp_cron',        array( __CLASS__, 'mp_cron' ) );
  99  
 100          if ( is_admin() )
 101          {
 102              register_activation_hook( plugin_basename( __FILE__ ),     array( __CLASS__, 'install' ) );    // for install
 103  
 104              add_action( 'admin_init',            array( __CLASS__, 'admin_init' ) );                    // for admin css
 105              add_action( 'admin_menu',            array( __CLASS__, 'admin_menu' ) );                    // for menu
 106  
 107              $in_plugin_update_message = 'in_plugin_update_message-' . MP_FOLDER . '/' . __FILE__;            // for plugin
 108              add_action($in_plugin_update_message,array( __CLASS__, 'in_plugin_update_message' ) );        //  * update message
 109              add_filter( 'plugin_action_links',    array( __CLASS__, 'plugin_action_links' ), 10, 2 );        //  * page links
 110          }
 111  
 112          add_shortcode( 'mailpress',            array( __CLASS__, 'shortcode' ) );                        // for shortcode
 113  
 114          do_action( 'MailPress_init' );
 115      }
 116  
 117  	public static function autoload( $class )
 118      {
 119          if ( 0 == strpos( $class, 'MP_' ) )
 120          {
 121              $file = MP_ABSPATH . "mp-includes/class/{$class}.class.php";
 122              if ( is_file( $file ) ) return require $file;
 123          }
 124          return false;
 125      }
 126  
 127  	public static function wp_ajax_mp_ajax()
 128      {
 129          new MP_WP_Ajax();
 130      }
 131  
 132  	public static function plugins_loaded() 
 133      {
 134          load_plugin_textdomain( 'MailPress', false, MP_FOLDER . '/' . MP_CONTENT_FOLDER . '/' . 'languages' );
 135          new MP_Addons();
 136      }
 137  
 138  	public static function init()
 139      {
 140      // for roles & capabilities
 141          $role = get_role( 'administrator' );
 142          foreach ( self::capabilities() as $capability => $v )
 143          {
 144              $role->add_cap( $capability );
 145          }
 146          do_action( 'MailPress_roles_and_capabilities' );
 147  
 148      // for admin bar menu
 149          add_action( 'admin_bar_menu', array( __CLASS__, 'admin_bar_menu' ), 71 );
 150  
 151      // for specific mailpress admin page
 152          if ( is_admin() && self::get_admin_page() )
 153          {
 154              self::admin_page();
 155          }
 156      }
 157  
 158  	public static function capabilities()                                        // for roles & capabilities
 159      {
 160          include  ( MP_ABSPATH . 'mp-admin/includes/capabilities/capabilities.php' );
 161          return apply_filters( 'MailPress_capabilities', $capabilities );
 162      }
 163  
 164  	public static function capability_groups()
 165      {
 166          include  ( MP_ABSPATH . 'mp-admin/includes/capabilities/capability_groups.php' );
 167          return apply_filters( 'MailPress_capability_groups', $capability_groups );
 168      }
 169  
 170  	public static function widgets_init()                                        // for widget
 171      {
 172          register_widget( 'MP_Widget' );
 173      }
 174  
 175  	public static function shutdown()
 176      {
 177          if ( defined( 'MP_DEBUG_LOG' ) )
 178          {
 179              global $mp_debug_log; 
 180              $mp_debug_log->end( true );
 181          }
 182      }
 183  
 184  	public static function process( $args )                                    // for scheduled draft
 185      {
 186          return MP_Mail_draft::send( $args );
 187      }
 188  
 189  ////  ADMIN  ////
 190  
 191  	static function heartbeat_settings( $settings )
 192      {
 193  //        $settings['suspend'] = true;
 194  //        return $settings;
 195          $settings['minimalInterval'] = 600;
 196          return $settings;
 197      }
 198  
 199  	static function is_bot( $HTTP_USER_AGENT = NULL )
 200      {
 201          $bots_useragent  = array( 'googlebot', 'google', 'msnbot', 'ia_archiver', 'lycos', 'jeeves', 'scooter', 'fast-webcrawler', 'slurp@inktomi', 'turnitinbot', 'technorati', 'yahoo', 'findexa', 'findlinks', 'gaisbo', 'zyborg', 'surveybot', 'bloglines', 'blogsearch', 'ubsub', 'syndic8', 'userland', 'gigabot', 'become.com' );
 202          $HTTP_USER_AGENT = $HTTP_USER_AGENT ?? filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
 203          foreach ( $bots_useragent as $bot ) if ( stristr( $HTTP_USER_AGENT, $bot ) !== false ) return true;
 204          return false;
 205      }
 206  
 207  // for install
 208  
 209  	public static function install() 
 210      {
 211          $min_ver_wp  = '5';
 212          include  ( MP_ABSPATH . 'mp-admin/includes/install/mailpress.php' );
 213      }
 214  
 215  // for admin stuff
 216  
 217  	public static function admin_init()
 218      {
 219      // for global css
 220          $pathcss        = MP_ABSPATH . 'mp-admin/css/colors_' . get_user_option( 'admin_color' ) . '.css';
 221          $css_url        = '/' . MP_PATH . 'mp-admin/css/colors_' . get_user_option( 'admin_color' ) . '.css';
 222          $css_url_default= '/' . MP_PATH . 'mp-admin/css/colors_fresh.css';
 223          $css_url        = ( is_file( $pathcss ) ) ? $css_url : $css_url_default;
 224          wp_register_style( 'mailPress_colors',     $css_url );
 225          wp_enqueue_style  ( 'mailPress_colors' );
 226  
 227      // for dashboard
 228          global $mp_general;
 229          if ( isset( $mp_general['dashboard'] ) && current_user_can( 'MailPress_edit_dashboard' ) )
 230              add_filter( 'wp_dashboard_setup',     array( __CLASS__, 'wp_dashboard_setup' ) );
 231  
 232      // for privacy policy
 233          new MP_WP_Privacy_exporters();
 234          new MP_WP_Privacy_erasers();
 235      }
 236  
 237  	public static function wp_dashboard_setup()
 238      {
 239          new MP_WP_Dashboard_widgets();
 240      }
 241  
 242  // for menus
 243  
 244  	public static function admin_menu()
 245      {
 246          new MP_WP_Admin_Menu();
 247      }
 248  
 249  	public static function admin_bar_menu( $wp_admin_bar )
 250      {
 251          new MP_WP_Admin_Bar_Menu( $wp_admin_bar );
 252      }
 253  
 254  // for admin page
 255  
 256  	public static function get_admin_page()
 257      {
 258          $admin_page = filter_input( INPUT_GET, 'page' );
 259          $file       = filter_input( INPUT_GET, 'file' );
 260  
 261          return ( !isset( $admin_page ) || strpos( $admin_page, 'mailpress' ) !== 0 ) ? false : ( $admin_page . ( ( isset( $file ) ) ? '&file=' . $file : '' ) );
 262      }
 263  
 264  	public static function admin_page()
 265      {
 266          $admin_page = self::get_admin_page();
 267  
 268          if ( !$admin_page ) return;
 269  
 270          $hub = array (     MailPress_page_mails         => 'mails', 
 271                      MailPress_page_write         => 'write', 
 272                      MailPress_page_edit         => 'write', 
 273                      MailPress_page_revision     => 'revision', 
 274                      MailPress_page_themes        => 'themes', 
 275                      MailPress_page_settings     => 'settings', 
 276                      MailPress_page_users         => 'users', 
 277                      MailPress_page_user         => 'user',
 278                      MailPress_page_addons        => 'addons'
 279           );
 280          $hub  = apply_filters( 'MailPress_load_admin_page', $hub );
 281          if ( !isset( $hub[$admin_page] ) )
 282          {
 283              return;
 284          }
 285  
 286          $file = MP_ABSPATH . 'mp-admin/' . $hub[$admin_page] . '.php';
 287          if ( !is_file( $file ) )
 288          {
 289              return;
 290          }
 291  
 292          require_once( $file );
 293          if ( !class_exists( 'MP_AdminPage' ) )
 294          {
 295              return;
 296          }
 297  
 298          new MP_AdminPage();
 299      }
 300  
 301  // for plugin
 302  
 303  	public static function in_plugin_update_message()
 304      {
 305          echo '<p style="color:red;margin:3px 0 0 0;border-top:1px solid #ddd;padding-top:3px">' . sprintf( __( 'IMPORTANT: <a href="%$1s">Read this before attempting to update MailPress</a>', 'MailPress' ), 'http://blog.mailpress.org/tutorials/' ) . '</p>';
 306      }
 307  
 308  	public static function plugin_action_links( $links, $file )
 309      {
 310          if ( plugin_basename( __FILE__ ) != $file )
 311          {
 312              return $links;
 313          }
 314  
 315          $addons_link = '<a href="' . MailPress_addons . '" title="' . esc_attr( __( 'Manage MailPress add-ons', 'MailPress' ) ) . '">' . __( 'Add-ons', 'MailPress' ) . '</a>';
 316          array_unshift ( $links, $addons_link );
 317  
 318          return self::plugin_links( $links, $file, plugin_basename( __FILE__ ), '0' );
 319      }
 320  
 321  	public static function plugin_links( $links, $file, $basename, $tab )
 322      {
 323          if ( $basename != $file )
 324          {
 325              return $links;
 326          }
 327  
 328          $settings_link = '<a href="' . esc_url( add_query_arg( 'tab', $tab, MailPress_settings ) ) . '">' . __( 'Settings' ) . '</a>';
 329          array_unshift ( $links, $settings_link );
 330  
 331          return $links;
 332      }
 333  
 334  ////    Subscription form    ////
 335  
 336  	public static function shortcode( $options=false )
 337      {
 338          $options['widget_id'] = 'sc';
 339  
 340          ob_start();
 341              self::form( $options );
 342              $x = ob_get_contents();
 343          ob_end_clean();
 344          return $x; 
 345      }
 346  
 347  	public static function form( $options = array() )
 348      {
 349          static $_widget_id = 0;
 350          $options['widget_id'] = ( isset( $options['widget_id'] ) ) ?  $options['widget_id'] . '_' . $_widget_id : 'mf_' . $_widget_id;
 351          MP_Widget::widget_form( $options );
 352          $_widget_id++;
 353      }
 354  
 355  ////    THE MAIL
 356  
 357  	public static function is_email( $email )
 358      {
 359          self::$validator = new MP_Swift_EmailValidator();
 360                  
 361          return self::$validator->isValid( $email );
 362      }
 363  
 364  	public static function mail( $args )
 365      {
 366          $x = new MP_Mail();
 367          return $x->send( $args );
 368      }
 369          
 370  	public static function mail_link() //links in mail
 371      {
 372          include  ( MP_ABSPATH . 'mp-includes/html/mail_link.php' );
 373      }
 374          
 375  	public static function mp_cron() //wp_cron
 376      {
 377          define( 'DOING_CRON', true );
 378          $hook = filter_input( INPUT_GET, 'hook' );
 379          do_action( $hook );
 380      }
 381  }
 382  new MailPress();


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