/**
     * Returns the HTML code of the view.
     *
     * @since  1.0.0
     * @api
     *
     * @return string
     */
    public function to_html()
    {
        $model = MS_Factory::create('MS_Model_Import_Membership');
        $model->prepare();
        $view = MS_Factory::create('MS_View_Settings_Import');
        $view->data = array('model' => $model, 'compact' => true);
        $msg = __('Tip: You can also import your data later by visiting the Admin page <b>Membership2 > Settings > Import Tool</b>.', 'membership2');
        ob_start();
        // Render tabbed interface.
        ?>
		<div class="ms-wrap wrap">
			<h2>
				<?php 
        _e('Import Your Membership Data To Membership2', 'membership2');
        ?>
			</h2>
			<?php 
        if (MS_Plugin::is_network_wide()) {
            $msg .= '<br><br>' . __('You have enabled Network Wide Protection. We will import Membership data from your main blog.', 'membership2');
        }
        lib3()->ui->admin_message($msg, 'info');
        ?>
			<div class="ms-settings-import">
				<?php 
        echo $view->to_html();
        ?>
			</div>
		</div>
		<?php 
        return ob_get_clean();
    }
    /**
     * Create view output.
     *
     * @since  1.0.0
     *
     * @return string
     */
    public function to_html()
    {
        $coupon_list = MS_Factory::create('MS_Addon_Coupon_Helper_Listtable');
        $coupon_list->prepare_items();
        $title = __('Coupons', MS_TEXT_DOMAIN);
        $add_new_button = array('id' => 'add_new', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url('coupons', array('action' => 'edit', 'coupon_id' => 0)), 'value' => __('Add New Coupon', MS_TEXT_DOMAIN), 'class' => 'button');
        ob_start();
        ?>
		<div class="wrap ms-wrap">
			<?php 
        MS_Helper_Html::settings_header(array('title' => $title, 'title_icon_class' => 'wpmui-fa wpmui-fa-credit-card'));
        ?>
			<div>
				<?php 
        MS_Helper_Html::html_element($add_new_button);
        ?>
			</div>

			<form action="" method="post">
				<?php 
        $coupon_list->display();
        ?>
			</form>
		</div>

		<?php 
        $html = ob_get_clean();
        return apply_filters('ms_addon_coupon_view_list_to_html', $html, $this);
    }
    public function to_html()
    {
        $this->check_simulation();
        // Search for orphaned relationships and delete them.
        MS_Model_Member::clean_db();
        $listview = MS_Factory::create('MS_Helper_ListTable_Member');
        $listview->prepare_items();
        ob_start();
        ?>

		<div class="wrap ms-wrap ms-member-list">
			<?php 
        MS_Helper_Html::settings_header(array('title' => __('Members', MS_TEXT_DOMAIN), 'title_icon_class' => 'wpmui-fa wpmui-fa-users', 'desc' => __('Here you can manage the Memberships of existing Users.', MS_TEXT_DOMAIN)));
        // Display a filter to switch between individual memberships.
        $this->membership_filter();
        $listview->views();
        $listview->search_box();
        ?>
			<form method="post">
				<?php 
        $listview->display();
        ?>
			</form>
		</div>

		<?php 
        $html = ob_get_clean();
        return $html;
    }
    /**
     * Create view output.
     *
     * @since  1.0.0
     * @return string
     */
    public function to_html()
    {
        $list_table = MS_Factory::create('MS_Helper_ListTable_Event');
        $list_table->prepare_items();
        if (isset($_REQUEST['membership_id'])) {
            $membership = MS_Factory::load('MS_Model_Membership', $_REQUEST['membership_id']);
            $title = sprintf(__('%s News', 'membership2'), $membership->get_name_tag());
            $url = esc_url_raw(add_query_arg(array('step' => MS_Controller_Membership::STEP_OVERVIEW), remove_query_arg(array('paged', 'order', 'post_mime_type', 'detached', 'orderby', 's'))));
            $back_link = array('id' => 'back', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'value' => __('&raquo; Back to Overview', 'membership2'), 'url' => $url, 'class' => 'wpmui-field-button button');
        } else {
            $title = __('Membership News', 'membership2');
            $back_link = '';
        }
        ob_start();
        ?>

		<div class="wrap ms-wrap ms-membership-news">
			<?php 
        MS_Helper_Html::settings_header(array('title' => $title));
        MS_Helper_Html::html_element($back_link);
        $list_table->search_box();
        $list_table->views();
        ?>
			<form action="" method="post">
				<?php 
        $list_table->display();
        ?>
			</form>
		</div>

		<?php 
        $html = ob_get_clean();
        echo '' . $html;
    }
    /**
     * Create view output.
     *
     * @since  1.0.0
     * @return string
     */
    public function to_html()
    {
        $this->check_simulation();
        $membership = $this->data['membership'];
        $admin_message = MS_Helper_Membership::get_admin_message(array($membership->name), $membership);
        $title = MS_Helper_Membership::get_admin_title();
        $membership_list = MS_Factory::create('MS_Helper_ListTable_Membership');
        $membership_list->prepare_items();
        $create_new_button = array('id' => 'create_new_ms_button', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => $this->data['create_new_url'], 'value' => __('Create New Membership', MS_TEXT_DOMAIN), 'class' => 'button');
        ob_start();
        ?>

		<div class="wrap ms-wrap">
			<?php 
        MS_Helper_Html::settings_header(array('title' => $title, 'desc' => array(__('Here you can view and edit all the Memberships you have created.', MS_TEXT_DOMAIN), $admin_message)));
        ?>
			<form action="" method="post">
				<div class="ms-list-table-wrapper ms-membership-list">
					<?php 
        MS_Helper_Html::html_element($create_new_button);
        $membership_list->display();
        MS_Helper_Html::html_element($create_new_button);
        ?>
				</div>
			</form>
		</div>

		<?php 
        $html = ob_get_clean();
        echo $html;
    }
    public function to_html()
    {
        $settings = $this->data['settings'];
        $fields = array('plugin_enabled' => array('id' => 'plugin_enabled', 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'title' => __('Content Protection', 'membership2'), 'desc' => __('This setting toggles the content protection on this site.', 'membership2'), 'value' => MS_Plugin::is_enabled(), 'data_ms' => array('action' => MS_Controller_Settings::AJAX_ACTION_TOGGLE_SETTINGS, 'setting' => 'plugin_enabled')), 'hide_admin_bar' => array('id' => 'hide_admin_bar', 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'title' => __('Hide admin toolbar', 'membership2'), 'desc' => __('Hide the admin toolbar for non administrator users.', 'membership2'), 'value' => $settings->hide_admin_bar, 'data_ms' => array('action' => MS_Controller_Settings::AJAX_ACTION_TOGGLE_SETTINGS, 'setting' => 'hide_admin_bar')));
        $fields = apply_filters('ms_view_settings_prepare_general_fields', $fields);
        $setup = MS_Factory::create('MS_View_Settings_Page_Setup');
        $action_url = esc_url_raw(remove_query_arg(array('msg')));
        ob_start();
        MS_Helper_Html::settings_tab_header();
        ?>

		<form action="<?php 
        echo esc_url($action_url);
        ?>
" method="post" class="cf">
			<div class="cf">
				<div class="ms-half">
					<?php 
        MS_Helper_Html::html_element($fields['plugin_enabled']);
        ?>
				</div>
				<div class="ms-half">
					<?php 
        MS_Helper_Html::html_element($fields['hide_admin_bar']);
        ?>
				</div>
			</div>
			<?php 
        MS_Helper_Html::html_separator();
        MS_Helper_Html::html_element($setup->html_full_form());
        ?>
		</form>
		<?php 
        return ob_get_clean();
    }
    /**
     * Create view output.
     *
     * @since  1.0.0
     *
     * @return string
     */
    public function to_html()
    {
        $code_list = MS_Factory::create('MS_Addon_Invitation_Helper_Listtable');
        $code_list->prepare_items();
        $title = __('Invitations', 'membership2');
        $add_new_button = array('id' => 'add_new', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url(MS_Addon_Invitation::SLUG, array('action' => 'edit', 'invitation_id' => 0)), 'value' => __('Add New Code', 'membership2'), 'class' => 'button');
        ob_start();
        ?>
		<div class="wrap ms-wrap">
			<?php 
        MS_Helper_Html::settings_header(array('title' => $title, 'title_icon_class' => 'wpmui-fa wpmui-fa-ticket'));
        ?>
			<div>
				<?php 
        MS_Helper_Html::html_element($add_new_button);
        ?>
			</div>

			<form action="" method="post">
				<?php 
        $code_list->display();
        ?>
			</form>
			<p><em>
				<?php 
        _e('By default all Memberships are protected and require an invitation code to register.<br>You can manually change this for individual memberships via a new setting in the "Payment Options" settings of each membership.', 'membership2');
        ?>
			</em></p>
		</div>

		<?php 
        $html = ob_get_clean();
        return apply_filters('ms_addon_invitation_view_list_to_html', $html, $this);
    }
 /**
  * Ajax handler. Handles incoming form data that was submitted via ajax.
  * Typically this form is displayed inside a popup.
  *
  * @since  1.0.0
  * @access public
  */
 public function ajax_submit()
 {
     $data = '';
     if (isset($_REQUEST['dialog'])) {
         $dialog = $_REQUEST['dialog'];
         $dlg = MS_Factory::create('MS_' . $dialog);
         $data = $dlg->submit();
     }
     $this->respond($data);
 }
 /**
  * Load and render the Documentation view.
  *
  * @since  1.0.0
  */
 public function admin_page()
 {
     /**
      * Create / Filter the view.
      *
      * @since  1.0.0
      * @param object $this The MS_Controller_Help object.
      */
     $view = MS_Factory::create('MS_View_Help');
     $data = array();
     $data['tabs'] = $this->get_tabs();
     $view->data = apply_filters('ms_view_help_data', $data);
     $view->render();
 }
 /**
  * Displays a PopUp to the user that shows a sumary of the setup wizard
  * including possible next steps for configuration.
  *
  * @since  1.0.0
  * @param  MS_Model_Membership $membership The membership that was created.
  */
 public static function show_setup_note($membership)
 {
     $popup = array();
     $popup['title'] = sprintf('<i class="dashicons dashicons-yes"></i> %1$s<div class="subtitle">%2$s</div>', __('Congratulations!', 'membership2'), sprintf(__('You have successfully set up your <b>%1$s</b> Membership.', 'membership2'), $membership->name));
     $setup = MS_Factory::create('MS_View_Settings_Page_Setup');
     $popup['modal'] = true;
     $popup['close'] = false;
     $popup['sticky'] = false;
     $popup['class'] = 'ms-setup-done';
     $popup['body'] = $setup->to_html();
     $popup['height'] = $setup->dialog_height();
     $popup['body'] .= sprintf('<div class="buttons">' . '<a href="%s" class="button">%s</a> ' . '<button type="button" class="button-primary close">%s</button>' . '</div>', MS_Controller_Plugin::get_admin_url('protection'), __('Set-up Access Levels', 'membership2'), __('Finish', 'membership2'));
     lib3()->html->popup($popup);
     $settings = MS_Plugin::instance()->settings;
     $settings->is_first_membership = false;
     if (!$membership->is_free) {
         $settings->is_first_paid_membership = false;
     }
     $settings->save();
 }
 /**
  * Display a welcome screen.
  *
  * @since  1.0.0
  */
 public function page_welcome()
 {
     $data = array();
     $data['step'] = $this->get_step();
     $data['action'] = 'start';
     $view = MS_Factory::create('MS_View_Welcome');
     $view->data = apply_filters('ms_view_welcome_data', $data, $this);
     $view->render();
 }
 /**
  * Callback function from 'Membership' navigation.
  *
  * Menu Item: Membership > Settings
  *
  * @since  1.0.0
  */
 public function admin_page()
 {
     $hook = 'ms_controller_settings-' . $this->active_tab;
     do_action($hook);
     $view = MS_Factory::create('MS_View_Settings_Edit');
     $view = apply_filters($hook . '_view', $view);
     $data = array();
     $data['tabs'] = $this->get_tabs();
     $data['settings'] = $this->get_model();
     $data['message'] = self::_message();
     if (isset($data['message']['error'])) {
         lib3()->ui->admin_message($data['message']['error'], 'err');
     }
     switch ($this->get_active_tab()) {
         case self::TAB_EMAILS:
             $type = MS_Model_Communication::COMM_TYPE_REGISTRATION;
             $temp_type = isset($_GET['comm_type']) ? $_GET['comm_type'] : '';
             if (MS_Model_Communication::is_valid_communication_type($temp_type)) {
                 $type = $temp_type;
             }
             $comm = MS_Model_Communication::get_communication($type);
             $data['comm'] = $comm;
             break;
     }
     $data = array_merge($data, $view->data);
     $view->data = apply_filters($hook . '_data', $data);
     $view->model = $this->get_model();
     $view->render();
 }
