Example #1
0
    /**
     * Overrides parent's to_html() method.
     *
     * Creates an output buffer, outputs the HTML and grabs the buffer content before releasing it.
     * Creates a wrapper 'ms-wrap' HTML element to contain content and navigation. The content inside
     * the navigation gets loaded with dynamic method calls.
     * e.g. if key is 'settings' then render_settings() gets called, if 'bob' then render_bob().
     *
     * @todo Could use callback functions to call dynamic methods from within the helper, thus
     * creating the navigation with a single method call and passing method pointers in the $tabs array.
     *
     * @since  1.0.0
     *
     * @return object
     */
    public function to_html()
    {
        $this->check_simulation();
        $items = $this->data['addon']->get_addon_list();
        $lang = (object) array('active_badge' => __('ACTIVE', MS_TEXT_DOMAIN), 'show_details' => __('Details...', MS_TEXT_DOMAIN), 'close_details' => __('Close', MS_TEXT_DOMAIN));
        $filters = array('all' => __('All', MS_TEXT_DOMAIN), 'active' => __('Active', MS_TEXT_DOMAIN), 'inactive' => __('Inactive', MS_TEXT_DOMAIN), 'options' => __('With options', MS_TEXT_DOMAIN));
        ob_start();
        ?>
		<div class="ms-wrap ms-addon-list">
			<h2 class="ms-settings-title">
				<i class="wpmui-fa wpmui-fa-puzzle-piece"></i>
				<?php 
        _e('Membership Add-ons', MS_TEXT_DOMAIN);
        ?>
			</h2>
			<form action="" method="post">
				<?php 
        lib2()->html->plugin_list($items, $lang, $filters);
        ?>
			</form>
		</div>
		<?php 
        $html = ob_get_clean();
        echo $html;
    }
 public static function print_admin_message()
 {
     $msg = !empty($_GET['msg']) ? (int) $_GET['msg'] : 0;
     $class = $msg > 0 ? 'updated' : 'error';
     if ($msg = self::get_admin_message($msg)) {
         lib2()->ui->admin_message($msg, $class);
     }
 }
 /**
  * Prepare fields that are displayed in the form.
  *
  * @since  1.0.1.0
  * @return array
  */
 protected function prepare_fields()
 {
     $api_status = MS_Addon_Mailchimp::get_api_status();
     $settings = $this->data['settings'];
     $action = MS_Controller_Settings::AJAX_ACTION_UPDATE_CUSTOM_SETTING;
     $auto_opt_in = $settings->get_custom_setting('mailchimp', 'auto_opt_in');
     $auto_opt_in = lib2()->is_true($auto_opt_in);
     $fields = array('mailchimp_api_test' => array('id' => 'mailchimp_api_test', 'type' => MS_Helper_Html::TYPE_HTML_TEXT, 'title' => __('MailChimp API test status: ', MS_TEXT_DOMAIN), 'value' => $api_status ? __('Verified', MS_TEXT_DOMAIN) : __('Failed', MS_TEXT_DOMAIN), 'class' => $api_status ? 'ms-ok' : 'ms-nok'), 'mailchimp_api_key' => array('id' => 'mailchimp_api_key', 'name' => 'custom[mailchimp][api_key]', 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'title' => __('MailChimp API Key', MS_TEXT_DOMAIN), 'desc' => sprintf('<div>' . __('Visit <a href="%1$s">your API dashboard</a> to create an API Key.', MS_TEXT_DOMAIN) . '</div>', 'http://admin.mailchimp.com/account/api" target="_blank'), 'value' => $settings->get_custom_setting('mailchimp', 'api_key'), 'class' => 'ms-text-medium', 'ajax_data' => array('group' => 'mailchimp', 'field' => 'api_key', 'action' => $action)), 'separator' => array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR), 'auto_opt_in' => array('id' => 'auto_opt_in', 'name' => 'custom[mailchimp][auto_opt_in]', 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'title' => __('Automatically opt-in new users to the mailing list.', MS_TEXT_DOMAIN), 'desc' => __('Users will not receive an email confirmation. You are responsible to inform your users.', MS_TEXT_DOMAIN), 'value' => $auto_opt_in, 'class' => 'inp-before', 'ajax_data' => array('group' => 'mailchimp', 'field' => 'auto_opt_in', 'action' => $action)), 'separator1' => array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR), 'mail_list_registered' => array('id' => 'mail_list_registered', 'name' => 'custom[mailchimp][mail_list_registered]', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'title' => __('Registered users mailing list (not members)', MS_TEXT_DOMAIN), 'field_options' => MS_Addon_Mailchimp::get_mail_lists(), 'value' => $settings->get_custom_setting('mailchimp', 'mail_list_registered'), 'ajax_data' => array('group' => 'mailchimp', 'field' => 'mail_list_registered', 'action' => $action)), 'mail_list_members' => array('id' => 'mail_list_members', 'name' => 'custom[mailchimp][mail_list_members]', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'title' => __('Members mailing list', MS_TEXT_DOMAIN), 'field_options' => MS_Addon_Mailchimp::get_mail_lists(), 'value' => $settings->get_custom_setting('mailchimp', 'mail_list_members'), 'ajax_data' => array('group' => 'mailchimp', 'field' => 'mail_list_members', 'action' => $action)), 'mail_list_deactivated' => array('id' => 'mail_list_deactivated', 'name' => 'custom[mailchimp][mail_list_deactivated]', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'title' => __('Deactivated memberships mailing list', MS_TEXT_DOMAIN), 'field_options' => MS_Addon_Mailchimp::get_mail_lists(), 'value' => $settings->get_custom_setting('mailchimp', 'mail_list_deactivated'), 'ajax_data' => array('group' => 'mailchimp', 'field' => 'mail_list_deactivated', 'action' => $action)));
     return $fields;
 }
 /**
  * Change a setting of the addon
  *
  * @since  1.0.0
  *
  * @param string $key
  * @param string $value
  */
 public function set($key, $value)
 {
     switch ($key) {
         case 'is_live':
             // This is a boolean value, not a string.
             $value = lib2()->is_true($value);
             break;
     }
     return $this->set_custom_setting(self::GROUP, $key, $value);
 }
 /**
  * Constructor is private -> singleton.
  *
  * @since  2.0
  */
 private function __construct()
 {
     if (is_admin()) {
         // in_widget_form: Add our button inside each widget.
         add_action('in_widget_form', array($this, 'admin_widget_button'), 10, 3);
         // in_widget_form: Update data of widget-group (see notes below).
         add_action('in_widget_form', array($this, 'update_widget_group'), 10, 3);
         // When the widget is saved (via Ajax) we save our options.
         add_filter('widget_update_callback', array($this, 'admin_widget_update'), 9999, 4);
         // Load the javascript support file for this module.
         lib2()->ui->add(CSB_JS_URL . 'cs-cloning.min.js', 'widgets.php');
         lib2()->ui->add(CSB_CSS_URL . 'cs-cloning.css', 'widgets.php');
     }
 }
 private function get_query_args()
 {
     $defaults = MS_Model_Invoice::get_query_args();
     lib2()->array->equip_request('s');
     $per_page = $this->get_items_per_page('invoice_per_page', self::DEFAULT_PAGE_SIZE);
     $current_page = $this->get_pagenum();
     $args = array('posts_per_page' => $per_page, 'offset' => ($current_page - 1) * $per_page);
     // Filter by search-term
     $search_filter = $_REQUEST['s'];
     if (!empty($search_filter)) {
         $this->search_string = $search_filter;
     }
     $args = wp_parse_args($args, $defaults);
     return $args;
 }
