コード例 #1
0
 /**
  * Setup the rule.
  *
  * @since  1.0.0
  */
 public function prepare_obj()
 {
     if (MS_Rule_MemberRoles_Model::is_active()) {
         MS_Model_Rule::register_rule(self::RULE_ID, __CLASS__, __('User Roles', MS_TEXT_DOMAIN), 2);
     }
     $this->add_filter('ms_view_protectedcontent_define-' . self::RULE_ID, 'handle_render_callback', 10, 2);
     $this->add_filter('ms_rule_listtable-' . self::RULE_ID, 'return_listtable');
 }
コード例 #2
0
 /**
  * Setup the rule.
  *
  * @since  1.0.0
  */
 public function prepare_obj()
 {
     if (MS_Rule_Post_Model::is_active()) {
         MS_Model_Rule::register_rule(self::RULE_ID, __CLASS__, __('Posts', 'membership2'), 11, true);
     }
     $this->add_filter('ms_view_protectedcontent_define-' . self::RULE_ID, 'handle_render_callback', 10, 2);
     $this->add_filter('ms_rule_listtable-' . self::RULE_ID, 'return_listtable');
 }
コード例 #3
0
 /**
  * Setup the rule.
  *
  * @since  1.0.0
  */
 public function prepare_obj()
 {
     MS_Model_Rule::register_rule(self::RULE_ID, __CLASS__, __('BuddyPress', MS_TEXT_DOMAIN), 40);
     $this->add_filter('ms_view_protectedcontent_define-' . self::RULE_ID, 'handle_render_callback', 10, 2);
 }
コード例 #4
0
 /**
  * Get available tabs for Membership2 page.
  *
  * @since  1.0.0
  *
  * @return array The tabs configuration.
  */
 public function get_available_tabs()
 {
     static $Tabs = null;
     if (null === $Tabs) {
         $membership = $this->load_membership();
         $membership_id = $membership->id;
         $is_base = $membership->is_base();
         $settings = MS_Factory::load('MS_Model_Settings');
         // First create a list including all possible tabs.
         $tabs = array(MS_Rule_Page::RULE_ID => true, MS_Rule_Post::RULE_ID => true, MS_Rule_Category::RULE_ID => true, MS_Rule_Content::RULE_ID => true, MS_Rule_Media::RULE_ID => true, MS_Rule_MenuItem::RULE_ID => true, MS_Rule_ReplaceMenu::RULE_ID => true, MS_Rule_ReplaceLocation::RULE_ID => true, MS_Rule_Shortcode::RULE_ID => true, MS_Rule_Url::RULE_ID => true, MS_Rule_Special::RULE_ID => true, MS_Rule_MemberCaps::RULE_ID => true, MS_Rule_MemberRoles::RULE_ID => true);
         // Now remove items from the list that are not available.
         // Optionally show "Posts"
         if (!MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_POST_BY_POST)) {
             $tabs[MS_Rule_Post::RULE_ID] = false;
         }
         // Optionally show "Category"
         if (!MS_Model_Addon::is_enabled(MS_Addon_Category::ID)) {
             $tabs[MS_Rule_Category::RULE_ID] = false;
         }
         // Optionally show "Media"
         if (!MS_Model_Addon::is_enabled(MS_Addon_Mediafiles::ID)) {
             $tabs[MS_Rule_Media::RULE_ID] = false;
         }
         // Either "Menu Item" or "Menus" or "Menu Location"
         switch ($settings->menu_protection) {
             case 'menu':
                 $tabs[MS_Rule_MenuItem::RULE_ID] = false;
                 $tabs[MS_Rule_ReplaceLocation::RULE_ID] = false;
                 break;
             case 'location':
                 $tabs[MS_Rule_MenuItem::RULE_ID] = false;
                 $tabs[MS_Rule_ReplaceMenu::RULE_ID] = false;
                 break;
             case 'item':
             default:
                 $tabs[MS_Rule_ReplaceMenu::RULE_ID] = false;
                 $tabs[MS_Rule_ReplaceLocation::RULE_ID] = false;
                 break;
         }
         // Maybe "Special Pages".
         if (!MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_SPECIAL_PAGES)) {
             $tabs[MS_Rule_Special::RULE_ID] = false;
         }
         // Maybe "URLs"
         if (!MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_URL_GROUPS)) {
             $tabs[MS_Rule_Url::RULE_ID] = false;
         }
         // Maybe "Shortcodes"
         if (!MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_SHORTCODE)) {
             $tabs[MS_Rule_Shortcode::RULE_ID] = false;
         }
         // Maybe "Membercaps"
         if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_MEMBERCAPS)) {
             if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_MEMBERCAPS_ADV)) {
                 $tabs[MS_Rule_MemberRoles::RULE_ID] = false;
             } else {
                 $tabs[MS_Rule_MemberCaps::RULE_ID] = false;
             }
         } else {
             $tabs[MS_Rule_MemberRoles::RULE_ID] = false;
             $tabs[MS_Rule_MemberCaps::RULE_ID] = false;
         }
         lib2()->array->equip($_GET, 'page');
         // Allow Add-ons to add or remove rule tabs
         $tabs = apply_filters('ms_controller_protection_tabs', $tabs, $membership_id);
         $page = sanitize_html_class($_GET['page'], MS_Controller_Plugin::MENU_SLUG . '-memberships');
         $rule_titles = MS_Model_Rule::get_rule_type_titles();
         $result = array();
         foreach ($tabs as $rule_type => $state) {
             if (!$state) {
                 continue;
             }
             $url = sprintf('%s?page=%s&tab=%s', admin_url('admin.php'), $page, $rule_type);
             // Try to keep the selected Membership and Status filter.
             if (!empty($_REQUEST['membership_id'])) {
                 $url = esc_url_raw(add_query_arg(array('membership_id' => $_REQUEST['membership_id']), $url));
             }
             if (!empty($_REQUEST['status'])) {
                 $url = esc_url_raw(add_query_arg(array('status' => $_REQUEST['status']), $url));
             }
             $result[$rule_type] = array('title' => $rule_titles[$rule_type], 'url' => $url);
         }
         $Tabs = apply_filters('ms_controller_protection_get_available_tabs', $result, $membership_id, $this);
     }
     return $Tabs;
 }