Пример #13
0
 /**
  * Manage user account actions.
  *
  * @since  1.0.0
  * @internal
  */
 public function user_account_manager()
 {
     $action = $this->get_action();
     $member = MS_Model_Member::get_current_member();
     /**
      * These actions are always executed when any user account page loads.
      *
      * @since  1.0.1.0
      */
     do_action('ms_frontend_user_account_manager-' . $action, $this);
     do_action('ms_frontend_user_account_manager', $action, $this);
     if ($this->verify_nonce()) {
         /**
          * The following two actions are only executed when a form was
          * submitted on a user account page.
          *
          * @since  1.0.1.0
          */
         do_action('ms_frontend_user_account_manager_submit-' . $action, $this);
         do_action('ms_frontend_user_account_manager_submit', $action, $this);
     }
     switch ($action) {
         case self::ACTION_EDIT_PROFILE:
             $data = array();
             if ($this->verify_nonce()) {
                 if (is_array($_POST)) {
                     foreach ($_POST as $field => $value) {
                         $member->{$field} = $value;
                     }
                 }
                 try {
                     $member->validate_member_info();
                     $member->save();
                     wp_safe_redirect(esc_url_raw(remove_query_arg('action')));
                     exit;
                 } catch (Exception $e) {
                     $data['errors'] = $e->getMessage();
                 }
             }
             $view = MS_Factory::create('MS_View_Frontend_Profile');
             $data['member'] = $member;
             $data['action'] = $action;
             $view->data = apply_filters('ms_view_frontend_profile_data', $data, $this);
             $view->add_filter('the_content', 'to_html', 1);
             break;
         case self::ACTION_VIEW_INVOICES:
             $data['invoices'] = MS_Model_Invoice::get_public_invoices($member->id);
             $view = MS_Factory::create('MS_View_Frontend_Invoices');
             $view->data = apply_filters('ms_view_frontend_frontend_invoices', $data, $this);
             $view->add_filter('the_content', 'to_html', 1);
             break;
         case self::ACTION_VIEW_ACTIVITIES:
             $data['events'] = MS_Model_Event::get_events(array('author' => $member->id, 'posts_per_page' => -1));
             $view = MS_Factory::create('MS_View_Frontend_Activities');
             $view->data = apply_filters('ms_view_frontend_frontend_activities', $data, $this);
             $view->add_filter('the_content', 'to_html', 1);
             break;
         case self::ACTION_VIEW_RESETPASS:
             /**
              * Reset password action.
              * This action is accessed via the password-reset email
              * @see  class-ms-controller-dialog.php
              *
              * The action is targeted to the Account-page but actually calls
              * the Login-Shortcode.
              */
             $view = MS_Factory::create('MS_View_Shortcode_Login');
             $view->data = array('action' => 'resetpass');
             $view->add_filter('the_content', 'to_html', 1);
             break;
         default:
             // Do nothing...
             break;
     }
 }
 /**
  * Import specific data: A single membership
  *
  * @since  1.0.0
  * @param  object $obj The import object
  */
 public function import_membership($obj)
 {
     $membership = MS_Factory::create('MS_Model_Membership');
     $this->populate_membership($membership, $obj);
     $membership->save();
     $this->store_import_obj('membership', $obj->id, $membership);
 }
 /**
  * Load and render the Add-on manager view.
  *
  * @since  1.0.0
  */
 public function admin_page()
 {
     // Reload the add-on list.
     do_action('ms_model_addon_flush');
     /**
      * Create / Filter the Addon admin view.
      *
      * @since  1.0.0
      * @param object $this The MS_Controller_Addon object.
      */
     $view = MS_Factory::create('MS_View_Addon');
     $data = array('addon' => MS_Factory::load('MS_Model_Addon'));
     $view->data = apply_filters('ms_view_addon_data', $data);
     $view->render();
 }
 /**
  * Helper function called by create_ms_relationship()
  *
  * @since  1.0.0
  * @internal
  *
  * @return MS_Model_Relationship The created relationship.
  */
 private static function _create_ms_relationship($membership_id, $user_id, $gateway_id, $move_from_id)
 {
     $is_simulated = false;
     // Try to reuse existing db record to keep history.
     $subscription = self::get_subscription($user_id, $membership_id);
     if ('simulation' == $gateway_id) {
         $is_simulated = true;
         $gateway_id = 'admin';
         $subscription = false;
     }
     // Not found, create a new one.
     if (empty($subscription)) {
         $subscription = MS_Factory::create('MS_Model_Relationship');
         $subscription->status = self::STATUS_PENDING;
         $subscription->is_simulated = $is_simulated;
         if ($is_simulated) {
             $subscription->id = -1;
         }
     }
     // Always update these fields.
     $subscription->membership_id = $membership_id;
     $subscription->user_id = $user_id;
     $subscription->move_from_id = $move_from_id;
     $subscription->gateway_id = $gateway_id;
     $subscription->expire_date = '';
     // Set initial state.
     switch ($subscription->status) {
         case self::STATUS_DEACTIVATED:
             $subscription->status = self::STATUS_PENDING;
             break;
         case self::STATUS_TRIAL:
         case self::STATUS_TRIAL_EXPIRED:
         case self::STATUS_ACTIVE:
         case self::STATUS_EXPIRED:
         case self::STATUS_CANCELED:
             /* Once a member or have tried the membership, not
              * eligible to another trial period, unless the relationship
              * is permanetly deleted.
              */
             $subscription->trial_period_completed = true;
             break;
         case self::STATUS_PENDING:
         default:
             // Initial status
             $subscription->name = "user_id: {$user_id}, membership_id: {$membership_id}";
             $subscription->description = $subscription->name;
             $subscription->trial_period_completed = false;
             break;
     }
     $subscription->config_period();
     $membership = $subscription->get_membership();
     $subscription->payment_type = $membership->payment_type;
     if ('admin' == $gateway_id) {
         $subscription->trial_period_completed = true;
         $subscription->status = self::STATUS_ACTIVE;
         // Set the start/expire dates. Do this *after* the set_status() call!
         $subscription->config_period();
         if (!$subscription->is_system() && !$is_simulated) {
             // Create event.
             MS_Model_Event::save_event(MS_Model_Event::TYPE_MS_SIGNED_UP, $subscription);
         }
     }
     $subscription->save();
     return $subscription;
 }
