field_type; $field_view_path = WPDIRECTORYKIT_PATH.'application/views/fields_edit/'.$field_type.'.php'; if(file_exists($field_view_path)) { include $field_view_path; } else { echo __('Missing VIEW file: ', 'wpdirectorykit').esc_html($field_type).'.php'; } } } if ( ! function_exists('wdk_generate_search_form')) { function wdk_generate_search_form($form_id=1, $subfolder='', $print = TRUE, $predefinedfields_query = array()) { /* load WMVC data */ $WMVC = &wdk_get_instance(); $WMVC->model('searchform_m'); $WMVC->model('field_m'); $output = ''; /* get WMVC form data */ $fields = $WMVC->searchform_m->get($form_id, TRUE); $user_fields = NULL; /* get WMVC form fields */ if(is_object($fields)) $user_fields = json_decode($fields->searchform_json); /* generate WMVC form fields html */ if(is_array($user_fields)) foreach($user_fields as $used_field) { if($used_field->field_id == 'cat') { $field = array( "idfield" => 'category', "field_type" => 'CATEGORY', "field_label" => __('Category', 'wpdirectorykit'), "prefix" => '', "suffix" => '', "values_list" => '', ); }else if($used_field->field_id == 'loc') { $field = array( "idfield" => 'location', "field_type" => 'LOCATION', "field_label" => __('Location', 'wpdirectorykit'), "prefix" => '', "suffix" => '', "values_list" => '', ); }else if($used_field->field_id == 'address') { $field = array( "idfield" => 'address', "field_type" => 'INPUTBOX', "field_label" => __('Address', 'wpdirectorykit'), "prefix" => '', "suffix" => '', "values_list" => '', ); }else if($used_field->field_id == 'post_title') { $field = array( "idfield" => 'post_title', "field_type" => 'INPUTBOX', "field_label" => __('Title', 'wpdirectorykit'), "prefix" => '', "suffix" => '', "values_list" => '', ); }else if($used_field->field_id == 'search') { $field = array( "idfield" => 'search', "field_type" => 'INPUTBOX', "field_label" => __('Search', 'wpdirectorykit'), "prefix" => '', "suffix" => '', "values_list" => '', ); }else if(function_exists('run_wdk_bookings') && $used_field->field_id == 'booking_date') { $field = array( "idfield" => 'booking_date', "field_type" => 'BOOKINGS_DATE', "field_label" => __('Booking Date', 'wpdirectorykit'), "prefix" => '', "suffix" => '', "values_list" => '', ); }else if($used_field->field_id == 'more') { $field = array( "idfield" => 'MORE', "field_type" => 'MORE', "field_label" => __('MORE', 'wpdirectorykit'), "prefix" => '', "suffix" => '', "values_list" => '', ); } else { $field_data = $WMVC->field_m->get_fields_data($used_field->field_id); if($field_data) $field = array( "idfield" => wmvc_show_data('idfield', $field_data), "field_type" => wmvc_show_data('field_type', $field_data), "field_label" =>wmvc_show_data('field_label', $field_data), "prefix" => wmvc_show_data('prefix', $field_data), "suffix" => wmvc_show_data('suffix', $field_data), "values_list" => wmvc_show_data('values_list', $field_data) ); } /* if field not detected or remove from fields list, skip field in search */ if(empty($field)) continue; /* add from user fields data */ $field['field_id'] = wmvc_show_data('field_id', $used_field); $field['class'] = wmvc_show_data('class', $used_field); $field['query_type'] = wmvc_show_data('query_type', $used_field); $field['columns'] = wmvc_show_data('columns', $used_field); $field_data = array(); $field_data ['field_data'] = $field; $field_data ['predefinedfields_query'] = $predefinedfields_query; $field_view_path = WPDIRECTORYKIT_PATH.'application/views/search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)).'.php'; if(file_exists($field_view_path)) { $output .= $WMVC->view('search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)), $field_data, FALSE); } else { /* show missing view file of field, only if print enable */ if($print) $output .= __('Missing VIEW file: ', 'wpdirectorykit').esc_html($subfolder).(wmvc_show_data('field_type', $field)).'.php'; } } if($print){ echo $output; return FALSE; } return $output; } } function &wdk_get_instance() { global $Winter_MVC_WDK; if(empty($Winter_MVC_WDK)) { $Winter_MVC_WDK = new MVC_Loader(plugin_dir_path( __FILE__ ).'../../'); $Winter_MVC_WDK->load_helper('basic'); } return $Winter_MVC_WDK; } function wdk_prepare_search_query_GET($columns = array(), $model_name = NULL, $external_columns = array(), $custom_parameters = array(), $skip_postget = FALSE) { global $Winter_MVC_WDK; $WMVC = &$Winter_MVC_WDK; $wdk_bookings_joinded = false; static $available_fields_listings = NULL; static $available_fields_static = array(); static $list_fields_static = NULL; $_GET_clone = array(); if(!$skip_postget) $_GET_clone = array_merge($_GET, $_POST); if(isset($_GET_clone['order_by']) && $_GET_clone['order_by'] =='undefined') { unset($_GET_clone['order_by']); } if(isset($custom_parameters['order_by'])) { if(isset($_GET_clone['order_by']) && !empty($_GET_clone['order_by'])) { $_GET_clone['order_by'] = $custom_parameters['order_by'].', '.$_GET_clone['order_by']; } else { $_GET_clone['order_by'] = $custom_parameters['order_by']; } unset($custom_parameters['order_by']); } if(!empty($custom_parameters)) $_GET_clone = array_merge($_GET_clone, $custom_parameters); $WMVC->model('listing_m'); $WMVC->model('field_m'); $WMVC->model('listingfield_m'); $smart_search = ''; if(isset($_GET_clone['search'])) $smart_search = sanitize_text_field($_GET_clone['search']); if(isset($_GET_clone['field_search'])) $smart_search = sanitize_text_field($_GET_clone['field_search']); if(!isset($available_fields_static[$model_name])) { $available_fields = $WMVC->$model_name->get_available_fields(); $available_fields_static[$model_name] = $available_fields; } else { $available_fields = $available_fields_static[$model_name]; } if($available_fields_listings === NULL) $available_fields_listings = $WMVC->listingfield_m->get_available_fields(); /* Пet column names from wdk_listings_fields and add to allow search + in _GET_clone replace field_#id to field_id_TYPE*/ if($list_fields_static === NULL) { $WMVC->db->where(array('field_type !='=> 'SECTION')); $list_fields = $WMVC->field_m->get(); $list_fields_static = $list_fields; } else { $list_fields = $list_fields_static; } foreach($list_fields as $field_data) { $field_id = wmvc_show_data('idfield',$field_data); $field_type = wmvc_show_data('field_type',$field_data); $column_name ='field_'.$field_id.'_'.$field_type; if(!isset($available_fields_listings[$column_name])) continue; if(isset($_GET_clone['field_'.$field_id])) { $_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); } if(isset($_GET_clone['field_'.$field_id.'_max'])) { $_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); } if(isset($_GET_clone['field_'.$field_id.'_min'])) { $_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); } if(isset($_GET_clone['field_'.$field_id.'_exactly'])) { $_GET_clone['field_'.$field_id.'_'.$field_type.'_exactly'] = sanitize_text_field($_GET_clone['field_'.$field_id.'_exactly']); } $columns[] = $column_name; $columns[] = $column_name.'_max'; $columns[] = $column_name.'_min'; $columns[] = $column_name.'_exactly'; $external_columns[] = $column_name; $external_columns[] = $column_name.'_max'; $external_columns[] = $column_name.'_min'; $external_columns[] = $column_name.'_exactly'; } if(isset($_GET_clone['search_location'])) { $column_name ='location_id'; $_GET_clone[$column_name] = $_GET_clone['search_location']; $columns[] = $column_name; $external_columns[] = $column_name; } if(isset($_GET_clone['search_category'])) { $column_name ='category_id'; $_GET_clone[$column_name] = $_GET_clone['search_category']; $columns[] = $column_name; $external_columns[] = $column_name; } if(isset($_GET_clone['field_address'])) { $column_name ='address'; $_GET_clone[$column_name] = $_GET_clone['field_address']; $columns[] = $column_name; $external_columns[] = $column_name; } if (function_exists('run_wdk_bookings') && isset($_GET_clone['field_booking_date_from'])) { $column_name ='field_booking_date_from'; $_GET_clone[$column_name] = $_GET_clone['field_booking_date_from']; $columns[] = $column_name; $external_columns[] = $column_name; } if (function_exists('run_wdk_bookings') && isset($_GET_clone['field_booking_date_to'])) { $column_name ='field_booking_date_to'; $_GET_clone[$column_name] = $_GET_clone['field_booking_date_to']; $columns[] = $column_name; $external_columns[] = $column_name; } //$table_name = substr($model_name, 0, -2); $columns_original = array(); foreach($columns as $key=>$val) { $columns_original[$val] = $val; // if column contain also "table_name.*" $splited = explode('.', $val); if(wmvc_count($splited) == 2) $val = $splited[1]; if(isset($available_fields[$val])) { } else { if(!in_array($columns[$key], $external_columns)) { unset($columns[$key]); } } } if(wmvc_count($_GET_clone) > 0) { unset($_GET_clone['search']); unset($_GET_clone['field_search']); // For quick/smart search if(wmvc_count($columns) > 0 && !empty($smart_search)) { $gen_q = ''; foreach($columns as $key=>$value) { if(substr_count($value, 'id') > 0 && is_numeric($smart_search)) { $gen_q.="$value = $smart_search OR "; } else if(substr_count($value, 'date') > 0) { $gen_search = $smart_search; $gen_q.="$value LIKE '%$gen_search%' OR "; } elseif(substr($value, -8) == '_exactly') { } elseif(substr($value, -4) == '_max') { } else if(substr($value, -4) == '_min') { } else { $gen_q.="$value LIKE '%$smart_search%' OR "; } } for($i = 1 ; $i <= 2; $i++){ $gen_q.="location_".$i.".location_title LIKE '%$smart_search%' OR "; } $gen_q = substr($gen_q, 0, -4); if(!empty($gen_q)) $WMVC->db->where("($gen_q)"); } // For column search if(isset($_GET_clone)) { $gen_q = ''; foreach($_GET_clone as $key=>$val) { if(!empty($val) && in_array($key, $columns)) { $col_name = $key; $val = esc_sql($val); //if(isset($key)) // $col_name = $key; if(strpos($key, 'skip') !== FALSE) continue; if($key == 'field_booking_date_from') { if(!$wdk_bookings_joinded){ $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'); $WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id'); $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'); $wdk_bookings_joinded = true; $gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND '; } if((bool)strtotime($val) && strtotime($val) > 1000) { if(!get_option('wdk_bookings_is_hours_enabled')) { $gen_search = date('Y-m-d', strtotime($val)); $gen_q.= "DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_price.date_from, '%Y-%m-%d') <= '".$gen_search."' AND "; } else { $gen_search = date('Y-m-d H:i:s', strtotime($val)); $gen_q.= $WMVC->db->prefix."wdk_booking_price.date_from >'".$gen_search."' AND "; } } if( isset($_GET_clone['field_booking_date_from']) && isset($_GET_clone['field_booking_date_to'])) { if(!get_option('wdk_bookings_is_hours_enabled')) { $gen_search_from = date('Y-m-d', strtotime($_GET_clone['field_booking_date_from'])); $gen_search_to = date('Y-m-d', strtotime($_GET_clone['field_booking_date_to'])); $gen_q.= $WMVC->listing_m->_table_name.".post_id NOT IN ( SELECT post_id FROM ".$WMVC->db->prefix."wdk_booking_reservation WHERE ".$WMVC->db->prefix."wdk_booking_reservation.is_approved = 1 AND DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_reservation.date_from, '%Y-%m-%d') < '".$gen_search_to."' AND DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_reservation.date_to, '%Y-%m-%d') > '".$gen_search_from."' ) AND "; } else { $gen_search_from = date('Y-m-d H:i:s', strtotime($_GET_clone['field_booking_date_from'])); $gen_search_to = date('Y-m-d H:i:s', strtotime($_GET_clone['field_booking_date_to'])); $gen_q.= $WMVC->listing_m->_table_name.".post_id NOT IN ( SELECT post_id FROM ".$WMVC->db->prefix."wdk_booking_reservation WHERE ".$WMVC->db->prefix."wdk_booking_reservation.is_approved = 1 AND ".$WMVC->db->prefix."wdk_booking_reservation.date_from < '".$gen_search_to."' AND ".$WMVC->db->prefix."wdk_booking_reservation.date_to > '".$gen_search_from."' ) AND "; } } } elseif($key == 'field_booking_date_to') { if(!$wdk_bookings_joinded){ $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'); $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'); $wdk_bookings_joinded = true; $gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND '; } if((bool)strtotime($val) && strtotime($val) > 1000) { if(!get_option('wdk_bookings_is_hours_enabled')) { $gen_search = date('Y-m-d', strtotime($val)); $gen_q.= "DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_price.date_to, '%Y-%m-%d') >= '".$gen_search."' AND "; } else { $gen_search = date('Y-m-d H:i:s', strtotime($val)); $gen_q.= $WMVC->db->prefix."wdk_booking_price.date_to >'".$gen_search."' AND "; } } } elseif(substr($key, -8) == '_exactly') { $col_name = substr($key, 0, -8); $gen_q.=$col_name." = '".$val."' AND "; } elseif(substr($key, -4) == '_max') { $col_name = substr($key, 0, -4); if(strpos($key, 'NUMBER') !== FALSE) { $gen_q.=$col_name." <= ".intval($val)." AND "; } else { $gen_q.=$col_name." <= '".$val."' AND "; } } else if(substr($key, -4) == '_min') { $col_name = substr($key, 0, -4); if(strpos($key, 'NUMBER') !== FALSE) { $gen_q.=$col_name." >= ".intval($val)." AND "; } else { $gen_q.=$col_name." >= '".$val."' AND "; } } elseif(substr_count($key, 'id') > 0 && is_numeric($val)) { // ID is always numeric if($key == 'location_id') { $gen_q .= "(`location_1`.`parent_path` = ".$val." OR "; $gen_q .= "`location_2`.`parent_path` = ".$val." OR "; $gen_q .= $col_name." = ".$val.") AND "; } elseif($key == 'category_id') { $gen_q .= "('parent_path' = ".$val." OR "; $gen_q .= $col_name." = ".$val.") AND "; } else { $gen_q.=$col_name." = ".$val." AND "; } } else if(substr_count($key, 'date') > 0) { // DATE VALUES $gen_search = $val; $detect_date = strtotime($gen_search); if(wdk_is_date($val) && $detect_date > 1000) { $gen_search = date('Y-m-d H:i:s', $detect_date); $gen_q.=$col_name." > '".$gen_search."' AND "; } else { $gen_q.=$col_name." LIKE '%".$gen_search."%' AND "; } } else if(substr_count($key, 'is_') > 0) { // CHECKBOXES if($val=='on') { $gen_search = 1; $gen_q.=$col_name." LIKE '%".$gen_search."%' AND "; } else if($val=='off') { $gen_q.=$col_name." IS NULL AND "; } } else { $gen_q.=$col_name." LIKE '%".$val."%' AND "; } } } $gen_q = substr($gen_q, 0, -5); if(!empty($gen_q)) $WMVC->db->where("($gen_q)"); } // order if(isset($_GET_clone['order_by'])) { $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_listings.post_id', $_GET_clone['order_by']); $WMVC->db->order_by($_GET_clone['order_by']); } } } function wdk_users_prepare_search_query_GET($columns = array(), $model_name = NULL, $external_columns = array(), $custom_parameters = array(), $skip_postget = FALSE) { global $Winter_MVC_WDK; $WMVC = &$Winter_MVC_WDK; $_GET_clone = array(); if(!$skip_postget) $_GET_clone = array_merge($_GET, $_POST); if(isset($custom_parameters['order_by'])) { if(isset($_GET_clone['order_by']) && !empty($_GET_clone['order_by'])) { $_GET_clone['order_by'] = $custom_parameters['order_by'].', '.$_GET_clone['order_by']; } else { $_GET_clone['order_by'] = $custom_parameters['order_by']; } unset($custom_parameters['order_by']); } if(!empty($custom_parameters)) $_GET_clone = array_merge($_GET_clone, $custom_parameters); $WMVC->model($model_name); $smart_search = ''; if(isset($_GET_clone['profile_search'])) $smart_search = sanitize_text_field($_GET_clone['profile_search']); $available_fields = array('user_login','user_nicename','user_email','user_url','display_name'); if(isset($_GET_clone['is_activated'])){ $_GET_clone[$WMVC->$model_name->_table_name.'.is_activated'] = sanitize_text_field($_GET_clone['is_activated']); unset($_GET_clone['is_activated']); } if(isset($_GET_clone['is_approved'])){ $_GET_clone[$WMVC->$model_name->_table_name.'.is_approved'] = sanitize_text_field($_GET_clone['is_approved']); unset($_GET_clone['is_approved']); } //$table_name = substr($model_name, 0, -2); $columns_original = array(); foreach($columns as $key=>$val) { $columns_original[$val] = $val; // if column contain also "table_name.*" $splited = explode('.', $val); if(wmvc_count($splited) == 2) $val = $splited[1]; if(isset($available_fields[$val])) { } else { if(!in_array($columns[$key], $external_columns)) { unset($columns[$key]); } } } if(wmvc_count($_GET_clone) > 0) { unset($_GET_clone['search']); // For quick/smart search if(wmvc_count($columns) > 0 && !empty($smart_search)) { $gen_q = ''; foreach($columns as $key=>$value) { if($value == 'post_type') { $value = $WMVC->$model_name->_table_name.'.'.$value; } if(substr_count($value, 'id') > 0 && is_numeric($smart_search)) { $gen_q.="$value = $smart_search OR "; } else if(substr_count($value, 'date') > 0) { //$gen_search = wmvc_generate_slug($smart_search, ' '); $gen_search = $smart_search; $gen_q.="$value LIKE '%$gen_search%' OR "; } else { $gen_q.="$value LIKE '%$smart_search%' OR "; } } $gen_q = substr($gen_q, 0, -4); if(!empty($gen_q)) $WMVC->db->where("($gen_q)"); } // For column search if(isset($_GET_clone)) { $gen_q = ''; foreach($_GET_clone as $key=>$val) { if(!empty($val) && in_array($key, $columns)) { $col_name = $key; if($col_name == 'post_type') { $col_name = $WMVC->$model_name->_table_name.'.'.$col_name; } //if(isset($key)) // $col_name = $key; if(strpos($key, 'skip') !== FALSE) continue; if(substr($key, -8) == '_exactly') { $col_name = substr($key, 0, -8); $gen_q.=$col_name." = '".$val."' AND "; } elseif(substr($key, -4) == '_max') { $col_name = substr($key, 0, -4); $gen_q.=$col_name." <= '".$val."' AND "; } else if(substr($key, -4) == '_min') { $col_name = substr($key, 0, -4); $gen_q.=$col_name." >= '".$val."' AND "; } elseif(substr_count($key, 'id') > 0 && is_numeric($val)) { // ID is always numeric $gen_q.=$col_name." = ".$val." AND "; } else if(substr_count($key, 'date') > 0) { // DATE VALUES $gen_search = $val; $detect_date = strtotime($gen_search); if(wdk_is_date($val) && $detect_date > 1000) { $gen_search = date('Y-m-d H:i:s', $detect_date); $gen_q.=$col_name." > '".$gen_search."' AND "; } else { $gen_q.=$col_name." LIKE '%".$gen_search."%' AND "; } } else if(substr_count($key, 'is_') > 0) { // CHECKBOXES if($val=='on') { $gen_search = 1; $gen_q.=$col_name." LIKE '%".$gen_search."%' AND "; } else if($val=='off') { $gen_q.=$col_name." IS NULL AND "; } } else { $gen_q.=$col_name." LIKE '%".$val."%' AND "; } } } $gen_q = substr($gen_q, 0, -5); if(!empty($gen_q)) $WMVC->db->where("($gen_q)"); } // order if(isset($_GET_clone['order_by'])) { $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_favorite.post_id', $_GET_clone['order_by']); $WMVC->db->order_by($_GET_clone['order_by']); } } } function wdk_date() { $date_format = get_option('date_format'); $time_format = get_option('time_format'); $date = date("{$date_format} {$time_format}", current_time('timestamp')); return $date; } if(!function_exists('wdk_placeholder_image_src')) { function wdk_placeholder_image_src () { $i = WPDIRECTORYKIT_URL.'/public/img/placeholder.jpg'; return $i; } } 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) { $current_page = 1; if(isset($_GET[$page_var])) $current_page = intval(wmvc_xss_clean($_GET[$page_var])); if(!isset($texts['previous_page']))$texts['previous_page'] = 'Previous page'; if(!isset($texts['next_page']))$texts['next_page'] = 'Next page'; if(!isset($texts['first_page']))$texts['first_page'] = ''; if(!isset($texts['last_page']))$texts['last_page'] = ''; if(!isset($texts['items']))$texts['items'] = 'items'; if(empty($current_page))$current_page = 1; // get url $url = strtok($_SERVER["REQUEST_URI"], '?'); $qs_parameters = wmvc_xss_clean( $_GET ); unset($qs_parameters[$page_var]); $qs_part = http_build_query($qs_parameters); $url.='?'.$qs_part; // total pages $total_pages = intval($total_items/$per_page+0.99); if($current_page == 1) { $limit_items = $limit_items * 2; } if($current_page == $total_pages) { $limit_items = $limit_items * 2; } $output = ''; return $output; } function wdk_viewe($content) { // @codingStandardsIgnoreStart echo wp_kses_post($content); // WPCS: XSS ok, sanitization ok. // @codingStandardsIgnoreEnd } if(!function_exists('wdk_search_fields_toggle')){ function wdk_search_fields_toggle ($class_add = NULL){ static $wdk_visible_filters = 0; global $wdk_visible_filters_limit; global $wdk_button_search_defined; global $wdk_enable_search_fields_toggle; global $wdk_activate_more; if(!$wdk_enable_search_fields_toggle) return false; $wdk_visible_filters++; if($wdk_activate_more || (!$wdk_button_search_defined && $wdk_visible_filters == $wdk_visible_filters_limit)){ $wdk_button_search_defined=true; $wdk_activate_more = false; global $wdk_text_search_button; if(empty($wdk_text_search_button)) $wdk_text_search_button = esc_html__('Search','wpdirectorykit'); global $wdk_text_more_button; if(empty($wdk_text_more_button)) $wdk_text_more_button = esc_html__('More','wpdirectorykit'); $form_closed = 'display: none;'; if(isset($_GET['wdk_search_additional_opened']) && wmvc_xss_clean($_GET['wdk_search_additional_opened']) == 1) { $form_closed = ''; } ?>
model($model_name); $attribute_id = $WMVC ->$model_name->_primary_key; $selected = (int) $selected; } if(empty($selected)) $selected=''; $form = ''; $skip_id = ''; //load javascript library if($counter==0) { wp_enqueue_script('wdk-treefield'); wp_enqueue_style('wdk-treefield'); } ?> format($format) == $date; } } if ( ! function_exists('wdk_url_suffix')) { function wdk_url_suffix($base_url, $extension_url="") { if(strpos($base_url,'?') !== FALSE){ $base_url .='&'; } else { $base_url .='?'; } return $base_url.$extension_url; } } /** * Insert an attachment from an URL address. * * @param String $url * @param Int $parent_post_id * @return Int Attachment ID */ function wdk_insert_attachment_from_url($url, $parent_post_id = null) { if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC . '/class-http.php' ); $http = new WP_Http(); $response = $http->request( $url ); if( is_wp_error($response) || $response['response']['code'] != 200 ) { return false; } $upload = wp_upload_bits( basename($url), null, $response['body'] ); if( !empty( $upload['error'] ) ) { return false; } $file_path = $upload['file']; $file_name = basename( $file_path ); $file_type = wp_check_filetype( $file_name, null ); $attachment_title = sanitize_file_name( pathinfo( $file_name, PATHINFO_FILENAME ) ); $wp_upload_dir = wp_upload_dir(); $post_info = array( 'guid' => $wp_upload_dir['url'] . '/' . $file_name, 'post_mime_type' => $file_type['type'], 'post_title' => $attachment_title, 'post_content' => '', 'post_status' => 'inherit', ); // Create the attachment $attach_id = wp_insert_attachment( $post_info, $file_path, $parent_post_id ); // Include image.php require_once( ABSPATH . 'wp-admin/includes/image.php' ); // Define attachment metadata $attach_data = wp_generate_attachment_metadata( $attach_id, $file_path ); // Assign metadata to attachment wp_update_attachment_metadata( $attach_id, $attach_data ); return $attach_id; } if(!function_exists('wdk_jsdateformat')) { function wdk_jsdateformat($format = '') { $date_specific = array( // Day 'd' => 'dd', 'D' => 'D', 'j' => 'd', 'l' => 'DD', 'N' => '', 'S' => '', 'w' => '', 'z' => 'o', // Week 'W' => '', // Month 'F' => 'MM', 'm' => 'mm', 'M' => 'M', 'n' => 'm', 't' => '', // Year 'L' => '', 'o' => '', 'y' => 'y', 'Y' => 'yy', // Time 'a' => '', 'A' => '', 'B' => '', 'g' => '', 'G' => '', 'h' => '', 'H' => '', 'i' => '', 's' => '', 'u' => '' ); return str_replace(array_keys($date_specific), array_values($date_specific), $format); } } function wdk_current_url() { global $wp; return add_query_arg( $wp->query_vars, home_url( $wp->request ) ); } if(!function_exists('wdk_generate_profile_permalink')) { /** * Insert user id and return link on user profile page * * @return Int user ID */ function wdk_generate_profile_permalink($profile = array()) { $profile_slug = ''; if(wmvc_show_data('user_login', $profile, false)){ $profile_slug = wmvc_show_data('user_login', $profile); } else if(is_intval($profile)){ $profile_data = get_userdata($profile); if(wmvc_show_data('user_login', $profile_data, false)){ $profile_slug = wmvc_show_data('user_login', $profile_data); } else { $profile_slug = $profile; } } $user_profile_page = get_option('wdk_membership_profile_preview_page'); if(!$user_profile_page) { return '#'; } // for polylang to detect translated page version if(function_exists('pll_get_post')) $user_profile_page = pll_get_post($user_profile_page); return wdk_url_suffix(get_permalink($user_profile_page), 'slug='. $profile_slug); } } if(!function_exists('wdk_get_profile_page_id')) { /** * Insert user id and return link on user profile page * * @return Int user ID */ function wdk_get_profile_page_id() { global $wp_query; if(get_option('wdk_membership_profile_preview_page') && isset($wp_query->post) && get_option('wdk_membership_profile_preview_page') == $wp_query->post->ID) { if (wmvc_show_data('slug', $_GET, false)) { if(is_intval(wmvc_show_data('slug', $_GET))) { return wmvc_show_data('slug', $_GET); } else { $profile = get_user_by('login',wmvc_show_data('slug', $_GET)); return (wmvc_show_data('ID', $profile, false)) ? wmvc_show_data('ID', $profile, false) : false; } } } return false; } } if(!function_exists('wdk_get_date')) { /** * Return date in format * */ function wdk_get_date($datetime = NULL, $time = TRUE, $default='timestamp') { if(is_null($datetime)) { if($default == 'timestamp') { $datetime = current_time('timestamp'); } else { return $default; } } else if(!is_numeric($datetime)) { $datetime = strtotime($datetime); } $date_format = get_option('date_format'); $time_format = ($time) ? get_option('time_format') : ''; $date = date_i18n("{$date_format} {$time_format}", $datetime); return $date; } } if(!function_exists('wdk_login_url')) { /** * Return date in format * @param string|url redirect url * @param string custom_message, showed on login form like alert, visible only on wdk login form */ function wdk_login_url($url_redirect = NULL, $custom_message = '') { $url = wp_login_url($url_redirect); if(get_option('wdk_membership_login_page')){ $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')), 'redirect_to='. urlencode($url_redirect).'&custom_message='. urlencode($custom_message)); } return $url; } } if(!function_exists('wdk_mail')) { /** * Return date in format * @param string|url redirect url */ function wdk_mail( $email_to, $subject = '', $data = array(), $layout = 'default', $email_from = '', $attachments = array(), $reply_to = '') { $WMVC = &wdk_get_instance(); $ret = false; if(empty($email_from)) $email_from = get_bloginfo('admin_email'); if(empty($subject)) $subject = __("New message", "wpdirectorykit"); $headers = array('Content-Type: text/html; charset=UTF-8'); $headers[] = 'From: '.$email_from; if(!empty($reply_to)) { $headers[] = 'Reply-To: '.$reply_to; } else { $headers[] = 'Reply-To: '.$email_from; } $data['subject'] = $subject; $message = $WMVC->view('email/'.$layout, $data, FALSE); $ret = wp_mail( $email_to, $subject, $message, $headers, $attachments ); return $ret; } } if(!function_exists('wdk_show_data')) { function wdk_show_data($field_name, &$db_value = NULL, $default = '', $xss_clean = TRUE, $skip_post = FALSE) { if(!$skip_post && isset($_POST[$field_name])) { if($xss_clean === FALSE) return stripslashes($_POST[$field_name]); return wmvc_xss_clean(stripslashes($_POST[$field_name])); } if(is_array($db_value)) { if(isset($db_value[$field_name])) { if($xss_clean === FALSE) return $db_value[$field_name]; return wmvc_xss_clean($db_value[$field_name]); } else { return $default; } } if(is_object($db_value)) { if(isset($db_value->$field_name)) { if($xss_clean === FALSE) return $db_value->$field_name; return wmvc_xss_clean($db_value->$field_name); } else { return $default; } } if(!empty($db_value)) { if($xss_clean === FALSE) return $db_value; return wmvc_xss_clean($db_value); } if($xss_clean === FALSE) return $default; return wmvc_xss_clean($default); } } if (!function_exists('wdk_input_checked')) { function wdk_input_checked($field_id, $db_data, $value = 1) { if(wmvc_show_data($field_id, $db_data, false) && wmvc_show_data($field_id, $db_data) == $value) { return 'checked'; } return ''; } } function wdk_upload_file($field_name, $file_id) { static $media_element_counter = 0; $media_element_counter++; $img_field = $field_name.'_'.$media_element_counter; wp_register_script( 'wpmediaelement_file', WPDIRECTORYKIT_URL . 'admin/js/jquery.wpmediaelement_file.js', array( 'jquery' ), false, false ); wp_enqueue_script( 'wpmediaelement_file' ); wp_enqueue_media(); ?> ".$custom_js.""; ?> model($model_name); if(empty($item_id) || $WMVC->$model_name->is_related($item_id, $user_id, $method)) { // User is related return true; } else { //echo $CI->db->last_query(); exit('Access denied ROLES RELATED'); } } else { return true; } exit('Access denied ROLES'); } } if ( ! function_exists('wdk_recaptcha_field')) { function wdk_recaptcha_field($is_compact=false, $style="", $load_script=true) { static $counter = 0; static $recaptcha_array = array(); if(get_option('wdk_recaptcha_site_key') !== FALSE && get_option('wdk_recaptcha_secret_key') !== NULL) { if($load_script && $counter===0) { echo ""; } $counter++; $compact_tag=''; $size_tag=''; if($is_compact) { $compact_tag='data-size="compact"'; $size_tag='compact'; } $recaptcha_array[$counter] = array('size'=>$size_tag); echo '
'; ?> 200, 'blocking' => true, 'headers' => array(), 'body' => array( 'secret' => get_option('wdk_recaptcha_secret_key'), 'response' => $g_recaptcha_response, 'remoteip' => sanitize_textarea_field($_SERVER['REMOTE_ADDR']) ), 'cookies' => array() ); $response = wp_remote_post( $url, $args ); if ( is_wp_error( $response ) ) { /*$error_message = $response->get_error_message();*/ return true; } else { $response = json_decode($response['body']); return $response->success; } } if(!function_exists('wdk_get_option')) { /** * Cached and get wp options * * @param string option Option key * @return string alt or title */ function wdk_get_option($option_key = '') { return get_option($option_key); if(isset($options[$option_key])) { return $options[$option_key]; } $options[$option_key] = get_option($option_key); return $options[$option_key]; } } if(!function_exists('wdk_server_current_url')) { /** * Get current url basic on $_SERVER, exists function wdk_current_url(), on some urls have issue on listing preview page * * @return string url */ function wdk_server_current_url() { return (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; } } if(!function_exists('wdk_filter_date_decimal')) { /** * Filter 00:00:00 from date * * @param string * @return string date without 00:00:00 */ function wdk_filter_date_decimal($data) { return str_replace(' 00:00:00','', $data); } } function wdk_get_post() { $post = array(); foreach($_POST as $key => $val) { if(is_array($val)) { return wdk_clean($_POST); } else { $post[sanitize_text_field($key)] = wp_kses_post($val); } } return $post; } function wdk_get_get() { $log_array = array(); foreach($_GET as $key => $val) { if(is_array($val)) { return wdk_clean($_POST); } else { $log_array[sanitize_text_field($key)] = wp_kses_post($val); } } return $log_array; } function wdk_clean($array) { $arr_cleaned = array(); foreach($array as $key=>$val) { if(is_array($val)) { $arr_cleaned[sanitize_text_field($key)] = wdk_clean($val); } else { $arr_cleaned[sanitize_text_field($key)] = wp_kses_post($val); } } //dump($arr_cleaned); return $arr_cleaned; } ?>