コード例 #5
0
 /**
  * Validate specific property before set.
  *
  * @since  1.0.0
  * @param string $property The name of a property to associate.
  * @param mixed $value The value of a property.
  */
 public function __set($property, $value)
 {
     if (property_exists($this, $property)) {
         switch ($property) {
             case 'rule_type':
                 if (in_array($value, MS_Model_Rule::get_rule_types())) {
                     $this->{$property} = $value;
                 }
                 break;
             case 'dripped':
                 if (is_array($value)) {
                     $this->{$property} = $value;
                 }
                 break;
             default:
                 $this->{$property} = $value;
                 break;
         }
     }
     do_action('ms_rule__set_after', $property, $value, $this);
 }
コード例 #6
0
 /**
  * Setup the rule.
  *
  * @since  1.0.0
  */
 public function prepare_obj()
 {
     MS_Model_Rule::register_rule(self::RULE_ID, __CLASS__, __('bbPress', 'membership2'), 100);
     $this->add_filter('ms_view_protectedcontent_define-' . self::RULE_ID, 'handle_render_callback', 10, 2);
 }
コード例 #7
0
 /**
  * Register meta-information on a rule
  *
  * @since  1.0.0
  * @param  string $id ID of the rule.
  * @param  string $class Name of the rule class, used to find Model-class.
  * @param  string $title Rule Title for display.
  * @param  int $priority Loading-priority (0 - 999), lower is earlier.
  */
 public static function register_rule($id, $class, $title, $priority = 0, $dripped = false)
 {
     if (!is_array(self::$rule_meta)) {
         self::$rule_meta = array('title' => array(), 'class' => array(), 'model_class' => array(), 'order' => array(), 'dripped' => array());
     }
     self::$rule_meta['title'][$id] = $title;
     self::$rule_meta['class'][$id] = $class;
     self::$rule_meta['model_class'][$id] = $class . '_Model';
     if ($dripped) {
         self::$rule_meta['dripped'][] = $id;
     }
     $priority = min($priority, 999);
     $priority = max($priority, 0);
     $real_priority = $priority * 20;
     while (isset(self::$rule_meta['order'][$real_priority])) {
         $real_priority += 1;
     }
     self::$rule_meta['order'][$real_priority] = $id;
 }
    /**
     * Echo a content list as tag-list.
     *
     * @since  1.0.0
     *
     * @param  array $contents List of content items to display.
     */
    protected function content_box($rule)
    {
        static $row_items = 0;
        $rule_titles = MS_Model_Rule::get_rule_type_titles();
        $title = $rule_titles[$rule->rule_type];
        $contents = (array) $rule->get_contents(null, true);
        $membership_id = $this->data['membership']->id;
        $row_items += 1;
        $new_row = $row_items % 4 === 0;
        $show_sep = ($row_items - 1) % 4 === 0;
        if ($show_sep && $row_items > 1) {
            MS_Helper_Html::html_separator();
        }
        ?>
		<div class="ms-part-4 ms-min-height">
			<?php 
        if (!$new_row) {
            MS_Helper_Html::html_separator('vertical');
        }
        ?>
			<div class="ms-bold">
				<?php 
        printf('%s (%s):', $title, $rule->count_rules());
        ?>
			</div>

			<div class="inside">
				<ul class="ms-content-tag-list ms-group">
				<?php 
        foreach ($contents as $content) {
            if ($content->access) {
                MS_Helper_Html::content_tag($content);
            }
        }
        ?>
				</ul>

				<div class="ms-protection-edit-wrapper">
					<?php 
        $edit_url = MS_Controller_Plugin::get_admin_url('protection', array('tab' => $rule->rule_type, 'membership_id' => $membership_id));
        MS_Helper_Html::html_element(array('id' => 'edit_' . $rule->rule_type, 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'title' => $title, 'value' => sprintf(__('Edit %s Access', 'membership2'), $title), 'url' => $edit_url, 'class' => 'wpmui-field-button button'));
        ?>
				</div>
			</div>
		</div>
		<?php 
        if ($new_row) {
            echo '</div><div class="ms-group">';
        }
    }
