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-eots-in.inc.php

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

183 lines 7.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 `[s2Eot /]` (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\s2Eot
16 * @since 150713
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_eots_in'))
22 {
23 /**
24 * Shortcode `[s2Eot /]` (inner processing routines).
25 *
26 * @package s2Member\s2Eot
27 * @since 150713
28 */
29 class c_ws_plugin__s2member_sc_eots_in
30 {
31 /**
32 * Handles the Shortcode for: `[s2Eot /]`.
33 *
34 * @package s2Member\s2Eot
35 * @since 150713
36 *
37 * @attaches-to ``add_shortcode('s2Eot');``
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 string Value of the requested data.
44 */
45 public static function sc_eot_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_eot_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 = (array) $attr; // Force an array.
54
55 $mode = ''; // Initialize shortcode mode and validate.
56 if(!empty($attr['mode']) && in_array(strtolower($attr['mode']), array('fixed', 'next'), TRUE))
57 $mode = strtolower($attr['mode']); // A specific mode; i.e., `fixed`, `next`.
58
59 if(empty($attr['user_id']) || !(int)$attr['user_id'])
60 $attr['user_id'] = $user_id = get_current_user_id();
61 else $user_id = (int)$attr['user_id'];
62
63 $subscr_gateway = get_user_option('s2member_subscr_gateway', $user_id);
64 $subscr_id = get_user_option('s2member_subscr_id', $user_id);
65 $subscr_cid = get_user_option('s2member_subscr_cid', $user_id);
66 $auto_eot_time = get_user_option('s2member_auto_eot_time', $user_id);
67
68 $attr = shortcode_atts( // Attributes.
69 array(
70 'debug' => 'no', // Off.
71 'user_id' => '0', // Current.
72 'date_format' => 'M jS, Y, g:i a T',
73 'round_to' => '', // Optional rounding.
74 'offset' => '0', // Optional time offset.
75 'timezone' => '', // Default timezone; i.e., GMT/UTC.
76 'future_format' => $mode ? '%%date%%' : '<strong class="s2member-sc-eot-label -future">'._x('Access Expires:', 's2member-front', 's2member').'</strong> <span class="s2member-sc-eot-date -future">%%date%%</span>',
77 'past_format' => $mode ? '%%date%%' : '<strong class="s2member-sc-eot-label -past">'._x('Access Expired:', 's2member-front', 's2member').'</strong> <span class="s2member-sc-eot-date -past">%%date%%</span>',
78 'next_format' => $mode ? '%%date%%' : '<strong class="s2member-sc-eot-label -next">'._x('Next Payment:', 's2member-front', 's2member').'</strong> <span class="s2member-sc-eot-date -next">%%date%%</span>',
79 'empty_format' => $mode ? (in_array($subscr_gateway, array('stripe', 'paypal', 'clickbank'), TRUE) ? _x('N/A', 's2member-front', 's2member') : _x('', 's2member-front', 's2member')) : '',
80 ),
81 c_ws_plugin__s2member_utils_strings::trim_qts_deep($attr)
82 );
83 foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
84 do_action('ws_plugin__s2member_before_sc_eot_details_after_shortcode_atts', get_defined_vars());
85 unset($__refs, $__v); // Allow variables to be modified by reference.
86
87 //251223 Sanitize shortcode attributes
88 foreach ($attr as $key => $value) {
89 if (in_array($key, array('user_id', 'offset'), true)) {
90 $attr[$key] = (int) $value;
91 } elseif (in_array($key, array('debug', 'date_format', 'round_to', 'timezone'), true)) {
92 $attr[$key] = sanitize_text_field($value);
93 } elseif (in_array($key, array('future_format', 'past_format', 'next_format', 'empty_format'), true)) {
94 $attr[$key] = wp_kses_post($value);
95 }
96 }
97
98 // Collect and cache the EOT for this user.
99
100 $prefix = 's2m_eot_'; // Transient prefix for this shortcode.
101 $hash_vars = $user_id.$subscr_gateway.$subscr_id.$subscr_cid.$auto_eot_time;
102 $transient = $prefix.md5('s2member_sc_eot_'.$mode.serialize($attr).$hash_vars);
103
104 if(!is_array($eot = get_transient($transient)))
105 {
106 $eot = c_ws_plugin__s2member_utils_users::get_user_eot($user_id, true, $mode);
107 set_transient($transient, $eot, DAY_IN_SECONDS / 2);
108 }
109 if($eot['time'] && (int)$attr['offset'])
110 $eot['time'] = $eot['time'] + (int)$attr['offset'];
111
112 // Initialize EOT details/output format.
113
114 if($eot['type'] === 'fixed' && $eot['time'] && $eot['tense'] === 'past')
115 $details = $attr['past_format'];
116
117 else if($eot['type'] === 'fixed' && $eot['time'] && $eot['tense'] === 'future')
118 $details = $attr['future_format'];
119
120 else if($eot['type'] === 'next' && $eot['time'] && $eot['tense'] === 'future')
121 $details = $attr['next_format'];
122
123 else $details = $attr['empty_format'];
124
125 // Initialize EOT details/output date format.
126
127 $time = null; // Initialize the time calculation.
128 if($eot['time']) // // Do we have a time to work with?
129 {
130 $time = new DateTime(date('Y-m-d H:i:s', $eot['time']));
131 if($attr['timezone'] && strtoupper($attr['timezone']) !== 'UTC')
132 $time->setTimezone(new DateTimeZone($attr['timezone']));
133 if($attr['round_to'])
134 $time->modify($attr['round_to']);
135 }
136 if($time && $attr['date_format'] === 'timestamp')
137 $date = (string)$time->getTimestamp();
138
139 else if($time && $attr['date_format'] === 'default')
140 $date = $time->format(get_option('date_format'));
141
142 else if($time && $attr['date_format'])
143 $date = $time->format($attr['date_format']);
144
145 else if($time) // Default date/time format.
146 $date = $time->format('M jS, Y, g:i a T');
147
148 else $date = ''; // Default date; i.e., nothing.
149
150 $details = str_ireplace('%%date%%', esc_html($date), $details);
151
152 // Check special considerations and the current mode.
153
154 if($eot['type'] === 'fixed' && !$GLOBALS['WS_PLUGIN__']['s2member']['o']['auto_eot_system_enabled'])
155 {
156 $details = $attr['empty_format']; // EOTs are disabled on this site.
157 $eot['debug'] = 's2Member\'s Auto-EOT System is disabled on this site.';
158 }
159 else if($eot['type'] === 'fixed' && $mode === 'next')
160 {
161 $details = $attr['empty_format']; // Empty this.
162 $eot['debug'] = 'No fixed EOT time was found for this user.';
163 }
164 else if($eot['type'] === 'next' && $mode === 'fixed')
165 {
166 $details = $attr['empty_format']; // Empty this.
167 $eot['debug'] = 'No more payments needed from this user.';
168 }
169 // Wrapper and debug info...
170
171 if($details) // Wrapper for CSS styling.
172 $details = '<span class="ws-plugin--s2member-sc-eot">'.$details.'</span>';
173
174 if(filter_var($attr['debug'], FILTER_VALIDATE_BOOLEAN))
175 $details .= '<pre>'.esc_html($eot['debug'] ? $eot['debug'] : 'Unknown error.').'</pre>';
176
177 // Return the details/output from this shortcode.
178
179 return apply_filters('ws_plugin__s2member_sc_eot_details', $details, get_defined_vars());
180 }
181 }
182 }
183