PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 260805
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v260805
260917 260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 All 189 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 260805, at src/includes/classes/sc-gets-in.inc.php

145 lines 7.3 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 //260322 Whitelist user_fields allowed user_id="" via General Options.
77 $sc_s2get_userid_whitelist = trim((string)$GLOBALS['WS_PLUGIN__']['s2member']['o']['sc_s2get_userid_whitelist']);
78 $sc_s2get_userid_whitelist = ($sc_s2get_userid_whitelist !== '') ? preg_split('/\s*,\s*/', strtolower($sc_s2get_userid_whitelist), -1, PREG_SPLIT_NO_EMPTY) : array();
79 $sc_s2get_userid_whitelist = array_flip($sc_s2get_userid_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 $user_field_user_id = (isset($sc_s2get_userid_whitelist[strtolower($attr['user_field'])]) && $attr['user_id_backup'] > 0) ? $attr['user_id_backup'] : 0;
93 $get = c_ws_plugin__s2member_utils_users::get_user_field($attr['user_field'], $user_field_user_id, $user_field_args);
94
95 if(preg_match('/time$/i', $attr['user_field']) && $attr['date_format'])
96 if((is_numeric($get) && strlen($get) === 10) || ($get = strtotime($get))) // Timestamp?
97 {
98 if($attr['date_format'] === 'timestamp')
99 $get = (string)$get; // No change.
100
101 else if($attr['date_format'] === 'default')
102 $get = date(get_option('date_format'), (integer)$get);
103
104 else $get = date($attr['date_format'], (integer)$get);
105 }
106 }
107 else if($attr['user_option'] && isset($valid_user_options[$attr['user_option']]))
108 {
109 $get = get_user_option($attr['user_option'], (int)$attr['user_id']);
110
111 if(preg_match('/time$/i', $attr['user_option']) && $attr['date_format'])
112 if((is_numeric($get) && strlen($get) === 10) || ($get = strtotime($get))) // Timestamp?
113 {
114 if($attr['date_format'] === 'timestamp')
115 $get = (string)$get; // No change.
116
117 else if($attr['date_format'] === 'default')
118 $get = date(get_option('date_format'), (integer)$get);
119
120 else $get = date($attr['date_format'], (integer)$get);
121 }
122 }
123 if(isset($get) && (is_array($get) || is_object($get)))
124 {
125 $_get_array = $get; // Temporary variable.
126 $get = array(); // New empty array.
127
128 foreach($_get_array as $_key_prop => $_value)
129 {
130 if(is_scalar($_value)) // One dimension only.
131 $get[$_key_prop] = (string)$_value;
132 }
133 unset($_get_array, $_key_prop, $_value); // Housekeeping.
134
135 $get = implode(', ', $get); // Convert to a string now.
136 }
137 if(isset($get) && !is_scalar($get))
138 $get = ''; // Do not allow non-scalar values to be returned by a shortcode.
139 else if(isset($get)) $get = (string)$get; // Convert to a string.
140
141 return apply_filters('ws_plugin__s2member_sc_get_details', isset($get) ? $get : '', get_defined_vars());
142 }
143 }
144 }
145