PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110710
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110710
260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 120219 All 188 releases
s2member / includes / classes / utils-forms.inc.php

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

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