/**
  * Show register user form.
  *
  * Related Filter Hooks:
  * - the_content
  *
  * @since  1.0.0
  *
  * @param string $content The page content to filter.
  * @return string The filtered content.
  */
 public function register_form($content)
 {
     // Check if the WordPress settings allow user registration.
     if (!MS_Model_Member::can_register()) {
         return __('Registration is currently not allowed.', MS_TEXT_DOMAIN);
     }
     // Do not parse the form when building the excerpt
     global $wp_current_filter;
     if (in_array('get_the_excerpt', $wp_current_filter)) {
         return '';
     }
     /**
      * Add-ons or other plugins can use this filter to define a completely
      * different registration form. If this filter returns any content, then
      * the default form will not be generated
      *
      * @since  1.0.0
      * @var string
      */
     $custom_code = apply_filters('ms_frontend_custom_registration_form', '', $this->register_errors, $this);
     if ($custom_code) {
         $content = $custom_code;
     } else {
         remove_filter('the_content', 'wpautop');
         $did_form = MS_Helper_Shortcode::has_shortcode(MS_Helper_Shortcode::SCODE_REGISTER_USER, $content);
         if (!$did_form) {
             $scode = sprintf('[%s errors="%s"]', MS_Helper_Shortcode::SCODE_REGISTER_USER, str_replace('"', "'", $this->register_errors));
             $reg_form = do_shortcode($scode);
             if (!MS_Model_Member::is_logged_in()) {
                 $content = $reg_form;
             } else {
                 $content .= $reg_form;
             }
         }
     }
     return apply_filters('ms_controller_frontend_register_form_content', $content, $this);
 }
 /**
  * Resets the shortcode-memory.
  *
  * This is required when a page has multiple calls to the_content - if the
  * usage would not be reset, then only the first call to the_content would
  * actually add certain shortcodes.
  *
  * @since  1.0.0
  */
 public static function reset_shortcode_usage()
 {
     self::$did_shortcodes = array();
 }
    public function to_html()
    {
        global $post;
        /**
         * Provide a customized account page.
         *
         * @since  1.0.0
         */
        $html = apply_filters('ms_shortcode_custom_account', '', $this->data);
        if (!empty($html)) {
            return $html;
        } else {
            $html = '';
        }
        $member = MS_Model_Member::get_current_member();
        $fields = $this->prepare_fields();
        // Extract shortcode options.
        extract($this->data);
        ob_start();
        ?>
		<div class="ms-account-wrapper">
			<?php 
        if (MS_Model_Member::is_logged_in()) {
            ?>

				<?php 
            // ================================================= MEMBERSHIPS
            if ($show_membership) {
                ?>
				<div id="account-membership">
				<h2>
					<?php 
                echo $membership_title;
                if ($show_membership_change) {
                    $signup_url = MS_Model_Pages::get_page_url(MS_Model_Pages::MS_PAGE_REGISTER);
                    printf('<a href="%s" class="ms-edit-profile">%s</a>', $signup_url, $membership_change_label);
                }
                ?>
				</h2>
				<?php 
                /**
                 * Add custom content right before the memberships list.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_memberships_top', $member, $this);
                if (MS_Model_Member::is_admin_user()) {
                    _e('You are an admin user and have access to all memberships', 'membership2');
                } else {
                    if (!empty($this->data['subscription'])) {
                        ?>
						<table>
							<tr>
								<th class="ms-col-membership"><?php 
                        _e('Membership name', 'membership2');
                        ?>
</th>
								<th class="ms-col-status"><?php 
                        _e('Status', 'membership2');
                        ?>
</th>
								<th class="ms-col-expire-date"><?php 
                        _e('Expire date', 'membership2');
                        ?>
</th>
							</tr>
							<?php 
                        $empty = true;
                        // These subscriptions have no expire date
                        $no_expire_list = array(MS_Model_Relationship::STATUS_PENDING, MS_Model_Relationship::STATUS_WAITING, MS_Model_Relationship::STATUS_DEACTIVATED);
                        // These subscriptions display the trial-expire date
                        $trial_expire_list = array(MS_Model_Relationship::STATUS_TRIAL, MS_Model_Relationship::STATUS_TRIAL_EXPIRED);
                        foreach ($this->data['subscription'] as $subscription) {
                            $empty = false;
                            $membership = $subscription->get_membership();
                            $subs_classes = array('ms-subscription-' . $subscription->id, 'ms-status-' . $subscription->status, 'ms-type-' . $membership->type, 'ms-payment-' . $membership->payment_type, 'ms-gateway-' . $subscription->gateway_id, 'ms-membership-' . $subscription->membership_id, $subscription->has_trial() ? 'ms-with-trial' : 'ms-no-trial');
                            ?>
								<tr class="<?php 
                            echo esc_attr(implode(' ', $subs_classes));
                            ?>
">
									<td class="ms-col-membership"><?php 
                            echo esc_html($membership->name);
                            ?>
</td>
									<td class="ms-col-status">
									<?php 
                            if (MS_Model_Relationship::STATUS_PENDING == $subscription->status) {
                                // Display a "Purchase" link when status is Pending
                                $code = sprintf('[%s id="%s" label="%s"]', MS_Helper_Shortcode::SCODE_MS_BUY, $membership->id, __('Pending', 'membership2'));
                                echo do_shortcode($code);
                            } else {
                                echo esc_html($subscription->status_text());
                            }
                            ?>
									</td>
									<td class="ms-col-expire-date"><?php 
                            if (in_array($subscription->status, $no_expire_list)) {
                                echo '&nbsp;';
                            } elseif (in_array($subscription->status, $trial_expire_list)) {
                                echo esc_html(MS_Helper_Period::format_date($subscription->trial_expire_date));
                            } elseif ($subscription->expire_date) {
                                echo esc_html(MS_Helper_Period::format_date($subscription->expire_date));
                            } else {
                                _e('Never', 'membership2');
                            }
                            ?>
</td>
								</tr>
							<?php 
                        }
                        if ($empty) {
                            $cols = 3;
                            if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_TRIAL)) {
                                $cols += 1;
                            }
                            printf('<tr><td colspan="%1$s">%2$s</td></tr>', $cols, __('(No Membership)', 'membership2'));
                        }
                        ?>
						</table>
					<?php 
                    } else {
                        _e('No memberships', 'membership2');
                    }
                }
                /**
                 * Add custom content right after the memberships list.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_memberships_bottom', $member, $this);
                ?>
				</div>
				<?php 
            }
            // END: if ( $show_membership )
            // =============================================================
            ?>

				<?php 
            // ===================================================== PROFILE
            if ($show_profile) {
                ?>
				<div id="account-profile">
				<h2>
					<?php 
                echo $profile_title;
                if ($show_profile_change) {
                    $edit_url = esc_url_raw(add_query_arg(array('action' => MS_Controller_Frontend::ACTION_EDIT_PROFILE)));
                    printf('<a href="%s" class="ms-edit-profile">%s</a>', $edit_url, $profile_change_label);
                }
                ?>
				</h2>
				<?php 
                /**
                 * Add custom content right before the profile overview.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_profile_top', $member, $this);
                ?>
				<table>
					<?php 
                foreach ($fields['personal_info'] as $field => $title) {
                    ?>
						<tr>
							<th class="ms-label-title"><?php 
                    echo esc_html($title);
                    ?>
: </th>
							<td class="ms-label-field"><?php 
                    echo esc_html($this->data['member']->{$field});
                    ?>
</td>
						</tr>
					<?php 
                }
                ?>
				</table>
				<?php 
                do_action('ms_view_shortcode_account_card_info', $this->data);
                /**
                 * Add custom content right after the profile overview.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_profile_bottom', $member, $this);
                ?>
				</div>
				<?php 
            }
            // END: if ( $show_profile )
            // =============================================================
            ?>

				<?php 
            // ==================================================== INVOICES
            if ($show_invoices) {
                ?>
				<div id="account-invoices">
				<h2>
					<?php 
                echo $invoices_title;
                if ($show_all_invoices) {
                    $detail_url = esc_url_raw(add_query_arg(array('action' => MS_Controller_Frontend::ACTION_VIEW_INVOICES)));
                    printf('<a href="%s" class="ms-all-invoices">%s</a>', $detail_url, $invoices_details_label);
                }
                ?>
				</h2>
				<?php 
                /**
                 * Add custom content right before the invoice overview list.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_invoices_top', $member, $this);
                ?>
				<table>
					<thead>
						<tr>
							<th class="ms-col-invoice-no"><?php 
                _e('Invoice #', 'membership2');
                ?>
</th>
							<th class="ms-col-invoice-status"><?php 
                _e('Status', 'membership2');
                ?>
</th>
							<th class="ms-col-invoice-total"><?php 
                printf('%s (%s)', __('Total', 'membership2'), MS_Plugin::instance()->settings->currency);
                ?>
</th>
							<th class="ms-col-invoice-title"><?php 
                _e('Membership', 'membership2');
                ?>
</th>
							<th class="ms-col-invoice-due"><?php 
                _e('Due date', 'membership2');
                ?>
</th>
						</tr>
					</thead>
					<tbody>
					<?php 
                foreach ($this->data['invoices'] as $invoice) {
                    $inv_membership = MS_Factory::load('MS_Model_Membership', $invoice->membership_id);
                    $inv_classes = array('ms-invoice-' . $invoice->id, 'ms-subscription-' . $invoice->ms_relationship_id, 'ms-invoice-' . $invoice->status, 'ms-gateway-' . $invoice->gateway_id, 'ms-membership-' . $invoice->membership_id, 'ms-type-' . $inv_membership->type, 'ms-payment-' . $inv_membership->payment_type);
                    ?>
						<tr class="<?php 
                    echo esc_attr(implode(' ', $inv_classes));
                    ?>
">
							<td class="ms-col-invoice-no"><?php 
                    printf('<a href="%s">%s</a>', get_permalink($invoice->id), $invoice->get_invoice_number());
                    ?>
</td>
							<td class="ms-col-invoice-status"><?php 
                    echo esc_html($invoice->status_text());
                    ?>
</td>
							<td class="ms-col-invoice-total"><?php 
                    echo esc_html(MS_Helper_Billing::format_price($invoice->total));
                    ?>
</td>
							<td class="ms-col-invoice-title"><?php 
                    echo esc_html($inv_membership->name);
                    ?>
</td>
							<td class="ms-col-invoice-due"><?php 
                    echo esc_html(MS_Helper_Period::format_date($invoice->due_date, __('F j', 'membership2')));
                    ?>
</td>
						</tr>
					<?php 
                }
                ?>
					</tbody>
				</table>
				<?php 
                /**
                 * Add custom content right after the invoices overview list.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_invoices_bottom', $member, $this);
                ?>
				</div>
				<?php 
            }
            // END: if ( $show_invoices )
            // =============================================================
            ?>

				<?php 
            // ==================================================== ACTIVITY
            if ($show_activity) {
                ?>
				<div id="account-activity">
				<h2>
					<?php 
                echo $activity_title;
                if ($show_all_activities) {
                    $detail_url = esc_url_raw(add_query_arg(array('action' => MS_Controller_Frontend::ACTION_VIEW_ACTIVITIES)));
                    printf('<a href="%s" class="ms-all-activities">%s</a>', $detail_url, $activity_details_label);
                }
                ?>
				</h2>
				<?php 
                /**
                 * Add custom content right before the activities overview list.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_activity_top', $member, $this);
                ?>
				<table>
					<thead>
						<tr>
							<th class="ms-col-activity-date"><?php 
                _e('Date', 'membership2');
                ?>
</th>
							<th class="ms-col-activity-title"><?php 
                _e('Activity', 'membership2');
                ?>
</th>
						</tr>
					</thead>
					<tbody>
					<?php 
                foreach ($this->data['events'] as $event) {
                    $ev_classes = array('ms-activity-topic-' . $event->topic, 'ms-activity-type-' . $event->type, 'ms-membership-' . $event->membership_id);
                    ?>
						<tr class="<?php 
                    echo esc_attr(implode(' ', $ev_classes));
                    ?>
">
							<td class="ms-col-activity-date"><?php 
                    echo esc_html(MS_Helper_Period::format_date($event->post_modified));
                    ?>
</td>
							<td class="ms-col-activity-title"><?php 
                    echo esc_html($event->description);
                    ?>
</td>
						</tr>
					<?php 
                }
                ?>
					</tbody>
				</table>
				<?php 
                /**
                 * Add custom content right after the activities overview list.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_activity_bottom', $member, $this);
                ?>
				</div>
				<?php 
            }
            // END: if ( $show_activity )
            // =============================================================
            ?>

			<?php 
        } else {
            $has_login_form = MS_Helper_Shortcode::has_shortcode(MS_Helper_Shortcode::SCODE_LOGIN, $post->post_content);
            if (!$has_login_form) {
                $redirect = esc_url_raw(add_query_arg(array()));
                $title = __('Your account', 'membership2');
                $scode = sprintf('[%1$s redirect="%2$s" title="%3$s"]', MS_Helper_Shortcode::SCODE_LOGIN, esc_url($redirect), esc_attr($title));
                echo do_shortcode($scode);
            }
        }
        ?>
		</div>
		<?php 
        $html = ob_get_clean();
        $html = apply_filters('ms_compact_code', $html);
        return apply_filters('ms_shortcode_account', $html, $this->data);
    }
 /**
  * Shortcode callback: Show member infos.
  *
  * @since  1.0.0
  *
  * @param mixed[] $atts Shortcode attributes.
  */
 public function ms_member_info($atts, $content = '')
 {
     MS_Helper_Shortcode::did_shortcode(MS_Helper_Shortcode::SCODE_MEMBER_INFO);
     $data = apply_filters('ms_controller_shortcode_member_info_atts', shortcode_atts(array('value' => 'fullname', 'before' => '<span>', 'after' => '</span>', 'default' => '', 'custom_field' => '', 'list_before' => '', 'list_after' => '', 'list_separator' => ', ', 'user' => 0), $atts));
     $data['user'] = intval($data['user']);
     if ($data['user'] < 1) {
         $data['user'] = get_current_user_id();
     }
     $member = MS_Factory::load('MS_Model_Member', $data['user']);
     $content = '';
     switch ($data['value']) {
         case 'email':
             $content = $member->email;
             break;
         case 'firstname':
         case 'first name':
             $content = $member->first_name;
             break;
         case 'lastname':
         case 'last name':
             $content = $member->last_name;
             break;
         case 'fullname':
         case 'full name':
             $content = $member->first_name . ' ' . $member->last_name;
             break;
         case 'memberships':
         case 'membership':
             $ids = $member->get_membership_ids();
             $content = array();
             foreach ($ids as $id) {
                 $membership = MS_Factory::load('MS_Model_Membership', $id);
                 if ($membership->is_system()) {
                     continue;
                 }
                 $content[] = $membership->name;
             }
             break;
         case 'custom':
             $content = $member->get_custom_data($data['custom_field']);
             break;
     }
     if (is_array($content)) {
         if ($content) {
             $content = $data['list_before'] . implode($data['list_separator'], $content) . $data['list_after'];
         } else {
             $content = '';
         }
     } else {
         $content = (string) $content;
     }
     $content = trim($content);
     if ($content) {
         $content = $data['before'] . $content . $data['after'];
     } else {
         $content = $data['default'];
     }
     return apply_filters('ms_controller_shortcode_member_info', $content, $this);
 }
 /**
  * Get content to protect.
  *
  * @since  1.0.0
  * @param $args The filter args
  *
  * @return array The contents array.
  */
 public function get_contents($args = null)
 {
     global $shortcode_tags;
     $exclude = MS_Helper_Shortcode::get_membership_shortcodes();
     $contents = array();
     foreach ($shortcode_tags as $key => $function) {
         if (in_array($key, $exclude)) {
             continue;
         }
         // Search the shortcode-tag...
         if (!empty($args['s'])) {
             if (false === stripos($key, $args['s'])) {
                 continue;
             }
         }
         $contents[$key] = new StdClass();
         $contents[$key]->id = $key;
         $contents[$key]->name = "[{$key}]";
         $contents[$key]->type = MS_Rule_Shortcode::RULE_ID;
         $contents[$key]->access = $this->get_rule_value($key);
     }
     $filter = $this->get_exclude_include($args);
     if (is_array($filter->include)) {
         $contents = array_intersect_key($contents, array_flip($filter->include));
     } elseif (is_array($filter->exclude)) {
         $contents = array_diff_key($contents, array_flip($filter->exclude));
     }
     if (!empty($args['posts_per_page'])) {
         $total = $args['posts_per_page'];
         $offset = !empty($args['offset']) ? $args['offset'] : 0;
         $contents = array_slice($contents, $offset, $total);
     }
     return apply_filters('ms_rule_shortcode_model_get_contents', $contents);
 }