| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly. |
| 5 |
} |
| 6 |
|
| 7 |
function wdk_generate_fields($fields, $db_data) |
| 8 |
{ |
| 9 |
if(is_array($fields)) |
| 10 |
foreach($fields as $field) |
| 11 |
{ |
| 12 |
$field = (object) $field; |
| 13 |
|
| 14 |
$field_type = $field->field_type; |
| 15 |
|
| 16 |
$field_view_path = WPDIRECTORYKIT_PATH.'application/views/fields_edit/'.$field_type.'.php'; |
| 17 |
|
| 18 |
if(file_exists($field_view_path)) |
| 19 |
{ |
| 20 |
include $field_view_path; |
| 21 |
} |
| 22 |
else |
| 23 |
{ |
| 24 |
echo __('Missing VIEW file: ', 'wpdirectorykit').esc_html($field_type).'.php'; |
| 25 |
} |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
if ( ! function_exists('wdk_generate_search_form')) |
| 30 |
{ |
| 31 |
function wdk_generate_search_form($form_id=1, $subfolder='', $print = TRUE, $predefinedfields_query = array()) |
| 32 |
{ |
| 33 |
/* load WMVC data */ |
| 34 |
$WMVC = &wdk_get_instance(); |
| 35 |
$WMVC->model('searchform_m'); |
| 36 |
$WMVC->model('field_m'); |
| 37 |
$output = ''; |
| 38 |
|
| 39 |
/* get WMVC form data */ |
| 40 |
$fields = $WMVC->searchform_m->get($form_id, TRUE); |
| 41 |
$user_fields = NULL; |
| 42 |
|
| 43 |
/* get WMVC form fields */ |
| 44 |
if(is_object($fields)) |
| 45 |
$user_fields = json_decode($fields->searchform_json); |
| 46 |
/* generate WMVC form fields html */ |
| 47 |
if(is_array($user_fields)) |
| 48 |
foreach($user_fields as $used_field) |
| 49 |
{ |
| 50 |
|
| 51 |
if($used_field->field_id == 'cat') { |
| 52 |
$field = array( |
| 53 |
"idfield" => 'category', |
| 54 |
"field_type" => 'CATEGORY', |
| 55 |
"field_label" => __('Category', 'wpdirectorykit'), |
| 56 |
"prefix" => '', |
| 57 |
"suffix" => '', |
| 58 |
"values_list" => '', |
| 59 |
"placeholder" => '', |
| 60 |
); |
| 61 |
}else if($used_field->field_id == 'loc') { |
| 62 |
$field = array( |
| 63 |
"idfield" => 'location', |
| 64 |
"field_type" => 'LOCATION', |
| 65 |
"field_label" => __('Location', 'wpdirectorykit'), |
| 66 |
"prefix" => '', |
| 67 |
"suffix" => '', |
| 68 |
"values_list" => '', |
| 69 |
"placeholder" => '', |
| 70 |
); |
| 71 |
}else if($used_field->field_id == 'address') { |
| 72 |
$field = array( |
| 73 |
"idfield" => 'address', |
| 74 |
"field_type" => 'INPUTBOX', |
| 75 |
"field_label" => __('Address', 'wpdirectorykit'), |
| 76 |
"prefix" => '', |
| 77 |
"suffix" => '', |
| 78 |
"values_list" => '', |
| 79 |
"placeholder" => '', |
| 80 |
); |
| 81 |
}else if($used_field->field_id == 'post_title') { |
| 82 |
$field = array( |
| 83 |
"idfield" => 'post_title', |
| 84 |
"field_type" => 'INPUTBOX', |
| 85 |
"field_label" => __('Title', 'wpdirectorykit'), |
| 86 |
"prefix" => '', |
| 87 |
"suffix" => '', |
| 88 |
"values_list" => '', |
| 89 |
"placeholder" => '', |
| 90 |
); |
| 91 |
}else if($used_field->field_id == 'search') { |
| 92 |
$field = array( |
| 93 |
"idfield" => 'search', |
| 94 |
"field_type" => 'INPUTBOX', |
| 95 |
"field_label" => __('Search', 'wpdirectorykit'), |
| 96 |
"prefix" => '', |
| 97 |
"suffix" => '', |
| 98 |
"values_list" => '', |
| 99 |
"placeholder" => '', |
| 100 |
); |
| 101 |
}else if(function_exists('run_wdk_bookings') && $used_field->field_id == 'booking_date') { |
| 102 |
$field = array( |
| 103 |
"idfield" => 'booking_date', |
| 104 |
"field_type" => 'BOOKINGS_DATE', |
| 105 |
"field_label" => __('Booking Date', 'wpdirectorykit'), |
| 106 |
"prefix" => '', |
| 107 |
"suffix" => '', |
| 108 |
"values_list" => '', |
| 109 |
"placeholder" => '', |
| 110 |
); |
| 111 |
}else if($used_field->field_id == 'more') { |
| 112 |
$field = array( |
| 113 |
"idfield" => 'MORE', |
| 114 |
"field_type" => 'MORE', |
| 115 |
"field_label" => __('MORE', 'wpdirectorykit'), |
| 116 |
"prefix" => '', |
| 117 |
"suffix" => '', |
| 118 |
"values_list" => '', |
| 119 |
"placeholder" => '', |
| 120 |
); |
| 121 |
} else { |
| 122 |
$field_data = $WMVC->field_m->get_fields_data($used_field->field_id); |
| 123 |
if($field_data) { |
| 124 |
if($used_field->query_type == 'slider_range') { |
| 125 |
$field = array( |
| 126 |
"idfield" => wmvc_show_data('idfield', $field_data), |
| 127 |
"field_type" => 'SLIDER_RANGE', |
| 128 |
"field_label" =>wmvc_show_data('field_label', $field_data), |
| 129 |
"prefix" => wmvc_show_data('prefix', $field_data), |
| 130 |
"suffix" => wmvc_show_data('suffix', $field_data), |
| 131 |
"value_min" => wmvc_show_data('value_min', $used_field), |
| 132 |
"value_max" => wmvc_show_data('value_max', $used_field), |
| 133 |
"values_list" => wmvc_show_data('values_list', $field_data), |
| 134 |
"placeholder" => wmvc_show_data('placeholder', $field_data) |
| 135 |
); |
| 136 |
} else { |
| 137 |
$field = array( |
| 138 |
"idfield" => wmvc_show_data('idfield', $field_data), |
| 139 |
"field_type" => wmvc_show_data('field_type', $field_data), |
| 140 |
"field_label" =>wmvc_show_data('field_label', $field_data), |
| 141 |
"prefix" => wmvc_show_data('prefix', $field_data), |
| 142 |
"suffix" => wmvc_show_data('suffix', $field_data), |
| 143 |
"values_list" => wmvc_show_data('values_list', $field_data), |
| 144 |
"placeholder" => wmvc_show_data('placeholder', $field_data) |
| 145 |
); |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
/* if field not detected or remove from fields list, skip field in search */ |
| 151 |
if(empty($field)) continue; |
| 152 |
|
| 153 |
/* add from user fields data */ |
| 154 |
$field['field_id'] = wmvc_show_data('field_id', $used_field); |
| 155 |
$field['class'] = wmvc_show_data('class', $used_field); |
| 156 |
$field['query_type'] = wmvc_show_data('query_type', $used_field); |
| 157 |
$field['columns'] = wmvc_show_data('columns', $used_field); |
| 158 |
|
| 159 |
|
| 160 |
$field_data = array(); |
| 161 |
$field_data ['field_data'] = $field; |
| 162 |
$field_data ['predefinedfields_query'] = $predefinedfields_query; |
| 163 |
|
| 164 |
if(in_array(wmvc_show_data('field_type', $field),array('SECTION'))) { |
| 165 |
continue; |
| 166 |
} |
| 167 |
|
| 168 |
$field_view_path = WPDIRECTORYKIT_PATH.'application/views/search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)).'.php'; |
| 169 |
if(file_exists($field_view_path)) |
| 170 |
{ |
| 171 |
$output .= $WMVC->view('search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)), $field_data, FALSE); |
| 172 |
} |
| 173 |
else |
| 174 |
{ |
| 175 |
/* show missing view file of field, only if print enable */ |
| 176 |
if($print) |
| 177 |
$output .= __('Missing VIEW file: ', 'wpdirectorykit').esc_html($subfolder).(wmvc_show_data('field_type', $field)).'.php'; |
| 178 |
} |
| 179 |
|
| 180 |
} |
| 181 |
|
| 182 |
if($print){ |
| 183 |
echo $output; |
| 184 |
return FALSE; |
| 185 |
} |
| 186 |
|
| 187 |
return $output; |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
function &wdk_get_instance() |
| 192 |
{ |
| 193 |
global $Winter_MVC_WDK; |
| 194 |
|
| 195 |
if(empty($Winter_MVC_WDK)) |
| 196 |
{ |
| 197 |
$Winter_MVC_WDK = new MVC_Loader(plugin_dir_path( __FILE__ ).'../../'); |
| 198 |
|
| 199 |
$Winter_MVC_WDK->load_helper('basic'); |
| 200 |
} |
| 201 |
|
| 202 |
return $Winter_MVC_WDK; |
| 203 |
} |
| 204 |
|
| 205 |
function wdk_prepare_search_query_GET($columns = array(), $model_name = NULL, $external_columns = array(), $custom_parameters = array(), $skip_postget = FALSE) |
| 206 |
{ |
| 207 |
|
| 208 |
global $Winter_MVC_WDK; |
| 209 |
$WMVC = &$Winter_MVC_WDK; |
| 210 |
$wdk_bookings_joinded = false; |
| 211 |
static $available_fields_listings = NULL; |
| 212 |
static $available_fields_static = array(); |
| 213 |
static $list_fields_static = NULL; |
| 214 |
|
| 215 |
/* add if missing columns */ |
| 216 |
if(!in_array('post_id', $columns)) { |
| 217 |
$columns[] = $Winter_MVC_WDK->db->prefix.'wdk_listings.post_id'; |
| 218 |
} |
| 219 |
|
| 220 |
$_GET_clone = array(); |
| 221 |
|
| 222 |
if(!$skip_postget) |
| 223 |
$_GET_clone = array_merge($_GET, $_POST); |
| 224 |
|
| 225 |
if(isset($_GET_clone['order_by']) && $_GET_clone['order_by'] =='undefined') { |
| 226 |
unset($_GET_clone['order_by']); |
| 227 |
} |
| 228 |
|
| 229 |
if(isset($custom_parameters['order_by'])) { |
| 230 |
|
| 231 |
if(isset($_GET_clone['order_by']) && !empty($_GET_clone['order_by'])) { |
| 232 |
$_GET_clone['order_by'] = $custom_parameters['order_by'].', '.$_GET_clone['order_by']; |
| 233 |
} else { |
| 234 |
$_GET_clone['order_by'] = $custom_parameters['order_by']; |
| 235 |
} |
| 236 |
|
| 237 |
unset($custom_parameters['order_by']); |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
if(!empty($custom_parameters)) |
| 242 |
$_GET_clone = array_merge($_GET_clone, $custom_parameters); |
| 243 |
|
| 244 |
$WMVC->model('listing_m'); |
| 245 |
$WMVC->model('field_m'); |
| 246 |
$WMVC->model('listingfield_m'); |
| 247 |
|
| 248 |
$smart_search = ''; |
| 249 |
if(isset($_GET_clone['search'])) |
| 250 |
$smart_search = sanitize_text_field($_GET_clone['search']); |
| 251 |
|
| 252 |
if(isset($_GET_clone['field_search'])) |
| 253 |
$smart_search = sanitize_text_field($_GET_clone['field_search']); |
| 254 |
|
| 255 |
if(!isset($available_fields_static[$model_name])) |
| 256 |
{ |
| 257 |
$available_fields = $WMVC->$model_name->get_available_fields(); |
| 258 |
|
| 259 |
$available_fields_static[$model_name] = $available_fields; |
| 260 |
} |
| 261 |
else |
| 262 |
{ |
| 263 |
$available_fields = $available_fields_static[$model_name]; |
| 264 |
} |
| 265 |
|
| 266 |
if($available_fields_listings === NULL) |
| 267 |
$available_fields_listings = $WMVC->listingfield_m->get_available_fields(); |
| 268 |
|
| 269 |
/* Пet column names from wdk_listings_fields and add to allow search + |
| 270 |
in _GET_clone replace field_#id to field_id_TYPE*/ |
| 271 |
|
| 272 |
if($list_fields_static === NULL) |
| 273 |
{ |
| 274 |
$WMVC->db->where(array('field_type !='=> 'SECTION')); |
| 275 |
$list_fields = $WMVC->field_m->get(); |
| 276 |
$list_fields_static = $list_fields; |
| 277 |
} |
| 278 |
else |
| 279 |
{ |
| 280 |
$list_fields = $list_fields_static; |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
foreach($list_fields as $field_data) { |
| 285 |
|
| 286 |
$field_id = wmvc_show_data('idfield',$field_data); |
| 287 |
$field_type = wmvc_show_data('field_type',$field_data); |
| 288 |
$column_name ='field_'.$field_id.'_'.$field_type; |
| 289 |
if(!isset($available_fields_listings[$column_name])) continue; |
| 290 |
|
| 291 |
if(isset($_GET_clone['field_'.$field_id])) { |
| 292 |
|
| 293 |
if($field_type == 'DROPDOWNMULTIPLE') { |
| 294 |
$_GET_clone['field_'.$field_id.'_'.$field_type] = $_GET_clone['field_'.$field_id]; |
| 295 |
} else { |
| 296 |
$_GET_clone['field_'.$field_id.'_'.$field_type] = apply_filters( 'wdk-currency-conversion/convert/default_value',sanitize_text_field($_GET_clone['field_'.$field_id]), $field_id); |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
if(isset($_GET_clone['field_'.$field_id.'_max'])) { |
| 301 |
$_GET_clone['field_'.$field_id.'_'.$field_type.'_max'] = apply_filters( 'wdk-currency-conversion/convert/default_value',sanitize_text_field($_GET_clone['field_'.$field_id.'_max']), $field_id); |
| 302 |
} |
| 303 |
if(isset($_GET_clone['field_'.$field_id.'_min'])) { |
| 304 |
$_GET_clone['field_'.$field_id.'_'.$field_type.'_min'] = apply_filters( 'wdk-currency-conversion/convert/default_value',sanitize_text_field($_GET_clone['field_'.$field_id.'_min']), $field_id); |
| 305 |
} |
| 306 |
if(isset($_GET_clone['field_'.$field_id.'_exactly'])) { |
| 307 |
$_GET_clone['field_'.$field_id.'_'.$field_type.'_exactly'] = sanitize_text_field($_GET_clone['field_'.$field_id.'_exactly']); |
| 308 |
} |
| 309 |
|
| 310 |
$columns[] = $column_name; |
| 311 |
$columns[] = $column_name.'_max'; |
| 312 |
$columns[] = $column_name.'_min'; |
| 313 |
$columns[] = $column_name.'_exactly'; |
| 314 |
$external_columns[] = $column_name; |
| 315 |
$external_columns[] = $column_name.'_max'; |
| 316 |
$external_columns[] = $column_name.'_min'; |
| 317 |
$external_columns[] = $column_name.'_exactly'; |
| 318 |
} |
| 319 |
|
| 320 |
if(isset($_GET_clone['search_agents_ids'])) { |
| 321 |
$column_name ='agents_ids'; |
| 322 |
$_GET_clone[$column_name] = $_GET_clone['search_agents_ids']; |
| 323 |
$columns[] = $column_name; |
| 324 |
$external_columns[] = $column_name; |
| 325 |
} |
| 326 |
|
| 327 |
if(isset($_GET_clone['search_user_editor_ids'])) { |
| 328 |
$column_name ='user_editor_ids'; |
| 329 |
$_GET_clone[$column_name] = $_GET_clone['search_user_editor_ids']; |
| 330 |
$columns[] = $column_name; |
| 331 |
$external_columns[] = $column_name; |
| 332 |
} |
| 333 |
|
| 334 |
if(isset($_GET_clone['search_location'])) { |
| 335 |
$column_name ='location_id'; |
| 336 |
$_GET_clone[$column_name] = $_GET_clone['search_location']; |
| 337 |
$columns[] = $column_name; |
| 338 |
$external_columns[] = $column_name; |
| 339 |
} |
| 340 |
|
| 341 |
if(isset($_GET_clone['search_category'])) { |
| 342 |
$column_name ='category_id'; |
| 343 |
$_GET_clone[$column_name] = $_GET_clone['search_category']; |
| 344 |
$columns[] = $column_name; |
| 345 |
$external_columns[] = $column_name; |
| 346 |
} |
| 347 |
|
| 348 |
if(isset($_GET_clone['search_gps'])) { |
| 349 |
$column_name ='gps'; |
| 350 |
$_GET_clone[$column_name] = $_GET_clone['search_gps']; |
| 351 |
$columns[] = $column_name; |
| 352 |
$external_columns[] = $column_name; |
| 353 |
} |
| 354 |
|
| 355 |
if(isset($_GET_clone['field_address'])) { |
| 356 |
$column_name ='address'; |
| 357 |
$_GET_clone[$column_name] = $_GET_clone['field_address']; |
| 358 |
$columns[] = $column_name; |
| 359 |
$external_columns[] = $column_name; |
| 360 |
} |
| 361 |
|
| 362 |
if(isset($_GET_clone['field_post_id'])) { |
| 363 |
$column_name ='ID_exactly'; |
| 364 |
$_GET_clone[$column_name] = intval($_GET_clone['field_post_id']); |
| 365 |
$columns[] = $column_name; |
| 366 |
$external_columns[] = $column_name; |
| 367 |
} |
| 368 |
|
| 369 |
if (function_exists('run_wdk_bookings') && isset($_GET_clone['field_booking_date_from'])) { |
| 370 |
$column_name ='field_booking_date_from'; |
| 371 |
$_GET_clone[$column_name] = $_GET_clone['field_booking_date_from']; |
| 372 |
$columns[] = $column_name; |
| 373 |
$external_columns[] = $column_name; |
| 374 |
} |
| 375 |
|
| 376 |
if (function_exists('run_wdk_bookings') && isset($_GET_clone['field_booking_date_to'])) { |
| 377 |
$column_name ='field_booking_date_to'; |
| 378 |
$_GET_clone[$column_name] = $_GET_clone['field_booking_date_to']; |
| 379 |
$columns[] = $column_name; |
| 380 |
$external_columns[] = $column_name; |
| 381 |
} |
| 382 |
|
| 383 |
//$table_name = substr($model_name, 0, -2); |
| 384 |
$columns_original = array(); |
| 385 |
foreach($columns as $key=>$val) |
| 386 |
{ |
| 387 |
$columns_original[$val] = $val; |
| 388 |
|
| 389 |
// if column contain also "table_name.*" |
| 390 |
$splited = explode('.', $val); |
| 391 |
if(wmvc_count($splited) == 2) |
| 392 |
$val = $splited[1]; |
| 393 |
|
| 394 |
if(isset($available_fields[$val])) |
| 395 |
{ |
| 396 |
|
| 397 |
} |
| 398 |
else |
| 399 |
{ |
| 400 |
if(!in_array($columns[$key], $external_columns)) |
| 401 |
{ |
| 402 |
unset($columns[$key]); |
| 403 |
} |
| 404 |
} |
| 405 |
} |
| 406 |
|
| 407 |
if(wmvc_count($_GET_clone) > 0) |
| 408 |
{ |
| 409 |
unset($_GET_clone['search']); |
| 410 |
unset($_GET_clone['field_search']); |
| 411 |
|
| 412 |
// For quick/smart search |
| 413 |
if(wmvc_count($columns) > 0 && !empty($smart_search)) |
| 414 |
{ |
| 415 |
$gen_q = ''; |
| 416 |
foreach($columns as $key=>$value) |
| 417 |
{ |
| 418 |
|
| 419 |
if($value == 'field_booking_date_from' || $value == 'field_booking_date_to' || $value == 'agents_ids' || $value == 'gps' || $value == 'is_featured') continue; |
| 420 |
|
| 421 |
if(strpos($value, '_CHECKBOX') !== FALSE) continue; |
| 422 |
|
| 423 |
// if smart is number, search only im number fields |
| 424 |
|
| 425 |
|
| 426 |
if(is_intval($smart_search)) { |
| 427 |
if(strpos($value, '_NUMBER') === FALSE /*&& $value != 'category_id' && $value != 'location_id'*/ && strpos($value, 'post_id') === FALSE ) continue; |
| 428 |
} else { |
| 429 |
if($value == 'category_id' || $value == 'location_id' || strpos($value, 'post_id') !== FALSE) continue; |
| 430 |
} |
| 431 |
|
| 432 |
if(substr_count($value, 'id') > 0 && is_numeric($smart_search)) |
| 433 |
{ |
| 434 |
$gen_q.="$value = $smart_search OR "; |
| 435 |
} |
| 436 |
else if(substr_count($value, 'date') > 0) |
| 437 |
{ |
| 438 |
$gen_search = $smart_search; |
| 439 |
|
| 440 |
$gen_q.="$value LIKE '%$gen_search%' OR "; |
| 441 |
} |
| 442 |
elseif(substr($value, -8) == '_exactly') |
| 443 |
{ |
| 444 |
|
| 445 |
} |
| 446 |
elseif(substr($value, -4) == '_max') |
| 447 |
{ |
| 448 |
|
| 449 |
} |
| 450 |
else if(substr($value, -4) == '_min') |
| 451 |
{ |
| 452 |
|
| 453 |
} |
| 454 |
else if(strpos($value, '_NUMBER') !== FALSE) |
| 455 |
{ |
| 456 |
if(is_intval($smart_search)){ |
| 457 |
$gen_search = $smart_search; |
| 458 |
$gen_q.="$value = $gen_search OR "; |
| 459 |
} |
| 460 |
} |
| 461 |
else |
| 462 |
{ |
| 463 |
$gen_q.="$value LIKE '%$smart_search%' OR "; |
| 464 |
} |
| 465 |
} |
| 466 |
|
| 467 |
/* location / categories */ |
| 468 |
if(!is_intval($smart_search)) { |
| 469 |
$gen_q.="location_title LIKE '%$smart_search%' OR "; |
| 470 |
$gen_q.="category_title LIKE '%$smart_search%' OR "; |
| 471 |
} |
| 472 |
/* get address and gps */ |
| 473 |
if(strlen($smart_search) > 5) { |
| 474 |
$coordinates_center = wdk_get_gps($smart_search); |
| 475 |
$search_radius = 5; |
| 476 |
if($coordinates_center && $coordinates_center['lat'] != 0 && is_numeric($search_radius)) |
| 477 |
{ |
| 478 |
$distance_unit = 'km'; |
| 479 |
if(__('km', 'wpdirectorykit') == 'm') |
| 480 |
{ |
| 481 |
$distance_unit = 'm'; |
| 482 |
} |
| 483 |
|
| 484 |
// calculate rectangle |
| 485 |
$rectangle_ne = wdk_getDueCoords($coordinates_center['lat'], $coordinates_center['lng'], 45, $search_radius, $distance_unit); |
| 486 |
$rectangle_sw = wdk_getDueCoords($coordinates_center['lat'], $coordinates_center['lng'], 225, $search_radius, $distance_unit); |
| 487 |
|
| 488 |
$gps_ne = explode(', ', $rectangle_ne); |
| 489 |
$gps_sw = explode(', ', $rectangle_sw); |
| 490 |
|
| 491 |
$gen_q .="(".$WMVC->db->prefix."wdk_listings.lat < '$gps_ne[0]' AND ".$WMVC->db->prefix."wdk_listings.lat > '$gps_sw[0]' AND |
| 492 |
".$WMVC->db->prefix."wdk_listings.lng < '$gps_ne[1]' AND ".$WMVC->db->prefix."wdk_listings.lng > '$gps_sw[1]') OR "; |
| 493 |
|
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
/* detect is gps */ |
| 498 |
if(wdk_is_gps($smart_search)) { |
| 499 |
$gps = explode(',',$smart_search); |
| 500 |
$coordinates_center = array('lat'=>trim($gps[0]),'lng'=>trim($gps[1])); |
| 501 |
$search_radius = 5; |
| 502 |
if($coordinates_center && $coordinates_center['lat'] != 0 && is_numeric($search_radius)) |
| 503 |
{ |
| 504 |
$distance_unit = 'km'; |
| 505 |
if(__('km', 'wpdirectorykit') == 'm') |
| 506 |
{ |
| 507 |
$distance_unit = 'm'; |
| 508 |
} |
| 509 |
|
| 510 |
// calculate rectangle |
| 511 |
$rectangle_ne = wdk_getDueCoords($coordinates_center['lat'], $coordinates_center['lng'], 45, $search_radius, $distance_unit); |
| 512 |
$rectangle_sw = wdk_getDueCoords($coordinates_center['lat'], $coordinates_center['lng'], 225, $search_radius, $distance_unit); |
| 513 |
|
| 514 |
$gps_ne = explode(', ', $rectangle_ne); |
| 515 |
$gps_sw = explode(', ', $rectangle_sw); |
| 516 |
|
| 517 |
$gen_q .="(".$WMVC->db->prefix."wdk_listings.lat < '$gps_ne[0]' AND ".$WMVC->db->prefix."wdk_listings.lat > '$gps_sw[0]' AND |
| 518 |
".$WMVC->db->prefix."wdk_listings.lng < '$gps_ne[1]' AND ".$WMVC->db->prefix."wdk_listings.lng > '$gps_sw[1]') OR "; |
| 519 |
|
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
$gen_q = substr($gen_q, 0, -4); |
| 524 |
|
| 525 |
if(!empty($gen_q)) |
| 526 |
$WMVC->db->where("($gen_q)"); |
| 527 |
} |
| 528 |
|
| 529 |
// For column search |
| 530 |
if(isset($_GET_clone)) |
| 531 |
{ |
| 532 |
$gen_q = ''; |
| 533 |
foreach($_GET_clone as $key=>$val) |
| 534 |
{ |
| 535 |
if(!empty($val) && in_array($key, $columns)) |
| 536 |
{ |
| 537 |
$col_name = $key; |
| 538 |
|
| 539 |
$val = esc_sql($val); |
| 540 |
//if(isset($key)) |
| 541 |
// $col_name = $key; |
| 542 |
|
| 543 |
if(strpos($key, 'skip') !== FALSE) continue; |
| 544 |
|
| 545 |
if(function_exists('pll_current_language')) |
| 546 |
{ |
| 547 |
$lang_term_id = pll_current_language('term_id'); |
| 548 |
|
| 549 |
if(is_numeric($lang_term_id)) |
| 550 |
{ |
| 551 |
$WMVC->db->join($WMVC->db->prefix.'term_relationships ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'term_relationships.object_id', NULL, NULL); |
| 552 |
$WMVC->db->where("({$WMVC->db->prefix}term_relationships.term_taxonomy_id = $lang_term_id)"); |
| 553 |
} |
| 554 |
} |
| 555 |
|
| 556 |
if($key == 'field_booking_date_from') |
| 557 |
{ |
| 558 |
if(!$wdk_bookings_joinded){ |
| 559 |
$WMVC->db->join($WMVC->db->prefix.'wdk_booking_price ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_price.post_id', NULL, 'LEFT'); |
| 560 |
$WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id'); |
| 561 |
$WMVC->db->join($WMVC->db->prefix.'wdk_booking_reservation ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_price.post_id', NULL, 'LEFT'); |
| 562 |
$wdk_bookings_joinded = true; |
| 563 |
$gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND '; |
| 564 |
} |
| 565 |
|
| 566 |
if(wdk_is_date($val)) |
| 567 |
{ |
| 568 |
if(!get_option('wdk_bookings_is_hours_enabled')) { |
| 569 |
$gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d'); |
| 570 |
$gen_q.= "DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_price.date_from, '%Y-%m-%d') <= '".$gen_search."' AND "; |
| 571 |
} else { |
| 572 |
$gen_search = wdk_normalize_date_db($val); |
| 573 |
$gen_q.= $WMVC->db->prefix."wdk_booking_price.date_from >'".$gen_search."' AND "; |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
if( isset($_GET_clone['field_booking_date_from']) && isset($_GET_clone['field_booking_date_to'])) { |
| 578 |
|
| 579 |
if(!get_option('wdk_bookings_is_hours_enabled')) { |
| 580 |
$gen_search_from = wdk_normalize_date_db($_GET_clone['field_booking_date_from'], 'Y-m-d H:i:s', 'Y-m-d'); |
| 581 |
$gen_search_to = wdk_normalize_date_db($_GET_clone['field_booking_date_to'], 'Y-m-d H:i:s', 'Y-m-d'); |
| 582 |
|
| 583 |
$gen_q.= $WMVC->listing_m->_table_name.".post_id NOT IN ( |
| 584 |
SELECT post_id |
| 585 |
FROM ".$WMVC->db->prefix."wdk_booking_reservation |
| 586 |
WHERE |
| 587 |
".$WMVC->db->prefix."wdk_booking_reservation.is_approved = 1 |
| 588 |
AND |
| 589 |
DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_reservation.date_from, '%Y-%m-%d') < '".$gen_search_to."' |
| 590 |
AND |
| 591 |
DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_reservation.date_to, '%Y-%m-%d') > '".$gen_search_from."' |
| 592 |
) AND "; |
| 593 |
|
| 594 |
} else { |
| 595 |
$gen_search_from = wdk_normalize_date_db($_GET_clone['field_booking_date_from']); |
| 596 |
$gen_search_to = wdk_normalize_date_db($_GET_clone['field_booking_date_to']); |
| 597 |
|
| 598 |
$gen_q.= $WMVC->listing_m->_table_name.".post_id NOT IN ( |
| 599 |
SELECT post_id |
| 600 |
FROM ".$WMVC->db->prefix."wdk_booking_reservation |
| 601 |
WHERE |
| 602 |
".$WMVC->db->prefix."wdk_booking_reservation.is_approved = 1 |
| 603 |
AND |
| 604 |
".$WMVC->db->prefix."wdk_booking_reservation.date_from < '".$gen_search_to."' |
| 605 |
AND |
| 606 |
".$WMVC->db->prefix."wdk_booking_reservation.date_to > '".$gen_search_from."' |
| 607 |
) AND "; |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
} |
| 612 |
elseif($key == 'field_booking_date_to') |
| 613 |
{ |
| 614 |
if(!$wdk_bookings_joinded){ |
| 615 |
$WMVC->db->join($WMVC->db->prefix.'wdk_booking_price ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_price.post_id',NULL, 'LEFT'); |
| 616 |
$WMVC->db->join($WMVC->db->prefix.'wdk_booking_reservation ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_price.post_id',NULL, 'LEFT'); |
| 617 |
$wdk_bookings_joinded = true; |
| 618 |
$gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND '; |
| 619 |
} |
| 620 |
|
| 621 |
if(wdk_is_date($val)) |
| 622 |
{ |
| 623 |
if(!get_option('wdk_bookings_is_hours_enabled')) { |
| 624 |
$gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d'); |
| 625 |
$gen_q.= "DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_price.date_to, '%Y-%m-%d') >= '".$gen_search."' AND "; |
| 626 |
} else { |
| 627 |
$gen_search = wdk_normalize_date_db($val); |
| 628 |
$gen_q.= $WMVC->db->prefix."wdk_booking_price.date_to >'".$gen_search."' AND "; |
| 629 |
} |
| 630 |
} |
| 631 |
|
| 632 |
} |
| 633 |
elseif(substr($key, -8) == '_exactly') |
| 634 |
{ |
| 635 |
$col_name = substr($key, 0, -8); |
| 636 |
$gen_q.=$col_name." = '".$val."' AND "; |
| 637 |
} |
| 638 |
elseif(substr($key, -4) == '_max') |
| 639 |
{ |
| 640 |
$col_name = substr($key, 0, -4); |
| 641 |
|
| 642 |
if(strpos($key, 'NUMBER') !== FALSE) { |
| 643 |
$gen_q.=$col_name." <= ".intval($val)." AND "; |
| 644 |
} else if(strpos($key, 'DATE') !== FALSE) { |
| 645 |
if(wdk_is_date($val)) |
| 646 |
{ |
| 647 |
$gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d'); |
| 648 |
$gen_q.=$col_name." >= ".$gen_search." AND "; |
| 649 |
} |
| 650 |
} else { |
| 651 |
$gen_q.=$col_name." <= '".$val."' AND "; |
| 652 |
} |
| 653 |
} |
| 654 |
else if(substr($key, -4) == '_min') |
| 655 |
{ |
| 656 |
$col_name = substr($key, 0, -4); |
| 657 |
|
| 658 |
if(strpos($key, 'NUMBER') !== FALSE) { |
| 659 |
$gen_q.=$col_name." >= ".intval($val)." AND "; |
| 660 |
} else if(strpos($key, 'DATE') !== FALSE) { |
| 661 |
if(wdk_is_date($val)) |
| 662 |
{ |
| 663 |
$gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d'); |
| 664 |
$gen_q.=$col_name." >= ".$gen_search." AND "; |
| 665 |
} |
| 666 |
} else { |
| 667 |
$gen_q.=$col_name." >= '".$val."' AND "; |
| 668 |
} |
| 669 |
} |
| 670 |
elseif(substr_count($key, 'id') > 0 && is_numeric($val) && $key != 'agents_ids' && $key !='user_editor_ids' && $key !='location_id' && $key !='category_id') |
| 671 |
{ |
| 672 |
// ID is always numeric |
| 673 |
|
| 674 |
if($key == 'location_id') { |
| 675 |
/* $gen_q .= "(`location_table`.`parent_path` = ".$val." OR "; |
| 676 |
$gen_q .= "`location_2`.`parent_path` = ".$val." OR ";*/ |
| 677 |
$gen_q .= "(`location_table`.`parent_id` = ".$val." OR "; |
| 678 |
//$gen_q .= "`".$WMVC->db->prefix."wdk_locations `.`level_0_id` = ".$val." OR "; |
| 679 |
|
| 680 |
$gen_q .= $col_name." = ".$val.") AND "; |
| 681 |
} elseif($key == 'category_id') { |
| 682 |
$gen_q .= "('parent_path' = ".$val." OR "; |
| 683 |
$gen_q .= $col_name." = ".$val.") AND "; |
| 684 |
} else { |
| 685 |
$gen_q.=$col_name." = ".$val." AND "; |
| 686 |
} |
| 687 |
} |
| 688 |
else if(substr_count($key, '_DATE') > 0) |
| 689 |
{ |
| 690 |
// DATE VALUES |
| 691 |
|
| 692 |
$gen_search = $val; |
| 693 |
if(wdk_is_date($val)) |
| 694 |
{ |
| 695 |
$gen_search = wdk_normalize_date_db($gen_search, 'Y-m-d H:i:s', 'Y-m-d'); |
| 696 |
$gen_q.=$col_name." LIKE '%".$gen_search."%' AND "; |
| 697 |
} |
| 698 |
else |
| 699 |
{ |
| 700 |
$gen_q.=$col_name." LIKE '%".$gen_search."%' AND "; |
| 701 |
|
| 702 |
} |
| 703 |
} |
| 704 |
else if(substr_count($key, 'is_') > 0) |
| 705 |
{ |
| 706 |
// CHECKBOXES |
| 707 |
|
| 708 |
if($val=='on') |
| 709 |
{ |
| 710 |
$gen_search = 1; |
| 711 |
$gen_q.=$col_name." LIKE '%".$gen_search."%' AND "; |
| 712 |
} |
| 713 |
else if($val=='off') |
| 714 |
{ |
| 715 |
$gen_q.=$col_name." IS NULL AND "; |
| 716 |
} |
| 717 |
} |
| 718 |
elseif($key == 'agents_ids') |
| 719 |
{ |
| 720 |
if(is_string($val) && strpos($val, ',') !== FALSE){ |
| 721 |
$val =explode(',', $val); |
| 722 |
} elseif(is_string($val)){ |
| 723 |
$val =array($val); |
| 724 |
} |
| 725 |
|
| 726 |
if(is_array($val)) { |
| 727 |
|
| 728 |
$WMVC->db->join($WMVC->db->prefix.'wdk_listings_users ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_listings_users.post_id', NULL, 'LEFT'); |
| 729 |
$WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id'); |
| 730 |
$sql_search = ''; |
| 731 |
foreach ($val as $v) { |
| 732 |
if(empty($v)) continue; |
| 733 |
|
| 734 |
if(!empty($sql_search)) |
| 735 |
$sql_search .= " OR "; |
| 736 |
|
| 737 |
|
| 738 |
$sql_search .=" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($v)." OR `".$WMVC->db->prefix."wdk_listings_users`.`user_id` = ".intval($v)." "; |
| 739 |
} |
| 740 |
|
| 741 |
if(!empty($sql_search)) |
| 742 |
$gen_q.=" ( ".$sql_search." ) AND "; |
| 743 |
|
| 744 |
} elseif(is_string($val) && !empty($val)) { |
| 745 |
$WMVC->db->join($WMVC->db->prefix.'wdk_listings_users ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_listings_users.post_id', NULL, 'LEFT'); |
| 746 |
$WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id'); |
| 747 |
$sql_search =" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($val)." OR `".$WMVC->db->prefix."wdk_listings_users`.`user_id` = ".intval($val)." "; |
| 748 |
$gen_q.=" ( ".$sql_search." ) AND "; |
| 749 |
} |
| 750 |
} |
| 751 |
elseif($key == 'user_editor_ids') |
| 752 |
{ |
| 753 |
|
| 754 |
if(is_array($val)) { |
| 755 |
|
| 756 |
$sql_search = ''; |
| 757 |
foreach ($val as $v) { |
| 758 |
if(empty($v)) continue; |
| 759 |
|
| 760 |
if(!empty($sql_search)) |
| 761 |
$sql_search .= " OR "; |
| 762 |
|
| 763 |
|
| 764 |
$sql_search .=" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($v)." "; |
| 765 |
} |
| 766 |
|
| 767 |
if(!empty($sql_search)) |
| 768 |
$gen_q.=" ( ".$sql_search." ) AND "; |
| 769 |
|
| 770 |
} elseif(is_string($val) && !empty($val)) { |
| 771 |
$sql_search =" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($val)." "; |
| 772 |
$gen_q.=" ( ".$sql_search." ) AND "; |
| 773 |
} |
| 774 |
} |
| 775 |
elseif($key == 'location_id') |
| 776 |
{ |
| 777 |
|
| 778 |
if(is_string($val) && strpos($val, ',') !== FALSE){ |
| 779 |
$val =explode(',', $val); |
| 780 |
} elseif(is_string($val)){ |
| 781 |
$val =array($val); |
| 782 |
} |
| 783 |
|
| 784 |
if(is_array($val)) { |
| 785 |
|
| 786 |
if(false){ |
| 787 |
$WMVC->db->join($WMVC->db->prefix.'wdk_listings_locations ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_listings_locations.post_id', NULL, 'LEFT'); |
| 788 |
$WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id'); |
| 789 |
} |
| 790 |
|
| 791 |
$sql_search = ''; |
| 792 |
foreach ($val as $v) { |
| 793 |
if(empty($v)) continue; |
| 794 |
|
| 795 |
if(!empty($sql_search)) |
| 796 |
$sql_search .= " OR "; |
| 797 |
|
| 798 |
$sql_search .= " ".$WMVC->listing_m->_table_name.".`location_id`=".intval($v).""; |
| 799 |
$sql_search .= " OR `location_table`.`parent_id`=".intval($v).""; |
| 800 |
|
| 801 |
/* other locations */ |
| 802 |
/* multi select */ |
| 803 |
if(false){ |
| 804 |
$sql_search .= " OR `".$WMVC->db->prefix."wdk_listings`.`post_id` IN (SELECT `post_id` FROM `".$WMVC->db->prefix."wdk_listings_locations` WHERE `location_id` = ".intval($v).") "; |
| 805 |
} elseif(false) { |
| 806 |
$sql_search .= " OR ".$WMVC->db->prefix."wdk_listings_locations.location_id=".intval($v).""; |
| 807 |
} else { |
| 808 |
$sql_search .= " OR ".$WMVC->listing_m->_table_name.".locations_list LIKE '%,".intval($v).",%'"; |
| 809 |
} |
| 810 |
|
| 811 |
} |
| 812 |
|
| 813 |
if(!empty($sql_search)) |
| 814 |
$gen_q.=" ( ".$sql_search." ) AND "; |
| 815 |
} |
| 816 |
} |
| 817 |
elseif($key == 'category_id') |
| 818 |
{ |
| 819 |
|
| 820 |
if(is_string($val) && strpos($val, ',') !== FALSE){ |
| 821 |
$val =explode(',', $val); |
| 822 |
} elseif(is_string($val)){ |
| 823 |
$val =array($val); |
| 824 |
} |
| 825 |
|
| 826 |
|
| 827 |
if(is_array($val)) { |
| 828 |
if(false){ |
| 829 |
$WMVC->db->join($WMVC->db->prefix.'wdk_listings_categories ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_listings_categories.post_id', NULL, 'LEFT'); |
| 830 |
} |
| 831 |
|
| 832 |
$sql_search = ''; |
| 833 |
foreach ($val as $v) { |
| 834 |
if(empty($v)) continue; |
| 835 |
|
| 836 |
if(!empty($sql_search)) |
| 837 |
$sql_search .= " OR "; |
| 838 |
|
| 839 |
$sql_search .= " ".$WMVC->db->prefix."wdk_listings.`category_id` = ".intval($v).""; |
| 840 |
$sql_search .= " OR `category_table`.`parent_id`=".intval($v).""; |
| 841 |
|
| 842 |
/* other categories */ |
| 843 |
if(false){ |
| 844 |
$sql_search .= " OR `".$WMVC->db->prefix."wdk_listings`.`post_id` IN (SELECT `post_id` FROM `".$WMVC->db->prefix."wdk_listings_categories` WHERE `category_id` = ".intval($v).")"; |
| 845 |
} elseif(false) { |
| 846 |
$sql_search .= " OR ".$WMVC->db->prefix."wdk_listings_categories.category_id=".intval($v).""; |
| 847 |
} else { |
| 848 |
$sql_search .= " OR ".$WMVC->listing_m->_table_name.".categories_list LIKE '%,".intval($v).",%'"; |
| 849 |
} |
| 850 |
|
| 851 |
} |
| 852 |
|
| 853 |
if(!empty($sql_search)) |
| 854 |
$gen_q.=" ( ".$sql_search." ) AND "; |
| 855 |
} |
| 856 |
} |
| 857 |
elseif(is_string($val)) |
| 858 |
{ |
| 859 |
|
| 860 |
if(strpos($val, ',') !== FALSE){ |
| 861 |
$val = explode(',', $val); |
| 862 |
} |
| 863 |
|
| 864 |
if(is_array($val)) { |
| 865 |
$sql_search = ''; |
| 866 |
foreach ($val as $v) { |
| 867 |
if(empty($v)) continue; |
| 868 |
|
| 869 |
if(!empty($sql_search)) |
| 870 |
$sql_search .= " OR "; |
| 871 |
|
| 872 |
$sql_search .= $col_name." LIKE '%".$v."%'"; |
| 873 |
|
| 874 |
} |
| 875 |
|
| 876 |
if(!empty($sql_search)) |
| 877 |
$gen_q.=" ( ".$sql_search." ) AND "; |
| 878 |
} else { |
| 879 |
$gen_q.=$col_name." LIKE '%".$val."%' AND "; |
| 880 |
} |
| 881 |
|
| 882 |
} |
| 883 |
elseif(is_array($val)) |
| 884 |
{ |
| 885 |
$sql_search = ''; |
| 886 |
foreach ($val as $v) { |
| 887 |
if(empty($v)) continue; |
| 888 |
|
| 889 |
if(!empty($sql_search)) |
| 890 |
$sql_search .= " OR "; |
| 891 |
|
| 892 |
$sql_search .= " ".$col_name." LIKE '%".esc_sql($v)."%' "; |
| 893 |
} |
| 894 |
|
| 895 |
if(!empty($sql_search)) |
| 896 |
$gen_q.=" ( ".$sql_search." ) AND "; |
| 897 |
} |
| 898 |
} |
| 899 |
|
| 900 |
} |
| 901 |
|
| 902 |
$gen_q = substr($gen_q, 0, -5); |
| 903 |
|
| 904 |
if(!empty($gen_q)) |
| 905 |
$WMVC->db->where("($gen_q)"); |
| 906 |
} |
| 907 |
|
| 908 |
// order |
| 909 |
if(isset($_GET_clone['order_by'])) |
| 910 |
{ |
| 911 |
$_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_listings.post_id', $_GET_clone['order_by']); |
| 912 |
$WMVC->db->order_by($_GET_clone['order_by']); |
| 913 |
} |
| 914 |
|
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
function wdk_users_prepare_search_query_GET($columns = array(), $model_name = NULL, $external_columns = array(), $custom_parameters = array(), $skip_postget = FALSE) |
| 919 |
{ |
| 920 |
global $Winter_MVC_WDK; |
| 921 |
$WMVC = &$Winter_MVC_WDK; |
| 922 |
|
| 923 |
$_GET_clone = array(); |
| 924 |
|
| 925 |
if(!$skip_postget) |
| 926 |
$_GET_clone = array_merge($_GET, $_POST); |
| 927 |
|
| 928 |
if(isset($custom_parameters['order_by'])) { |
| 929 |
|
| 930 |
if(isset($_GET_clone['order_by']) && !empty($_GET_clone['order_by'])) { |
| 931 |
$_GET_clone['order_by'] = $custom_parameters['order_by'].', '.$_GET_clone['order_by']; |
| 932 |
} else { |
| 933 |
$_GET_clone['order_by'] = $custom_parameters['order_by']; |
| 934 |
} |
| 935 |
|
| 936 |
unset($custom_parameters['order_by']); |
| 937 |
} |
| 938 |
|
| 939 |
|
| 940 |
if(!empty($custom_parameters)) |
| 941 |
$_GET_clone = array_merge($_GET_clone, $custom_parameters); |
| 942 |
|
| 943 |
$WMVC->model($model_name); |
| 944 |
|
| 945 |
$smart_search = ''; |
| 946 |
if(isset($_GET_clone['profile_search'])) |
| 947 |
$smart_search = sanitize_text_field($_GET_clone['profile_search']); |
| 948 |
|
| 949 |
$available_fields = array('user_login','user_nicename','user_email','user_url','display_name'); |
| 950 |
|
| 951 |
if(isset($_GET_clone['is_activated'])){ |
| 952 |
$_GET_clone[$WMVC->$model_name->_table_name.'.is_activated'] = sanitize_text_field($_GET_clone['is_activated']); |
| 953 |
unset($_GET_clone['is_activated']); |
| 954 |
} |
| 955 |
|
| 956 |
if(isset($_GET_clone['is_approved'])){ |
| 957 |
$_GET_clone[$WMVC->$model_name->_table_name.'.is_approved'] = sanitize_text_field($_GET_clone['is_approved']); |
| 958 |
unset($_GET_clone['is_approved']); |
| 959 |
} |
| 960 |
|
| 961 |
|
| 962 |
//$table_name = substr($model_name, 0, -2); |
| 963 |
$columns_original = array(); |
| 964 |
foreach($columns as $key=>$val) |
| 965 |
{ |
| 966 |
$columns_original[$val] = $val; |
| 967 |
|
| 968 |
// if column contain also "table_name.*" |
| 969 |
$splited = explode('.', $val); |
| 970 |
if(wmvc_count($splited) == 2) |
| 971 |
$val = $splited[1]; |
| 972 |
|
| 973 |
if(isset($available_fields[$val])) |
| 974 |
{ |
| 975 |
|
| 976 |
} |
| 977 |
else |
| 978 |
{ |
| 979 |
if(!in_array($columns[$key], $external_columns)) |
| 980 |
{ |
| 981 |
unset($columns[$key]); |
| 982 |
} |
| 983 |
} |
| 984 |
} |
| 985 |
|
| 986 |
if(wmvc_count($_GET_clone) > 0) |
| 987 |
{ |
| 988 |
unset($_GET_clone['search']); |
| 989 |
|
| 990 |
// For quick/smart search |
| 991 |
if(wmvc_count($columns) > 0 && !empty($smart_search)) |
| 992 |
{ |
| 993 |
$gen_q = ''; |
| 994 |
foreach($columns as $key=>$value) |
| 995 |
{ |
| 996 |
|
| 997 |
if($value == 'post_type') |
| 998 |
{ |
| 999 |
$value = $WMVC->$model_name->_table_name.'.'.$value; |
| 1000 |
} |
| 1001 |
|
| 1002 |
if(substr_count($value, 'id') > 0 && is_numeric($smart_search)) |
| 1003 |
{ |
| 1004 |
$gen_q.="$value = $smart_search OR "; |
| 1005 |
} |
| 1006 |
else if(substr_count($value, 'date') > 0) |
| 1007 |
{ |
| 1008 |
//$gen_search = wmvc_generate_slug($smart_search, ' '); |
| 1009 |
|
| 1010 |
$gen_search = $smart_search; |
| 1011 |
|
| 1012 |
$gen_q.="$value LIKE '%$gen_search%' OR "; |
| 1013 |
} |
| 1014 |
else |
| 1015 |
{ |
| 1016 |
$gen_q.="$value LIKE '%$smart_search%' OR "; |
| 1017 |
} |
| 1018 |
} |
| 1019 |
$gen_q = substr($gen_q, 0, -4); |
| 1020 |
|
| 1021 |
if(!empty($gen_q)) |
| 1022 |
$WMVC->db->where("($gen_q)"); |
| 1023 |
} |
| 1024 |
|
| 1025 |
// For column search |
| 1026 |
if(isset($_GET_clone)) |
| 1027 |
{ |
| 1028 |
$gen_q = ''; |
| 1029 |
|
| 1030 |
foreach($_GET_clone as $key=>$val) |
| 1031 |
{ |
| 1032 |
if(!empty($val) && in_array($key, $columns)) |
| 1033 |
{ |
| 1034 |
$col_name = $key; |
| 1035 |
|
| 1036 |
if($col_name == 'post_type') |
| 1037 |
{ |
| 1038 |
$col_name = $WMVC->$model_name->_table_name.'.'.$col_name; |
| 1039 |
} |
| 1040 |
|
| 1041 |
//if(isset($key)) |
| 1042 |
// $col_name = $key; |
| 1043 |
|
| 1044 |
if(strpos($key, 'skip') !== FALSE) continue; |
| 1045 |
|
| 1046 |
if(substr($key, -8) == '_exactly') |
| 1047 |
{ |
| 1048 |
$col_name = substr($key, 0, -8); |
| 1049 |
$gen_q.=$col_name." = '".$val."' AND "; |
| 1050 |
} |
| 1051 |
elseif(substr($key, -4) == '_max') |
| 1052 |
{ |
| 1053 |
$col_name = substr($key, 0, -4); |
| 1054 |
$gen_q.=$col_name." <= '".$val."' AND "; |
| 1055 |
} |
| 1056 |
else if(substr($key, -4) == '_min') |
| 1057 |
{ |
| 1058 |
$col_name = substr($key, 0, -4); |
| 1059 |
|
| 1060 |
$gen_q.=$col_name." >= '".$val."' AND "; |
| 1061 |
} |
| 1062 |
elseif(substr_count($key, 'id') > 0 && is_numeric($val)) |
| 1063 |
{ |
| 1064 |
// ID is always numeric |
| 1065 |
|
| 1066 |
$gen_q.=$col_name." = ".$val." AND "; |
| 1067 |
} |
| 1068 |
else if(substr_count($key, 'date') > 0) |
| 1069 |
{ |
| 1070 |
// DATE VALUES |
| 1071 |
|
| 1072 |
$gen_search = $val; |
| 1073 |
|
| 1074 |
if(wdk_is_date($val)) |
| 1075 |
{ |
| 1076 |
$gen_search = wdk_normalize_date_db($gen_search); |
| 1077 |
$gen_q.=$col_name." > '".$gen_search."' AND "; |
| 1078 |
} |
| 1079 |
else |
| 1080 |
{ |
| 1081 |
$gen_q.=$col_name." LIKE '%".$gen_search."%' AND "; |
| 1082 |
} |
| 1083 |
} |
| 1084 |
else if(substr_count($key, 'is_') > 0) |
| 1085 |
{ |
| 1086 |
// CHECKBOXES |
| 1087 |
|
| 1088 |
if($val=='on') |
| 1089 |
{ |
| 1090 |
$gen_search = 1; |
| 1091 |
$gen_q.=$col_name." LIKE '%".$gen_search."%' AND "; |
| 1092 |
} |
| 1093 |
else if($val=='off') |
| 1094 |
{ |
| 1095 |
$gen_q.=$col_name." IS NULL AND "; |
| 1096 |
} |
| 1097 |
} |
| 1098 |
else |
| 1099 |
{ |
| 1100 |
$gen_q.=$col_name." LIKE '%".$val."%' AND "; |
| 1101 |
} |
| 1102 |
} |
| 1103 |
|
| 1104 |
} |
| 1105 |
|
| 1106 |
$gen_q = substr($gen_q, 0, -5); |
| 1107 |
|
| 1108 |
if(!empty($gen_q)) |
| 1109 |
$WMVC->db->where("($gen_q)"); |
| 1110 |
} |
| 1111 |
|
| 1112 |
// order |
| 1113 |
if(isset($_GET_clone['order_by'])) |
| 1114 |
{ |
| 1115 |
$_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_favorite.post_id', $_GET_clone['order_by']); |
| 1116 |
$WMVC->db->order_by($_GET_clone['order_by']); |
| 1117 |
} |
| 1118 |
|
| 1119 |
} |
| 1120 |
} |
| 1121 |
|
| 1122 |
function wdk_messages_prepare_search_query_GET($columns = array(), $model_name = NULL, $external_columns = array(), $custom_parameters = array(), $skip_postget = FALSE) |
| 1123 |
{ |
| 1124 |
global $Winter_MVC_WDK; |
| 1125 |
$WMVC = &$Winter_MVC_WDK; |
| 1126 |
|
| 1127 |
$_GET_clone = array(); |
| 1128 |
|
| 1129 |
if(!$skip_postget) |
| 1130 |
$_GET_clone = array_merge($_GET, $_POST); |
| 1131 |
|
| 1132 |
if(isset($custom_parameters['order_by'])) { |
| 1133 |
|
| 1134 |
if(isset($_GET_clone['order_by']) && !empty($_GET_clone['order_by'])) { |
| 1135 |
$_GET_clone['order_by'] = $custom_parameters['order_by'].', '.$_GET_clone['order_by']; |
| 1136 |
} else { |
| 1137 |
$_GET_clone['order_by'] = $custom_parameters['order_by']; |
| 1138 |
} |
| 1139 |
|
| 1140 |
unset($custom_parameters['order_by']); |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
if(!empty($custom_parameters)) |
| 1145 |
$_GET_clone = array_merge($_GET_clone, $custom_parameters); |
| 1146 |
|
| 1147 |
$WMVC->model($model_name); |
| 1148 |
|
| 1149 |
$smart_search = ''; |
| 1150 |
if(isset($_GET_clone['profile_search'])) |
| 1151 |
$smart_search = sanitize_text_field($_GET_clone['profile_search']); |
| 1152 |
|
| 1153 |
$available_fields = array('user_login','user_nicename','user_email','user_url','display_name'); |
| 1154 |
|
| 1155 |
if(isset($_GET_clone['is_activated'])){ |
| 1156 |
$_GET_clone[$WMVC->$model_name->_table_name.'.is_activated'] = sanitize_text_field($_GET_clone['is_activated']); |
| 1157 |
unset($_GET_clone['is_activated']); |
| 1158 |
} |
| 1159 |
|
| 1160 |
if(isset($_GET_clone['is_approved'])){ |
| 1161 |
$_GET_clone[$WMVC->$model_name->_table_name.'.is_approved'] = sanitize_text_field($_GET_clone['is_approved']); |
| 1162 |
unset($_GET_clone['is_approved']); |
| 1163 |
} |
| 1164 |
|
| 1165 |
|
| 1166 |
//$table_name = substr($model_name, 0, -2); |
| 1167 |
$columns_original = array(); |
| 1168 |
foreach($columns as $key=>$val) |
| 1169 |
{ |
| 1170 |
$columns_original[$val] = $val; |
| 1171 |
|
| 1172 |
// if column contain also "table_name.*" |
| 1173 |
$splited = explode('.', $val); |
| 1174 |
if(wmvc_count($splited) == 2) |
| 1175 |
$val = $splited[1]; |
| 1176 |
|
| 1177 |
if(isset($available_fields[$val])) |
| 1178 |
{ |
| 1179 |
|
| 1180 |
} |
| 1181 |
else |
| 1182 |
{ |
| 1183 |
if(!in_array($columns[$key], $external_columns)) |
| 1184 |
{ |
| 1185 |
unset($columns[$key]); |
| 1186 |
} |
| 1187 |
} |
| 1188 |
} |
| 1189 |
|
| 1190 |
if(wmvc_count($_GET_clone) > 0) |
| 1191 |
{ |
| 1192 |
unset($_GET_clone['search']); |
| 1193 |
|
| 1194 |
// For quick/smart search |
| 1195 |
if(wmvc_count($columns) > 0 && !empty($smart_search)) |
| 1196 |
{ |
| 1197 |
$gen_q = ''; |
| 1198 |
foreach($columns as $key=>$value) |
| 1199 |
{ |
| 1200 |
|
| 1201 |
if($value == 'post_type') |
| 1202 |
{ |
| 1203 |
$value = $WMVC->$model_name->_table_name.'.'.$value; |
| 1204 |
} |
| 1205 |
|
| 1206 |
if(substr_count($value, 'id') > 0 && is_numeric($smart_search)) |
| 1207 |
{ |
| 1208 |
$gen_q.="$value = $smart_search OR "; |
| 1209 |
} |
| 1210 |
else if(substr_count($value, 'date') > 0) |
| 1211 |
{ |
| 1212 |
//$gen_search = wmvc_generate_slug($smart_search, ' '); |
| 1213 |
|
| 1214 |
$gen_search = $smart_search; |
| 1215 |
|
| 1216 |
$gen_q.="$value LIKE '%$gen_search%' OR "; |
| 1217 |
} |
| 1218 |
else |
| 1219 |
{ |
| 1220 |
$gen_q.="$value LIKE '%$smart_search%' OR "; |
| 1221 |
} |
| 1222 |
} |
| 1223 |
$gen_q = substr($gen_q, 0, -4); |
| 1224 |
|
| 1225 |
if(!empty($gen_q)) |
| 1226 |
$WMVC->db->where("($gen_q)"); |
| 1227 |
} |
| 1228 |
|
| 1229 |
// For column search |
| 1230 |
if(isset($_GET_clone)) |
| 1231 |
{ |
| 1232 |
$gen_q = ''; |
| 1233 |
|
| 1234 |
foreach($_GET_clone as $key=>$val) |
| 1235 |
{ |
| 1236 |
if(!empty($val) && in_array($key, $columns)) |
| 1237 |
{ |
| 1238 |
$col_name = $key; |
| 1239 |
|
| 1240 |
if($col_name == 'post_type') |
| 1241 |
{ |
| 1242 |
$col_name = $WMVC->$model_name->_table_name.'.'.$col_name; |
| 1243 |
} |
| 1244 |
|
| 1245 |
//if(isset($key)) |
| 1246 |
// $col_name = $key; |
| 1247 |
|
| 1248 |
if(strpos($key, 'skip') !== FALSE) continue; |
| 1249 |
|
| 1250 |
if(substr($key, -8) == '_exactly') |
| 1251 |
{ |
| 1252 |
$col_name = substr($key, 0, -8); |
| 1253 |
$gen_q.=$col_name." = '".$val."' AND "; |
| 1254 |
} |
| 1255 |
elseif(substr($key, -4) == '_max') |
| 1256 |
{ |
| 1257 |
$col_name = substr($key, 0, -4); |
| 1258 |
$gen_q.=$col_name." <= '".$val."' AND "; |
| 1259 |
} |
| 1260 |
else if(substr($key, -4) == '_min') |
| 1261 |
{ |
| 1262 |
$col_name = substr($key, 0, -4); |
| 1263 |
|
| 1264 |
$gen_q.=$col_name." >= '".$val."' AND "; |
| 1265 |
} |
| 1266 |
elseif(substr_count($key, 'id') > 0 && is_numeric($val)) |
| 1267 |
{ |
| 1268 |
// ID is always numeric |
| 1269 |
|
| 1270 |
$gen_q.=$col_name." = ".$val." AND "; |
| 1271 |
} |
| 1272 |
else if(substr_count($key, 'date') > 0) |
| 1273 |
{ |
| 1274 |
// DATE VALUES |
| 1275 |
|
| 1276 |
$gen_search = $val; |
| 1277 |
|
| 1278 |
|
| 1279 |
if(wdk_is_date($val)) |
| 1280 |
{ |
| 1281 |
$gen_search = wdk_normalize_date_db($gen_search); |
| 1282 |
$gen_q.=$col_name." > '".$gen_search."' AND "; |
| 1283 |
} |
| 1284 |
else |
| 1285 |
{ |
| 1286 |
$gen_q.=$col_name." LIKE '%".$gen_search."%' AND "; |
| 1287 |
} |
| 1288 |
} |
| 1289 |
else if(substr_count($key, 'is_') > 0) |
| 1290 |
{ |
| 1291 |
// CHECKBOXES |
| 1292 |
|
| 1293 |
if($val=='on') |
| 1294 |
{ |
| 1295 |
$gen_search = 1; |
| 1296 |
$gen_q.=$col_name." LIKE '%".$gen_search."%' AND "; |
| 1297 |
} |
| 1298 |
else if($val=='off') |
| 1299 |
{ |
| 1300 |
$gen_q.=$col_name." IS NULL AND "; |
| 1301 |
} |
| 1302 |
} |
| 1303 |
else |
| 1304 |
{ |
| 1305 |
$gen_q.=$col_name." LIKE '%".$val."%' AND "; |
| 1306 |
} |
| 1307 |
} |
| 1308 |
|
| 1309 |
} |
| 1310 |
|
| 1311 |
$gen_q = substr($gen_q, 0, -5); |
| 1312 |
|
| 1313 |
if(!empty($gen_q)) |
| 1314 |
$WMVC->db->where("($gen_q)"); |
| 1315 |
} |
| 1316 |
|
| 1317 |
// order |
| 1318 |
if(isset($_GET_clone['order_by'])) |
| 1319 |
{ |
| 1320 |
$_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_favorite.post_id', $_GET_clone['order_by']); |
| 1321 |
$WMVC->db->order_by($_GET_clone['order_by']); |
| 1322 |
} |
| 1323 |
|
| 1324 |
} |
| 1325 |
} |
| 1326 |
|
| 1327 |
function wdk_date() { |
| 1328 |
$date_format = get_option('date_format'); |
| 1329 |
$time_format = get_option('time_format'); |
| 1330 |
$date = date("{$date_format} {$time_format}", current_time('timestamp')); |
| 1331 |
return $date; |
| 1332 |
} |
| 1333 |
|
| 1334 |
if(!function_exists('wdk_placeholder_image_src')) { |
| 1335 |
function wdk_placeholder_image_src () { |
| 1336 |
$i = WPDIRECTORYKIT_URL.'public/img/placeholder.jpg'; |
| 1337 |
|
| 1338 |
if(wdk_get_option('wdk_placeholder')) { |
| 1339 |
$image = wp_get_attachment_image_src(wdk_get_option('wdk_placeholder'), 'full' ); |
| 1340 |
if(!empty($image) && file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $image[0]))) |
| 1341 |
$i = $image[0]; |
| 1342 |
} |
| 1343 |
|
| 1344 |
return $i; |
| 1345 |
} |
| 1346 |
} |
| 1347 |
|
| 1348 |
|
| 1349 |
function wdk_wp_frontend_paginate($total_items, $per_page = 10, $page_var = 'wmvc_paged', $texts = array(), $enable_latest_first = TRUE, $enable_count = FALSE, $enable_compact = FALSE, $limit_items = 1) |
| 1350 |
{ |
| 1351 |
$current_page = 1; |
| 1352 |
|
| 1353 |
if(isset($_GET[$page_var])) |
| 1354 |
$current_page = intval(wmvc_xss_clean($_GET[$page_var])); |
| 1355 |
|
| 1356 |
if(!isset($texts['previous_page']))$texts['previous_page'] = 'Previous page'; |
| 1357 |
if(!isset($texts['next_page']))$texts['next_page'] = 'Next page'; |
| 1358 |
if(!isset($texts['first_page']))$texts['first_page'] = ''; |
| 1359 |
if(!isset($texts['last_page']))$texts['last_page'] = ''; |
| 1360 |
if(!isset($texts['items']))$texts['items'] = 'items'; |
| 1361 |
|
| 1362 |
if(empty($current_page))$current_page = 1; |
| 1363 |
|
| 1364 |
// get url |
| 1365 |
$url = strtok($_SERVER["REQUEST_URI"], '?'); |
| 1366 |
$qs_parameters = wmvc_xss_clean( $_GET ); |
| 1367 |
unset($qs_parameters[$page_var]); |
| 1368 |
$qs_part = http_build_query($qs_parameters); |
| 1369 |
$url = wdk_url_suffix($url, $qs_part); |
| 1370 |
|
| 1371 |
// total pages |
| 1372 |
$total_pages = intval($total_items/$per_page+0.99); |
| 1373 |
|
| 1374 |
if($current_page == 1) { |
| 1375 |
$limit_items = $limit_items * 2; |
| 1376 |
} |
| 1377 |
|
| 1378 |
if($current_page == $total_pages) { |
| 1379 |
$limit_items = $limit_items * 2; |
| 1380 |
} |
| 1381 |
|
| 1382 |
$output = '<nav class="wdk-pagination navigation pagination" role="navigation">'; |
| 1383 |
if($enable_count){ |
| 1384 |
$output.= '<span class="displaying-num">'.$total_items.' '.$texts['items'].'</span>'; |
| 1385 |
} |
| 1386 |
|
| 1387 |
$output .= '<div class="nav-links">'; |
| 1388 |
|
| 1389 |
if($enable_latest_first && $current_page-1 > 0) |
| 1390 |
$output.= '<a class="next page-numbers" href="'.esc_url($url).'#results"><span class="screen-reader-text">'.esc_html($texts['first_page']).'</span><span aria-hidden="true">«</span></a>'; |
| 1391 |
|
| 1392 |
if ($current_page-1 > 0) { |
| 1393 |
|
| 1394 |
$output.= '<a class="next page-numbers" href="'.esc_url(wdk_url_suffix($url,esc_attr($page_var).'='.esc_attr($current_page-1))).'#results"><span class="screen-reader-text">'.esc_html($texts['previous_page']).'</span><span aria-hidden="true">‹</span></a>'; |
| 1395 |
} elseif($enable_compact) |
| 1396 |
{ |
| 1397 |
$output.= '<span class="next page-numbers disabled" href=""><span class="screen-reader-text">'.esc_html($texts['previous_page']).'</span><span aria-hidden="true">‹</span></span>'; |
| 1398 |
} |
| 1399 |
|
| 1400 |
if (!$enable_compact) { |
| 1401 |
for ($i = 1 ; $i <= $total_pages; $i++) { |
| 1402 |
$class = ($current_page == $i) ? "active" : ""; |
| 1403 |
if(($current_page-$limit_items) <= $i && ($current_page+$limit_items) >= $i) { |
| 1404 |
if (($current_page == $i)) { |
| 1405 |
$output.= '<span aria-current="page" class="page-numbers current">'.$i.'</span>'; |
| 1406 |
} else { |
| 1407 |
$output.= '<a class="page-numbers" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($i))).'#results">'.esc_attr($i).'</a>'; |
| 1408 |
} |
| 1409 |
} |
| 1410 |
} |
| 1411 |
} else { |
| 1412 |
$output.= '<span class="wdk_pages_range">'.$current_page.' '.esc_html__('of','wpdirectorykit').' '.$total_pages.'</span>'; |
| 1413 |
} |
| 1414 |
|
| 1415 |
if($current_page+1 <= $total_pages) |
| 1416 |
{ |
| 1417 |
$output.= '<a class="next page-numbers" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($current_page+1))).'#results"><span class="screen-reader-text">'.esc_html($texts['next_page']).'</span><span aria-hidden="true">›</span></a>'; |
| 1418 |
} |
| 1419 |
elseif($enable_compact) |
| 1420 |
{ |
| 1421 |
$output.= '<a class="next page-numbers disabled" href=""><span class="screen-reader-text">'.esc_html($texts['next_page']).'</span><span aria-hidden="true">›</span></a>'; |
| 1422 |
} |
| 1423 |
|
| 1424 |
if($enable_latest_first && $current_page+1 <= $total_pages) |
| 1425 |
$output.= '<a class="next page-numbers" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($total_pages))).'#results"><span class="screen-reader-text">'.esc_html($texts['last_page']).'</span><span aria-hidden="true">»</span></a>'; |
| 1426 |
|
| 1427 |
|
| 1428 |
$output.= '</div>'; |
| 1429 |
$output.= '</nav>'; |
| 1430 |
|
| 1431 |
return $output; |
| 1432 |
} |
| 1433 |
|
| 1434 |
function wdk_viewe($content) { |
| 1435 |
// @codingStandardsIgnoreStart |
| 1436 |
echo wp_kses_post($content); // WPCS: XSS ok, sanitization ok. |
| 1437 |
// @codingStandardsIgnoreEnd |
| 1438 |
} |
| 1439 |
|
| 1440 |
|
| 1441 |
if(!function_exists('wdk_search_fields_toggle')){ |
| 1442 |
function wdk_search_fields_toggle ($class_add = NULL){ |
| 1443 |
static $wdk_visible_filters = 0; |
| 1444 |
global $wdk_visible_filters_limit; |
| 1445 |
global $wdk_button_search_defined; |
| 1446 |
global $wdk_enable_search_fields_toggle; |
| 1447 |
global $wdk_activate_more; |
| 1448 |
|
| 1449 |
if(!$wdk_enable_search_fields_toggle) return false; |
| 1450 |
|
| 1451 |
global $wdk_search_fields_toggle_reset; |
| 1452 |
if($wdk_search_fields_toggle_reset) { |
| 1453 |
$wdk_visible_filters = 0; |
| 1454 |
$wdk_search_fields_toggle_reset = false; |
| 1455 |
} |
| 1456 |
|
| 1457 |
$wdk_visible_filters++; |
| 1458 |
|
| 1459 |
if($wdk_activate_more || (!empty($wdk_visible_filters_limit) && !$wdk_button_search_defined && $wdk_visible_filters == $wdk_visible_filters_limit)){ |
| 1460 |
$wdk_button_search_defined=true; |
| 1461 |
$wdk_activate_more = false; |
| 1462 |
|
| 1463 |
global $wdk_text_search_button; |
| 1464 |
if(empty($wdk_text_search_button)) |
| 1465 |
$wdk_text_search_button = esc_html__('Search','wpdirectorykit'); |
| 1466 |
|
| 1467 |
global $wdk_text_more_button; |
| 1468 |
if(empty($wdk_text_more_button)) |
| 1469 |
$wdk_text_more_button = esc_html__('More','wpdirectorykit'); |
| 1470 |
|
| 1471 |
$form_closed = 'display: none;'; |
| 1472 |
if(isset($_GET['wdk_search_additional_opened']) && wmvc_xss_clean($_GET['wdk_search_additional_opened']) == 1) { |
| 1473 |
$form_closed = ''; |
| 1474 |
} |
| 1475 |
|
| 1476 |
?> |
| 1477 |
<div class="wdk-col wdk-col-btns"> |
| 1478 |
<div class="wdk-field wdk-field-btn"> |
| 1479 |
<div class="wdk-field-group wdk-field-group-additional"> |
| 1480 |
<button id="wdk-search-additional" type="button" class="wdk-search-additional-btn"><?php echo esc_html($wdk_text_more_button); ?><i class="wdk-toggle-icon"></i></button> |
| 1481 |
<input type='checkbox' style="display: none !important" value='1' name='wdk_search_additional_opened' /> |
| 1482 |
</div> |
| 1483 |
<div class="wdk-field-group wdk-field-group-search"> |
| 1484 |
<button id="wdk-start-primary" type="submit" class="wdk-search-start wdk-click-load-animation"> <?php echo esc_html($wdk_text_search_button);?> <i class="fa fa-spinner fa-spin fa-ajax-indicator" style="display: none;"></i> </button> |
| 1485 |
<?php if(function_exists('run_wdk_save_search') && get_option('wdk_save_search_show_on_searchform')):?> |
| 1486 |
<div class="section-widget-control right"> |
| 1487 |
<a class="wdk-c-btn wdk-c-edit wdk-save-search-button" href="#" data-url="<?php echo esc_url(admin_url('admin-ajax.php')); ?>" title="<?php echo esc_attr_e('Save Search', 'selio'); ?>" target="_blank"> |
| 1488 |
<i class="fas fa-save" aria-hidden="true"></i> |
| 1489 |
<i class="fa fa-spinner fa-spin fa-ajax-indicator"></i> |
| 1490 |
</a> |
| 1491 |
</div> |
| 1492 |
<?php endif;?> |
| 1493 |
</div> |
| 1494 |
</div> |
| 1495 |
</div> |
| 1496 |
<div id='wdk-form-additional' class="wdk-col" style="<?php echo esc_attr($form_closed) ;?>"> |
| 1497 |
<div class="wdk-row"> |
| 1498 |
<?php |
| 1499 |
} |
| 1500 |
} |
| 1501 |
} |
| 1502 |
|
| 1503 |
|
| 1504 |
/* |
| 1505 |
* @param $filter_ids string|array, included ids, what will be visible, other skiped, if set 1_fetch_child, where 1 is category_id, will be detected all childs and filtered, for visible |
| 1506 |
* |
| 1507 |
*/ |
| 1508 |
if ( ! function_exists('wdk_treefield_option')) |
| 1509 |
{ |
| 1510 |
function wdk_treefield_option($name = '', $table=NULL, $selected = NULL, |
| 1511 |
$column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE) |
| 1512 |
{ |
| 1513 |
$WMVC = &wdk_get_instance(); |
| 1514 |
|
| 1515 |
if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids); |
| 1516 |
|
| 1517 |
static $counter = 0; |
| 1518 |
|
| 1519 |
$model_name = $table; |
| 1520 |
if($table == 'calendar_listing_m') |
| 1521 |
$model_name = 'listing_m'; |
| 1522 |
|
| 1523 |
$table_name = str_replace('_m', '', $table); |
| 1524 |
|
| 1525 |
$attribute_id = 'id'.$table_name; |
| 1526 |
|
| 1527 |
if($table_name == 'icons_list') { |
| 1528 |
|
| 1529 |
} else { |
| 1530 |
$WMVC->model($model_name); |
| 1531 |
$attribute_id = $WMVC ->$model_name->_primary_key; |
| 1532 |
$selected = (int) $selected; |
| 1533 |
} |
| 1534 |
|
| 1535 |
if(empty($selected)) |
| 1536 |
$selected=''; |
| 1537 |
|
| 1538 |
$form = '<input name="'.$name.'" value="'.$selected.'" class="wdk-hidden" type="text" id="wdktreeelem'.$counter.'" readonly/>'; |
| 1539 |
|
| 1540 |
$skip_id = ''; |
| 1541 |
//load javascript library |
| 1542 |
if($counter==0) |
| 1543 |
{ |
| 1544 |
wp_enqueue_script('wdk-treefield'); |
| 1545 |
wp_enqueue_style('wdk-treefield'); |
| 1546 |
} |
| 1547 |
?> |
| 1548 |
<script> |
| 1549 |
jQuery(document).ready(function($) { |
| 1550 |
$('#wdktreeelem<?php echo esc_js($counter);?>:not(.init)').wdkTreefield({ |
| 1551 |
ajax_url: '<?php echo admin_url('admin-ajax.php'); ?>', |
| 1552 |
ajax_param: { |
| 1553 |
"page": 'wdk_frontendajax', |
| 1554 |
"function": 'treefieldid', |
| 1555 |
"action": 'wdk_public_action', |
| 1556 |
"table": '<?php echo esc_js($table); ?>', |
| 1557 |
"filter_ids": '<?php echo esc_js($filter_ids); ?>', |
| 1558 |
"start_id": '<?php if(!empty($filter_ids)) esc_js($selected); else echo ""; ?>', |
| 1559 |
"empty_value": '<?php echo esc_js($empty_value); ?>', |
| 1560 |
"user_check": '<?php echo esc_js($user_check); ?>' |
| 1561 |
}, |
| 1562 |
attribute_id: '<?php echo esc_js($attribute_id); ?>', |
| 1563 |
language_id: '<?php echo esc_js($language_id); ?>', |
| 1564 |
attribute_value: '<?php echo esc_js($column); ?>', |
| 1565 |
skip_id: '<?php echo esc_js($skip_id); ?>', |
| 1566 |
empty_value: ' - ', |
| 1567 |
text_search: '<?php esc_html_e('Search term', 'wpdirectorykit');?>', |
| 1568 |
text_no_results: '<?php esc_html_e('No results found', 'wpdirectorykit');?>', |
| 1569 |
callback_selected: function(key) { |
| 1570 |
$('#wdktreeelem<?php echo esc_js($counter);?>').trigger("change"); |
| 1571 |
} |
| 1572 |
}).addClass('init'); |
| 1573 |
}); |
| 1574 |
</script> |
| 1575 |
<?php |
| 1576 |
$counter++; |
| 1577 |
return $form; |
| 1578 |
} |
| 1579 |
} |
| 1580 |
|
| 1581 |
/* |
| 1582 |
* @param $filter_ids string|array, included ids, what will be visible, other skiped, if set 1_fetch_child, where 1 is category_id, will be detected all childs and filtered, for visible |
| 1583 |
* |
| 1584 |
*/ |
| 1585 |
if ( ! function_exists('wdk_treefield_option_checkboxes')) |
| 1586 |
{ |
| 1587 |
function wdk_treefield_option_checkboxes($name = '', $table=NULL, $selected = NULL, |
| 1588 |
$column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE) |
| 1589 |
{ |
| 1590 |
$WMVC = &wdk_get_instance(); |
| 1591 |
|
| 1592 |
if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids); |
| 1593 |
|
| 1594 |
static $counter = 0; |
| 1595 |
|
| 1596 |
$model_name = $table; |
| 1597 |
|
| 1598 |
$table_name = str_replace('_m', '', $table); |
| 1599 |
|
| 1600 |
$attribute_id = 'id'.$table_name; |
| 1601 |
|
| 1602 |
|
| 1603 |
$WMVC->model($model_name); |
| 1604 |
$attribute_id = $WMVC ->$model_name->_primary_key; |
| 1605 |
|
| 1606 |
$values = ''; |
| 1607 |
if(!empty($selected)){ |
| 1608 |
$ids = array(); |
| 1609 |
|
| 1610 |
if(is_string($selected) && strpos($selected, ',') !== FALSE){ |
| 1611 |
$val_selected = explode(',', $selected); |
| 1612 |
} elseif(is_string($selected)){ |
| 1613 |
$val_selected = array($selected); |
| 1614 |
} |
| 1615 |
|
| 1616 |
foreach($val_selected as $selected_item) { |
| 1617 |
if(!empty($selected_item) && is_intval($selected_item)) { |
| 1618 |
$ids [] = $selected_item; |
| 1619 |
} |
| 1620 |
} |
| 1621 |
|
| 1622 |
/* where in */ |
| 1623 |
if(!empty($ids)){ |
| 1624 |
$WMVC->db->select($WMVC->$table->_table_name.'.*'); |
| 1625 |
$WMVC->db->where($WMVC->$table->_table_name.'.'.$WMVC->$table->_primary_key.' IN(' . implode(',', $ids) . ')', null, false); |
| 1626 |
$WMVC->db->order_by('FIELD('.$WMVC->$table->_table_name.'.'.$WMVC->$table->_primary_key.', '. implode(',', $ids) . ')'); |
| 1627 |
|
| 1628 |
$results = $WMVC->$table->get(); |
| 1629 |
foreach ($results as $item) { |
| 1630 |
if($item) { |
| 1631 |
$values .= wmvc_show_data($column, $item, false, TRUE, TRUE).','; |
| 1632 |
} |
| 1633 |
} |
| 1634 |
$values = substr($values,0,-1); |
| 1635 |
|
| 1636 |
if(strlen($values)>23) { |
| 1637 |
$values = substr($values,0,20).'...'; |
| 1638 |
} |
| 1639 |
} |
| 1640 |
} |
| 1641 |
|
| 1642 |
if(empty($values)) { |
| 1643 |
$values = $empty_value; |
| 1644 |
} |
| 1645 |
|
| 1646 |
$form = '<input name="'.$name.'" value="'.esc_html($selected).'" data-placehoder="'.esc_html($values).'" class="wdk-hidden" type="text" id="wdktreeelem_checkbox'.$counter.'" readonly/>'; |
| 1647 |
|
| 1648 |
$skip_id = ''; |
| 1649 |
//load javascript library |
| 1650 |
if($counter==0) |
| 1651 |
{ |
| 1652 |
wp_enqueue_script('wdk-treefield'); |
| 1653 |
wp_enqueue_style('wdk-treefield'); |
| 1654 |
} |
| 1655 |
?> |
| 1656 |
<script> |
| 1657 |
jQuery(document).ready(function($) { |
| 1658 |
$('#wdktreeelem_checkbox<?php echo esc_js($counter);?>:not(.init)').wdkTreefieldCheckboxes({ |
| 1659 |
ajax_url: '<?php echo admin_url('admin-ajax.php'); ?>', |
| 1660 |
ajax_param: { |
| 1661 |
"page": 'wdk_frontendajax', |
| 1662 |
"function": 'treefieldid_checkboxes', |
| 1663 |
"action": 'wdk_public_action', |
| 1664 |
"table": '<?php echo esc_js($table); ?>', |
| 1665 |
"filter_ids": '<?php echo esc_js($filter_ids); ?>', |
| 1666 |
"empty_value": '<?php echo esc_js($empty_value); ?>', |
| 1667 |
"user_check": '<?php echo esc_js($user_check); ?>', |
| 1668 |
}, |
| 1669 |
selected: '<?php echo esc_js($selected); ?>', |
| 1670 |
attribute_id: '<?php echo esc_js($attribute_id); ?>', |
| 1671 |
language_id: '<?php echo esc_js($language_id); ?>', |
| 1672 |
attribute_value: '<?php echo esc_js($column); ?>', |
| 1673 |
skip_id: '<?php echo esc_js($skip_id); ?>', |
| 1674 |
empty_value: ' - ', |
| 1675 |
text_search: '<?php esc_html_e('Search term', 'wpdirectorykit');?>', |
| 1676 |
text_no_results: '<?php esc_html_e('No results found', 'wpdirectorykit');?>', |
| 1677 |
callback_selected: function(key) { |
| 1678 |
$('#wdktreeelem_checkbox<?php echo esc_js($counter);?>').trigger("change"); |
| 1679 |
} |
| 1680 |
}).addClass('init'); |
| 1681 |
}); |
| 1682 |
</script> |
| 1683 |
<?php |
| 1684 |
$counter++; |
| 1685 |
return $form; |
| 1686 |
} |
| 1687 |
} |
| 1688 |
|
| 1689 |
if ( ! function_exists('wdk_filter_decimal')) |
| 1690 |
{ |
| 1691 |
function wdk_filter_decimal($string = '') |
| 1692 |
{ |
| 1693 |
if(substr($string, -3, 3) === ".00") { |
| 1694 |
return substr($string, 0, -3); |
| 1695 |
} |
| 1696 |
|
| 1697 |
return $string; |
| 1698 |
} |
| 1699 |
} |
| 1700 |
|
| 1701 |
if ( ! function_exists('wdk_is_date')) |
| 1702 |
{ |
| 1703 |
function wdk_is_date($date, $format = 'Y-m-d H:i:s') |
| 1704 |
{ |
| 1705 |
|
| 1706 |
/* check is date on strtotime */ |
| 1707 |
if((bool)strtotime($date)){ |
| 1708 |
return true; |
| 1709 |
} |
| 1710 |
|
| 1711 |
/* check is date from argument */ |
| 1712 |
$d = \DateTime::createFromFormat($format, $date); |
| 1713 |
if($d) { |
| 1714 |
return true; |
| 1715 |
} |
| 1716 |
|
| 1717 |
/* check is date from wp date and time */ |
| 1718 |
$d = \DateTime::createFromFormat(get_option('date_format').' '.get_option('time_format'), $date); |
| 1719 |
if($d) { |
| 1720 |
return true; |
| 1721 |
} |
| 1722 |
|
| 1723 |
/* check is date from wp date */ |
| 1724 |
$d = \DateTime::createFromFormat(get_option('date_format'), $date); |
| 1725 |
if($d) { |
| 1726 |
return true; |
| 1727 |
} |
| 1728 |
|
| 1729 |
/* try with default */ |
| 1730 |
if('Y-m-d H:i:s' != $format) { |
| 1731 |
$d = \DateTime::createFromFormat('Y-m-d H:i:s', $date); |
| 1732 |
if($d) { |
| 1733 |
return true; |
| 1734 |
} |
| 1735 |
|
| 1736 |
$d = \DateTime::createFromFormat('Y-m-d', $date); |
| 1737 |
if($d) { |
| 1738 |
return true; |
| 1739 |
} |
| 1740 |
} |
| 1741 |
|
| 1742 |
/* issue with pm/am inside date, example bug format like "2023 01 19 pm8:06" => 'Y n j ag:i' */ |
| 1743 |
$format = get_option('date_format').' '.get_option('time_format'); |
| 1744 |
if(strpos($format, 'a') !== FALSE) { |
| 1745 |
$format = str_replace('a', '',$format).' a'; |
| 1746 |
if(strpos($date, 'am') !== FALSE) { |
| 1747 |
$date = str_replace('am', '',$date).' am'; |
| 1748 |
} |
| 1749 |
if(strpos($date, 'pm') !== FALSE) { |
| 1750 |
$date = str_replace('pm', '',$date).' pm'; |
| 1751 |
} |
| 1752 |
$d = \DateTime::createFromFormat($format, $date); |
| 1753 |
if($d) { |
| 1754 |
return true; |
| 1755 |
} |
| 1756 |
} |
| 1757 |
|
| 1758 |
return false; |
| 1759 |
} |
| 1760 |
} |
| 1761 |
|
| 1762 |
|
| 1763 |
if ( ! function_exists('wdk_normalize_date_db')) |
| 1764 |
{ |
| 1765 |
/** |
| 1766 |
* Convert date to db format, from wp format |
| 1767 |
* @param string $date Date in string |
| 1768 |
* @param string $format Special format |
| 1769 |
* @param string $format Special format |
| 1770 |
* @param string $return_format return date format |
| 1771 |
* @return string date in format Y-m-d H:i:s |
| 1772 |
*/ |
| 1773 |
function wdk_normalize_date_db($date, $format = 'Y-m-d H:i:s', $return_format = 'Y-m-d H:i:s') |
| 1774 |
{ |
| 1775 |
/* check is date on strtotime */ |
| 1776 |
if((bool)strtotime($date)){ |
| 1777 |
return date($return_format, strtotime($date)); |
| 1778 |
} |
| 1779 |
|
| 1780 |
/* check is date from argument */ |
| 1781 |
$d = \DateTime::createFromFormat($format, $date); |
| 1782 |
if($d) { |
| 1783 |
return $d->format($return_format); |
| 1784 |
} |
| 1785 |
|
| 1786 |
/* check is date from wp date and time */ |
| 1787 |
$d = \DateTime::createFromFormat(get_option('date_format').' '.get_option('time_format'), $date); |
| 1788 |
if($d) { |
| 1789 |
return $d->format($return_format); |
| 1790 |
} |
| 1791 |
|
| 1792 |
/* check is date from wp date */ |
| 1793 |
$d = \DateTime::createFromFormat(get_option('date_format'), $date); |
| 1794 |
if($d) { |
| 1795 |
return $d->format($return_format); |
| 1796 |
} |
| 1797 |
|
| 1798 |
/* try with default */ |
| 1799 |
if('Y-m-d H:i:s' != $format) { |
| 1800 |
$d = \DateTime::createFromFormat('Y-m-d H:i:s', $date); |
| 1801 |
if($d) { |
| 1802 |
return $d->format($return_format); |
| 1803 |
} |
| 1804 |
|
| 1805 |
$d = \DateTime::createFromFormat('Y-m-d', $date); |
| 1806 |
if($d) { |
| 1807 |
return $d->format($return_format); |
| 1808 |
} |
| 1809 |
} |
| 1810 |
|
| 1811 |
/* issue with pm/am inside date, example bug format like "2023 01 19 pm8:06" => 'Y n j ag:i' */ |
| 1812 |
$format = get_option('date_format').' '.get_option('time_format'); |
| 1813 |
if(strpos($format, 'a') !== FALSE) { |
| 1814 |
$format = str_replace('a', '',$format).' a'; |
| 1815 |
if(strpos($date, 'am') !== FALSE) { |
| 1816 |
$date = str_replace('am', '',$date).' am'; |
| 1817 |
} |
| 1818 |
if(strpos($date, 'pm') !== FALSE) { |
| 1819 |
$date = str_replace('pm', '',$date).' pm'; |
| 1820 |
} |
| 1821 |
$d = \DateTime::createFromFormat($format, $date); |
| 1822 |
if($d) { |
| 1823 |
return $d->format($return_format); |
| 1824 |
} |
| 1825 |
} |
| 1826 |
|
| 1827 |
return false; |
| 1828 |
} |
| 1829 |
} |
| 1830 |
|
| 1831 |
if ( ! function_exists('wdk_url_suffix')) |
| 1832 |
{ |
| 1833 |
function wdk_url_suffix($base_url, $extension_url="") |
| 1834 |
{ |
| 1835 |
if(substr($base_url, -1) == '?'){ |
| 1836 |
$base_url .=''; |
| 1837 |
} elseif(strpos($base_url,'?') !== FALSE){ |
| 1838 |
$base_url .='&'; |
| 1839 |
} else { |
| 1840 |
$base_url .='?'; |
| 1841 |
} |
| 1842 |
return $base_url.$extension_url; |
| 1843 |
} |
| 1844 |
} |
| 1845 |
|
| 1846 |
/** |
| 1847 |
* Insert an attachment from an URL address. |
| 1848 |
* |
| 1849 |
* @param String $url |
| 1850 |
* @param Int $parent_post_id |
| 1851 |
* @return Int Attachment ID |
| 1852 |
*/ |
| 1853 |
function wdk_insert_attachment_from_url($url, $parent_post_id = null) { |
| 1854 |
|
| 1855 |
if( !class_exists( 'WP_Http' ) ) |
| 1856 |
include_once( ABSPATH . WPINC . '/class-http.php' ); |
| 1857 |
|
| 1858 |
$http = new WP_Http(); |
| 1859 |
$response = $http->request( $url ); |
| 1860 |
if( is_wp_error($response) || $response['response']['code'] != 200 ) { |
| 1861 |
return false; |
| 1862 |
} |
| 1863 |
|
| 1864 |
$upload = wp_upload_bits( basename($url), null, $response['body'] ); |
| 1865 |
if( !empty( $upload['error'] ) ) { |
| 1866 |
return false; |
| 1867 |
} |
| 1868 |
|
| 1869 |
$file_path = $upload['file']; |
| 1870 |
$file_name = basename( $file_path ); |
| 1871 |
$file_type = wp_check_filetype( $file_name, null ); |
| 1872 |
$attachment_title = sanitize_file_name( pathinfo( $file_name, PATHINFO_FILENAME ) ); |
| 1873 |
$wp_upload_dir = wp_upload_dir(); |
| 1874 |
|
| 1875 |
$post_info = array( |
| 1876 |
'guid' => $wp_upload_dir['url'] . '/' . $file_name, |
| 1877 |
'post_mime_type' => $file_type['type'], |
| 1878 |
'post_title' => $attachment_title, |
| 1879 |
'post_content' => '', |
| 1880 |
'post_status' => 'inherit', |
| 1881 |
); |
| 1882 |
|
| 1883 |
// Create the attachment |
| 1884 |
$attach_id = wp_insert_attachment( $post_info, $file_path, $parent_post_id ); |
| 1885 |
|
| 1886 |
// Include image.php |
| 1887 |
require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
| 1888 |
|
| 1889 |
// Define attachment metadata |
| 1890 |
$attach_data = wp_generate_attachment_metadata( $attach_id, $file_path ); |
| 1891 |
|
| 1892 |
// Assign metadata to attachment |
| 1893 |
wp_update_attachment_metadata( $attach_id, $attach_data ); |
| 1894 |
|
| 1895 |
return $attach_id; |
| 1896 |
|
| 1897 |
} |
| 1898 |
|
| 1899 |
if(!function_exists('wdk_jsdateformat')) { |
| 1900 |
function wdk_jsdateformat($format = '') { |
| 1901 |
$date_specific = array( |
| 1902 |
// Day |
| 1903 |
'd' => 'dd', |
| 1904 |
'D' => 'D', |
| 1905 |
'j' => 'd', |
| 1906 |
'l' => 'DD', |
| 1907 |
'N' => '', |
| 1908 |
'S' => '', |
| 1909 |
'w' => '', |
| 1910 |
'z' => 'o', |
| 1911 |
// Week |
| 1912 |
'W' => '', |
| 1913 |
// Month |
| 1914 |
'F' => 'MM', |
| 1915 |
'm' => 'mm', |
| 1916 |
'M' => 'M', |
| 1917 |
'n' => 'm', |
| 1918 |
't' => '', |
| 1919 |
// Year |
| 1920 |
'L' => '', |
| 1921 |
'o' => '', |
| 1922 |
'y' => 'y', |
| 1923 |
'Y' => 'yy', |
| 1924 |
// Time |
| 1925 |
'a' => '', |
| 1926 |
'A' => '', |
| 1927 |
'B' => '', |
| 1928 |
'g' => '', |
| 1929 |
'G' => '', |
| 1930 |
'h' => '', |
| 1931 |
'H' => '', |
| 1932 |
'i' => '', |
| 1933 |
's' => '', |
| 1934 |
'u' => '' |
| 1935 |
); |
| 1936 |
return str_replace(array_keys($date_specific), array_values($date_specific), $format); |
| 1937 |
} |
| 1938 |
|
| 1939 |
} |
| 1940 |
|
| 1941 |
function wdk_current_url() |
| 1942 |
{ |
| 1943 |
global $wp; |
| 1944 |
return add_query_arg( $wp->query_vars, home_url( $wp->request ) ); |
| 1945 |
} |
| 1946 |
|
| 1947 |
if(!function_exists('wdk_generate_profile_permalink')) { |
| 1948 |
/** |
| 1949 |
* Insert user id and return link on user profile page |
| 1950 |
* |
| 1951 |
* @return Int user ID |
| 1952 |
*/ |
| 1953 |
|
| 1954 |
function wdk_generate_profile_permalink($profile = array()) |
| 1955 |
{ |
| 1956 |
|
| 1957 |
$profile_slug = ''; |
| 1958 |
if(wmvc_show_data('user_login', $profile, false)){ |
| 1959 |
$profile_slug = wmvc_show_data('user_login', $profile); |
| 1960 |
} else if(is_intval($profile)){ |
| 1961 |
$profile_data = get_userdata($profile); |
| 1962 |
if(wmvc_show_data('user_login', $profile_data, false)){ |
| 1963 |
$profile_slug = wmvc_show_data('user_login', $profile_data); |
| 1964 |
} else { |
| 1965 |
$profile_slug = $profile; |
| 1966 |
} |
| 1967 |
} |
| 1968 |
|
| 1969 |
$user_profile_page = get_option('wdk_membership_profile_preview_page'); |
| 1970 |
if(!$user_profile_page) { |
| 1971 |
return '#'; |
| 1972 |
} |
| 1973 |
// for polylang to detect translated page version |
| 1974 |
if(function_exists('pll_get_post')) |
| 1975 |
$user_profile_page = pll_get_post($user_profile_page); |
| 1976 |
|
| 1977 |
return wdk_url_suffix(get_permalink($user_profile_page), 'slug='. $profile_slug); |
| 1978 |
} |
| 1979 |
} |
| 1980 |
|
| 1981 |
if(!function_exists('wdk_get_profile_page_id')) { |
| 1982 |
/** |
| 1983 |
* Insert user id and return link on user profile page |
| 1984 |
* |
| 1985 |
* @return Int user ID |
| 1986 |
*/ |
| 1987 |
|
| 1988 |
function wdk_get_profile_page_id() |
| 1989 |
{ |
| 1990 |
global $wp_query; |
| 1991 |
if(get_option('wdk_membership_profile_preview_page') && isset($wp_query->post) && get_option('wdk_membership_profile_preview_page') == $wp_query->post->ID) { |
| 1992 |
if (wmvc_show_data('slug', $_GET, false)) { |
| 1993 |
if(is_intval(wmvc_show_data('slug', $_GET))) { |
| 1994 |
return wmvc_show_data('slug', $_GET); |
| 1995 |
} else { |
| 1996 |
$profile = get_user_by('login',wmvc_show_data('slug', $_GET)); |
| 1997 |
return (wmvc_show_data('ID', $profile, false)) ? wmvc_show_data('ID', $profile, false) : false; |
| 1998 |
} |
| 1999 |
} |
| 2000 |
} |
| 2001 |
|
| 2002 |
return false; |
| 2003 |
} |
| 2004 |
} |
| 2005 |
|
| 2006 |
if(!function_exists('wdk_get_date')) { |
| 2007 |
/** |
| 2008 |
* Return date in format |
| 2009 |
* |
| 2010 |
*/ |
| 2011 |
function wdk_get_date($datetime = NULL, $time = TRUE, $default='timestamp') |
| 2012 |
{ |
| 2013 |
$init_datetime = $datetime; |
| 2014 |
if(is_null($datetime)) |
| 2015 |
{ |
| 2016 |
if($default == 'timestamp') |
| 2017 |
{ |
| 2018 |
$datetime = current_time('timestamp'); |
| 2019 |
} |
| 2020 |
else |
| 2021 |
{ |
| 2022 |
return $default; |
| 2023 |
} |
| 2024 |
} |
| 2025 |
else if(!is_numeric($datetime)) |
| 2026 |
{ |
| 2027 |
$datetime = strtotime($datetime); |
| 2028 |
} |
| 2029 |
|
| 2030 |
$date_format = get_option('date_format'); |
| 2031 |
|
| 2032 |
$time_format = ($time && strpos($init_datetime, '00:00:00')===FALSE) ? get_option('time_format') : ''; |
| 2033 |
|
| 2034 |
$date = date_i18n("{$date_format} {$time_format}", $datetime); |
| 2035 |
return $date; |
| 2036 |
} |
| 2037 |
} |
| 2038 |
|
| 2039 |
if(!function_exists('wdk_login_url')) { |
| 2040 |
/** |
| 2041 |
* Return date in format |
| 2042 |
* @param string|url redirect url |
| 2043 |
* @param string custom_message, showed on login form like alert, visible only on wdk login form |
| 2044 |
*/ |
| 2045 |
function wdk_login_url($url_redirect = NULL, $custom_message = '') |
| 2046 |
{ |
| 2047 |
$url = wp_login_url($url_redirect); |
| 2048 |
|
| 2049 |
if(get_option('wdk_membership_login_page')){ |
| 2050 |
$url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')), 'redirect_to='. urlencode($url_redirect).'&custom_message='. urlencode($custom_message)); |
| 2051 |
} |
| 2052 |
|
| 2053 |
return $url; |
| 2054 |
} |
| 2055 |
} |
| 2056 |
|
| 2057 |
if(!function_exists('wdk_mail')) { |
| 2058 |
/** |
| 2059 |
* Return date in format |
| 2060 |
* @param string|url redirect url |
| 2061 |
*/ |
| 2062 |
function wdk_mail( $email_to, $subject = '', $data = array(), $layout = 'default', $email_from = '', $attachments = array(), $reply_to = '') |
| 2063 |
{ |
| 2064 |
$WMVC = &wdk_get_instance(); |
| 2065 |
|
| 2066 |
$ret = false; |
| 2067 |
if(empty($email_from)) |
| 2068 |
$email_from = get_bloginfo('admin_email'); |
| 2069 |
|
| 2070 |
if(empty($subject)) |
| 2071 |
$subject = __("New message", "wpdirectorykit"); |
| 2072 |
|
| 2073 |
$headers = array('Content-Type: text/html; charset=UTF-8'); |
| 2074 |
$headers[] = 'From: '.$email_from; |
| 2075 |
|
| 2076 |
if(!empty($reply_to)) { |
| 2077 |
$headers[] = 'Reply-To: '.$reply_to; |
| 2078 |
} else { |
| 2079 |
$headers[] = 'Reply-To: '.$email_from; |
| 2080 |
} |
| 2081 |
|
| 2082 |
$data['subject'] = $subject; |
| 2083 |
|
| 2084 |
$message = $WMVC->view('email/'.$layout, $data, FALSE); |
| 2085 |
$ret = wp_mail( $email_to, $subject, $message, $headers, $attachments ); |
| 2086 |
|
| 2087 |
return $ret; |
| 2088 |
} |
| 2089 |
} |
| 2090 |
|
| 2091 |
if(!function_exists('wdk_show_data')) { |
| 2092 |
function wdk_show_data($field_name, &$db_value = NULL, $default = '', $xss_clean = TRUE, $skip_post = FALSE) |
| 2093 |
{ |
| 2094 |
if(!$skip_post && isset($_POST[$field_name])) |
| 2095 |
{ |
| 2096 |
if($xss_clean === FALSE) |
| 2097 |
return stripslashes($_POST[$field_name]); |
| 2098 |
|
| 2099 |
return wmvc_xss_clean(stripslashes($_POST[$field_name])); |
| 2100 |
} |
| 2101 |
|
| 2102 |
|
| 2103 |
if(is_array($db_value)) |
| 2104 |
{ |
| 2105 |
if(isset($db_value[$field_name])) |
| 2106 |
{ |
| 2107 |
if($xss_clean === FALSE) |
| 2108 |
return $db_value[$field_name]; |
| 2109 |
|
| 2110 |
return wmvc_xss_clean($db_value[$field_name]); |
| 2111 |
} |
| 2112 |
else |
| 2113 |
{ |
| 2114 |
return $default; |
| 2115 |
} |
| 2116 |
} |
| 2117 |
|
| 2118 |
if(is_object($db_value)) |
| 2119 |
{ |
| 2120 |
if(isset($db_value->$field_name)) |
| 2121 |
{ |
| 2122 |
if($xss_clean === FALSE) |
| 2123 |
return $db_value->$field_name; |
| 2124 |
|
| 2125 |
return wmvc_xss_clean($db_value->$field_name); |
| 2126 |
} |
| 2127 |
else |
| 2128 |
{ |
| 2129 |
return $default; |
| 2130 |
} |
| 2131 |
} |
| 2132 |
|
| 2133 |
if(!empty($db_value)) |
| 2134 |
{ |
| 2135 |
if($xss_clean === FALSE) |
| 2136 |
return $db_value; |
| 2137 |
|
| 2138 |
return wmvc_xss_clean($db_value); |
| 2139 |
} |
| 2140 |
|
| 2141 |
if($xss_clean === FALSE) |
| 2142 |
return $default; |
| 2143 |
|
| 2144 |
return wmvc_xss_clean($default); |
| 2145 |
} |
| 2146 |
} |
| 2147 |
|
| 2148 |
|
| 2149 |
if (!function_exists('wdk_input_checked')) |
| 2150 |
{ |
| 2151 |
function wdk_input_checked($field_id, $db_data, $value = 1) |
| 2152 |
{ |
| 2153 |
|
| 2154 |
if(wmvc_show_data($field_id, $db_data, false) && wmvc_show_data($field_id, $db_data) == $value) |
| 2155 |
{ |
| 2156 |
return 'checked'; |
| 2157 |
} |
| 2158 |
|
| 2159 |
return ''; |
| 2160 |
} |
| 2161 |
} |
| 2162 |
|
| 2163 |
function wdk_upload_file($field_name, $file_id) |
| 2164 |
{ |
| 2165 |
static $media_element_counter = 0; |
| 2166 |
|
| 2167 |
$media_element_counter++; |
| 2168 |
|
| 2169 |
$img_field = $field_name.'_'.$media_element_counter; |
| 2170 |
|
| 2171 |
wp_register_script( 'wpmediaelement_file', WPDIRECTORYKIT_URL . 'admin/js/jquery.wpmediaelement_file.js', array( 'jquery' ), false, false ); |
| 2172 |
wp_enqueue_script( 'wpmediaelement_file' ); |
| 2173 |
wp_enqueue_media(); |
| 2174 |
|
| 2175 |
?> |
| 2176 |
<div id="<?php echo esc_attr($field_name); ?>meta-box-id" class="postbox-upload"> |
| 2177 |
<?php |
| 2178 |
// Get WordPress' media upload URL |
| 2179 |
$upload_link = '#'; |
| 2180 |
|
| 2181 |
// Get the file src |
| 2182 |
|
| 2183 |
// Get the file src |
| 2184 |
$your_file_src = get_attached_file(intval( $file_id)); |
| 2185 |
|
| 2186 |
// For convenience, see if the array is valid |
| 2187 |
$you_have_file = false; |
| 2188 |
if($your_file_src) |
| 2189 |
$you_have_file = basename($your_file_src); |
| 2190 |
|
| 2191 |
?> |
| 2192 |
|
| 2193 |
<!-- Your file container, which can be manipulated with js --> |
| 2194 |
<div class="custom-img-container"> |
| 2195 |
<?php if ( $you_have_file ) : ?> |
| 2196 |
<?php echo esc_html($you_have_file); ?> |
| 2197 |
<?php endif; ?> |
| 2198 |
</div> |
| 2199 |
|
| 2200 |
<?php //if(sw_user_in_role('administrator')): ?> |
| 2201 |
<!-- Your add & remove file links --> |
| 2202 |
<p class="hide-if-no-js"> |
| 2203 |
<a class="upload-custom-img <?php if ( $you_have_file ) { echo 'hidden'; } ?>" |
| 2204 |
href="<?php echo esc_url($upload_link) ?>"> |
| 2205 |
<?php echo esc_html__('Select file','wmvc_win') ?> |
| 2206 |
</a> |
| 2207 |
<a class="delete-custom-img <?php if ( ! $you_have_file ) { echo 'hidden'; } ?>" |
| 2208 |
href="#"> |
| 2209 |
<?php echo esc_html__('Remove file','wmvc_win') ?> |
| 2210 |
</a> |
| 2211 |
</p> |
| 2212 |
<?php //endif; ?> |
| 2213 |
|
| 2214 |
<!-- A hidden input to set and post the chosen file id --> |
| 2215 |
<input class="logo_file_id" type="hidden" id="<?php echo esc_html($field_name); ?>" name="<?php echo esc_html($field_name); ?>" value="<?php echo esc_html($file_id); ?>" /> |
| 2216 |
</div> |
| 2217 |
|
| 2218 |
<?php |
| 2219 |
$custom_js =''; |
| 2220 |
$custom_js .=" jQuery(function($) { |
| 2221 |
if( typeof jQuery.fn.wpMediaElementFile == 'function') |
| 2222 |
$('#".esc_js($field_name)."meta-box-id.postbox-upload').wpMediaElementFile(); |
| 2223 |
});"; |
| 2224 |
|
| 2225 |
echo "<script>".$custom_js."</script>"; |
| 2226 |
|
| 2227 |
?> |
| 2228 |
|
| 2229 |
<?php |
| 2230 |
} |
| 2231 |
|
| 2232 |
if ( ! function_exists('wdk_file_extension')) |
| 2233 |
{ |
| 2234 |
function wdk_file_extension($filepath) |
| 2235 |
{ |
| 2236 |
|
| 2237 |
/* filters */ |
| 2238 |
if(strpos($filepath, '?') !== FALSE) { |
| 2239 |
$filepath = $filepath; |
| 2240 |
$filepath = substr($filepath, 0,strpos($filepath, '?')); |
| 2241 |
} |
| 2242 |
if(strpos($filepath, '#') !== FALSE) { |
| 2243 |
$filepath = $filepath; |
| 2244 |
$filepath = substr($filepath, 0,strpos($filepath, '#')); |
| 2245 |
} |
| 2246 |
|
| 2247 |
return substr($filepath, strrpos($filepath, '.')+1); |
| 2248 |
} |
| 2249 |
} |
| 2250 |
|
| 2251 |
if ( ! function_exists('wdk_file_extension_type')) |
| 2252 |
{ |
| 2253 |
/** |
| 2254 |
* Get image type based on extension |
| 2255 |
* |
| 2256 |
* @param string $filepath string path(url) to file with extension |
| 2257 |
* @return string type of file (image,video,docs) |
| 2258 |
*/ |
| 2259 |
function wdk_file_extension_type($filepath = NULL) |
| 2260 |
{ |
| 2261 |
|
| 2262 |
if(in_array(wdk_file_extension($filepath),array('jpg','jpeg','bmp','png','webp'))) { |
| 2263 |
return 'image'; |
| 2264 |
} |
| 2265 |
if(in_array(wdk_file_extension($filepath),array('mp4','mov','flv','mkv','avi','webm'))) { |
| 2266 |
return 'video'; |
| 2267 |
} |
| 2268 |
|
| 2269 |
return 'docs'; |
| 2270 |
} |
| 2271 |
} |
| 2272 |
|
| 2273 |
function wdk_upload_multi_files($field_name, $image_ids='', $texts = array()) |
| 2274 |
{ |
| 2275 |
static $media_element_counter = 0; |
| 2276 |
|
| 2277 |
if(!isset($texts['file_select']))$texts['file_select'] = esc_html__('Select file','wmvc_win'); |
| 2278 |
if(!isset($texts['file_remove']))$texts['file_remove'] = esc_html__('Remove file','wmvc_win'); |
| 2279 |
|
| 2280 |
$media_element_counter++; |
| 2281 |
|
| 2282 |
$img_field = $field_name.'_'.$media_element_counter; |
| 2283 |
|
| 2284 |
wp_register_script( 'wpmediaelement_file', WPDIRECTORYKIT_URL . 'admin/js/jquery.wpmediaelement_file.js', array( 'jquery' ), false, false ); |
| 2285 |
wp_enqueue_script( 'wpmediaelement_file' ); |
| 2286 |
wp_enqueue_media(); |
| 2287 |
|
| 2288 |
wp_enqueue_script( 'wpmediamultiple' ); |
| 2289 |
wp_enqueue_script( 'jquery-ui-mouse' ); |
| 2290 |
wp_enqueue_media(); |
| 2291 |
|
| 2292 |
?> |
| 2293 |
<div id="<?php echo esc_attr($field_name); ?>meta-box-id" class="postbox-upload-multiple"> |
| 2294 |
<?php |
| 2295 |
// Get WordPress' media upload URL |
| 2296 |
$upload_link = '#'; |
| 2297 |
|
| 2298 |
|
| 2299 |
// Get the image src |
| 2300 |
|
| 2301 |
$your_img_src = array(); |
| 2302 |
|
| 2303 |
foreach(explode(',', $image_ids) as $image_id) |
| 2304 |
{ |
| 2305 |
if(is_numeric($image_id)){ |
| 2306 |
$src = wp_get_attachment_url( $image_id, 'full' ); |
| 2307 |
if(!in_array(wdk_file_extension($src),array('jpg','jpeg','bmp','png','webp'))) { |
| 2308 |
if(file_exists(WPDIRECTORYKIT_PATH.'/public/img/filetype/'.wdk_file_extension($src).'.png')) { |
| 2309 |
$src = WPDIRECTORYKIT_URL.'public/img/filetype/'.wdk_file_extension($src).'.png'; |
| 2310 |
} else { |
| 2311 |
$src = WPDIRECTORYKIT_URL.'public/img/filetype/_blank.png'; |
| 2312 |
} |
| 2313 |
} |
| 2314 |
$your_img_src[$image_id] = $src; |
| 2315 |
} |
| 2316 |
} |
| 2317 |
|
| 2318 |
// For convenience, see if the array is valid |
| 2319 |
$you_have_img = count($your_img_src) > 0; |
| 2320 |
?> |
| 2321 |
|
| 2322 |
<!-- Your image container, which can be manipulated with js --> |
| 2323 |
<div class="custom-img-container winter_mvc-media"> |
| 2324 |
<?php if($you_have_img)foreach($your_img_src as $image_id => $img_src) : ?> |
| 2325 |
<div class="winter_mvc-media-card" data-media-id="<?php echo esc_attr($image_id);?>"> |
| 2326 |
<img src="<?php echo esc_html($img_src); ?>" style="object-fit: contain;" alt="<?php echo esc_attr__('thumb', 'wmvc_win');?>" style="max-width:100%;" class="thumbnail"/> |
| 2327 |
<a href="#" class="remove"></a> |
| 2328 |
</div> |
| 2329 |
<?php endforeach; ?> |
| 2330 |
</div> |
| 2331 |
<br style="clear:both;" /> |
| 2332 |
|
| 2333 |
<?php //if(sw_user_in_role('administrator')): ?> |
| 2334 |
<!-- Your add & remove image links --> |
| 2335 |
<p class="hide-if-no-js"> |
| 2336 |
<a class="button button-primary upload-custom-img <?php if ( $you_have_img ) { echo ''; } ?>" |
| 2337 |
href="<?php echo esc_url($upload_link) ?>"> |
| 2338 |
<?php echo esc_html($texts['file_select']) ?> |
| 2339 |
</a> |
| 2340 |
<a class="button button-secondary delete-custom-img <?php if ( ! $you_have_img ) { echo 'hidden'; } ?>" |
| 2341 |
href="#"> |
| 2342 |
<?php echo esc_html($texts['file_remove']) ?> |
| 2343 |
</a> |
| 2344 |
</p> |
| 2345 |
<?php //endif; ?> |
| 2346 |
|
| 2347 |
<!-- A hidden input to set and post the chosen image id --> |
| 2348 |
<input class="logo_image_id" type="hidden" id="<?php echo esc_html(esc_html($field_name)); ?>" name="<?php echo esc_html($field_name); ?>" value="<?php echo esc_html($image_ids); ?>" /> |
| 2349 |
</div> |
| 2350 |
<?php |
| 2351 |
$custom_js =''; |
| 2352 |
$custom_js .=" jQuery(function($) { |
| 2353 |
if( typeof jQuery.fn.wpMediaMultiple == 'function') |
| 2354 |
$('#".esc_js($field_name)."meta-box-id.postbox-upload-multiple').wpMediaMultiple({ |
| 2355 |
frame: { |
| 2356 |
title: '".esc_js(__('Select or Upload Media Of Your Chosen Persuasion','wpdirectorykit'))."', |
| 2357 |
button: '".esc_js(__('Use this media','wpdirectorykit'))."', |
| 2358 |
} |
| 2359 |
}); |
| 2360 |
/* order */ |
| 2361 |
var re_order = function(media_element){ |
| 2362 |
var list_media = ''; |
| 2363 |
media_element.find('.winter_mvc-media-card').each(function(){ |
| 2364 |
if(list_media !='') |
| 2365 |
list_media +=','; |
| 2366 |
|
| 2367 |
list_media += $(this).attr('data-media-id'); |
| 2368 |
}) |
| 2369 |
media_element.closest('.postbox-upload-multiple').find('.logo_image_id').val(list_media); |
| 2370 |
} |
| 2371 |
/* Sort table */ |
| 2372 |
$( '.winter_mvc-media' ).sortable({ |
| 2373 |
update: function(event, ui) { |
| 2374 |
re_order($(this)); |
| 2375 |
} |
| 2376 |
}); |
| 2377 |
/* remove media */ |
| 2378 |
$( '.winter_mvc-media' ).find('.winter_mvc-media-card .remove').on('click', function(e){ |
| 2379 |
e.preventDefault(); |
| 2380 |
var media = $(this).closest('.winter_mvc-media') |
| 2381 |
$(this).closest('.winter_mvc-media-card').remove(); |
| 2382 |
re_order(media) |
| 2383 |
}) |
| 2384 |
}); |
| 2385 |
"; |
| 2386 |
|
| 2387 |
echo "<script>".$custom_js."</script>"; |
| 2388 |
|
| 2389 |
?> |
| 2390 |
|
| 2391 |
<?php |
| 2392 |
} |
| 2393 |
|
| 2394 |
|
| 2395 |
if(!function_exists('wdk_access_check')) { |
| 2396 |
/** |
| 2397 |
* Generate listing card html |
| 2398 |
* |
| 2399 |
* @param array $listing The listing data. |
| 2400 |
* @param array $settings The settings. |
| 2401 |
* @param bool $json_output Encode for json, default false |
| 2402 |
* @param string $html Html for sprintf(), where |
| 2403 |
* %1$s - content |
| 2404 |
* @return string |
| 2405 |
*/ |
| 2406 |
function wdk_access_check($model_name, $item_id, $user_id=NULL, $method='edit') { |
| 2407 |
|
| 2408 |
if(!empty($item_id) && !is_numeric($item_id)) |
| 2409 |
exit('Issue with ID'); |
| 2410 |
|
| 2411 |
if (in_array($model_name, array('reviews_m','reviews_type_m','reviews_option_m','reviews_data_m'))) { |
| 2412 |
global $Winter_MVC_wdk_reviews; |
| 2413 |
$WMVC = $Winter_MVC_wdk_reviews; |
| 2414 |
}elseif(in_array($model_name,array('package_m','payment_m'))) { |
| 2415 |
global $Winter_MVC_wdk_payments; |
| 2416 |
$WMVC = $Winter_MVC_wdk_payments; |
| 2417 |
}elseif(in_array($model_name,array('favorite_m','favoritecategory_m'))) { |
| 2418 |
global $Winter_MVC_wdk_favorites; |
| 2419 |
$WMVC = $Winter_MVC_wdk_favorites; |
| 2420 |
}elseif(in_array($model_name,array('currency_m'))) { |
| 2421 |
global $Winter_MVC_wdk_currency; |
| 2422 |
$WMVC = $Winter_MVC_wdk_currency; |
| 2423 |
}elseif(in_array($model_name,array('calendar_m','price_m','reservation_m'))) { |
| 2424 |
global $Winter_MVC_wdk_bookings; |
| 2425 |
$WMVC = $Winter_MVC_wdk_bookings; |
| 2426 |
}elseif(in_array($model_name,array('save_search_m'))) { |
| 2427 |
global $Winter_MVC_wdk_save_search; |
| 2428 |
$WMVC = $Winter_MVC_wdk_save_search; |
| 2429 |
}elseif(in_array($model_name,array('messageschat_m'))) { |
| 2430 |
global $Winter_MVC_wdk_messages_chat; |
| 2431 |
$WMVC = $Winter_MVC_wdk_messages_chat; |
| 2432 |
} else { |
| 2433 |
$WMVC = &wdk_get_instance(); |
| 2434 |
} |
| 2435 |
|
| 2436 |
if(empty($user_id)) |
| 2437 |
$user_id = get_current_user_id(); |
| 2438 |
|
| 2439 |
if(wmvc_user_in_role('administrator')) { |
| 2440 |
return true; |
| 2441 |
} |
| 2442 |
|
| 2443 |
if(substr($model_name,-2,2) == '_m') |
| 2444 |
{ |
| 2445 |
// its model |
| 2446 |
$WMVC->model($model_name); |
| 2447 |
|
| 2448 |
if(empty($item_id) || $WMVC->$model_name->is_related($item_id, $user_id, $method)) |
| 2449 |
{ |
| 2450 |
// User is related |
| 2451 |
return true; |
| 2452 |
} |
| 2453 |
else |
| 2454 |
{ |
| 2455 |
//echo $CI->db->last_query(); |
| 2456 |
exit('Access denied ROLES RELATED'); |
| 2457 |
} |
| 2458 |
} |
| 2459 |
else |
| 2460 |
{ |
| 2461 |
return true; |
| 2462 |
} |
| 2463 |
|
| 2464 |
exit('Access denied ROLES'); |
| 2465 |
|
| 2466 |
} |
| 2467 |
} |
| 2468 |
|
| 2469 |
if ( ! function_exists('wdk_recaptcha_field')) |
| 2470 |
{ |
| 2471 |
function wdk_recaptcha_field($is_compact=false, $style="", $load_script=true) |
| 2472 |
{ |
| 2473 |
static $counter = 0; |
| 2474 |
static $recaptcha_array = array(); |
| 2475 |
|
| 2476 |
if(get_option('wdk_recaptcha_site_key') !== FALSE && get_option('wdk_recaptcha_secret_key') !== NULL) |
| 2477 |
{ |
| 2478 |
if($load_script && $counter===0) |
| 2479 |
{ |
| 2480 |
echo "<script src='https://www.google.com/recaptcha/api.js?onload=CaptchaCallback&render=explicit'></script>"; |
| 2481 |
} |
| 2482 |
$counter++; |
| 2483 |
|
| 2484 |
$compact_tag=''; |
| 2485 |
$size_tag=''; |
| 2486 |
if($is_compact) |
| 2487 |
{ |
| 2488 |
$compact_tag='data-size="compact"'; |
| 2489 |
$size_tag='compact'; |
| 2490 |
} |
| 2491 |
|
| 2492 |
$recaptcha_array[$counter] = array('size'=>$size_tag); |
| 2493 |
|
| 2494 |
echo '<div id="recaptcha_called_'.$counter.'" class="g-recaptcha" style="'.$style.'" '.$compact_tag.' data-sitekey="'.get_option('wdk_recaptcha_site_key').'"></div>'; |
| 2495 |
?> |
| 2496 |
|
| 2497 |
<script> |
| 2498 |
<?php if($counter===1)echo 'var ';?>CaptchaCallback = function(){ |
| 2499 |
<?php for($j=1;$j<=$counter;$j++): ?> |
| 2500 |
grecaptcha.render(document.getElementById('recaptcha_called_<?php echo $j;?>'), {'size' : '<?php echo $recaptcha_array[$j]['size']; ?>', 'sitekey' : '<?php echo get_option('wdk_recaptcha_site_key'); ?>'}); |
| 2501 |
<?php endfor; ?> |
| 2502 |
}; |
| 2503 |
</script> |
| 2504 |
|
| 2505 |
<?php |
| 2506 |
} |
| 2507 |
} |
| 2508 |
} |
| 2509 |
|
| 2510 |
function is_wdk_valid_recaptcha() |
| 2511 |
{ |
| 2512 |
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){ |
| 2513 |
//your site secret key |
| 2514 |
if(wdk_valid_recaptcha_curl($_POST['g-recaptcha-response'])) |
| 2515 |
{ |
| 2516 |
return TRUE; |
| 2517 |
} |
| 2518 |
} |
| 2519 |
return FALSE; |
| 2520 |
} |
| 2521 |
|
| 2522 |
function wdk_valid_recaptcha_curl($g_recaptcha_response='') { |
| 2523 |
$url = 'https://www.google.com/recaptcha/api/siteverify'; |
| 2524 |
$args = array( |
| 2525 |
'timeout' => 200, |
| 2526 |
'blocking' => true, |
| 2527 |
'headers' => array(), |
| 2528 |
'body' => array( |
| 2529 |
'secret' => get_option('wdk_recaptcha_secret_key'), |
| 2530 |
'response' => $g_recaptcha_response, |
| 2531 |
'remoteip' => sanitize_textarea_field($_SERVER['REMOTE_ADDR']) |
| 2532 |
), |
| 2533 |
'cookies' => array() |
| 2534 |
); |
| 2535 |
$response = wp_remote_post( $url, $args ); |
| 2536 |
|
| 2537 |
if ( is_wp_error( $response ) ) { |
| 2538 |
/*$error_message = $response->get_error_message();*/ |
| 2539 |
return true; |
| 2540 |
} else { |
| 2541 |
$response = json_decode($response['body']); |
| 2542 |
return $response->success; |
| 2543 |
} |
| 2544 |
} |
| 2545 |
|
| 2546 |
if(!function_exists('wdk_get_option')) { |
| 2547 |
/** |
| 2548 |
* Cached and get wp options |
| 2549 |
* |
| 2550 |
* @param string option Option key |
| 2551 |
* @return string alt or title |
| 2552 |
*/ |
| 2553 |
|
| 2554 |
function wdk_get_option($option_key = '') { |
| 2555 |
return get_option($option_key); |
| 2556 |
if(isset($options[$option_key])) { |
| 2557 |
return $options[$option_key]; |
| 2558 |
} |
| 2559 |
|
| 2560 |
$options[$option_key] = get_option($option_key); |
| 2561 |
|
| 2562 |
return $options[$option_key]; |
| 2563 |
} |
| 2564 |
} |
| 2565 |
|
| 2566 |
if(!function_exists('wdk_server_current_url')) { |
| 2567 |
/** |
| 2568 |
* Get current url basic on $_SERVER, exists function wdk_current_url(), on some urls have issue on listing preview page |
| 2569 |
* |
| 2570 |
* @return string url |
| 2571 |
*/ |
| 2572 |
|
| 2573 |
function wdk_server_current_url() |
| 2574 |
{ |
| 2575 |
return (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
| 2576 |
} |
| 2577 |
} |
| 2578 |
|
| 2579 |
|
| 2580 |
if(!function_exists('wdk_filter_date_decimal')) { |
| 2581 |
/** |
| 2582 |
* Filter 00:00:00 from date |
| 2583 |
* |
| 2584 |
* @param string |
| 2585 |
* @return string date without 00:00:00 |
| 2586 |
*/ |
| 2587 |
|
| 2588 |
function wdk_filter_date_decimal($data) |
| 2589 |
{ |
| 2590 |
return str_replace(' 00:00:00','', $data); |
| 2591 |
} |
| 2592 |
} |
| 2593 |
|
| 2594 |
function wdk_get_post() |
| 2595 |
{ |
| 2596 |
$post = array(); |
| 2597 |
|
| 2598 |
foreach($_POST as $key => $val) |
| 2599 |
{ |
| 2600 |
if(is_array($val)) |
| 2601 |
{ |
| 2602 |
return wdk_clean($_POST); |
| 2603 |
} |
| 2604 |
else |
| 2605 |
{ |
| 2606 |
if(strpos($val, '<iframe') === 0) |
| 2607 |
$val = str_replace("'",'"', $val); |
| 2608 |
|
| 2609 |
$post[sanitize_text_field($key)] = wp_kses_post($val); |
| 2610 |
} |
| 2611 |
} |
| 2612 |
|
| 2613 |
return $post; |
| 2614 |
} |
| 2615 |
|
| 2616 |
|
| 2617 |
function wdk_get_get() |
| 2618 |
{ |
| 2619 |
$log_array = array(); |
| 2620 |
|
| 2621 |
foreach($_GET as $key => $val) |
| 2622 |
{ |
| 2623 |
if(is_array($val)) |
| 2624 |
{ |
| 2625 |
return wdk_clean($_POST); |
| 2626 |
} |
| 2627 |
else |
| 2628 |
{ |
| 2629 |
$log_array[sanitize_text_field($key)] = wp_kses_post($val); |
| 2630 |
} |
| 2631 |
} |
| 2632 |
|
| 2633 |
return $log_array; |
| 2634 |
} |
| 2635 |
|
| 2636 |
function wdk_clean($array) |
| 2637 |
{ |
| 2638 |
$arr_cleaned = array(); |
| 2639 |
foreach($array as $key=>$val) |
| 2640 |
{ |
| 2641 |
if(is_array($val)) |
| 2642 |
{ |
| 2643 |
$arr_cleaned[sanitize_text_field($key)] = wdk_clean($val); |
| 2644 |
} |
| 2645 |
else |
| 2646 |
{ |
| 2647 |
$arr_cleaned[sanitize_text_field($key)] = wp_kses_post($val); |
| 2648 |
} |
| 2649 |
|
| 2650 |
} |
| 2651 |
|
| 2652 |
//dump($arr_cleaned); |
| 2653 |
|
| 2654 |
return $arr_cleaned; |
| 2655 |
} |
| 2656 |
|
| 2657 |
/* |
| 2658 |
<select class="form-control" name="<?php echo 'control_operator_'.$i_fieldnum; ?>"> |
| 2659 |
<option value="CONTAINS">CONTAINS</option> |
| 2660 |
<option value="NOT_CONTAINS">NOT_CONTAINS</option> |
| 2661 |
</select> |
| 2662 |
*/ |
| 2663 |
function wdk_select_multi_option($field_name, $options = array(), $selected = NULL, $extra=NULL, $empty_text = NULL, $empty_val = '') |
| 2664 |
{ |
| 2665 |
$output = '<select name="'.$field_name.'" '.$extra.' multiple="multiple">'; |
| 2666 |
|
| 2667 |
if(!is_null($empty_text)) |
| 2668 |
$output.= '<option value="'.esc_attr($empty_val).'">'.esc_html($empty_text).'</option>'; |
| 2669 |
|
| 2670 |
if(is_array($options) && count($options) > 0) |
| 2671 |
foreach($options as $key=>$val) |
| 2672 |
{ |
| 2673 |
$output.= '<option value="'.$key.'" '.($selected==$key?'selected':'').'>'.$val.'</option>'; |
| 2674 |
} |
| 2675 |
|
| 2676 |
$output.= '</select>'; |
| 2677 |
|
| 2678 |
return $output; |
| 2679 |
} |
| 2680 |
|
| 2681 |
|
| 2682 |
if ( ! function_exists('wdk_treefield_select_ajax')) |
| 2683 |
{ |
| 2684 |
/** |
| 2685 |
* Return select2 ajax |
| 2686 |
* |
| 2687 |
* @param string option Option key |
| 2688 |
* @return string alt or title |
| 2689 |
*/ |
| 2690 |
function wdk_treefield_select_ajax($name = '', $table=NULL, $selected = NULL, |
| 2691 |
$column_print = 'category_title', $column_key = 'idcategory', $language_id=NULL, $empty_value='', $filter_ids = '', $attr = '') |
| 2692 |
{ |
| 2693 |
$WMVC = &wdk_get_instance(); |
| 2694 |
$WMVC->model($table); |
| 2695 |
|
| 2696 |
if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids); |
| 2697 |
|
| 2698 |
static $counter = 0; |
| 2699 |
$form = '<select data-ajax="'.admin_url('admin-ajax.php').'" name="'.$name.'" data-table="'.$table.'" '.$attr.' data-placeholder="'.$empty_value.'" class="form-control select_ajax" id="wdk_select2_'.$counter.'" multiple="">'; |
| 2700 |
|
| 2701 |
|
| 2702 |
if(false) |
| 2703 |
if( $column_key == 'idcategory') { |
| 2704 |
$form .= '<option selected="selected" value="">'.esc_html__('Select Category', 'wpdirectorykit').'</option>'; |
| 2705 |
} else { |
| 2706 |
$form .= '<option selected="selected" value="">'.esc_html__('Select Location', 'wpdirectorykit').'</option>'; |
| 2707 |
} |
| 2708 |
|
| 2709 |
if($selected) { |
| 2710 |
if(is_array($selected)) { |
| 2711 |
|
| 2712 |
$ids = array(); |
| 2713 |
foreach($selected as $selected_item) { |
| 2714 |
if(!empty($selected_item)) { |
| 2715 |
$ids [] = $selected_item; |
| 2716 |
} |
| 2717 |
} |
| 2718 |
|
| 2719 |
/* where in */ |
| 2720 |
if(!empty($ids)){ |
| 2721 |
$WMVC->db->select($WMVC->$table->_table_name.'.*'); |
| 2722 |
$WMVC->db->where($WMVC->$table->_table_name.'.'.$column_key.' IN(' . implode(',', $ids) . ')', null, false); |
| 2723 |
$WMVC->db->order_by('FIELD('.$WMVC->$table->_table_name.'.'.$column_key.', '. implode(',', $ids) . ')'); |
| 2724 |
|
| 2725 |
$results = $WMVC->$table->get(); |
| 2726 |
foreach ($results as $item) { |
| 2727 |
if($item) |
| 2728 |
$form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data($column_key, $item, false, TRUE, TRUE)).'">'.esc_html(wmvc_show_data($column_print, $item, false, TRUE, TRUE)).'</option>'; |
| 2729 |
} |
| 2730 |
} |
| 2731 |
} elseif(is_intval($selected)) { |
| 2732 |
$db_item = $WMVC->$table->get($selected, TRUE); |
| 2733 |
if($db_item) |
| 2734 |
$form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data($column_key, $db_item, false, TRUE, TRUE)).'">'.esc_attr(wmvc_show_data($column_print, $db_item, false, TRUE, TRUE)).'</option>'; |
| 2735 |
} |
| 2736 |
} else { |
| 2737 |
//$form .= '<option value="" selected="selected">'.esc_html__('Not selected', 'wpdirectorykit').'</option>'; |
| 2738 |
} |
| 2739 |
$form .= '</select>'; |
| 2740 |
|
| 2741 |
//load javascript library |
| 2742 |
if($counter==0) |
| 2743 |
{ |
| 2744 |
wp_enqueue_script('select2'); |
| 2745 |
wp_enqueue_script('wdk-select2'); |
| 2746 |
wp_enqueue_style('select2'); |
| 2747 |
} |
| 2748 |
?> |
| 2749 |
<?php |
| 2750 |
$counter++; |
| 2751 |
return $form; |
| 2752 |
} |
| 2753 |
} |
| 2754 |
|
| 2755 |
if ( ! function_exists('wdk_user_select_ajax')) |
| 2756 |
{ |
| 2757 |
/** |
| 2758 |
* Return select2 ajax |
| 2759 |
* |
| 2760 |
* @param string option Option key |
| 2761 |
* @return string alt or title |
| 2762 |
*/ |
| 2763 |
function wdk_user_select_ajax($name = '', $selected = NULL, $empty_value='', $filter_ids = '') |
| 2764 |
{ |
| 2765 |
$WMVC = &wdk_get_instance(); |
| 2766 |
|
| 2767 |
if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids); |
| 2768 |
|
| 2769 |
static $counter = 0; |
| 2770 |
$form = '<select data-ajax="'.admin_url('admin-ajax.php').'" name="'.$name.'" data-placeholder="'.$empty_value.'" class="form-control select_ajax_user" id="wdk_select2_user_'.$counter.'" multiple="">'; |
| 2771 |
if($selected) { |
| 2772 |
if(is_array($selected)) { |
| 2773 |
/* where in */ |
| 2774 |
foreach ($selected as $item) { |
| 2775 |
$user_data = get_userdata($item); |
| 2776 |
if($user_data) |
| 2777 |
$form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data('ID', $user_data, false, TRUE, TRUE)).'">'.esc_html(wmvc_show_data('display_name', $user_data, false, TRUE, TRUE)).'</option>'; |
| 2778 |
} |
| 2779 |
} elseif(is_intval($selected)) { |
| 2780 |
$user_data = get_userdata($selected); |
| 2781 |
if($user_data) |
| 2782 |
$form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data('ID', $user_data, false, TRUE, TRUE)).'">'.esc_html(wmvc_show_data('display_name', $user_data, false, TRUE, TRUE)).'</option>'; |
| 2783 |
} |
| 2784 |
} else { |
| 2785 |
//$form .= '<option value="" selected="selected">'.esc_html__('Not selected', 'wpdirectorykit').'</option>'; |
| 2786 |
} |
| 2787 |
$form .= '</select>'; |
| 2788 |
|
| 2789 |
//load javascript library |
| 2790 |
if($counter==0) |
| 2791 |
{ |
| 2792 |
wp_enqueue_script('select2'); |
| 2793 |
wp_enqueue_script('wdk-select2'); |
| 2794 |
wp_enqueue_style('select2'); |
| 2795 |
} |
| 2796 |
?> |
| 2797 |
<?php |
| 2798 |
$counter++; |
| 2799 |
return $form; |
| 2800 |
} |
| 2801 |
} |
| 2802 |
|
| 2803 |
|
| 2804 |
/* |
| 2805 |
<select class="form-control" name="<?php echo 'control_operator_'.$i_fieldnum; ?>"> |
| 2806 |
<option value="CONTAINS">CONTAINS</option> |
| 2807 |
<option value="NOT_CONTAINS">NOT_CONTAINS</option> |
| 2808 |
</select> |
| 2809 |
*/ |
| 2810 |
function wdk_select_option_multiple($field_name, $options = array(), $selected = array(), $extra=NULL, $empty_text = NULL, $empty_val = '') |
| 2811 |
{ |
| 2812 |
$output = '<select name="'.$field_name.'" '.$extra.' multiple >'; |
| 2813 |
|
| 2814 |
if(!is_null($empty_text)) |
| 2815 |
$output.= '<option value="'.esc_attr($empty_val).'">'.esc_html($empty_text).'</option>'; |
| 2816 |
|
| 2817 |
if(is_array($options) && count($options) > 0) |
| 2818 |
foreach($options as $key=>$val) |
| 2819 |
{ |
| 2820 |
if(is_string($selected)) { |
| 2821 |
$output.= '<option value="'.$key.'" '.(($selected == $key)?'selected="selected"':'').'>'.$val.'</option>'; |
| 2822 |
} else if(is_array($selected)){ |
| 2823 |
$output.= '<option value="'.$key.'" '.((in_array($key, $selected) === TRUE)?'selected="selected"':'').'>'.$val.'</option>'; |
| 2824 |
} |
| 2825 |
} |
| 2826 |
|
| 2827 |
$output.= '</select>'; |
| 2828 |
|
| 2829 |
return $output; |
| 2830 |
} |
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
if ( ! function_exists('wdk_convert_date_format_js')) |
| 2835 |
{ |
| 2836 |
/** |
| 2837 |
* Convert date format for support in js |
| 2838 |
* From: https://wordpress.org/support/article/formatting-date-and-time/ |
| 2839 |
* To: https://momentjscom.readthedocs.io/en/latest/moment/04-displaying/01-format/ |
| 2840 |
* |
| 2841 |
* @param string php date format Option key |
| 2842 |
* @return string js date format |
| 2843 |
*/ |
| 2844 |
function wdk_convert_date_format_js($date_format) |
| 2845 |
{ |
| 2846 |
$replaced = array( |
| 2847 |
'D'=>'ddd', |
| 2848 |
'j'=>'D', |
| 2849 |
'd'=>'DD', |
| 2850 |
'l'=>'dddd', |
| 2851 |
'F'=>'MMMM', |
| 2852 |
'Y'=>'YYYY', |
| 2853 |
'S'=>'Do', |
| 2854 |
'm'=>'MM', |
| 2855 |
'n'=>'MM', |
| 2856 |
'F'=>'MMMM', |
| 2857 |
'M'=>'MMM', |
| 2858 |
'Y'=>'YYYY', |
| 2859 |
'y'=>'YY', |
| 2860 |
'a'=>'a', |
| 2861 |
'A'=>'A', |
| 2862 |
'h'=>'hh', |
| 2863 |
'G'=>'H', |
| 2864 |
'H'=>'HH', |
| 2865 |
'g'=>'h', |
| 2866 |
'i'=>'mm', |
| 2867 |
's'=>'ss', |
| 2868 |
'T'=>'zz', |
| 2869 |
'c'=>'', |
| 2870 |
'r'=>'llll', |
| 2871 |
'u'=>'x', |
| 2872 |
); |
| 2873 |
|
| 2874 |
$replaced_from = array_keys($replaced); |
| 2875 |
$date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format); |
| 2876 |
return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format); |
| 2877 |
} |
| 2878 |
} |
| 2879 |
|
| 2880 |
if ( ! function_exists('wdk_convert_date_format_jquery')) |
| 2881 |
{ |
| 2882 |
/** |
| 2883 |
* Convert date format for support in js |
| 2884 |
* From: https://wordpress.org/support/article/formatting-date-and-time/ |
| 2885 |
* To: https://api.jqueryui.com/datepicker/ |
| 2886 |
* |
| 2887 |
* @param string php date format Option key |
| 2888 |
* @return string js date format |
| 2889 |
*/ |
| 2890 |
function wdk_convert_date_format_jquery($date_format) |
| 2891 |
{ |
| 2892 |
$replaced = array( |
| 2893 |
'D'=>'D', |
| 2894 |
'd'=>'dd', |
| 2895 |
'j'=>'d', |
| 2896 |
'l'=>'DD', |
| 2897 |
'Y'=>'yy', |
| 2898 |
'S'=>'d', |
| 2899 |
'm'=>'mm', |
| 2900 |
'n'=>'m', |
| 2901 |
'M'=>'m', |
| 2902 |
'F'=>'MM', |
| 2903 |
'y'=>'y', |
| 2904 |
'a'=>'', |
| 2905 |
'A'=>'', |
| 2906 |
'h'=>'', |
| 2907 |
'G'=>'', |
| 2908 |
'H'=>'', |
| 2909 |
'g'=>'', |
| 2910 |
'i'=>'', |
| 2911 |
's'=>'', |
| 2912 |
'T'=>'', |
| 2913 |
'c'=>'ISO_8601', |
| 2914 |
'r'=>'RFC_2822', |
| 2915 |
'u'=>'@', |
| 2916 |
':'=>'', |
| 2917 |
); |
| 2918 |
|
| 2919 |
$replaced_from = array_keys($replaced); |
| 2920 |
$date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format); |
| 2921 |
return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format); |
| 2922 |
} |
| 2923 |
} |
| 2924 |
|
| 2925 |
if ( ! function_exists('wdk_convert_date_format_jquery')) |
| 2926 |
{ |
| 2927 |
/** |
| 2928 |
* Convert date format for support in js |
| 2929 |
* From: https://wordpress.org/support/article/formatting-date-and-time/ |
| 2930 |
* To: https://api.jqueryui.com/datepicker/ |
| 2931 |
* |
| 2932 |
* @param string php date format Option key |
| 2933 |
* @return string js date format |
| 2934 |
*/ |
| 2935 |
function wdk_convert_date_format_jquery($date_format) |
| 2936 |
{ |
| 2937 |
$replaced = array( |
| 2938 |
'D'=>'D', |
| 2939 |
'd'=>'dd', |
| 2940 |
'j'=>'d', |
| 2941 |
'l'=>'DD', |
| 2942 |
'Y'=>'yy', |
| 2943 |
'S'=>'d', |
| 2944 |
'm'=>'mm', |
| 2945 |
'n'=>'m', |
| 2946 |
'M'=>'m', |
| 2947 |
'F'=>'MM', |
| 2948 |
'y'=>'y', |
| 2949 |
'a'=>'', |
| 2950 |
'A'=>'', |
| 2951 |
'h'=>'', |
| 2952 |
'G'=>'', |
| 2953 |
'H'=>'', |
| 2954 |
'g'=>'', |
| 2955 |
'i'=>'', |
| 2956 |
's'=>'', |
| 2957 |
'T'=>'', |
| 2958 |
'c'=>'ISO_8601', |
| 2959 |
'r'=>'RFC_2822', |
| 2960 |
'u'=>'@', |
| 2961 |
':'=>'', |
| 2962 |
); |
| 2963 |
|
| 2964 |
$replaced_from = array_keys($replaced); |
| 2965 |
$date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format); |
| 2966 |
return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format); |
| 2967 |
} |
| 2968 |
} |
| 2969 |
|
| 2970 |
if ( ! function_exists('wdk_get_gps')) |
| 2971 |
{ |
| 2972 |
|
| 2973 |
/** |
| 2974 |
* Get Latitude/Longitude/Altitude based on an address |
| 2975 |
* @param string $address The address for converting into coordinates |
| 2976 |
* @return array An array containing Latitude/Longitude/Altitude data |
| 2977 |
*/ |
| 2978 |
function wdk_get_gps($address = '') |
| 2979 |
{ |
| 2980 |
static $results = array(); |
| 2981 |
$address = str_replace(' ','+',$address); |
| 2982 |
|
| 2983 |
if(!isset($results[$address])) { |
| 2984 |
$results[$address] = NULL; |
| 2985 |
$url = 'https://nominatim.openstreetmap.org/search?format=json&q=' . $address; |
| 2986 |
$request = wp_remote_get( $url ); |
| 2987 |
$response = ''; |
| 2988 |
|
| 2989 |
// request failed |
| 2990 |
if ( is_wp_error( $request ) ) { |
| 2991 |
$response = $request; |
| 2992 |
} |
| 2993 |
$code = (int) wp_remote_retrieve_response_code( $request ); |
| 2994 |
|
| 2995 |
// make sure the fetch was successful |
| 2996 |
if (empty($response) && $code == 200 ) { |
| 2997 |
$response = wp_remote_retrieve_body( $request ); |
| 2998 |
// Decode the json |
| 2999 |
$resp = json_decode( $response, true ); |
| 3000 |
|
| 3001 |
if(!empty($resp) && isset($resp[0]) && isset($resp[0]['lat']) && isset($resp[0]['lon'])) { |
| 3002 |
$results[$address] = array('lat' => $resp[0]['lat'], 'lng' => $resp[0]['lon'], 'alt' => 0); |
| 3003 |
return $results[$address]; |
| 3004 |
} |
| 3005 |
} |
| 3006 |
} else { |
| 3007 |
return $results[$address]; |
| 3008 |
} |
| 3009 |
return false; |
| 3010 |
} |
| 3011 |
} |
| 3012 |
|
| 3013 |
if ( ! function_exists('wdk_get_gps_google')) |
| 3014 |
{ |
| 3015 |
|
| 3016 |
/** |
| 3017 |
* Get Latitude/Longitude/Altitude based on an address from Google Api |
| 3018 |
* @param string $address The address for converting into coordinates |
| 3019 |
* @param string $api_key Custom google API Key |
| 3020 |
* |
| 3021 |
* @return array An array containing Latitude/Longitude/Altitude data |
| 3022 |
*/ |
| 3023 |
function wdk_get_gps_google($address = '', $api_key = NULL) |
| 3024 |
{ |
| 3025 |
static $results = array(); |
| 3026 |
|
| 3027 |
if ( empty( $api_key ) ) { |
| 3028 |
$api_key = wdk_get_option('wdk_geo_google_api_key'); |
| 3029 |
} |
| 3030 |
|
| 3031 |
$address = str_replace(' ','+',$address); |
| 3032 |
|
| 3033 |
if(!isset($results[$address])) { |
| 3034 |
$results[$address] = NULL; |
| 3035 |
$url = 'https://maps.googleapis.com/maps/api/geocode/json?address='.trim($address).'&key='.$api_key; |
| 3036 |
$request = wp_remote_get( $url ); |
| 3037 |
$response = ''; |
| 3038 |
|
| 3039 |
// request failed |
| 3040 |
if ( is_wp_error( $request ) ) { |
| 3041 |
$response = $request; |
| 3042 |
} |
| 3043 |
$code = (int) wp_remote_retrieve_response_code( $request ); |
| 3044 |
|
| 3045 |
// make sure the fetch was successful |
| 3046 |
if (empty($response) && $code == 200 ) { |
| 3047 |
$response = wp_remote_retrieve_body( $request ); |
| 3048 |
// Decode the json |
| 3049 |
$resp = json_decode( $response, true ); |
| 3050 |
$status = $resp['status']; |
| 3051 |
|
| 3052 |
//if request status is successful |
| 3053 |
if($status == "OK"){ |
| 3054 |
//get address from json data |
| 3055 |
$lat = $resp['results'][0]['geometry']['location']['lat']; |
| 3056 |
$lng = $resp['results'][0]['geometry']['location']['lng']; |
| 3057 |
|
| 3058 |
$results[$address] = array('lat' => $lat , 'lng' => $lng, 'alt' => 0); |
| 3059 |
return $results[$address]; |
| 3060 |
} |
| 3061 |
} |
| 3062 |
} else { |
| 3063 |
return $results[$address]; |
| 3064 |
} |
| 3065 |
|
| 3066 |
return false; |
| 3067 |
} |
| 3068 |
} |
| 3069 |
|
| 3070 |
|
| 3071 |
if ( ! function_exists('wdk_getDueCoords')) |
| 3072 |
{ |
| 3073 |
// Modified from: |
| 3074 |
// http://www.sitepoint.com/forums/showthread.php?656315-adding-distance-gps-coordinates-get-bounding-box |
| 3075 |
/** |
| 3076 |
* bearing is 0 = north, 180 = south, 90 = east, 270 = west |
| 3077 |
* |
| 3078 |
*/ |
| 3079 |
function wdk_getDueCoords($latitude, $longitude, $bearing, $distance, $distance_unit = "km", $return_as_array = FALSE) { |
| 3080 |
|
| 3081 |
if ($distance_unit == "m") { |
| 3082 |
// Distance is in miles. |
| 3083 |
$radius = 3963.1676; |
| 3084 |
} |
| 3085 |
else { |
| 3086 |
// distance is in km. |
| 3087 |
$radius = 6378.1; |
| 3088 |
} |
| 3089 |
|
| 3090 |
// New latitude in degrees. |
| 3091 |
$new_latitude = rad2deg(asin(sin(deg2rad($latitude)) * cos($distance / $radius) + cos(deg2rad($latitude)) * sin($distance / $radius) * cos(deg2rad($bearing)))); |
| 3092 |
|
| 3093 |
// New longitude in degrees. |
| 3094 |
$new_longitude = rad2deg(deg2rad($longitude) + atan2(sin(deg2rad($bearing)) * sin($distance / $radius) * cos(deg2rad($latitude)), cos($distance / $radius) - sin(deg2rad($latitude)) * sin(deg2rad($new_latitude)))); |
| 3095 |
|
| 3096 |
if ($return_as_array) { |
| 3097 |
// Assign new latitude and longitude to an array to be returned to the caller. |
| 3098 |
$coord = array(); |
| 3099 |
$coord['lat'] = $new_latitude; |
| 3100 |
$coord['lng'] = $new_longitude; |
| 3101 |
} |
| 3102 |
else { |
| 3103 |
$coord = $new_latitude . ", " . $new_longitude; |
| 3104 |
} |
| 3105 |
|
| 3106 |
return $coord; |
| 3107 |
|
| 3108 |
} |
| 3109 |
} |
| 3110 |
|
| 3111 |
if ( ! function_exists('wdk_is_gps')) |
| 3112 |
{ |
| 3113 |
// Validation gps |
| 3114 |
/** |
| 3115 |
* @param string $string_gps gps in string like xx.xxxx,xx.xxxxx |
| 3116 |
* @return bool |
| 3117 |
*/ |
| 3118 |
function wdk_is_gps($string_gps = '') { |
| 3119 |
if(preg_match('/^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$/', $string_gps)) { |
| 3120 |
return true; |
| 3121 |
} |
| 3122 |
|
| 3123 |
return false; |
| 3124 |
} |
| 3125 |
} |
| 3126 |
|
| 3127 |
|
| 3128 |
if ( ! function_exists('wdk_is_phone')) |
| 3129 |
{ |
| 3130 |
// Validation phone |
| 3131 |
/** |
| 3132 |
* @param string $value phone in string |
| 3133 |
* @return bool |
| 3134 |
*/ |
| 3135 |
function wdk_is_phone($value = '') { |
| 3136 |
if(preg_match("/.*[0-9]{3,4}-[0-9]{3,4}.*$/", $value)) { |
| 3137 |
return true; |
| 3138 |
} |
| 3139 |
|
| 3140 |
return false; |
| 3141 |
} |
| 3142 |
} |
| 3143 |
|
| 3144 |
if ( ! function_exists('wdk_filter_phone')) |
| 3145 |
{ |
| 3146 |
// Validation phone |
| 3147 |
/** |
| 3148 |
* @param string $value phone in string |
| 3149 |
* @return bool |
| 3150 |
*/ |
| 3151 |
function wdk_filter_phone($value = '') { |
| 3152 |
return str_replace(array(' ','-','(',')'),'',$value); |
| 3153 |
} |
| 3154 |
} |
| 3155 |
|
| 3156 |
|
| 3157 |
if ( ! function_exists('wdk_generate_media_field')) |
| 3158 |
{ |
| 3159 |
// Based on value return video embed, youtube, source video tag |
| 3160 |
/** |
| 3161 |
* @param string $value value |
| 3162 |
* @param string $class help css class |
| 3163 |
* @return string html or NULL |
| 3164 |
*/ |
| 3165 |
function wdk_generate_media_field($value = '', $class="wdk-image") { |
| 3166 |
$output = NULL; |
| 3167 |
|
| 3168 |
if(strpos($value, 'vimeo.com') !== FALSE) |
| 3169 |
{ |
| 3170 |
$output = wp_oembed_get($value, array("width"=>"800", "height"=>"450")); |
| 3171 |
$output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output); |
| 3172 |
} |
| 3173 |
elseif(strpos($value, 'watch?v=') !== FALSE) |
| 3174 |
{ |
| 3175 |
$embed_code = substr($value, strpos($value, 'watch?v=')+8); |
| 3176 |
$output = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455")); |
| 3177 |
$output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output ); |
| 3178 |
} |
| 3179 |
elseif(strpos($value, 'youtu.be/') !== FALSE) |
| 3180 |
{ |
| 3181 |
$embed_code = substr($value, strpos($value, 'youtu.be/')+9); |
| 3182 |
$output = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455")); |
| 3183 |
$output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output ); |
| 3184 |
} |
| 3185 |
elseif(strpos($value, 'youtube.com/embed/') !== FALSE) |
| 3186 |
{ |
| 3187 |
$embed_code = substr($value, strpos($value, 'youtube.com/embed/')+18); |
| 3188 |
$output = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455")); |
| 3189 |
$output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output ); |
| 3190 |
} |
| 3191 |
elseif(filter_var($value, FILTER_VALIDATE_URL) !== FALSE && preg_match('/\.(mp4|flv|wmw|ogv|webm|ogg)$/i', $value)) |
| 3192 |
{ |
| 3193 |
$output = '<video src="'.$value.'" controls class="'.$class.'"></video> '; |
| 3194 |
} |
| 3195 |
|
| 3196 |
return $output; |
| 3197 |
} |
| 3198 |
} |
| 3199 |
|
| 3200 |
|
| 3201 |
if ( ! function_exists('wdk_depend_get_hidden_fields')) |
| 3202 |
{ |
| 3203 |
// Based on value return video embed, youtube, source video tag |
| 3204 |
/** |
| 3205 |
* @param int $tree_id tree_id of category |
| 3206 |
* @param string $type type, default 'categories' |
| 3207 |
* @return string string with hidden fields like ,1,2,3,4, or NULL |
| 3208 |
*/ |
| 3209 |
function wdk_depend_get_hidden_fields($tree_id = NULL, $type="categories") { |
| 3210 |
static $output = array(); |
| 3211 |
|
| 3212 |
if(isset($output[$tree_id])) { |
| 3213 |
return $output[$tree_id]; |
| 3214 |
} |
| 3215 |
if(empty($tree_id)) { |
| 3216 |
return NULL; |
| 3217 |
} else { |
| 3218 |
$output[$tree_id] = false; |
| 3219 |
|
| 3220 |
global $Winter_MVC_WDK; |
| 3221 |
$Winter_MVC_WDK->model('dependfields_m'); |
| 3222 |
|
| 3223 |
$depend_fields = $Winter_MVC_WDK->dependfields_m->get_by(array('field_id' => $tree_id,'main_field' => $type), TRUE); |
| 3224 |
|
| 3225 |
if($depend_fields && !empty($depend_fields->hidden_fields_list)) { |
| 3226 |
$output[$tree_id] = ','.$depend_fields->hidden_fields_list. ','; |
| 3227 |
} |
| 3228 |
return $output[$tree_id]; |
| 3229 |
} |
| 3230 |
|
| 3231 |
return false; |
| 3232 |
} |
| 3233 |
} |
| 3234 |
|
| 3235 |
if ( ! function_exists('wdk_depend_is_hidden_field')) |
| 3236 |
{ |
| 3237 |
// Based on value return video embed, youtube, source video tag |
| 3238 |
/** |
| 3239 |
* @param int $field_id field_id |
| 3240 |
* @param int $tree_id id for category |
| 3241 |
* @param string $type type, default 'categories' |
| 3242 |
* @return string string with hidden fields like ,1,2,3,4, or NULL |
| 3243 |
*/ |
| 3244 |
function wdk_depend_is_hidden_field($field_id = NULL, $tree_id = NULL, $type="categories") { |
| 3245 |
$hidden_fields = wdk_depend_get_hidden_fields($tree_id, $type); |
| 3246 |
if($hidden_fields && strpos($hidden_fields, ','.trim($field_id).',') !== FALSE) { |
| 3247 |
return true; |
| 3248 |
} |
| 3249 |
|
| 3250 |
return false; |
| 3251 |
} |
| 3252 |
} |
| 3253 |
|
| 3254 |
|
| 3255 |
if ( ! function_exists('is_wdk_slug_format')) |
| 3256 |
{ |
| 3257 |
function is_wdk_slug_format($string) |
| 3258 |
{ |
| 3259 |
if(empty($string))return FALSE; |
| 3260 |
|
| 3261 |
|
| 3262 |
if (preg_match("/^[a-z0-9-_]+\$/", $string)) { |
| 3263 |
|
| 3264 |
return TRUE; |
| 3265 |
} |
| 3266 |
|
| 3267 |
return FALSE; |
| 3268 |
} |
| 3269 |
} |
| 3270 |
|
| 3271 |
if ( ! function_exists('wdk_number_format_i18n')) |
| 3272 |
{ |
| 3273 |
function wdk_number_format_i18n($value) |
| 3274 |
{ |
| 3275 |
if(empty($value))return NULL; |
| 3276 |
|
| 3277 |
|
| 3278 |
$value = filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
| 3279 |
$value = (float)str_replace(array(","," ",' '), "", $value); |
| 3280 |
|
| 3281 |
return number_format_i18n($value); |
| 3282 |
} |
| 3283 |
} |
| 3284 |
|
| 3285 |
if ( ! function_exists('wdk_currency_symbol')) |
| 3286 |
{ |
| 3287 |
/** |
| 3288 |
* Return currency symbol |
| 3289 |
* |
| 3290 |
* @return string currency symbol |
| 3291 |
*/ |
| 3292 |
function wdk_currency_symbol() |
| 3293 |
{ |
| 3294 |
|
| 3295 |
if(function_exists('get_woocommerce_currency_symbol')) |
| 3296 |
return get_woocommerce_currency_symbol(); |
| 3297 |
|
| 3298 |
if(wdk_get_option('wdk_default_currency_symbol')) |
| 3299 |
return wdk_get_option('wdk_default_currency_symbol'); |
| 3300 |
|
| 3301 |
return '$'; |
| 3302 |
} |
| 3303 |
} |
| 3304 |
|
| 3305 |
if ( ! function_exists('wdk_generate_path_image')) |
| 3306 |
{ |
| 3307 |
/** |
| 3308 |
* Generate path of images |
| 3309 |
* |
| 3310 |
* @param string $id or ids of images, separeted by comma |
| 3311 |
* @param bool $multi multi images, separeted by comma |
| 3312 |
* @param int $limit limit characters for path |
| 3313 |
* @param int $limit limit images for path |
| 3314 |
* |
| 3315 |
* @return string with path of image or multi images |
| 3316 |
*/ |
| 3317 |
function wdk_generate_path_image($ids = NULL, $multi = FALSE, $limit = 95, $limit_images = 10) |
| 3318 |
{ |
| 3319 |
$path = ''; |
| 3320 |
if(empty($ids)) |
| 3321 |
return $path; |
| 3322 |
|
| 3323 |
$image_ids = explode(',', $ids); |
| 3324 |
$count_images = 0; |
| 3325 |
if(is_array($image_ids)) { |
| 3326 |
foreach ($image_ids as $image_id) { |
| 3327 |
if(is_numeric($image_id)) |
| 3328 |
{ |
| 3329 |
|
| 3330 |
if($count_images>=$limit_images) |
| 3331 |
break; |
| 3332 |
|
| 3333 |
$image_path = wp_get_original_image_path($image_id); |
| 3334 |
if($image_path) { |
| 3335 |
/* path of image */ |
| 3336 |
$next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path); |
| 3337 |
|
| 3338 |
/* check length listing_images_path + next image + comma, should be less then $limit */ |
| 3339 |
if(strlen($path.$next_path)<$limit) { |
| 3340 |
|
| 3341 |
if($multi) { |
| 3342 |
if(!empty($path)) |
| 3343 |
$path .= ','; |
| 3344 |
} |
| 3345 |
|
| 3346 |
$path .= $next_path; |
| 3347 |
} |
| 3348 |
|
| 3349 |
if(!$multi) |
| 3350 |
break; |
| 3351 |
|
| 3352 |
$count_images++; |
| 3353 |
} |
| 3354 |
} |
| 3355 |
} |
| 3356 |
} |
| 3357 |
|
| 3358 |
return $path; |
| 3359 |
} |
| 3360 |
} |
| 3361 |
|
| 3362 |
?> |