'; var_dump($data); echo ''; } /** * check data * * @param [type] $data * @param [type] $key * @return bool */ public function check_data($data, $key) { return (isset($data[$key]) && !empty($data[$key])) ? true : false; } /** * Required input attributes * * @param [type] $data * @return void */ public function required($data) { echo $this->check_data($data, 'is_required') ? 'required="required"' : ''; } public function required_html($data) { echo $this->check_data($data, 'is_required') ? ' *' : ''; } /** * is admin only */ public function admin_view($data) { return $this->check_data($data, 'admin_view') ? current_user_can('manage_options') : true; } /** * Get Data */ public function get_data($data = array(), $key = '', $default = '') { return $this->check_data($data, $key) ? $data[$key] : $default; } /** * Meta Value for adding */ public function meta_val($post_id = 0, $meta_key = '', $default = '') { return !empty(get_post_meta($post_id, $meta_key, true)) ? get_post_meta($post_id, $meta_key, true) : $default; } /** * Meta Post Data */ public function post_data($post = array(), $meta_key = '', $default = '') { return isset($post[$meta_key]) ? $post[$meta_key] : $default; } /** * Get File name From Folder */ public function file_name_from_folder($path = '', $ext = 'php') { $filenames = glob($path); $filenames = array_map( function ($path) use ($ext) { return basename($path, ".{$ext}"); }, $filenames ); return $filenames; } /** * Text to slug generate * * @param [type] $str * @param string $delimiter * @return string */ public function text_to_slug($str, $delimiter = '-') { $slug = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter)); return $slug; } /** * determine Video Url Type * * @param [type] $url * @return array */ public function determineVideoUrlType($url) { if (empty($url)) { return array(); } $yt_rx = '/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$/'; $has_match_youtube = preg_match($yt_rx, $url, $yt_matches); $vm_rx = '/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/'; $has_match_vimeo = preg_match($vm_rx, $url, $vm_matches); // Then we want the video id which is: if ($has_match_youtube) { $video_id = $yt_matches[5] ?? ''; $type = 'youtube'; } elseif ($has_match_vimeo) { $video_id = $vm_matches[5] ?? ''; $type = 'vimeo'; } else { $video_id = 0; $type = 'none'; } $data['video_id'] = $video_id; $data['video_type'] = $type; return $data; } /** * Get review rating * * @return $maxPrice */ public function get_author_ratings($author_id = 0) { if (empty($author_id)) { return 0; } global $wpdb; $cache_key = "adqs_authlrRatings_{$author_id}"; $authlrRatings = wp_cache_get($cache_key, 'adqs_cache'); if ($authlrRatings === false) { $query = $wpdb->prepare( "SELECT AVG(meta_value) FROM $wpdb->postmeta WHERE meta_key = 'adqs_avg_ratings' AND post_id IN ( SELECT ID FROM $wpdb->posts WHERE post_type = 'adqs_directory' AND post_status = 'publish' AND post_author = %d )", $author_id ); $authlrRatings = $wpdb->get_var($query); wp_cache_set($cache_key, $authlrRatings, 'adqs_cache'); } $authlrRatings = $authlrRatings ? round($authlrRatings, 1) : ''; $current_rating = get_user_meta($author_id, 'adqs_agent_rating', true); if ($authlrRatings !== $current_rating) { update_user_meta($author_id, 'adqs_agent_rating', $authlrRatings); } return $current_rating; } /** * Get review count * * @return $maxPrice */ public function get_author_review_count($author_id = 0) { if (empty($author_id)) { return; } global $wpdb; $authlrReviewCount = wp_cache_get("adqs_authlrReviewCount_{$author_id}", 'adqs_cache'); if ($authlrReviewCount === false) { $authlrReviewCount = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID IN(SELECT ID FROM $wpdb->posts WHERE post_type='adqs_directory' AND post_status='publish' AND post_author=%d)", $author_id ) ); wp_cache_set("adqs_authlrReviewCount_{$author_id}", $authlrReviewCount, 'adqs_cache'); } $authlrReviewCount = !empty($authlrReviewCount) ? $authlrReviewCount : false; $current_review = get_user_meta($author_id, 'adqs_agent_review', true); if ($authlrReviewCount !== $current_review) { update_user_meta($author_id, 'adqs_agent_review', $authlrReviewCount); } return $current_review; } /** * Get Max Price * * @return $maxPrice */ public function get_maxPrice() { global $wpdb; $maxPrice = wp_cache_get('adqs_maxPrice', 'adqs_cache'); if ($maxPrice === false) { $maxPrice = $wpdb->get_var("SELECT MAX(CAST(meta_value AS DECIMAL(10, 0))) AS max_numeric_price FROM {$wpdb->postmeta} WHERE meta_key = '_price' AND meta_value REGEXP '^[0-9]+\.?[0-9]*$' AND post_id IN (SELECT ID FROM {$wpdb->posts} WHERE post_type='adqs_directory' AND post_status='publish')"); wp_cache_set('adqs_maxPrice', $maxPrice, 'adqs_cache'); } return !empty($maxPrice) ? $maxPrice : false; } /** * Price * * @param [type] $post_id * @return string */ public function get_price($post_id) { $priceRangeTypes = apply_filters( 'adqs_meta_price_range', array( 'skimming' => esc_html__('High ($$$$)', 'adirectory'), 'moderate' => esc_html__('Expensive ($$$)', 'adirectory'), 'economy' => esc_html__('Moderate ($$)', 'adirectory'), 'bellow_economy' => esc_html__('Cheap ($)', 'adirectory'), ) ); $value_price = $this->meta_val($post_id, '_price') ?? ''; $value_price_sub = $this->meta_val($post_id, '_price_sub'); $value_price_range = $this->meta_val($post_id, '_price_range'); $value_price_type = $this->meta_val($post_id, '_price_type'); if ($value_price_type === '_price_range') { return $priceRangeTypes[$value_price_range] ?? ''; } else { $value_price = apply_filters('adqs_listing_price', $value_price); $value_price_sub = !empty($value_price_sub) ? "{$value_price_sub}" : ''; $price = adqs_get_price_ws($value_price); return join(' ', array_filter([$price, $value_price_sub])); } } /** * Comment Review Html * * @param integer $ratings * @return void */ public function get_review_rating_html($ratings = 0) { $ratings = !empty($ratings) ? floatval($ratings) : 0; $stars = '