| 1 |
<?php |
| 2 |
// @codingStandardsIgnoreFile |
| 3 |
/** |
| 4 |
* Form utilities. |
| 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\Utilities |
| 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_utils_forms")) |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Form utilities. |
| 25 |
* |
| 26 |
* @package s2Member\Utilities |
| 27 |
* @since 3.5 |
| 28 |
*/ |
| 29 |
class c_ws_plugin__s2member_utils_forms |
| 30 |
{ |
| 31 |
/** |
| 32 |
* Converts a form with hidden inputs into a URL w/ query string. |
| 33 |
* |
| 34 |
* @package s2Member\Utilities |
| 35 |
* @since 3.5 |
| 36 |
* |
| 37 |
* @param string $form A form tag with hidden input fields. |
| 38 |
* @return string A URL with query string equivalents. |
| 39 |
*/ |
| 40 |
public static function form_whips_2_url ($form = FALSE) |
| 41 |
{ |
| 42 |
if (preg_match ("/\<form(.+?)\>/is", $form, $form_attr_m)) // Is this a form? |
| 43 |
{ |
| 44 |
if (preg_match ("/(\s)(action)( ?)(\=)( ?)(['\"])(.+?)(['\"])/is", $form_attr_m[1], $form_action_m)) |
| 45 |
{ |
| 46 |
if (($url = trim ($form_action_m[7]))) // Set URL value dynamically. Now we add values. |
| 47 |
{ |
| 48 |
foreach ((array)c_ws_plugin__s2member_utils_forms::form_whips_2_array($form) as $name => $value) |
| 49 |
{ |
| 50 |
if (strlen ($name) && strlen ($value)) // Check $name → $value lengths. |
| 51 |
|
| 52 |
if (strlen ($value = (preg_match ("/^http(s)?\:\/\//i", $value)) ? rawurlencode ($value) : urlencode ($value))) |
| 53 |
{ |
| 54 |
$url = add_query_arg ($name, $value, $url); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
return $url; |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
return false; |
| 64 |
} |
| 65 |
/** |
| 66 |
* Converts a form with hidden inputs into an associative array. |
| 67 |
* |
| 68 |
* @package s2Member\Utilities |
| 69 |
* @since 3.5 |
| 70 |
* |
| 71 |
* @param string $form A form tag with hidden input fields. |
| 72 |
* @return array An associative array of all hidden input fields. |
| 73 |
*/ |
| 74 |
public static function form_whips_2_array($form = FALSE) |
| 75 |
{ |
| 76 |
if (preg_match ("/\<form(.+?)\>/is", $form)) // Is this a form? |
| 77 |
{ |
| 78 |
if (preg_match_all ("/(?<!\<\!--)\<input(.+?)\>/is", $form, $input_attr_ms, PREG_SET_ORDER)) |
| 79 |
{ |
| 80 |
foreach ($input_attr_ms as $input_attr_m) // Go through each hidden input variable. |
| 81 |
{ |
| 82 |
if (preg_match ("/(\s)(type)( ?)(\=)( ?)(['\"])(hidden)(['\"])/is", $input_attr_m[1])) |
| 83 |
{ |
| 84 |
if (preg_match ("/(\s)(name)( ?)(\=)( ?)(['\"])(.+?)(['\"])/is", $input_attr_m[1], $input_name_m)) |
| 85 |
{ |
| 86 |
if (preg_match ("/(\s)(value)( ?)(\=)( ?)(['\"])(.+?)(['\"])/is", $input_attr_m[1], $input_value_m)) |
| 87 |
{ |
| 88 |
$array[trim ($input_name_m[7])] = trim (wp_specialchars_decode ($input_value_m[7], ENT_QUOTES)); |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
return (array)$array; |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
|