Пример #17
0
 /**
  * Loads primary plugin controllers.
  *
  * Related Action Hooks:
  * - setup_theme
  *
  * @since  1.0.0
  */
 public function ms_plugin_constructing()
 {
     /**
      * Creates and Filters the Plugin Controller.
      *
      * ---> MAIN ENTRY POINT CONTROLLER FOR PLUGIN <---
      *
      * @uses  MS_Controller_Plugin
      * @since  1.0.0
      */
     $this->controller = MS_Factory::create('MS_Controller_Plugin');
 }
 /**
  * Main entry point: Processes the import/export action.
  *
  * This function is called by the settings-controller whenever the
  * Import/Export tab provides a correct nonce. We will first find out which
  * action to execute and then handle all the details...
  *
  * @since  1.0.0
  */
 public function process()
 {
     lib3()->array->equip_post('action', 'import_source');
     $action = $_POST['action'];
     if (isset($_POST['submit'])) {
         $action = $_POST['submit'];
     }
     switch ($action) {
         case self::ACTION_EXPORT:
             $handler = MS_Factory::create('MS_Model_Import_Export');
             $handler->process();
             break;
         case self::ACTION_PREVIEW:
             $view = MS_Factory::create('MS_View_Settings_Import');
             $model_name = 'MS_Model_Import_' . $_POST['import_source'];
             $model = null;
             try {
                 $model = MS_Factory::create($model_name);
             } catch (Exception $ex) {
                 self::_message('error', __('Coming soon: This import source is not supported yet...', 'membership2'));
             }
             if (is_a($model, 'MS_Model_Import')) {
                 if ($model->prepare()) {
                     $data = array('model' => $model);
                     $view->data = apply_filters('ms_view_import_data', $data);
                     self::_message('preview', apply_filters('ms_view_import_preview', $view->to_html()));
                 }
             }
             break;
     }
 }
 /**
  * Display Setup Membership2 page.
  *
  * @since  1.0.0
  */
 public function admin_page()
 {
     do_action('ms_controller_protection_admin_page');
     $data = array();
     $data['tabs'] = $this->get_available_tabs();
     $data['active_tab'] = $this->get_active_tab();
     $view = MS_Factory::create('MS_View_Protection');
     $view->data = apply_filters('ms_view_protection_data', $data, $this);
     $view->render();
 }
