| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly. |
| 4 |
} |
| 5 |
/************************************************************************************************************************************************************************* |
| 6 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 7 |
RemovE Epmty Value |
| 8 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 9 |
**************************************************************************************************************************************************************************/ |
| 10 |
if (!function_exists("vs_new_removeEmptyValues")) { |
| 11 |
function vs_new_removeEmptyValues($array=[]) { |
| 12 |
foreach ($array as $key => $value) { |
| 13 |
if (is_array($value)) { |
| 14 |
$array[$key] = vs_new_removeEmptyValues($value); |
| 15 |
if (empty($array[$key])) { |
| 16 |
unset($array[$key]); |
| 17 |
} |
| 18 |
} elseif ($value === '' || $value === null || $value === false || $value === []) { |
| 19 |
unset($array[$key]); |
| 20 |
} |
| 21 |
} |
| 22 |
return $array; |
| 23 |
} |
| 24 |
} |
| 25 |
/************************************************************************************************************************************************************************* |
| 26 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 27 |
Urlencode |
| 28 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 29 |
**************************************************************************************************************************************************************************/ |
| 30 |
if (!function_exists("vs_new_urlencode")) { |
| 31 |
function vs_new_urlencode($inputString = '') { |
| 32 |
if (isset($inputString) && !is_array($inputString)) { |
| 33 |
$encodedString = urlencode($inputString); |
| 34 |
return base64_encode($encodedString); |
| 35 |
} else { |
| 36 |
return ''; |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
/************************************************************************************************************************************************************************* |
| 42 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 43 |
Urldecode |
| 44 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 45 |
**************************************************************************************************************************************************************************/ |
| 46 |
if (!function_exists("vs_new_urldecode")) { |
| 47 |
function vs_new_urldecode($inputString = '') { |
| 48 |
if (isset($inputString) && !is_array($inputString)) { |
| 49 |
$decodedString = base64_decode($inputString, true); |
| 50 |
if ($decodedString === false) { |
| 51 |
return ''; |
| 52 |
} |
| 53 |
return urldecode($decodedString); |
| 54 |
} else { |
| 55 |
return ''; |
| 56 |
} |
| 57 |
|
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
/************************************************************************************************************************************************************************* |
| 62 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 63 |
Options encode |
| 64 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 65 |
**************************************************************************************************************************************************************************/ |
| 66 |
if ( !function_exists ( "vs_new_encode" )){ |
| 67 |
function vs_new_encode($options=false,$code='dt',$parentIndex=0) { |
| 68 |
$output = ''; |
| 69 |
$r = 0; |
| 70 |
foreach ($options as $key => $value) { |
| 71 |
if($value !=='' ){ |
| 72 |
$index = ($parentIndex !== 0) ? $parentIndex . '_' : ''; |
| 73 |
if (is_array($value)) { |
| 74 |
$r++; |
| 75 |
$output.='['.$code.'_'. $index . $r . ' key="'. $key.'"]'; |
| 76 |
$output .= vs_new_encode($value,$code, $index . $r); |
| 77 |
|
| 78 |
$output.='[/'.$code.'_'. $index . $r . ']'; |
| 79 |
} else { |
| 80 |
$r++; |
| 81 |
$output.='['.$code.'_'. $index . $r . ' key="'. $key.'"]'; |
| 82 |
$output.= vs_new_urlencode($value) ; |
| 83 |
$output.='[/'.$code.'_'. $index . $r . ']'; |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
return $output; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
/************************************************************************************************************************************************************************* |
| 93 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 94 |
Options encode |
| 95 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 96 |
**************************************************************************************************************************************************************************/ |
| 97 |
if ( !function_exists ( "vs_new_decode" )){ |
| 98 |
function vs_new_decode($data='',$code=''){ |
| 99 |
if(isset($data) && is_string($data)){ |
| 100 |
|
| 101 |
$o = vs_new_serialize_code( $data,$code); |
| 102 |
$a =array(); |
| 103 |
if(is_array($o) && !empty($o)){ |
| 104 |
foreach($o as $v) : |
| 105 |
if(isset( $v)&& $v !=='' ){ |
| 106 |
$a[$v['key']] = vs_new_options_decode_array($v,$code); |
| 107 |
} |
| 108 |
endforeach; |
| 109 |
}else{ |
| 110 |
|
| 111 |
if( $code=='el'){ |
| 112 |
$a = $o; |
| 113 |
}else{ |
| 114 |
$a = vs_new_urldecode($o); |
| 115 |
} |
| 116 |
} |
| 117 |
return $a; |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
/************************************************************************************************************************************************************************* |
| 124 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 125 |
Decode Array |
| 126 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 127 |
**************************************************************************************************************************************************************************/ |
| 128 |
if ( !function_exists ( "vs_new_options_decode_array" )){ |
| 129 |
function vs_new_options_decode_array($v,$code=false){ |
| 130 |
$a = array(); |
| 131 |
$value=isset($v['value'])?$v['value']:''; |
| 132 |
$name=isset($v['name'])?$v['name']:''; |
| 133 |
$key=isset($v['key'])?$v['key']:''; |
| 134 |
$o_2 = vs_new_serialize_code($value,$name); |
| 135 |
if(is_array($o_2)){ |
| 136 |
foreach($o_2 as $v_2) : |
| 137 |
if(isset( $v_2)&& $v_2 !=='' ){ |
| 138 |
$a[$v_2['key']] = vs_new_options_decode_array($v_2,$code=false); |
| 139 |
} |
| 140 |
endforeach; |
| 141 |
}else{ |
| 142 |
|
| 143 |
$a = vs_new_urldecode($value); |
| 144 |
|
| 145 |
} |
| 146 |
return $a; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
/************************************************************************************************************************************************************************* |
| 151 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 152 |
Decode Array url |
| 153 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 154 |
**************************************************************************************************************************************************************************/ |
| 155 |
if ( !function_exists ( "vs_new_options_decode_array_url" )){ |
| 156 |
function vs_new_options_decode_array_url($v,$code=false){ |
| 157 |
$a = array(); |
| 158 |
$value=isset($v['value'])?$v['value']:''; |
| 159 |
$name=isset($v['name'])?$v['name']:''; |
| 160 |
$key=isset($v['key'])?$v['key']:''; |
| 161 |
$o_2 = vs_new_serialize_code($value,$name); |
| 162 |
if(is_array($o_2)){ |
| 163 |
foreach($o_2 as $v_2) : |
| 164 |
if(isset( $v_2)&& $v_2 !=='' ){ |
| 165 |
$a[$v_2['key']] = vs_new_options_decode_array_url($v_2,$code=false); |
| 166 |
} |
| 167 |
endforeach; |
| 168 |
}else{ |
| 169 |
|
| 170 |
if( $code=='el'){ |
| 171 |
$a = $value; |
| 172 |
}else{ |
| 173 |
$a = vs_new_urldecode_url($value); |
| 174 |
} |
| 175 |
|
| 176 |
} |
| 177 |
return $a; |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
/************************************************************************************************************************************************************************* |
| 182 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 183 |
Serialize Code |
| 184 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 185 |
**************************************************************************************************************************************************************************/ |
| 186 |
if ( !function_exists ( "vs_new_serialize_code" )){ |
| 187 |
function vs_new_serialize_code($in='',$code='') { |
| 188 |
if(!empty($in) && !empty($code) && is_string($in)){ |
| 189 |
preg_match_all('/\[('.$code.'_\d+)(_\d+)?(?: (key)="([^"]*)")?\](.+(?=\[\/\1\2?\]))?/',$in,$out,PREG_SET_ORDER); |
| 190 |
foreach($out as $sc){ |
| 191 |
if(isset($sc[1]) && $sc[1] !=='' ){ |
| 192 |
$shortcodes[$sc[1]]=array('name'=>$sc[1].$sc[2],'key'=>isset($sc[4]) && $sc[4] !=='' ? $sc[4]:'' ,'value'=> isset($sc[5]) && $sc[5] !==''? $sc[5]:'' ); |
| 193 |
} |
| 194 |
} |
| 195 |
$shortcod = isset($shortcodes) && $shortcodes !==''? $shortcodes:''; |
| 196 |
return $shortcod; |
| 197 |
} |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
if ( ! function_exists( 'vs_new_validate_decode_code' ) ) { |
| 202 |
function vs_new_validate_decode_code( $input='') { |
| 203 |
$input = wp_unslash( $input ); |
| 204 |
|
| 205 |
if ( preg_match( '/^[\[\]a-zA-Z0-9_="\.\/\+\-\s,%&!@#$^*():;?{}\\\\]+$/u', $input ) ) { |
| 206 |
return $input; |
| 207 |
} |
| 208 |
|
| 209 |
return ''; |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
if ( ! function_exists( 'vs_validate_decode_code' ) ) { |
| 214 |
function vs_validate_decode_code( $input = '') { |
| 215 |
|
| 216 |
if ( preg_match( '/\[[a-zA-Z0-9_]+_1.*key="[^"]*"\]/s', $input ) ) { |
| 217 |
return $input; |
| 218 |
} |
| 219 |
|
| 220 |
return ''; |
| 221 |
} |
| 222 |
} |