commit by denisbaranov:

- fixed conditional logic in form;
- fixed prohibition on editing a field (Form->field->Can user edit this field?);
- fixed cleaning on XSS injection;
- fixed addition "wp_unslash" and "esc_attr" in the "Admin_Forms" class method "render_form_row";
This commit is contained in:
nikitozzzzzzz
2017-10-03 16:29:04 +03:00
parent 63a5c9dcb4
commit a714be2d5c
7 changed files with 3520 additions and 3272 deletions
+6 -6
View File
@@ -187,9 +187,9 @@ div.uimob340 .um-header .um-meta-text {
padding: 0 20px;
}
div.uimob340 .um-header .um-meta {padding: 0 20px}
div.uimob340 .um-header .um-meta span:first-child {display: block}
div.uimob340 .um-header .um-meta span {display: none}
div.uimob340 .um-header .um-meta {padding: 0 10px; display: inline-block;}
/*div.uimob340 .um-header .um-meta span:first-child {display: block}*/
/*div.uimob340 .um-header .um-meta span {display: none}*/
div.uimob340 .um-col-121,
div.uimob340 .um-col-122,
@@ -409,9 +409,9 @@ div.uimob500 .um-header .um-meta-text {
padding: 0 20px;
}
div.uimob500 .um-header .um-meta {padding: 0 20px}
div.uimob500 .um-header .um-meta span:first-child {display: block}
div.uimob500 .um-header .um-meta span {display: none}
div.uimob500 .um-header .um-meta {padding: 0 20px;display: block;}
/*div.uimob500 .um-header .um-meta span:first-child {display: block}*/
/*div.uimob500 .um-header .um-meta span {display: none}*/
div.uimob500 .um-col-121,
div.uimob500 .um-col-122,
+58 -23
View File
@@ -191,6 +191,18 @@ jQuery(document).ready( function (){
}
function um_in_array(needle, haystack, strict){
var found = false, key, strict = !!strict;
for (key in haystack) {
if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
found = true;
break;
}
}
return found;
}
/**
* Apply field conditions
* @param object $dom
@@ -204,67 +216,90 @@ jQuery(document).ready( function (){
var live_field_value = um_get_field_data($dom);
var $owners = {};
var $owners_values = {};
var $owner_conditions = {};
jQuery.each(conditions, function (index, condition) {
if (typeof $owners_values[condition.owner] == 'undefined') {
$owners_values[condition.owner] = [];
$owner_conditions[condition.owner] = {}
}
$owners_values[condition.owner].push(condition.value);
$owner_conditions[condition.owner] = condition;
});
jQuery.each(conditions, function (index, condition) {
if (typeof $owners[condition.owner] == 'undefined') {
$owners[condition.owner] = {};
}
if (condition.operator == 'empty') {
if (!live_field_value || live_field_value == '') {
um_field_apply_action($dom, condition, true);
if (!live_field_value || live_field_value == '' && um_in_array(live_field_value, $owners_values[condition.owner])) {
$owners[condition.owner][index] = true;
} else {
um_field_apply_action($dom, condition, false);
$owners[condition.owner][index] = false;
}
}
if (condition.operator == 'not empty') {
if (live_field_value && live_field_value != '') {
um_field_apply_action($dom, condition, true);
if (live_field_value && live_field_value != '' && !um_in_array(live_field_value, $owners_values[condition.owner])) {
$owners[condition.owner][index] = true;
} else {
um_field_apply_action($dom, condition, false);
$owners[condition.owner][index] = false;
}
}
if (condition.operator == 'equals to') {
if (condition.value == live_field_value) {
um_field_apply_action($dom, condition, true);
if (condition.value == live_field_value && um_in_array(live_field_value, $owners_values[condition.owner])) {
$owners[condition.owner][index] = true;
} else {
um_field_apply_action($dom, condition, false);
$owners[condition.owner][index] = false;
}
}
if (condition.operator == 'not equals') {
if (jQuery.isNumeric(condition.value) && parseInt(live_field_value) != parseInt(condition.value) && live_field_value) {
um_field_apply_action($dom, condition, true);
} else if (!jQuery.isNumeric(condition.value) && condition.value != live_field_value) {
um_field_apply_action($dom, condition, true);
if (jQuery.isNumeric(condition.value) && parseInt(live_field_value) != parseInt(condition.value) && live_field_value && !um_in_array(live_field_value, $owners_values[condition.owner])) {
$owners[condition.owner][index] = true;
} else if (condition.value != live_field_value && !um_in_array(live_field_value, $owners_values[condition.owner])) {
$owners[condition.owner][index] = true;
} else {
um_field_apply_action($dom, condition, false);
$owners[condition.owner][index] = false;
}
}
if (condition.operator == 'greater than') {
if (jQuery.isNumeric(condition.value) && parseInt(live_field_value) > parseInt(condition.value)) {
um_field_apply_action($dom, condition, true);
$owners[condition.owner][index] = true;
} else {
um_field_apply_action($dom, condition, false);
$owners[condition.owner][index] = false;
}
}
if (condition.operator == 'less than') {
if (jQuery.isNumeric(condition.value) && parseInt(live_field_value) < parseInt(condition.value) && live_field_value) {
um_field_apply_action($dom, condition, true);
if (jQuery.isNumeric(condition.value) && parseInt(live_field_value) < parseInt(condition.value)) {
$owners[condition.owner][index] = true;
} else {
um_field_apply_action($dom, condition, false);
$owners[condition.owner][index] = false;
}
}
if (condition.operator == 'contains') {
if (live_field_value && live_field_value.indexOf(condition.value) >= 0) {
um_field_apply_action($dom, condition, true);
if (live_field_value && live_field_value.indexOf(condition.value) >= 0 && um_in_array(live_field_value, $owners_values[condition.owner])) {
$owners[condition.owner][index] = true;
} else {
um_field_apply_action($dom, condition, false);
$owners[condition.owner][index] = false;
}
}
}); // end foreach `conditions`
jQuery.each($owners, function (index, field) {
if (um_in_array(true, field)) {
um_field_apply_action($dom, $owner_conditions[index], true);
} else {
um_field_apply_action($dom, $owner_conditions[index], false);
}
});
$dom.trigger('um_fields_change');
}
+10 -1
View File
@@ -77,6 +77,15 @@ if ( ! class_exists( 'Admin_Forms' ) ) {
if ( empty( $data['type'] ) )
return '';
if ( !empty( $data['value'] ) && $data['type'] != 'email_template' ) {
$data['value'] = wp_unslash( $data['value'] );
/*for multi_text*/
if ( !is_array( $data['value'] ) ) {
$data['value'] = esc_attr( $data['value'] );
}
}
$conditional = ! empty( $data['conditional'] ) ? 'data-conditional="' . esc_attr( json_encode( $data['conditional'] ) ) . '"' : '';
$prefix_attr = ! empty( $this->form_data['prefix_id'] ) ? ' data-prefix="' . $this->form_data['prefix_id'] . '" ' : '';
@@ -805,7 +814,7 @@ if ( ! class_exists( 'Admin_Forms' ) ) {
if ( ! empty( $values ) ) {
foreach ( $values as $k=>$value ) {
$value = esc_attr($value);
$id_attr = ' id="' . $id . '-' . $k . '" ';
$html .= "<li class=\"um-multi-text-option-line {$size}\"><span class=\"um-field-wrapper\">
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+23
View File
@@ -458,4 +458,27 @@
}
/**
* Cleaning on XSS injection
* @param $value string
* @param $data array
* @return $value string
* @uses hook filters: um_profile_field_filter_hook__
*/
add_filter('um_profile_field_filter_hook__','um_profile_field_filter_xss_validation',10,2);
function um_profile_field_filter__xss_validation( $value, $data ){
if( ! empty( $value ) && is_string($value)){
$value = stripslashes( $value );
$data['validate'] = isset( $data['validate'] ) ? $data['validate'] : '';
if( 'text' == $data['type'] && !in_array( $data['validate'], array( 'unique_email' ) ) ||
'password' == $data['type'] ){
$value = esc_attr( $value );
}else if ( 'textarea' == $data['type'] ){
$value = wp_kses_post( $value );
}
}
return $value;
}
File diff suppressed because it is too large Load Diff