PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / trunk
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions vtrunk
260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 120219 All 188 releases
s2member / src / includes / classes / sc-gets-in.inc.php

sc-gets-in.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions trunk, at src/includes/classes/sc-gets-in.inc.php

148 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // @codingStandardsIgnoreFile
3 /**
4 * Shortcode `[s2Get /]` (inner processing routines).
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\s2Get
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_sc_gets_in'))
22 {
23 /**
24 * Shortcode `[s2Get /]` (inner processing routines).
25 *
26 * @package s2Member\s2Get
27 * @since 3.5
28 */
29 class c_ws_plugin__s2member_sc_gets_in
30 {
31 /**
32 * Handles the Shortcode for: `[s2Get /]`.
33 *
34 * @package s2Member\s2Get
35 * @since 3.5
36 *
37 * @attaches-to ``add_shortcode('s2Get');``
38 *
39 * @param array $attr An array of Attributes.
40 * @param string $content Content inside the Shortcode.
41 * @param string $shortcode The actual Shortcode name itself.
42 *
43 * @return mixed Value of the requested data.
44 */
45 public static function sc_get_details($attr = array(), $content = '', $shortcode = '')
46 {
47 foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
48 do_action('ws_plugin__s2member_before_sc_get_details', get_defined_vars());
49 unset($__refs, $__v); // Allow variables to be modified by reference.
50
51 c_ws_plugin__s2member_no_cache::no_cache_constants(true);
52
53 $attr = shortcode_atts( // Attributes.
54 array(
55 // One of these.
56 'constant' => '',
57 'user_field' => '',
58 'user_option' => '',
59
60 // Options.
61 'user_id' => '',
62 'date_format' => '',
63 'size' => '',
64 ),
65 c_ws_plugin__s2member_utils_strings::trim_qts_deep((array)$attr)
66 );
67
68 //241114 Valid attribute values
69 $valid_constants = array_flip(array('S2MEMBER_CURRENT_USER_ACCESS_LABEL', 'S2MEMBER_CURRENT_USER_ACCESS_LEVEL', 'S2MEMBER_CURRENT_USER_CUSTOM', 'S2MEMBER_CURRENT_USER_DISPLAY_NAME', 'S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED', 'S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS', 'S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_IS_UNLIMITED', 'S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY', 'S2MEMBER_CURRENT_USER_EMAIL', 'S2MEMBER_CURRENT_USER_FIELDS', 'S2MEMBER_CURRENT_USER_FIRST_NAME', 'S2MEMBER_CURRENT_USER_ID', 'S2MEMBER_CURRENT_USER_IP', 'S2MEMBER_CURRENT_USER_IS_LOGGED_IN', 'S2MEMBER_CURRENT_USER_IS_LOGGED_IN_AS_MEMBER', 'S2MEMBER_CURRENT_USER_LAST_NAME', 'S2MEMBER_CURRENT_USER_LOGIN', 'S2MEMBER_CURRENT_USER_LOGIN_COUNTER', 'S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS', 'S2MEMBER_CURRENT_USER_PAID_REGISTRATION_TIME', 'S2MEMBER_CURRENT_USER_PROFILE_MODIFICATION_PAGE_URL', 'S2MEMBER_CURRENT_USER_REGISTRATION_DAYS', 'S2MEMBER_CURRENT_USER_REGISTRATION_IP', 'S2MEMBER_CURRENT_USER_REGISTRATION_TIME', 'S2MEMBER_CURRENT_USER_SUBSCR_GATEWAY', 'S2MEMBER_CURRENT_USER_SUBSCR_ID', 'S2MEMBER_CURRENT_USER_SUBSCR_OR_WP_ID', 'S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON0', 'S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON1', 'S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS0', 'S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS1'));
70 $valid_user_fields = array_flip(array('user_login', 'user_email', 'first_name', 'last_name', 'full_name', 'display_name', 'avatar', 's2member_custom', 's2member_subscr_id', 's2member_subscr_or_wp_id', 's2member_subscr_gateway', 's2member_registration_ip', 's2member_custom_fields', 's2member_file_download_access_log', 's2member_file_download_access_arc', 's2member_auto_eot_time', 's2member_last_payment_time', 's2member_paid_registration_times', 's2member_access_role', 's2member_access_level', 's2member_access_label', 's2member_ccaps', 's2member_file_downloads_allowed', 's2member_file_downloads_allowed_is_unlimited', 's2member_file_downloads_current', 's2member_login_counter', 's2member_last_login_time', 's2member_notes'));
71 $valid_user_fields += get_s2member_custom_fields(); //250211
72 $valid_user_options = array_flip(array('s2member_custom', 's2member_subscr_id', 's2member_subscr_gateway', 's2member_registration_ip', 's2member_login_counter', 's2member_last_payment_time', 's2member_access_label', 's2member_ccaps'));
73 // Current user only
74 $attr['user_id_backup'] = (int)$attr['user_id'];
75 $attr['user_id'] = 0;
76 //260812 Load the shared user-fields whitelist for cross-user shortcode access.
77 $shortcode_user_fields_whitelist = trim((string)$GLOBALS['WS_PLUGIN__']['s2member']['o']['sc_user_fields_whitelist']);
78 $shortcode_user_fields_whitelist = ($shortcode_user_fields_whitelist !== '') ? preg_split('/\s*,\s*/', strtolower($shortcode_user_fields_whitelist), -1, PREG_SPLIT_NO_EMPTY) : array();
79 $shortcode_user_fields_whitelist = array_flip($shortcode_user_fields_whitelist);
80
81 foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
82 do_action('ws_plugin__s2member_before_sc_get_details_after_shortcode_atts', get_defined_vars());
83 unset($__refs, $__v); // Allow variables to be modified by reference.
84
85 if($attr['constant'] && defined($attr['constant']) && isset($valid_constants[$attr['constant']]))
86 {
87 $get = constant($attr['constant']);
88 }
89 else if($attr['user_field'] && isset($valid_user_fields[$attr['user_field']]))
90 {
91 $user_field_args = array('size' => $attr['size']);
92 //260813 Record blocked cross-user fields for the shared administrator warning.
93 if($attr['user_id_backup'] > 0 && $attr['user_id_backup'] !== get_current_user_id() && !isset($shortcode_user_fields_whitelist[strtolower($attr['user_field'])]))
94 c_ws_plugin__s2member_admin_notices::shortcode_user_field_unapproved($attr['user_field'], ($shortcode) ? $shortcode : 's2Get', get_the_ID());
95 $user_field_user_id = (isset($shortcode_user_fields_whitelist[strtolower($attr['user_field'])]) && $attr['user_id_backup'] > 0) ? $attr['user_id_backup'] : 0;
96 $get = c_ws_plugin__s2member_utils_users::get_user_field($attr['user_field'], $user_field_user_id, $user_field_args);
97
98 if(preg_match('/time$/i', $attr['user_field']) && $attr['date_format'])
99 if((is_numeric($get) && strlen($get) === 10) || ($get = strtotime($get))) // Timestamp?
100 {
101 if($attr['date_format'] === 'timestamp')
102 $get = (string)$get; // No change.
103
104 else if($attr['date_format'] === 'default')
105 $get = date(get_option('date_format'), (int)$get);
106
107 else $get = date($attr['date_format'], (int)$get);
108 }
109 }
110 else if($attr['user_option'] && isset($valid_user_options[$attr['user_option']]))
111 {
112 $get = get_user_option($attr['user_option'], (int)$attr['user_id']);
113
114 if(preg_match('/time$/i', $attr['user_option']) && $attr['date_format'])
115 if((is_numeric($get) && strlen($get) === 10) || ($get = strtotime($get))) // Timestamp?
116 {
117 if($attr['date_format'] === 'timestamp')
118 $get = (string)$get; // No change.
119
120 else if($attr['date_format'] === 'default')
121 $get = date(get_option('date_format'), (int)$get);
122
123 else $get = date($attr['date_format'], (int)$get);
124 }
125 }
126 if(isset($get) && (is_array($get) || is_object($get)))
127 {
128 $_get_array = $get; // Temporary variable.
129 $get = array(); // New empty array.
130
131 foreach($_get_array as $_key_prop => $_value)
132 {
133 if(is_scalar($_value)) // One dimension only.
134 $get[$_key_prop] = (string)$_value;
135 }
136 unset($_get_array, $_key_prop, $_value); // Housekeeping.
137
138 $get = implode(', ', $get); // Convert to a string now.
139 }
140 if(isset($get) && !is_scalar($get))
141 $get = ''; // Do not allow non-scalar values to be returned by a shortcode.
142 else if(isset($get)) $get = (string)$get; // Convert to a string.
143
144 return apply_filters('ws_plugin__s2member_sc_get_details', isset($get) ? $get : '', get_defined_vars());
145 }
146 }
147 }
148