[ Index ]

MailPress 544

[ 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. <b>(do not use automatic upgrade!)</b>
   6  Author: Andre Renaut
   7  Author URI: http://www.mailpress.org
   8  Requires at least: 4.3
   9  Tested up to: 4.3
  10  Version: 5.4.4
  11  */
  12  
  13  /** for admin plugin pages */
  14  define ('MailPress_page_mails',     'mailpress_mails');
  15  define ('MailPress_page_write',     'mailpress_write');
  16  define ('MailPress_page_edit',        MailPress_page_mails . '&file=write');
  17  define ('MailPress_page_revision',     MailPress_page_mails . '&file=revision');
  18  define ('MailPress_page_themes',     'mailpress_themes');
  19  define ('MailPress_page_settings',     'mailpress_settings');
  20  define ('MailPress_page_users',     'mailpress_users');
  21  define ('MailPress_page_user',        MailPress_page_users . '&file=uzer');
  22  define ('MailPress_page_addons',     'mailpress_addons');
  23  
  24  /** for admin plugin urls */
  25  $mp_file = 'admin.php';
  26  define ('MailPress_mails',        $mp_file . '?page='     . MailPress_page_mails);
  27  define ('MailPress_write',        $mp_file . '?page='     . MailPress_page_write);
  28  define ('MailPress_edit',        $mp_file . '?page='     . MailPress_page_edit);
  29  define ('MailPress_revision',     $mp_file . '?page='     . MailPress_page_revision);
  30  define ('MailPress_themes',    $mp_file . '?page='     . MailPress_page_themes);
  31  define ('MailPress_settings',     'options-general.php' . '?page='     . MailPress_page_settings);
  32  define ('MailPress_users',        $mp_file . '?page='     . MailPress_page_users);
  33  define ('MailPress_user',        $mp_file . '?page='     . MailPress_page_user);
  34  define ('MailPress_addons',    'plugins.php' . '?page='     . MailPress_page_addons);
  35  
  36  /** for mysql */
  37  global $wpdb;
  38  $wpdb->mp_mails     = $wpdb->prefix . 'mailpress_mails';
  39  $wpdb->mp_mailmeta  = $wpdb->prefix . 'mailpress_mailmeta';
  40  $wpdb->mp_users     = $wpdb->prefix . 'mailpress_users';
  41  $wpdb->mp_usermeta  = $wpdb->prefix . 'mailpress_usermeta';
  42  $wpdb->mp_stats     = $wpdb->prefix . 'mailpress_stats';
  43  
  44  class MailPress
  45  {
  46      const option_name_general = 'MailPress_general';
  47      const option_name_test    = 'MailPress_test';
  48      const option_name_logs    = 'MailPress_logs';
  49  
  50      const option_name_subscriptions = 'MailPress_subscriptions';
  51  
  52      const option_name_smtp    = 'MailPress_smtp_config';
  53  
  54      public static $default_option_logs = array('level' => 8191, 'lognbr' => 10, 'lastpurge' => '');
  55  
  56  	function __construct() 
  57      {
  58          require_once ('mp-load.php');
  59  
  60          spl_autoload_register(array(__CLASS__, 'autoload'));                        // for class loader
  61  
  62          if (defined('MP_DEBUG_LOG')) { global $mp_debug_log; $mp_debug_log = new MP_Log('debug_mailpress', array('option_name' => 'debug')); }
  63  
  64          add_action('plugins_loaded',         array(__CLASS__, 'plugins_loaded'));        // for add-ons & gettext
  65          add_action('init',                 array(__CLASS__, 'init'));                // for init
  66          add_action('widgets_init',         array(__CLASS__, 'widgets_init'));        // for widget
  67          add_action('shutdown',             array(__CLASS__, 'shutdown'), 999);        // for shutdown
  68  
  69          add_action('mp_process_send_draft',    array(__CLASS__, 'process'));            // for scheduled draft
  70  
  71          if (is_admin())
  72          {
  73              register_activation_hook(plugin_basename(__FILE__),     array(__CLASS__, 'install'));                    // for install
  74  
  75              add_action('admin_init',         array(__CLASS__, 'admin_init'));                // for admin css
  76              add_action('admin_menu',         array(__CLASS__, 'admin_menu'));                // for menu
  77  
  78              $in_plugin_update_message = 'in_plugin_update_message-' . MP_FOLDER . '/' . __FILE__;                // for plugin
  79              add_action($in_plugin_update_message,        array(__CLASS__, 'in_plugin_update_message') );     //  * update message
  80              add_filter('plugin_action_links',        array(__CLASS__, 'plugin_action_links'), 10, 2 );    //  * page links
  81          }
  82  
  83          add_shortcode('mailpress',         array(__CLASS__, 'shortcode'));            // for shortcode
  84  
  85          do_action('MailPress_init');
  86      }
  87  
  88  	public static function autoload($class)
  89      {
  90          if (0 !== strpos($class, 'MP_')) return false;
  91          $file = MP_ABSPATH . "mp-includes/class/{$class}.class.php";
  92          if (is_file($file)) return require $file;
  93          return false;
  94      }
  95  
  96  	public static function plugins_loaded() 
  97      {
  98          load_plugin_textdomain(MP_TXTDOM, false, MP_FOLDER . '/' . MP_CONTENT_FOLDER . '/' . 'languages');
  99  
 100          new MP_Addons();
 101  
 102          defined('MP_Action_url')  or define('MP_Action_url',   add_query_arg(apply_filters('MailPress_action_url_arg', array() ),  ( (defined('WP_SITEURL')) ? WP_SITEURL : site_url() ) . '/' . MP_PATH . 'mp-includes/action.php'  ) );
 103          defined('MP_Action_home') or define('MP_Action_home',  add_query_arg(apply_filters('MailPress_action_url_arg', array() ),  home_url() . '/' . MP_PATH . 'mp-includes/action.php'  ) );
 104      }
 105  
 106  	public static function init()
 107      {
 108      // for roles & capabilities
 109          $role = get_role('administrator');
 110          foreach (self::capabilities() as $capability => $v) $role->add_cap($capability);
 111          do_action('MailPress_roles_and_capabilities');
 112  
 113      // for admin bar menu
 114          add_action('admin_bar_menu', array(__CLASS__, 'admin_bar_menu'), 71 );
 115  
 116      // for specific mailpress admin page
 117          if (is_admin() && self::get_admin_page()) self::admin_page();
 118      }
 119  
 120  	public static function capabilities()                                        // for roles & capabilities
 121      {
 122          include  (MP_ABSPATH . 'mp-admin/includes/capabilities/capabilities.php');
 123          return apply_filters('MailPress_capabilities', $capabilities);
 124      }
 125  
 126  	public static function capability_groups()
 127      {
 128          include  (MP_ABSPATH . 'mp-admin/includes/capabilities/capability_groups.php');
 129          return apply_filters('MailPress_capability_groups', $capability_groups);
 130      }
 131  
 132  	public static function widgets_init() { register_widget('MP_Widget'); }                    // for widget
 133  
 134  	public static function shutdown() { if (defined('MP_DEBUG_LOG')) { global $mp_debug_log; $mp_debug_log->end(true); } }
 135  
 136  	public static function process($args) { return MP_Mail_draft::send($args); }             // for scheduled draft
 137  
 138  ////  ADMIN  ////
 139  
 140  // for install
 141  
 142  	public static function install() 
 143      {
 144          $min_ver_wp  = '3.4';
 145          include  (MP_ABSPATH . 'mp-admin/includes/install/mailpress.php');
 146      }
 147  
 148  // for admin stuff
 149  
 150  	public static function admin_init()
 151      {
 152      // for global css
 153          $pathcss        = MP_ABSPATH . 'mp-admin/css/colors_' . get_user_option('admin_color') . '.css';
 154          $css_url        = '/' . MP_PATH . 'mp-admin/css/colors_' . get_user_option('admin_color') . '.css';
 155          $css_url_default= '/' . MP_PATH . 'mp-admin/css/colors_fresh.css';
 156          $css_url        = (is_file($pathcss)) ? $css_url : $css_url_default;
 157          wp_register_style ( 'MailPress_colors',     $css_url);
 158          wp_enqueue_style  ( 'MailPress_colors' );
 159  
 160      // for dashboard
 161          global $mp_general;
 162          if ( isset($mp_general['dashboard']) && current_user_can('MailPress_edit_dashboard') )
 163              add_filter('wp_dashboard_setup',     array(__CLASS__, 'wp_dashboard_setup'));
 164      }
 165  
 166  	public static function wp_dashboard_setup() { new MP_Dashboard_widgets(); }
 167  
 168  // for menus
 169  
 170  	public static function admin_menu() { new MP_Admin_Menu(); }
 171  
 172  	public static function admin_bar_menu($wp_admin_bar) { new MP_Admin_Bar_Menu($wp_admin_bar); }
 173  
 174  // for admin page
 175  
 176  	public static function get_admin_page()
 177      {
 178          return ( !isset($_GET['page']) || strpos($_GET['page'], 'mailpress') !== 0 ) ? false : ( $_GET['page'] . ( (isset($_GET['file'])) ? '&file=' . $_GET['file'] : '' ) );
 179      }
 180  
 181  	public static function admin_page()
 182      {
 183          $admin_page = self::get_admin_page();
 184  
 185          $hub = array (    MailPress_page_mails     => 'mails', 
 186                      MailPress_page_write     => 'write', 
 187                      MailPress_page_edit     => 'write', 
 188                      MailPress_page_revision => 'revision', 
 189                      MailPress_page_themes    => 'themes', 
 190                      MailPress_page_settings => 'settings', 
 191                      MailPress_page_users     => 'users', 
 192                      MailPress_page_user     => 'user',
 193                      MailPress_page_addons    => 'addons'
 194          );
 195          $hub  = apply_filters('MailPress_load_admin_page', $hub);
 196          if (!isset($hub[$admin_page])) return;
 197  
 198          $file = MP_ABSPATH . 'mp-admin/' . $hub[$admin_page] . '.php';
 199          if (!is_file($file)) return;
 200  
 201          require_once($file);
 202          if (!class_exists('MP_AdminPage')) return;
 203  
 204          new MP_AdminPage();
 205      }
 206  
 207  // for plugin
 208  
 209  	public static function in_plugin_update_message()
 210      {
 211  ?>
 212          <p style="color:red;margin:3px 0 0 0;border-top:1px solid #ddd;padding-top:3px">
 213              <?php printf(__( 'IMPORTANT: <a href="%$1s">Read this before attempting to update MailPress</a>', MP_TXTDOM), 'http://blog.mailpress.org/tutorials/'); ?>
 214          </p>
 215  <?php
 216      }
 217  
 218  	public static function plugin_action_links($links, $file)
 219      {
 220          if (plugin_basename(__FILE__) != $file) return $links;
 221  
 222          $addons_link = "<a href='" . MailPress_addons . "' title='" . __('Manage MailPress add-ons', MP_TXTDOM) . "'>" . __('Add-ons', MP_TXTDOM) . '</a>';
 223          array_unshift ($links, $addons_link);
 224  
 225          return self::plugin_links($links, $file, plugin_basename(__FILE__), '0');
 226      }
 227  
 228  	public static function plugin_links($links, $file, $basename, $tab)
 229      {
 230          if ($basename != $file) return $links;
 231  
 232          $settings_link = "<a href='" . MailPress_settings . "&amp;tab=$tab'>" . __('Settings') . '</a>';
 233          array_unshift ($links, $settings_link);
 234          return $links;
 235      }
 236  
 237  ////    Subscription form    ////
 238  
 239  	public static function shortcode($options=false)
 240      {
 241          $options['widget_id'] = 'sc';
 242  
 243          ob_start();
 244              self::form($options);
 245              $x = ob_get_contents();
 246          ob_end_clean();
 247          return $x; 
 248      }
 249  
 250  	public static function form($options = array())
 251      {
 252          static $_widget_id = 0;
 253  
 254          $options['widget_id'] = (isset($options['widget_id'])) ?  $options['widget_id'] . '_' . $_widget_id : 'mf_' . $_widget_id;
 255  
 256          MP_Widget::widget_form($options);
 257  
 258          $_widget_id++;
 259      }
 260  
 261  ////    THE MAIL
 262  
 263  	public static function mail($args)
 264      {
 265          $x = new MP_Mail();
 266          return $x->send($args);
 267      }
 268  }
 269  new MailPress();


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