Пример #20
0
 /**
  * Create a rule model.
  *
  * @since  1.0.0
  * @param string $rule_type The rule type to create.
  * @param int $membership_id The Membership model this rule belongs to.
  * @param int $subscription_id The Subscription ID
  *
  * @return MS_Rule The rule model.
  * @throws Exception when rule type is not valid.
  */
 public static function rule_factory($rule_type, $membership_id, $subscription_id)
 {
     $rule_types = MS_Model_Rule::get_rule_type_classes();
     if (isset($rule_types[$rule_type])) {
         $class = $rule_types[$rule_type];
         $rule = MS_Factory::load($class, $membership_id, $subscription_id);
         $rule->_subscription_id = $subscription_id;
     } else {
         $rule = MS_Factory::create('MS_Rule', $membership_id);
     }
     return apply_filters('ms_rule_rule_factory', $rule, $rule_type, $membership_id);
 }
Пример #21
0
 /**
  * Saves transaction details to the database. The transaction logs can later
  * be displayed in the Billings section.
  *
  * @since  1.0.0
  * @internal Action handler for 'ms_gateway_transaction_log'
  *
  *
  * @param string $gateway_id The gateway ID.
  * @param string $method Following values:
  *        "handle": IPN response
  *        "process": Process order (i.e. user comes from Payment screen)
  *        "request": Automatically request recurring payment
  * @param bool $success True means that the transaction was paid/successful.
  *        False indicates an error.
  *        NULL indicates a message that was intentionally skipped.
  * @param int $subscription_id
  * @param int $invoice_id
  * @param float $amount Payment amount.
  * @param string $notes Additional text to describe the transaction or error.
  */
 public function log_transaction($gateway_id, $method, $success, $subscription_id, $invoice_id, $amount, $notes)
 {
     $log = MS_Factory::create('MS_Model_Transactionlog');
     $log->description = $notes;
     $log->gateway_id = $gateway_id;
     $log->method = $method;
     $log->success = $success;
     $log->subscription_id = $subscription_id;
     $log->invoice_id = $invoice_id;
     $log->amount = $amount;
     $log->save();
 }
 /**
  * Create invoice.
  *
  * Create a new invoice using the membership information.
  *
  * @since  1.0.0
  *
  * @param MS_Model_Relationship $subscription The membership to create invoice for.
  * @param int $invoice_number Optional. The invoice number.
  *
  * @return object $invoice
  */
 public static function create_invoice($subscription, $invoice_number = false)
 {
     $membership = $subscription->get_membership();
     if (!MS_Model_Membership::is_valid_membership($membership->id)) {
         throw new Exception('Invalid Membership.');
     }
     $invoice = null;
     $member = MS_Factory::load('MS_Model_Member', $subscription->user_id);
     $invoice_status = self::STATUS_NEW;
     $notes = null;
     if (empty($invoice_number)) {
         $invoice_number = $subscription->current_invoice_number;
     }
     $invoice = self::get_invoice($subscription->id, $invoice_number);
     // No existing invoice, create a new one.
     if (!$invoice || !$invoice->id) {
         $invoice = MS_Factory::create('MS_Model_Invoice');
         $invoice = apply_filters('ms_model_invoice', $invoice);
     }
     // Update invoice info.
     $invoice->ms_relationship_id = $subscription->id;
     $invoice->gateway_id = $subscription->gateway_id;
     $invoice->status = $invoice_status;
     $invoice->invoice_date = MS_Helper_Period::current_date();
     $invoice->membership_id = $membership->id;
     $invoice->currency = MS_Plugin::instance()->settings->currency;
     $invoice->user_id = $member->id;
     $invoice->name = apply_filters('ms_model_invoice_name', sprintf(__('Invoice for %s - %s', MS_TEXT_DOMAIN), $membership->name, $member->username));
     $invoice->invoice_number = $invoice_number;
     $invoice->discount = 0;
     $invoice->notes = $notes;
     $invoice->amount = $membership->price;
     // Without taxes!
     // Check for trial period in the first period.
     if ($subscription->is_trial_eligible() && $invoice_number === $subscription->current_invoice_number) {
         $invoice->trial_price = $membership->trial_price;
         // Without taxes!
         $invoice->uses_trial = true;
         $invoice->trial_ends = $subscription->trial_expire_date;
     }
     $invoice->set_due_date();
     $invoice = apply_filters('ms_model_invoice_create_before_save', $invoice, $subscription);
     $invoice->save();
     // Refresh the tax-rate and payment description.
     $invoice->total_amount_changed();
     $invoice->save();
     return apply_filters('ms_model_relationship_create_invoice', $invoice, $subscription, $invoice_number);
 }
 /**
  * Creates a new menu (not menu-item but whole menu).
  * All top-level pages are added automatically to this new menu.
  *
  * Related action hooks:
  * - wp_ajax_create_menu
  *
  * @since  1.0.0
  */
 public function ajax_action_create_menu()
 {
     $msg = MS_Helper_Settings::SETTINGS_MSG_NOT_UPDATED;
     $content = '';
     if ($this->verify_nonce() && $this->is_admin_user()) {
         MS_Model_Pages::create_default_menu();
         $setup = MS_Factory::create('MS_View_Settings_Page_Setup');
         $content = $setup->show_menu_controls();
         $msg = MS_Helper_Settings::SETTINGS_MSG_UPDATED;
     }
     echo $msg . ':' . $content;
     exit;
 }
 /**
  * Membership metabox callback function for displaying the UI.
  *
  * @since  1.0.0
  *
  * @param object $post The current post object.
  */
 public function membership_metabox($post)
 {
     $data = array();
     if (MS_Model_Pages::is_membership_page()) {
         $data['special_page'] = true;
     } else {
         $all_memberships = MS_Model_Membership::get_memberships();
         $base = MS_Model_Membership::get_base();
         $data['base_id'] = $base->id;
         // Find the post-type of the current post.
         if ('attachment' == $post->post_type) {
             $parent_id = $post->post_parent;
             $post_type = get_post_type($parent_id);
         } else {
             $post_type = $post->post_type;
         }
         // Get the base protection rule and check if post is protected.
         $rule = $this->get_rule($base, $post_type);
         $data['is_protected'] = !$rule->has_access($post->ID, false);
         $data['rule_type'] = $rule->rule_type;
         // Check each membership to see if the post is protected.
         foreach ($all_memberships as $membership) {
             if ($membership->is_base) {
                 continue;
             }
             $rule = $this->get_rule($membership, $post_type);
             $data['access'][$membership->id]['has_access'] = $rule->get_rule_value($post->ID);
             $data['access'][$membership->id]['name'] = $membership->name;
         }
     }
     $data['post_id'] = $post->ID;
     $data['read_only'] = $this->is_read_only($post->post_type);
     $view = MS_Factory::create('MS_View_Metabox');
     $view->data = apply_filters('ms_view_membership_metabox_data', $data, $this);
     $view->render();
 }
 /**
  * Render the Coupon admin manager.
  *
  * @since  1.0.0
  */
 public function admin_coupon()
 {
     $isset = array('action', 'coupon_id');
     if (self::validate_required($isset, 'GET', false) && 'edit' == $_GET['action']) {
         // Edit action view page request
         $coupon_id = !empty($_GET['coupon_id']) ? $_GET['coupon_id'] : 0;
         $data['coupon'] = MS_Factory::load('MS_Addon_Coupon_Model', $coupon_id);
         $data['memberships'] = array(__('Any', MS_TEXT_DOMAIN));
         $data['memberships'] += MS_Model_Membership::get_membership_names();
         $data['action'] = $_GET['action'];
         $view = MS_Factory::create('MS_Addon_Coupon_View_Edit');
         $view->data = apply_filters('ms_addon_coupon_view_edit_data', $data);
         $view->render();
     } else {
         // Coupon admin list page
         $view = MS_Factory::create('MS_Addon_Coupon_View_List');
         $view->render();
     }
 }
 /**
  * Membership invoice shortcode callback function.
  *
  * @since  1.0.0
  *
  * @param mixed[] $atts Shortcode attributes.
  */
 public function membership_invoice($atts)
 {
     MS_Helper_Shortcode::did_shortcode(MS_Helper_Shortcode::SCODE_MS_INVOICE);
     $data = apply_filters('ms_controller_shortcode_invoice_atts', shortcode_atts(array('post_id' => 0, 'id' => 0, 'pay_button' => 1), $atts, MS_Helper_Shortcode::SCODE_MS_INVOICE));
     if (!empty($data['id'])) {
         $data['post_id'] = $data['id'];
     }
     if (!empty($data['post_id'])) {
         $invoice = MS_Factory::load('MS_Model_Invoice', $data['post_id']);
         $subscription = MS_Factory::load('MS_Model_Relationship', $invoice->ms_relationship_id);
         $data['invoice'] = $invoice;
         $data['member'] = MS_Factory::load('MS_Model_Member', $invoice->user_id);
         $data['ms_relationship'] = $subscription;
         $data['membership'] = $subscription->get_membership();
         $data['gateway'] = MS_Model_Gateway::factory($invoice->gateway_id);
         $view = MS_Factory::create('MS_View_Shortcode_Invoice');
         $view->data = apply_filters('ms_view_shortcode_invoice_data', $data, $this);
         return $view->to_html();
     }
 }
 /**
  * Get default membership for all logged-in users that did not yet subscribe
  * to any membership.
  *
  * Create a new membership if membership does not exist.
  *
  * @since  1.0.0
  * @api
  *
  * @param  string $role A WordPress user-role.
  * @return MS_Model_Membership The guest membership.
  */
 public static function get_user()
 {
     static $User_Membership = null;
     if (null === $User_Membership) {
         $User_Membership = self::_get_system_membership(self::TYPE_USER, false);
     }
     if (!$User_Membership) {
         $User_Membership = MS_Factory::create('MS_Model_Membership');
     }
     return apply_filters('ms_model_membership_get_user', $User_Membership);
 }
 public function render_tab_type()
 {
     $tab = MS_Factory::create('MS_View_Membership_Tab_Type');
     $tab->data = $this->data;
     return $tab->to_html();
 }
 /**
  * Ajax action handler used by the transaction logs list to change a
  * transaction log entry.
  *
  * Returns a form to link a transaction with an invoice.
  *
  * @since  1.0.1.0
  */
 public function ajax_link_transaction()
 {
     $data = array();
     $resp = '';
     $fields = array('id');
     if (self::validate_required($fields) && $this->verify_nonce()) {
         $id = intval($_POST['id']);
         $log = MS_Factory::load('MS_Model_Transactionlog', $id);
         if ($log->member_id) {
             $data['member'] = $log->get_member();
         } else {
             $data['member'] = false;
         }
         $data['log'] = $log;
         $view = MS_Factory::create('MS_View_Billing_Link');
         $view->data = apply_filters('ms_view_billing_link_data', $data);
         $resp = $view->to_html();
     }
     echo $resp;
     exit;
 }
