@@ -67,77 +67,77 @@ discard block |
||
67 | 67 | */ |
68 | 68 | function geodir_draw_map($map_args = array()) |
69 | 69 | { |
70 | - global $map_canvas_arr; |
|
71 | - $map_canvas_name = (!empty($map_args) && $map_args['map_canvas_name'] != '') ? $map_args['map_canvas_name'] : 'home_map_canvas'; |
|
72 | - $map_class_name = (!empty($map_args) && isset($map_args['map_class_name'])) ? $map_args['map_class_name'] : ''; |
|
73 | - |
|
74 | - $default_location = geodir_get_default_location(); |
|
75 | - |
|
76 | - $map_default_lat = isset($default_location->city_latitude) ? $default_location->city_latitude : ''; |
|
77 | - $map_default_lng = isset($default_location->city_longitude) ? $default_location->city_longitude : ''; |
|
78 | - $map_default_zoom = 12; |
|
79 | - // map options default values |
|
80 | - $width = 950; |
|
81 | - $height = 450; |
|
82 | - $child_collapse = '0'; |
|
83 | - $sticky = ''; |
|
84 | - $enable_cat_filters = false; |
|
85 | - $enable_text_search = false; |
|
86 | - $enable_post_type_filters = false; |
|
87 | - $enable_location_filters = false; |
|
88 | - $enable_jason_on_load = false; |
|
89 | - $enable_map_direction = false; |
|
90 | - $enable_marker_cluster = false; |
|
91 | - $enable_map_resize_button = false; |
|
92 | - $maptype = 'ROADMAP'; |
|
93 | - |
|
94 | - $geodir_map_options = array( |
|
95 | - 'width' => $width, |
|
96 | - 'height' => $height, |
|
97 | - 'child_collapse' => $child_collapse, |
|
98 | - 'sticky' => $sticky, |
|
99 | - 'enable_map_resize_button' => $enable_map_resize_button, |
|
100 | - 'enable_cat_filters' => $enable_cat_filters, |
|
101 | - 'enable_text_search' => $enable_text_search, |
|
102 | - 'enable_post_type_filters' => $enable_post_type_filters, |
|
103 | - 'enable_location_filters' => $enable_location_filters, |
|
104 | - 'enable_jason_on_load' => $enable_jason_on_load, |
|
105 | - 'enable_map_direction' => $enable_map_direction, |
|
106 | - 'enable_marker_cluster' => $enable_marker_cluster, |
|
107 | - 'ajax_url' => geodir_get_ajax_url(), |
|
108 | - 'map_canvas_name' => $map_canvas_name, |
|
109 | - 'inputText' => __('Title or Keyword', 'geodirectory'), |
|
110 | - 'latitude' => $map_default_lat, |
|
111 | - 'longitude' => $map_default_lng, |
|
112 | - 'zoom' => $map_default_zoom, |
|
113 | - 'scrollwheel' => true, |
|
114 | - 'streetViewControl' => true, |
|
115 | - 'maptype' => $maptype, |
|
116 | - 'showPreview' => '0', |
|
117 | - 'maxZoom' => 21, |
|
118 | - 'autozoom' => true, |
|
119 | - 'bubble_size' => 'small', |
|
120 | - 'token' => '68f48005e256696074e1da9bf9f67f06', |
|
121 | - 'navigationControlOptions' => array('position' => 'TOP_LEFT', 'style' => 'ZOOM_PAN') |
|
122 | - ); |
|
123 | - |
|
124 | - if (!empty($map_args)) { |
|
125 | - foreach ($map_args as $map_option_key => $map_option_value) { |
|
126 | - $geodir_map_options[$map_option_key] = $map_option_value; |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - if (strpos($geodir_map_options['height'], '%') !== false || strpos($geodir_map_options['height'], 'px') !== false || strpos($geodir_map_options['height'], 'vh') !== false) { |
|
131 | - } else { |
|
132 | - $geodir_map_options['height'] = $geodir_map_options['height'] . 'px'; |
|
133 | - } |
|
134 | - |
|
135 | - if (strpos($geodir_map_options['width'], '%') !== false || strpos($geodir_map_options['width'], 'px') !== false) { |
|
136 | - } else { |
|
137 | - $geodir_map_options['width'] = $geodir_map_options['width'] . 'px'; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
70 | + global $map_canvas_arr; |
|
71 | + $map_canvas_name = (!empty($map_args) && $map_args['map_canvas_name'] != '') ? $map_args['map_canvas_name'] : 'home_map_canvas'; |
|
72 | + $map_class_name = (!empty($map_args) && isset($map_args['map_class_name'])) ? $map_args['map_class_name'] : ''; |
|
73 | + |
|
74 | + $default_location = geodir_get_default_location(); |
|
75 | + |
|
76 | + $map_default_lat = isset($default_location->city_latitude) ? $default_location->city_latitude : ''; |
|
77 | + $map_default_lng = isset($default_location->city_longitude) ? $default_location->city_longitude : ''; |
|
78 | + $map_default_zoom = 12; |
|
79 | + // map options default values |
|
80 | + $width = 950; |
|
81 | + $height = 450; |
|
82 | + $child_collapse = '0'; |
|
83 | + $sticky = ''; |
|
84 | + $enable_cat_filters = false; |
|
85 | + $enable_text_search = false; |
|
86 | + $enable_post_type_filters = false; |
|
87 | + $enable_location_filters = false; |
|
88 | + $enable_jason_on_load = false; |
|
89 | + $enable_map_direction = false; |
|
90 | + $enable_marker_cluster = false; |
|
91 | + $enable_map_resize_button = false; |
|
92 | + $maptype = 'ROADMAP'; |
|
93 | + |
|
94 | + $geodir_map_options = array( |
|
95 | + 'width' => $width, |
|
96 | + 'height' => $height, |
|
97 | + 'child_collapse' => $child_collapse, |
|
98 | + 'sticky' => $sticky, |
|
99 | + 'enable_map_resize_button' => $enable_map_resize_button, |
|
100 | + 'enable_cat_filters' => $enable_cat_filters, |
|
101 | + 'enable_text_search' => $enable_text_search, |
|
102 | + 'enable_post_type_filters' => $enable_post_type_filters, |
|
103 | + 'enable_location_filters' => $enable_location_filters, |
|
104 | + 'enable_jason_on_load' => $enable_jason_on_load, |
|
105 | + 'enable_map_direction' => $enable_map_direction, |
|
106 | + 'enable_marker_cluster' => $enable_marker_cluster, |
|
107 | + 'ajax_url' => geodir_get_ajax_url(), |
|
108 | + 'map_canvas_name' => $map_canvas_name, |
|
109 | + 'inputText' => __('Title or Keyword', 'geodirectory'), |
|
110 | + 'latitude' => $map_default_lat, |
|
111 | + 'longitude' => $map_default_lng, |
|
112 | + 'zoom' => $map_default_zoom, |
|
113 | + 'scrollwheel' => true, |
|
114 | + 'streetViewControl' => true, |
|
115 | + 'maptype' => $maptype, |
|
116 | + 'showPreview' => '0', |
|
117 | + 'maxZoom' => 21, |
|
118 | + 'autozoom' => true, |
|
119 | + 'bubble_size' => 'small', |
|
120 | + 'token' => '68f48005e256696074e1da9bf9f67f06', |
|
121 | + 'navigationControlOptions' => array('position' => 'TOP_LEFT', 'style' => 'ZOOM_PAN') |
|
122 | + ); |
|
123 | + |
|
124 | + if (!empty($map_args)) { |
|
125 | + foreach ($map_args as $map_option_key => $map_option_value) { |
|
126 | + $geodir_map_options[$map_option_key] = $map_option_value; |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + if (strpos($geodir_map_options['height'], '%') !== false || strpos($geodir_map_options['height'], 'px') !== false || strpos($geodir_map_options['height'], 'vh') !== false) { |
|
131 | + } else { |
|
132 | + $geodir_map_options['height'] = $geodir_map_options['height'] . 'px'; |
|
133 | + } |
|
134 | + |
|
135 | + if (strpos($geodir_map_options['width'], '%') !== false || strpos($geodir_map_options['width'], 'px') !== false) { |
|
136 | + } else { |
|
137 | + $geodir_map_options['width'] = $geodir_map_options['width'] . 'px'; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | 141 | * Filter the options to use in google map. |
142 | 142 | * |
143 | 143 | * @since 1.0.0 |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | */ |
147 | 147 | $geodir_map_options = apply_filters("geodir_map_options_{$map_canvas_name}", $geodir_map_options); |
148 | 148 | |
149 | - $map_canvas_arr[$map_canvas_name] = array(); |
|
149 | + $map_canvas_arr[$map_canvas_name] = array(); |
|
150 | 150 | |
151 | - /** |
|
151 | + /** |
|
152 | 152 | * Filter the post types to display data on map. |
153 | 153 | * |
154 | 154 | * @since 1.0.0 |
@@ -166,20 +166,20 @@ discard block |
||
166 | 166 | */ |
167 | 167 | $exclude_post_types = apply_filters("geodir_exclude_post_type_on_map_{$map_canvas_name}", get_option('geodir_exclude_post_type_on_map')); |
168 | 168 | |
169 | - if (count((array)$post_types) != count($exclude_post_types) || ($enable_jason_on_load)): |
|
170 | - // Set default map options |
|
169 | + if (count((array)$post_types) != count($exclude_post_types) || ($enable_jason_on_load)): |
|
170 | + // Set default map options |
|
171 | 171 | |
172 | - wp_enqueue_script('geodir-map-widget', geodir_plugin_url() . '/geodirectory-functions/map-functions/js/map.min.js',array(),false,true); |
|
172 | + wp_enqueue_script('geodir-map-widget', geodir_plugin_url() . '/geodirectory-functions/map-functions/js/map.min.js',array(),false,true); |
|
173 | 173 | |
174 | - wp_localize_script('geodir-map-widget', $map_canvas_name, $geodir_map_options); |
|
174 | + wp_localize_script('geodir-map-widget', $map_canvas_name, $geodir_map_options); |
|
175 | 175 | |
176 | - if ($map_canvas_name == 'detail_page_map_canvas' || $map_canvas_name == 'preview_map_canvas') { |
|
177 | - $map_width = '100%'; |
|
178 | - } else { |
|
179 | - $map_width = $geodir_map_options['width']; |
|
180 | - } |
|
176 | + if ($map_canvas_name == 'detail_page_map_canvas' || $map_canvas_name == 'preview_map_canvas') { |
|
177 | + $map_width = '100%'; |
|
178 | + } else { |
|
179 | + $map_width = $geodir_map_options['width']; |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
182 | + /** |
|
183 | 183 | * Filter the width of map. |
184 | 184 | * |
185 | 185 | * @since 1.0.0 |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param int $map_width Width of map box, eg: gd_place. |
188 | 188 | */ |
189 | 189 | $map_width = apply_filters('geodir_change_map_width', $map_width); |
190 | - ?> |
|
190 | + ?> |
|
191 | 191 | <div id="catcher_<?php echo $map_canvas_name;?>"></div> |
192 | 192 | <div class="stick_trigger_container"> |
193 | 193 | <div class="trigger_sticky triggeroff_sticky"></div> |
@@ -221,15 +221,15 @@ discard block |
||
221 | 221 | <?php if ($geodir_map_options['enable_jason_on_load']) { ?> |
222 | 222 | <input type="hidden" id="<?php echo $map_canvas_name;?>_jason_enabled" value="1"/> |
223 | 223 | <?php } else { |
224 | - ?> |
|
224 | + ?> |
|
225 | 225 | <input type="hidden" id="<?php echo $map_canvas_name;?>_jason_enabled" value="0"/> |
226 | 226 | <?php } |
227 | 227 | |
228 | - if (!$geodir_map_options['enable_text_search'] && !$geodir_map_options['enable_cat_filters']) |
|
229 | - $show_entire_cat_panel = "none"; |
|
230 | - else |
|
231 | - $show_entire_cat_panel = "''"; |
|
232 | - ?> |
|
228 | + if (!$geodir_map_options['enable_text_search'] && !$geodir_map_options['enable_cat_filters']) |
|
229 | + $show_entire_cat_panel = "none"; |
|
230 | + else |
|
231 | + $show_entire_cat_panel = "''"; |
|
232 | + ?> |
|
233 | 233 | |
234 | 234 | <?php if ($geodir_map_options['enable_map_direction']) { ?> |
235 | 235 | <div class="gd-input-group gd-get-directions"> |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | <select id="travel-units" onchange="calcRoute('<?php echo $map_canvas_name; ?>')"> |
293 | 293 | <option value="miles"><?php _e('Miles', 'geodirectory'); ?></option> |
294 | 294 | <option <?php if (get_option('geodir_search_dist_1') == 'km') { |
295 | - echo 'selected="selected"'; |
|
296 | - } ?> value="kilometers"><?php _e('Kilometers', 'geodirectory'); ?></option> |
|
295 | + echo 'selected="selected"'; |
|
296 | + } ?> value="kilometers"><?php _e('Kilometers', 'geodirectory'); ?></option> |
|
297 | 297 | </select> |
298 | 298 | </div> |
299 | 299 | |
@@ -305,12 +305,12 @@ discard block |
||
305 | 305 | if (empty($geodir_default_map_search_pt)) |
306 | 306 | $geodir_default_map_search_pt = 'gd_place'; |
307 | 307 | |
308 | - global $gd_session; |
|
309 | - $homemap_catlist_ptype = $gd_session->get('homemap_catlist_ptype'); |
|
308 | + global $gd_session; |
|
309 | + $homemap_catlist_ptype = $gd_session->get('homemap_catlist_ptype'); |
|
310 | 310 | |
311 | - if ($homemap_catlist_ptype) { |
|
312 | - $geodir_default_map_search_pt = $homemap_catlist_ptype; |
|
313 | - } |
|
311 | + if ($homemap_catlist_ptype) { |
|
312 | + $geodir_default_map_search_pt = $homemap_catlist_ptype; |
|
313 | + } |
|
314 | 314 | |
315 | 315 | /** |
316 | 316 | * Filter the post type to retrieve data for map |
@@ -323,13 +323,13 @@ discard block |
||
323 | 323 | ?> |
324 | 324 | <div class="map-category-listing-main" style="display:<?php echo $show_entire_cat_panel;?>"> |
325 | 325 | <?php |
326 | - $exclude_post_types = get_option('geodir_exclude_post_type_on_map'); |
|
327 | - $geodir_available_pt_on_map = count(geodir_get_posttypes('array')) - count($exclude_post_types); |
|
326 | + $exclude_post_types = get_option('geodir_exclude_post_type_on_map'); |
|
327 | + $geodir_available_pt_on_map = count(geodir_get_posttypes('array')) - count($exclude_post_types); |
|
328 | 328 | $map_cat_class = ''; |
329 | 329 | if ($geodir_map_options['enable_post_type_filters']) { |
330 | 330 | $map_cat_class = $geodir_available_pt_on_map > 1 ? ' map-cat-ptypes' : ' map-cat-floor'; |
331 | 331 | } |
332 | - ?> |
|
332 | + ?> |
|
333 | 333 | <div |
334 | 334 | class="map-category-listing<?php echo $map_cat_class;?>"> |
335 | 335 | <div class="gd-trigger gd-triggeroff"><i class="fa fa-compress"></i><i class="fa fa-expand"></i></div> |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | <?php if ($geodir_map_options['child_collapse']) { $child_collapse = "1"; ?> |
348 | 348 | <input type="hidden" id="<?php echo $map_canvas_name; ?>_child_collapse" value="1"/> |
349 | 349 | <?php } else {$child_collapse = "0"; |
350 | - ?> |
|
350 | + ?> |
|
351 | 351 | <input type="hidden" id="<?php echo $map_canvas_name;?>_child_collapse" value="0"/> |
352 | 352 | <?php } ?> |
353 | 353 | <input type="hidden" id="<?php echo $map_canvas_name; ?>_cat_enabled" value="1"/> |
@@ -369,17 +369,17 @@ discard block |
||
369 | 369 | <!-- map-category-listings--> |
370 | 370 | |
371 | 371 | <?php |
372 | - if ($geodir_map_options['enable_location_filters']) { |
|
372 | + if ($geodir_map_options['enable_location_filters']) { |
|
373 | 373 | $country = get_query_var('gd_country'); |
374 | 374 | $region = get_query_var('gd_region'); |
375 | 375 | $city = get_query_var('gd_city'); |
376 | 376 | |
377 | - //fix for location/me page |
|
378 | - $country = $country != 'me' ? $country : ''; |
|
377 | + //fix for location/me page |
|
378 | + $country = $country != 'me' ? $country : ''; |
|
379 | 379 | $region = $region != 'me' ? $region : ''; |
380 | 380 | $city = $country != 'me' ? $city : ''; |
381 | - $gd_neighbourhood = isset($_REQUEST['gd_neighbourhood']) ? sanitize_text_field($_REQUEST['gd_neighbourhood']) : ''; |
|
382 | - ?> |
|
381 | + $gd_neighbourhood = isset($_REQUEST['gd_neighbourhood']) ? sanitize_text_field($_REQUEST['gd_neighbourhood']) : ''; |
|
382 | + ?> |
|
383 | 383 | <input type="hidden" id="<?php echo $map_canvas_name;?>_location_enabled" value="1"/> |
384 | 384 | <input type="hidden" id="<?php echo $map_canvas_name;?>_country" name="gd_country" |
385 | 385 | value="<?php echo $country;?>"/> |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | <input type="hidden" id="<?php echo $map_canvas_name;?>_neighbourhood" name="gd_neighbourhood" |
391 | 391 | value="<?php echo $gd_neighbourhood;?>"/> |
392 | 392 | <?php } else { //end of location filter |
393 | - ?> |
|
393 | + ?> |
|
394 | 394 | <input type="hidden" id="<?php echo $map_canvas_name;?>_location_enabled" value="0"/> |
395 | 395 | <?php }?> |
396 | 396 | |
@@ -401,16 +401,16 @@ discard block |
||
401 | 401 | |
402 | 402 | |
403 | 403 | <?php if ($geodir_map_options['enable_post_type_filters']) { |
404 | - $post_types = geodir_get_posttypes('object'); |
|
405 | - $all_post_types = geodir_get_posttypes('names'); |
|
406 | - $exclude_post_types = get_option('geodir_exclude_post_type_on_map'); |
|
407 | - if (is_array($exclude_post_types)) { |
|
408 | - $map_post_types = array_diff($all_post_types, $exclude_post_types); |
|
409 | - } else { |
|
410 | - $map_post_types = $all_post_types; |
|
411 | - } |
|
412 | - if (count($map_post_types) > 1) { |
|
413 | - ?> |
|
404 | + $post_types = geodir_get_posttypes('object'); |
|
405 | + $all_post_types = geodir_get_posttypes('names'); |
|
406 | + $exclude_post_types = get_option('geodir_exclude_post_type_on_map'); |
|
407 | + if (is_array($exclude_post_types)) { |
|
408 | + $map_post_types = array_diff($all_post_types, $exclude_post_types); |
|
409 | + } else { |
|
410 | + $map_post_types = $all_post_types; |
|
411 | + } |
|
412 | + if (count($map_post_types) > 1) { |
|
413 | + ?> |
|
414 | 414 | <div class="map-places-listing" id="<?php echo $map_canvas_name;?>_posttype_menu" |
415 | 415 | style="max-width:<?php echo $map_width;?>!important;"> |
416 | 416 | |
@@ -420,13 +420,13 @@ discard block |
||
420 | 420 | <?php |
421 | 421 | |
422 | 422 | |
423 | - foreach ($post_types as $post_type => $args) { |
|
424 | - if (!in_array($post_type, $exclude_post_types)) { |
|
425 | - $class = $map_search_pt == $post_type ? 'class="gd-map-search-pt"' : ''; |
|
423 | + foreach ($post_types as $post_type => $args) { |
|
424 | + if (!in_array($post_type, $exclude_post_types)) { |
|
425 | + $class = $map_search_pt == $post_type ? 'class="gd-map-search-pt"' : ''; |
|
426 | 426 | echo '<li id="' . $post_type . '" ' . $class . '><a href="javascript:void(0);" onclick="jQuery(\'#' . $map_canvas_name . '_posttype\').val(\'' . $post_type . '\');build_map_ajax_search_param(\'' . $map_canvas_name . '\', true)">' . __($args->labels->name, 'geodirectory') . '</a></li>'; |
427 | - } |
|
428 | - } |
|
429 | - ?> |
|
427 | + } |
|
428 | + } |
|
429 | + ?> |
|
430 | 430 | </ul> |
431 | 431 | <?php if (isset($geodir_map_options['is_geodir_home_map_widget']) && $map_args['is_geodir_home_map_widget']) { ?> |
432 | 432 | </div><?php } ?> |
@@ -440,8 +440,8 @@ discard block |
||
440 | 440 | |
441 | 441 | </div> <!-- map-places-listings--> |
442 | 442 | <?php } |
443 | - } // end of post type filter if |
|
444 | - ?> |
|
443 | + } // end of post type filter if |
|
444 | + ?> |
|
445 | 445 | |
446 | 446 | </div> |
447 | 447 | </div> <!--end of stick trigger container--> |
@@ -456,8 +456,8 @@ discard block |
||
456 | 456 | </script> |
457 | 457 | <?php |
458 | 458 | |
459 | - if (strpos($geodir_map_options['height'], 'vh')) { |
|
460 | - ?> |
|
459 | + if (strpos($geodir_map_options['height'], 'vh')) { |
|
460 | + ?> |
|
461 | 461 | <script> |
462 | 462 | (function () { |
463 | 463 | var screenH = jQuery(window).height(); |
@@ -479,8 +479,8 @@ discard block |
||
479 | 479 | |
480 | 480 | <?php |
481 | 481 | |
482 | - } elseif (strpos($geodir_map_options['height'], 'px')) { |
|
483 | - ?> |
|
482 | + } elseif (strpos($geodir_map_options['height'], 'px')) { |
|
483 | + ?> |
|
484 | 484 | <script> |
485 | 485 | (function () { |
486 | 486 | var screenH = jQuery(window).height(); |
@@ -495,20 +495,20 @@ discard block |
||
495 | 495 | }()); |
496 | 496 | </script> |
497 | 497 | <?php |
498 | - } |
|
498 | + } |
|
499 | 499 | |
500 | - /** |
|
501 | - * Action that runs after all the map code has been output; |
|
502 | - * |
|
503 | - * @since 1.5.3 |
|
504 | - * |
|
505 | - * @param array $geodir_map_options Array of map settings. |
|
506 | - * @param string $map_canvas_name The canvas name and ID for the map. |
|
507 | - */ |
|
508 | - do_action('geodir_map_after_render',$geodir_map_options,$map_canvas_name); |
|
500 | + /** |
|
501 | + * Action that runs after all the map code has been output; |
|
502 | + * |
|
503 | + * @since 1.5.3 |
|
504 | + * |
|
505 | + * @param array $geodir_map_options Array of map settings. |
|
506 | + * @param string $map_canvas_name The canvas name and ID for the map. |
|
507 | + */ |
|
508 | + do_action('geodir_map_after_render',$geodir_map_options,$map_canvas_name); |
|
509 | 509 | |
510 | 510 | |
511 | - endif; // Exclude posttypes if end |
|
511 | + endif; // Exclude posttypes if end |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | /** |
@@ -20,492 +20,492 @@ discard block |
||
20 | 20 | function geodir_set_postcat_structure($post_id, $taxonomy, $default_cat = '', $category_str = '') |
21 | 21 | { |
22 | 22 | |
23 | - $post_cat_ids = geodir_get_post_meta($post_id, $taxonomy); |
|
24 | - if (!empty($post_cat_ids)) |
|
25 | - $post_cat_array = explode(",", trim($post_cat_ids, ",")); |
|
26 | - |
|
27 | - if (!isset($default_cat) || empty($default_cat)) { |
|
28 | - $default_cat = isset($post_cat_array[0]) ? $post_cat_array[0] : ''; |
|
29 | - }else{ |
|
30 | - if(!is_int($default_cat)){ |
|
31 | - $category = get_term_by('name', $default_cat, $taxonomy); |
|
32 | - if(isset($category->term_id)){ |
|
33 | - $default_cat = $category->term_id; |
|
34 | - } |
|
35 | - } |
|
23 | + $post_cat_ids = geodir_get_post_meta($post_id, $taxonomy); |
|
24 | + if (!empty($post_cat_ids)) |
|
25 | + $post_cat_array = explode(",", trim($post_cat_ids, ",")); |
|
26 | + |
|
27 | + if (!isset($default_cat) || empty($default_cat)) { |
|
28 | + $default_cat = isset($post_cat_array[0]) ? $post_cat_array[0] : ''; |
|
29 | + }else{ |
|
30 | + if(!is_int($default_cat)){ |
|
31 | + $category = get_term_by('name', $default_cat, $taxonomy); |
|
32 | + if(isset($category->term_id)){ |
|
33 | + $default_cat = $category->term_id; |
|
34 | + } |
|
35 | + } |
|
36 | 36 | |
37 | - } |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - geodir_save_post_meta($post_id, 'default_category', $default_cat); |
|
40 | + geodir_save_post_meta($post_id, 'default_category', $default_cat); |
|
41 | 41 | |
42 | - if (isset($category_str) && empty($category_str)) { |
|
42 | + if (isset($category_str) && empty($category_str)) { |
|
43 | 43 | |
44 | - $post_cat_str = ''; |
|
45 | - $post_categories = array(); |
|
46 | - if (isset($post_cat_array) && is_array($post_cat_array) && !empty($post_cat_array)) { |
|
47 | - $post_cat_str = implode(",y:#", $post_cat_array); |
|
48 | - $post_cat_str .= ",y:"; |
|
49 | - $post_cat_str = substr_replace($post_cat_str, ',y,d:', strpos($post_cat_str, ',y:'), strlen(',y:')); |
|
50 | - } |
|
51 | - $post_categories[$taxonomy] = $post_cat_str; |
|
52 | - $category_str = $post_categories; |
|
53 | - } |
|
44 | + $post_cat_str = ''; |
|
45 | + $post_categories = array(); |
|
46 | + if (isset($post_cat_array) && is_array($post_cat_array) && !empty($post_cat_array)) { |
|
47 | + $post_cat_str = implode(",y:#", $post_cat_array); |
|
48 | + $post_cat_str .= ",y:"; |
|
49 | + $post_cat_str = substr_replace($post_cat_str, ',y,d:', strpos($post_cat_str, ',y:'), strlen(',y:')); |
|
50 | + } |
|
51 | + $post_categories[$taxonomy] = $post_cat_str; |
|
52 | + $category_str = $post_categories; |
|
53 | + } |
|
54 | 54 | |
55 | - $change_cat_str = $category_str[$taxonomy]; |
|
55 | + $change_cat_str = $category_str[$taxonomy]; |
|
56 | 56 | |
57 | - $default_pos = strpos($change_cat_str, 'd:'); |
|
57 | + $default_pos = strpos($change_cat_str, 'd:'); |
|
58 | 58 | |
59 | - if ($default_pos === false) { |
|
59 | + if ($default_pos === false) { |
|
60 | 60 | |
61 | - $change_cat_str = str_replace($default_cat . ',y:', $default_cat . ',y,d:', $change_cat_str); |
|
61 | + $change_cat_str = str_replace($default_cat . ',y:', $default_cat . ',y,d:', $change_cat_str); |
|
62 | 62 | |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - $category_str[$taxonomy] = $change_cat_str; |
|
65 | + $category_str[$taxonomy] = $change_cat_str; |
|
66 | 66 | |
67 | - update_post_meta($post_id, 'post_categories', $category_str); |
|
67 | + update_post_meta($post_id, 'post_categories', $category_str); |
|
68 | 68 | |
69 | 69 | } |
70 | 70 | |
71 | 71 | |
72 | 72 | if (!function_exists('geodir_save_listing')) { |
73 | - /** |
|
74 | - * Saves listing in the database using given information. |
|
75 | - * |
|
76 | - * @since 1.0.0 |
|
77 | - * @since 1.5.4 New parameter $wp_error added. |
|
78 | - * @since 1.6.18 Admin use only date field should not lost value if saved by user - FIXED |
|
79 | - * @package GeoDirectory |
|
80 | - * @global object $wpdb WordPress Database object. |
|
81 | - * @global object $post The current post object. |
|
82 | - * @global object $current_user Current user object. |
|
83 | - * @global object $gd_session GeoDirectory Session object. |
|
84 | - * @param array $request_info { |
|
85 | - * Array of request info arguments. |
|
86 | - * |
|
87 | - * @type string $action Ajax action name. |
|
88 | - * @type string $geodir_ajax Ajax type. |
|
89 | - * @type string $ajax_action Ajax action. |
|
90 | - * @type string $listing_type Listing type. |
|
91 | - * @type string $pid Default Post ID. |
|
92 | - * @type string $preview Todo Desc needed. |
|
93 | - * @type string $add_listing_page_id Add listing page ID. |
|
94 | - * @type string $post_title Listing title. |
|
95 | - * @type string $post_desc Listing Description. |
|
96 | - * @type string $post_tags Listing tags. |
|
97 | - * @type array $cat_limit Category limit. |
|
98 | - * @type array $post_category Category IDs. |
|
99 | - * @type array $post_category_str Category string. |
|
100 | - * @type string $post_default_category Default category ID. |
|
101 | - * @type string $post_address Listing address. |
|
102 | - * @type string $geodir_location_add_listing_country_val Add listing country value. |
|
103 | - * @type string $post_country Listing country. |
|
104 | - * @type string $geodir_location_add_listing_region_val Add listing region value. |
|
105 | - * @type string $post_region Listing region. |
|
106 | - * @type string $geodir_location_add_listing_city_val Add listing city value. |
|
107 | - * @type string $post_city Listing city. |
|
108 | - * @type string $post_zip Listing zip. |
|
109 | - * @type string $post_latitude Listing latitude. |
|
110 | - * @type string $post_longitude Listing longitude. |
|
111 | - * @type string $post_mapview Listing mapview. Default "ROADMAP". |
|
112 | - * @type string $post_mapzoom Listing mapzoom Default "9". |
|
113 | - * @type string $geodir_timing Business timing info. |
|
114 | - * @type string $geodir_contact Contact number. |
|
115 | - * @type string $geodir_email Business contact email. |
|
116 | - * @type string $geodir_website Business website. |
|
117 | - * @type string $geodir_twitter Twitter link. |
|
118 | - * @type string $geodir_facebook Facebook link. |
|
119 | - * @type string $geodir_video Video link. |
|
120 | - * @type string $geodir_special_offers Special offers. |
|
121 | - * @type string $post_images Post image urls. |
|
122 | - * @type string $post_imagesimage_limit Post images limit. |
|
123 | - * @type string $post_imagestotImg Todo Desc needed. |
|
124 | - * @type string $geodir_accept_term_condition Has accepted terms and conditions?. |
|
125 | - * @type string $geodir_spamblocker Todo Desc needed. |
|
126 | - * @type string $geodir_filled_by_spam_bot Todo Desc needed. |
|
127 | - * |
|
128 | - * } |
|
129 | - * @param bool $dummy Optional. Is this a dummy listing? Default false. |
|
130 | - * @param bool $wp_error Optional. Allow return of WP_Error on failure. Default false. |
|
131 | - * @return int|string|WP_Error Created post id or WP_Error on failure. |
|
132 | - */ |
|
133 | - function geodir_save_listing($request_info = array(), $dummy = false, $wp_error = false) |
|
134 | - { |
|
135 | - global $wpdb, $current_user, $gd_session; |
|
136 | - |
|
137 | - $last_post_id = ''; |
|
138 | - |
|
139 | - if ($gd_session->get('listing') && !$dummy) { |
|
140 | - $request_info = array(); |
|
141 | - $request_session = $gd_session->get('listing'); |
|
142 | - $request_info = array_merge($_REQUEST, $request_session); |
|
143 | - } else if (!$gd_session->get('listing') && !$dummy) { |
|
144 | - global $post; |
|
73 | + /** |
|
74 | + * Saves listing in the database using given information. |
|
75 | + * |
|
76 | + * @since 1.0.0 |
|
77 | + * @since 1.5.4 New parameter $wp_error added. |
|
78 | + * @since 1.6.18 Admin use only date field should not lost value if saved by user - FIXED |
|
79 | + * @package GeoDirectory |
|
80 | + * @global object $wpdb WordPress Database object. |
|
81 | + * @global object $post The current post object. |
|
82 | + * @global object $current_user Current user object. |
|
83 | + * @global object $gd_session GeoDirectory Session object. |
|
84 | + * @param array $request_info { |
|
85 | + * Array of request info arguments. |
|
86 | + * |
|
87 | + * @type string $action Ajax action name. |
|
88 | + * @type string $geodir_ajax Ajax type. |
|
89 | + * @type string $ajax_action Ajax action. |
|
90 | + * @type string $listing_type Listing type. |
|
91 | + * @type string $pid Default Post ID. |
|
92 | + * @type string $preview Todo Desc needed. |
|
93 | + * @type string $add_listing_page_id Add listing page ID. |
|
94 | + * @type string $post_title Listing title. |
|
95 | + * @type string $post_desc Listing Description. |
|
96 | + * @type string $post_tags Listing tags. |
|
97 | + * @type array $cat_limit Category limit. |
|
98 | + * @type array $post_category Category IDs. |
|
99 | + * @type array $post_category_str Category string. |
|
100 | + * @type string $post_default_category Default category ID. |
|
101 | + * @type string $post_address Listing address. |
|
102 | + * @type string $geodir_location_add_listing_country_val Add listing country value. |
|
103 | + * @type string $post_country Listing country. |
|
104 | + * @type string $geodir_location_add_listing_region_val Add listing region value. |
|
105 | + * @type string $post_region Listing region. |
|
106 | + * @type string $geodir_location_add_listing_city_val Add listing city value. |
|
107 | + * @type string $post_city Listing city. |
|
108 | + * @type string $post_zip Listing zip. |
|
109 | + * @type string $post_latitude Listing latitude. |
|
110 | + * @type string $post_longitude Listing longitude. |
|
111 | + * @type string $post_mapview Listing mapview. Default "ROADMAP". |
|
112 | + * @type string $post_mapzoom Listing mapzoom Default "9". |
|
113 | + * @type string $geodir_timing Business timing info. |
|
114 | + * @type string $geodir_contact Contact number. |
|
115 | + * @type string $geodir_email Business contact email. |
|
116 | + * @type string $geodir_website Business website. |
|
117 | + * @type string $geodir_twitter Twitter link. |
|
118 | + * @type string $geodir_facebook Facebook link. |
|
119 | + * @type string $geodir_video Video link. |
|
120 | + * @type string $geodir_special_offers Special offers. |
|
121 | + * @type string $post_images Post image urls. |
|
122 | + * @type string $post_imagesimage_limit Post images limit. |
|
123 | + * @type string $post_imagestotImg Todo Desc needed. |
|
124 | + * @type string $geodir_accept_term_condition Has accepted terms and conditions?. |
|
125 | + * @type string $geodir_spamblocker Todo Desc needed. |
|
126 | + * @type string $geodir_filled_by_spam_bot Todo Desc needed. |
|
127 | + * |
|
128 | + * } |
|
129 | + * @param bool $dummy Optional. Is this a dummy listing? Default false. |
|
130 | + * @param bool $wp_error Optional. Allow return of WP_Error on failure. Default false. |
|
131 | + * @return int|string|WP_Error Created post id or WP_Error on failure. |
|
132 | + */ |
|
133 | + function geodir_save_listing($request_info = array(), $dummy = false, $wp_error = false) |
|
134 | + { |
|
135 | + global $wpdb, $current_user, $gd_session; |
|
136 | + |
|
137 | + $last_post_id = ''; |
|
138 | + |
|
139 | + if ($gd_session->get('listing') && !$dummy) { |
|
140 | + $request_info = array(); |
|
141 | + $request_session = $gd_session->get('listing'); |
|
142 | + $request_info = array_merge($_REQUEST, $request_session); |
|
143 | + } else if (!$gd_session->get('listing') && !$dummy) { |
|
144 | + global $post; |
|
145 | 145 | |
146 | - $gd_post = $post; |
|
147 | - if (!empty($gd_post) && is_array($gd_post)) { |
|
148 | - $gd_post = (object)$post; |
|
146 | + $gd_post = $post; |
|
147 | + if (!empty($gd_post) && is_array($gd_post)) { |
|
148 | + $gd_post = (object)$post; |
|
149 | 149 | |
150 | - // Fix WPML duplicate. |
|
151 | - if (geodir_is_wpml() && !empty($request_info['action']) && $request_info['action'] == 'editpost' && !empty($request_info['icl_trid']) && !isset($post['post_date'])) { |
|
152 | - return false; |
|
153 | - } |
|
154 | - } |
|
150 | + // Fix WPML duplicate. |
|
151 | + if (geodir_is_wpml() && !empty($request_info['action']) && $request_info['action'] == 'editpost' && !empty($request_info['icl_trid']) && !isset($post['post_date'])) { |
|
152 | + return false; |
|
153 | + } |
|
154 | + } |
|
155 | 155 | |
156 | - $request_info['pid'] = !empty($gd_post->ID) ? $gd_post->ID : (!empty($request_info['post_id']) ? $request_info['post_id'] : NULL); |
|
157 | - $request_info['post_title'] = $request_info['post_title']; |
|
158 | - $request_info['listing_type'] = !empty($gd_post->post_type) ? $gd_post->post_type : (!empty($request_info['post_type']) ? $request_info['post_type'] : get_post_type($request_info['pid'])); |
|
159 | - $request_info['post_desc'] = $request_info['content']; |
|
160 | - } else if (!$dummy) { |
|
161 | - return false; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Filter the request_info array. |
|
166 | - * |
|
167 | - * You can use this filter to modify request_info array. |
|
168 | - * |
|
169 | - * @since 1.0.0 |
|
170 | - * @package GeoDirectory |
|
171 | - * @param array $request_info See {@see geodir_save_listing()} for accepted args. |
|
172 | - */ |
|
173 | - $request_info = apply_filters('geodir_action_get_request_info', $request_info); |
|
174 | - |
|
175 | - // Check if we need to save post location as new location |
|
176 | - $location_result = geodir_get_default_location(); |
|
177 | - |
|
178 | - if ($location_result->location_id > 0) { |
|
179 | - if (isset($request_info['post_city']) && isset($request_info['post_region'])) { |
|
180 | - $request_info['post_location'] = array( |
|
181 | - 'city' => $request_info['post_city'], |
|
182 | - 'region' => isset($request_info['post_region']) ? $request_info['post_region'] : '', |
|
183 | - 'country' => isset($request_info['post_country']) ? $request_info['post_country'] : '', |
|
184 | - 'geo_lat' => isset($request_info['post_latitude']) ? $request_info['post_latitude'] : '', |
|
185 | - 'geo_lng' => isset($request_info['post_longitude']) ? $request_info['post_longitude'] : '' |
|
186 | - ); |
|
187 | - |
|
188 | - $post_location_info = $request_info['post_location']; |
|
189 | - |
|
190 | - if ($location_id = geodir_add_new_location($post_location_info)) { |
|
191 | - $post_location_id = $location_id; |
|
192 | - } |
|
193 | - } else { |
|
194 | - $post_location_id = $location_result->location_id; |
|
195 | - } |
|
196 | - } else { |
|
197 | - $post_location_id = $location_result->location_id; |
|
198 | - } |
|
199 | - |
|
200 | - if ($dummy) { |
|
201 | - $post_status = 'publish'; |
|
202 | - } else { |
|
203 | - $post_status = geodir_new_post_default_status(); |
|
204 | - } |
|
205 | - |
|
206 | - if (isset($request_info['pid']) && $request_info['pid'] != '') { |
|
207 | - $post_status = get_post_status($request_info['pid']); |
|
208 | - } |
|
209 | - |
|
210 | - /* fix change of slug on every title edit */ |
|
211 | - if (!isset($request_info['post_name'])) { |
|
212 | - $request_info['post_name'] = $request_info['post_title']; |
|
213 | - |
|
214 | - if (!empty($request_info['pid'])) { |
|
215 | - $post_info = get_post($request_info['pid']); |
|
216 | - |
|
217 | - if (!empty($post_info) && isset($post_info->post_name)) { |
|
218 | - $request_info['post_name'] = $post_info->post_name; |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - $post = array( |
|
224 | - 'post_content' => $request_info['post_desc'], |
|
225 | - 'post_status' => $post_status, |
|
226 | - 'post_title' => $request_info['post_title'], |
|
227 | - 'post_name' => $request_info['post_name'], |
|
228 | - 'post_type' => $request_info['listing_type'] |
|
229 | - ); |
|
230 | - |
|
231 | - /** |
|
232 | - * Called before a listing is saved to the database. |
|
233 | - * |
|
234 | - * @since 1.0.0 |
|
235 | - * @param object $post The post object. |
|
236 | - */ |
|
237 | - do_action_ref_array('geodir_before_save_listing', $post); |
|
156 | + $request_info['pid'] = !empty($gd_post->ID) ? $gd_post->ID : (!empty($request_info['post_id']) ? $request_info['post_id'] : NULL); |
|
157 | + $request_info['post_title'] = $request_info['post_title']; |
|
158 | + $request_info['listing_type'] = !empty($gd_post->post_type) ? $gd_post->post_type : (!empty($request_info['post_type']) ? $request_info['post_type'] : get_post_type($request_info['pid'])); |
|
159 | + $request_info['post_desc'] = $request_info['content']; |
|
160 | + } else if (!$dummy) { |
|
161 | + return false; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Filter the request_info array. |
|
166 | + * |
|
167 | + * You can use this filter to modify request_info array. |
|
168 | + * |
|
169 | + * @since 1.0.0 |
|
170 | + * @package GeoDirectory |
|
171 | + * @param array $request_info See {@see geodir_save_listing()} for accepted args. |
|
172 | + */ |
|
173 | + $request_info = apply_filters('geodir_action_get_request_info', $request_info); |
|
174 | + |
|
175 | + // Check if we need to save post location as new location |
|
176 | + $location_result = geodir_get_default_location(); |
|
177 | + |
|
178 | + if ($location_result->location_id > 0) { |
|
179 | + if (isset($request_info['post_city']) && isset($request_info['post_region'])) { |
|
180 | + $request_info['post_location'] = array( |
|
181 | + 'city' => $request_info['post_city'], |
|
182 | + 'region' => isset($request_info['post_region']) ? $request_info['post_region'] : '', |
|
183 | + 'country' => isset($request_info['post_country']) ? $request_info['post_country'] : '', |
|
184 | + 'geo_lat' => isset($request_info['post_latitude']) ? $request_info['post_latitude'] : '', |
|
185 | + 'geo_lng' => isset($request_info['post_longitude']) ? $request_info['post_longitude'] : '' |
|
186 | + ); |
|
187 | + |
|
188 | + $post_location_info = $request_info['post_location']; |
|
189 | + |
|
190 | + if ($location_id = geodir_add_new_location($post_location_info)) { |
|
191 | + $post_location_id = $location_id; |
|
192 | + } |
|
193 | + } else { |
|
194 | + $post_location_id = $location_result->location_id; |
|
195 | + } |
|
196 | + } else { |
|
197 | + $post_location_id = $location_result->location_id; |
|
198 | + } |
|
238 | 199 | |
239 | - $send_post_submit_mail = false; |
|
200 | + if ($dummy) { |
|
201 | + $post_status = 'publish'; |
|
202 | + } else { |
|
203 | + $post_status = geodir_new_post_default_status(); |
|
204 | + } |
|
240 | 205 | |
241 | - // unhook this function so it doesn't loop infinitely |
|
242 | - remove_action('save_post', 'geodir_post_information_save',10,2); |
|
206 | + if (isset($request_info['pid']) && $request_info['pid'] != '') { |
|
207 | + $post_status = get_post_status($request_info['pid']); |
|
208 | + } |
|
243 | 209 | |
244 | - if (isset($request_info['pid']) && $request_info['pid'] != '') { |
|
245 | - $post['ID'] = $request_info['pid']; |
|
210 | + /* fix change of slug on every title edit */ |
|
211 | + if (!isset($request_info['post_name'])) { |
|
212 | + $request_info['post_name'] = $request_info['post_title']; |
|
246 | 213 | |
247 | - $last_post_id = wp_update_post($post, $wp_error); |
|
248 | - } else { |
|
249 | - $last_post_id = wp_insert_post($post, $wp_error); |
|
214 | + if (!empty($request_info['pid'])) { |
|
215 | + $post_info = get_post($request_info['pid']); |
|
250 | 216 | |
251 | - if (!$dummy && $last_post_id) { |
|
252 | - $send_post_submit_mail = true; // we move post_submit email from here so the rest of the variables are added to the db first(was breaking permalink in email) |
|
253 | - //geodir_sendEmail('','',$current_user->user_email,$current_user->display_name,'','',$request_info,'post_submit',$last_post_id,$current_user->ID); |
|
254 | - } |
|
255 | - } |
|
217 | + if (!empty($post_info) && isset($post_info->post_name)) { |
|
218 | + $request_info['post_name'] = $post_info->post_name; |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + $post = array( |
|
224 | + 'post_content' => $request_info['post_desc'], |
|
225 | + 'post_status' => $post_status, |
|
226 | + 'post_title' => $request_info['post_title'], |
|
227 | + 'post_name' => $request_info['post_name'], |
|
228 | + 'post_type' => $request_info['listing_type'] |
|
229 | + ); |
|
230 | + |
|
231 | + /** |
|
232 | + * Called before a listing is saved to the database. |
|
233 | + * |
|
234 | + * @since 1.0.0 |
|
235 | + * @param object $post The post object. |
|
236 | + */ |
|
237 | + do_action_ref_array('geodir_before_save_listing', $post); |
|
238 | + |
|
239 | + $send_post_submit_mail = false; |
|
240 | + |
|
241 | + // unhook this function so it doesn't loop infinitely |
|
242 | + remove_action('save_post', 'geodir_post_information_save',10,2); |
|
243 | + |
|
244 | + if (isset($request_info['pid']) && $request_info['pid'] != '') { |
|
245 | + $post['ID'] = $request_info['pid']; |
|
246 | + |
|
247 | + $last_post_id = wp_update_post($post, $wp_error); |
|
248 | + } else { |
|
249 | + $last_post_id = wp_insert_post($post, $wp_error); |
|
250 | + |
|
251 | + if (!$dummy && $last_post_id) { |
|
252 | + $send_post_submit_mail = true; // we move post_submit email from here so the rest of the variables are added to the db first(was breaking permalink in email) |
|
253 | + //geodir_sendEmail('','',$current_user->user_email,$current_user->display_name,'','',$request_info,'post_submit',$last_post_id,$current_user->ID); |
|
254 | + } |
|
255 | + } |
|
256 | 256 | |
257 | - if ($wp_error && is_wp_error($last_post_id)) { |
|
258 | - return $last_post_id; // Return WP_Error on save failure. |
|
259 | - } |
|
257 | + if ($wp_error && is_wp_error($last_post_id)) { |
|
258 | + return $last_post_id; // Return WP_Error on save failure. |
|
259 | + } |
|
260 | 260 | |
261 | - if (!$last_post_id) { |
|
262 | - return false; // Save failure. |
|
263 | - } |
|
261 | + if (!$last_post_id) { |
|
262 | + return false; // Save failure. |
|
263 | + } |
|
264 | 264 | |
265 | - // re-hook this function |
|
266 | - add_action('save_post', 'geodir_post_information_save',10,2); |
|
265 | + // re-hook this function |
|
266 | + add_action('save_post', 'geodir_post_information_save',10,2); |
|
267 | 267 | |
268 | - $post_tags = ''; |
|
269 | - if (!isset($request_info['post_tags'])) { |
|
268 | + $post_tags = ''; |
|
269 | + if (!isset($request_info['post_tags'])) { |
|
270 | 270 | |
271 | - $post_type = $request_info['listing_type']; |
|
272 | - $post_tags = implode(",", wp_get_object_terms($last_post_id, $post_type . '_tags', array('fields' => 'names'))); |
|
271 | + $post_type = $request_info['listing_type']; |
|
272 | + $post_tags = implode(",", wp_get_object_terms($last_post_id, $post_type . '_tags', array('fields' => 'names'))); |
|
273 | 273 | |
274 | - } |
|
274 | + } |
|
275 | 275 | |
276 | - $gd_post_info = array( |
|
277 | - "post_title" => $request_info['post_title'], |
|
278 | - "post_tags" => isset($request_info['post_tags']) ? $request_info['post_tags'] : $post_tags, |
|
279 | - "post_status" => $post_status, |
|
280 | - "post_location_id" => $post_location_id, |
|
281 | - "claimed" => isset($request_info['claimed']) ? $request_info['claimed'] : '', |
|
282 | - "businesses" => isset($request_info['a_businesses']) ? $request_info['a_businesses'] : '', |
|
283 | - "submit_time" => time(), |
|
284 | - "submit_ip" => $_SERVER['REMOTE_ADDR'], |
|
285 | - ); |
|
276 | + $gd_post_info = array( |
|
277 | + "post_title" => $request_info['post_title'], |
|
278 | + "post_tags" => isset($request_info['post_tags']) ? $request_info['post_tags'] : $post_tags, |
|
279 | + "post_status" => $post_status, |
|
280 | + "post_location_id" => $post_location_id, |
|
281 | + "claimed" => isset($request_info['claimed']) ? $request_info['claimed'] : '', |
|
282 | + "businesses" => isset($request_info['a_businesses']) ? $request_info['a_businesses'] : '', |
|
283 | + "submit_time" => time(), |
|
284 | + "submit_ip" => $_SERVER['REMOTE_ADDR'], |
|
285 | + ); |
|
286 | 286 | |
287 | - $payment_info = array(); |
|
288 | - $package_info = array(); |
|
287 | + $payment_info = array(); |
|
288 | + $package_info = array(); |
|
289 | 289 | |
290 | - $package_info = (array)geodir_post_package_info($package_info, $post); |
|
290 | + $package_info = (array)geodir_post_package_info($package_info, $post); |
|
291 | 291 | |
292 | - $post_package_id = geodir_get_post_meta($last_post_id, 'package_id'); |
|
292 | + $post_package_id = geodir_get_post_meta($last_post_id, 'package_id'); |
|
293 | 293 | |
294 | - if (!empty($package_info) && !$post_package_id) { |
|
295 | - if (isset($package_info['days']) && $package_info['days'] != 0) { |
|
296 | - $payment_info['expire_date'] = date('Y-m-d', strtotime("+" . $package_info['days'] . " days")); |
|
297 | - } else { |
|
298 | - $payment_info['expire_date'] = 'Never'; |
|
299 | - } |
|
294 | + if (!empty($package_info) && !$post_package_id) { |
|
295 | + if (isset($package_info['days']) && $package_info['days'] != 0) { |
|
296 | + $payment_info['expire_date'] = date('Y-m-d', strtotime("+" . $package_info['days'] . " days")); |
|
297 | + } else { |
|
298 | + $payment_info['expire_date'] = 'Never'; |
|
299 | + } |
|
300 | 300 | |
301 | - $payment_info['package_id'] = $package_info['pid']; |
|
302 | - $payment_info['alive_days'] = $package_info['days']; |
|
303 | - $payment_info['is_featured'] = $package_info['is_featured']; |
|
301 | + $payment_info['package_id'] = $package_info['pid']; |
|
302 | + $payment_info['alive_days'] = $package_info['days']; |
|
303 | + $payment_info['is_featured'] = $package_info['is_featured']; |
|
304 | 304 | |
305 | - $gd_post_info = array_merge($gd_post_info, $payment_info); |
|
306 | - } |
|
305 | + $gd_post_info = array_merge($gd_post_info, $payment_info); |
|
306 | + } |
|
307 | 307 | |
308 | - $custom_metaboxes = geodir_post_custom_fields('', 'all', $request_info['listing_type']); |
|
308 | + $custom_metaboxes = geodir_post_custom_fields('', 'all', $request_info['listing_type']); |
|
309 | 309 | |
310 | - foreach ($custom_metaboxes as $key => $val): |
|
310 | + foreach ($custom_metaboxes as $key => $val): |
|
311 | 311 | |
312 | - $name = $val['name']; |
|
313 | - $type = $val['type']; |
|
314 | - $extrafields = $val['extra_fields']; |
|
312 | + $name = $val['name']; |
|
313 | + $type = $val['type']; |
|
314 | + $extrafields = $val['extra_fields']; |
|
315 | 315 | |
316 | - if (trim($type) == 'address') { |
|
317 | - $prefix = $name . '_'; |
|
318 | - $address = $prefix . 'address'; |
|
316 | + if (trim($type) == 'address') { |
|
317 | + $prefix = $name . '_'; |
|
318 | + $address = $prefix . 'address'; |
|
319 | 319 | |
320 | - if (isset($request_info[$address]) && $request_info[$address] != '') { |
|
321 | - $gd_post_info[$address] = wp_slash($request_info[$address]); |
|
322 | - } |
|
320 | + if (isset($request_info[$address]) && $request_info[$address] != '') { |
|
321 | + $gd_post_info[$address] = wp_slash($request_info[$address]); |
|
322 | + } |
|
323 | 323 | |
324 | - if ($extrafields != '') { |
|
325 | - $extrafields = unserialize($extrafields); |
|
324 | + if ($extrafields != '') { |
|
325 | + $extrafields = unserialize($extrafields); |
|
326 | 326 | |
327 | 327 | |
328 | - if (!isset($request_info[$prefix . 'city']) || $request_info[$prefix . 'city'] == '') { |
|
328 | + if (!isset($request_info[$prefix . 'city']) || $request_info[$prefix . 'city'] == '') { |
|
329 | 329 | |
330 | - $location_result = geodir_get_default_location(); |
|
330 | + $location_result = geodir_get_default_location(); |
|
331 | 331 | |
332 | - $gd_post_info[$prefix . 'city'] = $location_result->city; |
|
333 | - $gd_post_info[$prefix . 'region'] = $location_result->region; |
|
334 | - $gd_post_info[$prefix . 'country'] = $location_result->country; |
|
332 | + $gd_post_info[$prefix . 'city'] = $location_result->city; |
|
333 | + $gd_post_info[$prefix . 'region'] = $location_result->region; |
|
334 | + $gd_post_info[$prefix . 'country'] = $location_result->country; |
|
335 | 335 | |
336 | - $gd_post_info['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']'; // set all overall post location |
|
336 | + $gd_post_info['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']'; // set all overall post location |
|
337 | 337 | |
338 | - } else { |
|
338 | + } else { |
|
339 | 339 | |
340 | - $gd_post_info[$prefix . 'city'] = $request_info[$prefix . 'city']; |
|
341 | - $gd_post_info[$prefix . 'region'] = $request_info[$prefix . 'region']; |
|
342 | - $gd_post_info[$prefix . 'country'] = $request_info[$prefix . 'country']; |
|
340 | + $gd_post_info[$prefix . 'city'] = $request_info[$prefix . 'city']; |
|
341 | + $gd_post_info[$prefix . 'region'] = $request_info[$prefix . 'region']; |
|
342 | + $gd_post_info[$prefix . 'country'] = $request_info[$prefix . 'country']; |
|
343 | 343 | |
344 | - //----------set post locations when import dummy data------- |
|
345 | - $location_result = geodir_get_default_location(); |
|
344 | + //----------set post locations when import dummy data------- |
|
345 | + $location_result = geodir_get_default_location(); |
|
346 | 346 | |
347 | - $gd_post_info['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']'; // set all overall post location |
|
348 | - //----------------------------------------------------------------- |
|
347 | + $gd_post_info['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']'; // set all overall post location |
|
348 | + //----------------------------------------------------------------- |
|
349 | 349 | |
350 | - } |
|
350 | + } |
|
351 | 351 | |
352 | 352 | |
353 | - if (isset($extrafields['show_zip']) && $extrafields['show_zip'] && isset($request_info[$prefix . 'zip'])) { |
|
354 | - $gd_post_info[$prefix . 'zip'] = $request_info[$prefix . 'zip']; |
|
355 | - } |
|
353 | + if (isset($extrafields['show_zip']) && $extrafields['show_zip'] && isset($request_info[$prefix . 'zip'])) { |
|
354 | + $gd_post_info[$prefix . 'zip'] = $request_info[$prefix . 'zip']; |
|
355 | + } |
|
356 | 356 | |
357 | 357 | |
358 | - if (isset($extrafields['show_map']) && $extrafields['show_map']) { |
|
358 | + if (isset($extrafields['show_map']) && $extrafields['show_map']) { |
|
359 | 359 | |
360 | - if (isset($request_info[$prefix . 'latitude']) && $request_info[$prefix . 'latitude'] != '') { |
|
361 | - $gd_post_info[$prefix . 'latitude'] = $request_info[$prefix . 'latitude']; |
|
362 | - } |
|
360 | + if (isset($request_info[$prefix . 'latitude']) && $request_info[$prefix . 'latitude'] != '') { |
|
361 | + $gd_post_info[$prefix . 'latitude'] = $request_info[$prefix . 'latitude']; |
|
362 | + } |
|
363 | 363 | |
364 | - if (isset($request_info[$prefix . 'longitude']) && $request_info[$prefix . 'longitude'] != '') { |
|
365 | - $gd_post_info[$prefix . 'longitude'] = $request_info[$prefix . 'longitude']; |
|
366 | - } |
|
364 | + if (isset($request_info[$prefix . 'longitude']) && $request_info[$prefix . 'longitude'] != '') { |
|
365 | + $gd_post_info[$prefix . 'longitude'] = $request_info[$prefix . 'longitude']; |
|
366 | + } |
|
367 | 367 | |
368 | - if (isset($request_info[$prefix . 'mapview']) && $request_info[$prefix . 'mapview'] != '') { |
|
369 | - $gd_post_info[$prefix . 'mapview'] = $request_info[$prefix . 'mapview']; |
|
370 | - } |
|
368 | + if (isset($request_info[$prefix . 'mapview']) && $request_info[$prefix . 'mapview'] != '') { |
|
369 | + $gd_post_info[$prefix . 'mapview'] = $request_info[$prefix . 'mapview']; |
|
370 | + } |
|
371 | 371 | |
372 | - if (isset($request_info[$prefix . 'mapzoom']) && $request_info[$prefix . 'mapzoom'] != '') { |
|
373 | - $gd_post_info[$prefix . 'mapzoom'] = $request_info[$prefix . 'mapzoom']; |
|
374 | - } |
|
372 | + if (isset($request_info[$prefix . 'mapzoom']) && $request_info[$prefix . 'mapzoom'] != '') { |
|
373 | + $gd_post_info[$prefix . 'mapzoom'] = $request_info[$prefix . 'mapzoom']; |
|
374 | + } |
|
375 | 375 | |
376 | - } |
|
376 | + } |
|
377 | 377 | |
378 | - // show lat lng |
|
379 | - if (isset($extrafields['show_latlng']) && $extrafields['show_latlng'] && isset($request_info[$prefix . 'latlng'])) { |
|
380 | - $gd_post_info[$prefix . 'latlng'] = $request_info[$prefix . 'latlng']; |
|
381 | - } |
|
382 | - } |
|
378 | + // show lat lng |
|
379 | + if (isset($extrafields['show_latlng']) && $extrafields['show_latlng'] && isset($request_info[$prefix . 'latlng'])) { |
|
380 | + $gd_post_info[$prefix . 'latlng'] = $request_info[$prefix . 'latlng']; |
|
381 | + } |
|
382 | + } |
|
383 | 383 | |
384 | - } elseif (trim($type) == 'file') { |
|
385 | - if (isset($request_info[$name])) { |
|
386 | - $request_files = array(); |
|
387 | - if ($request_info[$name] != '') |
|
388 | - $request_files = explode(",", $request_info[$name]); |
|
384 | + } elseif (trim($type) == 'file') { |
|
385 | + if (isset($request_info[$name])) { |
|
386 | + $request_files = array(); |
|
387 | + if ($request_info[$name] != '') |
|
388 | + $request_files = explode(",", $request_info[$name]); |
|
389 | 389 | |
390 | - $extrafields = $extrafields != '' ? maybe_unserialize($extrafields) : NULL; |
|
391 | - geodir_save_post_file_fields($last_post_id, $name, $request_files, $extrafields); |
|
392 | - } |
|
393 | - } elseif (trim($type) == 'datepicker') { |
|
394 | - if (isset($request_info[$name])) { |
|
395 | - $datetime = ''; |
|
390 | + $extrafields = $extrafields != '' ? maybe_unserialize($extrafields) : NULL; |
|
391 | + geodir_save_post_file_fields($last_post_id, $name, $request_files, $extrafields); |
|
392 | + } |
|
393 | + } elseif (trim($type) == 'datepicker') { |
|
394 | + if (isset($request_info[$name])) { |
|
395 | + $datetime = ''; |
|
396 | 396 | |
397 | - if (!empty($request_info[$name])) { |
|
398 | - $date_format = geodir_default_date_format(); |
|
399 | - if (isset($val['extra_fields']) && $val['extra_fields'] != '') { |
|
400 | - $extra_fields = unserialize($val['extra_fields']); |
|
401 | - $date_format = isset($extra_fields['date_format']) && $extra_fields['date_format'] != '' ? $extra_fields['date_format'] : $date_format; |
|
402 | - } |
|
403 | - |
|
404 | - // check if we need to change the format or not |
|
405 | - $date_format_len = strlen(str_replace(' ', '', $date_format)); |
|
406 | - if($date_format_len>5){// if greater then 5 then it's the old style format. |
|
397 | + if (!empty($request_info[$name])) { |
|
398 | + $date_format = geodir_default_date_format(); |
|
399 | + if (isset($val['extra_fields']) && $val['extra_fields'] != '') { |
|
400 | + $extra_fields = unserialize($val['extra_fields']); |
|
401 | + $date_format = isset($extra_fields['date_format']) && $extra_fields['date_format'] != '' ? $extra_fields['date_format'] : $date_format; |
|
402 | + } |
|
407 | 403 | |
408 | - $search = array('dd','d','DD','mm','m','MM','yy'); //jQuery UI datepicker format |
|
409 | - $replace = array('d','j','l','m','n','F','Y');//PHP date format |
|
404 | + // check if we need to change the format or not |
|
405 | + $date_format_len = strlen(str_replace(' ', '', $date_format)); |
|
406 | + if($date_format_len>5){// if greater then 5 then it's the old style format. |
|
410 | 407 | |
411 | - $date_format = str_replace($search, $replace, $date_format); |
|
408 | + $search = array('dd','d','DD','mm','m','MM','yy'); //jQuery UI datepicker format |
|
409 | + $replace = array('d','j','l','m','n','F','Y');//PHP date format |
|
412 | 410 | |
413 | - $post_htmlvar_value = $date_format == 'd/m/Y' ? str_replace('/', '-', $request_info[$name]) : $request_info[$name]; |
|
411 | + $date_format = str_replace($search, $replace, $date_format); |
|
414 | 412 | |
415 | - }else{ |
|
416 | - $post_htmlvar_value = $request_info[$name]; |
|
417 | - } |
|
413 | + $post_htmlvar_value = $date_format == 'd/m/Y' ? str_replace('/', '-', $request_info[$name]) : $request_info[$name]; |
|
418 | 414 | |
419 | - $post_htmlvar_value = geodir_date($post_htmlvar_value, 'Y-m-d', $date_format); // save as sql format Y-m-d |
|
420 | - $datetime = geodir_maybe_untranslate_date($post_htmlvar_value); // maybe untranslate date string if it was translated |
|
421 | - } |
|
415 | + }else{ |
|
416 | + $post_htmlvar_value = $request_info[$name]; |
|
417 | + } |
|
422 | 418 | |
423 | - $gd_post_info[$name] = $datetime; |
|
424 | - } |
|
425 | - } else if ($type == 'multiselect') { |
|
426 | - if (isset($request_info[$name])) { |
|
427 | - $gd_post_info[$name] = $request_info[$name]; |
|
428 | - } else { |
|
429 | - if (isset($request_info['gd_field_' . $name])) { |
|
430 | - $gd_post_info[$name] = ''; /* fix de-select for multiselect */ |
|
431 | - } |
|
432 | - } |
|
433 | - } else if (isset($request_info[$name])) { |
|
434 | - $gd_post_info[$name] = $request_info[$name]; |
|
435 | - } |
|
419 | + $post_htmlvar_value = geodir_date($post_htmlvar_value, 'Y-m-d', $date_format); // save as sql format Y-m-d |
|
420 | + $datetime = geodir_maybe_untranslate_date($post_htmlvar_value); // maybe untranslate date string if it was translated |
|
421 | + } |
|
422 | + |
|
423 | + $gd_post_info[$name] = $datetime; |
|
424 | + } |
|
425 | + } else if ($type == 'multiselect') { |
|
426 | + if (isset($request_info[$name])) { |
|
427 | + $gd_post_info[$name] = $request_info[$name]; |
|
428 | + } else { |
|
429 | + if (isset($request_info['gd_field_' . $name])) { |
|
430 | + $gd_post_info[$name] = ''; /* fix de-select for multiselect */ |
|
431 | + } |
|
432 | + } |
|
433 | + } else if (isset($request_info[$name])) { |
|
434 | + $gd_post_info[$name] = $request_info[$name]; |
|
435 | + } |
|
436 | 436 | |
437 | - endforeach; |
|
437 | + endforeach; |
|
438 | 438 | |
439 | - if (isset($request_info['post_dummy']) && $request_info['post_dummy'] != '') { |
|
440 | - $gd_post_info['post_dummy'] = $request_info['post_dummy']; |
|
441 | - } |
|
439 | + if (isset($request_info['post_dummy']) && $request_info['post_dummy'] != '') { |
|
440 | + $gd_post_info['post_dummy'] = $request_info['post_dummy']; |
|
441 | + } |
|
442 | 442 | |
443 | - // Save post detail info in detail table |
|
444 | - if (!empty($gd_post_info)) { |
|
445 | - geodir_save_post_info($last_post_id, $gd_post_info); |
|
446 | - } |
|
443 | + // Save post detail info in detail table |
|
444 | + if (!empty($gd_post_info)) { |
|
445 | + geodir_save_post_info($last_post_id, $gd_post_info); |
|
446 | + } |
|
447 | 447 | |
448 | 448 | |
449 | - // Set categories to the listing |
|
450 | - if (isset($request_info['post_category']) && !empty($request_info['post_category'])) { |
|
451 | - $post_category = array(); |
|
449 | + // Set categories to the listing |
|
450 | + if (isset($request_info['post_category']) && !empty($request_info['post_category'])) { |
|
451 | + $post_category = array(); |
|
452 | 452 | |
453 | - foreach ($request_info['post_category'] as $taxonomy => $cat) { |
|
453 | + foreach ($request_info['post_category'] as $taxonomy => $cat) { |
|
454 | 454 | |
455 | - if ($dummy) |
|
456 | - $post_category = $cat; |
|
457 | - else { |
|
455 | + if ($dummy) |
|
456 | + $post_category = $cat; |
|
457 | + else { |
|
458 | 458 | |
459 | - if (!is_array($cat) && strstr($cat, ',')) |
|
460 | - $cat = explode(',', $cat); |
|
459 | + if (!is_array($cat) && strstr($cat, ',')) |
|
460 | + $cat = explode(',', $cat); |
|
461 | 461 | |
462 | - if (!empty($cat) && is_array($cat)) |
|
463 | - $post_category = array_map('intval', $cat); |
|
464 | - } |
|
462 | + if (!empty($cat) && is_array($cat)) |
|
463 | + $post_category = array_map('intval', $cat); |
|
464 | + } |
|
465 | 465 | |
466 | - wp_set_object_terms($last_post_id, $post_category, $taxonomy); |
|
467 | - } |
|
466 | + wp_set_object_terms($last_post_id, $post_category, $taxonomy); |
|
467 | + } |
|
468 | 468 | |
469 | - $post_default_category = isset($request_info['post_default_category']) ? $request_info['post_default_category'] : ''; |
|
469 | + $post_default_category = isset($request_info['post_default_category']) ? $request_info['post_default_category'] : ''; |
|
470 | 470 | |
471 | - $post_category_str = isset($request_info['post_category_str']) ? $request_info['post_category_str'] : ''; |
|
472 | - geodir_set_postcat_structure($last_post_id, $taxonomy, $post_default_category, $post_category_str); |
|
471 | + $post_category_str = isset($request_info['post_category_str']) ? $request_info['post_category_str'] : ''; |
|
472 | + geodir_set_postcat_structure($last_post_id, $taxonomy, $post_default_category, $post_category_str); |
|
473 | 473 | |
474 | - } |
|
474 | + } |
|
475 | 475 | |
476 | - $post_tags = ''; |
|
477 | - // Set tags to the listing |
|
478 | - if (isset($request_info['post_tags']) && !is_array($request_info['post_tags']) && !empty($request_info['post_tags'])) { |
|
479 | - $post_tags = explode(",", $request_info['post_tags']); |
|
480 | - } elseif (isset($request_info['post_tags']) && is_array($request_info['post_tags'])) { |
|
481 | - if ($dummy) |
|
482 | - $post_tags = $request_info['post_tags']; |
|
483 | - } else { |
|
484 | - if ($dummy) |
|
485 | - $post_tags = array($request_info['post_title']); |
|
486 | - } |
|
476 | + $post_tags = ''; |
|
477 | + // Set tags to the listing |
|
478 | + if (isset($request_info['post_tags']) && !is_array($request_info['post_tags']) && !empty($request_info['post_tags'])) { |
|
479 | + $post_tags = explode(",", $request_info['post_tags']); |
|
480 | + } elseif (isset($request_info['post_tags']) && is_array($request_info['post_tags'])) { |
|
481 | + if ($dummy) |
|
482 | + $post_tags = $request_info['post_tags']; |
|
483 | + } else { |
|
484 | + if ($dummy) |
|
485 | + $post_tags = array($request_info['post_title']); |
|
486 | + } |
|
487 | 487 | |
488 | - if (is_array($post_tags)) { |
|
489 | - $taxonomy = $request_info['listing_type'] . '_tags'; |
|
490 | - wp_set_object_terms($last_post_id, $post_tags, $taxonomy); |
|
491 | - } |
|
488 | + if (is_array($post_tags)) { |
|
489 | + $taxonomy = $request_info['listing_type'] . '_tags'; |
|
490 | + wp_set_object_terms($last_post_id, $post_tags, $taxonomy); |
|
491 | + } |
|
492 | 492 | |
493 | 493 | |
494 | - // Insert attachment |
|
494 | + // Insert attachment |
|
495 | 495 | |
496 | - if (isset($request_info['post_images']) && !is_wp_error($last_post_id)) { |
|
497 | - if (!$dummy) { |
|
498 | - $tmpimgArr = trim($request_info['post_images'], ","); |
|
499 | - $tmpimgArr = explode(",", $tmpimgArr); |
|
500 | - geodir_save_post_images($last_post_id, $tmpimgArr, $dummy); |
|
501 | - } else{ |
|
502 | - geodir_save_post_images($last_post_id, $request_info['post_images'], $dummy); |
|
503 | - } |
|
496 | + if (isset($request_info['post_images']) && !is_wp_error($last_post_id)) { |
|
497 | + if (!$dummy) { |
|
498 | + $tmpimgArr = trim($request_info['post_images'], ","); |
|
499 | + $tmpimgArr = explode(",", $tmpimgArr); |
|
500 | + geodir_save_post_images($last_post_id, $tmpimgArr, $dummy); |
|
501 | + } else{ |
|
502 | + geodir_save_post_images($last_post_id, $request_info['post_images'], $dummy); |
|
503 | + } |
|
504 | 504 | |
505 | 505 | |
506 | - } elseif (!isset($request_info['post_images']) || $request_info['post_images'] == '') { |
|
506 | + } elseif (!isset($request_info['post_images']) || $request_info['post_images'] == '') { |
|
507 | 507 | |
508 | - /* Delete Attachments |
|
508 | + /* Delete Attachments |
|
509 | 509 | $postcurr_images = geodir_get_images($last_post_id); |
510 | 510 | |
511 | 511 | $wpdb->query( |
@@ -521,34 +521,34 @@ discard block |
||
521 | 521 | geodir_save_post_info($last_post_id, $gd_post_featured_img); |
522 | 522 | */ |
523 | 523 | |
524 | - } |
|
524 | + } |
|
525 | 525 | |
526 | - geodir_remove_temp_images(); |
|
527 | - geodir_set_wp_featured_image($last_post_id); |
|
526 | + geodir_remove_temp_images(); |
|
527 | + geodir_set_wp_featured_image($last_post_id); |
|
528 | 528 | |
529 | - /** |
|
530 | - * Called after a listing is saved to the database and before any email have been sent. |
|
531 | - * |
|
532 | - * @since 1.0.0 |
|
533 | - * @param int $last_post_id The saved post ID. |
|
534 | - * @param array $request_info The post details in an array. |
|
535 | - * @see 'geodir_after_save_listinginfo' |
|
536 | - */ |
|
537 | - do_action('geodir_after_save_listing', $last_post_id, $request_info); |
|
529 | + /** |
|
530 | + * Called after a listing is saved to the database and before any email have been sent. |
|
531 | + * |
|
532 | + * @since 1.0.0 |
|
533 | + * @param int $last_post_id The saved post ID. |
|
534 | + * @param array $request_info The post details in an array. |
|
535 | + * @see 'geodir_after_save_listinginfo' |
|
536 | + */ |
|
537 | + do_action('geodir_after_save_listing', $last_post_id, $request_info); |
|
538 | 538 | |
539 | - //die; |
|
539 | + //die; |
|
540 | 540 | |
541 | - if ($send_post_submit_mail) { // if new post send out email |
|
542 | - $to_name = geodir_get_client_name($current_user->ID); |
|
543 | - geodir_sendEmail('', '', $current_user->user_email, $to_name, '', '', $request_info, 'post_submit', $last_post_id, $current_user->ID); |
|
544 | - } |
|
545 | - /* |
|
541 | + if ($send_post_submit_mail) { // if new post send out email |
|
542 | + $to_name = geodir_get_client_name($current_user->ID); |
|
543 | + geodir_sendEmail('', '', $current_user->user_email, $to_name, '', '', $request_info, 'post_submit', $last_post_id, $current_user->ID); |
|
544 | + } |
|
545 | + /* |
|
546 | 546 | * Unset the session so we don't loop. |
547 | 547 | */ |
548 | - $gd_session->un_set('listing'); |
|
549 | - return $last_post_id; |
|
548 | + $gd_session->un_set('listing'); |
|
549 | + return $last_post_id; |
|
550 | 550 | |
551 | - } |
|
551 | + } |
|
552 | 552 | |
553 | 553 | } |
554 | 554 | |
@@ -567,599 +567,599 @@ discard block |
||
567 | 567 | function geodir_get_post_info($post_id = '') |
568 | 568 | { |
569 | 569 | |
570 | - global $wpdb, $plugin_prefix, $post, $post_info; |
|
570 | + global $wpdb, $plugin_prefix, $post, $post_info; |
|
571 | 571 | |
572 | - if ($post_id == '' && !empty($post)) |
|
573 | - $post_id = $post->ID; |
|
572 | + if ($post_id == '' && !empty($post)) |
|
573 | + $post_id = $post->ID; |
|
574 | 574 | |
575 | - $post_type = get_post_type($post_id); |
|
575 | + $post_type = get_post_type($post_id); |
|
576 | 576 | |
577 | - $all_postypes = geodir_get_posttypes(); |
|
577 | + $all_postypes = geodir_get_posttypes(); |
|
578 | 578 | |
579 | - if (!in_array($post_type, $all_postypes)) |
|
580 | - return false; |
|
579 | + if (!in_array($post_type, $all_postypes)) |
|
580 | + return false; |
|
581 | 581 | |
582 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
582 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
583 | 583 | |
584 | - /** |
|
585 | - * Apply Filter to change Post info |
|
586 | - * |
|
587 | - * You can use this filter to change Post info. |
|
588 | - * |
|
589 | - * @since 1.0.0 |
|
590 | - * @package GeoDirectory |
|
591 | - */ |
|
592 | - $query = apply_filters('geodir_post_info_query', $wpdb->prepare("SELECT p.*,pd.* FROM " . $wpdb->posts . " p," . $table . " pd |
|
584 | + /** |
|
585 | + * Apply Filter to change Post info |
|
586 | + * |
|
587 | + * You can use this filter to change Post info. |
|
588 | + * |
|
589 | + * @since 1.0.0 |
|
590 | + * @package GeoDirectory |
|
591 | + */ |
|
592 | + $query = apply_filters('geodir_post_info_query', $wpdb->prepare("SELECT p.*,pd.* FROM " . $wpdb->posts . " p," . $table . " pd |
|
593 | 593 | WHERE p.ID = pd.post_id |
594 | 594 | AND pd.post_id = %d", $post_id)); |
595 | 595 | |
596 | - $post_detail = $wpdb->get_row($query); |
|
596 | + $post_detail = $wpdb->get_row($query); |
|
597 | 597 | |
598 | - return (!empty($post_detail)) ? $post_info = $post_detail : $post_info = false; |
|
598 | + return (!empty($post_detail)) ? $post_info = $post_detail : $post_info = false; |
|
599 | 599 | |
600 | 600 | } |
601 | 601 | |
602 | 602 | |
603 | 603 | if (!function_exists('geodir_save_post_info')) { |
604 | - /** |
|
605 | - * Saves post detail info in detail table. |
|
606 | - * |
|
607 | - * @since 1.0.0 |
|
608 | - * @package GeoDirectory |
|
609 | - * @global object $wpdb WordPress Database object. |
|
610 | - * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
611 | - * @param int $post_id The post ID. |
|
612 | - * @param array $postinfo_array { |
|
613 | - * Post info that needs to be saved in detail table. |
|
614 | - * |
|
615 | - * @type string $post_title Listing title. |
|
616 | - * @type string $post_tags Listing tags. |
|
617 | - * @type string $post_status Listing post status. |
|
618 | - * @type string $post_location_id Listing location ID. |
|
619 | - * @type string $claimed Todo Desc needed. |
|
620 | - * @type string $businesses Todo Desc needed. |
|
621 | - * @type int $submit_time Submitted time in unix timestamp. |
|
622 | - * @type string $submit_ip Submitted IP. |
|
623 | - * @type string $expire_date Listing expiration date. |
|
624 | - * @type int $package_id Listing package ID. |
|
625 | - * @type int $alive_days Todo Desc needed. |
|
626 | - * @type int $is_featured Is this a featured listing?. |
|
627 | - * @type string $post_address Listing address. |
|
628 | - * @type string $post_city Listing city. |
|
629 | - * @type string $post_region Listing region. |
|
630 | - * @type string $post_country Listing country. |
|
631 | - * @type string $post_locations Listing locations. |
|
632 | - * @type string $post_zip Listing zip. |
|
633 | - * @type string $post_latitude Listing latitude. |
|
634 | - * @type string $post_longitude Listing longitude. |
|
635 | - * @type string $post_mapview Listing mapview. Default "ROADMAP". |
|
636 | - * @type string $post_mapzoom Listing mapzoom Default "9". |
|
637 | - * @type string $geodir_timing Business timing info. |
|
638 | - * @type string $geodir_contact Contact number. |
|
639 | - * @type string $geodir_email Business contact email. |
|
640 | - * @type string $geodir_website Business website. |
|
641 | - * @type string $geodir_twitter Twitter link. |
|
642 | - * @type string $geodir_facebook Facebook link. |
|
643 | - * @type string $geodir_video Video link. |
|
644 | - * @type string $geodir_special_offers Special offers. |
|
645 | - * |
|
646 | - * } |
|
647 | - * @return bool |
|
648 | - */ |
|
649 | - function geodir_save_post_info($post_id, $postinfo_array = array()) |
|
650 | - { |
|
651 | - global $wpdb, $plugin_prefix; |
|
652 | - |
|
653 | - $post_type = get_post_type($post_id); |
|
654 | - |
|
655 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
656 | - |
|
657 | - /** |
|
658 | - * Filter to change Post info |
|
659 | - * |
|
660 | - * You can use this filter to change Post info. |
|
661 | - * |
|
662 | - * @since 1.0.0 |
|
663 | - * @package GeoDirectory |
|
664 | - * @param array $postinfo_array See {@see geodir_save_post_info()} for accepted args. |
|
665 | - * @param int $post_id The post ID. |
|
666 | - */ |
|
667 | - $postmeta = apply_filters('geodir_listinginfo_request', $postinfo_array, $post_id); |
|
604 | + /** |
|
605 | + * Saves post detail info in detail table. |
|
606 | + * |
|
607 | + * @since 1.0.0 |
|
608 | + * @package GeoDirectory |
|
609 | + * @global object $wpdb WordPress Database object. |
|
610 | + * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
611 | + * @param int $post_id The post ID. |
|
612 | + * @param array $postinfo_array { |
|
613 | + * Post info that needs to be saved in detail table. |
|
614 | + * |
|
615 | + * @type string $post_title Listing title. |
|
616 | + * @type string $post_tags Listing tags. |
|
617 | + * @type string $post_status Listing post status. |
|
618 | + * @type string $post_location_id Listing location ID. |
|
619 | + * @type string $claimed Todo Desc needed. |
|
620 | + * @type string $businesses Todo Desc needed. |
|
621 | + * @type int $submit_time Submitted time in unix timestamp. |
|
622 | + * @type string $submit_ip Submitted IP. |
|
623 | + * @type string $expire_date Listing expiration date. |
|
624 | + * @type int $package_id Listing package ID. |
|
625 | + * @type int $alive_days Todo Desc needed. |
|
626 | + * @type int $is_featured Is this a featured listing?. |
|
627 | + * @type string $post_address Listing address. |
|
628 | + * @type string $post_city Listing city. |
|
629 | + * @type string $post_region Listing region. |
|
630 | + * @type string $post_country Listing country. |
|
631 | + * @type string $post_locations Listing locations. |
|
632 | + * @type string $post_zip Listing zip. |
|
633 | + * @type string $post_latitude Listing latitude. |
|
634 | + * @type string $post_longitude Listing longitude. |
|
635 | + * @type string $post_mapview Listing mapview. Default "ROADMAP". |
|
636 | + * @type string $post_mapzoom Listing mapzoom Default "9". |
|
637 | + * @type string $geodir_timing Business timing info. |
|
638 | + * @type string $geodir_contact Contact number. |
|
639 | + * @type string $geodir_email Business contact email. |
|
640 | + * @type string $geodir_website Business website. |
|
641 | + * @type string $geodir_twitter Twitter link. |
|
642 | + * @type string $geodir_facebook Facebook link. |
|
643 | + * @type string $geodir_video Video link. |
|
644 | + * @type string $geodir_special_offers Special offers. |
|
645 | + * |
|
646 | + * } |
|
647 | + * @return bool |
|
648 | + */ |
|
649 | + function geodir_save_post_info($post_id, $postinfo_array = array()) |
|
650 | + { |
|
651 | + global $wpdb, $plugin_prefix; |
|
652 | + |
|
653 | + $post_type = get_post_type($post_id); |
|
654 | + |
|
655 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
656 | + |
|
657 | + /** |
|
658 | + * Filter to change Post info |
|
659 | + * |
|
660 | + * You can use this filter to change Post info. |
|
661 | + * |
|
662 | + * @since 1.0.0 |
|
663 | + * @package GeoDirectory |
|
664 | + * @param array $postinfo_array See {@see geodir_save_post_info()} for accepted args. |
|
665 | + * @param int $post_id The post ID. |
|
666 | + */ |
|
667 | + $postmeta = apply_filters('geodir_listinginfo_request', $postinfo_array, $post_id); |
|
668 | + |
|
669 | + $query_string_escaped = ''; |
|
670 | + $query_string_array = array(); |
|
671 | + |
|
672 | + if (!empty($postmeta) && $post_id) { |
|
673 | + |
|
674 | + $columns = $wpdb->get_col("show columns from $table"); |
|
675 | + foreach ($postmeta as $mkey => $mval) { |
|
676 | + if(in_array($mkey,$columns)) { |
|
677 | + if (is_array($mval)) { |
|
678 | + $mval = implode(",", $mval); |
|
679 | + } |
|
680 | + $query_string_escaped .= " $mkey = %s, "; // we can set the key here as we check if the column exists above |
|
681 | + $query_string_array[] = stripslashes($mval); // we strip slashes as we are using wpdb prepare |
|
668 | 682 | |
669 | - $query_string_escaped = ''; |
|
670 | - $query_string_array = array(); |
|
683 | + } |
|
684 | + } |
|
671 | 685 | |
672 | - if (!empty($postmeta) && $post_id) { |
|
686 | + $query_string_escaped = trim($query_string_escaped, ", "); |
|
673 | 687 | |
674 | - $columns = $wpdb->get_col("show columns from $table"); |
|
675 | - foreach ($postmeta as $mkey => $mval) { |
|
676 | - if(in_array($mkey,$columns)) { |
|
677 | - if (is_array($mval)) { |
|
678 | - $mval = implode(",", $mval); |
|
679 | - } |
|
680 | - $query_string_escaped .= " $mkey = %s, "; // we can set the key here as we check if the column exists above |
|
681 | - $query_string_array[] = stripslashes($mval); // we strip slashes as we are using wpdb prepare |
|
688 | + if (empty($query_string_array) || trim($query_string_escaped) == '') { |
|
689 | + return false; |
|
690 | + } |
|
682 | 691 | |
683 | - } |
|
684 | - } |
|
692 | + $query_string_array = str_replace(array("'%", "%'"), array("'%%", "%%'"), $query_string_array); |
|
685 | 693 | |
686 | - $query_string_escaped = trim($query_string_escaped, ", "); |
|
687 | 694 | |
688 | - if (empty($query_string_array) || trim($query_string_escaped) == '') { |
|
689 | - return false; |
|
690 | - } |
|
695 | + /** |
|
696 | + * Called before saving the listing info. |
|
697 | + * |
|
698 | + * @since 1.0.0 |
|
699 | + * @package GeoDirectory |
|
700 | + * @param array $postinfo_array See {@see geodir_save_post_info()} for accepted args. |
|
701 | + * @param int $post_id The post ID. |
|
702 | + */ |
|
703 | + do_action('geodir_before_save_listinginfo', $postinfo_array, $post_id); |
|
691 | 704 | |
692 | - $query_string_array = str_replace(array("'%", "%'"), array("'%%", "%%'"), $query_string_array); |
|
705 | + if ($wpdb->get_var($wpdb->prepare("SELECT post_id from " . $table . " where post_id = %d", array($post_id)))) { |
|
693 | 706 | |
707 | + $query_string_array[] = $post_id; |
|
708 | + $wpdb->query( |
|
709 | + $wpdb->prepare( |
|
710 | + "UPDATE " . $table . " SET " . $query_string_escaped . " where post_id =%d", |
|
711 | + $query_string_array |
|
712 | + ) |
|
713 | + ); |
|
694 | 714 | |
695 | - /** |
|
696 | - * Called before saving the listing info. |
|
697 | - * |
|
698 | - * @since 1.0.0 |
|
699 | - * @package GeoDirectory |
|
700 | - * @param array $postinfo_array See {@see geodir_save_post_info()} for accepted args. |
|
701 | - * @param int $post_id The post ID. |
|
702 | - */ |
|
703 | - do_action('geodir_before_save_listinginfo', $postinfo_array, $post_id); |
|
704 | 715 | |
705 | - if ($wpdb->get_var($wpdb->prepare("SELECT post_id from " . $table . " where post_id = %d", array($post_id)))) { |
|
716 | + } else { |
|
706 | 717 | |
707 | - $query_string_array[] = $post_id; |
|
708 | - $wpdb->query( |
|
709 | - $wpdb->prepare( |
|
710 | - "UPDATE " . $table . " SET " . $query_string_escaped . " where post_id =%d", |
|
711 | - $query_string_array |
|
712 | - ) |
|
713 | - ); |
|
718 | + array_unshift($query_string_array, $post_id); |
|
719 | + $wpdb->query( |
|
720 | + $wpdb->prepare( |
|
721 | + "INSERT INTO " . $table . " SET post_id = %d," . $query_string_escaped, |
|
722 | + $query_string_array |
|
723 | + ) |
|
724 | + ); |
|
725 | + |
|
726 | + } |
|
714 | 727 | |
728 | + /** |
|
729 | + * Called after saving the listing info. |
|
730 | + * |
|
731 | + * @since 1.0.0 |
|
732 | + * @package GeoDirectory |
|
733 | + * @param array $postinfo_array Post info that needs to be saved in detail table. |
|
734 | + * @param int $post_id The post ID. |
|
735 | + * @see 'geodir_after_save_listing' |
|
736 | + */ |
|
737 | + do_action('geodir_after_save_listinginfo', $postinfo_array, $post_id); |
|
738 | + |
|
739 | + return true; |
|
740 | + } else |
|
741 | + return false; |
|
715 | 742 | |
716 | - } else { |
|
743 | + } |
|
744 | +} |
|
717 | 745 | |
718 | - array_unshift($query_string_array, $post_id); |
|
719 | - $wpdb->query( |
|
720 | - $wpdb->prepare( |
|
721 | - "INSERT INTO " . $table . " SET post_id = %d," . $query_string_escaped, |
|
722 | - $query_string_array |
|
723 | - ) |
|
724 | - ); |
|
725 | - |
|
726 | - } |
|
727 | 746 | |
728 | - /** |
|
729 | - * Called after saving the listing info. |
|
730 | - * |
|
731 | - * @since 1.0.0 |
|
732 | - * @package GeoDirectory |
|
733 | - * @param array $postinfo_array Post info that needs to be saved in detail table. |
|
734 | - * @param int $post_id The post ID. |
|
735 | - * @see 'geodir_after_save_listing' |
|
736 | - */ |
|
737 | - do_action('geodir_after_save_listinginfo', $postinfo_array, $post_id); |
|
747 | +if (!function_exists('geodir_save_post_meta')) { |
|
748 | + /** |
|
749 | + * Save or update post custom fields. |
|
750 | + * |
|
751 | + * @since 1.0.0 |
|
752 | + * @package GeoDirectory |
|
753 | + * @global object $wpdb WordPress Database object. |
|
754 | + * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
755 | + * @param int $post_id The post ID. |
|
756 | + * @param string $postmeta Detail table column name. |
|
757 | + * @param string $meta_value Detail table column value. |
|
758 | + * @return void|bool |
|
759 | + */ |
|
760 | + function geodir_save_post_meta($post_id, $postmeta = '', $meta_value = '') |
|
761 | + { |
|
762 | + |
|
763 | + global $wpdb, $plugin_prefix; |
|
764 | + |
|
765 | + $post_type = get_post_type($post_id); |
|
766 | + |
|
767 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
768 | + |
|
769 | + if ($postmeta != '' && geodir_column_exist($table, $postmeta) && $post_id) { |
|
770 | + |
|
771 | + if (is_array($meta_value)) { |
|
772 | + $meta_value = implode(",", $meta_value); |
|
773 | + } |
|
738 | 774 | |
739 | - return true; |
|
740 | - } else |
|
741 | - return false; |
|
775 | + if ($wpdb->get_var($wpdb->prepare("SELECT post_id from " . $table . " where post_id = %d", array($post_id)))) { |
|
742 | 776 | |
743 | - } |
|
744 | -} |
|
777 | + $wpdb->query( |
|
778 | + $wpdb->prepare( |
|
779 | + "UPDATE " . $table . " SET " . $postmeta . " = '" . $meta_value . "' where post_id =%d", |
|
780 | + array($post_id) |
|
781 | + ) |
|
782 | + ); |
|
745 | 783 | |
784 | + } else { |
|
746 | 785 | |
747 | -if (!function_exists('geodir_save_post_meta')) { |
|
748 | - /** |
|
749 | - * Save or update post custom fields. |
|
750 | - * |
|
751 | - * @since 1.0.0 |
|
752 | - * @package GeoDirectory |
|
753 | - * @global object $wpdb WordPress Database object. |
|
754 | - * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
755 | - * @param int $post_id The post ID. |
|
756 | - * @param string $postmeta Detail table column name. |
|
757 | - * @param string $meta_value Detail table column value. |
|
758 | - * @return void|bool |
|
759 | - */ |
|
760 | - function geodir_save_post_meta($post_id, $postmeta = '', $meta_value = '') |
|
761 | - { |
|
762 | - |
|
763 | - global $wpdb, $plugin_prefix; |
|
764 | - |
|
765 | - $post_type = get_post_type($post_id); |
|
766 | - |
|
767 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
768 | - |
|
769 | - if ($postmeta != '' && geodir_column_exist($table, $postmeta) && $post_id) { |
|
770 | - |
|
771 | - if (is_array($meta_value)) { |
|
772 | - $meta_value = implode(",", $meta_value); |
|
773 | - } |
|
774 | - |
|
775 | - if ($wpdb->get_var($wpdb->prepare("SELECT post_id from " . $table . " where post_id = %d", array($post_id)))) { |
|
776 | - |
|
777 | - $wpdb->query( |
|
778 | - $wpdb->prepare( |
|
779 | - "UPDATE " . $table . " SET " . $postmeta . " = '" . $meta_value . "' where post_id =%d", |
|
780 | - array($post_id) |
|
781 | - ) |
|
782 | - ); |
|
783 | - |
|
784 | - } else { |
|
785 | - |
|
786 | - $wpdb->query( |
|
787 | - $wpdb->prepare( |
|
788 | - "INSERT INTO " . $table . " SET post_id = %d, " . $postmeta . " = '" . $meta_value . "'", |
|
789 | - array($post_id) |
|
790 | - ) |
|
791 | - ); |
|
792 | - } |
|
793 | - |
|
794 | - |
|
795 | - } else |
|
796 | - return false; |
|
797 | - } |
|
786 | + $wpdb->query( |
|
787 | + $wpdb->prepare( |
|
788 | + "INSERT INTO " . $table . " SET post_id = %d, " . $postmeta . " = '" . $meta_value . "'", |
|
789 | + array($post_id) |
|
790 | + ) |
|
791 | + ); |
|
792 | + } |
|
793 | + |
|
794 | + |
|
795 | + } else |
|
796 | + return false; |
|
797 | + } |
|
798 | 798 | } |
799 | 799 | |
800 | 800 | if (!function_exists('geodir_delete_post_meta')) { |
801 | - /** |
|
802 | - * Delete post custom fields. |
|
803 | - * |
|
804 | - * @since 1.0.0 |
|
805 | - * @package GeoDirectory |
|
806 | - * @global object $wpdb WordPress Database object. |
|
807 | - * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
808 | - * @param int $post_id The post ID. |
|
809 | - * @param string $postmeta Detail table column name. |
|
810 | - * @todo check if this is depreciated |
|
811 | - * @todo Fix unknown variable mval |
|
812 | - * @return bool |
|
813 | - */ |
|
814 | - function geodir_delete_post_meta($post_id, $postmeta) |
|
815 | - { |
|
816 | - |
|
817 | - global $wpdb, $plugin_prefix; |
|
818 | - |
|
819 | - $post_type = get_post_type($post_id); |
|
820 | - |
|
821 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
822 | - |
|
823 | - if (is_array($postmeta) && !empty($postmeta) && $post_id) { |
|
824 | - $post_meta_set_query = ''; |
|
825 | - |
|
826 | - foreach ($postmeta as $mkey) { |
|
827 | - if ($mval != '') |
|
828 | - $post_meta_set_query .= $mkey . " = '', "; |
|
829 | - } |
|
830 | - |
|
831 | - $post_meta_set_query = trim($post_meta_set_query, ", "); |
|
801 | + /** |
|
802 | + * Delete post custom fields. |
|
803 | + * |
|
804 | + * @since 1.0.0 |
|
805 | + * @package GeoDirectory |
|
806 | + * @global object $wpdb WordPress Database object. |
|
807 | + * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
808 | + * @param int $post_id The post ID. |
|
809 | + * @param string $postmeta Detail table column name. |
|
810 | + * @todo check if this is depreciated |
|
811 | + * @todo Fix unknown variable mval |
|
812 | + * @return bool |
|
813 | + */ |
|
814 | + function geodir_delete_post_meta($post_id, $postmeta) |
|
815 | + { |
|
816 | + |
|
817 | + global $wpdb, $plugin_prefix; |
|
818 | + |
|
819 | + $post_type = get_post_type($post_id); |
|
820 | + |
|
821 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
822 | + |
|
823 | + if (is_array($postmeta) && !empty($postmeta) && $post_id) { |
|
824 | + $post_meta_set_query = ''; |
|
825 | + |
|
826 | + foreach ($postmeta as $mkey) { |
|
827 | + if ($mval != '') |
|
828 | + $post_meta_set_query .= $mkey . " = '', "; |
|
829 | + } |
|
830 | + |
|
831 | + $post_meta_set_query = trim($post_meta_set_query, ", "); |
|
832 | 832 | |
833 | - if (empty($post_meta_set_query) || trim($post_meta_set_query) == '') { |
|
834 | - return false; |
|
835 | - } |
|
836 | - |
|
837 | - if ($wpdb->get_var("SHOW COLUMNS FROM " . $table . " WHERE field = '" . $postmeta . "'") != '') { |
|
838 | - |
|
839 | - $wpdb->query( |
|
840 | - $wpdb->prepare( |
|
841 | - "UPDATE " . $table . " SET " . $post_meta_set_query . " where post_id = %d", |
|
842 | - array($post_id) |
|
843 | - ) |
|
844 | - ); |
|
845 | - |
|
846 | - return true; |
|
847 | - } |
|
848 | - |
|
849 | - } elseif ($postmeta != '' && $post_id) { |
|
850 | - if ($wpdb->get_var("SHOW COLUMNS FROM " . $table . " WHERE field = '" . $postmeta . "'") != '') { |
|
851 | - |
|
852 | - $wpdb->query( |
|
853 | - $wpdb->prepare( |
|
854 | - "UPDATE " . $table . " SET " . $postmeta . "= '' where post_id = %d", |
|
855 | - array($post_id) |
|
856 | - ) |
|
857 | - ); |
|
858 | - |
|
859 | - return true; |
|
860 | - } |
|
861 | - |
|
862 | - } else |
|
863 | - return false; |
|
864 | - } |
|
833 | + if (empty($post_meta_set_query) || trim($post_meta_set_query) == '') { |
|
834 | + return false; |
|
835 | + } |
|
836 | + |
|
837 | + if ($wpdb->get_var("SHOW COLUMNS FROM " . $table . " WHERE field = '" . $postmeta . "'") != '') { |
|
838 | + |
|
839 | + $wpdb->query( |
|
840 | + $wpdb->prepare( |
|
841 | + "UPDATE " . $table . " SET " . $post_meta_set_query . " where post_id = %d", |
|
842 | + array($post_id) |
|
843 | + ) |
|
844 | + ); |
|
845 | + |
|
846 | + return true; |
|
847 | + } |
|
848 | + |
|
849 | + } elseif ($postmeta != '' && $post_id) { |
|
850 | + if ($wpdb->get_var("SHOW COLUMNS FROM " . $table . " WHERE field = '" . $postmeta . "'") != '') { |
|
851 | + |
|
852 | + $wpdb->query( |
|
853 | + $wpdb->prepare( |
|
854 | + "UPDATE " . $table . " SET " . $postmeta . "= '' where post_id = %d", |
|
855 | + array($post_id) |
|
856 | + ) |
|
857 | + ); |
|
858 | + |
|
859 | + return true; |
|
860 | + } |
|
861 | + |
|
862 | + } else |
|
863 | + return false; |
|
864 | + } |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | |
868 | 868 | if (!function_exists('geodir_get_post_meta')) { |
869 | - /** |
|
870 | - * Get post custom meta. |
|
871 | - * |
|
872 | - * @since 1.0.0 |
|
873 | - * @package GeoDirectory |
|
874 | - * @global object $wpdb WordPress Database object. |
|
875 | - * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
876 | - * @param int $post_id The post ID. |
|
877 | - * @param string $meta_key The meta key to retrieve. |
|
878 | - * @param bool $single Optional. Whether to return a single value. Default false. |
|
879 | - * @todo single variable not yet implemented. |
|
880 | - * @return bool|mixed|null|string Will be an array if $single is false. Will be value of meta data field if $single is true. |
|
881 | - */ |
|
882 | - function geodir_get_post_meta($post_id, $meta_key, $single = false) |
|
883 | - { |
|
884 | - if (!$post_id) { |
|
885 | - return false; |
|
886 | - } |
|
887 | - global $wpdb, $plugin_prefix; |
|
888 | - |
|
889 | - $all_postypes = geodir_get_posttypes(); |
|
890 | - |
|
891 | - $post_type = get_post_type($post_id); |
|
892 | - |
|
893 | - if (!in_array($post_type, $all_postypes)) |
|
894 | - return false; |
|
895 | - |
|
896 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
897 | - |
|
898 | - if ($wpdb->get_var("SHOW COLUMNS FROM " . $table . " WHERE field = '" . $meta_key . "'") != '') { |
|
899 | - $meta_value = $wpdb->get_var($wpdb->prepare("SELECT " . $meta_key . " from " . $table . " where post_id = %d", array($post_id))); |
|
900 | - if ($meta_value && $meta_value !== '') { |
|
901 | - return maybe_serialize($meta_value); |
|
902 | - } else |
|
903 | - return $meta_value; |
|
904 | - } else { |
|
905 | - return false; |
|
906 | - } |
|
907 | - } |
|
869 | + /** |
|
870 | + * Get post custom meta. |
|
871 | + * |
|
872 | + * @since 1.0.0 |
|
873 | + * @package GeoDirectory |
|
874 | + * @global object $wpdb WordPress Database object. |
|
875 | + * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
876 | + * @param int $post_id The post ID. |
|
877 | + * @param string $meta_key The meta key to retrieve. |
|
878 | + * @param bool $single Optional. Whether to return a single value. Default false. |
|
879 | + * @todo single variable not yet implemented. |
|
880 | + * @return bool|mixed|null|string Will be an array if $single is false. Will be value of meta data field if $single is true. |
|
881 | + */ |
|
882 | + function geodir_get_post_meta($post_id, $meta_key, $single = false) |
|
883 | + { |
|
884 | + if (!$post_id) { |
|
885 | + return false; |
|
886 | + } |
|
887 | + global $wpdb, $plugin_prefix; |
|
888 | + |
|
889 | + $all_postypes = geodir_get_posttypes(); |
|
890 | + |
|
891 | + $post_type = get_post_type($post_id); |
|
892 | + |
|
893 | + if (!in_array($post_type, $all_postypes)) |
|
894 | + return false; |
|
895 | + |
|
896 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
897 | + |
|
898 | + if ($wpdb->get_var("SHOW COLUMNS FROM " . $table . " WHERE field = '" . $meta_key . "'") != '') { |
|
899 | + $meta_value = $wpdb->get_var($wpdb->prepare("SELECT " . $meta_key . " from " . $table . " where post_id = %d", array($post_id))); |
|
900 | + if ($meta_value && $meta_value !== '') { |
|
901 | + return maybe_serialize($meta_value); |
|
902 | + } else |
|
903 | + return $meta_value; |
|
904 | + } else { |
|
905 | + return false; |
|
906 | + } |
|
907 | + } |
|
908 | 908 | } |
909 | 909 | |
910 | 910 | |
911 | 911 | if (!function_exists('geodir_save_post_images')) { |
912 | - /** |
|
913 | - * Save post attachments. |
|
914 | - * |
|
915 | - * @since 1.0.0 |
|
916 | - * @package GeoDirectory |
|
917 | - * @global object $wpdb WordPress Database object. |
|
918 | - * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
919 | - * @global object $current_user Current user object. |
|
920 | - * @param int $post_id The post ID. |
|
921 | - * @param array $post_image Post image urls as an array. |
|
922 | - * @param bool $dummy Optional. Is this a dummy listing? Default false. |
|
923 | - */ |
|
924 | - function geodir_save_post_images($post_id = 0, $post_image = array(), $dummy = false) |
|
925 | - { |
|
926 | - |
|
912 | + /** |
|
913 | + * Save post attachments. |
|
914 | + * |
|
915 | + * @since 1.0.0 |
|
916 | + * @package GeoDirectory |
|
917 | + * @global object $wpdb WordPress Database object. |
|
918 | + * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
919 | + * @global object $current_user Current user object. |
|
920 | + * @param int $post_id The post ID. |
|
921 | + * @param array $post_image Post image urls as an array. |
|
922 | + * @param bool $dummy Optional. Is this a dummy listing? Default false. |
|
923 | + */ |
|
924 | + function geodir_save_post_images($post_id = 0, $post_image = array(), $dummy = false) |
|
925 | + { |
|
927 | 926 | |
928 | - global $wpdb, $plugin_prefix, $current_user; |
|
929 | 927 | |
930 | - $post_type = get_post_type($post_id); |
|
928 | + global $wpdb, $plugin_prefix, $current_user; |
|
931 | 929 | |
932 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
930 | + $post_type = get_post_type($post_id); |
|
933 | 931 | |
934 | - $post_images = geodir_get_images($post_id); |
|
932 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
935 | 933 | |
936 | - $wpdb->query( |
|
937 | - $wpdb->prepare( |
|
938 | - "UPDATE " . $table . " SET featured_image = '' where post_id =%d", |
|
939 | - array($post_id) |
|
940 | - ) |
|
941 | - ); |
|
934 | + $post_images = geodir_get_images($post_id); |
|
942 | 935 | |
943 | - $invalid_files = $post_images; |
|
944 | - $valid_file_ids = array(); |
|
945 | - $valid_files_condition = ''; |
|
946 | - $geodir_uploaddir = ''; |
|
936 | + $wpdb->query( |
|
937 | + $wpdb->prepare( |
|
938 | + "UPDATE " . $table . " SET featured_image = '' where post_id =%d", |
|
939 | + array($post_id) |
|
940 | + ) |
|
941 | + ); |
|
947 | 942 | |
948 | - $remove_files = array(); |
|
943 | + $invalid_files = $post_images; |
|
944 | + $valid_file_ids = array(); |
|
945 | + $valid_files_condition = ''; |
|
946 | + $geodir_uploaddir = ''; |
|
949 | 947 | |
950 | - if (!empty($post_image)) { |
|
948 | + $remove_files = array(); |
|
951 | 949 | |
952 | - $uploads = wp_upload_dir(); |
|
953 | - $uploads_dir = $uploads['path']; |
|
950 | + if (!empty($post_image)) { |
|
954 | 951 | |
955 | - $geodir_uploadpath = $uploads['path']; |
|
956 | - $geodir_uploadurl = $uploads['url']; |
|
957 | - $sub_dir = isset($uploads['subdir']) ? $uploads['subdir'] : ''; |
|
952 | + $uploads = wp_upload_dir(); |
|
953 | + $uploads_dir = $uploads['path']; |
|
958 | 954 | |
959 | - $invalid_files = array(); |
|
960 | - $postcurr_images = array(); |
|
955 | + $geodir_uploadpath = $uploads['path']; |
|
956 | + $geodir_uploadurl = $uploads['url']; |
|
957 | + $sub_dir = isset($uploads['subdir']) ? $uploads['subdir'] : ''; |
|
961 | 958 | |
962 | - for ($m = 0; $m < count($post_image); $m++) { |
|
963 | - $menu_order = $m + 1; |
|
959 | + $invalid_files = array(); |
|
960 | + $postcurr_images = array(); |
|
964 | 961 | |
965 | - $file_path = ''; |
|
966 | - /* --------- start ------- */ |
|
962 | + for ($m = 0; $m < count($post_image); $m++) { |
|
963 | + $menu_order = $m + 1; |
|
967 | 964 | |
968 | - $split_img_path = explode(str_replace(array('http://','https://'),'',$uploads['baseurl']), str_replace(array('http://','https://'),'',$post_image[$m])); |
|
965 | + $file_path = ''; |
|
966 | + /* --------- start ------- */ |
|
969 | 967 | |
970 | - $split_img_file_path = isset($split_img_path[1]) ? $split_img_path[1] : ''; |
|
968 | + $split_img_path = explode(str_replace(array('http://','https://'),'',$uploads['baseurl']), str_replace(array('http://','https://'),'',$post_image[$m])); |
|
971 | 969 | |
970 | + $split_img_file_path = isset($split_img_path[1]) ? $split_img_path[1] : ''; |
|
972 | 971 | |
973 | - if (!$find_image = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE file=%s AND post_id = %d", array($split_img_file_path, $post_id)))) { |
|
974 | 972 | |
975 | - /* --------- end ------- */ |
|
976 | - $curr_img_url = $post_image[$m]; |
|
973 | + if (!$find_image = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE file=%s AND post_id = %d", array($split_img_file_path, $post_id)))) { |
|
977 | 974 | |
978 | - $image_name_arr = explode('/', $curr_img_url); |
|
975 | + /* --------- end ------- */ |
|
976 | + $curr_img_url = $post_image[$m]; |
|
979 | 977 | |
980 | - $count_image_name_arr = count($image_name_arr) - 2; |
|
978 | + $image_name_arr = explode('/', $curr_img_url); |
|
981 | 979 | |
982 | - $count_image_name_arr = ($count_image_name_arr >= 0) ? $count_image_name_arr : 0; |
|
980 | + $count_image_name_arr = count($image_name_arr) - 2; |
|
983 | 981 | |
984 | - $curr_img_dir = $image_name_arr[$count_image_name_arr]; |
|
982 | + $count_image_name_arr = ($count_image_name_arr >= 0) ? $count_image_name_arr : 0; |
|
985 | 983 | |
986 | - $filename = end($image_name_arr); |
|
987 | - if (strpos($filename, '?') !== false) { |
|
988 | - list($filename) = explode('?', $filename); |
|
989 | - } |
|
984 | + $curr_img_dir = $image_name_arr[$count_image_name_arr]; |
|
990 | 985 | |
991 | - $curr_img_dir = str_replace($uploads['baseurl'], "", $curr_img_url); |
|
992 | - $curr_img_dir = str_replace($filename, "", $curr_img_dir); |
|
986 | + $filename = end($image_name_arr); |
|
987 | + if (strpos($filename, '?') !== false) { |
|
988 | + list($filename) = explode('?', $filename); |
|
989 | + } |
|
993 | 990 | |
994 | - $img_name_arr = explode('.', $filename); |
|
991 | + $curr_img_dir = str_replace($uploads['baseurl'], "", $curr_img_url); |
|
992 | + $curr_img_dir = str_replace($filename, "", $curr_img_dir); |
|
995 | 993 | |
996 | - $file_title = isset($img_name_arr[0]) ? $img_name_arr[0] : $filename; |
|
997 | - if (!empty($img_name_arr) && count($img_name_arr) > 2) { |
|
998 | - $new_img_name_arr = $img_name_arr; |
|
999 | - if (isset($new_img_name_arr[count($img_name_arr) - 1])) { |
|
1000 | - unset($new_img_name_arr[count($img_name_arr) - 1]); |
|
1001 | - $file_title = implode('.', $new_img_name_arr); |
|
1002 | - } |
|
1003 | - } |
|
1004 | - $file_title = sanitize_file_name($file_title); |
|
1005 | - $file_name = sanitize_file_name($filename); |
|
994 | + $img_name_arr = explode('.', $filename); |
|
1006 | 995 | |
1007 | - $arr_file_type = wp_check_filetype($filename); |
|
996 | + $file_title = isset($img_name_arr[0]) ? $img_name_arr[0] : $filename; |
|
997 | + if (!empty($img_name_arr) && count($img_name_arr) > 2) { |
|
998 | + $new_img_name_arr = $img_name_arr; |
|
999 | + if (isset($new_img_name_arr[count($img_name_arr) - 1])) { |
|
1000 | + unset($new_img_name_arr[count($img_name_arr) - 1]); |
|
1001 | + $file_title = implode('.', $new_img_name_arr); |
|
1002 | + } |
|
1003 | + } |
|
1004 | + $file_title = sanitize_file_name($file_title); |
|
1005 | + $file_name = sanitize_file_name($filename); |
|
1008 | 1006 | |
1009 | - $uploaded_file_type = $arr_file_type['type']; |
|
1007 | + $arr_file_type = wp_check_filetype($filename); |
|
1010 | 1008 | |
1011 | - // Set an array containing a list of acceptable formats |
|
1012 | - $allowed_file_types = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png'); |
|
1009 | + $uploaded_file_type = $arr_file_type['type']; |
|
1013 | 1010 | |
1014 | - // If the uploaded file is the right format |
|
1015 | - if (in_array($uploaded_file_type, $allowed_file_types)) { |
|
1016 | - if (!function_exists('wp_handle_upload')) { |
|
1017 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
1018 | - } |
|
1011 | + // Set an array containing a list of acceptable formats |
|
1012 | + $allowed_file_types = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png'); |
|
1019 | 1013 | |
1020 | - if (!is_dir($geodir_uploadpath)) { |
|
1021 | - mkdir($geodir_uploadpath); |
|
1022 | - } |
|
1014 | + // If the uploaded file is the right format |
|
1015 | + if (in_array($uploaded_file_type, $allowed_file_types)) { |
|
1016 | + if (!function_exists('wp_handle_upload')) { |
|
1017 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
1018 | + } |
|
1023 | 1019 | |
1024 | - $external_img = false; |
|
1025 | - if (strpos( str_replace( array('http://','https://'),'',$curr_img_url ), str_replace(array('http://','https://'),'',$uploads['baseurl'] ) ) !== false) { |
|
1026 | - } else { |
|
1027 | - $external_img = true; |
|
1028 | - } |
|
1020 | + if (!is_dir($geodir_uploadpath)) { |
|
1021 | + mkdir($geodir_uploadpath); |
|
1022 | + } |
|
1029 | 1023 | |
1030 | - if ($dummy || $external_img) { |
|
1031 | - $uploaded_file = array(); |
|
1032 | - $uploaded = (array)fetch_remote_file($curr_img_url); |
|
1024 | + $external_img = false; |
|
1025 | + if (strpos( str_replace( array('http://','https://'),'',$curr_img_url ), str_replace(array('http://','https://'),'',$uploads['baseurl'] ) ) !== false) { |
|
1026 | + } else { |
|
1027 | + $external_img = true; |
|
1028 | + } |
|
1033 | 1029 | |
1034 | - if (isset($uploaded['error']) && empty($uploaded['error'])) { |
|
1035 | - $new_name = basename($uploaded['file']); |
|
1036 | - $uploaded_file = $uploaded; |
|
1037 | - }else{ |
|
1038 | - print_r($uploaded);exit; |
|
1039 | - } |
|
1040 | - $external_img = false; |
|
1041 | - } else { |
|
1042 | - $new_name = $post_id . '_' . $file_name; |
|
1030 | + if ($dummy || $external_img) { |
|
1031 | + $uploaded_file = array(); |
|
1032 | + $uploaded = (array)fetch_remote_file($curr_img_url); |
|
1043 | 1033 | |
1044 | - if ($curr_img_dir == $sub_dir) { |
|
1045 | - $img_path = $geodir_uploadpath . '/' . $filename; |
|
1046 | - $img_url = $geodir_uploadurl . '/' . $filename; |
|
1047 | - } else { |
|
1048 | - $img_path = $uploads_dir . '/temp_' . $current_user->data->ID . '/' . $filename; |
|
1049 | - $img_url = $uploads['url'] . '/temp_' . $current_user->data->ID . '/' . $filename; |
|
1050 | - } |
|
1034 | + if (isset($uploaded['error']) && empty($uploaded['error'])) { |
|
1035 | + $new_name = basename($uploaded['file']); |
|
1036 | + $uploaded_file = $uploaded; |
|
1037 | + }else{ |
|
1038 | + print_r($uploaded);exit; |
|
1039 | + } |
|
1040 | + $external_img = false; |
|
1041 | + } else { |
|
1042 | + $new_name = $post_id . '_' . $file_name; |
|
1051 | 1043 | |
1052 | - $uploaded_file = ''; |
|
1044 | + if ($curr_img_dir == $sub_dir) { |
|
1045 | + $img_path = $geodir_uploadpath . '/' . $filename; |
|
1046 | + $img_url = $geodir_uploadurl . '/' . $filename; |
|
1047 | + } else { |
|
1048 | + $img_path = $uploads_dir . '/temp_' . $current_user->data->ID . '/' . $filename; |
|
1049 | + $img_url = $uploads['url'] . '/temp_' . $current_user->data->ID . '/' . $filename; |
|
1050 | + } |
|
1053 | 1051 | |
1054 | - if (file_exists($img_path)) { |
|
1055 | - $uploaded_file = copy($img_path, $geodir_uploadpath . '/' . $new_name); |
|
1056 | - $file_path = ''; |
|
1057 | - } else if (file_exists($uploads['basedir'] . $curr_img_dir . $filename)) { |
|
1058 | - $uploaded_file = true; |
|
1059 | - $file_path = $curr_img_dir . '/' . $filename; |
|
1060 | - } |
|
1052 | + $uploaded_file = ''; |
|
1061 | 1053 | |
1062 | - if ($curr_img_dir != $geodir_uploaddir && file_exists($img_path)) |
|
1063 | - unlink($img_path); |
|
1064 | - } |
|
1054 | + if (file_exists($img_path)) { |
|
1055 | + $uploaded_file = copy($img_path, $geodir_uploadpath . '/' . $new_name); |
|
1056 | + $file_path = ''; |
|
1057 | + } else if (file_exists($uploads['basedir'] . $curr_img_dir . $filename)) { |
|
1058 | + $uploaded_file = true; |
|
1059 | + $file_path = $curr_img_dir . '/' . $filename; |
|
1060 | + } |
|
1065 | 1061 | |
1066 | - if (!empty($uploaded_file)) { |
|
1067 | - if (!isset($file_path) || !$file_path) { |
|
1068 | - $file_path = $sub_dir . '/' . $new_name; |
|
1069 | - } |
|
1062 | + if ($curr_img_dir != $geodir_uploaddir && file_exists($img_path)) |
|
1063 | + unlink($img_path); |
|
1064 | + } |
|
1070 | 1065 | |
1071 | - $postcurr_images[] = str_replace(array('http://','https://'),'',$uploads['baseurl'] . $file_path); |
|
1066 | + if (!empty($uploaded_file)) { |
|
1067 | + if (!isset($file_path) || !$file_path) { |
|
1068 | + $file_path = $sub_dir . '/' . $new_name; |
|
1069 | + } |
|
1072 | 1070 | |
1073 | - if ($menu_order == 1) { |
|
1071 | + $postcurr_images[] = str_replace(array('http://','https://'),'',$uploads['baseurl'] . $file_path); |
|
1074 | 1072 | |
1075 | - $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET featured_image = %s where post_id =%d", array($file_path, $post_id))); |
|
1073 | + if ($menu_order == 1) { |
|
1076 | 1074 | |
1077 | - } |
|
1075 | + $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET featured_image = %s where post_id =%d", array($file_path, $post_id))); |
|
1078 | 1076 | |
1079 | - // Set up options array to add this file as an attachment |
|
1080 | - $attachment = array(); |
|
1081 | - $attachment['post_id'] = $post_id; |
|
1082 | - $attachment['title'] = $file_title; |
|
1083 | - $attachment['content'] = ''; |
|
1084 | - $attachment['file'] = $file_path; |
|
1085 | - $attachment['mime_type'] = $uploaded_file_type; |
|
1086 | - $attachment['menu_order'] = $menu_order; |
|
1087 | - $attachment['is_featured'] = 0; |
|
1077 | + } |
|
1088 | 1078 | |
1089 | - $attachment_set = ''; |
|
1079 | + // Set up options array to add this file as an attachment |
|
1080 | + $attachment = array(); |
|
1081 | + $attachment['post_id'] = $post_id; |
|
1082 | + $attachment['title'] = $file_title; |
|
1083 | + $attachment['content'] = ''; |
|
1084 | + $attachment['file'] = $file_path; |
|
1085 | + $attachment['mime_type'] = $uploaded_file_type; |
|
1086 | + $attachment['menu_order'] = $menu_order; |
|
1087 | + $attachment['is_featured'] = 0; |
|
1090 | 1088 | |
1091 | - foreach ($attachment as $key => $val) { |
|
1092 | - if ($val != '') |
|
1093 | - $attachment_set .= $key . " = '" . $val . "', "; |
|
1094 | - } |
|
1089 | + $attachment_set = ''; |
|
1095 | 1090 | |
1096 | - $attachment_set = trim($attachment_set, ", "); |
|
1091 | + foreach ($attachment as $key => $val) { |
|
1092 | + if ($val != '') |
|
1093 | + $attachment_set .= $key . " = '" . $val . "', "; |
|
1094 | + } |
|
1097 | 1095 | |
1098 | - $wpdb->query("INSERT INTO " . GEODIR_ATTACHMENT_TABLE . " SET " . $attachment_set); |
|
1096 | + $attachment_set = trim($attachment_set, ", "); |
|
1097 | + |
|
1098 | + $wpdb->query("INSERT INTO " . GEODIR_ATTACHMENT_TABLE . " SET " . $attachment_set); |
|
1099 | 1099 | |
1100 | - $valid_file_ids[] = $wpdb->insert_id; |
|
1101 | - } |
|
1100 | + $valid_file_ids[] = $wpdb->insert_id; |
|
1101 | + } |
|
1102 | 1102 | |
1103 | - } |
|
1103 | + } |
|
1104 | 1104 | |
1105 | 1105 | |
1106 | - } else { |
|
1107 | - $valid_file_ids[] = $find_image; |
|
1106 | + } else { |
|
1107 | + $valid_file_ids[] = $find_image; |
|
1108 | 1108 | |
1109 | - $postcurr_images[] = str_replace(array('http://','https://'),'',$post_image[$m]); |
|
1109 | + $postcurr_images[] = str_replace(array('http://','https://'),'',$post_image[$m]); |
|
1110 | 1110 | |
1111 | - $wpdb->query( |
|
1112 | - $wpdb->prepare( |
|
1113 | - "UPDATE " . GEODIR_ATTACHMENT_TABLE . " SET menu_order = %d where file =%s AND post_id =%d", |
|
1114 | - array($menu_order, $split_img_path[1], $post_id) |
|
1115 | - ) |
|
1116 | - ); |
|
1111 | + $wpdb->query( |
|
1112 | + $wpdb->prepare( |
|
1113 | + "UPDATE " . GEODIR_ATTACHMENT_TABLE . " SET menu_order = %d where file =%s AND post_id =%d", |
|
1114 | + array($menu_order, $split_img_path[1], $post_id) |
|
1115 | + ) |
|
1116 | + ); |
|
1117 | 1117 | |
1118 | - if ($menu_order == 1) |
|
1119 | - $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET featured_image = %s where post_id =%d", array($split_img_path[1], $post_id))); |
|
1118 | + if ($menu_order == 1) |
|
1119 | + $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET featured_image = %s where post_id =%d", array($split_img_path[1], $post_id))); |
|
1120 | 1120 | |
1121 | - } |
|
1121 | + } |
|
1122 | 1122 | |
1123 | 1123 | |
1124 | - } |
|
1124 | + } |
|
1125 | 1125 | |
1126 | - if (!empty($valid_file_ids)) { |
|
1126 | + if (!empty($valid_file_ids)) { |
|
1127 | 1127 | |
1128 | - $remove_files = $valid_file_ids; |
|
1128 | + $remove_files = $valid_file_ids; |
|
1129 | 1129 | |
1130 | - $remove_files_length = count($remove_files); |
|
1131 | - $remove_files_format = array_fill(0, $remove_files_length, '%d'); |
|
1132 | - $format = implode(',', $remove_files_format); |
|
1133 | - $valid_files_condition = " ID NOT IN ($format) AND "; |
|
1130 | + $remove_files_length = count($remove_files); |
|
1131 | + $remove_files_format = array_fill(0, $remove_files_length, '%d'); |
|
1132 | + $format = implode(',', $remove_files_format); |
|
1133 | + $valid_files_condition = " ID NOT IN ($format) AND "; |
|
1134 | 1134 | |
1135 | - } |
|
1135 | + } |
|
1136 | 1136 | |
1137 | - //Get and remove all old images of post from database to set by new order |
|
1137 | + //Get and remove all old images of post from database to set by new order |
|
1138 | 1138 | |
1139 | - if (!empty($post_images)) { |
|
1139 | + if (!empty($post_images)) { |
|
1140 | 1140 | |
1141 | - foreach ($post_images as $img) { |
|
1141 | + foreach ($post_images as $img) { |
|
1142 | 1142 | |
1143 | - if (!in_array(str_replace(array('http://','https://'),'',$img->src), $postcurr_images)) { |
|
1143 | + if (!in_array(str_replace(array('http://','https://'),'',$img->src), $postcurr_images)) { |
|
1144 | 1144 | |
1145 | - $invalid_files[] = (object)array('src' => $img->src); |
|
1145 | + $invalid_files[] = (object)array('src' => $img->src); |
|
1146 | 1146 | |
1147 | - } |
|
1147 | + } |
|
1148 | 1148 | |
1149 | - } |
|
1149 | + } |
|
1150 | 1150 | |
1151 | - } |
|
1151 | + } |
|
1152 | 1152 | |
1153 | - $invalid_files = (object)$invalid_files; |
|
1154 | - } |
|
1153 | + $invalid_files = (object)$invalid_files; |
|
1154 | + } |
|
1155 | 1155 | |
1156 | - $remove_files[] = $post_id; |
|
1156 | + $remove_files[] = $post_id; |
|
1157 | 1157 | |
1158 | - $wpdb->query($wpdb->prepare("DELETE FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE " . $valid_files_condition . " post_id = %d", $remove_files)); |
|
1158 | + $wpdb->query($wpdb->prepare("DELETE FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE " . $valid_files_condition . " post_id = %d", $remove_files)); |
|
1159 | 1159 | |
1160 | - if (!empty($invalid_files)) |
|
1161 | - geodir_remove_attachments($invalid_files); |
|
1162 | - } |
|
1160 | + if (!empty($invalid_files)) |
|
1161 | + geodir_remove_attachments($invalid_files); |
|
1162 | + } |
|
1163 | 1163 | |
1164 | 1164 | } |
1165 | 1165 | |
@@ -1173,12 +1173,12 @@ discard block |
||
1173 | 1173 | function geodir_remove_temp_images() |
1174 | 1174 | { |
1175 | 1175 | |
1176 | - global $current_user; |
|
1176 | + global $current_user; |
|
1177 | 1177 | |
1178 | - $uploads = wp_upload_dir(); |
|
1179 | - $uploads_dir = $uploads['path']; |
|
1178 | + $uploads = wp_upload_dir(); |
|
1179 | + $uploads_dir = $uploads['path']; |
|
1180 | 1180 | |
1181 | - /* if(is_dir($uploads_dir.'/temp_'.$current_user->data->ID)){ |
|
1181 | + /* if(is_dir($uploads_dir.'/temp_'.$current_user->data->ID)){ |
|
1182 | 1182 | |
1183 | 1183 | $dirPath = $uploads_dir.'/temp_'.$current_user->data->ID; |
1184 | 1184 | if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { |
@@ -1195,8 +1195,8 @@ discard block |
||
1195 | 1195 | rmdir($dirPath); |
1196 | 1196 | } */ |
1197 | 1197 | |
1198 | - $dirname = $uploads_dir . '/temp_' . $current_user->ID; |
|
1199 | - geodir_delete_directory($dirname); |
|
1198 | + $dirname = $uploads_dir . '/temp_' . $current_user->ID; |
|
1199 | + geodir_delete_directory($dirname); |
|
1200 | 1200 | } |
1201 | 1201 | |
1202 | 1202 | |
@@ -1210,117 +1210,117 @@ discard block |
||
1210 | 1210 | */ |
1211 | 1211 | function geodir_delete_directory($dirname) |
1212 | 1212 | { |
1213 | - $dir_handle = ''; |
|
1214 | - if (is_dir($dirname)) |
|
1215 | - $dir_handle = opendir($dirname); |
|
1216 | - if (!$dir_handle) |
|
1217 | - return false; |
|
1218 | - while ($file = readdir($dir_handle)) { |
|
1219 | - if ($file != "." && $file != "..") { |
|
1220 | - if (!is_dir($dirname . "/" . $file)) |
|
1221 | - unlink($dirname . "/" . $file); |
|
1222 | - else |
|
1223 | - geodir_delete_directory($dirname . '/' . $file); |
|
1224 | - } |
|
1225 | - } |
|
1226 | - closedir($dir_handle); |
|
1227 | - rmdir($dirname); |
|
1228 | - return true; |
|
1213 | + $dir_handle = ''; |
|
1214 | + if (is_dir($dirname)) |
|
1215 | + $dir_handle = opendir($dirname); |
|
1216 | + if (!$dir_handle) |
|
1217 | + return false; |
|
1218 | + while ($file = readdir($dir_handle)) { |
|
1219 | + if ($file != "." && $file != "..") { |
|
1220 | + if (!is_dir($dirname . "/" . $file)) |
|
1221 | + unlink($dirname . "/" . $file); |
|
1222 | + else |
|
1223 | + geodir_delete_directory($dirname . '/' . $file); |
|
1224 | + } |
|
1225 | + } |
|
1226 | + closedir($dir_handle); |
|
1227 | + rmdir($dirname); |
|
1228 | + return true; |
|
1229 | 1229 | |
1230 | 1230 | } |
1231 | 1231 | |
1232 | 1232 | |
1233 | 1233 | if (!function_exists('geodir_remove_attachments')) { |
1234 | - /** |
|
1235 | - * Remove post attachments. |
|
1236 | - * |
|
1237 | - * @since 1.0.0 |
|
1238 | - * @package GeoDirectory |
|
1239 | - * @param array $postcurr_images Array of image objects. |
|
1240 | - */ |
|
1241 | - function geodir_remove_attachments($postcurr_images = array()) |
|
1242 | - { |
|
1243 | - // Unlink all past images of post |
|
1244 | - if (!empty($postcurr_images)) { |
|
1245 | - |
|
1246 | - $uploads = wp_upload_dir(); |
|
1247 | - $uploads_dir = $uploads['path']; |
|
1248 | - |
|
1249 | - foreach ($postcurr_images as $postimg) { |
|
1250 | - $image_name_arr = explode('/', $postimg->src); |
|
1251 | - $filename = end($image_name_arr); |
|
1252 | - if (file_exists($uploads_dir . '/' . $filename)) |
|
1253 | - unlink($uploads_dir . '/' . $filename); |
|
1254 | - } |
|
1255 | - |
|
1256 | - } // endif |
|
1257 | - // Unlink all past images of post end |
|
1258 | - } |
|
1234 | + /** |
|
1235 | + * Remove post attachments. |
|
1236 | + * |
|
1237 | + * @since 1.0.0 |
|
1238 | + * @package GeoDirectory |
|
1239 | + * @param array $postcurr_images Array of image objects. |
|
1240 | + */ |
|
1241 | + function geodir_remove_attachments($postcurr_images = array()) |
|
1242 | + { |
|
1243 | + // Unlink all past images of post |
|
1244 | + if (!empty($postcurr_images)) { |
|
1245 | + |
|
1246 | + $uploads = wp_upload_dir(); |
|
1247 | + $uploads_dir = $uploads['path']; |
|
1248 | + |
|
1249 | + foreach ($postcurr_images as $postimg) { |
|
1250 | + $image_name_arr = explode('/', $postimg->src); |
|
1251 | + $filename = end($image_name_arr); |
|
1252 | + if (file_exists($uploads_dir . '/' . $filename)) |
|
1253 | + unlink($uploads_dir . '/' . $filename); |
|
1254 | + } |
|
1255 | + |
|
1256 | + } // endif |
|
1257 | + // Unlink all past images of post end |
|
1258 | + } |
|
1259 | 1259 | } |
1260 | 1260 | |
1261 | 1261 | if (!function_exists('geodir_get_featured_image')) { |
1262 | - /** |
|
1263 | - * Gets the post featured image. |
|
1264 | - * |
|
1265 | - * @since 1.0.0 |
|
1266 | - * @package GeoDirectory |
|
1267 | - * @global object $wpdb WordPress Database object. |
|
1268 | - * @global object $post The current post object. |
|
1269 | - * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
1270 | - * @param int|string $post_id The post ID. |
|
1271 | - * @param string $size Optional. Thumbnail size. Default: thumbnail. |
|
1272 | - * @param bool $no_image Optional. Do you want to return the default image when no image is available? Default: false. |
|
1273 | - * @param bool|string $file Optional. The file path from which you want to get the image details. Default: false. |
|
1274 | - * @return bool|object Image details as an object. |
|
1275 | - */ |
|
1276 | - function geodir_get_featured_image($post_id = '', $size = '', $no_image = false, $file = false) |
|
1277 | - { |
|
1278 | - |
|
1279 | - /*$img_arr['src'] = get_the_post_thumbnail_url( $post_id, 'medium');//medium/thumbnail |
|
1262 | + /** |
|
1263 | + * Gets the post featured image. |
|
1264 | + * |
|
1265 | + * @since 1.0.0 |
|
1266 | + * @package GeoDirectory |
|
1267 | + * @global object $wpdb WordPress Database object. |
|
1268 | + * @global object $post The current post object. |
|
1269 | + * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
1270 | + * @param int|string $post_id The post ID. |
|
1271 | + * @param string $size Optional. Thumbnail size. Default: thumbnail. |
|
1272 | + * @param bool $no_image Optional. Do you want to return the default image when no image is available? Default: false. |
|
1273 | + * @param bool|string $file Optional. The file path from which you want to get the image details. Default: false. |
|
1274 | + * @return bool|object Image details as an object. |
|
1275 | + */ |
|
1276 | + function geodir_get_featured_image($post_id = '', $size = '', $no_image = false, $file = false) |
|
1277 | + { |
|
1278 | + |
|
1279 | + /*$img_arr['src'] = get_the_post_thumbnail_url( $post_id, 'medium');//medium/thumbnail |
|
1280 | 1280 | $img_arr['path'] = ''; |
1281 | 1281 | $img_arr['width'] = ''; |
1282 | 1282 | $img_arr['height'] = ''; |
1283 | 1283 | $img_arr['title'] = ''; |
1284 | 1284 | return (object)$img_arr;*/ |
1285 | - global $wpdb, $plugin_prefix, $post; |
|
1285 | + global $wpdb, $plugin_prefix, $post; |
|
1286 | 1286 | |
1287 | - if (isset($post->ID) && isset($post->post_type) && $post->ID == $post_id) { |
|
1288 | - $post_type = $post->post_type; |
|
1289 | - } else { |
|
1290 | - $post_type = get_post_type($post_id); |
|
1291 | - } |
|
1287 | + if (isset($post->ID) && isset($post->post_type) && $post->ID == $post_id) { |
|
1288 | + $post_type = $post->post_type; |
|
1289 | + } else { |
|
1290 | + $post_type = get_post_type($post_id); |
|
1291 | + } |
|
1292 | 1292 | |
1293 | - if (!in_array($post_type, geodir_get_posttypes())) { |
|
1294 | - return false;// if not a GD CPT return; |
|
1295 | - } |
|
1293 | + if (!in_array($post_type, geodir_get_posttypes())) { |
|
1294 | + return false;// if not a GD CPT return; |
|
1295 | + } |
|
1296 | 1296 | |
1297 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
1297 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
1298 | 1298 | |
1299 | - if (!$file) { |
|
1300 | - if (isset($post->featured_image)) { |
|
1301 | - $file = $post->featured_image; |
|
1302 | - } else { |
|
1303 | - $file = $wpdb->get_var($wpdb->prepare("SELECT featured_image FROM " . $table . " WHERE post_id = %d", array($post_id))); |
|
1304 | - } |
|
1305 | - } |
|
1299 | + if (!$file) { |
|
1300 | + if (isset($post->featured_image)) { |
|
1301 | + $file = $post->featured_image; |
|
1302 | + } else { |
|
1303 | + $file = $wpdb->get_var($wpdb->prepare("SELECT featured_image FROM " . $table . " WHERE post_id = %d", array($post_id))); |
|
1304 | + } |
|
1305 | + } |
|
1306 | 1306 | |
1307 | - if ($file != NULL && $file != '' && (($uploads = wp_upload_dir()) && false === $uploads['error'])) { |
|
1308 | - $img_arr = array(); |
|
1307 | + if ($file != NULL && $file != '' && (($uploads = wp_upload_dir()) && false === $uploads['error'])) { |
|
1308 | + $img_arr = array(); |
|
1309 | 1309 | |
1310 | - $file_info = pathinfo($file); |
|
1311 | - $sub_dir = ''; |
|
1312 | - if ($file_info['dirname'] != '.' && $file_info['dirname'] != '..') { |
|
1313 | - $sub_dir = stripslashes_deep($file_info['dirname']); |
|
1314 | - } |
|
1310 | + $file_info = pathinfo($file); |
|
1311 | + $sub_dir = ''; |
|
1312 | + if ($file_info['dirname'] != '.' && $file_info['dirname'] != '..') { |
|
1313 | + $sub_dir = stripslashes_deep($file_info['dirname']); |
|
1314 | + } |
|
1315 | 1315 | |
1316 | - $uploads = wp_upload_dir(trim($sub_dir, '/')); // Array of key => value pairs |
|
1317 | - $uploads_baseurl = $uploads['baseurl']; |
|
1318 | - $uploads_path = $uploads['path']; |
|
1316 | + $uploads = wp_upload_dir(trim($sub_dir, '/')); // Array of key => value pairs |
|
1317 | + $uploads_baseurl = $uploads['baseurl']; |
|
1318 | + $uploads_path = $uploads['path']; |
|
1319 | 1319 | |
1320 | - $file_name = $file_info['basename']; |
|
1320 | + $file_name = $file_info['basename']; |
|
1321 | 1321 | |
1322 | - $uploads_url = $uploads_baseurl . $sub_dir; |
|
1323 | - /* |
|
1322 | + $uploads_url = $uploads_baseurl . $sub_dir; |
|
1323 | + /* |
|
1324 | 1324 | * Allows the filter of image src for such things as CDN change. |
1325 | 1325 | * |
1326 | 1326 | * @since 1.5.7 |
@@ -1329,158 +1329,158 @@ discard block |
||
1329 | 1329 | * @param string $uploads_url The server upload directory url. |
1330 | 1330 | * @param string $uploads_baseurl The uploads dir base url. |
1331 | 1331 | */ |
1332 | - $img_arr['src'] = apply_filters('geodir_get_featured_image_src',$uploads_url . '/' . $file_name,$file_name,$uploads_url,$uploads_baseurl); |
|
1333 | - $img_arr['path'] = $uploads_path . '/' . $file_name; |
|
1334 | - $width = 0; |
|
1335 | - $height = 0; |
|
1336 | - if (is_file($img_arr['path']) && file_exists($img_arr['path'])) { |
|
1337 | - $imagesize = getimagesize($img_arr['path']); |
|
1338 | - $width = !empty($imagesize) && isset($imagesize[0]) ? $imagesize[0] : ''; |
|
1339 | - $height = !empty($imagesize) && isset($imagesize[1]) ? $imagesize[1] : ''; |
|
1340 | - } |
|
1341 | - $img_arr['width'] = $width; |
|
1342 | - $img_arr['height'] = $height; |
|
1343 | - $img_arr['title'] = ''; |
|
1344 | - } elseif ($post_images = geodir_get_images($post_id, $size, $no_image, 1)) { |
|
1345 | - foreach ($post_images as $image) { |
|
1346 | - return $image; |
|
1347 | - } |
|
1348 | - } else if ($no_image) { |
|
1349 | - $img_arr = array(); |
|
1350 | - |
|
1351 | - $default_img = ''; |
|
1352 | - if (isset($post->default_category) && $post->default_category) { |
|
1353 | - $default_cat = $post->default_category; |
|
1354 | - } else { |
|
1355 | - $default_cat = geodir_get_post_meta($post_id, 'default_category', true); |
|
1356 | - } |
|
1357 | - |
|
1358 | - if ($default_catimg = geodir_get_default_catimage($default_cat, $post_type)) |
|
1359 | - $default_img = $default_catimg['src']; |
|
1360 | - elseif ($no_image) { |
|
1361 | - $default_img = get_option('geodir_listing_no_img'); |
|
1362 | - } |
|
1363 | - |
|
1364 | - if (!empty($default_img)) { |
|
1365 | - $uploads = wp_upload_dir(); // Array of key => value pairs |
|
1366 | - $uploads_baseurl = $uploads['baseurl']; |
|
1367 | - $uploads_path = $uploads['path']; |
|
1368 | - |
|
1369 | - $img_arr = array(); |
|
1370 | - |
|
1371 | - $file_info = pathinfo($default_img); |
|
1372 | - |
|
1373 | - $file_name = $file_info['basename']; |
|
1374 | - |
|
1375 | - $img_arr['src'] = $default_img; |
|
1376 | - $img_arr['path'] = $uploads_path . '/' . $file_name; |
|
1377 | - |
|
1378 | - $width = 0; |
|
1379 | - $height = 0; |
|
1380 | - if (is_file($img_arr['path']) && file_exists($img_arr['path'])) { |
|
1381 | - $imagesize = getimagesize($img_arr['path']); |
|
1382 | - $width = !empty($imagesize) && isset($imagesize[0]) ? $imagesize[0] : ''; |
|
1383 | - $height = !empty($imagesize) && isset($imagesize[1]) ? $imagesize[1] : ''; |
|
1384 | - } |
|
1385 | - $img_arr['width'] = $width; |
|
1386 | - $img_arr['height'] = $height; |
|
1387 | - |
|
1388 | - $img_arr['title'] = ''; // add the title to the array |
|
1389 | - } |
|
1390 | - } |
|
1391 | - |
|
1392 | - if (!empty($img_arr)) |
|
1393 | - return (object)$img_arr;//return (object)array( 'src' => $file_url, 'path' => $file_path ); |
|
1394 | - else |
|
1395 | - return false; |
|
1396 | - } |
|
1332 | + $img_arr['src'] = apply_filters('geodir_get_featured_image_src',$uploads_url . '/' . $file_name,$file_name,$uploads_url,$uploads_baseurl); |
|
1333 | + $img_arr['path'] = $uploads_path . '/' . $file_name; |
|
1334 | + $width = 0; |
|
1335 | + $height = 0; |
|
1336 | + if (is_file($img_arr['path']) && file_exists($img_arr['path'])) { |
|
1337 | + $imagesize = getimagesize($img_arr['path']); |
|
1338 | + $width = !empty($imagesize) && isset($imagesize[0]) ? $imagesize[0] : ''; |
|
1339 | + $height = !empty($imagesize) && isset($imagesize[1]) ? $imagesize[1] : ''; |
|
1340 | + } |
|
1341 | + $img_arr['width'] = $width; |
|
1342 | + $img_arr['height'] = $height; |
|
1343 | + $img_arr['title'] = ''; |
|
1344 | + } elseif ($post_images = geodir_get_images($post_id, $size, $no_image, 1)) { |
|
1345 | + foreach ($post_images as $image) { |
|
1346 | + return $image; |
|
1347 | + } |
|
1348 | + } else if ($no_image) { |
|
1349 | + $img_arr = array(); |
|
1350 | + |
|
1351 | + $default_img = ''; |
|
1352 | + if (isset($post->default_category) && $post->default_category) { |
|
1353 | + $default_cat = $post->default_category; |
|
1354 | + } else { |
|
1355 | + $default_cat = geodir_get_post_meta($post_id, 'default_category', true); |
|
1356 | + } |
|
1357 | + |
|
1358 | + if ($default_catimg = geodir_get_default_catimage($default_cat, $post_type)) |
|
1359 | + $default_img = $default_catimg['src']; |
|
1360 | + elseif ($no_image) { |
|
1361 | + $default_img = get_option('geodir_listing_no_img'); |
|
1362 | + } |
|
1363 | + |
|
1364 | + if (!empty($default_img)) { |
|
1365 | + $uploads = wp_upload_dir(); // Array of key => value pairs |
|
1366 | + $uploads_baseurl = $uploads['baseurl']; |
|
1367 | + $uploads_path = $uploads['path']; |
|
1368 | + |
|
1369 | + $img_arr = array(); |
|
1370 | + |
|
1371 | + $file_info = pathinfo($default_img); |
|
1372 | + |
|
1373 | + $file_name = $file_info['basename']; |
|
1374 | + |
|
1375 | + $img_arr['src'] = $default_img; |
|
1376 | + $img_arr['path'] = $uploads_path . '/' . $file_name; |
|
1377 | + |
|
1378 | + $width = 0; |
|
1379 | + $height = 0; |
|
1380 | + if (is_file($img_arr['path']) && file_exists($img_arr['path'])) { |
|
1381 | + $imagesize = getimagesize($img_arr['path']); |
|
1382 | + $width = !empty($imagesize) && isset($imagesize[0]) ? $imagesize[0] : ''; |
|
1383 | + $height = !empty($imagesize) && isset($imagesize[1]) ? $imagesize[1] : ''; |
|
1384 | + } |
|
1385 | + $img_arr['width'] = $width; |
|
1386 | + $img_arr['height'] = $height; |
|
1387 | + |
|
1388 | + $img_arr['title'] = ''; // add the title to the array |
|
1389 | + } |
|
1390 | + } |
|
1391 | + |
|
1392 | + if (!empty($img_arr)) |
|
1393 | + return (object)$img_arr;//return (object)array( 'src' => $file_url, 'path' => $file_path ); |
|
1394 | + else |
|
1395 | + return false; |
|
1396 | + } |
|
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | if (!function_exists('geodir_show_featured_image')) { |
1400 | - /** |
|
1401 | - * Gets the post featured image. |
|
1402 | - * |
|
1403 | - * @since 1.0.0 |
|
1404 | - * @package GeoDirectory |
|
1405 | - * @param int|string $post_id The post ID. |
|
1406 | - * @param string $size Optional. Thumbnail size. Default: thumbnail. |
|
1407 | - * @param bool $no_image Optional. Do you want to return the default image when no image is available? Default: false. |
|
1408 | - * @param bool $echo Optional. Do you want to print it instead of returning it? Default: true. |
|
1409 | - * @param bool|string $fimage Optional. The file path from which you want to get the image details. Default: false. |
|
1410 | - * @return bool|string Returns image html. |
|
1411 | - */ |
|
1412 | - function geodir_show_featured_image($post_id = '', $size = 'thumbnail', $no_image = false, $echo = true, $fimage = false) |
|
1413 | - { |
|
1414 | - $image = geodir_get_featured_image($post_id, $size, $no_image, $fimage); |
|
1415 | - |
|
1416 | - $html = geodir_show_image($image, $size, $no_image, false); |
|
1417 | - |
|
1418 | - if (!empty($html) && $echo) { |
|
1419 | - echo $html; |
|
1420 | - } elseif (!empty($html)) { |
|
1421 | - return $html; |
|
1422 | - } else |
|
1423 | - return false; |
|
1424 | - } |
|
1400 | + /** |
|
1401 | + * Gets the post featured image. |
|
1402 | + * |
|
1403 | + * @since 1.0.0 |
|
1404 | + * @package GeoDirectory |
|
1405 | + * @param int|string $post_id The post ID. |
|
1406 | + * @param string $size Optional. Thumbnail size. Default: thumbnail. |
|
1407 | + * @param bool $no_image Optional. Do you want to return the default image when no image is available? Default: false. |
|
1408 | + * @param bool $echo Optional. Do you want to print it instead of returning it? Default: true. |
|
1409 | + * @param bool|string $fimage Optional. The file path from which you want to get the image details. Default: false. |
|
1410 | + * @return bool|string Returns image html. |
|
1411 | + */ |
|
1412 | + function geodir_show_featured_image($post_id = '', $size = 'thumbnail', $no_image = false, $echo = true, $fimage = false) |
|
1413 | + { |
|
1414 | + $image = geodir_get_featured_image($post_id, $size, $no_image, $fimage); |
|
1415 | + |
|
1416 | + $html = geodir_show_image($image, $size, $no_image, false); |
|
1417 | + |
|
1418 | + if (!empty($html) && $echo) { |
|
1419 | + echo $html; |
|
1420 | + } elseif (!empty($html)) { |
|
1421 | + return $html; |
|
1422 | + } else |
|
1423 | + return false; |
|
1424 | + } |
|
1425 | 1425 | } |
1426 | 1426 | |
1427 | 1427 | if (!function_exists('geodir_get_images')) { |
1428 | - /** |
|
1429 | - * Gets the post images. |
|
1430 | - * |
|
1431 | - * @since 1.0.0 |
|
1432 | - * @package GeoDirectory |
|
1433 | - * @global object $wpdb WordPress Database object. |
|
1434 | - * @param int $post_id The post ID. |
|
1435 | - * @param string $img_size Optional. Thumbnail size. |
|
1436 | - * @param bool $no_images Optional. Do you want to return the default image when no image is available? Default: false. |
|
1437 | - * @param bool $add_featured Optional. Do you want to include featured images too? Default: true. |
|
1438 | - * @param int|string $limit Optional. Number of images. |
|
1439 | - * @return array|bool Returns images as an array. Each item is an object. |
|
1440 | - */ |
|
1441 | - function geodir_get_images($post_id = 0, $img_size = '', $no_images = false, $add_featured = true, $limit = '') |
|
1442 | - { |
|
1443 | - global $wpdb; |
|
1444 | - if ($limit) { |
|
1445 | - $limit_q = " LIMIT $limit "; |
|
1446 | - } else { |
|
1447 | - $limit_q = ''; |
|
1448 | - } |
|
1449 | - $not_featured = ''; |
|
1450 | - $sub_dir = ''; |
|
1451 | - if (!$add_featured) |
|
1452 | - $not_featured = " AND is_featured = 0 "; |
|
1453 | - |
|
1454 | - $arrImages = $wpdb->get_results( |
|
1455 | - $wpdb->prepare( |
|
1456 | - "SELECT * FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE mime_type like %s AND post_id = %d" . $not_featured . " ORDER BY menu_order ASC, ID DESC $limit_q ", |
|
1457 | - array('%image%', $post_id) |
|
1458 | - ) |
|
1459 | - ); |
|
1460 | - |
|
1461 | - $counter = 0; |
|
1462 | - $return_arr = array(); |
|
1463 | - |
|
1464 | - if (!empty($arrImages)) { |
|
1465 | - foreach ($arrImages as $attechment) { |
|
1466 | - |
|
1467 | - $img_arr = array(); |
|
1468 | - $img_arr['id'] = $attechment->ID; |
|
1469 | - $img_arr['user_id'] = isset($attechment->user_id) ? $attechment->user_id : 0; |
|
1470 | - |
|
1471 | - $file_info = pathinfo($attechment->file); |
|
1472 | - |
|
1473 | - if ($file_info['dirname'] != '.' && $file_info['dirname'] != '..') |
|
1474 | - $sub_dir = stripslashes_deep($file_info['dirname']); |
|
1475 | - |
|
1476 | - $uploads = wp_upload_dir(trim($sub_dir, '/')); // Array of key => value pairs |
|
1477 | - $uploads_baseurl = $uploads['baseurl']; |
|
1478 | - $uploads_path = $uploads['path']; |
|
1479 | - |
|
1480 | - $file_name = $file_info['basename']; |
|
1481 | - |
|
1482 | - $uploads_url = $uploads_baseurl . $sub_dir; |
|
1483 | - /* |
|
1428 | + /** |
|
1429 | + * Gets the post images. |
|
1430 | + * |
|
1431 | + * @since 1.0.0 |
|
1432 | + * @package GeoDirectory |
|
1433 | + * @global object $wpdb WordPress Database object. |
|
1434 | + * @param int $post_id The post ID. |
|
1435 | + * @param string $img_size Optional. Thumbnail size. |
|
1436 | + * @param bool $no_images Optional. Do you want to return the default image when no image is available? Default: false. |
|
1437 | + * @param bool $add_featured Optional. Do you want to include featured images too? Default: true. |
|
1438 | + * @param int|string $limit Optional. Number of images. |
|
1439 | + * @return array|bool Returns images as an array. Each item is an object. |
|
1440 | + */ |
|
1441 | + function geodir_get_images($post_id = 0, $img_size = '', $no_images = false, $add_featured = true, $limit = '') |
|
1442 | + { |
|
1443 | + global $wpdb; |
|
1444 | + if ($limit) { |
|
1445 | + $limit_q = " LIMIT $limit "; |
|
1446 | + } else { |
|
1447 | + $limit_q = ''; |
|
1448 | + } |
|
1449 | + $not_featured = ''; |
|
1450 | + $sub_dir = ''; |
|
1451 | + if (!$add_featured) |
|
1452 | + $not_featured = " AND is_featured = 0 "; |
|
1453 | + |
|
1454 | + $arrImages = $wpdb->get_results( |
|
1455 | + $wpdb->prepare( |
|
1456 | + "SELECT * FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE mime_type like %s AND post_id = %d" . $not_featured . " ORDER BY menu_order ASC, ID DESC $limit_q ", |
|
1457 | + array('%image%', $post_id) |
|
1458 | + ) |
|
1459 | + ); |
|
1460 | + |
|
1461 | + $counter = 0; |
|
1462 | + $return_arr = array(); |
|
1463 | + |
|
1464 | + if (!empty($arrImages)) { |
|
1465 | + foreach ($arrImages as $attechment) { |
|
1466 | + |
|
1467 | + $img_arr = array(); |
|
1468 | + $img_arr['id'] = $attechment->ID; |
|
1469 | + $img_arr['user_id'] = isset($attechment->user_id) ? $attechment->user_id : 0; |
|
1470 | + |
|
1471 | + $file_info = pathinfo($attechment->file); |
|
1472 | + |
|
1473 | + if ($file_info['dirname'] != '.' && $file_info['dirname'] != '..') |
|
1474 | + $sub_dir = stripslashes_deep($file_info['dirname']); |
|
1475 | + |
|
1476 | + $uploads = wp_upload_dir(trim($sub_dir, '/')); // Array of key => value pairs |
|
1477 | + $uploads_baseurl = $uploads['baseurl']; |
|
1478 | + $uploads_path = $uploads['path']; |
|
1479 | + |
|
1480 | + $file_name = $file_info['basename']; |
|
1481 | + |
|
1482 | + $uploads_url = $uploads_baseurl . $sub_dir; |
|
1483 | + /* |
|
1484 | 1484 | * Allows the filter of image src for such things as CDN change. |
1485 | 1485 | * |
1486 | 1486 | * @since 1.5.7 |
@@ -1489,514 +1489,514 @@ discard block |
||
1489 | 1489 | * @param string $uploads_url The server upload directory url. |
1490 | 1490 | * @param string $uploads_baseurl The uploads dir base url. |
1491 | 1491 | */ |
1492 | - $img_arr['src'] = apply_filters('geodir_get_images_src',$uploads_url . '/' . $file_name,$file_name,$uploads_url,$uploads_baseurl); |
|
1493 | - $img_arr['path'] = $uploads_path . '/' . $file_name; |
|
1494 | - $width = 0; |
|
1495 | - $height = 0; |
|
1496 | - if (is_file($img_arr['path']) && file_exists($img_arr['path'])) { |
|
1497 | - $imagesize = getimagesize($img_arr['path']); |
|
1498 | - $width = !empty($imagesize) && isset($imagesize[0]) ? $imagesize[0] : ''; |
|
1499 | - $height = !empty($imagesize) && isset($imagesize[1]) ? $imagesize[1] : ''; |
|
1500 | - } |
|
1501 | - $img_arr['width'] = $width; |
|
1502 | - $img_arr['height'] = $height; |
|
1503 | - |
|
1504 | - $img_arr['file'] = $file_name; // add the title to the array |
|
1505 | - $img_arr['title'] = $attechment->title; // add the title to the array |
|
1506 | - $img_arr['caption'] = isset($attechment->caption) ? $attechment->caption : ''; // add the caption to the array |
|
1507 | - $img_arr['content'] = $attechment->content; // add the description to the array |
|
1508 | - $img_arr['is_approved'] = isset($attechment->is_approved) ? $attechment->is_approved : ''; // used for user image moderation. For backward compatibility Default value is 1. |
|
1509 | - |
|
1510 | - $return_arr[] = (object)$img_arr; |
|
1511 | - |
|
1512 | - $counter++; |
|
1513 | - } |
|
1514 | - return (object)$return_arr; |
|
1515 | - } else if ($no_images) { |
|
1516 | - $default_img = ''; |
|
1517 | - $default_cat = geodir_get_post_meta($post_id, 'default_category', true); |
|
1518 | - $post_type = get_post_type($post_id); |
|
1519 | - if ($default_catimg = geodir_get_default_catimage($default_cat, $post_type)) |
|
1520 | - $default_img = $default_catimg['src']; |
|
1521 | - elseif ($no_images) { |
|
1522 | - $default_img = get_option('geodir_listing_no_img'); |
|
1523 | - } |
|
1524 | - |
|
1525 | - if (!empty($default_img)) { |
|
1526 | - $uploads = wp_upload_dir(); // Array of key => value pairs |
|
1492 | + $img_arr['src'] = apply_filters('geodir_get_images_src',$uploads_url . '/' . $file_name,$file_name,$uploads_url,$uploads_baseurl); |
|
1493 | + $img_arr['path'] = $uploads_path . '/' . $file_name; |
|
1494 | + $width = 0; |
|
1495 | + $height = 0; |
|
1496 | + if (is_file($img_arr['path']) && file_exists($img_arr['path'])) { |
|
1497 | + $imagesize = getimagesize($img_arr['path']); |
|
1498 | + $width = !empty($imagesize) && isset($imagesize[0]) ? $imagesize[0] : ''; |
|
1499 | + $height = !empty($imagesize) && isset($imagesize[1]) ? $imagesize[1] : ''; |
|
1500 | + } |
|
1501 | + $img_arr['width'] = $width; |
|
1502 | + $img_arr['height'] = $height; |
|
1503 | + |
|
1504 | + $img_arr['file'] = $file_name; // add the title to the array |
|
1505 | + $img_arr['title'] = $attechment->title; // add the title to the array |
|
1506 | + $img_arr['caption'] = isset($attechment->caption) ? $attechment->caption : ''; // add the caption to the array |
|
1507 | + $img_arr['content'] = $attechment->content; // add the description to the array |
|
1508 | + $img_arr['is_approved'] = isset($attechment->is_approved) ? $attechment->is_approved : ''; // used for user image moderation. For backward compatibility Default value is 1. |
|
1509 | + |
|
1510 | + $return_arr[] = (object)$img_arr; |
|
1511 | + |
|
1512 | + $counter++; |
|
1513 | + } |
|
1514 | + return (object)$return_arr; |
|
1515 | + } else if ($no_images) { |
|
1516 | + $default_img = ''; |
|
1517 | + $default_cat = geodir_get_post_meta($post_id, 'default_category', true); |
|
1518 | + $post_type = get_post_type($post_id); |
|
1519 | + if ($default_catimg = geodir_get_default_catimage($default_cat, $post_type)) |
|
1520 | + $default_img = $default_catimg['src']; |
|
1521 | + elseif ($no_images) { |
|
1522 | + $default_img = get_option('geodir_listing_no_img'); |
|
1523 | + } |
|
1524 | + |
|
1525 | + if (!empty($default_img)) { |
|
1526 | + $uploads = wp_upload_dir(); // Array of key => value pairs |
|
1527 | 1527 | |
1528 | - $image_path = $default_img; |
|
1529 | - if (!path_is_absolute($image_path)) { |
|
1530 | - $image_path = str_replace($uploads['baseurl'], $uploads['basedir'], $image_path); |
|
1531 | - } |
|
1532 | - |
|
1533 | - $file_info = pathinfo($default_img); |
|
1534 | - $file_name = $file_info['basename']; |
|
1535 | - |
|
1536 | - $width = ''; |
|
1537 | - $height = ''; |
|
1538 | - if (is_file($image_path) && file_exists($image_path)) { |
|
1539 | - $imagesize = getimagesize($image_path); |
|
1540 | - $width = !empty($imagesize) && isset($imagesize[0]) ? $imagesize[0] : ''; |
|
1541 | - $height = !empty($imagesize) && isset($imagesize[1]) ? $imagesize[1] : ''; |
|
1542 | - } |
|
1528 | + $image_path = $default_img; |
|
1529 | + if (!path_is_absolute($image_path)) { |
|
1530 | + $image_path = str_replace($uploads['baseurl'], $uploads['basedir'], $image_path); |
|
1531 | + } |
|
1532 | + |
|
1533 | + $file_info = pathinfo($default_img); |
|
1534 | + $file_name = $file_info['basename']; |
|
1535 | + |
|
1536 | + $width = ''; |
|
1537 | + $height = ''; |
|
1538 | + if (is_file($image_path) && file_exists($image_path)) { |
|
1539 | + $imagesize = getimagesize($image_path); |
|
1540 | + $width = !empty($imagesize) && isset($imagesize[0]) ? $imagesize[0] : ''; |
|
1541 | + $height = !empty($imagesize) && isset($imagesize[1]) ? $imagesize[1] : ''; |
|
1542 | + } |
|
1543 | 1543 | |
1544 | - $img_arr = array(); |
|
1545 | - $img_arr['src'] = $default_img; |
|
1546 | - $img_arr['path'] = $image_path; |
|
1547 | - $img_arr['width'] = $width; |
|
1548 | - $img_arr['height'] = $height; |
|
1549 | - $img_arr['file'] = $file_name; // add the title to the array |
|
1550 | - $img_arr['title'] = $file_info['filename']; // add the title to the array |
|
1551 | - $img_arr['content'] = $file_info['filename']; // add the description to the array |
|
1552 | - |
|
1553 | - $return_arr[] = (object)$img_arr; |
|
1554 | - |
|
1555 | - return $return_arr; |
|
1556 | - } else |
|
1557 | - return false; |
|
1558 | - } |
|
1559 | - } |
|
1544 | + $img_arr = array(); |
|
1545 | + $img_arr['src'] = $default_img; |
|
1546 | + $img_arr['path'] = $image_path; |
|
1547 | + $img_arr['width'] = $width; |
|
1548 | + $img_arr['height'] = $height; |
|
1549 | + $img_arr['file'] = $file_name; // add the title to the array |
|
1550 | + $img_arr['title'] = $file_info['filename']; // add the title to the array |
|
1551 | + $img_arr['content'] = $file_info['filename']; // add the description to the array |
|
1552 | + |
|
1553 | + $return_arr[] = (object)$img_arr; |
|
1554 | + |
|
1555 | + return $return_arr; |
|
1556 | + } else |
|
1557 | + return false; |
|
1558 | + } |
|
1559 | + } |
|
1560 | 1560 | } |
1561 | 1561 | |
1562 | 1562 | if (!function_exists('geodir_show_image')) { |
1563 | - /** |
|
1564 | - * Show image using image details. |
|
1565 | - * |
|
1566 | - * @since 1.0.0 |
|
1567 | - * @package GeoDirectory |
|
1568 | - * @param array|object $request Image info either as an array or object. |
|
1569 | - * @param string $size Optional. Thumbnail size. Default: thumbnail. |
|
1570 | - * @param bool $no_image Optional. Do you want to return the default image when no image is available? Default: false. |
|
1571 | - * @param bool $echo Optional. Do you want to print it instead of returning it? Default: true. |
|
1572 | - * @return bool|string Returns image html. |
|
1573 | - */ |
|
1574 | - function geodir_show_image($request = array(), $size = 'thumbnail', $no_image = false, $echo = true) |
|
1575 | - { |
|
1576 | - $image = new stdClass(); |
|
1577 | - |
|
1578 | - $html = ''; |
|
1579 | - if (!empty($request)) { |
|
1580 | - if (!is_object($request)){ |
|
1581 | - $request = (object)$request; |
|
1582 | - } |
|
1583 | - |
|
1584 | - if (isset($request->src) && !isset($request->path)) { |
|
1585 | - $request->path = $request->src; |
|
1586 | - } |
|
1587 | - |
|
1588 | - /* |
|
1563 | + /** |
|
1564 | + * Show image using image details. |
|
1565 | + * |
|
1566 | + * @since 1.0.0 |
|
1567 | + * @package GeoDirectory |
|
1568 | + * @param array|object $request Image info either as an array or object. |
|
1569 | + * @param string $size Optional. Thumbnail size. Default: thumbnail. |
|
1570 | + * @param bool $no_image Optional. Do you want to return the default image when no image is available? Default: false. |
|
1571 | + * @param bool $echo Optional. Do you want to print it instead of returning it? Default: true. |
|
1572 | + * @return bool|string Returns image html. |
|
1573 | + */ |
|
1574 | + function geodir_show_image($request = array(), $size = 'thumbnail', $no_image = false, $echo = true) |
|
1575 | + { |
|
1576 | + $image = new stdClass(); |
|
1577 | + |
|
1578 | + $html = ''; |
|
1579 | + if (!empty($request)) { |
|
1580 | + if (!is_object($request)){ |
|
1581 | + $request = (object)$request; |
|
1582 | + } |
|
1583 | + |
|
1584 | + if (isset($request->src) && !isset($request->path)) { |
|
1585 | + $request->path = $request->src; |
|
1586 | + } |
|
1587 | + |
|
1588 | + /* |
|
1589 | 1589 | * getimagesize() works faster from path than url so we try and get path if we can. |
1590 | 1590 | */ |
1591 | - $upload_dir = wp_upload_dir(); |
|
1592 | - $img_no_http = str_replace(array("http://", "https://"), "", $request->path); |
|
1593 | - $upload_no_http = str_replace(array("http://", "https://"), "", $upload_dir['baseurl']); |
|
1594 | - if (strpos($img_no_http, $upload_no_http) !== false) { |
|
1595 | - $request->path = str_replace( $img_no_http,$upload_dir['basedir'], $request->path); |
|
1596 | - } |
|
1591 | + $upload_dir = wp_upload_dir(); |
|
1592 | + $img_no_http = str_replace(array("http://", "https://"), "", $request->path); |
|
1593 | + $upload_no_http = str_replace(array("http://", "https://"), "", $upload_dir['baseurl']); |
|
1594 | + if (strpos($img_no_http, $upload_no_http) !== false) { |
|
1595 | + $request->path = str_replace( $img_no_http,$upload_dir['basedir'], $request->path); |
|
1596 | + } |
|
1597 | 1597 | |
1598 | - $width = 0; |
|
1599 | - $height = 0; |
|
1600 | - if (is_file($request->path) && file_exists($request->path)) { |
|
1601 | - $imagesize = getimagesize($request->path); |
|
1602 | - $width = !empty($imagesize) && isset($imagesize[0]) ? $imagesize[0] : ''; |
|
1603 | - $height = !empty($imagesize) && isset($imagesize[1]) ? $imagesize[1] : ''; |
|
1604 | - } |
|
1605 | - |
|
1606 | - $image->src = $request->src; |
|
1607 | - $image->width = $width; |
|
1608 | - $image->height = $height; |
|
1609 | - |
|
1610 | - $max_size = (object)geodir_get_imagesize($size); |
|
1611 | - |
|
1612 | - if (!is_wp_error($max_size)) { |
|
1613 | - if ($image->width) { |
|
1614 | - if ($image->height >= $image->width) { |
|
1615 | - $width_per = round(((($image->width * ($max_size->h / $image->height)) / $max_size->w) * 100), 2); |
|
1616 | - } else if ($image->width < ($max_size->h)) { |
|
1617 | - $width_per = round((($image->width / $max_size->w) * 100), 2); |
|
1618 | - } else |
|
1619 | - $width_per = 100; |
|
1620 | - } |
|
1621 | - |
|
1622 | - if (is_admin() && !isset($_REQUEST['geodir_ajax'])){ |
|
1623 | - $html = '<div class="geodir_thumbnail"><img style="max-height:' . $max_size->h . 'px;" alt="place image" src="' . $image->src . '" /></div>'; |
|
1624 | - } else { |
|
1625 | - if($size=='widget-thumb' || !get_option('geodir_lazy_load',1)){ |
|
1626 | - $html = '<div class="geodir_thumbnail" style="background-image:url(\'' . $image->src . '\');"></div>'; |
|
1627 | - }else{ |
|
1628 | - //$html = '<div class="geodir_thumbnail" style="background-image:url(\'' . $image->src . '\');"></div>'; |
|
1629 | - //$html = '<div data-src="'.$image->src.'" class="geodir_thumbnail" ></div>'; |
|
1630 | - $html = '<div data-src="'.str_replace(' ','%20',$image->src).'" class="geodir_thumbnail geodir_lazy_load_thumbnail" ></div>'; |
|
1631 | - |
|
1632 | - } |
|
1633 | - |
|
1634 | - } |
|
1635 | - } |
|
1636 | - } |
|
1637 | - |
|
1638 | - if (!empty($html) && $echo) { |
|
1639 | - echo $html; |
|
1640 | - } elseif (!empty($html)) { |
|
1641 | - return $html; |
|
1642 | - } else |
|
1643 | - return false; |
|
1644 | - } |
|
1645 | -} |
|
1598 | + $width = 0; |
|
1599 | + $height = 0; |
|
1600 | + if (is_file($request->path) && file_exists($request->path)) { |
|
1601 | + $imagesize = getimagesize($request->path); |
|
1602 | + $width = !empty($imagesize) && isset($imagesize[0]) ? $imagesize[0] : ''; |
|
1603 | + $height = !empty($imagesize) && isset($imagesize[1]) ? $imagesize[1] : ''; |
|
1604 | + } |
|
1646 | 1605 | |
1647 | -if (!function_exists('geodir_set_post_terms')) { |
|
1648 | - /** |
|
1649 | - * Set post Categories. |
|
1650 | - * |
|
1651 | - * @since 1.0.0 |
|
1652 | - * @package GeoDirectory |
|
1653 | - * @global object $wpdb WordPress Database object. |
|
1654 | - * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
1655 | - * @param int $post_id The post ID. |
|
1656 | - * @param array $terms An array of term objects. |
|
1657 | - * @param array $tt_ids An array of term taxonomy IDs. |
|
1658 | - * @param string $taxonomy Taxonomy slug. |
|
1659 | - */ |
|
1660 | - function geodir_set_post_terms($post_id, $terms, $tt_ids, $taxonomy) |
|
1661 | - { |
|
1662 | - global $wpdb, $plugin_prefix; |
|
1606 | + $image->src = $request->src; |
|
1607 | + $image->width = $width; |
|
1608 | + $image->height = $height; |
|
1609 | + |
|
1610 | + $max_size = (object)geodir_get_imagesize($size); |
|
1611 | + |
|
1612 | + if (!is_wp_error($max_size)) { |
|
1613 | + if ($image->width) { |
|
1614 | + if ($image->height >= $image->width) { |
|
1615 | + $width_per = round(((($image->width * ($max_size->h / $image->height)) / $max_size->w) * 100), 2); |
|
1616 | + } else if ($image->width < ($max_size->h)) { |
|
1617 | + $width_per = round((($image->width / $max_size->w) * 100), 2); |
|
1618 | + } else |
|
1619 | + $width_per = 100; |
|
1620 | + } |
|
1663 | 1621 | |
1664 | - $post_type = get_post_type($post_id); |
|
1622 | + if (is_admin() && !isset($_REQUEST['geodir_ajax'])){ |
|
1623 | + $html = '<div class="geodir_thumbnail"><img style="max-height:' . $max_size->h . 'px;" alt="place image" src="' . $image->src . '" /></div>'; |
|
1624 | + } else { |
|
1625 | + if($size=='widget-thumb' || !get_option('geodir_lazy_load',1)){ |
|
1626 | + $html = '<div class="geodir_thumbnail" style="background-image:url(\'' . $image->src . '\');"></div>'; |
|
1627 | + }else{ |
|
1628 | + //$html = '<div class="geodir_thumbnail" style="background-image:url(\'' . $image->src . '\');"></div>'; |
|
1629 | + //$html = '<div data-src="'.$image->src.'" class="geodir_thumbnail" ></div>'; |
|
1630 | + $html = '<div data-src="'.str_replace(' ','%20',$image->src).'" class="geodir_thumbnail geodir_lazy_load_thumbnail" ></div>'; |
|
1665 | 1631 | |
1666 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
1632 | + } |
|
1667 | 1633 | |
1668 | - if (in_array($post_type, geodir_get_posttypes()) && !wp_is_post_revision($post_id)) { |
|
1634 | + } |
|
1635 | + } |
|
1636 | + } |
|
1637 | + |
|
1638 | + if (!empty($html) && $echo) { |
|
1639 | + echo $html; |
|
1640 | + } elseif (!empty($html)) { |
|
1641 | + return $html; |
|
1642 | + } else |
|
1643 | + return false; |
|
1644 | + } |
|
1645 | +} |
|
1669 | 1646 | |
1670 | - if ($taxonomy == $post_type . '_tags') { |
|
1671 | - if (isset($_POST['action']) && $_POST['action'] == 'inline-save') { |
|
1672 | - geodir_save_post_meta($post_id, 'post_tags', $terms); |
|
1673 | - } |
|
1674 | - } elseif ($taxonomy == $post_type . 'category') { |
|
1675 | - $srcharr = array('"', '\\'); |
|
1676 | - $replarr = array(""", ''); |
|
1647 | +if (!function_exists('geodir_set_post_terms')) { |
|
1648 | + /** |
|
1649 | + * Set post Categories. |
|
1650 | + * |
|
1651 | + * @since 1.0.0 |
|
1652 | + * @package GeoDirectory |
|
1653 | + * @global object $wpdb WordPress Database object. |
|
1654 | + * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
1655 | + * @param int $post_id The post ID. |
|
1656 | + * @param array $terms An array of term objects. |
|
1657 | + * @param array $tt_ids An array of term taxonomy IDs. |
|
1658 | + * @param string $taxonomy Taxonomy slug. |
|
1659 | + */ |
|
1660 | + function geodir_set_post_terms($post_id, $terms, $tt_ids, $taxonomy) |
|
1661 | + { |
|
1662 | + global $wpdb, $plugin_prefix; |
|
1663 | + |
|
1664 | + $post_type = get_post_type($post_id); |
|
1665 | + |
|
1666 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
1667 | + |
|
1668 | + if (in_array($post_type, geodir_get_posttypes()) && !wp_is_post_revision($post_id)) { |
|
1669 | + |
|
1670 | + if ($taxonomy == $post_type . '_tags') { |
|
1671 | + if (isset($_POST['action']) && $_POST['action'] == 'inline-save') { |
|
1672 | + geodir_save_post_meta($post_id, 'post_tags', $terms); |
|
1673 | + } |
|
1674 | + } elseif ($taxonomy == $post_type . 'category') { |
|
1675 | + $srcharr = array('"', '\\'); |
|
1676 | + $replarr = array(""", ''); |
|
1677 | 1677 | |
1678 | - $post_obj = get_post($post_id); |
|
1678 | + $post_obj = get_post($post_id); |
|
1679 | 1679 | |
1680 | - $cat_ids = array('0'); |
|
1681 | - if (is_array($tt_ids)) |
|
1682 | - $cat_ids = $tt_ids; |
|
1680 | + $cat_ids = array('0'); |
|
1681 | + if (is_array($tt_ids)) |
|
1682 | + $cat_ids = $tt_ids; |
|
1683 | 1683 | |
1684 | 1684 | |
1685 | - if (!empty($cat_ids)) { |
|
1686 | - $cat_ids_array = $cat_ids; |
|
1687 | - $cat_ids_length = count($cat_ids_array); |
|
1688 | - $cat_ids_format = array_fill(0, $cat_ids_length, '%d'); |
|
1689 | - $format = implode(',', $cat_ids_format); |
|
1685 | + if (!empty($cat_ids)) { |
|
1686 | + $cat_ids_array = $cat_ids; |
|
1687 | + $cat_ids_length = count($cat_ids_array); |
|
1688 | + $cat_ids_format = array_fill(0, $cat_ids_length, '%d'); |
|
1689 | + $format = implode(',', $cat_ids_format); |
|
1690 | 1690 | |
1691 | - $cat_ids_array_del = $cat_ids_array; |
|
1692 | - $cat_ids_array_del[] = $post_id; |
|
1691 | + $cat_ids_array_del = $cat_ids_array; |
|
1692 | + $cat_ids_array_del[] = $post_id; |
|
1693 | 1693 | |
1694 | - $wpdb->get_var( |
|
1695 | - $wpdb->prepare( |
|
1696 | - "DELETE from " . GEODIR_ICON_TABLE . " WHERE cat_id NOT IN ($format) AND post_id = %d ", |
|
1697 | - $cat_ids_array_del |
|
1698 | - ) |
|
1699 | - ); |
|
1694 | + $wpdb->get_var( |
|
1695 | + $wpdb->prepare( |
|
1696 | + "DELETE from " . GEODIR_ICON_TABLE . " WHERE cat_id NOT IN ($format) AND post_id = %d ", |
|
1697 | + $cat_ids_array_del |
|
1698 | + ) |
|
1699 | + ); |
|
1700 | 1700 | |
1701 | 1701 | |
1702 | - $post_term = $wpdb->get_col( |
|
1703 | - $wpdb->prepare( |
|
1704 | - "SELECT term_id FROM " . $wpdb->term_taxonomy . " WHERE term_taxonomy_id IN($format) GROUP BY term_id", |
|
1705 | - $cat_ids_array |
|
1706 | - ) |
|
1707 | - ); |
|
1702 | + $post_term = $wpdb->get_col( |
|
1703 | + $wpdb->prepare( |
|
1704 | + "SELECT term_id FROM " . $wpdb->term_taxonomy . " WHERE term_taxonomy_id IN($format) GROUP BY term_id", |
|
1705 | + $cat_ids_array |
|
1706 | + ) |
|
1707 | + ); |
|
1708 | 1708 | |
1709 | - } |
|
1709 | + } |
|
1710 | 1710 | |
1711 | - $post_marker_json = ''; |
|
1711 | + $post_marker_json = ''; |
|
1712 | 1712 | |
1713 | - if (!empty($post_term)): |
|
1713 | + if (!empty($post_term)): |
|
1714 | 1714 | |
1715 | - foreach ($post_term as $cat_id): |
|
1715 | + foreach ($post_term as $cat_id): |
|
1716 | 1716 | |
1717 | - $term_icon_url = get_tax_meta($cat_id, 'ct_cat_icon', false, $post_type); |
|
1718 | - $term_icon = isset($term_icon_url['src']) ? $term_icon_url['src'] : ''; |
|
1717 | + $term_icon_url = get_tax_meta($cat_id, 'ct_cat_icon', false, $post_type); |
|
1718 | + $term_icon = isset($term_icon_url['src']) ? $term_icon_url['src'] : ''; |
|
1719 | 1719 | |
1720 | - $post_title = $post_obj->title; |
|
1721 | - $title = str_replace($srcharr, $replarr, $post_title); |
|
1720 | + $post_title = $post_obj->title; |
|
1721 | + $title = str_replace($srcharr, $replarr, $post_title); |
|
1722 | 1722 | |
1723 | - $lat = geodir_get_post_meta($post_id, 'post_latitude', true); |
|
1724 | - $lng = geodir_get_post_meta($post_id, 'post_longitude', true); |
|
1723 | + $lat = geodir_get_post_meta($post_id, 'post_latitude', true); |
|
1724 | + $lng = geodir_get_post_meta($post_id, 'post_longitude', true); |
|
1725 | 1725 | |
1726 | - $timing = ' - ' . date('D M j, Y', strtotime(geodir_get_post_meta($post_id, 'st_date', true))); |
|
1727 | - $timing .= ' - ' . geodir_get_post_meta($post_id, 'st_time', true); |
|
1726 | + $timing = ' - ' . date('D M j, Y', strtotime(geodir_get_post_meta($post_id, 'st_date', true))); |
|
1727 | + $timing .= ' - ' . geodir_get_post_meta($post_id, 'st_time', true); |
|
1728 | 1728 | |
1729 | - $json = '{'; |
|
1730 | - $json .= '"id":"' . $post_id . '",'; |
|
1731 | - $json .= '"lat_pos": "' . $lat . '",'; |
|
1732 | - $json .= '"long_pos": "' . $lng . '",'; |
|
1733 | - $json .= '"marker_id":"' . $post_id . '_' . $cat_id . '",'; |
|
1734 | - $json .= '"icon":"' . $term_icon . '",'; |
|
1735 | - $json .= '"group":"catgroup' . $cat_id . '"'; |
|
1736 | - $json .= '}'; |
|
1729 | + $json = '{'; |
|
1730 | + $json .= '"id":"' . $post_id . '",'; |
|
1731 | + $json .= '"lat_pos": "' . $lat . '",'; |
|
1732 | + $json .= '"long_pos": "' . $lng . '",'; |
|
1733 | + $json .= '"marker_id":"' . $post_id . '_' . $cat_id . '",'; |
|
1734 | + $json .= '"icon":"' . $term_icon . '",'; |
|
1735 | + $json .= '"group":"catgroup' . $cat_id . '"'; |
|
1736 | + $json .= '}'; |
|
1737 | 1737 | |
1738 | 1738 | |
1739 | - if ($cat_id == geodir_get_post_meta($post_id, 'default_category', true)) |
|
1740 | - $post_marker_json = $json; |
|
1739 | + if ($cat_id == geodir_get_post_meta($post_id, 'default_category', true)) |
|
1740 | + $post_marker_json = $json; |
|
1741 | 1741 | |
1742 | 1742 | |
1743 | - if ($wpdb->get_var($wpdb->prepare("SELECT post_id from " . GEODIR_ICON_TABLE . " WHERE post_id = %d AND cat_id = %d", array($post_id, $cat_id)))) { |
|
1743 | + if ($wpdb->get_var($wpdb->prepare("SELECT post_id from " . GEODIR_ICON_TABLE . " WHERE post_id = %d AND cat_id = %d", array($post_id, $cat_id)))) { |
|
1744 | 1744 | |
1745 | - $json_query = $wpdb->prepare("UPDATE " . GEODIR_ICON_TABLE . " SET |
|
1745 | + $json_query = $wpdb->prepare("UPDATE " . GEODIR_ICON_TABLE . " SET |
|
1746 | 1746 | post_title = %s, |
1747 | 1747 | json = %s |
1748 | 1748 | WHERE post_id = %d AND cat_id = %d ", |
1749 | - array($post_title, $json, $post_id, $cat_id)); |
|
1749 | + array($post_title, $json, $post_id, $cat_id)); |
|
1750 | 1750 | |
1751 | - } else { |
|
1751 | + } else { |
|
1752 | 1752 | |
1753 | - $json_query = $wpdb->prepare("INSERT INTO " . GEODIR_ICON_TABLE . " SET |
|
1753 | + $json_query = $wpdb->prepare("INSERT INTO " . GEODIR_ICON_TABLE . " SET |
|
1754 | 1754 | post_id = %d, |
1755 | 1755 | post_title = %s, |
1756 | 1756 | cat_id = %d, |
1757 | 1757 | json = %s", |
1758 | - array($post_id, $post_title, $cat_id, $json)); |
|
1758 | + array($post_id, $post_title, $cat_id, $json)); |
|
1759 | 1759 | |
1760 | - } |
|
1760 | + } |
|
1761 | 1761 | |
1762 | - $wpdb->query($json_query); |
|
1762 | + $wpdb->query($json_query); |
|
1763 | 1763 | |
1764 | - endforeach; |
|
1764 | + endforeach; |
|
1765 | 1765 | |
1766 | - endif; |
|
1766 | + endif; |
|
1767 | 1767 | |
1768 | - if (!empty($post_term) && is_array($post_term)) { |
|
1769 | - $categories = implode(',', $post_term); |
|
1768 | + if (!empty($post_term) && is_array($post_term)) { |
|
1769 | + $categories = implode(',', $post_term); |
|
1770 | 1770 | |
1771 | - if ($categories != '' && $categories != 0) $categories = ',' . $categories . ','; |
|
1771 | + if ($categories != '' && $categories != 0) $categories = ',' . $categories . ','; |
|
1772 | 1772 | |
1773 | - if (empty($post_marker_json)) |
|
1774 | - $post_marker_json = isset($json) ? $json : ''; |
|
1773 | + if (empty($post_marker_json)) |
|
1774 | + $post_marker_json = isset($json) ? $json : ''; |
|
1775 | 1775 | |
1776 | - if ($wpdb->get_var($wpdb->prepare("SELECT post_id from " . $table . " where post_id = %d", array($post_id)))) { |
|
1776 | + if ($wpdb->get_var($wpdb->prepare("SELECT post_id from " . $table . " where post_id = %d", array($post_id)))) { |
|
1777 | 1777 | |
1778 | - $wpdb->query( |
|
1779 | - $wpdb->prepare( |
|
1780 | - "UPDATE " . $table . " SET |
|
1778 | + $wpdb->query( |
|
1779 | + $wpdb->prepare( |
|
1780 | + "UPDATE " . $table . " SET |
|
1781 | 1781 | " . $taxonomy . " = %s, |
1782 | 1782 | marker_json = %s |
1783 | 1783 | where post_id = %d", |
1784 | - array($categories, $post_marker_json, $post_id) |
|
1785 | - ) |
|
1786 | - ); |
|
1784 | + array($categories, $post_marker_json, $post_id) |
|
1785 | + ) |
|
1786 | + ); |
|
1787 | 1787 | |
1788 | - if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'inline-save') { |
|
1788 | + if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'inline-save') { |
|
1789 | 1789 | |
1790 | - $categories = trim($categories, ','); |
|
1790 | + $categories = trim($categories, ','); |
|
1791 | 1791 | |
1792 | - if ($categories) { |
|
1792 | + if ($categories) { |
|
1793 | 1793 | |
1794 | - $categories = explode(',', $categories); |
|
1794 | + $categories = explode(',', $categories); |
|
1795 | 1795 | |
1796 | - $default_category = geodir_get_post_meta($post_id, 'default_category', true); |
|
1796 | + $default_category = geodir_get_post_meta($post_id, 'default_category', true); |
|
1797 | 1797 | |
1798 | - if (!in_array($default_category, $categories)) { |
|
1798 | + if (!in_array($default_category, $categories)) { |
|
1799 | 1799 | |
1800 | - $wpdb->query( |
|
1801 | - $wpdb->prepare( |
|
1802 | - "UPDATE " . $table . " SET |
|
1800 | + $wpdb->query( |
|
1801 | + $wpdb->prepare( |
|
1802 | + "UPDATE " . $table . " SET |
|
1803 | 1803 | default_category = %s |
1804 | 1804 | where post_id = %d", |
1805 | - array($categories[0], $post_id) |
|
1806 | - ) |
|
1807 | - ); |
|
1805 | + array($categories[0], $post_id) |
|
1806 | + ) |
|
1807 | + ); |
|
1808 | 1808 | |
1809 | - $default_category = $categories[0]; |
|
1809 | + $default_category = $categories[0]; |
|
1810 | 1810 | |
1811 | - } |
|
1811 | + } |
|
1812 | 1812 | |
1813 | - if ($default_category == '') |
|
1814 | - $default_category = $categories[0]; |
|
1813 | + if ($default_category == '') |
|
1814 | + $default_category = $categories[0]; |
|
1815 | 1815 | |
1816 | - geodir_set_postcat_structure($post_id, $taxonomy, $default_category, ''); |
|
1816 | + geodir_set_postcat_structure($post_id, $taxonomy, $default_category, ''); |
|
1817 | 1817 | |
1818 | - } |
|
1818 | + } |
|
1819 | 1819 | |
1820 | - } |
|
1820 | + } |
|
1821 | 1821 | |
1822 | 1822 | |
1823 | - } else { |
|
1823 | + } else { |
|
1824 | 1824 | |
1825 | - $wpdb->query( |
|
1826 | - $wpdb->prepare( |
|
1827 | - "INSERT INTO " . $table . " SET |
|
1825 | + $wpdb->query( |
|
1826 | + $wpdb->prepare( |
|
1827 | + "INSERT INTO " . $table . " SET |
|
1828 | 1828 | post_id = %d, |
1829 | 1829 | " . $taxonomy . " = %s, |
1830 | 1830 | marker_json = %s ", |
1831 | 1831 | |
1832 | - array($post_id, $categories, $post_marker_json) |
|
1833 | - ) |
|
1834 | - ); |
|
1835 | - } |
|
1836 | - } |
|
1837 | - } |
|
1838 | - } |
|
1839 | - } |
|
1832 | + array($post_id, $categories, $post_marker_json) |
|
1833 | + ) |
|
1834 | + ); |
|
1835 | + } |
|
1836 | + } |
|
1837 | + } |
|
1838 | + } |
|
1839 | + } |
|
1840 | 1840 | } |
1841 | 1841 | |
1842 | 1842 | if (!function_exists('geodir_get_infowindow_html')) { |
1843 | - /** |
|
1844 | - * Set post Map Marker info html. |
|
1845 | - * |
|
1846 | - * @since 1.0.0 |
|
1847 | - * @since 1.5.4 Modified to add new action "geodir_infowindow_meta_before". |
|
1848 | - * @since 1.6.16 Changes for disable review stars for certain post type. |
|
1849 | - * @package GeoDirectory |
|
1850 | - * @global array $geodir_addon_list List of active GeoDirectory extensions. |
|
1851 | - * @global object $gd_session GeoDirectory Session object. |
|
1852 | - * @param object $postinfo_obj The post details object. |
|
1853 | - * @param string $post_preview Is this a post preview?. |
|
1854 | - * @return mixed|string|void |
|
1855 | - */ |
|
1856 | - function geodir_get_infowindow_html($postinfo_obj, $post_preview = '') |
|
1857 | - { |
|
1858 | - global $preview, $gd_session; |
|
1859 | - $srcharr = array("'", "/", "-", '"', '\\'); |
|
1860 | - $replarr = array("′", "⁄", "–", "“", ''); |
|
1861 | - |
|
1862 | - if ($gd_session->get('listing') && isset($post_preview) && $post_preview != '') { |
|
1863 | - $ID = ''; |
|
1864 | - $plink = ''; |
|
1865 | - |
|
1866 | - if (isset($postinfo_obj->pid)) { |
|
1867 | - $ID = $postinfo_obj->pid; |
|
1868 | - $plink = get_permalink($ID); |
|
1869 | - } |
|
1870 | - |
|
1871 | - $title = str_replace($srcharr, $replarr, ($postinfo_obj->post_title)); |
|
1872 | - $lat = $postinfo_obj->post_latitude; |
|
1873 | - $lng = $postinfo_obj->post_longitude; |
|
1874 | - } else { |
|
1875 | - $ID = $postinfo_obj->post_id; |
|
1876 | - $title = str_replace($srcharr, $replarr, htmlentities($postinfo_obj->post_title, ENT_COMPAT, 'UTF-8')); // fix by Stiofan |
|
1877 | - $title = wp_specialchars_decode($title); // Fixed #post-320722 on 2016-12-08 |
|
1878 | - $plink = get_permalink($ID); |
|
1879 | - $lat = htmlentities(geodir_get_post_meta($ID, 'post_latitude', true)); |
|
1880 | - $lng = htmlentities(geodir_get_post_meta($ID, 'post_longitude', true)); |
|
1881 | - } |
|
1843 | + /** |
|
1844 | + * Set post Map Marker info html. |
|
1845 | + * |
|
1846 | + * @since 1.0.0 |
|
1847 | + * @since 1.5.4 Modified to add new action "geodir_infowindow_meta_before". |
|
1848 | + * @since 1.6.16 Changes for disable review stars for certain post type. |
|
1849 | + * @package GeoDirectory |
|
1850 | + * @global array $geodir_addon_list List of active GeoDirectory extensions. |
|
1851 | + * @global object $gd_session GeoDirectory Session object. |
|
1852 | + * @param object $postinfo_obj The post details object. |
|
1853 | + * @param string $post_preview Is this a post preview?. |
|
1854 | + * @return mixed|string|void |
|
1855 | + */ |
|
1856 | + function geodir_get_infowindow_html($postinfo_obj, $post_preview = '') |
|
1857 | + { |
|
1858 | + global $preview, $gd_session; |
|
1859 | + $srcharr = array("'", "/", "-", '"', '\\'); |
|
1860 | + $replarr = array("′", "⁄", "–", "“", ''); |
|
1861 | + |
|
1862 | + if ($gd_session->get('listing') && isset($post_preview) && $post_preview != '') { |
|
1863 | + $ID = ''; |
|
1864 | + $plink = ''; |
|
1865 | + |
|
1866 | + if (isset($postinfo_obj->pid)) { |
|
1867 | + $ID = $postinfo_obj->pid; |
|
1868 | + $plink = get_permalink($ID); |
|
1869 | + } |
|
1870 | + |
|
1871 | + $title = str_replace($srcharr, $replarr, ($postinfo_obj->post_title)); |
|
1872 | + $lat = $postinfo_obj->post_latitude; |
|
1873 | + $lng = $postinfo_obj->post_longitude; |
|
1874 | + } else { |
|
1875 | + $ID = $postinfo_obj->post_id; |
|
1876 | + $title = str_replace($srcharr, $replarr, htmlentities($postinfo_obj->post_title, ENT_COMPAT, 'UTF-8')); // fix by Stiofan |
|
1877 | + $title = wp_specialchars_decode($title); // Fixed #post-320722 on 2016-12-08 |
|
1878 | + $plink = get_permalink($ID); |
|
1879 | + $lat = htmlentities(geodir_get_post_meta($ID, 'post_latitude', true)); |
|
1880 | + $lng = htmlentities(geodir_get_post_meta($ID, 'post_longitude', true)); |
|
1881 | + } |
|
1882 | 1882 | |
1883 | - $post_type = $ID ? get_post_type($ID) : ''; |
|
1884 | - |
|
1885 | - // filter field as per price package |
|
1886 | - global $geodir_addon_list; |
|
1887 | - if ($post_type && defined('GEODIRPAYMENT_VERSION')) { |
|
1888 | - $package_id = isset($postinfo_obj->package_id) && $postinfo_obj->package_id ? $postinfo_obj->package_id : NULL; |
|
1889 | - $field_name = 'geodir_contact'; |
|
1890 | - if (!check_field_visibility($package_id, $field_name, $post_type)) { |
|
1891 | - $contact = ''; |
|
1892 | - } |
|
1893 | - |
|
1894 | - $field_name = 'geodir_timing'; |
|
1895 | - if (!check_field_visibility($package_id, $field_name, $post_type)) { |
|
1896 | - $timing = ''; |
|
1897 | - } |
|
1898 | - } |
|
1899 | - |
|
1900 | - if ($lat && $lng) { |
|
1901 | - ob_start(); ?> |
|
1883 | + $post_type = $ID ? get_post_type($ID) : ''; |
|
1884 | + |
|
1885 | + // filter field as per price package |
|
1886 | + global $geodir_addon_list; |
|
1887 | + if ($post_type && defined('GEODIRPAYMENT_VERSION')) { |
|
1888 | + $package_id = isset($postinfo_obj->package_id) && $postinfo_obj->package_id ? $postinfo_obj->package_id : NULL; |
|
1889 | + $field_name = 'geodir_contact'; |
|
1890 | + if (!check_field_visibility($package_id, $field_name, $post_type)) { |
|
1891 | + $contact = ''; |
|
1892 | + } |
|
1893 | + |
|
1894 | + $field_name = 'geodir_timing'; |
|
1895 | + if (!check_field_visibility($package_id, $field_name, $post_type)) { |
|
1896 | + $timing = ''; |
|
1897 | + } |
|
1898 | + } |
|
1899 | + |
|
1900 | + if ($lat && $lng) { |
|
1901 | + ob_start(); ?> |
|
1902 | 1902 | <div class="gd-bubble" style=""> |
1903 | 1903 | <div class="gd-bubble-inside"> |
1904 | 1904 | <?php |
1905 | - $comment_count = ''; |
|
1906 | - $rating_star = ''; |
|
1907 | - if ($ID != '' && $post_type != '' && !geodir_cpt_has_rating_disabled($post_type)) { |
|
1908 | - $rating_star = ''; |
|
1909 | - $comment_count = geodir_get_review_count_total($ID); |
|
1910 | - |
|
1911 | - if (!$preview) { |
|
1912 | - $post_avgratings = geodir_get_post_rating($ID); |
|
1913 | - |
|
1914 | - $rating_star = geodir_get_rating_stars($post_avgratings, $ID, false); |
|
1915 | - |
|
1916 | - /** |
|
1917 | - * Filter to change rating stars |
|
1918 | - * |
|
1919 | - * You can use this filter to change Rating stars. |
|
1920 | - * |
|
1921 | - * @since 1.0.0 |
|
1922 | - * @package GeoDirectory |
|
1923 | - * @param string $rating_star Rating stars. |
|
1924 | - * @param float $post_avgratings Average ratings of the post. |
|
1925 | - * @param int $ID The post ID. |
|
1926 | - */ |
|
1927 | - $rating_star = apply_filters('geodir_review_rating_stars_on_infowindow', $rating_star, $post_avgratings, $ID); |
|
1928 | - } |
|
1929 | - } |
|
1930 | - ?> |
|
1905 | + $comment_count = ''; |
|
1906 | + $rating_star = ''; |
|
1907 | + if ($ID != '' && $post_type != '' && !geodir_cpt_has_rating_disabled($post_type)) { |
|
1908 | + $rating_star = ''; |
|
1909 | + $comment_count = geodir_get_review_count_total($ID); |
|
1910 | + |
|
1911 | + if (!$preview) { |
|
1912 | + $post_avgratings = geodir_get_post_rating($ID); |
|
1913 | + |
|
1914 | + $rating_star = geodir_get_rating_stars($post_avgratings, $ID, false); |
|
1915 | + |
|
1916 | + /** |
|
1917 | + * Filter to change rating stars |
|
1918 | + * |
|
1919 | + * You can use this filter to change Rating stars. |
|
1920 | + * |
|
1921 | + * @since 1.0.0 |
|
1922 | + * @package GeoDirectory |
|
1923 | + * @param string $rating_star Rating stars. |
|
1924 | + * @param float $post_avgratings Average ratings of the post. |
|
1925 | + * @param int $ID The post ID. |
|
1926 | + */ |
|
1927 | + $rating_star = apply_filters('geodir_review_rating_stars_on_infowindow', $rating_star, $post_avgratings, $ID); |
|
1928 | + } |
|
1929 | + } |
|
1930 | + ?> |
|
1931 | 1931 | <div class="geodir-bubble_desc"> |
1932 | 1932 | <h4> |
1933 | 1933 | <a href="<?php if ($plink != '') { |
1934 | - echo $plink; |
|
1935 | - } else { |
|
1936 | - echo 'javascript:void(0);'; |
|
1937 | - } ?>"><?php echo $title; ?></a> |
|
1934 | + echo $plink; |
|
1935 | + } else { |
|
1936 | + echo 'javascript:void(0);'; |
|
1937 | + } ?>"><?php echo $title; ?></a> |
|
1938 | 1938 | </h4> |
1939 | 1939 | <?php |
1940 | - if ($gd_session->get('listing') && isset($post_preview) && $post_preview != '') { |
|
1941 | - $post_images = array(); |
|
1942 | - if (!empty($postinfo_obj->post_images)) { |
|
1943 | - $post_images = explode(",", $postinfo_obj->post_images); |
|
1944 | - } |
|
1945 | - |
|
1946 | - if (!empty($post_images)) { |
|
1947 | - ?> |
|
1940 | + if ($gd_session->get('listing') && isset($post_preview) && $post_preview != '') { |
|
1941 | + $post_images = array(); |
|
1942 | + if (!empty($postinfo_obj->post_images)) { |
|
1943 | + $post_images = explode(",", $postinfo_obj->post_images); |
|
1944 | + } |
|
1945 | + |
|
1946 | + if (!empty($post_images)) { |
|
1947 | + ?> |
|
1948 | 1948 | <div class="geodir-bubble_image"><a href="<?php if ($plink != '') { |
1949 | - echo $plink; |
|
1950 | - } else { |
|
1951 | - echo 'javascript:void(0);'; |
|
1952 | - } ?>"><img alt="bubble image" style="max-height:50px;" |
|
1949 | + echo $plink; |
|
1950 | + } else { |
|
1951 | + echo 'javascript:void(0);'; |
|
1952 | + } ?>"><img alt="bubble image" style="max-height:50px;" |
|
1953 | 1953 | src="<?php echo $post_images[0]; ?>"/></a></div> |
1954 | 1954 | <?php |
1955 | - }else{ |
|
1956 | - echo '<div class="geodir-bubble_image"></div>'; |
|
1957 | - } |
|
1958 | - } else { |
|
1959 | - if ($image = geodir_show_featured_image($ID, 'widget-thumb', true, false, $postinfo_obj->featured_image)) { |
|
1960 | - ?> |
|
1955 | + }else{ |
|
1956 | + echo '<div class="geodir-bubble_image"></div>'; |
|
1957 | + } |
|
1958 | + } else { |
|
1959 | + if ($image = geodir_show_featured_image($ID, 'widget-thumb', true, false, $postinfo_obj->featured_image)) { |
|
1960 | + ?> |
|
1961 | 1961 | <div class="geodir-bubble_image"><a href="<?php echo $plink; ?>"><?php echo $image; ?></a></div> |
1962 | 1962 | <?php |
1963 | - }else{ |
|
1964 | - echo '<div class="geodir-bubble_image"></div>'; |
|
1965 | - } |
|
1966 | - } |
|
1967 | - ?> |
|
1963 | + }else{ |
|
1964 | + echo '<div class="geodir-bubble_image"></div>'; |
|
1965 | + } |
|
1966 | + } |
|
1967 | + ?> |
|
1968 | 1968 | <div class="geodir-bubble-meta-side"> |
1969 | 1969 | <?php |
1970 | - /** |
|
1971 | - * Fires before the meta info in the map info window. |
|
1972 | - * |
|
1973 | - * This can be used to add more info to the map info window before the normal meta info. |
|
1974 | - * |
|
1975 | - * @since 1.5.4 |
|
1976 | - * @param int $ID The post id. |
|
1977 | - * @param object $postinfo_obj The posts info as an object. |
|
1978 | - * @param bool|string $post_preview True if currently in post preview page. Empty string if not. * |
|
1979 | - */ |
|
1980 | - do_action('geodir_infowindow_meta_before', $ID, $postinfo_obj, $post_preview); |
|
1981 | - |
|
1982 | - echo geodir_show_listing_info('mapbubble'); |
|
1983 | - |
|
1984 | - /** |
|
1985 | - * Fires after the meta info in the map info window. |
|
1986 | - * |
|
1987 | - * This can be used to add more info to the map info window after the normal meta info. |
|
1988 | - * |
|
1989 | - * @since 1.4.2 |
|
1990 | - * @param object $postinfo_obj The posts info as an object. |
|
1991 | - * @param bool|string $post_preview True if currently in post preview page. Empty string if not. * |
|
1992 | - */ |
|
1993 | - do_action('geodir_infowindow_meta_after',$postinfo_obj,$post_preview ); |
|
1994 | - ?> |
|
1970 | + /** |
|
1971 | + * Fires before the meta info in the map info window. |
|
1972 | + * |
|
1973 | + * This can be used to add more info to the map info window before the normal meta info. |
|
1974 | + * |
|
1975 | + * @since 1.5.4 |
|
1976 | + * @param int $ID The post id. |
|
1977 | + * @param object $postinfo_obj The posts info as an object. |
|
1978 | + * @param bool|string $post_preview True if currently in post preview page. Empty string if not. * |
|
1979 | + */ |
|
1980 | + do_action('geodir_infowindow_meta_before', $ID, $postinfo_obj, $post_preview); |
|
1981 | + |
|
1982 | + echo geodir_show_listing_info('mapbubble'); |
|
1983 | + |
|
1984 | + /** |
|
1985 | + * Fires after the meta info in the map info window. |
|
1986 | + * |
|
1987 | + * This can be used to add more info to the map info window after the normal meta info. |
|
1988 | + * |
|
1989 | + * @since 1.4.2 |
|
1990 | + * @param object $postinfo_obj The posts info as an object. |
|
1991 | + * @param bool|string $post_preview True if currently in post preview page. Empty string if not. * |
|
1992 | + */ |
|
1993 | + do_action('geodir_infowindow_meta_after',$postinfo_obj,$post_preview ); |
|
1994 | + ?> |
|
1995 | 1995 | </div> |
1996 | 1996 | <?php |
1997 | - if ($ID) { |
|
1998 | - $post_author = isset($postinfo_obj->post_author) ? $postinfo_obj->post_author : get_post_field('post_author', $ID); |
|
1999 | - ?> |
|
1997 | + if ($ID) { |
|
1998 | + $post_author = isset($postinfo_obj->post_author) ? $postinfo_obj->post_author : get_post_field('post_author', $ID); |
|
1999 | + ?> |
|
2000 | 2000 | <div class="geodir-bubble-meta-fade"></div> |
2001 | 2001 | <div class="geodir-bubble-meta-bottom"> |
2002 | 2002 | <?php if ($rating_star != '') { ?> |
@@ -2012,69 +2012,69 @@ discard block |
||
2012 | 2012 | </div> |
2013 | 2013 | </div> |
2014 | 2014 | <?php |
2015 | - $html = ob_get_clean(); |
|
2016 | - /** |
|
2017 | - * Filter to change infowindow html |
|
2018 | - * |
|
2019 | - * You can use this filter to change infowindow html. |
|
2020 | - * |
|
2021 | - * @since 1.0.0 |
|
2022 | - * @package GeoDirectory |
|
2023 | - * @param string $html Infowindow html. |
|
2024 | - * @param object $postinfo_obj The Post object. |
|
2025 | - * @param bool|string $post_preview Is this a post preview? |
|
2026 | - */ |
|
2027 | - $html = apply_filters('geodir_custom_infowindow_html', $html, $postinfo_obj, $post_preview); |
|
2028 | - return $html; |
|
2029 | - } |
|
2030 | - } |
|
2015 | + $html = ob_get_clean(); |
|
2016 | + /** |
|
2017 | + * Filter to change infowindow html |
|
2018 | + * |
|
2019 | + * You can use this filter to change infowindow html. |
|
2020 | + * |
|
2021 | + * @since 1.0.0 |
|
2022 | + * @package GeoDirectory |
|
2023 | + * @param string $html Infowindow html. |
|
2024 | + * @param object $postinfo_obj The Post object. |
|
2025 | + * @param bool|string $post_preview Is this a post preview? |
|
2026 | + */ |
|
2027 | + $html = apply_filters('geodir_custom_infowindow_html', $html, $postinfo_obj, $post_preview); |
|
2028 | + return $html; |
|
2029 | + } |
|
2030 | + } |
|
2031 | 2031 | } |
2032 | 2032 | |
2033 | 2033 | |
2034 | 2034 | if (!function_exists('geodir_new_post_default_status')) { |
2035 | - /** |
|
2036 | - * Default post status for new posts. |
|
2037 | - * |
|
2038 | - * @since 1.0.0 |
|
2039 | - * @package GeoDirectory |
|
2040 | - * @return string Returns the default post status for new posts. Ex: draft, publish etc. |
|
2041 | - */ |
|
2042 | - function geodir_new_post_default_status() |
|
2043 | - { |
|
2044 | - if (get_option('geodir_new_post_default_status')) |
|
2045 | - return get_option('geodir_new_post_default_status'); |
|
2046 | - else |
|
2047 | - return 'publish'; |
|
2048 | - |
|
2049 | - } |
|
2035 | + /** |
|
2036 | + * Default post status for new posts. |
|
2037 | + * |
|
2038 | + * @since 1.0.0 |
|
2039 | + * @package GeoDirectory |
|
2040 | + * @return string Returns the default post status for new posts. Ex: draft, publish etc. |
|
2041 | + */ |
|
2042 | + function geodir_new_post_default_status() |
|
2043 | + { |
|
2044 | + if (get_option('geodir_new_post_default_status')) |
|
2045 | + return get_option('geodir_new_post_default_status'); |
|
2046 | + else |
|
2047 | + return 'publish'; |
|
2048 | + |
|
2049 | + } |
|
2050 | 2050 | } |
2051 | 2051 | |
2052 | 2052 | if (!function_exists('geodir_change_post_status')) { |
2053 | - /** |
|
2054 | - * Change post status of a post. |
|
2055 | - * |
|
2056 | - * @global object $wpdb WordPress Database object. |
|
2057 | - * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
2058 | - * @param int|string $post_id The post ID. |
|
2059 | - * @param string $status New post status. Ex: draft, publish etc. |
|
2060 | - */ |
|
2061 | - function geodir_change_post_status($post_id = '', $status = '') |
|
2062 | - { |
|
2063 | - global $wpdb, $plugin_prefix; |
|
2064 | - |
|
2065 | - $post_type = get_post_type($post_id); |
|
2066 | - |
|
2067 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
2068 | - |
|
2069 | - $wpdb->query( |
|
2070 | - $wpdb->prepare( |
|
2071 | - "UPDATE " . $table . " SET post_status=%s WHERE post_id=%d", |
|
2072 | - array($status, $post_id) |
|
2073 | - ) |
|
2074 | - ); |
|
2075 | - |
|
2076 | - |
|
2077 | - } |
|
2053 | + /** |
|
2054 | + * Change post status of a post. |
|
2055 | + * |
|
2056 | + * @global object $wpdb WordPress Database object. |
|
2057 | + * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
2058 | + * @param int|string $post_id The post ID. |
|
2059 | + * @param string $status New post status. Ex: draft, publish etc. |
|
2060 | + */ |
|
2061 | + function geodir_change_post_status($post_id = '', $status = '') |
|
2062 | + { |
|
2063 | + global $wpdb, $plugin_prefix; |
|
2064 | + |
|
2065 | + $post_type = get_post_type($post_id); |
|
2066 | + |
|
2067 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
2068 | + |
|
2069 | + $wpdb->query( |
|
2070 | + $wpdb->prepare( |
|
2071 | + "UPDATE " . $table . " SET post_status=%s WHERE post_id=%d", |
|
2072 | + array($status, $post_id) |
|
2073 | + ) |
|
2074 | + ); |
|
2075 | + |
|
2076 | + |
|
2077 | + } |
|
2078 | 2078 | } |
2079 | 2079 | |
2080 | 2080 | /** |
@@ -2088,13 +2088,13 @@ discard block |
||
2088 | 2088 | */ |
2089 | 2089 | function geodir_set_post_status($pid, $status) |
2090 | 2090 | { |
2091 | - if ($pid) { |
|
2092 | - global $wpdb; |
|
2093 | - $my_post = array(); |
|
2094 | - $my_post['post_status'] = $status; |
|
2095 | - $my_post['ID'] = $pid; |
|
2096 | - $last_postid = wp_update_post($my_post); |
|
2097 | - } |
|
2091 | + if ($pid) { |
|
2092 | + global $wpdb; |
|
2093 | + $my_post = array(); |
|
2094 | + $my_post['post_status'] = $status; |
|
2095 | + $my_post['ID'] = $pid; |
|
2096 | + $last_postid = wp_update_post($my_post); |
|
2097 | + } |
|
2098 | 2098 | } |
2099 | 2099 | |
2100 | 2100 | |
@@ -2110,384 +2110,384 @@ discard block |
||
2110 | 2110 | */ |
2111 | 2111 | function geodir_update_poststatus($new_status, $old_status, $post) |
2112 | 2112 | { |
2113 | - global $wpdb; |
|
2113 | + global $wpdb; |
|
2114 | 2114 | |
2115 | - $geodir_posttypes = geodir_get_posttypes(); |
|
2115 | + $geodir_posttypes = geodir_get_posttypes(); |
|
2116 | 2116 | |
2117 | - if (!wp_is_post_revision($post->ID) && in_array($post->post_type, $geodir_posttypes)) { |
|
2117 | + if (!wp_is_post_revision($post->ID) && in_array($post->post_type, $geodir_posttypes)) { |
|
2118 | 2118 | |
2119 | - geodir_change_post_status($post->ID, $new_status); |
|
2120 | - } |
|
2119 | + geodir_change_post_status($post->ID, $new_status); |
|
2120 | + } |
|
2121 | 2121 | } |
2122 | 2122 | |
2123 | 2123 | |
2124 | 2124 | if (!function_exists('geodir_update_listing_info')) { |
2125 | - /** |
|
2126 | - * Update post info. |
|
2127 | - * |
|
2128 | - * @since 1.0.0 |
|
2129 | - * @package GeoDirectory |
|
2130 | - * @global object $wpdb WordPress Database object. |
|
2131 | - * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
2132 | - * @param int $updatingpost The updating post ID. |
|
2133 | - * @param int $temppost The temporary post ID. |
|
2134 | - * @todo fix post_id variable |
|
2135 | - */ |
|
2136 | - function geodir_update_listing_info($updatingpost, $temppost) |
|
2137 | - { |
|
2138 | - |
|
2139 | - global $wpdb, $plugin_prefix; |
|
2140 | - |
|
2141 | - $post_type = get_post_type($post_id); |
|
2142 | - |
|
2143 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
2144 | - |
|
2145 | - $wpdb->query( |
|
2146 | - $wpdb->prepare( |
|
2147 | - "UPDATE " . $table . " SET `post_id` = %d WHERE `post_id` = %d", |
|
2148 | - array($updatingpost, $temppost) |
|
2149 | - ) |
|
2150 | - ); |
|
2151 | - |
|
2152 | - $wpdb->query( |
|
2153 | - $wpdb->prepare( |
|
2154 | - "UPDATE " . GEODIR_ICON_TABLE . " SET `post_id` = %d WHERE `post_id` = %d", |
|
2155 | - array($updatingpost, $temppost) |
|
2156 | - ) |
|
2157 | - ); |
|
2158 | - |
|
2159 | - /* Update Attachments*/ |
|
2160 | - |
|
2161 | - $wpdb->query( |
|
2162 | - $wpdb->prepare( |
|
2163 | - "UPDATE " . GEODIR_ATTACHMENT_TABLE . " SET `post_id` = %d WHERE `post_id` = %d", |
|
2164 | - array($updatingpost, $temppost) |
|
2165 | - ) |
|
2166 | - ); |
|
2167 | - |
|
2168 | - } |
|
2125 | + /** |
|
2126 | + * Update post info. |
|
2127 | + * |
|
2128 | + * @since 1.0.0 |
|
2129 | + * @package GeoDirectory |
|
2130 | + * @global object $wpdb WordPress Database object. |
|
2131 | + * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
2132 | + * @param int $updatingpost The updating post ID. |
|
2133 | + * @param int $temppost The temporary post ID. |
|
2134 | + * @todo fix post_id variable |
|
2135 | + */ |
|
2136 | + function geodir_update_listing_info($updatingpost, $temppost) |
|
2137 | + { |
|
2138 | + |
|
2139 | + global $wpdb, $plugin_prefix; |
|
2140 | + |
|
2141 | + $post_type = get_post_type($post_id); |
|
2142 | + |
|
2143 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
2144 | + |
|
2145 | + $wpdb->query( |
|
2146 | + $wpdb->prepare( |
|
2147 | + "UPDATE " . $table . " SET `post_id` = %d WHERE `post_id` = %d", |
|
2148 | + array($updatingpost, $temppost) |
|
2149 | + ) |
|
2150 | + ); |
|
2151 | + |
|
2152 | + $wpdb->query( |
|
2153 | + $wpdb->prepare( |
|
2154 | + "UPDATE " . GEODIR_ICON_TABLE . " SET `post_id` = %d WHERE `post_id` = %d", |
|
2155 | + array($updatingpost, $temppost) |
|
2156 | + ) |
|
2157 | + ); |
|
2158 | + |
|
2159 | + /* Update Attachments*/ |
|
2160 | + |
|
2161 | + $wpdb->query( |
|
2162 | + $wpdb->prepare( |
|
2163 | + "UPDATE " . GEODIR_ATTACHMENT_TABLE . " SET `post_id` = %d WHERE `post_id` = %d", |
|
2164 | + array($updatingpost, $temppost) |
|
2165 | + ) |
|
2166 | + ); |
|
2167 | + |
|
2168 | + } |
|
2169 | 2169 | } |
2170 | 2170 | |
2171 | 2171 | |
2172 | 2172 | if (!function_exists('geodir_delete_listing_info')) { |
2173 | - /** |
|
2174 | - * Delete Listing info from details table for the given post id. |
|
2175 | - * |
|
2176 | - * @since 1.0.0 |
|
2177 | - * @package GeoDirectory |
|
2178 | - * @global object $wpdb WordPress Database object. |
|
2179 | - * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
2180 | - * @param int $deleted_postid The post ID. |
|
2181 | - * @param bool $force Optional. Do you want to force delete it? Default: false. |
|
2182 | - * @return bool|void |
|
2183 | - */ |
|
2184 | - function geodir_delete_listing_info($deleted_postid, $force = false) |
|
2185 | - { |
|
2186 | - global $wpdb, $plugin_prefix; |
|
2187 | - |
|
2188 | - // check for multisite deletions |
|
2189 | - if (strpos($plugin_prefix, $wpdb->prefix) !== false) { |
|
2190 | - } else { |
|
2191 | - return; |
|
2192 | - } |
|
2193 | - |
|
2194 | - $post_type = get_post_type($deleted_postid); |
|
2195 | - |
|
2196 | - $all_postypes = geodir_get_posttypes(); |
|
2197 | - |
|
2198 | - if (!in_array($post_type, $all_postypes)) |
|
2199 | - return false; |
|
2200 | - |
|
2201 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
2202 | - |
|
2203 | - /* Delete custom post meta*/ |
|
2204 | - $wpdb->query( |
|
2205 | - $wpdb->prepare( |
|
2206 | - "DELETE FROM " . $table . " WHERE `post_id` = %d", |
|
2207 | - array($deleted_postid) |
|
2208 | - ) |
|
2209 | - ); |
|
2210 | - |
|
2211 | - /* Delete post map icons*/ |
|
2212 | - |
|
2213 | - $wpdb->query( |
|
2214 | - $wpdb->prepare( |
|
2215 | - "DELETE FROM " . GEODIR_ICON_TABLE . " WHERE `post_id` = %d", |
|
2216 | - array($deleted_postid) |
|
2217 | - ) |
|
2218 | - ); |
|
2219 | - |
|
2220 | - /* Delete Attachments*/ |
|
2221 | - $postcurr_images = geodir_get_images($deleted_postid); |
|
2222 | - |
|
2223 | - $wpdb->query( |
|
2224 | - $wpdb->prepare( |
|
2225 | - "DELETE FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE `post_id` = %d", |
|
2226 | - array($deleted_postid) |
|
2227 | - ) |
|
2228 | - ); |
|
2229 | - geodir_remove_attachments($postcurr_images); |
|
2230 | - |
|
2231 | - } |
|
2173 | + /** |
|
2174 | + * Delete Listing info from details table for the given post id. |
|
2175 | + * |
|
2176 | + * @since 1.0.0 |
|
2177 | + * @package GeoDirectory |
|
2178 | + * @global object $wpdb WordPress Database object. |
|
2179 | + * @global string $plugin_prefix Geodirectory plugin table prefix. |
|
2180 | + * @param int $deleted_postid The post ID. |
|
2181 | + * @param bool $force Optional. Do you want to force delete it? Default: false. |
|
2182 | + * @return bool|void |
|
2183 | + */ |
|
2184 | + function geodir_delete_listing_info($deleted_postid, $force = false) |
|
2185 | + { |
|
2186 | + global $wpdb, $plugin_prefix; |
|
2187 | + |
|
2188 | + // check for multisite deletions |
|
2189 | + if (strpos($plugin_prefix, $wpdb->prefix) !== false) { |
|
2190 | + } else { |
|
2191 | + return; |
|
2192 | + } |
|
2193 | + |
|
2194 | + $post_type = get_post_type($deleted_postid); |
|
2195 | + |
|
2196 | + $all_postypes = geodir_get_posttypes(); |
|
2197 | + |
|
2198 | + if (!in_array($post_type, $all_postypes)) |
|
2199 | + return false; |
|
2200 | + |
|
2201 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
2202 | + |
|
2203 | + /* Delete custom post meta*/ |
|
2204 | + $wpdb->query( |
|
2205 | + $wpdb->prepare( |
|
2206 | + "DELETE FROM " . $table . " WHERE `post_id` = %d", |
|
2207 | + array($deleted_postid) |
|
2208 | + ) |
|
2209 | + ); |
|
2210 | + |
|
2211 | + /* Delete post map icons*/ |
|
2212 | + |
|
2213 | + $wpdb->query( |
|
2214 | + $wpdb->prepare( |
|
2215 | + "DELETE FROM " . GEODIR_ICON_TABLE . " WHERE `post_id` = %d", |
|
2216 | + array($deleted_postid) |
|
2217 | + ) |
|
2218 | + ); |
|
2219 | + |
|
2220 | + /* Delete Attachments*/ |
|
2221 | + $postcurr_images = geodir_get_images($deleted_postid); |
|
2222 | + |
|
2223 | + $wpdb->query( |
|
2224 | + $wpdb->prepare( |
|
2225 | + "DELETE FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE `post_id` = %d", |
|
2226 | + array($deleted_postid) |
|
2227 | + ) |
|
2228 | + ); |
|
2229 | + geodir_remove_attachments($postcurr_images); |
|
2230 | + |
|
2231 | + } |
|
2232 | 2232 | } |
2233 | 2233 | |
2234 | 2234 | |
2235 | 2235 | if (!function_exists('geodir_add_to_favorite')) { |
2236 | - /** |
|
2237 | - * This function would add listing to favorite listing. |
|
2238 | - * |
|
2239 | - * @since 1.0.0 |
|
2240 | - * @package GeoDirectory |
|
2241 | - * @global object $current_user Current user object. |
|
2242 | - * @param int $post_id The post ID. |
|
2243 | - */ |
|
2244 | - function geodir_add_to_favorite($post_id) |
|
2245 | - { |
|
2246 | - |
|
2247 | - global $current_user; |
|
2248 | - |
|
2249 | - /** |
|
2250 | - * Filter to modify "Unfavorite" text |
|
2251 | - * |
|
2252 | - * You can use this filter to rename "Unfavorite" text to something else. |
|
2253 | - * |
|
2254 | - * @since 1.0.0 |
|
2255 | - * @package GeoDirectory |
|
2256 | - */ |
|
2257 | - $remove_favourite_text = apply_filters('geodir_remove_favourite_text', REMOVE_FAVOURITE_TEXT); |
|
2258 | - |
|
2259 | - /** |
|
2260 | - * Filter to modify "Remove from Favorites" text |
|
2261 | - * |
|
2262 | - * You can use this filter to rename "Remove from Favorites" text to something else. |
|
2263 | - * |
|
2264 | - * @since 1.0.0 |
|
2265 | - * @package GeoDirectory |
|
2266 | - */ |
|
2267 | - $unfavourite_text = apply_filters('geodir_unfavourite_text', UNFAVOURITE_TEXT); |
|
2268 | - |
|
2269 | - /** |
|
2270 | - * Filter to modify "fa fa-heart" icon |
|
2271 | - * |
|
2272 | - * You can use this filter to change "fa fa-heart" icon to something else. |
|
2273 | - * |
|
2274 | - * @since 1.0.0 |
|
2275 | - * @package GeoDirectory |
|
2276 | - */ |
|
2277 | - $favourite_icon = apply_filters('geodir_favourite_icon', 'fa fa-heart'); |
|
2278 | - |
|
2279 | - $user_meta_data = array(); |
|
2280 | - $user_meta_data = get_user_meta($current_user->data->ID, 'gd_user_favourite_post', true); |
|
2281 | - |
|
2282 | - if (empty($user_meta_data) || (!empty($user_meta_data) && !in_array($post_id, $user_meta_data))) { |
|
2283 | - $user_meta_data[] = $post_id; |
|
2284 | - } |
|
2285 | - |
|
2286 | - update_user_meta($current_user->data->ID, 'gd_user_favourite_post', $user_meta_data); |
|
2287 | - |
|
2288 | - /** |
|
2289 | - * Called before adding the post from favourites. |
|
2290 | - * |
|
2291 | - * @since 1.0.0 |
|
2292 | - * @package GeoDirectory |
|
2293 | - * @param int $post_id The post ID. |
|
2294 | - */ |
|
2295 | - do_action('geodir_before_add_from_favorite', $post_id); |
|
2296 | - |
|
2297 | - echo '<a href="javascript:void(0);" title="' . $remove_favourite_text . '" class="geodir-removetofav-icon" onclick="javascript:addToFavourite(\'' . $post_id . '\',\'remove\');"><i class="'. $favourite_icon .'"></i> ' . $unfavourite_text . '</a>'; |
|
2236 | + /** |
|
2237 | + * This function would add listing to favorite listing. |
|
2238 | + * |
|
2239 | + * @since 1.0.0 |
|
2240 | + * @package GeoDirectory |
|
2241 | + * @global object $current_user Current user object. |
|
2242 | + * @param int $post_id The post ID. |
|
2243 | + */ |
|
2244 | + function geodir_add_to_favorite($post_id) |
|
2245 | + { |
|
2246 | + |
|
2247 | + global $current_user; |
|
2248 | + |
|
2249 | + /** |
|
2250 | + * Filter to modify "Unfavorite" text |
|
2251 | + * |
|
2252 | + * You can use this filter to rename "Unfavorite" text to something else. |
|
2253 | + * |
|
2254 | + * @since 1.0.0 |
|
2255 | + * @package GeoDirectory |
|
2256 | + */ |
|
2257 | + $remove_favourite_text = apply_filters('geodir_remove_favourite_text', REMOVE_FAVOURITE_TEXT); |
|
2258 | + |
|
2259 | + /** |
|
2260 | + * Filter to modify "Remove from Favorites" text |
|
2261 | + * |
|
2262 | + * You can use this filter to rename "Remove from Favorites" text to something else. |
|
2263 | + * |
|
2264 | + * @since 1.0.0 |
|
2265 | + * @package GeoDirectory |
|
2266 | + */ |
|
2267 | + $unfavourite_text = apply_filters('geodir_unfavourite_text', UNFAVOURITE_TEXT); |
|
2268 | + |
|
2269 | + /** |
|
2270 | + * Filter to modify "fa fa-heart" icon |
|
2271 | + * |
|
2272 | + * You can use this filter to change "fa fa-heart" icon to something else. |
|
2273 | + * |
|
2274 | + * @since 1.0.0 |
|
2275 | + * @package GeoDirectory |
|
2276 | + */ |
|
2277 | + $favourite_icon = apply_filters('geodir_favourite_icon', 'fa fa-heart'); |
|
2278 | + |
|
2279 | + $user_meta_data = array(); |
|
2280 | + $user_meta_data = get_user_meta($current_user->data->ID, 'gd_user_favourite_post', true); |
|
2281 | + |
|
2282 | + if (empty($user_meta_data) || (!empty($user_meta_data) && !in_array($post_id, $user_meta_data))) { |
|
2283 | + $user_meta_data[] = $post_id; |
|
2284 | + } |
|
2285 | + |
|
2286 | + update_user_meta($current_user->data->ID, 'gd_user_favourite_post', $user_meta_data); |
|
2287 | + |
|
2288 | + /** |
|
2289 | + * Called before adding the post from favourites. |
|
2290 | + * |
|
2291 | + * @since 1.0.0 |
|
2292 | + * @package GeoDirectory |
|
2293 | + * @param int $post_id The post ID. |
|
2294 | + */ |
|
2295 | + do_action('geodir_before_add_from_favorite', $post_id); |
|
2296 | + |
|
2297 | + echo '<a href="javascript:void(0);" title="' . $remove_favourite_text . '" class="geodir-removetofav-icon" onclick="javascript:addToFavourite(\'' . $post_id . '\',\'remove\');"><i class="'. $favourite_icon .'"></i> ' . $unfavourite_text . '</a>'; |
|
2298 | + |
|
2299 | + /** |
|
2300 | + * Called after adding the post from favourites. |
|
2301 | + * |
|
2302 | + * @since 1.0.0 |
|
2303 | + * @package GeoDirectory |
|
2304 | + * @param int $post_id The post ID. |
|
2305 | + */ |
|
2306 | + do_action('geodir_after_add_from_favorite', $post_id); |
|
2298 | 2307 | |
2299 | - /** |
|
2300 | - * Called after adding the post from favourites. |
|
2301 | - * |
|
2302 | - * @since 1.0.0 |
|
2303 | - * @package GeoDirectory |
|
2304 | - * @param int $post_id The post ID. |
|
2305 | - */ |
|
2306 | - do_action('geodir_after_add_from_favorite', $post_id); |
|
2307 | - |
|
2308 | - } |
|
2308 | + } |
|
2309 | 2309 | } |
2310 | 2310 | |
2311 | 2311 | if (!function_exists('geodir_remove_from_favorite')) { |
2312 | - /** |
|
2313 | - * This function would remove the favourited property earlier. |
|
2314 | - * |
|
2315 | - * @since 1.0.0 |
|
2316 | - * @package GeoDirectory |
|
2317 | - * @global object $current_user Current user object. |
|
2318 | - * @param int $post_id The post ID. |
|
2319 | - */ |
|
2320 | - function geodir_remove_from_favorite($post_id) |
|
2321 | - { |
|
2322 | - global $current_user; |
|
2323 | - |
|
2324 | - /** |
|
2325 | - * Filter to modify "Add to Favorites" text |
|
2326 | - * |
|
2327 | - * You can use this filter to rename "Add to Favorites" text to something else. |
|
2328 | - * |
|
2329 | - * @since 1.0.0 |
|
2330 | - * @package GeoDirectory |
|
2331 | - */ |
|
2332 | - $add_favourite_text = apply_filters('geodir_add_favourite_text', ADD_FAVOURITE_TEXT); |
|
2333 | - |
|
2334 | - /** |
|
2335 | - * Filter to modify "Favourite" text |
|
2336 | - * |
|
2337 | - * You can use this filter to rename "Favourite" text to something else. |
|
2338 | - * |
|
2339 | - * @since 1.0.0 |
|
2340 | - * @package GeoDirectory |
|
2341 | - */ |
|
2342 | - $favourite_text = apply_filters('geodir_favourite_text', FAVOURITE_TEXT); |
|
2343 | - |
|
2344 | - /** |
|
2345 | - * Filter to modify "fa fa-heart" icon |
|
2346 | - * |
|
2347 | - * You can use this filter to change "fa fa-heart" icon to something else. |
|
2348 | - * |
|
2349 | - * @since 1.0.0 |
|
2350 | - * @package GeoDirectory |
|
2351 | - */ |
|
2352 | - $favourite_icon = apply_filters('geodir_favourite_icon', 'fa fa-heart'); |
|
2353 | - |
|
2354 | - $user_meta_data = array(); |
|
2355 | - $user_meta_data = get_user_meta($current_user->data->ID, 'gd_user_favourite_post', true); |
|
2356 | - |
|
2357 | - if (!empty($user_meta_data)) { |
|
2312 | + /** |
|
2313 | + * This function would remove the favourited property earlier. |
|
2314 | + * |
|
2315 | + * @since 1.0.0 |
|
2316 | + * @package GeoDirectory |
|
2317 | + * @global object $current_user Current user object. |
|
2318 | + * @param int $post_id The post ID. |
|
2319 | + */ |
|
2320 | + function geodir_remove_from_favorite($post_id) |
|
2321 | + { |
|
2322 | + global $current_user; |
|
2323 | + |
|
2324 | + /** |
|
2325 | + * Filter to modify "Add to Favorites" text |
|
2326 | + * |
|
2327 | + * You can use this filter to rename "Add to Favorites" text to something else. |
|
2328 | + * |
|
2329 | + * @since 1.0.0 |
|
2330 | + * @package GeoDirectory |
|
2331 | + */ |
|
2332 | + $add_favourite_text = apply_filters('geodir_add_favourite_text', ADD_FAVOURITE_TEXT); |
|
2333 | + |
|
2334 | + /** |
|
2335 | + * Filter to modify "Favourite" text |
|
2336 | + * |
|
2337 | + * You can use this filter to rename "Favourite" text to something else. |
|
2338 | + * |
|
2339 | + * @since 1.0.0 |
|
2340 | + * @package GeoDirectory |
|
2341 | + */ |
|
2342 | + $favourite_text = apply_filters('geodir_favourite_text', FAVOURITE_TEXT); |
|
2343 | + |
|
2344 | + /** |
|
2345 | + * Filter to modify "fa fa-heart" icon |
|
2346 | + * |
|
2347 | + * You can use this filter to change "fa fa-heart" icon to something else. |
|
2348 | + * |
|
2349 | + * @since 1.0.0 |
|
2350 | + * @package GeoDirectory |
|
2351 | + */ |
|
2352 | + $favourite_icon = apply_filters('geodir_favourite_icon', 'fa fa-heart'); |
|
2353 | + |
|
2354 | + $user_meta_data = array(); |
|
2355 | + $user_meta_data = get_user_meta($current_user->data->ID, 'gd_user_favourite_post', true); |
|
2356 | + |
|
2357 | + if (!empty($user_meta_data)) { |
|
2358 | + |
|
2359 | + if (($key = array_search($post_id, $user_meta_data)) !== false) { |
|
2360 | + unset($user_meta_data[$key]); |
|
2361 | + } |
|
2358 | 2362 | |
2359 | - if (($key = array_search($post_id, $user_meta_data)) !== false) { |
|
2360 | - unset($user_meta_data[$key]); |
|
2361 | - } |
|
2363 | + } |
|
2362 | 2364 | |
2363 | - } |
|
2365 | + update_user_meta($current_user->data->ID, 'gd_user_favourite_post', $user_meta_data); |
|
2364 | 2366 | |
2365 | - update_user_meta($current_user->data->ID, 'gd_user_favourite_post', $user_meta_data); |
|
2367 | + /** |
|
2368 | + * Called before removing the post from favourites. |
|
2369 | + * |
|
2370 | + * @since 1.0.0 |
|
2371 | + * @package GeoDirectory |
|
2372 | + * @param int $post_id The post ID. |
|
2373 | + */ |
|
2374 | + do_action('geodir_before_remove_from_favorite', $post_id); |
|
2366 | 2375 | |
2367 | - /** |
|
2368 | - * Called before removing the post from favourites. |
|
2369 | - * |
|
2370 | - * @since 1.0.0 |
|
2371 | - * @package GeoDirectory |
|
2372 | - * @param int $post_id The post ID. |
|
2373 | - */ |
|
2374 | - do_action('geodir_before_remove_from_favorite', $post_id); |
|
2376 | + echo '<a href="javascript:void(0);" title="' . $add_favourite_text . '" class="geodir-addtofav-icon" onclick="javascript:addToFavourite(\'' . $post_id . '\',\'add\');"><i class="'. $favourite_icon .'"></i> ' . $favourite_text . '</a>'; |
|
2375 | 2377 | |
2376 | - echo '<a href="javascript:void(0);" title="' . $add_favourite_text . '" class="geodir-addtofav-icon" onclick="javascript:addToFavourite(\'' . $post_id . '\',\'add\');"><i class="'. $favourite_icon .'"></i> ' . $favourite_text . '</a>'; |
|
2378 | + /** |
|
2379 | + * Called after removing the post from favourites. |
|
2380 | + * |
|
2381 | + * @since 1.0.0 |
|
2382 | + * @package GeoDirectory |
|
2383 | + * @param int $post_id The post ID. |
|
2384 | + */ |
|
2385 | + do_action('geodir_after_remove_from_favorite', $post_id); |
|
2377 | 2386 | |
2378 | - /** |
|
2379 | - * Called after removing the post from favourites. |
|
2380 | - * |
|
2381 | - * @since 1.0.0 |
|
2382 | - * @package GeoDirectory |
|
2383 | - * @param int $post_id The post ID. |
|
2384 | - */ |
|
2385 | - do_action('geodir_after_remove_from_favorite', $post_id); |
|
2386 | - |
|
2387 | - } |
|
2387 | + } |
|
2388 | 2388 | } |
2389 | 2389 | |
2390 | 2390 | if (!function_exists('geodir_favourite_html')) { |
2391 | - /** |
|
2392 | - * This function would display the html content for add to favorite or remove from favorite. |
|
2393 | - * |
|
2394 | - * @since 1.0.0 |
|
2395 | - * @package GeoDirectory |
|
2396 | - * @global object $current_user Current user object. |
|
2397 | - * @global object $post The current post object. |
|
2398 | - * @param int $user_id The user ID. |
|
2399 | - * @param int $post_id The post ID. |
|
2400 | - */ |
|
2401 | - function geodir_favourite_html($user_id, $post_id) |
|
2402 | - { |
|
2403 | - |
|
2404 | - global $current_user, $post; |
|
2405 | - |
|
2406 | - /** |
|
2407 | - * Filter to modify "Add to Favorites" text |
|
2408 | - * |
|
2409 | - * You can use this filter to rename "Add to Favorites" text to something else. |
|
2410 | - * |
|
2411 | - * @since 1.0.0 |
|
2412 | - * @package GeoDirectory |
|
2413 | - */ |
|
2414 | - $add_favourite_text = apply_filters('geodir_add_favourite_text', ADD_FAVOURITE_TEXT); |
|
2415 | - |
|
2416 | - /** |
|
2417 | - * Filter to modify "Favourite" text |
|
2418 | - * |
|
2419 | - * You can use this filter to rename "Favourite" text to something else. |
|
2420 | - * |
|
2421 | - * @since 1.0.0 |
|
2422 | - * @package GeoDirectory |
|
2423 | - */ |
|
2424 | - $favourite_text = apply_filters('geodir_favourite_text', FAVOURITE_TEXT); |
|
2425 | - |
|
2426 | - /** |
|
2427 | - * Filter to modify "Unfavorite" text |
|
2428 | - * |
|
2429 | - * You can use this filter to rename "Unfavorite" text to something else. |
|
2430 | - * |
|
2431 | - * @since 1.0.0 |
|
2432 | - * @package GeoDirectory |
|
2433 | - */ |
|
2434 | - $remove_favourite_text = apply_filters('geodir_remove_favourite_text', REMOVE_FAVOURITE_TEXT); |
|
2435 | - |
|
2436 | - /** |
|
2437 | - * Filter to modify "Remove from Favorites" text |
|
2438 | - * |
|
2439 | - * You can use this filter to rename "Remove from Favorites" text to something else. |
|
2440 | - * |
|
2441 | - * @since 1.0.0 |
|
2442 | - * @package GeoDirectory |
|
2443 | - */ |
|
2444 | - $unfavourite_text = apply_filters('geodir_unfavourite_text', UNFAVOURITE_TEXT); |
|
2445 | - |
|
2446 | - /** |
|
2447 | - * Filter to modify "fa fa-heart" icon |
|
2448 | - * |
|
2449 | - * You can use this filter to change "fa fa-heart" icon to something else. |
|
2450 | - * |
|
2451 | - * @since 1.0.0 |
|
2452 | - * @package GeoDirectory |
|
2453 | - */ |
|
2454 | - $favourite_icon = apply_filters('geodir_favourite_icon', 'fa fa-heart'); |
|
2455 | - |
|
2456 | - /** |
|
2457 | - * Filter to modify "fa fa-heart" icon for "remove from favorites" link |
|
2458 | - * |
|
2459 | - * You can use this filter to change "fa fa-heart" icon to something else. |
|
2460 | - * |
|
2461 | - * @since 1.0.0 |
|
2462 | - * @package GeoDirectory |
|
2463 | - */ |
|
2464 | - $unfavourite_icon = apply_filters('geodir_unfavourite_icon', 'fa fa-heart'); |
|
2465 | - |
|
2466 | - $user_meta_data = ''; |
|
2467 | - if (isset($current_user->data->ID)) |
|
2468 | - $user_meta_data = get_user_meta($current_user->data->ID, 'gd_user_favourite_post', true); |
|
2469 | - |
|
2470 | - if (!empty($user_meta_data) && in_array($post_id, $user_meta_data)) { |
|
2471 | - ?><span class="geodir-addtofav favorite_property_<?php echo $post_id;?>" ><a |
|
2391 | + /** |
|
2392 | + * This function would display the html content for add to favorite or remove from favorite. |
|
2393 | + * |
|
2394 | + * @since 1.0.0 |
|
2395 | + * @package GeoDirectory |
|
2396 | + * @global object $current_user Current user object. |
|
2397 | + * @global object $post The current post object. |
|
2398 | + * @param int $user_id The user ID. |
|
2399 | + * @param int $post_id The post ID. |
|
2400 | + */ |
|
2401 | + function geodir_favourite_html($user_id, $post_id) |
|
2402 | + { |
|
2403 | + |
|
2404 | + global $current_user, $post; |
|
2405 | + |
|
2406 | + /** |
|
2407 | + * Filter to modify "Add to Favorites" text |
|
2408 | + * |
|
2409 | + * You can use this filter to rename "Add to Favorites" text to something else. |
|
2410 | + * |
|
2411 | + * @since 1.0.0 |
|
2412 | + * @package GeoDirectory |
|
2413 | + */ |
|
2414 | + $add_favourite_text = apply_filters('geodir_add_favourite_text', ADD_FAVOURITE_TEXT); |
|
2415 | + |
|
2416 | + /** |
|
2417 | + * Filter to modify "Favourite" text |
|
2418 | + * |
|
2419 | + * You can use this filter to rename "Favourite" text to something else. |
|
2420 | + * |
|
2421 | + * @since 1.0.0 |
|
2422 | + * @package GeoDirectory |
|
2423 | + */ |
|
2424 | + $favourite_text = apply_filters('geodir_favourite_text', FAVOURITE_TEXT); |
|
2425 | + |
|
2426 | + /** |
|
2427 | + * Filter to modify "Unfavorite" text |
|
2428 | + * |
|
2429 | + * You can use this filter to rename "Unfavorite" text to something else. |
|
2430 | + * |
|
2431 | + * @since 1.0.0 |
|
2432 | + * @package GeoDirectory |
|
2433 | + */ |
|
2434 | + $remove_favourite_text = apply_filters('geodir_remove_favourite_text', REMOVE_FAVOURITE_TEXT); |
|
2435 | + |
|
2436 | + /** |
|
2437 | + * Filter to modify "Remove from Favorites" text |
|
2438 | + * |
|
2439 | + * You can use this filter to rename "Remove from Favorites" text to something else. |
|
2440 | + * |
|
2441 | + * @since 1.0.0 |
|
2442 | + * @package GeoDirectory |
|
2443 | + */ |
|
2444 | + $unfavourite_text = apply_filters('geodir_unfavourite_text', UNFAVOURITE_TEXT); |
|
2445 | + |
|
2446 | + /** |
|
2447 | + * Filter to modify "fa fa-heart" icon |
|
2448 | + * |
|
2449 | + * You can use this filter to change "fa fa-heart" icon to something else. |
|
2450 | + * |
|
2451 | + * @since 1.0.0 |
|
2452 | + * @package GeoDirectory |
|
2453 | + */ |
|
2454 | + $favourite_icon = apply_filters('geodir_favourite_icon', 'fa fa-heart'); |
|
2455 | + |
|
2456 | + /** |
|
2457 | + * Filter to modify "fa fa-heart" icon for "remove from favorites" link |
|
2458 | + * |
|
2459 | + * You can use this filter to change "fa fa-heart" icon to something else. |
|
2460 | + * |
|
2461 | + * @since 1.0.0 |
|
2462 | + * @package GeoDirectory |
|
2463 | + */ |
|
2464 | + $unfavourite_icon = apply_filters('geodir_unfavourite_icon', 'fa fa-heart'); |
|
2465 | + |
|
2466 | + $user_meta_data = ''; |
|
2467 | + if (isset($current_user->data->ID)) |
|
2468 | + $user_meta_data = get_user_meta($current_user->data->ID, 'gd_user_favourite_post', true); |
|
2469 | + |
|
2470 | + if (!empty($user_meta_data) && in_array($post_id, $user_meta_data)) { |
|
2471 | + ?><span class="geodir-addtofav favorite_property_<?php echo $post_id;?>" ><a |
|
2472 | 2472 | class="geodir-removetofav-icon" href="javascript:void(0);" |
2473 | 2473 | onclick="javascript:addToFavourite(<?php echo $post_id;?>,'remove');" |
2474 | 2474 | title="<?php echo $remove_favourite_text;?>"><i class="<?php echo $unfavourite_icon; ?>"></i> <?php echo $unfavourite_text;?> |
2475 | 2475 | </a> </span><?php |
2476 | 2476 | |
2477 | - } else { |
|
2477 | + } else { |
|
2478 | 2478 | |
2479 | - if (!isset($current_user->data->ID) || $current_user->data->ID == '') { |
|
2480 | - $script_text = 'javascript:window.location.href=\'' . geodir_login_url() . '\''; |
|
2481 | - } else |
|
2482 | - $script_text = 'javascript:addToFavourite(' . $post_id . ',\'add\')'; |
|
2479 | + if (!isset($current_user->data->ID) || $current_user->data->ID == '') { |
|
2480 | + $script_text = 'javascript:window.location.href=\'' . geodir_login_url() . '\''; |
|
2481 | + } else |
|
2482 | + $script_text = 'javascript:addToFavourite(' . $post_id . ',\'add\')'; |
|
2483 | 2483 | |
2484 | - ?><span class="geodir-addtofav favorite_property_<?php echo $post_id;?>"><a class="geodir-addtofav-icon" |
|
2484 | + ?><span class="geodir-addtofav favorite_property_<?php echo $post_id;?>"><a class="geodir-addtofav-icon" |
|
2485 | 2485 | href="javascript:void(0);" |
2486 | 2486 | onclick="<?php echo $script_text;?>" |
2487 | 2487 | title="<?php echo $add_favourite_text;?>"><i |
2488 | 2488 | class="<?php echo $favourite_icon; ?>"></i> <?php echo $favourite_text;?></a></span> |
2489 | 2489 | <?php } |
2490 | - } |
|
2490 | + } |
|
2491 | 2491 | } |
2492 | 2492 | |
2493 | 2493 | |
@@ -2504,54 +2504,54 @@ discard block |
||
2504 | 2504 | function geodir_get_cat_postcount($term = array()) |
2505 | 2505 | { |
2506 | 2506 | |
2507 | - if (!empty($term)) { |
|
2507 | + if (!empty($term)) { |
|
2508 | 2508 | |
2509 | - global $wpdb, $plugin_prefix; |
|
2509 | + global $wpdb, $plugin_prefix; |
|
2510 | 2510 | |
2511 | - $where = ''; |
|
2512 | - $join = ''; |
|
2513 | - if (get_query_var('gd_country') != '' || get_query_var('gd_region') != '' || get_query_var('gd_city') != '') { |
|
2514 | - $taxonomy_obj = get_taxonomy($term->taxonomy); |
|
2511 | + $where = ''; |
|
2512 | + $join = ''; |
|
2513 | + if (get_query_var('gd_country') != '' || get_query_var('gd_region') != '' || get_query_var('gd_city') != '') { |
|
2514 | + $taxonomy_obj = get_taxonomy($term->taxonomy); |
|
2515 | 2515 | |
2516 | - $post_type = $taxonomy_obj->object_type[0]; |
|
2516 | + $post_type = $taxonomy_obj->object_type[0]; |
|
2517 | 2517 | |
2518 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
2518 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
2519 | 2519 | |
2520 | - /** |
|
2521 | - * Filter to modify the 'join' query |
|
2522 | - * |
|
2523 | - * @since 1.0.0 |
|
2524 | - * @package GeoDirectory |
|
2525 | - * @param object|array $term category / term object that need to be processed. |
|
2526 | - * @param string $join The join query. |
|
2527 | - */ |
|
2528 | - $join = apply_filters('geodir_cat_post_count_join', $join, $term); |
|
2520 | + /** |
|
2521 | + * Filter to modify the 'join' query |
|
2522 | + * |
|
2523 | + * @since 1.0.0 |
|
2524 | + * @package GeoDirectory |
|
2525 | + * @param object|array $term category / term object that need to be processed. |
|
2526 | + * @param string $join The join query. |
|
2527 | + */ |
|
2528 | + $join = apply_filters('geodir_cat_post_count_join', $join, $term); |
|
2529 | 2529 | |
2530 | - /** |
|
2531 | - * Filter to modify the 'where' query |
|
2532 | - * |
|
2533 | - * @since 1.0.0 |
|
2534 | - * @package GeoDirectory |
|
2535 | - * @param object|array $term category / term object that need to be processed. |
|
2536 | - * @param string $where The where query. |
|
2537 | - */ |
|
2538 | - $where = apply_filters('geodir_cat_post_count_where', $where, $term); |
|
2530 | + /** |
|
2531 | + * Filter to modify the 'where' query |
|
2532 | + * |
|
2533 | + * @since 1.0.0 |
|
2534 | + * @package GeoDirectory |
|
2535 | + * @param object|array $term category / term object that need to be processed. |
|
2536 | + * @param string $where The where query. |
|
2537 | + */ |
|
2538 | + $where = apply_filters('geodir_cat_post_count_where', $where, $term); |
|
2539 | 2539 | |
2540 | - $count_query = "SELECT count(post_id) FROM |
|
2540 | + $count_query = "SELECT count(post_id) FROM |
|
2541 | 2541 | " . $table . " as pd " . $join . " |
2542 | 2542 | WHERE pd.post_status='publish' AND FIND_IN_SET('" . $term->term_id . "'," . $term->taxonomy . ") " . $where; |
2543 | 2543 | |
2544 | - $cat_post_count = $wpdb->get_var($count_query); |
|
2545 | - if (empty($cat_post_count) || is_wp_error($cat_post_count)) |
|
2546 | - $cat_post_count = 0; |
|
2544 | + $cat_post_count = $wpdb->get_var($count_query); |
|
2545 | + if (empty($cat_post_count) || is_wp_error($cat_post_count)) |
|
2546 | + $cat_post_count = 0; |
|
2547 | 2547 | |
2548 | - return $cat_post_count; |
|
2548 | + return $cat_post_count; |
|
2549 | 2549 | |
2550 | - } else |
|
2550 | + } else |
|
2551 | 2551 | |
2552 | - return $term->count; |
|
2553 | - } |
|
2554 | - return false; |
|
2552 | + return $term->count; |
|
2553 | + } |
|
2554 | + return false; |
|
2555 | 2555 | |
2556 | 2556 | } |
2557 | 2557 | |
@@ -2564,17 +2564,17 @@ discard block |
||
2564 | 2564 | */ |
2565 | 2565 | function geodir_allow_post_type_frontend() |
2566 | 2566 | { |
2567 | - $geodir_allow_posttype_frontend = get_option('geodir_allow_posttype_frontend'); |
|
2567 | + $geodir_allow_posttype_frontend = get_option('geodir_allow_posttype_frontend'); |
|
2568 | 2568 | |
2569 | - if (!is_admin() && isset($_REQUEST['listing_type']) |
|
2570 | - && !empty($geodir_allow_posttype_frontend) |
|
2571 | - && !in_array($_REQUEST['listing_type'], $geodir_allow_posttype_frontend) |
|
2572 | - ) { |
|
2569 | + if (!is_admin() && isset($_REQUEST['listing_type']) |
|
2570 | + && !empty($geodir_allow_posttype_frontend) |
|
2571 | + && !in_array($_REQUEST['listing_type'], $geodir_allow_posttype_frontend) |
|
2572 | + ) { |
|
2573 | 2573 | |
2574 | - wp_redirect(home_url()); |
|
2575 | - exit; |
|
2574 | + wp_redirect(home_url()); |
|
2575 | + exit; |
|
2576 | 2576 | |
2577 | - } |
|
2577 | + } |
|
2578 | 2578 | |
2579 | 2579 | } |
2580 | 2580 | |
@@ -2591,20 +2591,20 @@ discard block |
||
2591 | 2591 | */ |
2592 | 2592 | function geodir_excerpt_length($length) |
2593 | 2593 | { |
2594 | - global $wp_query, $geodir_is_widget_listing; |
|
2594 | + global $wp_query, $geodir_is_widget_listing; |
|
2595 | 2595 | if ($geodir_is_widget_listing) { |
2596 | 2596 | return $length; |
2597 | 2597 | } |
2598 | 2598 | |
2599 | - if (isset($wp_query->query_vars['is_geodir_loop']) && $wp_query->query_vars['is_geodir_loop'] && get_option('geodir_desc_word_limit')) |
|
2600 | - $length = get_option('geodir_desc_word_limit'); |
|
2601 | - elseif (get_query_var('excerpt_length')) |
|
2602 | - $length = get_query_var('excerpt_length'); |
|
2599 | + if (isset($wp_query->query_vars['is_geodir_loop']) && $wp_query->query_vars['is_geodir_loop'] && get_option('geodir_desc_word_limit')) |
|
2600 | + $length = get_option('geodir_desc_word_limit'); |
|
2601 | + elseif (get_query_var('excerpt_length')) |
|
2602 | + $length = get_query_var('excerpt_length'); |
|
2603 | 2603 | |
2604 | - if (geodir_is_page('author') && get_option('geodir_author_desc_word_limit')) |
|
2605 | - $length = get_option('geodir_author_desc_word_limit'); |
|
2604 | + if (geodir_is_page('author') && get_option('geodir_author_desc_word_limit')) |
|
2605 | + $length = get_option('geodir_author_desc_word_limit'); |
|
2606 | 2606 | |
2607 | - return $length; |
|
2607 | + return $length; |
|
2608 | 2608 | } |
2609 | 2609 | |
2610 | 2610 | /** |
@@ -2619,13 +2619,13 @@ discard block |
||
2619 | 2619 | */ |
2620 | 2620 | function geodir_excerpt_more($more) |
2621 | 2621 | { |
2622 | - global $post; |
|
2623 | - $all_postypes = geodir_get_posttypes(); |
|
2624 | - if (is_array($all_postypes) && in_array($post->post_type, $all_postypes)) { |
|
2625 | - return ' <a href="' . get_permalink($post->ID) . '">' . READ_MORE_TXT . '</a>'; |
|
2626 | - } |
|
2622 | + global $post; |
|
2623 | + $all_postypes = geodir_get_posttypes(); |
|
2624 | + if (is_array($all_postypes) && in_array($post->post_type, $all_postypes)) { |
|
2625 | + return ' <a href="' . get_permalink($post->ID) . '">' . READ_MORE_TXT . '</a>'; |
|
2626 | + } |
|
2627 | 2627 | |
2628 | - return $more; |
|
2628 | + return $more; |
|
2629 | 2629 | } |
2630 | 2630 | |
2631 | 2631 | |
@@ -2642,63 +2642,63 @@ discard block |
||
2642 | 2642 | */ |
2643 | 2643 | function geodir_update_markers_oncatedit($term_id, $tt_id, $taxonomy) |
2644 | 2644 | { |
2645 | - global $plugin_prefix, $wpdb; |
|
2645 | + global $plugin_prefix, $wpdb; |
|
2646 | 2646 | |
2647 | - $gd_taxonomies = geodir_get_taxonomies(); |
|
2647 | + $gd_taxonomies = geodir_get_taxonomies(); |
|
2648 | 2648 | |
2649 | - if (is_array($gd_taxonomies) && in_array($taxonomy, $gd_taxonomies)) { |
|
2649 | + if (is_array($gd_taxonomies) && in_array($taxonomy, $gd_taxonomies)) { |
|
2650 | 2650 | |
2651 | - $geodir_post_type = geodir_get_taxonomy_posttype($taxonomy); |
|
2652 | - $table = $plugin_prefix . $geodir_post_type . '_detail'; |
|
2651 | + $geodir_post_type = geodir_get_taxonomy_posttype($taxonomy); |
|
2652 | + $table = $plugin_prefix . $geodir_post_type . '_detail'; |
|
2653 | 2653 | |
2654 | - $path_parts = pathinfo($_REQUEST['ct_cat_icon']['src']); |
|
2655 | - $term_icon = $path_parts['dirname'] . '/cat_icon_' . $term_id . '.png'; |
|
2654 | + $path_parts = pathinfo($_REQUEST['ct_cat_icon']['src']); |
|
2655 | + $term_icon = $path_parts['dirname'] . '/cat_icon_' . $term_id . '.png'; |
|
2656 | 2656 | |
2657 | - $posts = $wpdb->get_results( |
|
2658 | - $wpdb->prepare( |
|
2659 | - "SELECT post_id,post_title,post_latitude,post_longitude,default_category FROM " . $table . " WHERE FIND_IN_SET(%s,%1\$s ) ", |
|
2660 | - array($term_id, $taxonomy) |
|
2661 | - ) |
|
2662 | - ); |
|
2657 | + $posts = $wpdb->get_results( |
|
2658 | + $wpdb->prepare( |
|
2659 | + "SELECT post_id,post_title,post_latitude,post_longitude,default_category FROM " . $table . " WHERE FIND_IN_SET(%s,%1\$s ) ", |
|
2660 | + array($term_id, $taxonomy) |
|
2661 | + ) |
|
2662 | + ); |
|
2663 | 2663 | |
2664 | - if (!empty($posts)): |
|
2665 | - foreach ($posts as $post_obj) { |
|
2664 | + if (!empty($posts)): |
|
2665 | + foreach ($posts as $post_obj) { |
|
2666 | 2666 | |
2667 | - $lat = $post_obj->post_latitude; |
|
2668 | - $lng = $post_obj->post_longitude; |
|
2667 | + $lat = $post_obj->post_latitude; |
|
2668 | + $lng = $post_obj->post_longitude; |
|
2669 | 2669 | |
2670 | - $json = '{'; |
|
2671 | - $json .= '"id":"' . $post_obj->post_id . '",'; |
|
2672 | - $json .= '"lat_pos": "' . $lat . '",'; |
|
2673 | - $json .= '"long_pos": "' . $lng . '",'; |
|
2674 | - $json .= '"marker_id":"' . $post_obj->post_id . '_' . $term_id . '",'; |
|
2675 | - $json .= '"icon":"' . $term_icon . '",'; |
|
2676 | - $json .= '"group":"catgroup' . $term_id . '"'; |
|
2677 | - $json .= '}'; |
|
2670 | + $json = '{'; |
|
2671 | + $json .= '"id":"' . $post_obj->post_id . '",'; |
|
2672 | + $json .= '"lat_pos": "' . $lat . '",'; |
|
2673 | + $json .= '"long_pos": "' . $lng . '",'; |
|
2674 | + $json .= '"marker_id":"' . $post_obj->post_id . '_' . $term_id . '",'; |
|
2675 | + $json .= '"icon":"' . $term_icon . '",'; |
|
2676 | + $json .= '"group":"catgroup' . $term_id . '"'; |
|
2677 | + $json .= '}'; |
|
2678 | 2678 | |
2679 | - if ($post_obj->default_category == $term_id) { |
|
2679 | + if ($post_obj->default_category == $term_id) { |
|
2680 | 2680 | |
2681 | - $wpdb->query( |
|
2682 | - $wpdb->prepare( |
|
2683 | - "UPDATE " . $table . " SET marker_json = %s where post_id = %d", |
|
2684 | - array($json, $post_obj->post_id) |
|
2685 | - ) |
|
2686 | - ); |
|
2687 | - } |
|
2681 | + $wpdb->query( |
|
2682 | + $wpdb->prepare( |
|
2683 | + "UPDATE " . $table . " SET marker_json = %s where post_id = %d", |
|
2684 | + array($json, $post_obj->post_id) |
|
2685 | + ) |
|
2686 | + ); |
|
2687 | + } |
|
2688 | 2688 | |
2689 | - $wpdb->query( |
|
2690 | - $wpdb->prepare( |
|
2691 | - "UPDATE " . GEODIR_ICON_TABLE . " SET json = %s WHERE post_id = %d AND cat_id = %d", |
|
2692 | - array($json, $post_obj->post_id, $term_id) |
|
2693 | - ) |
|
2694 | - ); |
|
2689 | + $wpdb->query( |
|
2690 | + $wpdb->prepare( |
|
2691 | + "UPDATE " . GEODIR_ICON_TABLE . " SET json = %s WHERE post_id = %d AND cat_id = %d", |
|
2692 | + array($json, $post_obj->post_id, $term_id) |
|
2693 | + ) |
|
2694 | + ); |
|
2695 | 2695 | |
2696 | - } |
|
2696 | + } |
|
2697 | 2697 | |
2698 | 2698 | |
2699 | - endif; |
|
2699 | + endif; |
|
2700 | 2700 | |
2701 | - } |
|
2701 | + } |
|
2702 | 2702 | |
2703 | 2703 | } |
2704 | 2704 | |
@@ -2712,14 +2712,14 @@ discard block |
||
2712 | 2712 | */ |
2713 | 2713 | function geodir_get_listing_author($listing_id = '') |
2714 | 2714 | { |
2715 | - if ($listing_id == '') { |
|
2716 | - if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { |
|
2717 | - $listing_id = $_REQUEST['pid']; |
|
2718 | - } |
|
2719 | - } |
|
2720 | - $listing = get_post(strip_tags($listing_id)); |
|
2721 | - $listing_author_id = $listing->post_author; |
|
2722 | - return $listing_author_id; |
|
2715 | + if ($listing_id == '') { |
|
2716 | + if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { |
|
2717 | + $listing_id = $_REQUEST['pid']; |
|
2718 | + } |
|
2719 | + } |
|
2720 | + $listing = get_post(strip_tags($listing_id)); |
|
2721 | + $listing_author_id = $listing->post_author; |
|
2722 | + return $listing_author_id; |
|
2723 | 2723 | } |
2724 | 2724 | |
2725 | 2725 | |
@@ -2734,11 +2734,11 @@ discard block |
||
2734 | 2734 | */ |
2735 | 2735 | function geodir_lisiting_belong_to_user($listing_id, $user_id) |
2736 | 2736 | { |
2737 | - $listing_author_id = geodir_get_listing_author($listing_id); |
|
2738 | - if ($listing_author_id == $user_id) |
|
2739 | - return true; |
|
2740 | - else |
|
2741 | - return false; |
|
2737 | + $listing_author_id = geodir_get_listing_author($listing_id); |
|
2738 | + if ($listing_author_id == $user_id) |
|
2739 | + return true; |
|
2740 | + else |
|
2741 | + return false; |
|
2742 | 2742 | |
2743 | 2743 | } |
2744 | 2744 | |
@@ -2754,17 +2754,17 @@ discard block |
||
2754 | 2754 | */ |
2755 | 2755 | function geodir_listing_belong_to_current_user($listing_id = '', $exclude_admin = true) |
2756 | 2756 | { |
2757 | - global $current_user; |
|
2758 | - if ($exclude_admin) { |
|
2759 | - foreach ($current_user->caps as $key => $caps) { |
|
2760 | - if (geodir_strtolower($key) == 'administrator') { |
|
2761 | - return true; |
|
2762 | - break; |
|
2763 | - } |
|
2764 | - } |
|
2765 | - } |
|
2766 | - |
|
2767 | - return geodir_lisiting_belong_to_user($listing_id, $current_user->ID); |
|
2757 | + global $current_user; |
|
2758 | + if ($exclude_admin) { |
|
2759 | + foreach ($current_user->caps as $key => $caps) { |
|
2760 | + if (geodir_strtolower($key) == 'administrator') { |
|
2761 | + return true; |
|
2762 | + break; |
|
2763 | + } |
|
2764 | + } |
|
2765 | + } |
|
2766 | + |
|
2767 | + return geodir_lisiting_belong_to_user($listing_id, $current_user->ID); |
|
2768 | 2768 | } |
2769 | 2769 | |
2770 | 2770 | |
@@ -2780,17 +2780,17 @@ discard block |
||
2780 | 2780 | function geodir_only_supportable_attachments_remove($file) |
2781 | 2781 | { |
2782 | 2782 | |
2783 | - global $wpdb; |
|
2783 | + global $wpdb; |
|
2784 | 2784 | |
2785 | - $matches = array(); |
|
2785 | + $matches = array(); |
|
2786 | 2786 | |
2787 | - $pattern = '/-\d+x\d+\./'; |
|
2788 | - preg_match($pattern, $file, $matches, PREG_OFFSET_CAPTURE); |
|
2787 | + $pattern = '/-\d+x\d+\./'; |
|
2788 | + preg_match($pattern, $file, $matches, PREG_OFFSET_CAPTURE); |
|
2789 | 2789 | |
2790 | - if (empty($matches)) |
|
2791 | - return ''; |
|
2792 | - else |
|
2793 | - return $file; |
|
2790 | + if (empty($matches)) |
|
2791 | + return ''; |
|
2792 | + else |
|
2793 | + return $file; |
|
2794 | 2794 | |
2795 | 2795 | } |
2796 | 2796 | |
@@ -2807,78 +2807,78 @@ discard block |
||
2807 | 2807 | function geodir_set_wp_featured_image($post_id) |
2808 | 2808 | { |
2809 | 2809 | |
2810 | - global $wpdb, $plugin_prefix; |
|
2811 | - $uploads = wp_upload_dir(); |
|
2810 | + global $wpdb, $plugin_prefix; |
|
2811 | + $uploads = wp_upload_dir(); |
|
2812 | 2812 | // print_r($uploads ) ; |
2813 | - $post_first_image = $wpdb->get_results( |
|
2814 | - $wpdb->prepare( |
|
2815 | - "SELECT * FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id = %d and menu_order = 1 ", array($post_id) |
|
2816 | - ) |
|
2817 | - ); |
|
2818 | - |
|
2819 | - $old_attachment_name = ''; |
|
2820 | - $post_thumbnail_id = ''; |
|
2821 | - if (has_post_thumbnail($post_id)) { |
|
2813 | + $post_first_image = $wpdb->get_results( |
|
2814 | + $wpdb->prepare( |
|
2815 | + "SELECT * FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id = %d and menu_order = 1 ", array($post_id) |
|
2816 | + ) |
|
2817 | + ); |
|
2822 | 2818 | |
2823 | - if (has_post_thumbnail($post_id)) { |
|
2819 | + $old_attachment_name = ''; |
|
2820 | + $post_thumbnail_id = ''; |
|
2821 | + if (has_post_thumbnail($post_id)) { |
|
2824 | 2822 | |
2825 | - $post_thumbnail_id = get_post_thumbnail_id($post_id); |
|
2823 | + if (has_post_thumbnail($post_id)) { |
|
2826 | 2824 | |
2827 | - $old_attachment_name = basename(get_attached_file($post_thumbnail_id)); |
|
2825 | + $post_thumbnail_id = get_post_thumbnail_id($post_id); |
|
2828 | 2826 | |
2829 | - } |
|
2830 | - } |
|
2827 | + $old_attachment_name = basename(get_attached_file($post_thumbnail_id)); |
|
2831 | 2828 | |
2832 | - if (!empty($post_first_image)) { |
|
2829 | + } |
|
2830 | + } |
|
2833 | 2831 | |
2834 | - $post_type = get_post_type($post_id); |
|
2832 | + if (!empty($post_first_image)) { |
|
2835 | 2833 | |
2836 | - $table_name = $plugin_prefix . $post_type . '_detail'; |
|
2834 | + $post_type = get_post_type($post_id); |
|
2837 | 2835 | |
2838 | - $wpdb->query("UPDATE " . $table_name . " SET featured_image='" . $post_first_image[0]->file . "' WHERE post_id =" . $post_id); |
|
2836 | + $table_name = $plugin_prefix . $post_type . '_detail'; |
|
2839 | 2837 | |
2840 | - $new_attachment_name = basename($post_first_image[0]->file); |
|
2838 | + $wpdb->query("UPDATE " . $table_name . " SET featured_image='" . $post_first_image[0]->file . "' WHERE post_id =" . $post_id); |
|
2841 | 2839 | |
2842 | - if (geodir_strtolower($new_attachment_name) != geodir_strtolower($old_attachment_name)) { |
|
2840 | + $new_attachment_name = basename($post_first_image[0]->file); |
|
2843 | 2841 | |
2844 | - if (has_post_thumbnail($post_id) && $post_thumbnail_id != '' && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'delete')) { |
|
2842 | + if (geodir_strtolower($new_attachment_name) != geodir_strtolower($old_attachment_name)) { |
|
2845 | 2843 | |
2846 | - add_filter('wp_delete_file', 'geodir_only_supportable_attachments_remove'); |
|
2844 | + if (has_post_thumbnail($post_id) && $post_thumbnail_id != '' && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'delete')) { |
|
2847 | 2845 | |
2848 | - wp_delete_attachment($post_thumbnail_id); |
|
2846 | + add_filter('wp_delete_file', 'geodir_only_supportable_attachments_remove'); |
|
2849 | 2847 | |
2850 | - } |
|
2851 | - $filename = $uploads['basedir'] . $post_first_image[0]->file; |
|
2848 | + wp_delete_attachment($post_thumbnail_id); |
|
2852 | 2849 | |
2853 | - $attachment = array( |
|
2854 | - 'post_mime_type' => $post_first_image[0]->mime_type, |
|
2855 | - 'guid' => $uploads['baseurl'] . $post_first_image[0]->file, |
|
2856 | - 'post_parent' => $post_id, |
|
2857 | - 'post_title' => preg_replace('/\.[^.]+$/', '', $post_first_image[0]->title), |
|
2858 | - 'post_content' => '' |
|
2859 | - ); |
|
2850 | + } |
|
2851 | + $filename = $uploads['basedir'] . $post_first_image[0]->file; |
|
2852 | + |
|
2853 | + $attachment = array( |
|
2854 | + 'post_mime_type' => $post_first_image[0]->mime_type, |
|
2855 | + 'guid' => $uploads['baseurl'] . $post_first_image[0]->file, |
|
2856 | + 'post_parent' => $post_id, |
|
2857 | + 'post_title' => preg_replace('/\.[^.]+$/', '', $post_first_image[0]->title), |
|
2858 | + 'post_content' => '' |
|
2859 | + ); |
|
2860 | 2860 | |
2861 | 2861 | |
2862 | - $id = wp_insert_attachment($attachment, $filename, $post_id); |
|
2862 | + $id = wp_insert_attachment($attachment, $filename, $post_id); |
|
2863 | 2863 | |
2864 | - if (!is_wp_error($id)) { |
|
2864 | + if (!is_wp_error($id)) { |
|
2865 | 2865 | |
2866 | - set_post_thumbnail($post_id, $id); |
|
2866 | + set_post_thumbnail($post_id, $id); |
|
2867 | 2867 | |
2868 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
2869 | - wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $filename)); |
|
2868 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
2869 | + wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $filename)); |
|
2870 | 2870 | |
2871 | - } |
|
2871 | + } |
|
2872 | 2872 | |
2873 | - } |
|
2873 | + } |
|
2874 | 2874 | |
2875 | - } else { |
|
2876 | - //set_post_thumbnail($post_id,-1); |
|
2875 | + } else { |
|
2876 | + //set_post_thumbnail($post_id,-1); |
|
2877 | 2877 | |
2878 | - if (has_post_thumbnail($post_id) && $post_thumbnail_id != '' && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'delete')) |
|
2879 | - wp_delete_attachment($post_thumbnail_id); |
|
2878 | + if (has_post_thumbnail($post_id) && $post_thumbnail_id != '' && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'delete')) |
|
2879 | + wp_delete_attachment($post_thumbnail_id); |
|
2880 | 2880 | |
2881 | - } |
|
2881 | + } |
|
2882 | 2882 | } |
2883 | 2883 | |
2884 | 2884 | |
@@ -2893,53 +2893,53 @@ discard block |
||
2893 | 2893 | */ |
2894 | 2894 | function gd_copy_original_translation() |
2895 | 2895 | { |
2896 | - if (function_exists('icl_object_id')) { |
|
2897 | - global $wpdb, $table_prefix, $plugin_prefix; |
|
2898 | - $post_id = absint($_POST['post_id']); |
|
2899 | - $upload_dir = wp_upload_dir(); |
|
2900 | - $post_type = get_post_type($_POST['post_id']); |
|
2901 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
2902 | - |
|
2903 | - $post_arr = $wpdb->get_results($wpdb->prepare( |
|
2904 | - "SELECT * FROM $wpdb->posts p JOIN " . $table . " gd ON gd.post_id=p.ID WHERE p.ID=%d LIMIT 1", |
|
2905 | - array($post_id) |
|
2906 | - ) |
|
2907 | - , ARRAY_A); |
|
2908 | - |
|
2909 | - $arrImages = $wpdb->get_results( |
|
2910 | - $wpdb->prepare( |
|
2911 | - "SELECT * FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE mime_type like %s AND post_id = %d ORDER BY menu_order ASC, ID DESC ", |
|
2912 | - array('%image%', $post_id) |
|
2913 | - ) |
|
2914 | - ); |
|
2915 | - if ($arrImages) { |
|
2916 | - $image_arr = array(); |
|
2917 | - foreach ($arrImages as $img) { |
|
2918 | - $image_arr[] = $upload_dir['baseurl'] . $img->file; |
|
2919 | - } |
|
2920 | - $comma_separated = implode(",", $image_arr); |
|
2921 | - $post_arr[0]['post_images'] = $comma_separated; |
|
2922 | - } |
|
2923 | - |
|
2924 | - |
|
2925 | - $cats = $post_arr[0][$post_arr[0]['post_type'] . 'category']; |
|
2926 | - $cat_arr = array_filter(explode(",", $cats)); |
|
2927 | - $trans_cat = array(); |
|
2928 | - foreach ($cat_arr as $cat) { |
|
2929 | - $trans_cat[] = icl_object_id($cat, $post_arr[0]['post_type'] . 'category', false); |
|
2930 | - } |
|
2931 | - |
|
2932 | - |
|
2933 | - $post_arr[0]['categories'] = array_filter($trans_cat); |
|
2896 | + if (function_exists('icl_object_id')) { |
|
2897 | + global $wpdb, $table_prefix, $plugin_prefix; |
|
2898 | + $post_id = absint($_POST['post_id']); |
|
2899 | + $upload_dir = wp_upload_dir(); |
|
2900 | + $post_type = get_post_type($_POST['post_id']); |
|
2901 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
2902 | + |
|
2903 | + $post_arr = $wpdb->get_results($wpdb->prepare( |
|
2904 | + "SELECT * FROM $wpdb->posts p JOIN " . $table . " gd ON gd.post_id=p.ID WHERE p.ID=%d LIMIT 1", |
|
2905 | + array($post_id) |
|
2906 | + ) |
|
2907 | + , ARRAY_A); |
|
2908 | + |
|
2909 | + $arrImages = $wpdb->get_results( |
|
2910 | + $wpdb->prepare( |
|
2911 | + "SELECT * FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE mime_type like %s AND post_id = %d ORDER BY menu_order ASC, ID DESC ", |
|
2912 | + array('%image%', $post_id) |
|
2913 | + ) |
|
2914 | + ); |
|
2915 | + if ($arrImages) { |
|
2916 | + $image_arr = array(); |
|
2917 | + foreach ($arrImages as $img) { |
|
2918 | + $image_arr[] = $upload_dir['baseurl'] . $img->file; |
|
2919 | + } |
|
2920 | + $comma_separated = implode(",", $image_arr); |
|
2921 | + $post_arr[0]['post_images'] = $comma_separated; |
|
2922 | + } |
|
2923 | + |
|
2924 | + |
|
2925 | + $cats = $post_arr[0][$post_arr[0]['post_type'] . 'category']; |
|
2926 | + $cat_arr = array_filter(explode(",", $cats)); |
|
2927 | + $trans_cat = array(); |
|
2928 | + foreach ($cat_arr as $cat) { |
|
2929 | + $trans_cat[] = icl_object_id($cat, $post_arr[0]['post_type'] . 'category', false); |
|
2930 | + } |
|
2931 | + |
|
2932 | + |
|
2933 | + $post_arr[0]['categories'] = array_filter($trans_cat); |
|
2934 | 2934 | //print_r($image_arr); |
2935 | - //print_r($arrImages); |
|
2936 | - //echo $_REQUEST['lang']; |
|
2935 | + //print_r($arrImages); |
|
2936 | + //echo $_REQUEST['lang']; |
|
2937 | 2937 | //print_r($post_arr); |
2938 | 2938 | //print_r($trans_cat); |
2939 | - echo json_encode($post_arr[0]); |
|
2939 | + echo json_encode($post_arr[0]); |
|
2940 | 2940 | |
2941 | - } |
|
2942 | - die(); |
|
2941 | + } |
|
2942 | + die(); |
|
2943 | 2943 | } |
2944 | 2944 | |
2945 | 2945 | |
@@ -2959,54 +2959,54 @@ discard block |
||
2959 | 2959 | function geodir_get_custom_fields_type($listing_type = '') |
2960 | 2960 | { |
2961 | 2961 | |
2962 | - global $wpdb; |
|
2962 | + global $wpdb; |
|
2963 | 2963 | |
2964 | - if ($listing_type == '') |
|
2965 | - $listing_type = 'gd_place'; |
|
2964 | + if ($listing_type == '') |
|
2965 | + $listing_type = 'gd_place'; |
|
2966 | 2966 | |
2967 | - $fields_info = array(); |
|
2967 | + $fields_info = array(); |
|
2968 | 2968 | |
2969 | - $get_data = $wpdb->get_results( |
|
2970 | - $wpdb->prepare( |
|
2971 | - "SELECT htmlvar_name, field_type, extra_fields FROM " . GEODIR_CUSTOM_FIELDS_TABLE . " WHERE post_type=%s AND is_active='1'", |
|
2972 | - array($listing_type) |
|
2973 | - ) |
|
2974 | - ); |
|
2969 | + $get_data = $wpdb->get_results( |
|
2970 | + $wpdb->prepare( |
|
2971 | + "SELECT htmlvar_name, field_type, extra_fields FROM " . GEODIR_CUSTOM_FIELDS_TABLE . " WHERE post_type=%s AND is_active='1'", |
|
2972 | + array($listing_type) |
|
2973 | + ) |
|
2974 | + ); |
|
2975 | 2975 | |
2976 | - if (!empty($get_data)) { |
|
2976 | + if (!empty($get_data)) { |
|
2977 | 2977 | |
2978 | - foreach ($get_data as $data) { |
|
2978 | + foreach ($get_data as $data) { |
|
2979 | 2979 | |
2980 | - if ($data->field_type == 'address') { |
|
2980 | + if ($data->field_type == 'address') { |
|
2981 | 2981 | |
2982 | - $extra_fields = unserialize($data->extra_fields); |
|
2982 | + $extra_fields = unserialize($data->extra_fields); |
|
2983 | 2983 | |
2984 | - $prefix = $data->htmlvar_name . '_'; |
|
2984 | + $prefix = $data->htmlvar_name . '_'; |
|
2985 | 2985 | |
2986 | - $fields_info[$prefix . 'address'] = $data->field_type; |
|
2986 | + $fields_info[$prefix . 'address'] = $data->field_type; |
|
2987 | 2987 | |
2988 | - if (isset($extra_fields['show_zip']) && $extra_fields['show_zip']) |
|
2989 | - $fields_info[$prefix . 'zip'] = $data->field_type; |
|
2988 | + if (isset($extra_fields['show_zip']) && $extra_fields['show_zip']) |
|
2989 | + $fields_info[$prefix . 'zip'] = $data->field_type; |
|
2990 | 2990 | |
2991 | - } else { |
|
2991 | + } else { |
|
2992 | 2992 | |
2993 | - $fields_info[$data->htmlvar_name] = $data->field_type; |
|
2993 | + $fields_info[$data->htmlvar_name] = $data->field_type; |
|
2994 | 2994 | |
2995 | - } |
|
2995 | + } |
|
2996 | 2996 | |
2997 | - } |
|
2997 | + } |
|
2998 | 2998 | |
2999 | - } |
|
2999 | + } |
|
3000 | 3000 | |
3001 | - /** |
|
3002 | - * Filter to modify custom fields info using listing post type. |
|
3003 | - * |
|
3004 | - * @since 1.0.0 |
|
3005 | - * @package GeoDirectory |
|
3006 | - * @return array $fields_info Custom fields info. |
|
3007 | - * @param string $listing_type The listing post type. |
|
3008 | - */ |
|
3009 | - return apply_filters('geodir_get_custom_fields_type', $fields_info, $listing_type); |
|
3001 | + /** |
|
3002 | + * Filter to modify custom fields info using listing post type. |
|
3003 | + * |
|
3004 | + * @since 1.0.0 |
|
3005 | + * @package GeoDirectory |
|
3006 | + * @return array $fields_info Custom fields info. |
|
3007 | + * @param string $listing_type The listing post type. |
|
3008 | + */ |
|
3009 | + return apply_filters('geodir_get_custom_fields_type', $fields_info, $listing_type); |
|
3010 | 3010 | } |
3011 | 3011 | |
3012 | 3012 | |
@@ -3021,58 +3021,58 @@ discard block |
||
3021 | 3021 | */ |
3022 | 3022 | function geodir_function_post_updated($post_ID, $post_after, $post_before) |
3023 | 3023 | { |
3024 | - $post_type = get_post_type($post_ID); |
|
3024 | + $post_type = get_post_type($post_ID); |
|
3025 | 3025 | |
3026 | - if ($post_type != '' && in_array($post_type, geodir_get_posttypes())) { |
|
3027 | - // send notification to client when post moves from draft to publish |
|
3028 | - if (!empty($post_after->post_status) && $post_after->post_status == 'publish' && !empty($post_before->post_status) && ($post_before->post_status == 'draft' || $post_before->post_status == 'auto-draft')) { |
|
3029 | - $post_author_id = !empty($post_after->post_author) ? $post_after->post_author : NULL; |
|
3030 | - $post_author_data = get_userdata($post_author_id); |
|
3026 | + if ($post_type != '' && in_array($post_type, geodir_get_posttypes())) { |
|
3027 | + // send notification to client when post moves from draft to publish |
|
3028 | + if (!empty($post_after->post_status) && $post_after->post_status == 'publish' && !empty($post_before->post_status) && ($post_before->post_status == 'draft' || $post_before->post_status == 'auto-draft')) { |
|
3029 | + $post_author_id = !empty($post_after->post_author) ? $post_after->post_author : NULL; |
|
3030 | + $post_author_data = get_userdata($post_author_id); |
|
3031 | 3031 | |
3032 | - $to_name = geodir_get_client_name($post_author_id); |
|
3032 | + $to_name = geodir_get_client_name($post_author_id); |
|
3033 | 3033 | |
3034 | - $from_email = geodir_get_site_email_id(); |
|
3035 | - $from_name = get_site_emailName(); |
|
3036 | - $to_email = $post_author_data->user_email; |
|
3034 | + $from_email = geodir_get_site_email_id(); |
|
3035 | + $from_name = get_site_emailName(); |
|
3036 | + $to_email = $post_author_data->user_email; |
|
3037 | 3037 | |
3038 | - if (!is_email($to_email) && !empty($post_author_data->user_email)) { |
|
3039 | - $to_email = $post_author_data->user_email; |
|
3040 | - } |
|
3038 | + if (!is_email($to_email) && !empty($post_author_data->user_email)) { |
|
3039 | + $to_email = $post_author_data->user_email; |
|
3040 | + } |
|
3041 | 3041 | |
3042 | - $message_type = 'listing_published'; |
|
3042 | + $message_type = 'listing_published'; |
|
3043 | 3043 | |
3044 | - if (get_option('geodir_post_published_email_subject') == '') { |
|
3045 | - update_option('geodir_post_published_email_subject', __('Listing Published Successfully', 'geodirectory')); |
|
3046 | - } |
|
3044 | + if (get_option('geodir_post_published_email_subject') == '') { |
|
3045 | + update_option('geodir_post_published_email_subject', __('Listing Published Successfully', 'geodirectory')); |
|
3046 | + } |
|
3047 | 3047 | |
3048 | - if (get_option('geodir_post_published_email_content') == '') { |
|
3049 | - update_option('geodir_post_published_email_content', __("<p>Dear [#client_name#],</p><p>Your listing [#listing_link#] has been published. This email is just for your information.</p><p>[#listing_link#]</p><br><p>Thank you for your contribution.</p><p>[#site_name#]</p>", 'geodirectory')); |
|
3050 | - } |
|
3048 | + if (get_option('geodir_post_published_email_content') == '') { |
|
3049 | + update_option('geodir_post_published_email_content', __("<p>Dear [#client_name#],</p><p>Your listing [#listing_link#] has been published. This email is just for your information.</p><p>[#listing_link#]</p><br><p>Thank you for your contribution.</p><p>[#site_name#]</p>", 'geodirectory')); |
|
3050 | + } |
|
3051 | 3051 | |
3052 | - /** |
|
3053 | - * Called before sending the email when listing gets published. |
|
3054 | - * |
|
3055 | - * @since 1.0.0 |
|
3056 | - * @package GeoDirectory |
|
3057 | - * @param object $post_after The post object after update. |
|
3058 | - * @param object $post_before The post object before update. |
|
3059 | - */ |
|
3060 | - do_action('geodir_before_listing_published_email', $post_after, $post_before); |
|
3061 | - if (is_email($to_email)) { |
|
3062 | - geodir_sendEmail($from_email, $from_name, $to_email, $to_name, '', '', '', $message_type, $post_ID); |
|
3063 | - } |
|
3052 | + /** |
|
3053 | + * Called before sending the email when listing gets published. |
|
3054 | + * |
|
3055 | + * @since 1.0.0 |
|
3056 | + * @package GeoDirectory |
|
3057 | + * @param object $post_after The post object after update. |
|
3058 | + * @param object $post_before The post object before update. |
|
3059 | + */ |
|
3060 | + do_action('geodir_before_listing_published_email', $post_after, $post_before); |
|
3061 | + if (is_email($to_email)) { |
|
3062 | + geodir_sendEmail($from_email, $from_name, $to_email, $to_name, '', '', '', $message_type, $post_ID); |
|
3063 | + } |
|
3064 | 3064 | |
3065 | - /** |
|
3066 | - * Called after sending the email when listing gets published. |
|
3067 | - * |
|
3068 | - * @since 1.0.0 |
|
3069 | - * @package GeoDirectory |
|
3070 | - * @param object $post_after The post object after update. |
|
3071 | - * @param object $post_before The post object before update. |
|
3072 | - */ |
|
3073 | - do_action('geodir_after_listing_published_email', $post_after, $post_before); |
|
3074 | - } |
|
3075 | - } |
|
3065 | + /** |
|
3066 | + * Called after sending the email when listing gets published. |
|
3067 | + * |
|
3068 | + * @since 1.0.0 |
|
3069 | + * @package GeoDirectory |
|
3070 | + * @param object $post_after The post object after update. |
|
3071 | + * @param object $post_before The post object before update. |
|
3072 | + */ |
|
3073 | + do_action('geodir_after_listing_published_email', $post_after, $post_before); |
|
3074 | + } |
|
3075 | + } |
|
3076 | 3076 | } |
3077 | 3077 | |
3078 | 3078 | add_action('wp_head', 'geodir_fb_like_thumbnail'); |
@@ -3086,14 +3086,14 @@ discard block |
||
3086 | 3086 | */ |
3087 | 3087 | function geodir_fb_like_thumbnail(){ |
3088 | 3088 | |
3089 | - // return if not a single post |
|
3090 | - if(!is_single()){return;} |
|
3089 | + // return if not a single post |
|
3090 | + if(!is_single()){return;} |
|
3091 | 3091 | |
3092 | - global $post; |
|
3093 | - if(isset($post->featured_image) && $post->featured_image){ |
|
3094 | - $upload_dir = wp_upload_dir(); |
|
3095 | - $thumb = $upload_dir['baseurl'].$post->featured_image; |
|
3096 | - echo "\n\n<!-- GD Facebook Like Thumbnail -->\n<link rel=\"image_src\" href=\"$thumb\" />\n<!-- End GD Facebook Like Thumbnail -->\n\n"; |
|
3092 | + global $post; |
|
3093 | + if(isset($post->featured_image) && $post->featured_image){ |
|
3094 | + $upload_dir = wp_upload_dir(); |
|
3095 | + $thumb = $upload_dir['baseurl'].$post->featured_image; |
|
3096 | + echo "\n\n<!-- GD Facebook Like Thumbnail -->\n<link rel=\"image_src\" href=\"$thumb\" />\n<!-- End GD Facebook Like Thumbnail -->\n\n"; |
|
3097 | 3097 | |
3098 | - } |
|
3098 | + } |
|
3099 | 3099 | } |
3100 | 3100 | \ No newline at end of file |