Example #7
0
/**
Plugin Name: WordPress PopUp
Plugin URI:  http://premium.wpmudev.org/project/the-pop-over-plugin/
Description: Allows you to display a fancy PopUp to visitors sitewide or per blog. A *very* effective way of advertising a mailing list, special offer or running a plain old ad.
Version:     4.7.1.1
Author:      WPMU DEV
Author URI:  http://premium.wpmudev.org
Textdomain:  popover
WDP ID:      123

Copyright 2007-2013 Incsub (http://incsub.com)
Author - Barry (Incsub)
Contributors - Marko Miljus (Incsub), Ve Bailovity (Incsub)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
function inc_popup_free_init()
{
    // Check if the PRO plugin is present and activated.
    if (defined('PO_VERSION') && 'pro' == PO_VERSION) {
        return false;
    }
    if (!defined('PO_LANG')) {
        // Used for more readable i18n functions: __( 'text', PO_LANG );
        define('PO_LANG', 'popover');
        define('PO_VERSION', '4.7');
        /**
         * The current DB/build version. NOT THE SAME AS THE PLUGIN VERSION!
         * Increase this when DB structure changes, migration code is required, etc.
         * See IncPopupDatabase: db_is_current() and db_update()
         */
        define('PO_BUILD', 6);
        $plugin_dir = trailingslashit(dirname(__FILE__));
        $plugin_dir_rel = trailingslashit(dirname(plugin_basename(__FILE__)));
        $plugin_url = plugin_dir_url(__FILE__);
        define('PO_LANG_DIR', $plugin_dir_rel . 'lang/');
        define('PO_TPL_DIR', $plugin_dir . 'css/tpl/');
        define('PO_INC_DIR', $plugin_dir . 'inc/');
        define('PO_JS_DIR', $plugin_dir . 'js/');
        define('PO_CSS_DIR', $plugin_dir . 'css/');
        define('PO_VIEWS_DIR', $plugin_dir . 'views/');
        define('PO_TPL_URL', $plugin_url . 'css/tpl/');
        define('PO_JS_URL', $plugin_url . 'js/');
        define('PO_CSS_URL', $plugin_url . 'css/');
        define('PO_IMG_URL', $plugin_url . 'img/');
        // Include function library.
        require_once PO_INC_DIR . 'external/wpmu-lib/core.php';
        lib2()->translate_plugin(PO_LANG, PO_LANG_DIR);
        require_once PO_INC_DIR . 'external/wdev-frash/module.php';
        // Register the current plugin.
        do_action('wdev-register-plugin', plugin_basename(__FILE__), 'WordPress PopUp', '/plugins/wordpress-popup/', __('Get Tips!', PO_LANG), '');
        // All done!
        require_once PO_INC_DIR . 'config-defaults.php';
        if (is_admin()) {
            // Defines class 'IncPopup'.
            require_once PO_INC_DIR . 'class-popup-admin.php';
        } else {
            // Defines class 'IncPopup'.
            require_once PO_INC_DIR . 'class-popup-public.php';
        }
        // Initialize the plugin as soon as we have identified the current user.
        IncPopup::instance();
    }
}
 /**
  * Constructor is private -> singleton.
  *
  * @since  2.0
  */
 private function __construct()
 {
     if (is_admin()) {
         // in_widget_form: Add our button inside each widget.
         add_action('in_widget_form', array($this, 'admin_widget_button'), 10, 3);
         // When the widget is saved (via Ajax) we save our options.
         add_filter('widget_update_callback', array($this, 'admin_widget_update'), 10, 3);
         lib2()->ui->add(CSB_JS_URL . 'cs-visibility.min.js', 'widgets.php');
         lib2()->ui->add(CSB_CSS_URL . 'cs-visibility.css', 'widgets.php');
         // Custom Sidebars Ajax request.
         add_action('cs_ajax_request_get', array($this, 'handle_ajax'));
     } else {
         // Filters the list of widget-areas and their widgets
         add_filter('sidebars_widgets', array($this, 'sidebars_widgets'));
     }
 }
 /**
  * Initializes the Add-on. Always executed.
  *
  * @since  1.0.1.0
  */
 public function init()
 {
     if (self::is_active()) {
         $this->first_click_free = lib2()->is_true($this->get_setting('first_click_free'));
         $this->add_filter('ms_model_membership_is_system', 'is_system', 10, 2);
         $this->add_filter('ms_model_membership_is_valid_type', 'is_valid_type', 10, 2);
         $this->add_filter('ms_model_membership_get_types', 'get_types');
         $this->add_filter('ms_helper_listtable_membership_column_name_actions', 'list_table_actions', 10, 2);
         $this->add_filter('ms_helper_listtable_memberships_name_badge', 'list_table_badge', 10, 2);
         $this->add_action('ms_init_done', 'apply_membership');
         // Last action in the init sequence.
         $this->create_membership();
     } else {
         $this->add_filter('ms_model_membership_get_memberships', 'hide_membership', 10, 2);
     }
 }
 /**
  * Enqueue the anonymous script.
  * Action: `popup-init-loading-method`
  *
  * @since  4.6
  * @param  string $method The option saved on the settings screen.
  * @param  IncPopup $handler Public IncPopup object that called the action.
  */
 public static function init_public($method, $handler)
 {
     if (self::METHOD != $method) {
         return false;
     }
     // Generate a random Script URL.
     $slug = self::$_slug;
     $val = self::_rot(time(), rand(1, 22));
     $script_url = esc_url_raw(add_query_arg(array($slug => $val), lib2()->net->current_url()));
     // The script is the home URL with a special URL-param.
     wp_enqueue_script($slug, $script_url, array('jquery'));
     // Enable animations in 'Anonymous Script'
     lib2()->ui->add(PO_CSS_URL . 'animate.min.css', 'front');
     // This checks if the current URL contains the special URL-param.
     // If the param is found then the PopUp details are output instead of the page.
     add_action('template_redirect', array(__CLASS__, 'apply'));
 }
 /**
  * Processes a form submit and changes the rule values, if valid form data
  * is found.
  *
  * @since  1.0.0
  */
 private function process_form()
 {
     $action = false;
     if (isset($_POST['rule_action'])) {
         $action = $_POST['rule_action'];
         if (!$this->verify_nonce($action)) {
             $action = false;
         }
     } elseif (isset($_GET['rule_action'])) {
         $action = $_GET['rule_action'];
         if (!$this->verify_nonce($action, 'GET')) {
             $action = false;
         }
     }
     if (empty($action)) {
         return;
     }
     $redirect = false;
     switch ($action) {
         case self::ACTION_ADD:
             lib2()->array->strip_slashes($_POST, 'url_value');
             $url = $_POST['url_value'];
             $base = MS_Model_Membership::get_base();
             $rule = $base->get_rule(self::RULE_ID);
             $rule->add_url($url);
             $base->set_rule(self::RULE_ID, $rule);
             $base->save();
             $redirect = true;
             break;
         case self::ACTION_DELETE:
             $id = $_REQUEST['item'];
             $base = MS_Model_Membership::get_base();
             $rule = $base->get_rule(self::RULE_ID);
             $rule->delete_url($id);
             $base->set_rule(self::RULE_ID, $rule);
             $base->save();
             $redirect = true;
             break;
     }
     if ($redirect) {
         $target = esc_url_raw(remove_query_arg(array('_wpnonce', 'item', 'rule_action')));
         wp_safe_redirect($target);
         exit;
     }
 }