Пример #30
0
 /**
  * Get communication type object.
  *
  * Load from DB if exists, create a new one if not.
  *
  * @since  1.0.0
  *
  * @param  string $type The type of the communication.
  * @param  MS_Model_Membership $membership Optional. If defined then we try
  *         to load the overridden template for that membership with fallback
  *         to the default template.
  * @param  bool $no_fallback Optional. Default value is false.
  *         True: Always return a communication for specified membership_id
  *         False: Fallback to default message if membership_id does not
  *         override the requested message.
  * @return MS_Model_Communication The communication object.
  */
 public static function get_communication($type, $membership = null, $no_fallback = false)
 {
     $comm = null;
     $key = 'all';
     $comm_id = 0;
     /*
      * If the Membership specific communication is not defined or it
      * is configured to use the default communication then fetch the
      * default communication object!
      */
     $can_fallback = $membership && !$no_fallback;
     if (self::is_valid_communication_type($type)) {
         $membership_id = 0;
         if ($membership) {
             if ($membership instanceof MS_Model_Membership) {
                 $membership_id = $membership->id;
             } elseif (is_scalar($membership)) {
                 $membership_id = $membership;
             }
             if ($membership_id) {
                 $key = $membership_id;
             }
         }
         if (empty(self::$Communication_IDs[$key])) {
             self::$Communication_IDs[$key] = array();
         }
         if (!empty(self::$Communication_IDs[$key][$type])) {
             $comm_id = self::$Communication_IDs[$key][$type];
         } else {
             $args = array('post_type' => self::get_post_type(), 'post_status' => 'any', 'fields' => 'ids', 'posts_per_page' => 1, 'post_parent' => $membership_id, 'meta_query' => array(array('key' => 'type', 'value' => $type, 'compare' => '=')));
             $args = apply_filters('ms_model_communication_get_communications_args', $args);
             MS_Factory::select_blog();
             $query = new WP_Query($args);
             $items = $query->posts;
             MS_Factory::revert_blog();
             if (1 == count($items)) {
                 $comm_id = $items[0];
             }
         }
         $comm_classes = self::get_communication_type_classes();
         $comm_class = $comm_classes[$type];
         if ($comm_id) {
             $comm = MS_Factory::load($comm_class, $comm_id);
         } elseif (!$can_fallback) {
             $comm = MS_Factory::create($comm_class);
             $comm->reset_to_default();
             $comm->membership_id = $membership_id;
         }
         if ($comm) {
             self::$Communication_IDs[$comm->membership_id][$type] = $comm->id;
         }
         // If no template found or defined then fallback to default template.
         $should_fallback = !$comm || !$comm->override;
         if ($can_fallback && $should_fallback) {
             $comm = self::get_communication($type, null);
         }
     }
     return apply_filters('ms_model_communication_get_communication_' . $type, $comm, $membership, $no_fallback);
 }