PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110731
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110731
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 / includes / classes / paypal-utilities.inc.php

paypal-utilities.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110731, at includes/classes/paypal-utilities.inc.php

465 lines 22.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PayPal® utilities.
4 *
5 * Copyright: © 2009-2011
6 * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
7 * ( coded in the USA )
8 *
9 * Released under the terms of the GNU General Public License.
10 * You should have received a copy of the GNU General Public License,
11 * along with this software. In the main directory, see: /licensing/
12 * If not, see: {@link http://www.gnu.org/licenses/}.
13 *
14 * @package s2Member\PayPal
15 * @since 3.5
16 */
17 if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
18 exit ("Do not access this file directly.");
19 /**/
20 if (!class_exists ("c_ws_plugin__s2member_paypal_utilities"))
21 {
22 /**
23 * PayPal® utilities.
24 *
25 * @package s2Member\PayPal
26 * @since 3.5
27 */
28 class c_ws_plugin__s2member_paypal_utilities
29 {
30 /**
31 * Get ``$_POST`` or ``$_REQUEST`` vars from PayPal®.
32 *
33 * @package s2Member\PayPal
34 * @since 3.5
35 *
36 * @return array|bool An array of verified ``$_POST`` or ``$_REQUEST`` variables, else false.
37 */
38 public static function paypal_postvars ()
39 {
40 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
41 do_action ("ws_plugin__s2member_before_paypal_postvars", get_defined_vars ());
42 unset ($__refs, $__v); /* Unset defined __refs, __v. */
43 /*
44 Custom conditionals can be applied by filters.
45 */
46 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
47 if (!($postvars = apply_filters ("ws_plugin__s2member_during_paypal_postvars_conditionals", array (), get_defined_vars ())))
48 {
49 unset ($__refs, $__v); /* Unset defined __refs, __v. */
50 /**/
51 if (!empty ($_GET["tx"]) && empty ($_GET["s2member_paypal_proxy"]))
52 {
53 $postback["tx"] = $_GET["tx"];
54 $postback["cmd"] = "_notify-synch";
55 $postback["at"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_identity_token"];
56 /**/
57 $endpoint = ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_sandbox"]) ? "www.sandbox.paypal.com" : "www.paypal.com";
58 /**/
59 if (preg_match ("/^SUCCESS/i", ($response = trim (c_ws_plugin__s2member_utils_urls::remote ("https://" . $endpoint . "/cgi-bin/webscr", $postback, array ("timeout" => 20))))))
60 {
61 foreach (preg_split ("/[\r\n]+/", preg_replace ("/^SUCCESS/i", "", $response)) as $varline)
62 {
63 list ($key, $value) = preg_split ("/\=/", $varline, 2);
64 if (strlen ($key = trim ($key)) && strlen ($value = trim ($value)))
65 $postvars[$key] = trim (stripslashes (urldecode ($value)));
66 }
67 /**/
68 return apply_filters ("ws_plugin__s2member_paypal_postvars", $postvars, get_defined_vars ());
69 }
70 else /* Nope. */
71 return false;
72 }
73 else if (!empty ($_REQUEST) && is_array ($postvars = stripslashes_deep ($_REQUEST)))
74 {
75 foreach ($postvars as $key => $value)
76 if (preg_match ("/^s2member_/", $key))
77 unset ($postvars[$key]);
78 /**/
79 $postback = $postvars; /* Copy. */
80 $postback["cmd"] = "_notify-validate";
81 /**/
82 $postvars = c_ws_plugin__s2member_utils_strings::trim_deep ($postvars);
83 /**/
84 $endpoint = ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_sandbox"]) ? "www.sandbox.paypal.com" : "www.paypal.com";
85 /**/
86 if (!empty ($_GET["s2member_paypal_proxy"]) && !empty ($_GET["s2member_paypal_proxy_verification"]) && $_GET["s2member_paypal_proxy_verification"] === c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen ())
87 return apply_filters ("ws_plugin__s2member_paypal_postvars", array_merge ($postvars, array ("proxy_verified" => $_GET["s2member_paypal_proxy"])), get_defined_vars ());
88 /**/
89 else if (trim (strtolower (c_ws_plugin__s2member_utils_urls::remote ("https://" . $endpoint . "/cgi-bin/webscr", $postback, array ("timeout" => 20)))) === "verified")
90 return apply_filters ("ws_plugin__s2member_paypal_postvars", $postvars, get_defined_vars ());
91 /**/
92 else /* Nope. */
93 return false;
94 }
95 else /* Nope. */
96 return false;
97 }
98 else /* Else a custom conditional has been applied by Filters. */
99 {
100 unset ($__refs, $__v); /* Unset defined __refs, __v. */
101 /**/
102 return apply_filters ("ws_plugin__s2member_paypal_postvars", $postvars, get_defined_vars ());
103 }
104 }
105 /**
106 * Generates a PayPal® Proxy Key, for simulated IPN responses.
107 *
108 * @package s2Member\PayPal
109 * @since 3.5
110 *
111 * @return str A Proxy Key. It's an MD5 Hash, 32 chars, URL-safe.
112 */
113 public static function paypal_proxy_key_gen () /* Generate Key. */
114 {
115 global $current_site, $current_blog; /* Multisite Networking. */
116 /**/
117 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
118 do_action ("ws_plugin__s2member_before_paypal_proxy_key_gen", get_defined_vars ());
119 unset ($__refs, $__v); /* Unset defined __refs, __v. */
120 /**/
121 if (is_multisite () && !is_main_site ())
122 $key = md5 (c_ws_plugin__s2member_utils_encryption::xencrypt ($current_blog->domain . $current_blog->path));
123 /**/
124 else /* Else it's a standard Proxy Key; not on a Multisite Network, or not on the Main Site anyway. */
125 $key = md5 (c_ws_plugin__s2member_utils_encryption::xencrypt (preg_replace ("/\:[0-9]+$/", "", $_SERVER["HTTP_HOST"])));
126 /**/
127 return apply_filters ("ws_plugin__s2member_paypal_proxy_key_gen", $key, get_defined_vars ());
128 }
129 /**
130 * Calls upon the PayPal® API, and returns the response.
131 *
132 * @package s2Member\PayPal
133 * @since 3.5
134 *
135 * @param array $post_vars An array of variables to send through the PayPal® API call.
136 * @return array An array of variables returned by the PayPal® API.
137 *
138 * @todo Optimize this routine with ``empty()`` and ``isset()``.
139 */
140 public static function paypal_api_response ($post_vars = FALSE)
141 {
142 global $current_site, $current_blog; /* For Multisite support. */
143 /**/
144 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
145 do_action ("ws_plugin__s2member_before_paypal_api_response", get_defined_vars ());
146 unset ($__refs, $__v); /* Unset defined __refs, __v. */
147 /**/
148 $url = "https://" . (($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_sandbox"]) ? "api-3t.sandbox.paypal.com" : "api-3t.paypal.com") . "/nvp";
149 /**/
150 $post_vars = apply_filters ("ws_plugin__s2member_paypal_api_post_vars", $post_vars, get_defined_vars ());
151 $post_vars = (is_array ($post_vars)) ? $post_vars : array (); /* Must be an array. */
152 /**/
153 $post_vars["VERSION"] = "71.0"; /* Configure the PayPal® API version. */
154 $post_vars["USER"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_api_username"];
155 $post_vars["PWD"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_api_password"];
156 $post_vars["SIGNATURE"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_api_signature"];
157 /**/
158 $input_time = date ("D M j, Y g:i:s a T"); /* Record input/nvp for logging. */
159 /**/
160 $nvp = trim (c_ws_plugin__s2member_utils_urls::remote ($url, $post_vars, array ("timeout" => 20)));
161 /**/
162 $output_time = date ("D M j, Y g:i:s a T"); /* Now record after output time. */
163 /**/
164 wp_parse_str ($nvp, $response); /* Parse NVP response. */
165 $response = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($response));
166 /**/
167 if (!$response["ACK"] || !preg_match ("/^(Success|SuccessWithWarning)$/i", $response["ACK"]))
168 {
169 if (strlen ($response["L_ERRORCODE0"]) || $response["L_SHORTMESSAGE0"] || $response["L_LONGMESSAGE0"]) /* Did we at least get an error msg? */
170 $response["__error"] = "Error# " . $response["L_ERRORCODE0"] . ". " . rtrim ($response["L_SHORTMESSAGE0"], ".") . ". " . rtrim ($response["L_LONGMESSAGE0"], ".") . ".";
171 /**/
172 else /* Else, generate an error messsage - so something is reported back to the Customer. */
173 $response["__error"] = "Error. Please contact Support for assistance.";
174 }
175 /*
176 If debugging is enabled; we need to maintain a comprehensive log file.
177 Logging now supports Multisite Networking as well.
178 */
179 $logv = c_ws_plugin__s2member_utilities::ver_details ();
180 $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"];
181 $log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4;
182 $log2 = (is_multisite () && !is_main_site ()) ? "paypal-api-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "paypal-api.log";
183 /**/
184 if (isset ($post_vars["ACCT"]) && strlen ($post_vars["ACCT"]) > 4)
185 $post_vars["ACCT"] = str_repeat ("*", strlen ($post_vars["ACCT"]) - 4) . substr ($post_vars["ACCT"], -4);
186 /**/
187 if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"])
188 if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
189 if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ())
190 if (($log = "-------- Input vars: ( " . $input_time . " ) --------\n" . var_export ($post_vars, true) . "\n"))
191 if (($log .= "-------- Output string/vars: ( " . $output_time . " ) --------\n" . $nvp . "\n" . var_export ($response, true)))
192 file_put_contents ($logs_dir . "/" . $log2, $logv . "\n" . $log4 . "\n" . $log . "\n\n", FILE_APPEND);
193 /**/
194 return apply_filters ("ws_plugin__s2member_paypal_api_response", c_ws_plugin__s2member_paypal_utilities::_paypal_api_response_filters ($response), get_defined_vars ());
195 }
196 /**
197 * A sort of callback function that Filters PayPal® responses.
198 *
199 * Provides alternative explanations in some cases that require special attention.
200 *
201 * @package s2Member\PayPal
202 * @since 3.5
203 *
204 * @param array $response Expects an array of response variables returned by the PayPal® API.
205 * @return array An array of variables returned by the PayPal® API, after ``$response["__error"]`` is Filtered.
206 */
207 public static function _paypal_api_response_filters ($response = FALSE)
208 {
209 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
210 do_action ("_ws_plugin__s2member_before_paypal_api_response_filters", get_defined_vars ());
211 unset ($__refs, $__v); /* Unset defined __refs, __v. */
212 /**/
213 if (!empty ($response["__error"]) && !empty ($response["L_ERRORCODE0"]))
214 {
215 if ($response["L_ERRORCODE0"] == 10422)
216 $response["__error"] = "Error# " . $response["L_ERRORCODE0"] . ". Transaction declined. Please use an alternate funding source.";
217 /**/
218 else if ($response["L_ERRORCODE0"] == 10435)
219 $response["__error"] = "Error# " . $response["L_ERRORCODE0"] . ". Transaction declined. Express Checkout was NOT confirmed.";
220 /**/
221 else if ($response["L_ERRORCODE0"] == 10417)
222 $response["__error"] = "Error# " . $response["L_ERRORCODE0"] . ". Transaction declined. Please use an alternate funding source.";
223 }
224 /**/
225 return $response; /* Filters already applied with: ``ws_plugin__s2member_paypal_api_response``. */
226 }
227 /**
228 * Converts a term `D|W|M|Y` into PayPal® Pro format.
229 *
230 * @package s2Member\PayPal
231 * @since 3.5
232 *
233 * @param str $term Expects one of `D|W|M|Y`.
234 * @return bool|str A full singular description of the term *( i.e. `Day|Week|Month|Year` )*, else false.
235 */
236 public static function paypal_pro_term ($term = FALSE)
237 {
238 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
239 do_action ("ws_plugin__s2member_before_paypal_pro_term", get_defined_vars ());
240 unset ($__refs, $__v); /* Unset defined __refs, __v. */
241 /**/
242 $paypal_pro_terms = array ("D" => "Day", "W" => "Week", "M" => "Month", "Y" => "Year");
243 /**/
244 $pro_term = (!empty ($paypal_pro_terms[strtoupper ($term)])) ? $paypal_pro_terms[strtoupper ($term)] : false;
245 /**/
246 return apply_filters ("ws_plugin__s2member_paypal_pro_term", $pro_term, get_defined_vars ());
247 }
248 /**
249 * Converts a term `Day|Week|Month|Year` into PayPal® Standard format.
250 *
251 * @package s2Member\PayPal
252 * @since 3.5
253 *
254 * @param str $term Expects one of `Day|Week|Month|Year`.
255 * @return bool|str A term code *( i.e. `D|W|M|Y` )*, else false.
256 */
257 public static function paypal_std_term ($term = FALSE)
258 {
259 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
260 do_action ("ws_plugin__s2member_before_paypal_std_term", get_defined_vars ());
261 unset ($__refs, $__v); /* Unset defined __refs, __v. */
262 /**/
263 $paypal_std_terms = array ("DAY" => "D", "WEEK" => "W", "MONTH" => "M", "YEAR" => "Y");
264 /**/
265 $std_term = (!empty ($paypal_std_terms[strtoupper ($term)])) ? $paypal_std_terms[strtoupper ($term)] : false;
266 /**/
267 return apply_filters ("ws_plugin__s2member_paypal_std_term", $std_term, get_defined_vars ());
268 }
269 /**
270 * Get `subscr_id` from either an array with `recurring_payment_id|subscr_id`, or use an existing string.
271 *
272 * @package s2Member\PayPal
273 * @since 3.5
274 *
275 * @param str|array $array_or_string Either an array of PayPal® post vars, or a string.
276 * @return str|bool A `subscr_id` string if non-empty, else false.
277 */
278 public static function paypal_pro_subscr_id ($array_or_string = FALSE)
279 {
280 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
281 do_action ("ws_plugin__s2member_before_paypal_pro_subscr_id", get_defined_vars ());
282 unset ($__refs, $__v); /* Unset defined __refs, __v. */
283 /**/
284 if (is_array ($array = $array_or_string) && !empty ($array["recurring_payment_id"]))
285 $subscr_id = trim ($array["recurring_payment_id"]);
286 /**/
287 else if (is_array ($array = $array_or_string) && !empty ($array["subscr_id"]))
288 $subscr_id = trim ($array["subscr_id"]);
289 /**/
290 else if (is_string ($string = $array_or_string) && !empty ($string))
291 $subscr_id = trim ($string);
292 /**/
293 return apply_filters ("ws_plugin__s2member_paypal_pro_subscr_id", ((!empty ($subscr_id)) ? $subscr_id : false), get_defined_vars ());
294 }
295 /**
296 * Get `item_number` from either an array with `PROFILEREFERENCE|rp_invoice_id|item_number1|item_number`, or use an existing string.
297 *
298 * @package s2Member\PayPal
299 * @since 3.5
300 *
301 * @param str|array $array_or_string Either an array of PayPal® post vars, or a string.
302 * If it's a string, we make sure it is a valid `level:ccaps:eotper` or `sp:ids:expiration` combination.
303 * @return str|bool An `item_number` string if non-empty, else false.
304 */
305 public static function paypal_pro_item_number ($array_or_string = FALSE)
306 {
307 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
308 do_action ("ws_plugin__s2member_before_paypal_pro_item_number", get_defined_vars ());
309 unset ($__refs, $__v); /* Unset defined __refs, __v. */
310 /**/
311 if (is_array ($array = $array_or_string) && (!empty ($array["PROFILEREFERENCE"]) || !empty ($array["rp_invoice_id"])))
312 list ($_reference, $_domain, $_item_number) = array_map ("trim", preg_split ("/~/", ((!empty ($array["PROFILEREFERENCE"])) ? $array["PROFILEREFERENCE"] : $array["rp_invoice_id"]), 3));
313 /**/
314 else if (is_array ($array = $array_or_string) && !empty ($array["item_number1"]))
315 $_item_number = trim ($array["item_number1"]);
316 /**/
317 else if (is_array ($array = $array_or_string) && !empty ($array["item_number"]))
318 $_item_number = trim ($array["item_number"]);
319 /**/
320 else if (is_string ($string = $array_or_string) && !empty ($string))
321 $_item_number = trim ($string);
322 /**/
323 if (!empty ($_item_number) && preg_match ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["membership_item_number_w_or_wo_level_regex"], $_item_number))
324 $item_number = $_item_number;
325 /**/
326 else if (!empty ($_item_number) && preg_match ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["sp_access_item_number_regex"], $_item_number))
327 $item_number = $_item_number;
328 /**/
329 return apply_filters ("ws_plugin__s2member_paypal_pro_item_number", ((!empty ($item_number)) ? $item_number : false), get_defined_vars ());
330 }
331 /**
332 * Get `item_name` from either an array with `product_name|item_name1|item_name`, or use an existing string.
333 *
334 * @package s2Member\PayPal
335 * @since 3.5
336 *
337 * @param str|array $array_or_string Either an array of PayPal® post vars, or a string.
338 * @return str|bool An `item_name` string if non-empty, else false.
339 */
340 public static function paypal_pro_item_name ($array_or_string = FALSE)
341 {
342 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
343 do_action ("ws_plugin__s2member_before_paypal_pro_item_name", get_defined_vars ());
344 unset ($__refs, $__v); /* Unset defined __refs, __v. */
345 /**/
346 if (is_array ($array = $array_or_string) && !empty ($array["product_name"]))
347 $item_name = trim ($array["product_name"]);
348 /**/
349 else if (is_array ($array = $array_or_string) && !empty ($array["item_name1"]))
350 $item_name = trim ($array["item_name1"]);
351 /**/
352 else if (is_array ($array = $array_or_string) && !empty ($array["item_name"]))
353 $item_name = trim ($array["item_name"]);
354 /**/
355 else if (is_string ($string = $array_or_string) && !empty ($string))
356 $item_name = trim ($string);
357 /**/
358 return apply_filters ("ws_plugin__s2member_paypal_pro_item_name", ((!empty ($item_name)) ? $item_name : false), get_defined_vars ());
359 }
360 /**
361 * Get `period1` from either an array with `PROFILEREFERENCE|rp_invoice_id|period1`, or use an existing string.
362 *
363 * This will also convert `1 Day`, into `1 D`, and so on.
364 * This will also convert `1 SemiMonth`, into `2 W`, and so on.
365 *
366 * @package s2Member\PayPal
367 * @since 3.5
368 *
369 * @param str|array $array_or_string Either an array of PayPal® post vars, or a string.
370 * If it's a string, we make sure it is a valid `period term` combination.
371 * @return str A `period1` string if possible, or defaults to `0 D`.
372 */
373 public static function paypal_pro_period1 ($array_or_string = FALSE)
374 {
375 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
376 do_action ("ws_plugin__s2member_before_paypal_pro_period1", get_defined_vars ());
377 unset ($__refs, $__v); /* Unset defined __refs, __v. */
378 /**/
379 if (is_array ($array = $array_or_string) && (!empty ($array["PROFILEREFERENCE"]) || !empty ($array["rp_invoice_id"])))
380 {
381 list ($_reference, $_domain, $_item_number) = array_map ("trim", preg_split ("/~/", ((!empty ($array["PROFILEREFERENCE"])) ? $array["PROFILEREFERENCE"] : $array["rp_invoice_id"]), 3));
382 list ($_start_time, $_period1, $_period3) = array_map ("trim", preg_split ("/\:/", $_reference, 3));
383 }
384 else if (is_array ($array = $array_or_string) && !empty ($array["period1"]))
385 $_period1 = trim ($array["period1"]);
386 /**/
387 else if (is_string ($string = $array_or_string) && !empty ($string))
388 $_period1 = trim ($string);
389 /**/
390 if (!empty ($_period1)) /* Were we able to get a `period1` string? */
391 {
392 list ($num, $span) = array_map ("trim", preg_split ("/ /", $_period1, 2));
393 /**/
394 if (strtoupper ($span) === "SEMIMONTH")
395 if (is_numeric ($num) && $num >= 1)
396 eval ('$num = "2"; $span = "W";');
397 /**/
398 if (strlen ($span) !== 1) /* To Standard format. */
399 $span = c_ws_plugin__s2member_paypal_utilities::paypal_std_term ($span);
400 /**/
401 $span = (preg_match ("/^[DWMY]$/i", $span)) ? $span : "";
402 $num = ($span && is_numeric ($num) && $num >= 0) ? $num : "";
403 /**/
404 $period1 = ($num && $span) ? $num . " " . strtoupper ($span) : "0 D";
405 /**/
406 return apply_filters ("ws_plugin__s2member_paypal_pro_period1", $period1, get_defined_vars ());
407 }
408 else /* Default. */
409 return apply_filters ("ws_plugin__s2member_paypal_pro_period1", "0 D", get_defined_vars ());
410 }
411 /**
412 * Get `period3` from either an array with `PROFILEREFERENCE|rp_invoice_id|period3`, or use an existing string.
413 *
414 * This will also convert `1 Day`, into `1 D`, and so on.
415 * This will also convert `1 SemiMonth`, into `2 W`, and so on.
416 * The Regular Period can never be less than 1 day ( `1 D` ).
417 *
418 * @package s2Member\PayPal
419 * @since 3.5
420 *
421 * @param str|array $array_or_string Either an array of PayPal® post vars, or a string.
422 * If it's a string, we make sure it is a valid `period term` combination.
423 * @return str A `period3` string if possible, or defaults to `1 D`.
424 */
425 public static function paypal_pro_period3 ($array_or_string = FALSE)
426 {
427 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
428 do_action ("ws_plugin__s2member_before_paypal_pro_period3", get_defined_vars ());
429 unset ($__refs, $__v); /* Unset defined __refs, __v. */
430 /**/
431 if (is_array ($array = $array_or_string) && (!empty ($array["PROFILEREFERENCE"]) || !empty ($array["rp_invoice_id"])))
432 {
433 list ($_reference, $_domain, $_item_number) = array_map ("trim", preg_split ("/~/", ((!empty ($array["PROFILEREFERENCE"])) ? $array["PROFILEREFERENCE"] : $array["rp_invoice_id"]), 3));
434 list ($_start_time, $_period1, $_period3) = array_map ("trim", preg_split ("/\:/", $_reference, 3));
435 }
436 else if (is_array ($array = $array_or_string) && !empty ($array["period3"]))
437 $_period3 = trim ($array["period3"]);
438 /**/
439 else if (is_string ($string = $array_or_string) && !empty ($string))
440 $_period3 = trim ($string);
441 /**/
442 if (!empty ($_period3)) /* Were we able to get a `period3` string? */
443 {
444 list ($num, $span) = array_map ("trim", preg_split ("/ /", $_period3, 2));
445 /**/
446 if (strtoupper ($span) === "SEMIMONTH")
447 if (is_numeric ($num) && $num >= 1)
448 eval ('$num = "2"; $span = "W";');
449 /**/
450 if (strlen ($span) !== 1) /* To Standard format. */
451 $span = c_ws_plugin__s2member_paypal_utilities::paypal_std_term ($span);
452 /**/
453 $span = (preg_match ("/^[DWMY]$/i", $span)) ? $span : "";
454 $num = ($span && is_numeric ($num) && $num >= 0) ? $num : "";
455 /**/
456 $period3 = ($num && $span) ? $num . " " . strtoupper ($span) : "1 D";
457 /**/
458 return apply_filters ("ws_plugin__s2member_paypal_pro_period3", $period3, get_defined_vars ());
459 }
460 else /* Default. */
461 return apply_filters ("ws_plugin__s2member_paypal_pro_period3", "1 D", get_defined_vars ());
462 }
463 }
464 }
465 ?>