function handle_level_edit_form($level_id = false, $clone = false)
        {
            global $page, $M_Rules, $M_SectionRules;
            if ($level_id && !$clone) {
                $mlevel = new M_Level($level_id);
                $level = $mlevel->get();
            } else {
                if ($clone) {
                    $mlevel = new M_Level($level_id);
                    $level = $mlevel->get();
                    $level->level_title .= __(' clone', 'membership');
                } else {
                    $level = new stdclass();
                    $level->level_title = __('new level', 'membership');
                }
                $level->id = time() * -1;
            }
            // Get the relevant parts
            if (isset($mlevel)) {
                $positives = $mlevel->get_rules('positive');
                $negatives = $mlevel->get_rules('negative');
            }
            // Re-arrange the rules
            $rules = array();
            $p = array();
            $n = array();
            if (!empty($positives)) {
                foreach ($positives as $positive) {
                    $rules[$positive->rule_area] = maybe_unserialize($positive->rule_value);
                    $p[$positive->rule_area] = maybe_unserialize($positive->rule_value);
                }
            }
            if (!empty($negatives)) {
                foreach ($negatives as $negative) {
                    $rules[$negative->rule_area] = maybe_unserialize($negative->rule_value);
                    $n[$negative->rule_area] = maybe_unserialize($negative->rule_value);
                }
            }
            // Check which tab we should open the edit form with
            if (!empty($p) && !empty($n)) {
                // We have content in both areas - so start with advanced open
                $advancedtab = 'activetab';
                $negativetab = '';
                $positivetab = '';
                $advancedcontent = 'activecontent';
                $negativecontent = 'activecontent';
                $positivecontent = 'activecontent';
            } else {
                if (!empty($n)) {
                    // We have content in the negative area - so start with that
                    $advancedtab = '';
                    $negativetab = 'activetab';
                    $positivetab = '';
                    $advancedcontent = 'inactivecontent';
                    $negativecontent = 'activecontent';
                    $positivecontent = 'inactivecontent';
                } else {
                    // Default to the positive area
                    $advancedtab = '';
                    $negativetab = '';
                    $positivetab = 'activetab';
                    $advancedcontent = 'inactivecontent';
                    $negativecontent = 'inactivecontent';
                    $positivecontent = 'activecontent';
                }
            }
            ?>
			<div class='wrap nosubsub'>
				<div class="icon32" id="icon-link-manager"><br></div>
				<h2><?php 
            echo __('Edit ', 'membership') . " - " . esc_html($level->level_title);
            ?>
</h2>

				<?php 
            if (isset($usemsg)) {
                echo '<div id="message" class="updated fade"><p>' . $messages[$usemsg] . '</p></div>';
                $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
            }
            ?>

				<div class='level-liquid-left'>

					<div id='level-left'>
						<form action='?page=<?php 
            echo $page;
            ?>
' name='leveledit' method='post'>
							<input type='hidden' name='level_id' id='level_id' value='<?php 
            echo $level->id;
            ?>
' />

							<input type='hidden' name='ontab' id='ontab' value='positive' />

							<input type='hidden' name='beingdragged' id='beingdragged' value='' />
							<input type='hidden' name='in-positive-rules' id='in-positive-rules' value=',<?php 
            echo implode(',', array_keys($p));
            ?>
' />
							<input type='hidden' name='in-negative-rules' id='in-negative-rules' value=',<?php 
            echo implode(',', array_keys($n));
            ?>
' />

							<input type='hidden' name='postive-rules-order' id='postive-rules-order' value='' />
							<input type='hidden' name='negative-rules-order' id='negative-rules-order' value='' />

						<div id='edit-level' class='level-holder-wrap'>
							<div class='sidebar-name no-movecursor'>
								<h3><?php 
            echo esc_html($level->level_title);
            ?>
</h3>
							</div>
							<div class='level-holder'>
								<div class='level-details'>
								<label for='level_title'><?php 
            _e('Level title', 'membership');
            ?>
</label><?php 
            //echo $this->_tips->add_tip( __('This is the title used throughout the system to identify this level.','membership') );
            ?>
<br/>
								<input class='wide' type='text' name='level_title' id='level_title' value='<?php 
            echo esc_attr($level->level_title);
            ?>
' />
								<br/><br/>
								<label for='level_shortcode'><?php 
            _e('Level shortcode', 'membership');
            ?>
</label><?php 
            echo $this->_tips->add_tip(__('The shortcode for this level is based on the title (above). It can be used to wrap content that you only want to be seen by members on this level e.g. [levelshortcode] protected content [/levelshortcode]', 'membership'));
            ?>
								<?php 
            if ($level->id > 0) {
                echo "[" . M_normalize_shortcode($level->level_title) . "]";
            } else {
                _e('Save your level to create the shortcode', 'membership');
            }
            ?>
								</div>

								<?php 
            do_action('membership_level_form_before_rules', $level->id);
            ?>

								<ul class='leveltabs'>
									<li class='positivetab <?php 
            echo $positivetab;
            ?>
'><div class='downarrow'></div><a href='#positive'><div><?php 
            _e('Positive Rules', 'membership');
            ?>
</div></a></li>
									<li class='negativetab <?php 
            echo $negativetab;
            ?>
'><div class='downarrow'></div><a href='#negative'><div><?php 
            _e('Negative Rules', 'membership');
            ?>
</div></a></li>
									<li class='advancedtab <?php 
            echo $advancedtab;
            ?>
'><div class='downarrow'></div><a href='#advanced'><div><?php 
            _e('Advanced (both)', 'membership');
            ?>
</div></a></li>
								</ul>

								<div class='advancedtabwarning <?php 
            echo $advancedcontent;
            ?>
'>
									<?php 
            _e('<strong>Warning:</strong> using both positive and negative rules on the same level can cause conflicts and unpredictable behaviour.', 'membership');
            ?>
								</div>

								<div class='positivecontent <?php 
            echo $positivecontent;
            ?>
'>
									<h3 class='positive positivetitle <?php 
            echo $advancedcontent;
            ?>
'><?php 
            _e('Positive rules', 'membership');
            ?>
</h3>
									<p class='description'><?php 
            _e('These are the areas / elements that a member of this level can access.', 'membership');
            ?>
</p>

									<div id='positive-rules' class='level-droppable-rules levels-sortable'>
										<?php 
            _e('Drop here', 'membership');
            ?>
									</div>

									<div id='positive-rules-holder'>
										<?php 
            do_action('membership_level_form_before_positive_rules', $level->id);
            ?>
										<?php 
            if (!empty($p)) {
                foreach ($p as $key => $value) {
                    if (isset($M_Rules[$key])) {
                        $rule = new $M_Rules[$key]();
                        $rule->admin_main($value);
                    }
                }
            }
            ?>
										<?php 
            do_action('membership_level_form_after_positive_rules', $level->id);
            ?>
									</div>
								</div>

								<div class='negativecontent <?php 
            echo $negativecontent;
            ?>
'>
									<h3 class='negative negativetitle <?php 
            echo $advancedcontent;
            ?>
'><?php 
            _e('Negative rules', 'membership');
            ?>
</h3>
									<p class='description'><?php 
            _e('These are the areas / elements that a member of this level doesn\'t have access to.', 'membership');
            ?>
</p>

									<div id='negative-rules' class='level-droppable-rules levels-sortable'>
										<?php 
            _e('Drop here', 'membership');
            ?>
									</div>

									<div id='negative-rules-holder'>
										<?php 
            do_action('membership_level_form_before_negative_rules', $level->id);
            ?>

										<?php 
            if (!empty($n)) {
                foreach ($n as $key => $value) {
                    if (isset($M_Rules[$key])) {
                        $rule = new $M_Rules[$key]();
                        $rule->admin_main($value);
                    }
                }
            }
            ?>

										<?php 
            do_action('membership_level_form_after_negative_rules', $level->id);
            ?>

									</div>
								</div>

								<div class='advancedcontent <?php 
            echo $advancedcontent;
            ?>
'>
									<h3><?php 
            _e('Custom shortcode protected content message', 'membership');
            ?>
</h3>
									<p class='description'><?php 
            _e('If you want a protected content message to be displayed for this level then you can enter it here.', 'membership');
            ?>
</p>
									<?php 
            $args = array("textarea_name" => "level_protectedcontent", "textarea_rows" => 20);
            if (!empty($mlevel)) {
                $level_protectedcontent = $mlevel->get_meta('level_protectedcontent');
            }
            if (empty($level_protectedcontent)) {
                $level_protectedcontent = '';
            }
            wp_editor(stripslashes($level_protectedcontent), "level_protectedcontent", $args);
            ?>
								</div>

								<div class='advancedcontent <?php 
            echo $advancedcontent;
            ?>
'>
								<?php 
            do_action('membership_level_form_after_rules', $level->id);
            ?>
								</div>

								<div class='buttons'>
									<?php 
            if ($level->id > 0) {
                wp_original_referer_field(true, 'previous');
                wp_nonce_field('update-' . $level->id);
                ?>
										<a href='?page=<?php 
                echo $page;
                ?>
' class='cancellink' title='Cancel edit'><?php 
                _e('Cancel', 'membership');
                ?>
</a>
										<input type='submit' value='<?php 
                _e('Update', 'membership');
                ?>
' class='button-primary' />
										<input type='hidden' name='action' value='updated' />
										<?php 
            } else {
                wp_original_referer_field(true, 'previous');
                wp_nonce_field('add-' . $level->id);
                ?>
										<a href='?page=<?php 
                echo $page;
                ?>
' class='cancellink' title='Cancel add'><?php 
                _e('Cancel', 'membership');
                ?>
</a>
										<input type='submit' value='<?php 
                _e('Add', 'membership');
                ?>
' class='button-primary' />
										<input type='hidden' name='action' value='added' />
										<?php 
            }
            ?>
								</div>

							</div>
						</div>
						</form>
					</div>


					<div id='hiden-actions'>
					<?php 
            $sections = apply_filters('membership_level_sections', array());
            foreach ($sections as $key => $section) {
                if (isset($M_SectionRules[$key])) {
                    foreach ($M_SectionRules[$key] as $mrule => $mclass) {
                        $rule = new $mclass();
                        if (!array_key_exists($mrule, $rules)) {
                            $rule->admin_main(false);
                        }
                    }
                }
            }
            ?>
					</div> <!-- hidden-actions -->

				</div> <!-- level-liquid-left -->

				<div class='level-liquid-right'>
					<div class="level-holder-wrap">
						<?php 
            do_action('membership_sidebar_top_level');
            do_action('membership_sidebar_top', 'level');
            $sections = apply_filters('membership_level_sections', array());
            foreach ($sections as $key => $section) {
                ?>

								<div class="sidebar-name no-movecursor">
									<h3><?php 
                echo $section['title'];
                ?>
</h3>
								</div>
								<div class="section-holder" id="sidebar-<?php 
                echo $key;
                ?>
" style="min-height: 98px;">
									<ul class='levels level-levels-draggable'>
									<?php 
                if (isset($M_SectionRules[$key])) {
                    foreach ($M_SectionRules[$key] as $mrule => $mclass) {
                        $rule = new $mclass();
                        if (!array_key_exists($mrule, $rules)) {
                            $rule->admin_sidebar(false);
                        } else {
                            $rule->admin_sidebar(true);
                        }
                    }
                }
                ?>
									</ul>
								</div>
								<?php 
            }
            ?>
					</div> <!-- level-holder-wrap -->

				</div> <!-- level-liquid-left -->

			</div> <!-- wrap -->

			<?php 
        }
        function show_level_ping_information($level_id)
        {
            // Get all the pings
            $pings = $this->get_pings();
            // Get the currentlt set ping for each level
            $level = new M_Level($level_id);
            $joinping = $level->get_meta('joining_ping', '');
            $leaveping = $level->get_meta('leaving_ping', '');
            ?>
				<h3><?php 
            _e('Level Pings', 'membership');
            ?>
</h3>
				<p class='description'><?php 
            _e('If you want any pings to be sent when a member joins and/or leaves this level then set them below.', 'membership');
            ?>
</p>

				<div class='level-details'>

				<label for='joiningping'><?php 
            _e('Joining Ping', 'membership');
            ?>
</label>
				<select name='joiningping'>
					<option value='' <?php 
            selected($joinping, '');
            ?>
><?php 
            _e('None', 'membership');
            ?>
</option>
					<?php 
            if (!empty($pings)) {
                foreach ($pings as $ping) {
                    ?>
							<option value='<?php 
                    echo $ping->id;
                    ?>
' <?php 
                    selected($joinping, $ping->id);
                    ?>
><?php 
                    echo stripslashes($ping->pingname);
                    ?>
</option>
							<?php 
                }
            }
            ?>
				</select><br/>

				<label for='leavingping'><?php 
            _e('Leaving Ping', 'membership');
            ?>
</label>
				<select name='leavingping'>
					<option value='' <?php 
            selected($leaveping, '');
            ?>
><?php 
            _e('None', 'membership');
            ?>
</option>
					<?php 
            if (!empty($pings)) {
                foreach ($pings as $ping) {
                    ?>
							<option value='<?php 
                    echo $ping->id;
                    ?>
' <?php 
                    selected($leaveping, $ping->id);
                    ?>
><?php 
                    echo stripslashes($ping->pingname);
                    ?>
</option>
							<?php 
                }
            }
            ?>
				</select>
				</div>
			<?php 
        }
 function do_levelprotected_shortcode($atts, $content = null, $code = "")
 {
     global $M_options;
     // Set up the level shortcodes here
     $shortcodes = apply_filters('membership_level_shortcodes', array());
     $notshortcodes = apply_filters('membership_not_level_shortcodes', array());
     $code = strtolower($code);
     if (substr($code, 0, 4) !== "not-") {
         if (!empty($shortcodes)) {
             // search positive shortcodes first
             $id = array_search($code, $shortcodes);
             if ($id !== false) {
                 // we have found a level so we need to check if it has a custom protected message, otherwise we'll just output the default main on
                 $level = new M_Level($id);
                 $message = $level->get_meta('level_protectedcontent');
                 if (!empty($message)) {
                     return stripslashes($message);
                 }
             }
         }
     } else {
         if (!empty($notshortcodes)) {
             // search positive shortcodes first
             $id = array_search($code, $notshortcodes);
             if ($id !== false) {
                 // we have found a level so we need to check if it has a custom protected message, otherwise we'll just output the default main on
                 $level = new M_Level($id);
                 $message = $level->get_meta('level_protectedcontent');
                 if (!empty($message)) {
                     return stripslashes($message);
                 }
             }
         }
     }
     // If we are here then we have no custom message, or the shortcode wasn't found so just output the standard message
     if (isset($M_options['shortcodemessage'])) {
         return stripslashes(do_shortcode($M_options['shortcodemessage']));
     } else {
         return '';
     }
 }
Beispiel #4
0
function M_ping_joinedsub($tosub_id, $tolevel_id, $to_order, $user_id)
{
    $sub = new M_Subscription($tosub_id);
    $subjoiningping_id = $sub->get_meta('joining_ping');
    if (!empty($subjoiningping_id)) {
        $ping = new M_Ping($subjoiningping_id);
        $ping->send_ping($tosub_id, $tolevel_id, $user_id);
    }
    $level = new M_Level($tolevel_id);
    $joiningping_id = $level->get_meta('joining_ping');
    if (!empty($joiningping_id)) {
        $ping = new M_Ping($joiningping_id);
        $ping->send_ping($tosub_id, $tolevel_id, $user_id);
    }
}