コード例 #9
0
 /**
  * Get protection rules sorted.
  *
  * First one has priority over the last one.
  * These rules are used to determine access.
  *
  * @since  1.0.0
  * @internal
  */
 private function get_rules_hierarchy()
 {
     $rule_types = MS_Model_Rule::get_rule_types();
     $rules = array();
     $subscription = MS_Factory::load('MS_Model_Relationship', $this->subscription_id);
     foreach ($rule_types as $rule_type) {
         $rule = $this->get_rule($rule_type);
         if ($rule->rule_type != $rule_type) {
             // This means that the $rule_type was not found...
             continue;
         }
         // Sometimes the $subscription->id can be 0, which is intentional:
         // This is the case when the membership was auto-assigned to guest
         // or default membership.
         $rule->_subscription_id = $subscription->id;
         $rule->membership_id = $this->id;
         $rules[$rule_type] = $rule;
     }
     return apply_filters('ms_model_membership_get_rules_hierarchy', $rules, $this);
 }
コード例 #10
0
 /**
  * Load all the rules that are used by the plugin.
  *
  * Related Action Hooks:
  * - ms_init_done
  *
  * @since  1.0.0
  */
 public function setup_rules()
 {
     // Make sure we stick to the correct workflow.
     if (!did_action('ms_init_done')) {
         throw new Exception('setup_rules() is called too early.', 1);
         return;
     }
     do_action('ms_initialize_rules', $this);
     $rule_types = MS_Model_Rule::get_rule_types();
     foreach ($this->member->subscriptions as $subscription) {
         foreach ($rule_types as $rule_type) {
             $rule = $subscription->get_membership()->get_rule($rule_type);
         }
     }
 }
    /**
     * Echo a content list as 2-column table that show Content-Title and the
     * Available date.
     * Used by Dripped-Content view.
     *
     * @since  1.0.0
     *
     * @param  array $contents List of content items to display.
     */
    protected function content_box($contents)
    {
        $row_class = '';
        ksort($contents);
        $rule_titles = MS_Model_Rule::get_rule_type_titles();
        $edit_url = MS_Controller_Plugin::get_admin_url('protection', array('tab' => $rule->rule_type));
        $edit_link = array('id' => 'edit_dripped', 'type' => MS_Helper_Html::TYPE_HTML_LINK);
        ?>
		<table class="ms-list-table ms-list-date widefat">
			<thead>
				<tr>
					<th class="col-icon">&nbsp;</th>
					<th class="col-text"><?php 
        _e('Rule', MS_TEXT_DOMAIN);
        ?>
</th>
					<th class="col-text"><?php 
        _e('Protected Item', MS_TEXT_DOMAIN);
        ?>
</th>
					<th class="col-date"><?php 
        _e('Access', MS_TEXT_DOMAIN);
        ?>
</th>
				</tr>
			</thead>
			<tbody>
			<?php 
        foreach ($contents as $id => $content) {
            $row_class = $row_class == 'alternate' ? '' : 'alternate';
            ?>
				<tr class="<?php 
            echo esc_attr($row_class . ' ' . $content->icon);
            ?>
">
					<td class="col-icon">
						<i class="dashicons dashicons-<?php 
            echo esc_attr($content->icon);
            ?>
"></i>
					</td>
					<td class="col-text col-type">
						<?php 
            $edit_link['url'] = esc_url_raw(add_query_arg('tab', $content->type, $edit_url));
            $edit_link['value'] = $rule_titles[$content->type];
            MS_Helper_Html::html_element($edit_link);
            ?>
					</td>
					<td class="col-text">
						<?php 
            MS_Helper_Html::content_tag($content, 'span');
            ?>
					</td>
					<td class="col-date">
						<?php 
            echo '' . $content->date;
            ?>
					</td>
				</tr>
			<?php 
        }
        ?>
			</tbody>
		</table>
		<?php 
    }
