/**
  * Generates all Custom Fields.
  *
  * @package optimizeMember\Custom_Reg_Fields
  * @since 3.5
  *
  * @param str $_function Function calling upon this routine.
  * @param array $_field The Field array of configuration options.
  * @param str $_name_prefix The `name=""` attribute prefix.
  * @param str $_id_prefix The `id=""` attribute prefix.
  * @param str $_classes Optional. String of space separated classes that will go inside the Field's `class=""` attribute.
  * @param str $_styles Optional. String of CSS styles that will go inside the Field's `style=""` attribute.
  * @param str|int $_tabindex. Optional numeric tabindex for the `tabindex=""` attribute.
  * @param str $_attrs Optional. Some additional Field attributes and values.
  * @param array $_submission Optional. But should be passed in with any submission data related to this Field. For instance, you might pass in ``$_POST``.
  * @param str|array $_value Optional. The value of this Field, either by default, or from the ``$_submission`` array.
  * @param str $_editable_context Optional. One of `profile|profile-view|registration`.
  * @return str The resulting Custom Field, in HTML format.
  */
 public static function custom_field_gen($_function = FALSE, $_field = FALSE, $_name_prefix = FALSE, $_id_prefix = FALSE, $_classes = FALSE, $_styles = FALSE, $_tabindex = FALSE, $_attrs = FALSE, $_submission = FALSE, $_value = FALSE, $_editable_context = FALSE)
 {
     eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
     do_action("ws_plugin__optimizemember_before_custom_field_gen", get_defined_vars());
     unset($__refs, $__v);
     /* Unset defined __refs, __v. */
     /**/
     if (!($gen = "") && $_function && is_array($field = $_field) && !empty($field["type"]) && !empty($field["id"]) && $_name_prefix && $_id_prefix) {
         eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
         do_action("ws_plugin__optimizemember_during_custom_field_gen_before", get_defined_vars());
         unset($__refs, $__v);
         /* Unset defined __refs, __v. */
         /**/
         $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"]));
         $field_id_class = preg_replace("/_/", "-", $field_var);
         /**/
         $name_suffix = preg_match("/\\[\$/", $_name_prefix) ? ']' : '';
         $field_name = trim($_name_prefix . $field_var . $name_suffix);
         /**/
         $common = '';
         /* Common attributes. */
         $common .= ' name="' . esc_attr($field_name) . '"';
         $common .= ' id="' . esc_attr($_id_prefix . $field_id_class) . '"';
         $common .= !empty($field["required"]) && $field["required"] === "yes" ? ' aria-required="true"' : '';
         $common .= strlen($_tabindex) ? ' tabindex="' . esc_attr($_tabindex) . '"' : '';
         $common .= !empty($field["expected"]) ? ' data-expected="' . esc_attr($field["expected"]) . '"' : '';
         $common .= $_editable_context === "profile-view" || $_editable_context === "profile" && !empty($field["editable"]) && strpos($field["editable"], "no") === 0 ? ' disabled="disabled"' : '';
         $common .= $_classes || !empty($field["classes"]) ? ' class="' . esc_attr(trim($_classes . (!empty($field["classes"]) ? ' ' . $field["classes"] : ''))) . '"' : '';
         $common .= $_styles || !empty($field["styles"]) ? ' style="' . esc_attr(trim($_styles . (!empty($field["styles"]) ? ' ' . $field["styles"] : ''))) . '"' : '';
         $common .= $_attrs || !empty($field["attrs"]) ? ' ' . trim($_attrs . (!empty($field["attrs"]) ? ' ' . $field["attrs"] : '')) : '';
         /**/
         if ($field["type"] === "text") {
             if ($_editable_context === "profile-view") {
                 $gen = esc_html((string) $_value);
             } else {
                 $gen = '<input type="text" maxlength="100" autocomplete="off"';
                 $gen .= ' value="' . format_to_edit(!$_submission && isset($field["deflt"]) && strlen((string) $field["deflt"]) ? (string) $field["deflt"] : (string) $_value) . '"';
                 $gen .= $common . ' />';
             }
         } else {
             if ($field["type"] === "textarea") {
                 if ($_editable_context === "profile-view") {
                     $gen = nl2br(esc_html((string) $_value));
                 } else {
                     $gen = '<textarea rows="3"' . $common . '>';
                     $gen .= format_to_edit(!$_submission && isset($field["deflt"]) && strlen((string) $field["deflt"]) ? (string) $field["deflt"] : (string) $_value);
                     $gen .= '</textarea>';
                 }
             } else {
                 if ($field["type"] === "select" && !empty($field["options"])) {
                     if ($_editable_context === "profile-view") {
                         foreach (preg_split("/[\r\n\t]+/", $field["options"]) as $option_line) {
                             list($option_value, $option_label, $option_default) = c_ws_plugin__optimizemember_utils_strings::trim_deep(preg_split("/\\|/", trim($option_line)));
                             if ($option_value === (string) $_value) {
                                 $gen = $option_label;
                                 break;
                             }
                         }
                     } else {
                         $gen = '<select' . $common . '>';
                         $selected_default_option = false;
                         foreach (preg_split("/[\r\n\t]+/", $field["options"]) as $option_line) {
                             list($option_value, $option_label, $option_default) = c_ws_plugin__optimizemember_utils_strings::trim_deep(preg_split("/\\|/", trim($option_line)));
                             $gen .= '<option value="' . esc_attr($option_value) . '"' . (($option_default && !$_submission || $option_value === (string) $_value && !$selected_default_option) && ($selected_default_option = true) ? ' selected="selected"' : '') . '>' . $option_label . '</option>';
                         }
                         $gen .= '</select>';
                     }
                 } else {
                     if ($field["type"] === "selects" && !empty($field["options"])) {
                         if ($_editable_context === "profile-view") {
                             foreach (preg_split("/[\r\n\t]+/", $field["options"]) as $option_line) {
                                 list($option_value, $option_label, $option_default) = c_ws_plugin__optimizemember_utils_strings::trim_deep(preg_split("/\\|/", trim($option_line)));
                                 if (in_array($option_value, (array) $_value)) {
                                     $gen .= $option_label . ", ";
                                 }
                             }
                             $gen = c_ws_plugin__optimizemember_utils_strings::trim($gen, 0, ",");
                         } else {
                             $common = preg_replace('/ name\\="(.+?)"/', ' name="$1[]"', $common);
                             $common = preg_replace('/ style\\="(.+?)"/', ' style="height:auto; $1"', $common);
                             /**/
                             $gen = '<select multiple="multiple" size="3"' . $common . '>';
                             foreach (preg_split("/[\r\n\t]+/", $field["options"]) as $option_line) {
                                 list($option_value, $option_label, $option_default) = c_ws_plugin__optimizemember_utils_strings::trim_deep(preg_split("/\\|/", trim($option_line)));
                                 $gen .= '<option value="' . esc_attr($option_value) . '"' . ($option_default && !$_submission || in_array($option_value, (array) $_value) ? ' selected="selected"' : '') . '>' . $option_label . '</option>';
                             }
                             $gen .= '</select>';
                         }
                     } else {
                         if ($field["type"] === "checkbox" && !empty($field["label"])) {
                             if ($_editable_context === "profile-view") {
                                 $gen = (string) $_value ? "yes" : "no";
                             } else {
                                 $gen = '<input type="checkbox" value="1"';
                                 $gen .= (string) $_value ? ' checked="checked"' : '';
                                 $gen .= $common . ' /><label for="' . esc_attr($_id_prefix . $field_id_class) . '" style="display:inline !important; margin:0 !important;">' . $field["label"] . '</label>';
                             }
                         } else {
                             if ($field["type"] === "pre_checkbox" && !empty($field["label"])) {
                                 if ($_editable_context === "profile-view") {
                                     $gen = (string) $_value ? "yes" : "no";
                                 } else {
                                     $gen = '<input type="checkbox" value="1"';
                                     $gen .= !$_submission || (string) $_value ? ' checked="checked"' : '';
                                     $gen .= $common . ' /><label for="' . esc_attr($_id_prefix . $field_id_class) . '" style="display:inline !important; margin:0 !important;">' . $field["label"] . '</label>';
                                 }
                             } else {
                                 if ($field["type"] === "checkboxes" && !empty($field["options"])) {
                                     if ($_editable_context === "profile-view") {
                                         foreach (preg_split("/[\r\n\t]+/", $field["options"]) as $i => $option_line) {
                                             list($option_value, $option_label, $option_default) = c_ws_plugin__optimizemember_utils_strings::trim_deep(preg_split("/\\|/", trim($option_line)));
                                             if (in_array($option_value, (array) $_value)) {
                                                 $gen .= $option_label . ", ";
                                             }
                                         }
                                         $gen = c_ws_plugin__optimizemember_utils_strings::trim($gen, 0, ",");
                                     } else {
                                         $common = preg_replace('/ name\\="(.+?)"/', ' name="$1[]"', $common);
                                         /**/
                                         $sep = apply_filters("ws_plugin__optimizemember_custom_field_gen_checkboxes_sep", "&nbsp;&nbsp;", get_defined_vars());
                                         $opl = apply_filters("ws_plugin__optimizemember_custom_field_gen_checkboxes_opl", "ws-plugin--optimizemember-custom-reg-field-op-l", get_defined_vars());
                                         /**/
                                         foreach (preg_split("/[\r\n\t]+/", $field["options"]) as $i => $option_line) {
                                             $common_i = preg_replace('/ id\\="(.+?)"/', ' id="$1-' . $i . '"', $common);
                                             /**/
                                             list($option_value, $option_label, $option_default) = c_ws_plugin__optimizemember_utils_strings::trim_deep(preg_split("/\\|/", trim($option_line)));
                                             /**/
                                             $gen .= $i > 0 ? $sep : '';
                                             /* Separators can be filtered above. */
                                             $gen .= '<input type="checkbox" value="' . esc_attr($option_value) . '"';
                                             $gen .= $option_default && !$_submission || in_array($option_value, (array) $_value) ? ' checked="checked"' : '';
                                             $gen .= $common_i . ' /><label for="' . esc_attr($_id_prefix . $field_id_class . "-" . $i) . '" class="' . esc_attr($opl) . '" style="display:inline !important; margin:0 !important;">' . $option_label . '</label>';
                                         }
                                     }
                                 } else {
                                     if ($field["type"] === "radios" && !empty($field["options"])) {
                                         if ($_editable_context === "profile-view") {
                                             foreach (preg_split("/[\r\n\t]+/", $field["options"]) as $i => $option_line) {
                                                 list($option_value, $option_label, $option_default) = c_ws_plugin__optimizemember_utils_strings::trim_deep(preg_split("/\\|/", trim($option_line)));
                                                 if ($option_value === (string) $_value) {
                                                     $gen = $option_label;
                                                     break;
                                                 }
                                             }
                                         } else {
                                             $sep = apply_filters("ws_plugin__optimizemember_custom_field_gen_radios_sep", "&nbsp;&nbsp;", get_defined_vars());
                                             $opl = apply_filters("ws_plugin__optimizemember_custom_field_gen_radios_opl", "ws-plugin--optimizemember-custom-reg-field-op-l", get_defined_vars());
                                             /**/
                                             foreach (preg_split("/[\r\n\t]+/", $field["options"]) as $i => $option_line) {
                                                 $common_i = preg_replace('/ id\\="(.+?)"/', ' id="$1-' . $i . '"', $common);
                                                 /**/
                                                 list($option_value, $option_label, $option_default) = c_ws_plugin__optimizemember_utils_strings::trim_deep(preg_split("/\\|/", trim($option_line)));
                                                 /**/
                                                 $gen .= $i > 0 ? $sep : '';
                                                 /* Separators can be filtered above. */
                                                 $gen .= '<input type="radio" value="' . esc_attr($option_value) . '"';
                                                 $gen .= $option_default && !$_submission || $option_value === (string) $_value ? ' checked="checked"' : '';
                                                 $gen .= $common_i . ' /><label for="' . esc_attr($_id_prefix . $field_id_class . "-" . $i) . '" class="' . esc_attr($opl) . '" style="display:inline !important; margin:0 !important;">' . $option_label . '</label>';
                                             }
                                         }
                                     } else {
                                         if ($_editable_context === "profile-view") {
                                             $gen = esc_html((string) $_value);
                                         } else {
                                             $gen = '<input type="text" maxlength="100" autocomplete="off"';
                                             $gen .= ' value="' . format_to_edit(!$_submission && isset($field["deflt"]) && strlen((string) $field["deflt"]) ? (string) $field["deflt"] : (string) $_value) . '"';
                                             $gen .= $common . ' />';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         /**/
         eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
         do_action("ws_plugin__optimizemember_during_custom_field_gen_after", get_defined_vars());
         unset($__refs, $__v);
         /* Unset defined __refs, __v. */
     }
     /**/
     return apply_filters("ws_plugin__optimizemember_custom_field_gen", $gen, get_defined_vars());
 }
Beispiel #2
0
 /**
  * Verifies an optimizeMember-generated signature; in a full URL, a partial URI, or in just a query string.
  *
  * @package optimizeMember\Utilities
  * @since 111106
  *
  * @param str $url_uri_query A full URL, a partial URI, or just a query string. Must have an optimizeMember-generated signature to validate.
  * @param bool $check_time Optional. Defaults to false. If true, optimizeMember will also check if the signature has expired, based on ``$exp_secs``.
  * @param str|int $exp_secs Optional. Defaults to (int)10. If ``$check_time`` is true, optimizeMember will check if the signature has expired, based on ``$exp_secs``.
  * @param str $sig_var Optional. The name of the optimizeMember-generated signature variable. Defaults to `_optimizemember_sig`.
  * @return bool True if the optimizeMember-generated signature is OK, else false.
  */
 public static function optimizemember_sig_ok($url_uri_query = FALSE, $check_time = FALSE, $exp_secs = FALSE, $sig_var = FALSE)
 {
     $url_uri_query = $query = c_ws_plugin__optimizemember_utils_strings::trim((string) $url_uri_query, false, "?&=");
     if (preg_match("/^(?:[a-z]+\\:\\/\\/|\\/)/i", $url_uri_query)) {
         $query = trim(c_ws_plugin__optimizemember_utils_urls::parse_url($url_uri_query, PHP_URL_QUERY), "?&=");
     }
     /**/
     $check_time = $check_time ? true : false;
     $exp_secs = is_numeric($exp_secs) ? (int) $exp_secs : 10;
     $sig_var = $sig_var && is_string($sig_var) ? $sig_var : "_optimizemember_sig";
     /**/
     $key = c_ws_plugin__optimizemember_utils_encryption::key();
     /**/
     if (preg_match_all("/" . preg_quote($sig_var, "/") . "\\=([0-9]+)-([^&\$]+)/", $query, $sigs)) {
         $query = c_ws_plugin__optimizemember_utils_urls::remove_optimizemember_sigs($query, $sig_var);
         /**/
         wp_parse_str($query, $vars);
         $vars = c_ws_plugin__optimizemember_utils_arrays::remove_0b_strings(c_ws_plugin__optimizemember_utils_strings::trim_deep($vars));
         $vars = serialize(c_ws_plugin__optimizemember_utils_arrays::ksort_deep($vars));
         /**/
         ($time = $sigs[1][$i = count($sigs[1]) - 1]) . ($sig = $sigs[2][$i]) . ($valid_sig = md5($key . $time . $vars));
         /**/
         if ($check_time) {
             return $sig === $valid_sig && $time >= strtotime("-" . $exp_secs . " seconds");
         } else {
             /* Ignoring time? Just need to compare signatures in this case. */
             return $sig === $valid_sig;
         }
     } else {
         /* Return false. No ``$query``, or no ``$sigs``. */
         return false;
     }
 }