/**
Plugin Name: PopUp Pro
Plugin URI:  http://premium.wpmudev.org/project/the-pop-over-plugin/
Description: Allows you to display a fancy PopUp to visitors sitewide or per blog. A *very* effective way of advertising a mailing list, special offer or running a plain old ad.
Version:     4.7.1.1
Author:      WPMU DEV
Author URI:  http://premium.wpmudev.org
Textdomain:  popover
WDP ID:      123

Copyright 2007-2013 Incsub (http://incsub.com)
Author - Barry (Incsub)
Contributors - Marko Miljus (Incsub), Ve Bailovity (Incsub)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
function inc_popup_pro_init()
{
    if (!defined('PO_LANG')) {
        // Used for more readable i18n functions: __( 'text', PO_LANG );
        define('PO_LANG', 'popover');
        define('PO_VERSION', 'pro');
        /**
         * The current DB/build version. NOT THE SAME AS THE PLUGIN VERSION!
         * Increase this when DB structure changes, migration code is required, etc.
         * See IncPopupDatabase: db_is_current() and db_update()
         */
        define('PO_BUILD', 6);
        $plugin_dir = trailingslashit(dirname(__FILE__));
        $plugin_dir_rel = trailingslashit(dirname(plugin_basename(__FILE__)));
        $plugin_url = plugin_dir_url(__FILE__);
        define('PO_LANG_DIR', $plugin_dir_rel . 'lang/');
        define('PO_TPL_DIR', $plugin_dir . 'css/tpl/');
        define('PO_INC_DIR', $plugin_dir . 'inc/');
        define('PO_JS_DIR', $plugin_dir . 'js/');
        define('PO_CSS_DIR', $plugin_dir . 'css/');
        define('PO_VIEWS_DIR', $plugin_dir . 'views/');
        define('PO_TPL_URL', $plugin_url . 'css/tpl/');
        define('PO_JS_URL', $plugin_url . 'js/');
        define('PO_CSS_URL', $plugin_url . 'css/');
        define('PO_IMG_URL', $plugin_url . 'img/');
        // Include function library.
        require_once PO_INC_DIR . 'external/wpmu-lib/core.php';
        lib2()->translate_plugin(PO_LANG, PO_LANG_DIR);
        require_once PO_INC_DIR . 'config-defaults.php';
        if (is_admin()) {
            // Defines class 'IncPopup'.
            require_once PO_INC_DIR . 'class-popup-admin.php';
        } else {
            // Defines class 'IncPopup'.
            require_once PO_INC_DIR . 'class-popup-public.php';
        }
        // Initialize the plugin as soon as we have identified the current user.
        IncPopup::instance();
    }
}
 /**
  * Initializes the Add-on. Always executed.
  *
  * @since  1.0.0
  */
 public function init()
 {
     if (self::is_active()) {
         $this->buddypress_registration = lib2()->is_true($this->get_setting('buddypress_registration'));
         $this->add_filter('ms_controller_protection_tabs', 'rule_tabs');
         MS_Factory::load('MS_Addon_BuddyPress_Rule');
         /*
          * Using the BuddyPress registration form is optional.
          * These actions are only needed when the BuddyPress registration
          * form is used instead of the M2 registration form.
          */
         if ($this->buddypress_registration) {
             $this->add_filter('ms_frontend_custom_registration_form', 'registration_form');
             $this->add_action('ms_controller_frontend_register_user_before', 'prepare_create_user');
             $this->add_action('ms_controller_frontend_register_user_complete', 'save_custom_fields');
         }
         // Disable BuddyPress Email activation.
         add_filter('bp_core_signup_send_activation_key', '__return_false');
         add_filter('bp_registration_needs_activation', '__return_false');
         $this->add_action('bp_core_signup_user', 'disable_validation');
     }
 }
