| 1 |
<?php |
| 2 |
// @codingStandardsIgnoreFile |
| 3 |
/** |
| 4 |
* Security meta box. |
| 5 |
* |
| 6 |
* Copyright: © 2009-2011 |
| 7 |
* {@link http://websharks-inc.com/ WebSharks, Inc.} |
| 8 |
* (coded in the USA) |
| 9 |
* |
| 10 |
* Released under the terms of the GNU General Public License. |
| 11 |
* You should have received a copy of the GNU General Public License, |
| 12 |
* along with this software. In the main directory, see: /licensing/ |
| 13 |
* If not, see: {@link http://www.gnu.org/licenses/}. |
| 14 |
* |
| 15 |
* @package s2Member\Meta_Boxes |
| 16 |
* @since 3.5 |
| 17 |
*/ |
| 18 |
if(!defined('WPINC')) // MUST have WordPress. |
| 19 |
exit("Do not access this file directly."); |
| 20 |
|
| 21 |
if(!class_exists("c_ws_plugin__s2member_meta_box_security")) |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Security meta box. |
| 25 |
* |
| 26 |
* @package s2Member\Meta_Boxes |
| 27 |
* @since 3.5 |
| 28 |
*/ |
| 29 |
class c_ws_plugin__s2member_meta_box_security |
| 30 |
{ |
| 31 |
/** |
| 32 |
* Adds security meta box to Post/Page editing stations. |
| 33 |
* |
| 34 |
* @package s2Member\Meta_Boxes |
| 35 |
* @since 3.5 |
| 36 |
* |
| 37 |
* @param object $post Post/Page object. |
| 38 |
* @return null |
| 39 |
*/ |
| 40 |
public static function security_meta_box($post = FALSE) |
| 41 |
{ |
| 42 |
foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v; |
| 43 |
do_action("ws_plugin__s2member_before_security_meta_box", get_defined_vars()); |
| 44 |
unset($__refs, $__v); |
| 45 |
|
| 46 |
if(is_object($post) && ($post_id = $post->ID) && (($post->post_type === "page" && current_user_can("edit_page", $post_id)) || current_user_can("edit_post", $post_id))) |
| 47 |
{ |
| 48 |
if /* OK. So we're dealing with a Page classification. */($post->post_type === "page" && ($page_id = $post_id)) |
| 49 |
{ |
| 50 |
if(!in_array($page_id, array_merge(array($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"], $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"], $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"]), preg_split("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["specific_ids"])))) |
| 51 |
{ |
| 52 |
echo '<input type="hidden" name="ws_plugin__s2member_security_meta_box_save" id="ws-plugin--s2member-security-meta-box-save" value="'.esc_attr(wp_create_nonce("ws-plugin--s2member-security-meta-box-save")).'" />'."\n"; |
| 53 |
echo '<input type="hidden" name="ws_plugin__s2member_security_meta_box_save_id" id="ws-plugin--s2member-security-meta-box-save-id" value="'.esc_attr($page_id).'" />'."\n"; |
| 54 |
|
| 55 |
for($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++) |
| 56 |
$pages[$n] = array_unique(preg_split("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level".$n."_pages"])); |
| 57 |
|
| 58 |
for($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++) |
| 59 |
$posts[$n] = array_unique(preg_split("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level".$n."_posts"])); |
| 60 |
|
| 61 |
echo '<p style="margin-left:2px;"><strong>Page Level Restriction?</strong></p>'."\n"; |
| 62 |
echo '<label class="screen-reader-text" for="ws-plugin--s2member-security-meta-box-level">Add Level Restriction?</label>'."\n"; |
| 63 |
echo '<select name="ws_plugin__s2member_security_meta_box_level" id="ws-plugin--s2member-security-meta-box-level" style="width:99%;">'."\n"; |
| 64 |
echo /* By default, we allow public access to any Post/Page. */'<option value=""></option>'."\n"; |
| 65 |
|
| 66 |
for($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++) |
| 67 |
echo ($pages[$n] !== array("all")) ? // Protecting `all` Pages, of any kind? |
| 68 |
((!in_array("all-page", $posts[$n]) && !in_array("all-pages", $posts[$n])) // Protecting Posts of type: `page`? |
| 69 |
? '<option value="'.$n.'"'.((in_array($page_id, $pages[$n])) ? ' selected="selected"' : '').'>'.(($n === $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]) ? 'Require Highest Level #'.$n : 'Require Level #'.$n.' (or higher)').'</option>'."\n" |
| 70 |
: '<option value="" disabled="disabled">Level #'.$n.' (already protects "all" Posts of this type)</option>'."\n") |
| 71 |
: '<option value="" disabled="disabled">Level #'.$n.' (already protects "all" Pages)</option>'."\n"; |
| 72 |
|
| 73 |
echo '</select><br /><small>* see: <strong>Restriction Options → Pages</strong></small>'."\n"; |
| 74 |
|
| 75 |
if(!is_multisite() || !c_ws_plugin__s2member_utils_conds::is_multisite_farm() || is_main_site()) |
| 76 |
// ^ Will change once Custom Capabilities are compatible with a Blog Farm. |
| 77 |
{ |
| 78 |
echo '<p style="margin-top:15px; margin-left:2px;"><strong>Require Custom Capabilities?</strong></p>'."\n"; |
| 79 |
echo '<label class="screen-reader-text" for="ws-plugin--s2member-security-meta-box-ccaps">Custom Capabilities?</label>'."\n"; |
| 80 |
echo '<input type="text" autocomplete="off" name="ws_plugin__s2member_security_meta_box_ccaps" id="ws-plugin--s2member-security-meta-box-ccaps" value="'.format_to_edit(trim(implode(",", (array)get_post_meta($page_id, "s2member_ccaps_req", true)))).'" onkeyup="if(this.value.match(/[^a-z_0-9,]/)) this.value = jQuery.trim (jQuery.trim (this.value).replace (/[ \-]/g, \'_\').replace (/[^a-z_0-9,]/gi, \'\').toLowerCase ());" style="width:99%;" />'."\n"; |
| 81 |
echo '<br /><small>* see: <strong>API Scripting → Custom Capabilities</strong></small>'."\n"; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
else if($page_id == $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]) |
| 86 |
echo 'This Page is your:<br /><strong>Membership Options Page</strong><br />(always publicly available)'; |
| 87 |
|
| 88 |
else if($page_id == $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"]) |
| 89 |
echo 'This Page is your:<br /><strong>Login Welcome Page</strong><br />(automatically guarded by s2Member)'; |
| 90 |
|
| 91 |
else if($page_id == $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"]) |
| 92 |
echo 'This Page is your:<br /><strong>Download Limit Exceeded Page</strong><br />(automatically guarded by s2Member)'; |
| 93 |
|
| 94 |
else if(in_array($page_id, preg_split("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["specific_ids"]))) |
| 95 |
echo 'This Page is a:<br /><strong>Specific Post/Page for sale</strong><br />(already guarded by s2Member)'; |
| 96 |
} |
| 97 |
else // Otherwise, we assume this is a Post, or possibly a Custom Post Type. It's NOT a Page. |
| 98 |
{ |
| 99 |
if(!in_array($post_id, preg_split("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["specific_ids"]))) |
| 100 |
{ |
| 101 |
echo '<input type="hidden" name="ws_plugin__s2member_security_meta_box_save" id="ws-plugin--s2member-security-meta-box-save" value="'.esc_attr(wp_create_nonce("ws-plugin--s2member-security-meta-box-save")).'" />'."\n"; |
| 102 |
echo '<input type="hidden" name="ws_plugin__s2member_security_meta_box_save_id" id="ws-plugin--s2member-security-meta-box-save-id" value="'.esc_attr($post_id).'" />'."\n"; |
| 103 |
|
| 104 |
for($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++) |
| 105 |
$posts[$n] = array_unique(preg_split("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level".$n."_posts"])); |
| 106 |
|
| 107 |
echo '<p style="margin-left:2px;"><strong>Post Level Restriction?</strong></p>'."\n"; |
| 108 |
echo '<label class="screen-reader-text" for="ws-plugin--s2member-security-meta-box-level">Add Level Restriction?</label>'."\n"; |
| 109 |
echo '<select name="ws_plugin__s2member_security_meta_box_level" id="ws-plugin--s2member-security-meta-box-level" style="width:99%;">'."\n"; |
| 110 |
echo '<option value=""></option>'."\n"; // By default, we allow public access to any Post/Page. |
| 111 |
|
| 112 |
for($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++) |
| 113 |
echo ($posts[$n] !== array("all")) ? // Protecting `all` Posts, of any kind? |
| 114 |
((!in_array("all-".$post->post_type, $posts[$n]) && !in_array("all-".$post->post_type."s", $posts[$n])) // Protecting Posts `all-[of-this-type]`? |
| 115 |
? '<option value="'.$n.'"'.((in_array($post_id, $posts[$n])) ? ' selected="selected"' : '').'>'.(($n === $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]) ? 'Require Highest Level #'.$n : 'Require Level #'.$n.' (or higher)').'</option>'."\n" |
| 116 |
: '<option value="" disabled="disabled">Level #'.$n.' (already protects "all" Posts of this type)</option>'."\n") |
| 117 |
: '<option value="" disabled="disabled">Level #'.$n.' (already protects "all" Posts)</option>'."\n"; |
| 118 |
|
| 119 |
echo '</select><br /><small>* see: <strong>Restriction Options → Posts</strong></small>'."\n"; |
| 120 |
|
| 121 |
if(!is_multisite() || !c_ws_plugin__s2member_utils_conds::is_multisite_farm() || is_main_site()) |
| 122 |
// ^ Will change once Custom Capabilities are compatible with a Blog Farm. |
| 123 |
{ |
| 124 |
echo '<p style="margin-top:15px; margin-left:2px;"><strong>Require Custom Capabilities?</strong></p>'."\n"; |
| 125 |
echo '<label class="screen-reader-text" for="ws-plugin--s2member-security-meta-box-ccaps">Custom Capabilities?</label>'."\n"; |
| 126 |
echo '<input type="text" autocomplete="off" name="ws_plugin__s2member_security_meta_box_ccaps" id="ws-plugin--s2member-security-meta-box-ccaps" value="'.format_to_edit(trim(implode(",", (array)get_post_meta($post_id, "s2member_ccaps_req", true)))).'" onkeyup="if(this.value.match(/[^a-z_0-9,]/)) this.value = jQuery.trim (jQuery.trim (this.value).replace (/[ \-]/g, \'_\').replace (/[^a-z_0-9,]/gi, \'\').toLowerCase ());" style="width:99%;" />'."\n"; |
| 127 |
echo '<br /><small>* see: <strong>API Scripting → Custom Capabilities</strong></small>'."\n"; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
else if(in_array($post_id, preg_split("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["specific_ids"]))) |
| 132 |
echo 'This Post is a:<br /><strong>Specific Post/Page for sale</strong><br />(already guarded by s2Member)'; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
do_action("ws_plugin__s2member_after_security_meta_box", get_defined_vars()); |
| 137 |
|
| 138 |
return /* Return for uniformity. */; |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
|