PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 260917
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v260917
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 260917, at src/includes/classes/sc-gets-in.inc.php

160 lines 8.4 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 //260913.1656 Only format explicitly known timestamp constants, and reject non-string formats before passing them to date().
90 if(is_string($attr['date_format']) && $attr['date_format'] && is_int($get) && $get > 0 && in_array($attr['constant'], array('S2MEMBER_CURRENT_USER_REGISTRATION_TIME', 'S2MEMBER_CURRENT_USER_PAID_REGISTRATION_TIME'), true))
91 {
92 if($attr['date_format'] === 'timestamp')
93 $get = (string)$get; // No change.
94
95 else if($attr['date_format'] === 'default')
96 $get = date(get_option('date_format'), $get);
97
98 else $get = date($attr['date_format'], $get);
99 }
100 }
101 else if($attr['user_field'] && isset($valid_user_fields[$attr['user_field']]))
102 {
103 $user_field_args = array('size' => $attr['size']);
104 //260813 Record blocked cross-user fields for the shared administrator warning.
105 if($attr['user_id_backup'] > 0 && $attr['user_id_backup'] !== get_current_user_id() && !isset($shortcode_user_fields_whitelist[strtolower($attr['user_field'])]))
106 c_ws_plugin__s2member_admin_notices::shortcode_user_field_unapproved($attr['user_field'], ($shortcode) ? $shortcode : 's2Get', get_the_ID());
107 $user_field_user_id = (isset($shortcode_user_fields_whitelist[strtolower($attr['user_field'])]) && $attr['user_id_backup'] > 0) ? $attr['user_id_backup'] : 0;
108 $get = c_ws_plugin__s2member_utils_users::get_user_field($attr['user_field'], $user_field_user_id, $user_field_args);
109
110 if(preg_match('/time$/i', $attr['user_field']) && $attr['date_format'])
111 if((is_numeric($get) && strlen($get) === 10) || ($get = strtotime($get))) // Timestamp?
112 {
113 if($attr['date_format'] === 'timestamp')
114 $get = (string)$get; // No change.
115
116 else if($attr['date_format'] === 'default')
117 $get = date(get_option('date_format'), (int)$get);
118
119 else $get = date($attr['date_format'], (int)$get);
120 }
121 }
122 else if($attr['user_option'] && isset($valid_user_options[$attr['user_option']]))
123 {
124 $get = get_user_option($attr['user_option'], (int)$attr['user_id']);
125
126 if(preg_match('/time$/i', $attr['user_option']) && $attr['date_format'])
127 if((is_numeric($get) && strlen($get) === 10) || ($get = strtotime($get))) // Timestamp?
128 {
129 if($attr['date_format'] === 'timestamp')
130 $get = (string)$get; // No change.
131
132 else if($attr['date_format'] === 'default')
133 $get = date(get_option('date_format'), (int)$get);
134
135 else $get = date($attr['date_format'], (int)$get);
136 }
137 }
138 if(isset($get) && (is_array($get) || is_object($get)))
139 {
140 $_get_array = $get; // Temporary variable.
141 $get = array(); // New empty array.
142
143 foreach($_get_array as $_key_prop => $_value)
144 {
145 if(is_scalar($_value)) // One dimension only.
146 $get[$_key_prop] = (string)$_value;
147 }
148 unset($_get_array, $_key_prop, $_value); // Housekeeping.
149
150 $get = implode(', ', $get); // Convert to a string now.
151 }
152 if(isset($get) && !is_scalar($get))
153 $get = ''; // Do not allow non-scalar values to be returned by a shortcode.
154 else if(isset($get)) $get = (string)$get; // Convert to a string.
155
156 return apply_filters('ws_plugin__s2member_sc_get_details', isset($get) ? $get : '', get_defined_vars());
157 }
158 }
159 }
160