Example #14
0
 /**
  * Outputs the content of the widget.
  *
  * @since  1.0.0
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     $redirect_login = false;
     $redirect_logout = false;
     $shortcode_args = '';
     if (!empty($instance['redirect_login'])) {
         $redirect_login = lib2()->net->expand_url($instance['redirect_login']);
     }
     if (!empty($instance['redirect_logout'])) {
         $redirect_logout = lib2()->net->expand_url($instance['redirect_logout']);
     }
     if (!empty($instance['shortcode_args'])) {
         $shortcode_args = $instance['shortcode_args'];
     }
     echo $args['before_widget'];
     if (!empty($instance['title'])) {
         echo $args['before_title'];
         echo apply_filters('widget_title', $instance['title']);
         echo $args['after_title'];
     }
     $scode = sprintf('[%1$s header="no" %2$s %3$s %4$s]', MS_Helper_Shortcode::SCODE_LOGIN, $redirect_login ? 'redirect_login="******"' : '', $redirect_logout ? 'redirect_logout="' . $redirect_logout . '"' : '', $shortcode_args);
     echo do_shortcode($scode);
     echo $args['after_widget'];
 }
 /**
  * Parses the specified content and looks for shortcodes that are not
  * compatible with the current PopUp loading method.
  *
  * The function does not return a value, but if incompatible shortcodes are
  * detected a new Admin Notification will be generated which is displayed to
  * the user after the page has finished loading.
  *
  * @since  4.7.0
  * @param  string $content
  */
 public static function validate_shortcodes($content)
 {
     $settings = IncPopupDatabase::get_settings();
     $method = isset($settings['loadingmethod']) ? $settings['loadingmethod'] : 'ajax';
     // Check for specific/frequently used shortcodes.
     if ('footer' !== $method && preg_match('#\\[gravityforms?(\\s.*?\\]|\\])#', $content)) {
         lib2()->ui->admin_message(sprintf(__('You are using Gravity Forms inside this PopUp. It is best to switch to the <a href="%s">loading method</a> "Page Footer" to ensure the form works as expected.', PO_LANG), 'edit.php?post_type=' . IncPopupItem::POST_TYPE . '&page=settings'), 'err');
     }
     // General check for shortcode incompatibility
     switch ($method) {
         case 'ajax':
         case 'anonymous':
             // Check if the content contains any of the Front-Shortcodes:
             $check = IncPopupAddon_HeaderFooter::check();
             $content = do_shortcode($content);
             foreach ($check->shortcodes as $code) {
                 $match = array();
                 if (preg_match('#\\[' . $code . '(\\s.*?\\]|\\])#', $content, $match)) {
                     lib2()->ui->admin_message(sprintf(__('Shortcode <code>%s</code> requires a different <a href="%s">loading method</a> to work.<br />Try "Page Footer", though sometimes the method "Custom AJAX" also works (please test the result)', PO_LANG), $match[0], 'edit.php?post_type=' . IncPopupItem::POST_TYPE . '&page=settings'), 'err');
                 }
             }
             break;
         case 'footer':
         case 'front':
             // Nothing needs to be validated here...
             break;
         default:
             //lib2()->ui->admin_message( 'Shortcode-Check not defined for: ' . $method );
     }
 }
 /**
  * Update and return the $settings array to save the form values.
  *
  * @since  4.6
  * @param  array $data The contents of $_POST['po_rule_data'].
  * @return mixed Data collection of this rule.
  */
 protected function save_no_taxonomy($data)
 {
     lib2()->array->equip($data, 'no_taxonomy');
     return $data['no_taxonomy'];
 }
 /**
  * Returns the current menu state: If a specific page is added to the menu,
  * this state is saved in the settings. So when the user removes a menu item
  * manually we still have the "inserted" flag in DB.
  *
  * We do this, because the menu items are added to all existing nav menus
  * and the user might remove them from one nav menu but not from all...
  *
  * @since  1.0.0
  * @param  string $page_type
  * @return bool
  */
 public static function has_menu($page_type)
 {
     $state = false;
     if (!MS_Plugin::is_network_wide()) {
         if (self::is_valid_type($page_type)) {
             $state = self::get_setting('has_nav_' . $page_type);
             $state = lib2()->is_true($state);
         }
     }
     return $state;
 }
 /**
  * Processes gateway IPN return.
  *
  * @since  1.0.0
  */
 public function handle_return()
 {
     $success = false;
     $ignore = false;
     $exit = false;
     $redirect = false;
     $notes = '';
     $status = null;
     $notes_pay = '';
     $notes_txn = '';
     $external_id = null;
     $invoice_id = 0;
     $subscription_id = 0;
     $amount = 0;
     $transaction_type = '';
     $payment_status = '';
     $is_m1 = false;
     $fields_set = false;
     if (!empty($_POST['txn_type'])) {
         $transaction_type = strtolower($_POST['txn_type']);
     }
     if (!empty($_POST['payment_status'])) {
         $payment_status = strtolower($_POST['payment_status']);
     }
     if ($payment_status || $transaction_type) {
         if (!empty($_POST['invoice'])) {
             // 'invoice' is set in all regular M2 subscriptions.
             $fields_set = true;
         } elseif (!empty($_POST['custom'])) {
             // First: We cannot process this payment.
             $fields_set = false;
             // But let's check if it is an M1 payment.
             $infos = explode(':', $_POST['custom']);
             if (count($infos) > 2) {
                 // $infos should contain [timestamp, user_id, sub_id, key]
                 $pay_types = array('subscr_signup', 'subscr_payment');
                 $pay_stati = array('completed', 'processed');
                 if (in_array($transaction_type, $pay_types)) {
                     $is_m1 = true;
                 } elseif (in_array($payment_status, $pay_stati)) {
                     $is_m1 = true;
                 }
             }
         }
     }
     if ($fields_set) {
         if ($this->is_live_mode()) {
             $domain = 'https://www.paypal.com';
         } else {
             $domain = 'https://www.sandbox.paypal.com';
         }
         // Paypal post authenticity verification
         $ipn_data = (array) stripslashes_deep($_POST);
         $ipn_data['cmd'] = '_notify-validate';
         $response = wp_remote_post($domain . '/cgi-bin/webscr', array('timeout' => 60, 'sslverify' => false, 'httpversion' => '1.1', 'body' => $ipn_data));
         $invoice_id = intval($_POST['invoice']);
         $currency = $_POST['mc_currency'];
         $invoice = MS_Factory::load('MS_Model_Invoice', $invoice_id);
         if (!is_wp_error($response) && 200 == $response['response']['code'] && !empty($response['body']) && 'VERIFIED' == $response['body'] && $invoice->id == $invoice_id) {
             $subscription = $invoice->get_subscription();
             $membership = $subscription->get_membership();
             $member = $subscription->get_member();
             $subscription_id = $subscription->id;
             // Process PayPal payment status
             if ($payment_status) {
                 $amount = (double) $_POST['mc_gross'];
                 $external_id = $_POST['txn_id'];
                 switch ($payment_status) {
                     // Successful payment
                     case 'completed':
                     case 'processed':
                         if ($amount == $invoice->total) {
                             $success = true;
                             $notes .= __('Payment successful', MS_TEXT_DOMAIN);
                         } else {
                             $notes_pay = __('Payment amount differs from invoice total.', MS_TEXT_DOMAIN);
                             $status = MS_Model_Invoice::STATUS_DENIED;
                         }
                         break;
                     case 'reversed':
                         $notes_pay = __('Last transaction has been reversed. Reason: Payment has been reversed (charge back).', MS_TEXT_DOMAIN);
                         $status = MS_Model_Invoice::STATUS_DENIED;
                         $ignore = true;
                         break;
                     case 'refunded':
                         $notes_pay = __('Last transaction has been reversed. Reason: Payment has been refunded.', MS_TEXT_DOMAIN);
                         $status = MS_Model_Invoice::STATUS_DENIED;
                         $ignore = true;
                         break;
                     case 'denied':
                         $notes_pay = __('Last transaction has been reversed. Reason: Payment Denied.', MS_TEXT_DOMAIN);
                         $status = MS_Model_Invoice::STATUS_DENIED;
                         $ignore = true;
                         break;
                     case 'pending':
                         lib2()->array->strip_slashes($_POST, 'pending_reason');
                         $notes_pay = __('Last transaction is pending.', MS_TEXT_DOMAIN) . ' ';
                         switch ($_POST['pending_reason']) {
                             case 'address':
                                 $notes_pay .= __('Customer did not include a confirmed shipping address', MS_TEXT_DOMAIN);
                                 break;
                             case 'authorization':
                                 $notes_pay .= __('Funds not captured yet', MS_TEXT_DOMAIN);
                                 break;
                             case 'echeck':
                                 $notes_pay .= __('The eCheck has not cleared yet', MS_TEXT_DOMAIN);
                                 break;
                             case 'intl':
                                 $notes_pay .= __('Payment waiting for approval by service provider', MS_TEXT_DOMAIN);
                                 break;
                             case 'multi-currency':
                                 $notes_pay .= __('Payment waiting for service provider to handle multi-currency process', MS_TEXT_DOMAIN);
                                 break;
                             case 'unilateral':
                                 $notes_pay .= __('Customer did not register or confirm his/her email yet', MS_TEXT_DOMAIN);
                                 break;
                             case 'upgrade':
                                 $notes_pay .= __('Waiting for service provider to upgrade the PayPal account', MS_TEXT_DOMAIN);
                                 break;
                             case 'verify':
                                 $notes_pay .= __('Waiting for service provider to verify his/her PayPal account', MS_TEXT_DOMAIN);
                                 break;
                             default:
                                 $notes_pay .= __('Unknown reason', MS_TEXT_DOMAIN);
                                 break;
                         }
                         $status = MS_Model_Invoice::STATUS_PENDING;
                         $ignore = true;
                         break;
                     default:
                     case 'partially-refunded':
                     case 'in-progress':
                         $notes_pay = sprintf(__('Not handling payment_status: %s', MS_TEXT_DOMAIN), $payment_status);
                         MS_Helper_Debug::log($notes_pay);
                         $ignore = true;
                         break;
                 }
             }
             // Check for subscription details
             if ($transaction_type) {
                 switch ($transaction_type) {
                     case 'subscr_signup':
                     case 'subscr_payment':
                         // Payment was received
                         $notes_txn = __('Paypal subscripton profile has been created.', MS_TEXT_DOMAIN);
                         if (0 == $invoice->total) {
                             $success = true;
                         } else {
                             $ignore = true;
                         }
                         break;
                     case 'subscr_modify':
                         // Payment profile was modified
                         $notes_txn = __('Paypal subscription profile has been modified.', MS_TEXT_DOMAIN);
                         $ignore = true;
                         break;
                     case 'recurring_payment_profile_canceled':
                     case 'subscr_cancel':
                         // Subscription was manually cancelled.
                         $notes_txn = __('Paypal subscription profile has been canceled.', MS_TEXT_DOMAIN);
                         $member->cancel_membership($membership->id);
                         $member->save();
                         $ignore = true;
                         break;
                     case 'recurring_payment_suspended':
                         // Recurring subscription was manually suspended.
                         $notes_txn = __('Paypal subscription profile has been suspended.', MS_TEXT_DOMAIN);
                         $member->cancel_membership($membership->id);
                         $member->save();
                         $ignore = true;
                         break;
                     case 'recurring_payment_suspended_due_to_max_failed_payment':
                         // Recurring subscription was automatically suspended.
                         $notes_txn = __('Paypal subscription profile has failed.', MS_TEXT_DOMAIN);
                         $member->cancel_membership($membership->id);
                         $member->save();
                         $ignore = true;
                         break;
                     case 'new_case':
                         // New Dispute was filed for a payment.
                         $status = MS_Model_Invoice::STATUS_DENIED;
                         $ignore = true;
                         break;
                     case 'subscr_eot':
                         /*
                          * Meaning: Subscription expired.
                          *
                          *   - after a one-time payment was madeafter last
                          *   - after last transaction in a recurring subscription
                          *   - payment failed
                          *   - ...
                          *
                          * We do not handle this event...
                          *
                          * One time payment sends 3 messages:
                          *   1. subscr_start (new subscription starts)
                          *   2. subscr_payment (payment confirmed)
                          *   3. subscr_eot (subscription ends)
                          */
                         $notes_txn = __('No more payments will be made for this subscription.', MS_TEXT_DOMAIN);
                         $ignore = true;
                         break;
                     default:
                         // Other event that we do not have a case for...
                         $notes_txn = sprintf(__('Not handling txn_type: %s', MS_TEXT_DOMAIN), $transaction_type);
                         MS_Helper_Debug::log($notes_txn);
                         $ignore = true;
                         break;
                 }
             }
             if (!empty($notes_pay)) {
                 $invoice->add_notes($notes_pay);
             }
             if (!empty($notes_txn)) {
                 $invoice->add_notes($notes_txn);
             }
             $notes .= $notes_pay . ' | ' . $notes_txn;
             $invoice->save();
             if ($success) {
                 $invoice->pay_it($this->id, $external_id);
             } elseif (!empty($status)) {
                 $invoice->status = $status;
                 $invoice->save();
                 $invoice->changed();
             }
             do_action('ms_gateway_paypalstandard_payment_processed_' . $status, $invoice, $subscription);
         } else {
             $reason = 'Unexpected transaction response';
             switch (true) {
                 case is_wp_error($response):
                     $reason = 'PayPal did not verify this transaction: Unknown error';
                     break;
                 case 200 != $response['response']['code']:
                     $reason = sprintf('PayPal did not verify the transaction: Code %s', $response['response']['code']);
                     break;
                 case empty($response['body']):
                     $reason = 'PayPal did not verify this transaction: Empty response';
                     break;
                 case 'VERIFIED' != $response['body']:
                     $reason = sprintf('PayPal did not verify this transaction: "%s"', $response['body']);
                     break;
                 case $invoice->id != $invoice_id:
                     $reason = sprintf('PayPal gave us an invalid invoice_id: "%s"', $invoice_id);
                     break;
             }
             $notes = 'Response Error: ' . $reason;
             MS_Helper_Debug::log($notes);
             MS_Helper_Debug::log($response);
             MS_Helper_Debug::log($_POST);
             $exit = true;
         }
     } else {
         // Did not find expected POST variables. Possible access attempt from a non PayPal site.
         $u_agent = $_SERVER['HTTP_USER_AGENT'];
         if (false === strpos($u_agent, 'PayPal')) {
             // Very likely someone tried to open the URL manually. Redirect to home page
             $notes = 'Error: Missing POST variables. Redirect user to Home-URL.';
             MS_Helper_Debug::log($notes);
             $redirect = home_url();
         } elseif ($is_m1) {
             /*
              * The payment belongs to an imported M1 subscription and could
              * not be auto-matched.
              * Do not return an error code, but also do not modify any
              * invoice/subscription.
              */
             $notes = 'M1 Payment detected. Manual matching required.';
             $ignore = false;
             $success = false;
         } else {
             if (!$payment_status && !$transaction_type) {
                 $notes = 'Error: payment_status and txn_type not specified. Cannot process.';
             } elseif (empty($_POST['invoice']) && empty($_POST['custom'])) {
                 $notes = 'Error: No invoice or custom data specified.';
             } else {
                 $notes = 'Error: Missing POST variables. Identification is not possible.';
             }
             // PayPal did provide invalid details...
             status_header(404);
             MS_Helper_Debug::log($notes);
         }
         $exit = true;
     }
     if ($ignore && !$success) {
         $success = null;
     }
     do_action('ms_gateway_transaction_log', self::ID, 'handle', $success, $subscription_id, $invoice_id, $amount, $notes);
     if ($redirect) {
         wp_safe_redirect($redirect);
         exit;
     }
     if ($exit) {
         exit;
     }
     do_action('ms_gateway_paypalstandard_handle_return_after', $this);
 }
 /**
  * Add custom filters to the searchbox
  *
  * @since  1.0.0
  */
 public function searchbox_filters()
 {
     lib2()->array->equip_request('search_options');
     $search_options = array('id' => 'search_options', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $_REQUEST['search_options'], 'field_options' => array('username' => __('Username / E-mail', MS_TEXT_DOMAIN), 'nickname' => __('Nickname', MS_TEXT_DOMAIN), 'first_name' => __('First Name', MS_TEXT_DOMAIN), 'last_name' => __('Last Name', MS_TEXT_DOMAIN)));
     // Display the extra search options
     MS_Helper_Html::html_element($search_options);
 }
 /**
  * Replaces the default "After Logout" URL
  *
  * @since  1.0.0
  *
  * @param  string $url
  * @return string
  */
 public function filter_url_after_logout($url, $enforce)
 {
     if (!$enforce) {
         $model = self::model();
         $new_url = $model->get('redirect_logout');
         if (!empty($new_url)) {
             $url = lib2()->net->expand_url($new_url);
         }
     }
     return $url;
 }
 /**
  * Adds activation details for a single add-on to the import object
  *
  * @since  1.0.0
  * @param  string $name The add-on name
  */
 protected function activate_addon($name)
 {
     $this->data->settings['addons'] = lib2()->array->get($this->data->settings['addons']);
     $this->data->settings['addons'][$name] = true;
 }
    public function to_html()
    {
        /**
         * Provide a customized invoice.
         *
         * @since  1.0.0
         */
        $html = apply_filters('ms_shortcode_custom_invoice', '', $this->data);
        if (!empty($html)) {
            return $html;
        } else {
            $html = '';
        }
        $invoice = $this->data['invoice'];
        $member = $this->data['member'];
        $subscription = $this->data['ms_relationship'];
        $membership = $this->data['membership'];
        $gateway = $this->data['gateway'];
        $is_free = false;
        $invoice_number = $invoice->get_invoice_number();
        $inv_title = sprintf('<a href="%s">%s</a>', get_permalink($invoice->id), esc_html(__('Invoice ', MS_TEXT_DOMAIN) . $invoice_number));
        if ($invoice->amount > 0) {
            $inv_amount = sprintf('%1$s %2$s', $invoice->currency, MS_Helper_Billing::format_price($invoice->amount));
        } else {
            $inv_amount = __('Free', MS_TEXT_DOMAIN);
            $is_free = true;
        }
        if ($invoice->tax) {
            $inv_taxes = sprintf('%s %s', $invoice->currency, MS_Helper_Billing::format_price($invoice->tax));
        } else {
            $inv_taxes = '';
        }
        if ($invoice->discount) {
            $inv_discount = sprintf('%s -%s', $invoice->currency, MS_Helper_Billing::format_price($invoice->discount));
        } else {
            $inv_discount = '';
        }
        if ($invoice->pro_rate) {
            $inv_pro_rate = sprintf('%s -%s', $invoice->currency, MS_Helper_Billing::format_price($invoice->pro_rate));
        } else {
            $inv_pro_rate = '';
        }
        $inv_total = sprintf('%s %s', $invoice->currency, MS_Helper_Billing::format_price($invoice->total));
        $inv_title = apply_filters('ms_invoice_title', $inv_title, $invoice);
        $inv_from = apply_filters('ms_invoice_sender', MS_Plugin::instance()->settings->invoice_sender_name, $invoice);
        $inv_to = apply_filters('ms_invoice_recipient', $member->username, $invoice, $member);
        $inv_status = apply_filters('ms_invoice_status', $invoice->status_text(), $invoice);
        $inv_item_name = apply_filters('ms_invoice_item_name', $membership->name, $invoice, $membership);
        $inv_amount = apply_filters('ms_invoice_amount', $inv_amount, $invoice);
        $inv_taxes = apply_filters('ms_invoice_taxes', $inv_taxes, $invoice);
        $inv_discount = apply_filters('ms_invoice_discount', $inv_discount, $invoice);
        $inv_pro_rate = apply_filters('ms_invoice_pro_rate', $inv_pro_rate, $invoice);
        $inv_total = apply_filters('ms_invoice_total', $inv_total, $invoice);
        $inv_details = apply_filters('ms_invoice_description', $invoice->description, $invoice, null);
        $inv_date = apply_filters('ms_invoice_date', MS_Helper_Period::format_date($invoice->invoice_date), $invoice, null);
        $inv_due_date = apply_filters('ms_invoice_due_date', MS_Helper_Period::format_date($invoice->due_date), $invoice, null);
        if ($invoice->uses_trial) {
            $trial_date = apply_filters('ms_invoice_trial_date', MS_Helper_Period::get_period_desc($membership->trial_period, true), $trial_invoice, $invoice);
            $trial_date .= sprintf(' <small>(%s %s)</small>', __('ends on', MS_TEXT_DOMAIN), MS_Helper_Period::format_date($invoice->trial_ends));
        } else {
            $trial_date = '';
        }
        ob_start();
        ?>
		<div class="entry-content ms-invoice" id="invoice">
			<?php 
        /**
         * We hardcode the CSS styles into this file, because the shortcode
         * is also used in Emails, which usually do not load remote CSS
         * files by default...
         */
        ?>
			<style>
			#invoice table, th, td { margin: 0; font-size: 14px; }
			#invoice table { padding: 0; width: 520px; border: 1px solid #DDD; background-color: #FFF; box-shadow: 0 1px 8px #F0F0F0; }
			#invoice th, td { border: 0; padding: 8px; }
			#invoice th { font-weight: bold; text-align: left; text-transform: none; font-size: 13px; }
			#invoice tr.alt { background-color: #F9F9F9; }
			#invoice tr.sep th,
			#invoice tr.sep td { border-top: 1px solid #DDD; padding-top: 16px; }
			#invoice tr.space th,
			#invoice tr.space td { padding-bottom: 16px; }
			#invoice tr.ms-inv-sep th,
			#invoice tr.ms-inv-sep td { line-height: 1px; height: 1px; padding: 0; border-bottom: 1px solid #DDD; background-color: #F9F9F9; }
			#invoice .ms-inv-total .ms-inv-price { font-weight: bold; font-size: 18px; text-align: right; }
			#invoice h2 { text-align: right; padding: 10px 10px 0 0; }
			#invoice h2 a { color: #000; }
			<?php 
        do_action('ms_invoice_css');
        ?>
			</style>

			<div class="ms-invoice-details ms-status-<?php 
        echo esc_attr($invoice->status);
        ?>
">
				<table class="ms-purchase-table">
					<tr class="ms-inv-title">
						<td colspan="2"><h2><?php 
        echo $inv_title;
        ?>
</h2></td>
					</tr>

					<?php 
        if (!empty($inv_from)) {
            ?>
						<tr class="ms-inv-from">
							<th><?php 
            _e('Sender', MS_TEXT_DOMAIN);
            ?>
</th>
							<td class="ms-inv-text"><?php 
            echo $inv_from;
            ?>
</td>
						</tr>
					<?php 
        }
        ?>

					<tr class="ms-inv-to">
						<th><?php 
        _e('Invoice to', MS_TEXT_DOMAIN);
        ?>
</th>
						<td class="ms-inv-text"><?php 
        echo $inv_to;
        ?>
</td>
					</tr>
					<tr class="ms-inv-invoice-date">
						<th><?php 
        _e('Invoice date', MS_TEXT_DOMAIN);
        ?>
</th>
						<td class="ms-inv-date"><?php 
        echo $inv_date;
        ?>
</td>
					</tr>
					<?php 
        if (!empty($trial_date)) {
            ?>
						<tr class="ms-inv-trial-end-date">
							<th><?php 
            _e('Trial period', MS_TEXT_DOMAIN);
            ?>
</th>
							<td class="ms-inv-date"><?php 
            echo $trial_date;
            ?>
</td>
						</tr>
					<?php 
        }
        ?>
					<tr class="ms-inv-status space">
						<th><?php 
        _e('Status', MS_TEXT_DOMAIN);
        ?>
</th>
						<td class="ms-inv-text"><?php 
        echo $inv_status;
        ?>
</td>
					</tr>
					<tr class="ms-inv-item-name alt sep">
						<th><?php 
        _e('Name', MS_TEXT_DOMAIN);
        ?>
</th>
						<td class="ms-inv-text"><?php 
        echo $inv_item_name;
        ?>
</td>
					</tr>

					<?php 
        if (!empty($inv_details)) {
            ?>
					<tr class="ms-inv-description alt">
						<th><?php 
            _e('Description', MS_TEXT_DOMAIN);
            ?>
</th>
						<td class="ms-inv-text"><?php 
            echo $inv_details;
            ?>
</td>
					</tr>
					<?php 
        }
        ?>

					<tr class="ms-inv-amount alt space">
						<th><?php 
        _e('Amount', MS_TEXT_DOMAIN);
        ?>
</th>
						<td class="ms-inv-price"><?php 
        echo $inv_amount;
        ?>
</td>
					</tr>

					<?php 
        $sep = 'sep';
        ?>

					<?php 
        if (!empty($inv_discount)) {
            ?>
						<tr class="ms-inv-discount <?php 
            echo esc_attr($sep);
            $sep = '';
            ?>
">
							<th><?php 
            _e('Coupon discount', MS_TEXT_DOMAIN);
            ?>
</th>
							<td class="ms-inv-price"><?php 
            echo $inv_discount;
            ?>
</td>
						</tr>
					<?php 
        }
        ?>

					<?php 
        if (!empty($inv_pro_rate)) {
            ?>
						<tr class="ms-inv-pro-rate <?php 
            echo esc_attr($sep);
            $sep = '';
            ?>
">
							<th><?php 
            _e('Pro rate discount', MS_TEXT_DOMAIN);
            ?>
</th>
							<td class="ms-inv-price"><?php 
            echo $inv_pro_rate;
            ?>
</td>
						</tr>
					<?php 
        }
        ?>

					<?php 
        if (!empty($inv_taxes)) {
            ?>
						<tr class="ms-inv-tax <?php 
            echo esc_attr($sep);
            $sep = '';
            ?>
">
							<th><?php 
            printf(__('Taxes %s', MS_TEXT_DOMAIN), '<small>(' . $invoice->tax_name . ')</small>');
            ?>
</th>
							<td class="ms-inv-price"><?php 
            echo $inv_taxes;
            ?>
</td>
						</tr>
					<?php 
        }
        ?>

					<?php 
        if (!$is_free) {
            ?>
						<tr class="ms-inv-due-date <?php 
            echo esc_attr($sep);
            $sep = '';
            ?>
">
							<th><?php 
            _e('Payment due', MS_TEXT_DOMAIN);
            ?>
</th>
							<td class="ms-inv-date"><?php 
            echo $inv_due_date;
            ?>
</td>
						</tr>
					<?php 
        }
        ?>
					<tr class="ms-inv-total <?php 
        echo esc_attr($sep);
        $sep = '';
        ?>
">
						<th><?php 
        _e('Total', MS_TEXT_DOMAIN);
        ?>
</th>
						<td class="ms-inv-price"><?php 
        echo $inv_total;
        ?>
</td>
					</tr>

					<?php 
        $show_button = lib2()->is_true($this->data['pay_button']);
        if ($invoice->is_paid()) {
            // Invoice is already paid. We don't need a payment
            // button...
            $show_button = false;
        }
        if ($show_button) {
            ?>
						<tr class="ms-inv-sep sep"><td colspan="2"></td></tr>
						<?php 
            do_action('ms_view_shortcode_invoice_purchase_button', $subscription, $invoice);
        }
        ?>
				</table>
			</div>
		</div>
		<?php 
        $html = ob_get_clean();
        $html = apply_filters('ms_compact_code', $html);
        return apply_filters('ms_shortcode_invoice', $html, $this->data);
    }
 /**
  * Append data to the popup javascript-variable.
  *
  * @since  4.6
  * @param  array $data Data collection that is printed to javascript.
  * @param  IncPopupItem $popup The original popup object.
  * @return array Modified data collection.
  */
 public function append_data_on_click($script_data, $popup)
 {
     $script_data = lib2()->array->get($script_data);
     if ('click' == $popup->display) {
         if (!isset($script_data['script'])) {
             $script_data['script'] = '';
         }
         $script_data['script'] .= 'me.custom_handler = ' . $this->script_on_click();
     }
     return $script_data;
 }
 /**
  * Echo HTML separator element.
  * Vertical separators will be on the right side of the parent element.
  *
  * @since  1.0.0
  *
  * @param  string $type Either 'horizontal' or 'vertical'
  */
 public static function html_separator($type = 'horizontal')
 {
     lib2()->html->element(array('type' => self::TYPE_HTML_SEPARATOR, 'value' => $type));
 }
 /**
  * Returns a static export-ID for the given type.
  *
  * The export-ID will be same during this request but may change in the next
  * export. This ID ensures that all links inside the export file are valid
  * but that we do not use actual WordPress IDs.
  *
  * @since  1.0.0
  * @param  string $type Type
  * @param  int $internal_id WordPress ID
  * @return int Export-ID
  */
 protected function exp_id($type, $internal_id)
 {
     static $Counter = 10000;
     static $Ids = array();
     $Ids[$type] = lib2()->array->get($Ids[$type]);
     if (!isset($Ids[$type][$internal_id])) {
         $Ids[$type][$internal_id] = $Counter;
         $Counter += 1;
     }
     return $Ids[$type][$internal_id];
 }
 /**
  * Adds CSS and JS for Membership special pages used in the front end.
  *
  * @since  1.0.0
  *
  * @return void
  */
 public function enqueue_scripts()
 {
     do_action('ms_controller_frontend_enqueue_scripts', $this->get_signup_step(), $this->get_action(), $this);
     $is_ms_page = MS_Model_Pages::is_membership_page();
     $is_profile = self::ACTION_EDIT_PROFILE == $this->get_action() && MS_Model_Pages::is_membership_page(null, MS_Model_Pages::MS_PAGE_ACCOUNT);
     if ($is_ms_page) {
         $data = array('ms_init' => array('shortcode'), 'cancel_msg' => __('Are you sure you want to cancel?', MS_TEXT_DOMAIN));
         lib2()->ui->css('ms-styles');
         lib2()->ui->js('jquery-validate');
         lib2()->ui->js('ms-public');
         MS_Controller_Plugin::translate_jquery_validator();
         if ($is_profile) {
             $data['ms_init'][] = 'frontend_profile';
         }
         lib2()->ui->data('ms_data', $data);
     }
 }
 /**
  * Prepare the fields that are displayed in the form.
  *
  * @since  1.0.1.0
  * @return array
  */
 protected function get_fields()
 {
     $comm = $this->data['comm'];
     $membership = false;
     $membership_id = 0;
     if (isset($this->data['membership'])) {
         $membership = $this->data['membership'];
         if ($membership instanceof MS_Model_Membership) {
             $membership_id = $membership->id;
         } else {
             $membership = false;
         }
     }
     lib2()->array->equip($comm, 'type', 'enabled', 'period', 'subject', 'description', 'cc_enabled', 'cc_email');
     $action = MS_Controller_Communication::AJAX_ACTION_UPDATE_COMM;
     $nonce = wp_create_nonce($action);
     $comm_titles = MS_Model_Communication::get_communication_type_titles($membership);
     $key_active = __('Send Email', MS_TEXT_DOMAIN);
     $key_inactive = __('No Email', MS_TEXT_DOMAIN);
     $key_skip = __('Use default template', MS_TEXT_DOMAIN);
     $titles = array($key_active => array(), $key_inactive => array(), $key_skip => array());
     foreach ($comm_titles as $type => $title) {
         $tmp_comm = MS_Model_Communication::get_communication($type, $membership, true);
         if ($membership && !$tmp_comm->override) {
             $titles[$key_skip][$type] = $title;
         } elseif ($tmp_comm->enabled) {
             $titles[$key_active][$type] = $title;
         } else {
             $titles[$key_inactive][$type] = $title;
         }
     }
     $fields = array('comm_type' => array('id' => 'comm_type', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $comm->type, 'field_options' => $titles), 'switch_comm_type' => array('id' => 'switch_comm_type', 'type' => MS_Helper_Html::INPUT_TYPE_BUTTON, 'value' => __('Load Template', MS_TEXT_DOMAIN)), 'override' => array('id' => 'override', 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'value' => $comm->override, 'before' => __('Use default template', MS_TEXT_DOMAIN), 'after' => __('Define custom template', MS_TEXT_DOMAIN), 'wrapper_class' => 'ms-block ms-tcenter', 'class' => 'override-slider', 'ajax_data' => array('type' => $comm->type, 'field' => 'override', 'action' => $action, '_wpnonce' => $nonce, 'membership_id' => $membership_id)), 'membership_id' => array('id' => 'membership_id', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $membership_id), 'type' => array('id' => 'type', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $comm->type), 'enabled' => array('id' => 'enabled', 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'value' => $comm->enabled, 'class' => 'state-slider', 'before' => '&nbsp;<i class="wpmui-fa wpmui-fa-ban"></i>', 'after' => '<i class="wpmui-fa wpmui-fa-envelope"></i>&nbsp;', 'ajax_data' => array('type' => $comm->type, 'field' => 'enabled', 'action' => $action, '_wpnonce' => $nonce, 'membership_id' => $membership_id)), 'period_unit' => array('id' => 'period_unit', 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'title' => __('Period after/before', MS_TEXT_DOMAIN), 'value' => $comm->period['period_unit']), 'period_type' => array('id' => 'period_type', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $comm->period['period_type'], 'field_options' => MS_Helper_Period::get_period_types('plural')), 'subject' => array('id' => 'subject', 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'title' => apply_filters('ms_translation_flag', __('Message Subject', MS_TEXT_DOMAIN), 'communication-subject'), 'value' => $comm->subject, 'class' => 'ms-comm-subject widefat'), 'email_body' => array('id' => 'email_body', 'type' => MS_Helper_Html::INPUT_TYPE_WP_EDITOR, 'title' => apply_filters('ms_translation_flag', '', 'communication-body'), 'value' => $comm->description, 'field_options' => array('media_buttons' => false, 'editor_class' => 'wpmui-ajax-update')), 'cc_enabled' => array('id' => 'cc_enabled', 'type' => MS_Helper_Html::INPUT_TYPE_CHECKBOX, 'title' => __('Send copy to Administrator', MS_TEXT_DOMAIN), 'value' => $comm->cc_enabled, 'class' => 'ms-inline-block'), 'cc_email' => array('id' => 'cc_email', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $comm->cc_email, 'field_options' => MS_Model_Member::get_admin_user_emails()), 'save_email' => array('id' => 'save_email', 'value' => __('Save Changes', MS_TEXT_DOMAIN), 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT), 'action' => array('id' => 'action', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => 'save_comm'), 'nonce' => array('id' => '_wpnonce', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => wp_create_nonce('save_comm')), 'load_action' => array('id' => 'load_action', 'name' => 'action', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => 'load_action'), 'load_nonce' => array('id' => '_wpnonce1', 'name' => '_wpnonce', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => wp_create_nonce('load_action')));
     if (!$membership instanceof MS_Model_Membership) {
         unset($fields['override']);
         unset($fields['membership_id']);
     }
     return apply_filters('ms_view_settings_prepare_email_fields', $fields);
 }
 /**
  * Load specific scripts.
  *
  * @since  1.0.0
  */
 public function enqueue_scripts()
 {
     $data = array('ms_init' => array('view_help'));
     lib2()->ui->data('ms_data', $data);
     wp_enqueue_script('ms-admin');
 }
 /**
  * Update and return the $settings array to save the form values.
  *
  * @since  4.6
  * @param  array $data The contents of $_POST['po_rule_data'].
  * @return mixed Data collection of this rule.
  */
 protected function save_count($data)
 {
     lib2()->array->equip($data, 'count');
     $count = absint($data['count']);
     if ($count < 1) {
         $count = 1;
     }
     return $count;
 }
 /**
  * Update and return the $settings array to save the form values.
  *
  * @since  4.6
  * @param  array $data The contents of $_POST['po_rule_data'].
  * @return mixed Data collection of this rule.
  */
 protected function save_no_referrer($data)
 {
     lib2()->array->equip($data, 'no_referrer');
     return explode("\n", $data['no_referrer']);
 }