| 1 |
<?php |
| 2 |
/* |
| 3 |
This is COMMERCIAL SCRIPT |
| 4 |
We are not guarantee correct work and support of Booking Calendar, if some file(s) was modified by someone else then wpdevelop. |
| 5 |
*/ |
| 6 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 7 |
|
| 8 |
|
| 9 |
/** |
| 10 |
* HTML shortcode description: |
| 11 |
* |
| 12 |
* R E P L A C I N G: |
| 13 |
* |
| 14 |
* <r> -> <div class="wpbc__row"> |
| 15 |
* </r> -> </div> |
| 16 |
* |
| 17 |
* <c> -> <div class="wpbc__field"> |
| 18 |
* </c> -> </div> |
| 19 |
* |
| 20 |
* <f> -> <span class="fieldvalue"> |
| 21 |
* </f> -> </span> |
| 22 |
* |
| 23 |
* <l> -> <label> |
| 24 |
* </l> -> </label> |
| 25 |
*/ |
| 26 |
|
| 27 |
/** |
| 28 |
* Replace Custom HTML shortcodes, such as <r> -> <div class="wpbc__row"> | <c> -> <div class="wpbc__field"> in Booking Form configuration |
| 29 |
* |
| 30 |
* @param $html_original_content |
| 31 |
* |
| 32 |
* @return array|mixed|string|string[] |
| 33 |
*/ |
| 34 |
function wpbc_bf__replace_custom_html_shortcodes( $html_original_content ){ |
| 35 |
|
| 36 |
$full_text_content = $html_original_content; |
| 37 |
|
| 38 |
$replacement_shortcode_arr = array( |
| 39 |
array( 'shortcode' => 'r', 'replace_to' => array( 'tag' => 'div', 'attr' => array( 'class' => "wpbc__row" ) ) ), // Row |
| 40 |
array( 'shortcode' => 'c', 'replace_to' => array( 'tag' => 'div', 'attr' => array( 'class' => "wpbc__field" ) ) ), // Column |
| 41 |
array( 'shortcode' => 'f', 'replace_to' => array( 'tag' => 'span', 'attr' => array( 'class' => "fieldvalue" ) ) ), // Field for "Content of booking fields data" form |
| 42 |
array( 'shortcode' => 'l', 'replace_to' => array( 'tag' => 'label', 'attr' => array() ) ) // Label |
| 43 |
|
| 44 |
// array( 'r', '<div class="wpbc__row">' , '</div>' ), // Row |
| 45 |
// array( 'c', '<div class="wpbc__field">' , '</div>' ), // Column |
| 46 |
// array( 'f', '<span class="fieldvalue">' , '</span>' ), // Field for "Content of booking fields data" form |
| 47 |
// array( 'l', '<label>' , '</label>' ) // Label |
| 48 |
); |
| 49 |
|
| 50 |
foreach ( $replacement_shortcode_arr as $shortcode_pair_arr ) { |
| 51 |
// Open tags |
| 52 |
if ( ! is_null( $full_text_content ) ) { |
| 53 |
$rx_shortcode = $shortcode_pair_arr['shortcode']; // 'r'; |
| 54 |
|
| 55 |
$replacement = '<' . $shortcode_pair_arr['replace_to']['tag'] . '>' ; // 'div class="wpbc__row"'; |
| 56 |
//$regex = '%<\s*' . $rx_shortcode . '\s*>%'; // ? $regex = '%<\s*(' . $rx_shortcode . ')\s*|\s+[^>]*>%'; |
| 57 |
//$full_text_content = preg_replace( $regex, $replacement, $full_text_content ); |
| 58 |
|
| 59 |
$found_shortcodes_count = preg_match_all( '%<\s*' . $rx_shortcode . '(\s+[^\<\>]+)*' . '\s*>%', $full_text_content, $matches_shortoces, PREG_SET_ORDER ); //FixIn: 10.1.0.1 |
| 60 |
foreach ( $matches_shortoces as $index => $found_shortcode ) { |
| 61 |
$found_shortcode_to_replace = $found_shortcode[0]; // <r id="first_row" class="sr_booking_info" style="background:red;"> |
| 62 |
$found_shortcode_attributes_to_replace = ( isset( $found_shortcode[1] ) ) ? $found_shortcode[1] : ''; // id="first_row" class="sr_booking_info" style="background:red;" |
| 63 |
$found_shortcode_attributes_to_replace = trim( $found_shortcode_attributes_to_replace ); |
| 64 |
$found_shortcode_attributes_to_replace = str_replace( ' ', ' ', $found_shortcode_attributes_to_replace ); |
| 65 |
|
| 66 |
$attributes_count = preg_match_all( '%([^=]+)=\s*[\'\"]{1}([^\'"]*)[\'\"]{1}\s*%', $found_shortcode_attributes_to_replace, $attributes_arr, PREG_SET_ORDER ); |
| 67 |
/** |
| 68 |
* $attributes_arr = [ |
| 69 |
* 0 = [ |
| 70 |
* 0 = "style="margin-right: auto;" " |
| 71 |
* 1 = "style" |
| 72 |
* 2 = "margin-right: auto;" |
| 73 |
* ] |
| 74 |
* 1 = ] |
| 75 |
* 0 = "class='wpbc_data and_cl'" |
| 76 |
* 1 = "class" |
| 77 |
* 2 = "wpbc_data and_cl" |
| 78 |
* ] |
| 79 |
* ] |
| 80 |
*/ |
| 81 |
$attributes_named_arr = array(); |
| 82 |
foreach ( $attributes_arr as $attribute ) { |
| 83 |
if ( ( ! empty( $attribute ) ) && ( count( $attribute ) > 2 ) ) { |
| 84 |
$a_name = $attribute[1]; |
| 85 |
$a_value = $attribute[2];; |
| 86 |
$attributes_named_arr[ $a_name ] = $a_value; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
foreach ( $shortcode_pair_arr['replace_to']['attr'] as $attr_name => $attr_value ) { |
| 91 |
if ( ! empty( $attributes_named_arr[ $attr_name ] ) ) { |
| 92 |
$attributes_named_arr[ $attr_name ] .= ' ' . $attr_value; |
| 93 |
} else { |
| 94 |
$attributes_named_arr[ $attr_name ] = $attr_value; |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
$final_attributes = WPBC_Settings_API::get_custom_attr_static( array( 'attr' => $attributes_named_arr ) ); |
| 99 |
|
| 100 |
if ( ! empty( $final_attributes ) ) { |
| 101 |
$replace_to = str_replace( '>', ' ' . $final_attributes . '>', $replacement ); |
| 102 |
} else { |
| 103 |
$replace_to = $replacement; |
| 104 |
} |
| 105 |
|
| 106 |
$full_text_content = str_replace( $found_shortcode_to_replace, $replace_to, $full_text_content ); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
// Close tags |
| 112 |
if ( ! is_null( $full_text_content ) ) { |
| 113 |
$regex = '%<\/\s*' . $rx_shortcode . '\s*>%'; |
| 114 |
$replacement = '</' . $shortcode_pair_arr['replace_to']['tag'] . '>'; |
| 115 |
$full_text_content = preg_replace( $regex, $replacement, $full_text_content ); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
if ( ! is_null( $full_text_content ) ){ |
| 120 |
|
| 121 |
// Replace <spacer></spacer> -> <div style="width:100%;clear:both;"></div> | <spacer>height:10px;</spacer> -> <div style="width:100%;clear:both;height:10px"></div> |
| 122 |
$full_text_content = wpbc_bf__replace_custom_html_shortcode__spacer( $full_text_content ); |
| 123 |
|
| 124 |
return $full_text_content; |
| 125 |
} |
| 126 |
|
| 127 |
// Error |
| 128 |
return 'WPBC. Error during replacing custom HTML shortcodes! <br>' . |
| 129 |
$html_original_content; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
/** |
| 135 |
* Escape booking from with alloweed HTML atgs + Simple HTML shortcodes |
| 136 |
* @param $content |
| 137 |
* |
| 138 |
* @return string |
| 139 |
*/ |
| 140 |
function wpbc_form_escape_in_demo( $content ) { |
| 141 |
|
| 142 |
// Replace my comments |
| 143 |
$content = str_replace( |
| 144 |
array( |
| 145 |
'<!-- Simple HTML shortcodes in the form (check more at "Generate Tag" section):', |
| 146 |
'Row: <r>...</r> | Columns: <c>...</c> | Labels: <l>...</l> | Spacer: <spacer></spacer> -->' |
| 147 |
), '', |
| 148 |
trim( stripslashes( $content ) ) |
| 149 |
); |
| 150 |
|
| 151 |
$value = wp_kses( |
| 152 |
trim( stripslashes( $content ) ), |
| 153 |
array_merge( array( |
| 154 |
'r' => array( 'style'=>true , 'class'=>true , 'id'=>true ), |
| 155 |
'f' => array( 'style'=>true , 'class'=>true , 'id'=>true ), |
| 156 |
'c' => array( 'style'=>true , 'class'=>true , 'id'=>true ), |
| 157 |
'l' => array( 'style'=>true , 'class'=>true , 'id'=>true ), |
| 158 |
'spacer' => array() |
| 159 |
), |
| 160 |
wp_kses_allowed_html( 'post' ) |
| 161 |
) |
| 162 |
); |
| 163 |
return $value; |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
/** |
| 168 |
* Replace SPACER shortcode: <spacer></spacer> -> <div style="width:100%;clear:both;"></div> | <spacer>height:10px;</spacer> -> <div style="width:100%;clear:both;height:10px"></div> |
| 169 |
* |
| 170 |
* @param $html_original_content |
| 171 |
* |
| 172 |
* @return mixed |
| 173 |
*/ |
| 174 |
function wpbc_bf__replace_custom_html_shortcode__spacer( $html_original_content ) { |
| 175 |
|
| 176 |
$rx_shortcode = 'spacer'; |
| 177 |
$regex = '%<\s*' . $rx_shortcode . '\s*>([-0-9a-zA-Z:;_!\(\)|\s]*)?<\/\s*' . $rx_shortcode . '\s*>%'; |
| 178 |
// $fields_count = preg_match_all( $regex, $html_original_content, $fields_matches, PREG_PATTERN_ORDER ); |
| 179 |
// debuge($fields_count, $fields_matches); |
| 180 |
$html_content_replaced = preg_replace( $regex, '<div class="wpbc__spacer" style="width:100%;clear:both;${1}"></div>' ,$html_original_content ); |
| 181 |
|
| 182 |
if ( ! is_null( $html_content_replaced ) ){ |
| 183 |
return $html_content_replaced; |
| 184 |
} |
| 185 |
|
| 186 |
return $html_original_content; |
| 187 |
} |