コード例 #12
0
 /**
  * Setup the rule.
  *
  * @since  1.0.0
  */
 public function prepare_obj()
 {
     MS_Model_Rule::register_rule(self::RULE_ID, __CLASS__, __('Shortcodes', MS_TEXT_DOMAIN), 70);
     $this->add_filter('ms_view_protectedcontent_define-' . self::RULE_ID, 'handle_render_callback', 10, 2);
     $this->add_filter('ms_rule_listtable-' . self::RULE_ID, 'return_listtable');
 }
コード例 #13
0
    /**
     * Displays the inline-edit form used to edit the dripped content details.
     *
     * @since  1.0.0
     */
    protected function inline_edit()
    {
        $rule = $this->model;
        $membership = $this->membership;
        $field_action = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'action', 'value' => MS_Controller_Rule::AJAX_ACTION_UPDATE_DRIPPED);
        $field_rule = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'rule_type', 'value' => $this->model->rule_type);
        $field_item = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'item_id');
        $field_offset = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'offset');
        $field_number = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'number');
        $field_filter = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'membership_id', 'value' => isset($_REQUEST['membership_id']) ? $_REQUEST['membership_id'] : '');
        $field_id = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'membership_ids');
        $field_type = array('type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'name' => 'dripped_type', 'class' => 'dripped_type', 'field_options' => MS_Model_Rule::get_dripped_types());
        $field_date = array('type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER, 'name' => 'date', 'placeholder' => __('Date', 'membership2') . '...');
        $field_delay_unit = array('type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'name' => 'delay_unit', 'class' => 'ms-text-small', 'placeholder' => '0');
        $field_delay_type = array('type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'name' => 'delay_type', 'field_options' => MS_Helper_Period::get_period_types('plural'), 'after' => __('after subscription', 'membership2'));
        ?>
		<div>
			<h4>
				<span class="lbl-name"></span> -
				<?php 
        _e('Dripped Content Settings', 'membership2');
        ?>
			</h4>
		</div>
		<fieldset>
			<div class="inline-edit-col">
				<?php 
        MS_Helper_Html::html_element($field_action);
        MS_Helper_Html::html_element($field_rule);
        MS_Helper_Html::html_element($field_item);
        MS_Helper_Html::html_element($field_offset);
        MS_Helper_Html::html_element($field_number);
        MS_Helper_Html::html_element($field_filter);
        ?>
				<div class="dynamic-form"></div>
			</div>
		</fieldset>
		<div class="dripped-form cf no-auto-init hidden">
			<div class="drip-col col-1">
				<span class="the-name ms-membership"></span>
				<?php 
        MS_Helper_Html::html_element($field_id);
        ?>
			</div>
			<div class="drip-col col-2">
				<?php 
        MS_Helper_Html::html_element($field_type);
        ?>
			</div>
			<div class="drip-col col-3">
				<div class="drip-option <?php 
        echo esc_attr(MS_Model_Rule::DRIPPED_TYPE_INSTANTLY);
        ?>
">
					<?php 
        _e('Instantly', 'membership2');
        ?>
				</div>
				<div class="drip-option <?php 
        echo esc_attr(MS_Model_Rule::DRIPPED_TYPE_SPEC_DATE);
        ?>
">
					<?php 
        MS_Helper_Html::html_element($field_date);
        ?>
				</div>
				<div class="drip-option <?php 
        echo esc_attr(MS_Model_Rule::DRIPPED_TYPE_FROM_REGISTRATION);
        ?>
">
					<?php 
        MS_Helper_Html::html_element($field_delay_unit);
        MS_Helper_Html::html_element($field_delay_type);
        ?>
				</div>
			</div>
			</div>
		</div>
		<?php 
    }
コード例 #14
0
    /**
     * Output details on which membership denied or allowed access to the
     * current page
     *
     * @since  1.0.0
     * @param  string $denied_url URL of the denied page (empty if not denied)
     * @param  int $membership_id Membership_id
     * @param  array $rules List of Rule_types
     */
    protected function output_deciding_info($denied_url, $membership_id, $rules)
    {
        $membership = MS_Factory::load('MS_Model_Membership', $membership_id);
        $rule_title = MS_Model_Rule::get_rule_type_titles();
        if (!empty($denied_url)) {
            ?>
			<div class="ms-sim-denied">
			<?php 
            printf(__('Access denied by %s', MS_TEXT_DOMAIN), '<b>' . esc_html($membership->name) . '</b>');
            ?>
			</div>
			<ul class="ms-sim-rules">
			<?php 
            printf('<li><a href="%1$s">%1$s</a></li>', $denied_url);
            foreach ($rules as $rule_type) {
                printf('<li><a href="%1$s" target="_blank">%3$s %2$s</a></li>', MS_Controller_Plugin::get_admin_url('protection', array('tab' => $rule_type, 'membership_id' => $membership->id)), $rule_title[$rule_type], __('Denied by Rule:', MS_TEXT_DOMAIN));
            }
            ?>
		<?php 
        } elseif ($membership->is_valid()) {
            ?>
			<div class="ms-sim-allowed">
			<?php 
            printf(__('Access granted by %s', MS_TEXT_DOMAIN), '<b>' . esc_html($membership->name) . '</b>');
            ?>
			</div>
			<ul class="ms-sim-rules">
			<?php 
            foreach ($rules as $rule_type) {
                printf('<li><a href="%1$s" target="_blank">%3$s %2$s</a></li>', MS_Controller_Plugin::get_admin_url('protection', array('tab' => $rule_type, 'membership_id' => $membership->id)), $rule_title[$rule_type], __('Allowed by Rule:', MS_TEXT_DOMAIN));
            }
            ?>
			</ul>
		<?php 
        } else {
            ?>
			<div class="ms-sim-public">
			<?php 
            _e('Unprotected', MS_TEXT_DOMAIN);
            ?>
			</div>
		<?php 
        }
    }