|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Shortcode functions. |
|
4
|
|
|
* |
|
5
|
|
|
* @since 1.0.0 |
|
6
|
|
|
* @package GeoDirectory |
|
7
|
|
|
*/ |
|
8
|
|
|
// If this file is called directly, abort. |
|
9
|
|
|
if (!defined('WPINC')) { |
|
10
|
|
|
die; |
|
11
|
|
|
} |
|
12
|
|
|
require_once('geodirectory-functions/shortcode_functions.php'); |
|
13
|
|
|
|
|
14
|
|
|
add_shortcode('gd_add_listing', 'geodir_sc_add_listing'); |
|
15
|
|
|
/** |
|
16
|
|
|
* The geodirectory add listing shortcode. |
|
17
|
|
|
* |
|
18
|
|
|
* This implements the functionality of the shortcode for displaying geodirectory add listing page form. |
|
19
|
|
|
* |
|
20
|
|
|
* @since 1.0.0 |
|
21
|
|
|
* @package GeoDirectory |
|
22
|
|
|
* @param array $atts { |
|
23
|
|
|
* Attributes of the shortcode. |
|
24
|
|
|
* |
|
25
|
|
|
* @type string $pid Post ID. If passed post will be edited. Default empty. |
|
26
|
|
|
* @type string $listing_type Post type of listing. Default gd_place. |
|
27
|
|
|
* @type string $login_msg Message to display when user not logged in. |
|
28
|
|
|
* @type bool $show_login Do you want to display login widget when user not logged in?. Default: false. |
|
29
|
|
|
* |
|
30
|
|
|
* } |
|
31
|
|
|
* @return string Add listing page HTML. |
|
32
|
|
|
*/ |
|
33
|
|
|
function geodir_sc_add_listing($atts) |
|
34
|
|
|
{ |
|
35
|
|
|
ob_start(); |
|
36
|
|
|
$defaults = array( |
|
37
|
|
|
'pid' => '', |
|
38
|
|
|
'listing_type' => 'gd_place', |
|
39
|
|
|
'login_msg' => __('You must login to post.', 'geodirectory'), |
|
40
|
|
|
'show_login' => false, |
|
41
|
|
|
); |
|
42
|
|
|
$params = shortcode_atts($defaults, $atts); |
|
43
|
|
|
|
|
44
|
|
|
foreach ($params as $key => $value) { |
|
45
|
|
|
$_REQUEST[$key] = $value; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$user_id = get_current_user_id(); |
|
49
|
|
|
if (!$user_id) { |
|
50
|
|
|
echo $params['login_msg']; |
|
51
|
|
|
if ($params['show_login']) { |
|
52
|
|
|
echo "<br />"; |
|
53
|
|
|
$defaults = array( |
|
54
|
|
|
'before_widget' => '', |
|
55
|
|
|
'after_widget' => '', |
|
56
|
|
|
'before_title' => '', |
|
57
|
|
|
'after_title' => '', |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
geodir_loginwidget_output($defaults, $defaults); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
} else { |
|
65
|
|
|
// Add listing page will be used if shortcode is detected in page content, no need to call it here |
|
66
|
|
|
} |
|
67
|
|
|
$output = ob_get_contents(); |
|
68
|
|
|
|
|
69
|
|
|
ob_end_clean(); |
|
70
|
|
|
|
|
71
|
|
|
return $output; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* The geodirectory home page map shortcode. |
|
76
|
|
|
* |
|
77
|
|
|
* This implements the functionality of the shortcode for displaying map on home page. |
|
78
|
|
|
* |
|
79
|
|
|
* @since 1.0.0 |
|
80
|
|
|
* @since 1.5.2 Added TERRAIN map type. |
|
81
|
|
|
* @package GeoDirectory |
|
82
|
|
|
* @param array $atts { |
|
83
|
|
|
* Attributes of the shortcode. |
|
84
|
|
|
* |
|
85
|
|
|
* @type string $width Map width in pixels. Default 960. |
|
86
|
|
|
* @type string $height Map height in pixels. Default 425. |
|
87
|
|
|
* @type string $maptype Map type. Default ROADMAP. Can be ROADMAP | SATELLITE | HYBRID | TERRAIN. |
|
88
|
|
|
* @type string $zoom The zoom level of the map. Between 1-19. Default 13. |
|
89
|
|
|
* @type string $autozoom True if the map should autozoom, false if not. |
|
90
|
|
|
* @type string $child_collapse True if the map should collapse the categories, false if not. |
|
91
|
|
|
* @type string $scrollwheel True to allow scroll wheel to scroll map or false if not. |
|
92
|
|
|
* @type bool $marker_cluster Enable marker cluster? Default: false. |
|
93
|
|
|
* |
|
94
|
|
|
* } |
|
95
|
|
|
* @return string Map HTML. |
|
96
|
|
|
*/ |
|
97
|
|
|
function geodir_sc_home_map($atts) |
|
98
|
|
|
{ |
|
99
|
1 |
|
ob_start(); |
|
100
|
|
|
$defaults = array( |
|
101
|
1 |
|
'width' => '960', |
|
102
|
1 |
|
'height' => '425', |
|
103
|
1 |
|
'maptype' => 'ROADMAP', |
|
104
|
1 |
|
'zoom' => '13', |
|
105
|
1 |
|
'autozoom' => '', |
|
106
|
1 |
|
'child_collapse' => '0', |
|
107
|
1 |
|
'scrollwheel' => '0', |
|
108
|
1 |
|
'marker_cluster' => false, |
|
109
|
1 |
|
'latitude' => '', |
|
110
|
|
|
'longitude' => '' |
|
111
|
1 |
|
); |
|
112
|
|
|
|
|
113
|
1 |
|
$params = shortcode_atts($defaults, $atts); |
|
114
|
|
|
|
|
115
|
1 |
|
$params = gdsc_validate_map_args($params); |
|
116
|
|
|
|
|
117
|
|
|
$map_args = array( |
|
118
|
1 |
|
'map_canvas_name' => 'gd_home_map', |
|
119
|
1 |
|
'latitude' => $params['latitude'], |
|
120
|
1 |
|
'longitude' => $params['longitude'], |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Filter the widget width of the map on home/listings page. |
|
124
|
|
|
* |
|
125
|
|
|
* @since 1.0.0 |
|
126
|
|
|
* @param mixed(string|int|float) $params['width'] The map width. |
|
127
|
|
|
*/ |
|
128
|
1 |
|
'width' => apply_filters('widget_width', $params['width']), |
|
129
|
|
|
/** |
|
130
|
|
|
* Filter the widget height of the map on home/listings page. |
|
131
|
|
|
* |
|
132
|
|
|
* @since 1.0.0 |
|
133
|
|
|
* @param mixed(string|int|float) $params['height'] The map height. |
|
134
|
|
|
*/ |
|
135
|
1 |
|
'height' => apply_filters('widget_heigh', $params['height']), |
|
136
|
|
|
/** |
|
137
|
|
|
* Filter the widget maptype of the map on home/listings page. |
|
138
|
|
|
* |
|
139
|
|
|
* @since 1.0.0 |
|
140
|
|
|
* @since 1.5.2 Added TERRAIN map type. |
|
141
|
|
|
* @param string $params['maptype'] The map type. Can be ROADMAP | SATELLITE | HYBRID | TERRAIN. |
|
142
|
|
|
*/ |
|
143
|
1 |
|
'maptype' => apply_filters('widget_maptype', $params['maptype']), |
|
144
|
|
|
/** |
|
145
|
|
|
* Filter the widget scrollwheel value of the map on home/listings page. |
|
146
|
|
|
* |
|
147
|
|
|
* Should the scrollwheel zoom the map or not. |
|
148
|
|
|
* |
|
149
|
|
|
* @since 1.0.0 |
|
150
|
|
|
* @param bool $params['scrollwheel'] True to allow scroll wheel to scroll map or false if not. |
|
151
|
|
|
*/ |
|
152
|
1 |
|
'scrollwheel' => apply_filters('widget_scrollwheel', $params['scrollwheel']), |
|
153
|
|
|
/** |
|
154
|
|
|
* Filter the widget zoom level of the map on home/listings page. |
|
155
|
|
|
* |
|
156
|
|
|
* @since 1.0.0 |
|
157
|
|
|
* @param int $params['zoom'] The zoom level of the map. Between 1-19. |
|
158
|
|
|
*/ |
|
159
|
1 |
|
'zoom' => apply_filters('widget_zoom', $params['zoom']), |
|
160
|
|
|
/** |
|
161
|
|
|
* Filter the widget auto zoom value of the map on home/listings page. |
|
162
|
|
|
* |
|
163
|
|
|
* If the map should autozoom to fit the markers shown. |
|
164
|
|
|
* |
|
165
|
|
|
* @since 1.0.0 |
|
166
|
|
|
* @param bool $params['autozoom'] True if the map should autozoom, false if not. |
|
167
|
|
|
*/ |
|
168
|
1 |
|
'autozoom' => apply_filters('widget_autozoom', $params['autozoom']), |
|
169
|
|
|
/** |
|
170
|
|
|
* Filter the widget child_collapse value of the map on home/listings page. |
|
171
|
|
|
* |
|
172
|
|
|
* If the map should auto collapse the child categories if the category bar is present. |
|
173
|
|
|
* |
|
174
|
|
|
* @since 1.0.0 |
|
175
|
|
|
* @param bool $params['child_collapse'] True if the map should collapse the categories, false if not. |
|
176
|
|
|
*/ |
|
177
|
1 |
|
'child_collapse' => apply_filters('widget_child_collapse', $params['child_collapse']), |
|
178
|
1 |
|
'enable_cat_filters' => true, |
|
179
|
1 |
|
'enable_text_search' => true, |
|
180
|
1 |
|
'enable_post_type_filters' => true, |
|
181
|
|
|
/** |
|
182
|
|
|
* Filter the widget enable_location_filters value of the map on home/listings page. |
|
183
|
|
|
* |
|
184
|
|
|
* This is used when the location addon is used. |
|
185
|
|
|
* |
|
186
|
|
|
* @since 1.0.0 |
|
187
|
|
|
* @param bool $val True if location filters should be used, false if not. |
|
188
|
|
|
*/ |
|
189
|
1 |
|
'enable_location_filters' => apply_filters('geodir_home_map_enable_location_filters', false), |
|
190
|
1 |
|
'enable_jason_on_load' => false, |
|
191
|
1 |
|
'enable_marker_cluster' => false, |
|
192
|
1 |
|
'enable_map_resize_button' => true, |
|
193
|
1 |
|
'map_class_name' => 'geodir-map-home-page', |
|
194
|
1 |
|
'is_geodir_home_map_widget' => true, |
|
195
|
1 |
|
); |
|
196
|
|
|
|
|
197
|
|
|
// Add marker cluster |
|
198
|
1 |
|
if (isset($params['marker_cluster']) && gdsc_to_bool_val($params['marker_cluster']) && defined('GDCLUSTER_VERSION')) { |
|
199
|
|
|
$map_args['enable_marker_cluster'] = true; |
|
200
|
|
|
if(get_option('geodir_marker_cluster_type')) { |
|
201
|
|
|
if ($map_args['autozoom']) { |
|
202
|
|
|
$map_args['enable_marker_cluster_no_reposition'] = false; |
|
203
|
|
|
} else { |
|
204
|
|
|
$map_args['enable_marker_cluster_no_reposition'] = true; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
$map_args['enable_marker_cluster_server'] = true ; |
|
208
|
|
|
|
|
209
|
|
|
} |
|
210
|
|
|
} else { |
|
211
|
1 |
|
$map_args['enable_marker_cluster'] = false; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
// if lat and long set in shortcode, hack it so the map is not repositioned |
|
215
|
1 |
|
if(!empty($params['latitude']) && !empty($params['longitude']) ){ |
|
216
|
|
|
$map_args['enable_marker_cluster_no_reposition'] = true; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
|
|
220
|
1 |
|
geodir_draw_map($map_args); |
|
221
|
|
|
|
|
222
|
1 |
|
add_action('wp_footer', 'geodir_home_map_add_script', 100); |
|
223
|
|
|
|
|
224
|
1 |
|
$output = ob_get_contents(); |
|
225
|
|
|
|
|
226
|
1 |
|
ob_end_clean(); |
|
227
|
|
|
|
|
228
|
1 |
|
return $output; |
|
229
|
|
|
} |
|
230
|
|
|
add_shortcode('gd_homepage_map', 'geodir_sc_home_map'); |
|
231
|
|
|
|
|
232
|
|
|
add_shortcode('gd_listing_map', 'geodir_sc_listing_map'); |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* The geodirectory listing map shortcode. |
|
236
|
|
|
* |
|
237
|
|
|
* This implements the functionality of the shortcode for displaying listing map. |
|
238
|
|
|
* |
|
239
|
|
|
* @since 1.0.0 |
|
240
|
|
|
* @since 1.5.2 Added TERRAIN for $maptype attribute. |
|
241
|
|
|
* @since 1.6.16 CHANGED: New parameters post_type, category & event_type added. |
|
242
|
|
|
* @since 1.6.18 FIXED: For CPT other then "gd_place" not working. |
|
243
|
|
|
* @package GeoDirectory |
|
244
|
|
|
* @global object $post The current post object. |
|
245
|
|
|
* @param array $atts { |
|
246
|
|
|
* Attributes of the shortcode. |
|
247
|
|
|
* |
|
248
|
|
|
* @type string $width Map width in pixels. Default 294. |
|
249
|
|
|
* @type string $height Map height in pixels. Default 370. |
|
250
|
|
|
* @type string $maptype Map type. Default ROADMAP. Can be ROADMAP | SATELLITE | HYBRID | TERRAIN. |
|
251
|
|
|
* @type string $zoom The zoom level of the map. Between 1-19. Default 13. |
|
252
|
|
|
* @type string $autozoom True if the map should autozoom, false if not. |
|
253
|
|
|
* @type bool $sticky True if should be sticky, false if not |
|
254
|
|
|
* @type string $showall Show all listings on map? (not just page list). Default 0. |
|
255
|
|
|
* @type string $child_collapse True if the map should collapse the categories, false if not. |
|
256
|
|
|
* @type string $scrollwheel True to allow scroll wheel to scroll map or false if not. |
|
257
|
|
|
* @type bool $marker_cluster Enable marker cluster? Default: false. |
|
258
|
|
|
* @type string $post_type Post type of listing. Default. gd_place. |
|
259
|
|
|
* @type string $category Category ids to filter listings. Ex: 1,3. Default. 0. |
|
260
|
|
|
* @type string $event_type The events filter.(for gd_event CPT only) Default: all. |
|
261
|
|
|
* |
|
262
|
|
|
* } |
|
263
|
|
|
* @return string Map HTML. |
|
264
|
|
|
*/ |
|
265
|
|
|
function geodir_sc_listing_map($atts) { |
|
266
|
|
|
|
|
267
|
|
|
// if some params are set then we need a new query, if not then we can use the main query |
|
268
|
1 |
|
if( isset($atts['post_type']) || isset($atts['category']) || isset($atts['event_type']) ) { |
|
269
|
|
|
|
|
270
|
|
|
global $add_post_in_marker_array, $gd_sc_map_params; |
|
271
|
|
|
$backup_globals = array(); |
|
272
|
|
|
$backup_globals['add_post_in_marker_array'] = $add_post_in_marker_array; |
|
273
|
|
|
$backup_globals['gd_sc_map_params'] = $gd_sc_map_params; |
|
274
|
|
|
|
|
275
|
|
|
$defaults = array( |
|
276
|
|
|
'width' => '294', |
|
277
|
|
|
'height' => '370', |
|
278
|
|
|
'zoom' => '13', |
|
279
|
|
|
'autozoom' => '', |
|
280
|
|
|
'sticky' => '', |
|
281
|
|
|
'showall' => '0', |
|
282
|
|
|
'scrollwheel' => '0', |
|
283
|
|
|
'maptype' => 'ROADMAP', |
|
284
|
|
|
'child_collapse' => 0, |
|
285
|
|
|
'marker_cluster' => false, |
|
286
|
|
|
'post_type' => 'gd_place', |
|
287
|
|
|
'category' => '0', |
|
288
|
|
|
'event_type' => 'all' |
|
289
|
|
|
); |
|
290
|
|
|
|
|
291
|
|
|
$params = shortcode_atts( $defaults, $atts ); |
|
292
|
|
|
|
|
293
|
|
|
if ( ! ( gdsc_is_post_type_valid( $params['post_type'] ) ) ) { |
|
294
|
|
|
$params['post_type'] = 'gd_place'; |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
// Validate the selected category/ies - Grab the current list based on post_type |
|
298
|
|
|
$category_taxonomy = geodir_get_taxonomies( $params['post_type'] ); |
|
299
|
|
|
$categories = get_terms( $category_taxonomy, array( |
|
300
|
|
|
'orderby' => 'count', |
|
301
|
|
|
'order' => 'DESC', |
|
302
|
|
|
'fields' => 'ids' |
|
303
|
|
|
) ); |
|
304
|
|
|
|
|
305
|
|
|
// Make sure we have an array |
|
306
|
|
|
if ( ! ( is_array( $params['category'] ) ) ) { |
|
307
|
|
|
$params['category'] = explode( ',', $params['category'] ); |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
// Array_intersect returns only the items in $params['category'] that are also in our category list |
|
311
|
|
|
// Otherwise it becomes empty and later on that will mean "All" |
|
312
|
|
|
$params['category'] = array_intersect( $params['category'], $categories ); |
|
313
|
|
|
|
|
314
|
|
|
if ( $params['post_type'] == 'gd_event' ) { |
|
315
|
|
|
$params['event_type'] = gdsc_validate_list_filter_choice( $params['event_type'] ); |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
$params = gdsc_validate_map_args( $params ); |
|
319
|
|
|
|
|
320
|
|
|
$gd_sc_map_params = $params; |
|
321
|
|
|
|
|
322
|
|
|
$query_args = array( |
|
323
|
|
|
'posts_per_page' => 1000000, //@todo kiran why was this added? |
|
324
|
|
|
'is_geodir_loop' => true, |
|
325
|
|
|
'gd_location' => false, |
|
326
|
|
|
'post_type' => $params['post_type'], |
|
327
|
|
|
); |
|
328
|
|
|
|
|
329
|
|
|
if ( ! empty( $params['category'] ) && isset( $params['category'][0] ) && (int) $params['category'][0] != 0 ) { |
|
330
|
|
|
$category_taxonomy = geodir_get_taxonomies( $params['post_type'] ); |
|
331
|
|
|
|
|
332
|
|
|
######### WPML ######### |
|
333
|
|
|
if ( geodir_wpml_is_taxonomy_translated( $category_taxonomy[0] ) ) { |
|
334
|
|
|
$category = gd_lang_object_ids( $params['category'], $category_taxonomy[0] ); |
|
335
|
|
|
} |
|
336
|
|
|
######### WPML ######### |
|
337
|
|
|
|
|
338
|
|
|
$tax_query = array( |
|
339
|
|
|
'taxonomy' => $category_taxonomy[0], |
|
340
|
|
|
'field' => 'id', |
|
341
|
|
|
'terms' => $params['category'] |
|
342
|
|
|
); |
|
343
|
|
|
|
|
344
|
|
|
$query_args['tax_query'] = array( $tax_query ); |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
$add_post_in_marker_array = true; |
|
348
|
|
|
|
|
349
|
|
|
if ( $params['post_type'] == 'gd_event' && function_exists( 'geodir_event_get_widget_events' ) ) { |
|
350
|
|
|
global $geodir_event_widget_listview; |
|
351
|
|
|
$geodir_event_widget_listview = true; |
|
352
|
|
|
|
|
353
|
|
|
$query_args['geodir_event_type'] = $params['event_type']; |
|
354
|
|
|
|
|
355
|
|
|
$listings = geodir_event_get_widget_events( $query_args ); |
|
356
|
|
|
|
|
357
|
|
|
$geodir_event_widget_listview = false; |
|
358
|
|
|
} else { |
|
359
|
|
|
$listings = geodir_get_widget_listings( $query_args ); |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
if ( ! empty( $listings ) ) { |
|
363
|
|
|
foreach ( $listings as $listing ) { |
|
364
|
|
|
create_marker_jason_of_posts( $listing ); |
|
365
|
|
|
} |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
ob_start(); |
|
369
|
|
|
add_action( 'wp_head', 'init_listing_map_script' ); // Initialize the map object and marker array |
|
370
|
|
|
|
|
371
|
|
|
add_action( 'the_post', 'create_list_jsondata' ); // Add marker in json array |
|
372
|
|
|
|
|
373
|
|
|
add_action( 'wp_footer', 'show_listing_widget_map' ); // Show map for listings with markers |
|
374
|
|
|
|
|
375
|
|
|
$default_location = geodir_get_default_location(); |
|
376
|
|
|
|
|
377
|
|
|
$map_args = array( |
|
378
|
|
|
'map_canvas_name' => 'gd_listing_map', |
|
379
|
|
|
'width' => $params['width'], |
|
380
|
|
|
'height' => $params['height'], |
|
381
|
|
|
'zoom' => $params['zoom'], |
|
382
|
|
|
'autozoom' => $params['autozoom'], |
|
383
|
|
|
'sticky' => $params['sticky'], |
|
384
|
|
|
'showall' => $params['showall'], |
|
385
|
|
|
'scrollwheel' => $params['scrollwheel'], |
|
386
|
|
|
'maptype' => $params['maptype'], |
|
387
|
|
|
'child_collapse' => 0, |
|
388
|
|
|
'enable_cat_filters' => false, |
|
389
|
|
|
'enable_text_search' => false, |
|
390
|
|
|
'enable_post_type_filters' => false, |
|
391
|
|
|
'enable_location_filters' => false, |
|
392
|
|
|
'enable_jason_on_load' => true, |
|
393
|
|
|
'ajax_url' => geodir_get_ajax_url(), |
|
394
|
|
|
'latitude' => isset( $default_location->city_latitude ) ? $default_location->city_latitude : '', |
|
395
|
|
|
'longitude' => isset( $default_location->city_longitude ) ? $default_location->city_longitude : '', |
|
396
|
|
|
'streetViewControl' => true, |
|
397
|
|
|
'showPreview' => '0', |
|
398
|
|
|
'maxZoom' => 21, |
|
399
|
|
|
'bubble_size' => 'small', |
|
400
|
|
|
); |
|
401
|
|
|
|
|
402
|
|
|
if ( is_single() ) { |
|
403
|
|
|
global $post; |
|
404
|
|
|
if ( isset( $post->post_latitude ) ) { |
|
405
|
|
|
$map_args['latitude'] = $post->post_latitude; |
|
406
|
|
|
$map_args['longitude'] = $post->post_longitude; |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
$map_args['map_class_name'] = 'geodir-map-listing-page-single'; |
|
410
|
|
|
} else { |
|
411
|
|
|
$map_args['map_class_name'] = 'geodir-map-listing-page'; |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
// Add marker cluster |
|
415
|
|
|
if ( isset( $params['marker_cluster'] ) && gdsc_to_bool_val( $params['marker_cluster'] ) && defined( 'GDCLUSTER_VERSION' ) ) { |
|
416
|
|
|
$map_args['enable_marker_cluster'] = true; |
|
417
|
|
|
} else { |
|
418
|
|
|
$map_args['enable_marker_cluster'] = false; |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
geodir_draw_map( $map_args ); |
|
422
|
|
|
|
|
423
|
|
|
$output = ob_get_contents(); |
|
424
|
|
|
|
|
425
|
|
|
ob_end_clean(); |
|
426
|
|
|
|
|
427
|
|
|
foreach ( $backup_globals as $global => $value ) { |
|
428
|
|
|
${$global} = $value; |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
return $output; |
|
432
|
|
|
}else{ |
|
433
|
1 |
|
ob_start(); |
|
434
|
1 |
|
add_action('wp_head', 'init_listing_map_script'); // Initialize the map object and marker array |
|
435
|
1 |
|
add_action('the_post', 'create_list_jsondata'); // Add marker in json array |
|
436
|
1 |
|
add_action('wp_footer', 'show_listing_widget_map'); // Show map for listings with markers |
|
437
|
|
|
$defaults = array( |
|
438
|
1 |
|
'width' => '294', |
|
439
|
1 |
|
'height' => '370', |
|
440
|
1 |
|
'zoom' => '13', |
|
441
|
1 |
|
'autozoom' => '', |
|
442
|
1 |
|
'sticky' => '', |
|
443
|
1 |
|
'showall' => '0', |
|
444
|
1 |
|
'scrollwheel' => '0', |
|
445
|
1 |
|
'maptype' => 'ROADMAP', |
|
446
|
1 |
|
'child_collapse' => 0, |
|
447
|
|
|
'marker_cluster' => false |
|
448
|
1 |
|
); |
|
449
|
1 |
|
$params = shortcode_atts($defaults, $atts); |
|
450
|
1 |
|
$params = gdsc_validate_map_args($params); |
|
451
|
|
|
$map_args = array( |
|
452
|
1 |
|
'map_canvas_name' => 'gd_listing_map', |
|
453
|
1 |
|
'width' => $params['width'], |
|
454
|
1 |
|
'height' => $params['height'], |
|
455
|
1 |
|
'zoom' => $params['zoom'], |
|
456
|
1 |
|
'autozoom' => $params['autozoom'], |
|
457
|
1 |
|
'sticky' => $params['sticky'], |
|
458
|
1 |
|
'showall' => $params['showall'], |
|
459
|
1 |
|
'scrollwheel' => $params['scrollwheel'], |
|
460
|
1 |
|
'child_collapse' => 0, |
|
461
|
1 |
|
'enable_cat_filters' => false, |
|
462
|
1 |
|
'enable_text_search' => false, |
|
463
|
1 |
|
'enable_post_type_filters' => false, |
|
464
|
1 |
|
'enable_location_filters' => false, |
|
465
|
1 |
|
'enable_jason_on_load' => true, |
|
466
|
1 |
|
); |
|
467
|
1 |
|
if (is_single()) { |
|
468
|
|
|
global $post; |
|
469
|
|
|
$map_default_lat = $address_latitude = $post->post_latitude; |
|
470
|
|
|
$map_default_lng = $address_longitude = $post->post_longitude; |
|
471
|
|
|
$mapview = $post->post_mapview; |
|
472
|
|
|
$map_args['zoom'] = $post->post_mapzoom; |
|
473
|
|
|
$map_args['map_class_name'] = 'geodir-map-listing-page-single'; |
|
474
|
|
|
} else { |
|
475
|
1 |
|
$default_location = geodir_get_default_location(); |
|
476
|
1 |
|
$map_default_lat = isset($default_location->city_latitude) ? $default_location->city_latitude : ''; |
|
477
|
1 |
|
$map_default_lng = isset($default_location->city_longitude) ? $default_location->city_longitude : ''; |
|
478
|
1 |
|
$map_args['map_class_name'] = 'geodir-map-listing-page'; |
|
479
|
|
|
if ( geodir_is_page( 'search' ) ) { |
|
480
|
1 |
|
$map_default_lat = ''; |
|
481
|
1 |
|
$map_default_lng = ''; |
|
482
|
1 |
|
if ( isset( $_REQUEST['sgeo_lat'] ) && isset( $_REQUEST['sgeo_lon'] ) ) { |
|
483
|
|
|
$map_default_lat = (float)sanitize_text_field( $_REQUEST['sgeo_lat'] ); |
|
484
|
1 |
|
$map_default_lng = (float)sanitize_text_field( $_REQUEST['sgeo_lon'] ); |
|
485
|
1 |
|
} |
|
486
|
1 |
|
if ( empty( $map_default_lat ) && empty( $map_default_lng ) && ! empty( $_REQUEST['set_location_type'] ) && ! empty( $_REQUEST['set_location_val'] ) && function_exists( 'geodir_get_location_by_id' ) ) { |
|
487
|
1 |
|
$location = geodir_get_location_by_id( '', (int)$_REQUEST['set_location_val'] ); |
|
488
|
1 |
|
if ( ! empty( $location ) ) { |
|
489
|
1 |
|
$map_default_lat = $location->city_latitude; |
|
490
|
1 |
|
$map_default_lng = $location->city_longitude; |
|
491
|
1 |
|
} |
|
492
|
|
|
} |
|
493
|
|
|
} |
|
494
|
1 |
|
} |
|
495
|
|
|
if (empty($mapview)) { |
|
496
|
|
|
$mapview = 'ROADMAP'; |
|
497
|
1 |
|
} |
|
498
|
|
|
// Set default map options |
|
499
|
1 |
|
$map_args['ajax_url'] = geodir_get_ajax_url(); |
|
500
|
1 |
|
$map_args['latitude'] = $map_default_lat; |
|
501
|
1 |
|
$map_args['longitude'] = $map_default_lng; |
|
502
|
1 |
|
$map_args['streetViewControl'] = true; |
|
503
|
|
|
$map_args['maptype'] = $mapview; |
|
504
|
|
|
$map_args['showPreview'] = '0'; |
|
505
|
|
|
$map_args['maxZoom'] = 21; |
|
506
|
|
|
$map_args['bubble_size'] = 'small'; |
|
507
|
|
|
|
|
508
|
|
|
// Add marker cluster |
|
509
|
|
|
if (isset($params['marker_cluster']) && gdsc_to_bool_val($params['marker_cluster']) && defined('GDCLUSTER_VERSION')) { |
|
510
|
|
|
$map_args['enable_marker_cluster'] = true; |
|
511
|
|
|
} else { |
|
512
|
|
|
$map_args['enable_marker_cluster'] = false; |
|
513
|
|
|
} |
|
514
|
|
|
geodir_draw_map($map_args); |
|
515
|
|
|
$output = ob_get_contents(); |
|
516
|
|
|
ob_end_clean(); |
|
517
|
|
|
return $output; |
|
518
|
|
|
} |
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
|
add_shortcode('gd_listing_slider', 'geodir_sc_listing_slider'); |
|
522
|
|
|
/** |
|
523
|
|
|
* The geodirectory listing slider shortcode. |
|
524
|
|
|
* |
|
525
|
|
|
* This implements the functionality of the shortcode for displaying listing slider. |
|
526
|
|
|
* |
|
527
|
|
|
* @since 1.0.0 |
|
528
|
|
|
* @package GeoDirectory |
|
529
|
|
|
* @param array $atts { |
|
530
|
|
|
* Attributes of the shortcode. |
|
531
|
|
|
* |
|
532
|
|
|
* @type string $animation Controls the animation type, "fade" or "slide". Default. slide. |
|
533
|
|
|
* @type int $animation_loop Gives the slider a seamless infinite loop. Default. 0. |
|
534
|
|
|
* @type int $animation_speed Set the speed of animations, in milliseconds. Default. 600. |
|
535
|
|
|
* @type string $category Filter by term. Can be any valid term. Default. 0. |
|
536
|
|
|
* @type int $direction_nav Enable previous/next arrow navigation?. Can be 1 or 0. Default. 0. |
|
537
|
|
|
* @type string $order_by Order by filter. Default. latest. |
|
538
|
|
|
* @type string $post_number Number of listings to display. Default. 5. |
|
539
|
|
|
* @type string $post_type Post type of listing. Default. gd_place. |
|
540
|
|
|
* @type string $show_featured_only Do you want to display only featured listing? Can be 1 or 0. Default. Empty. |
|
541
|
|
|
* @type string $show_title Do you want to display title? Can be 1 or 0. Default. Empty. |
|
542
|
|
|
* @type string $slideshow Setup a slideshow for the slider to animate automatically. Default. 0. |
|
543
|
|
|
* @type int $slideshow_speed Set the speed of the slideshow cycling, in milliseconds. Default. 5000. |
|
544
|
|
|
* @type string $title Slider title. Default. Empty. |
|
545
|
|
|
* |
|
546
|
|
|
* } |
|
547
|
|
|
* @return string Slider HTML. |
|
548
|
|
|
*/ |
|
549
|
|
|
function geodir_sc_listing_slider($atts) |
|
550
|
|
|
{ |
|
551
|
|
|
ob_start(); |
|
552
|
|
|
$defaults = array( |
|
553
|
|
|
'post_type' => 'gd_place', |
|
554
|
|
|
'category' => '0', |
|
555
|
|
|
'post_number' => '5', |
|
556
|
|
|
'slideshow' => '0', |
|
557
|
|
|
'animation_loop' => 0, |
|
558
|
|
|
'direction_nav' => 0, |
|
559
|
|
|
'slideshow_speed' => 5000, |
|
560
|
|
|
'animation_speed' => 600, |
|
561
|
|
|
'animation' => 'slide', |
|
562
|
|
|
'order_by' => 'latest', |
|
563
|
|
|
'show_title' => '', |
|
564
|
|
|
'show_featured_only' => '', |
|
565
|
|
|
'title' => '', |
|
566
|
|
|
); |
|
567
|
|
|
|
|
568
|
|
|
$params = shortcode_atts($defaults, $atts); |
|
569
|
|
|
|
|
570
|
|
|
|
|
571
|
|
|
/* |
|
572
|
|
|
* |
|
573
|
|
|
* Now we begin the validation of the attributes. |
|
574
|
|
|
*/ |
|
575
|
|
|
// Check we have a valid post_type |
|
576
|
|
|
if (!(gdsc_is_post_type_valid($params['post_type']))) { |
|
577
|
|
|
$params['post_type'] = 'gd_place'; |
|
578
|
|
|
} |
|
579
|
|
|
|
|
580
|
|
|
// Check we have a valid sort_order |
|
581
|
|
|
$params['order_by'] = gdsc_validate_sort_choice($params['order_by']); |
|
582
|
|
|
|
|
583
|
|
|
// Match the chosen animation to our options |
|
584
|
|
|
$animation_list = array('slide', 'fade'); |
|
585
|
|
|
if (!(in_array($params['animation'], $animation_list))) { |
|
586
|
|
|
$params['animation'] = 'slide'; |
|
587
|
|
|
} |
|
588
|
|
|
|
|
589
|
|
|
// Post_number needs to be a positive integer |
|
590
|
|
|
$params['post_number'] = absint($params['post_number']); |
|
591
|
|
|
if (0 == $params['post_number']) { |
|
592
|
|
|
$params['post_number'] = 1; |
|
593
|
|
|
} |
|
594
|
|
|
|
|
595
|
|
|
// Manage the entered categories |
|
596
|
|
|
if (0 != $params['category'] || '' != $params['category']) { |
|
597
|
|
|
$params['category'] = gdsc_manage_category_choice($params['post_type'], $params['category']); |
|
598
|
|
|
} |
|
599
|
|
|
// Convert show_title to a bool |
|
600
|
|
|
$params['show_title'] = intval(gdsc_to_bool_val($params['show_title'])); |
|
601
|
|
|
|
|
602
|
|
|
// Convert show_featured_only to a bool |
|
603
|
|
|
$params['show_featured_only'] = intval(gdsc_to_bool_val($params['show_featured_only'])); |
|
604
|
|
|
|
|
605
|
|
|
/* |
|
606
|
|
|
* Hopefully all attributes are now valid, and safe to pass forward |
|
607
|
|
|
*/ |
|
608
|
|
|
|
|
609
|
|
|
// redeclare vars after validation |
|
610
|
|
|
|
|
611
|
|
|
if (isset($params['direction_nav'])) { |
|
612
|
|
|
$params['directionNav'] = $params['direction_nav']; |
|
613
|
|
|
} |
|
614
|
|
|
if (isset($params['animation_loop'])) { |
|
615
|
|
|
$params['animationLoop'] = $params['animation_loop']; |
|
616
|
|
|
} |
|
617
|
|
|
if (isset($params['slideshow_speed'])) { |
|
618
|
|
|
$params['slideshowSpeed'] = $params['slideshow_speed']; |
|
619
|
|
|
} |
|
620
|
|
|
if (isset($params['animation_speed'])) { |
|
621
|
|
|
$params['animationSpeed'] = $params['animation_speed']; |
|
622
|
|
|
} |
|
623
|
|
|
if (isset($params['order_by'])) { |
|
624
|
|
|
$params['list_sort'] = $params['order_by']; |
|
625
|
|
|
} |
|
626
|
|
|
|
|
627
|
|
|
$query_args = array( |
|
628
|
|
|
'post_number' => $params['post_number'], |
|
629
|
|
|
'is_geodir_loop' => true, |
|
630
|
|
|
'post_type' => $params['post_type'], |
|
631
|
|
|
'order_by' => $params['order_by'] |
|
632
|
|
|
); |
|
633
|
|
|
|
|
634
|
|
|
if (1 == $params['show_featured_only']) { |
|
635
|
|
|
$query_args['show_featured_only'] = 1; |
|
636
|
|
|
} |
|
637
|
|
|
|
|
638
|
|
|
if (0 != $params['category'] && '' != $params['category']) { |
|
639
|
|
|
$category_taxonomy = geodir_get_taxonomies($params['post_type']); |
|
640
|
|
|
$tax_query = array( |
|
641
|
|
|
'taxonomy' => $category_taxonomy[0], |
|
642
|
|
|
'field' => 'id', |
|
643
|
|
|
'terms' => $params['category'], |
|
644
|
|
|
); |
|
645
|
|
|
|
|
646
|
|
|
$query_args['tax_query'] = array($tax_query); |
|
647
|
|
|
} |
|
648
|
|
|
|
|
649
|
|
|
$defaults = array( |
|
650
|
|
|
'before_widget' => '', |
|
651
|
|
|
'after_widget' => '', |
|
652
|
|
|
'before_title' => '', |
|
653
|
|
|
'after_title' => '', |
|
654
|
|
|
); |
|
655
|
|
|
|
|
656
|
|
|
$query_args = array_merge($query_args, $params); |
|
657
|
|
|
|
|
658
|
|
|
geodir_listing_slider_widget_output($defaults, $query_args); |
|
659
|
|
|
|
|
660
|
|
|
$output = ob_get_contents(); |
|
661
|
|
|
|
|
662
|
|
|
ob_end_clean(); |
|
663
|
|
|
|
|
664
|
|
|
return $output; |
|
665
|
|
|
} |
|
666
|
|
|
|
|
667
|
|
|
add_shortcode('gd_login_box', 'geodir_sc_login_box'); |
|
668
|
|
|
/** |
|
669
|
|
|
* The geodirectory login box shortcode. |
|
670
|
|
|
* |
|
671
|
|
|
* This implements the functionality of the shortcode for displaying login box. |
|
672
|
|
|
* |
|
673
|
|
|
* @since 1.0.0 |
|
674
|
|
|
* @package GeoDirectory |
|
675
|
|
|
* @param array $atts { |
|
676
|
|
|
* Attributes of the shortcode. |
|
677
|
|
|
* |
|
678
|
|
|
* @type string $before_widget HTML content to prepend to each widget's HTML output. Default. Empty. |
|
679
|
|
|
* @type string $after_widget HTML content to append to each widget's HTML output. Default. Empty. |
|
680
|
|
|
* @type string $before_title HTML content to prepend to the title when displayed. Default. Empty. |
|
681
|
|
|
* @type string $after_title HTML content to append to the title when displayed. Default. Empty. |
|
682
|
|
|
* |
|
683
|
|
|
* } |
|
684
|
|
|
* @return string Login box HTML. |
|
685
|
|
|
*/ |
|
686
|
|
|
function geodir_sc_login_box($atts) |
|
687
|
|
|
{ |
|
688
|
|
|
ob_start(); |
|
689
|
|
|
|
|
690
|
|
|
$defaults = array( |
|
691
|
|
|
'before_widget' => '', |
|
692
|
|
|
'after_widget' => '', |
|
693
|
|
|
'before_title' => '', |
|
694
|
|
|
'after_title' => '', |
|
695
|
|
|
); |
|
696
|
|
|
|
|
697
|
|
|
geodir_loginwidget_output($defaults, $defaults); |
|
698
|
|
|
|
|
699
|
|
|
$output = ob_get_contents(); |
|
700
|
|
|
|
|
701
|
|
|
ob_end_clean(); |
|
702
|
|
|
|
|
703
|
|
|
return $output; |
|
704
|
|
|
} |
|
705
|
|
|
|
|
706
|
|
|
add_shortcode('gd_popular_post_category', 'geodir_sc_popular_post_category'); |
|
707
|
|
|
/** |
|
708
|
|
|
* The geodirectory popular post category shortcode. |
|
709
|
|
|
* |
|
710
|
|
|
* This implements the functionality of the shortcode for displaying popular post category. |
|
711
|
|
|
* |
|
712
|
|
|
* @since 1.0.0 |
|
713
|
|
|
* @since 1.5.1 Added default_post_type parameter. |
|
714
|
|
|
* @since 1.6.9 Added parent_only parameter. |
|
715
|
|
|
* @package GeoDirectory |
|
716
|
|
|
* @global string $geodir_post_category_str The geodirectory post category. |
|
717
|
|
|
* @param array $atts { |
|
718
|
|
|
* Attributes of the shortcode. |
|
719
|
|
|
* |
|
720
|
|
|
* @type string $before_widget HTML content to prepend to each widget's HTML output. Default. Empty. |
|
721
|
|
|
* @type string $after_widget HTML content to append to each widget's HTML output. Default. Empty. |
|
722
|
|
|
* @type string $before_title HTML content to prepend to the title when displayed. Default. Empty. |
|
723
|
|
|
* @type string $after_title HTML content to append to the title when displayed. Default. Empty. |
|
724
|
|
|
* @type int $category_limit Number of categories to display. Default. 15. |
|
725
|
|
|
* @type string $title Widget title. Default. Empty. |
|
726
|
|
|
* @type string $default_post_type Default post type. Default. Empty. |
|
727
|
|
|
* @type bool $parent_only True to show parent categories only. Default False. |
|
728
|
|
|
* |
|
729
|
|
|
* } |
|
730
|
|
|
* @return string Popular post category HTML. |
|
731
|
|
|
*/ |
|
732
|
|
|
function geodir_sc_popular_post_category($atts) |
|
733
|
|
|
{ |
|
734
|
|
|
ob_start(); |
|
735
|
|
|
global $geodir_post_category_str; |
|
736
|
|
|
$defaults = array( |
|
737
|
|
|
'category_limit' => 15, |
|
738
|
|
|
'category_restrict' => false, |
|
739
|
|
|
'before_widget' => '', |
|
740
|
|
|
'after_widget' => '', |
|
741
|
|
|
'before_title' => '', |
|
742
|
|
|
'after_title' => '', |
|
743
|
|
|
'title' => '', |
|
744
|
|
|
'default_post_type' => '', |
|
745
|
|
|
'parent_only' => false, |
|
746
|
|
|
); |
|
747
|
|
|
|
|
748
|
|
|
$params = shortcode_atts($defaults, $atts, 'popular_post_category'); |
|
749
|
|
|
$params['category_limit'] = absint($params['category_limit']); |
|
750
|
|
|
$params['default_post_type'] = gdsc_is_post_type_valid($params['default_post_type']) ? $params['default_post_type'] : ''; |
|
751
|
|
|
$params['parent_only'] = gdsc_to_bool_val($params['parent_only']); |
|
752
|
|
|
geodir_popular_post_category_output($params, $params); |
|
753
|
|
|
|
|
754
|
|
|
$output = ob_get_contents(); |
|
755
|
|
|
|
|
756
|
|
|
ob_end_clean(); |
|
757
|
|
|
|
|
758
|
|
|
return $output; |
|
759
|
|
|
} |
|
760
|
|
|
|
|
761
|
|
|
add_shortcode('gd_popular_post_view', 'geodir_sc_popular_post_view'); |
|
762
|
|
|
/** |
|
763
|
|
|
* The geodirectory popular post view shortcode. |
|
764
|
|
|
* |
|
765
|
|
|
* This implements the functionality of the shortcode for displaying popular post view. |
|
766
|
|
|
* |
|
767
|
|
|
* @since 1.0.0 |
|
768
|
|
|
* @since 1.6.18 [gd_popular_post_view] shortcode character_count=0 not working - FIXED |
|
769
|
|
|
* @since 1.6.22 $hide_if_empty parameter added. |
|
770
|
|
|
* @package GeoDirectory |
|
771
|
|
|
* @param array $atts { |
|
772
|
|
|
* Attributes of the shortcode. |
|
773
|
|
|
* |
|
774
|
|
|
* @type string $add_location_filter Filter listings using current location. Default 0. |
|
775
|
|
|
* @type string $before_widget HTML content to prepend to each widget's HTML output. Default. Empty. |
|
776
|
|
|
* @type string $after_widget HTML content to append to each widget's HTML output. Default. Empty. |
|
777
|
|
|
* @type string $before_title HTML content to prepend to the title when displayed. Default. <h3 class="widget-title">. |
|
778
|
|
|
* @type string $after_title HTML content to append to the title when displayed. Default. </h3>. |
|
779
|
|
|
* @type string $category Category ids to filter listings. Ex: 1,3. Default. 0. |
|
780
|
|
|
* @type string $category_title Category title. Default. Empty. |
|
781
|
|
|
* @type string $character_count The excerpt length. Default. 20. |
|
782
|
|
|
* @type string $layout Layout to display listing. Should be gridview_onehalf, gridview_onethird, |
|
783
|
|
|
* gridview_onefourth, gridview_onefifth, list. Default 'gridview_onehalf'. Default. gridview_onehalf. |
|
784
|
|
|
* @type string $list_sort Sort by. Default. latest. |
|
785
|
|
|
* @type string $listing_width Width of the listing in %. Default. Empty. |
|
786
|
|
|
* @type string $post_number No. of post to display. Default. 5. |
|
787
|
|
|
* @type string $post_type Post type of listing. Default. gd_place. |
|
788
|
|
|
* @type string $show_featured_only Display only featured listings. Default. 0. |
|
789
|
|
|
* @type string $show_special_only Display only special offers listings. Default. 0. |
|
790
|
|
|
* @type string $title Widget title. Default. Empty. |
|
791
|
|
|
* @type string $use_viewing_post_type Filter using viewing post type. Default. 1. |
|
792
|
|
|
* @type string $with_pics_only Only display listings which has image available. Default empty. Default. 0. |
|
793
|
|
|
* @type string $with_videos_only Only display listings which has video available. Default. 0. |
|
794
|
|
|
* @type string $hide_if_empty Hide widget if no listings found. Default. 0. |
|
795
|
|
|
* |
|
796
|
|
|
* } |
|
797
|
|
|
* @return string Popular post view HTML. |
|
798
|
|
|
*/ |
|
799
|
|
|
function geodir_sc_popular_post_view($atts) |
|
800
|
|
|
{ |
|
801
|
|
|
ob_start(); |
|
802
|
|
|
$defaults = array( |
|
803
|
|
|
'post_type' => 'gd_place', |
|
804
|
|
|
'category' => '0', |
|
805
|
|
|
'post_number' => '5', |
|
806
|
|
|
'layout' => 'gridview_onehalf', |
|
807
|
|
|
'add_location_filter' => '0', |
|
808
|
|
|
'list_sort' => 'latest', |
|
809
|
|
|
'use_viewing_post_type' => '1', |
|
810
|
|
|
'character_count' => '20', |
|
811
|
|
|
'listing_width' => '', |
|
812
|
|
|
'show_featured_only' => '0', |
|
813
|
|
|
'show_special_only' => '0', |
|
814
|
|
|
'with_pics_only' => '0', |
|
815
|
|
|
'with_videos_only' => '0', |
|
816
|
|
|
'hide_if_empty' => '0', |
|
817
|
|
|
'before_widget' => '', |
|
818
|
|
|
'after_widget' => '', |
|
819
|
|
|
'before_title' => '<h3 class="widget-title">', |
|
820
|
|
|
'after_title' => '</h3>', |
|
821
|
|
|
'title' => '', |
|
822
|
|
|
'category_title' => '', |
|
823
|
|
|
); |
|
824
|
|
|
|
|
825
|
|
|
$params = shortcode_atts($defaults, $atts); |
|
826
|
|
|
|
|
827
|
|
|
/** |
|
828
|
|
|
* Validate our incoming params |
|
829
|
|
|
*/ |
|
830
|
|
|
|
|
831
|
|
|
// Validate the selected post type, default to gd_place on fail |
|
832
|
|
|
if (!(gdsc_is_post_type_valid($params['post_type']))) { |
|
833
|
|
|
$params['post_type'] = 'gd_place'; |
|
834
|
|
|
} |
|
835
|
|
|
|
|
836
|
|
|
// Validate the selected category/ies - Grab the current list based on post_type |
|
837
|
|
|
$category_taxonomy = geodir_get_taxonomies($params['post_type']); |
|
838
|
|
|
$categories = get_terms($category_taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'fields' => 'ids')); |
|
839
|
|
|
|
|
840
|
|
|
// Make sure we have an array |
|
841
|
|
|
if (!(is_array($params['category']))) { |
|
842
|
|
|
$params['category'] = explode(',', $params['category']); |
|
843
|
|
|
} |
|
844
|
|
|
|
|
845
|
|
|
// Array_intersect returns only the items in $params['category'] that are also in our category list |
|
846
|
|
|
// Otherwise it becomes empty and later on that will mean "All" |
|
847
|
|
|
$params['category'] = array_intersect($params['category'], $categories); |
|
848
|
|
|
|
|
849
|
|
|
// Post_number needs to be a positive integer |
|
850
|
|
|
$params['post_number'] = absint($params['post_number']); |
|
851
|
|
|
if (0 == $params['post_number']) { |
|
852
|
|
|
$params['post_number'] = 1; |
|
853
|
|
|
} |
|
854
|
|
|
|
|
855
|
|
|
// Validate our layout choice |
|
856
|
|
|
// Outside of the norm, I added some more simple terms to match the existing |
|
857
|
|
|
// So now I just run the switch to set it properly. |
|
858
|
|
|
$params['layout'] = gdsc_validate_layout_choice($params['layout']); |
|
859
|
|
|
|
|
860
|
|
|
// Validate our sorting choice |
|
861
|
|
|
$params['list_sort'] = gdsc_validate_sort_choice($params['list_sort'], $params['post_type']); |
|
862
|
|
|
|
|
863
|
|
|
// Validate character_count |
|
864
|
|
|
if ($params['character_count'] !== '') { |
|
865
|
|
|
$params['character_count'] = absint($params['character_count']); |
|
866
|
|
|
} |
|
867
|
|
|
|
|
868
|
|
|
// Validate Listing width, used in the template widget-listing-listview.php |
|
869
|
|
|
// The context is in width=$listing_width% - So we need a positive number between 0 & 100 |
|
870
|
|
|
$params['listing_width'] = gdsc_validate_listing_width($params['listing_width']); |
|
871
|
|
|
|
|
872
|
|
|
// Validate the checkboxes used on the widget |
|
873
|
|
|
$params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']); |
|
874
|
|
|
$params['show_featured_only'] = gdsc_to_bool_val($params['show_featured_only']); |
|
875
|
|
|
$params['show_special_only'] = gdsc_to_bool_val($params['show_special_only']); |
|
876
|
|
|
$params['with_pics_only'] = gdsc_to_bool_val($params['with_pics_only']); |
|
877
|
|
|
$params['with_videos_only'] = gdsc_to_bool_val($params['with_videos_only']); |
|
878
|
|
|
$params['use_viewing_post_type'] = gdsc_to_bool_val($params['use_viewing_post_type']); |
|
879
|
|
|
$params['hide_if_empty'] = gdsc_to_bool_val($params['hide_if_empty']); |
|
880
|
|
|
|
|
881
|
|
|
/** |
|
882
|
|
|
* End of validation |
|
883
|
|
|
*/ |
|
884
|
|
|
|
|
885
|
|
|
geodir_popular_postview_output($params, $params); |
|
886
|
|
|
|
|
887
|
|
|
|
|
888
|
|
|
$output = ob_get_contents(); |
|
889
|
|
|
|
|
890
|
|
|
ob_end_clean(); |
|
891
|
|
|
|
|
892
|
|
|
return $output; |
|
893
|
|
|
} |
|
894
|
|
|
|
|
895
|
|
|
add_shortcode('gd_recent_reviews', 'geodir_sc_recent_reviews'); |
|
896
|
|
|
/** |
|
897
|
|
|
* The geodirectory recent reviews shortcode. |
|
898
|
|
|
* |
|
899
|
|
|
* This implements the functionality of the shortcode for displaying recent reviews. |
|
900
|
|
|
* |
|
901
|
|
|
* @since 1.0.0 |
|
902
|
|
|
* @since 1.5.0 New title attribute added. |
|
903
|
|
|
* @package GeoDirectory |
|
904
|
|
|
* @param array $atts { |
|
905
|
|
|
* Attributes of the shortcode. |
|
906
|
|
|
* |
|
907
|
|
|
* @type string $title The title displayed above recent reviews. Default empty. |
|
908
|
|
|
* @type int $count Number of reviews you want to display. Default. 5. |
|
909
|
|
|
* |
|
910
|
|
|
* } |
|
911
|
|
|
* @return string Recent reviews HTML. |
|
912
|
|
|
*/ |
|
913
|
|
|
function geodir_sc_recent_reviews($atts) { |
|
914
|
|
|
ob_start(); |
|
915
|
|
|
$defaults = array( |
|
916
|
|
|
'title' => '', |
|
917
|
|
|
'count' => 5, |
|
918
|
|
|
); |
|
919
|
|
|
|
|
920
|
|
|
$params = shortcode_atts($defaults, $atts); |
|
921
|
|
|
|
|
922
|
|
|
$count = absint($params['count']); |
|
923
|
|
|
if (0 == $count) { |
|
924
|
|
|
$count = 1; |
|
925
|
|
|
} |
|
926
|
|
|
|
|
927
|
|
|
$title = !empty($params['title']) ? __($params['title'], 'geodirectory') : ''; |
|
928
|
|
|
|
|
929
|
|
|
$comments_li = geodir_get_recent_reviews(30, $count, 100, false); |
|
930
|
|
|
|
|
931
|
|
|
if ($comments_li) { |
|
932
|
|
|
if ($title != '') { ?> |
|
933
|
|
|
<h3 class="geodir-sc-recent-reviews-title widget-title"><?php echo $title; ?></h3> |
|
934
|
|
|
<?php } ?> |
|
935
|
|
|
<div class="geodir_sc_recent_reviews_section"> |
|
936
|
|
|
<ul class="geodir_sc_recent_reviews"><?php echo $comments_li; ?></ul> |
|
937
|
|
|
</div> |
|
938
|
|
|
<?php |
|
939
|
|
|
} |
|
940
|
|
|
$output = ob_get_contents(); |
|
941
|
|
|
|
|
942
|
|
|
ob_end_clean(); |
|
943
|
|
|
|
|
944
|
|
|
return $output; |
|
945
|
|
|
} |
|
946
|
|
|
|
|
947
|
|
|
add_shortcode('gd_related_listings', 'geodir_sc_related_listings'); |
|
948
|
|
|
/** |
|
949
|
|
|
* The geodirectory related listing widget shortcode. |
|
950
|
|
|
* |
|
951
|
|
|
* This implements the functionality of the shortcode for displaying related listing widget. |
|
952
|
|
|
* |
|
953
|
|
|
* @since 1.0.0 |
|
954
|
|
|
* @package GeoDirectory |
|
955
|
|
|
* @param array $atts { |
|
956
|
|
|
* Attributes of the shortcode. |
|
957
|
|
|
* |
|
958
|
|
|
* @type int $add_location_filter Filter listings using current location. Default 0. |
|
959
|
|
|
* @type string $before_title HTML content to prepend to the title when displayed. Default. <style type="text/css">.geodir_category_list_view li{margin:0px!important}</style>. |
|
960
|
|
|
* @type int $character_count The excerpt length Default. 20. |
|
961
|
|
|
* @type int $is_widget Is this a widget? Default. 1. |
|
962
|
|
|
* @type string $layout Layout to display listing. Should be gridview_onehalf, gridview_onethird, |
|
963
|
|
|
* gridview_onefourth, gridview_onefifth, list. Default 'gridview_onehalf'. Default. gridview_onehalf. |
|
964
|
|
|
* @type string $list_sort Sort by. Default. latest. |
|
965
|
|
|
* @type string $listing_width Width of the listing in %. Default. Empty. |
|
966
|
|
|
* @type int $post_number No. of post to display. Default. 5. |
|
967
|
|
|
* @type string $relate_to Type to use for making relation. Can be tags or category. Default. category. |
|
968
|
|
|
* |
|
969
|
|
|
* } |
|
970
|
|
|
* @return string Related widget HTML. |
|
971
|
|
|
*/ |
|
972
|
|
|
function geodir_sc_related_listings($atts) |
|
973
|
|
|
{ |
|
974
|
|
|
ob_start(); |
|
975
|
|
|
$defaults = array( |
|
976
|
|
|
'post_number' => 5, |
|
977
|
|
|
'relate_to' => 'category', |
|
978
|
|
|
'layout' => 'gridview_onehalf', |
|
979
|
|
|
'add_location_filter' => 0, |
|
980
|
|
|
'listing_width' => '', |
|
981
|
|
|
'list_sort' => 'latest', |
|
982
|
|
|
'character_count' => 20, |
|
983
|
|
|
'is_widget' => 1, |
|
984
|
|
|
'before_title' => '<style type="text/css">.geodir_category_list_view li{margin:0px!important}</style>', |
|
985
|
|
|
); |
|
986
|
|
|
// The "before_title" code is an ugly & terrible hack. But it works for now. I should enqueue a new stylesheet. |
|
987
|
|
|
|
|
988
|
|
|
$params = shortcode_atts($defaults, $atts); |
|
989
|
|
|
|
|
990
|
|
|
/** |
|
991
|
|
|
* Begin validating parameters |
|
992
|
|
|
*/ |
|
993
|
|
|
|
|
994
|
|
|
// Validate that post_number is a number and is 1 or higher |
|
995
|
|
|
$params['post_number'] = absint($params['post_number']); |
|
996
|
|
|
if (0 === $params['post_number']) { |
|
997
|
|
|
$params['post_number'] = 1; |
|
998
|
|
|
} |
|
999
|
|
|
|
|
1000
|
|
|
// Validate relate_to - only category or tags |
|
1001
|
|
|
$params['relate_to'] = geodir_strtolower($params['relate_to']); |
|
1002
|
|
|
if ('category' != $params['relate_to'] && 'tags' != $params['relate_to']) { |
|
1003
|
|
|
$params['relate_to'] = 'category'; |
|
1004
|
|
|
} |
|
1005
|
|
|
|
|
1006
|
|
|
// Validate layout selection |
|
1007
|
|
|
$params['layout'] = gdsc_validate_layout_choice($params['layout']); |
|
1008
|
|
|
|
|
1009
|
|
|
// Validate sorting option |
|
1010
|
|
|
$params['list_sort'] = gdsc_validate_sort_choice($params['list_sort']); |
|
1011
|
|
|
|
|
1012
|
|
|
// Validate add_location_filter |
|
1013
|
|
|
$params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']); |
|
1014
|
|
|
|
|
1015
|
|
|
// Validate listing_width |
|
1016
|
|
|
$params['listing_width'] = gdsc_validate_listing_width($params['listing_width']); |
|
1017
|
|
|
|
|
1018
|
|
|
// Validate character_count |
|
1019
|
|
|
if ($params['character_count'] !== '') { |
|
1020
|
|
|
$params['character_count'] = absint($params['character_count']); |
|
1021
|
|
|
} |
|
1022
|
|
|
|
|
1023
|
|
|
if ($related_display = geodir_related_posts_display($params)) { |
|
1024
|
|
|
echo $related_display; |
|
1025
|
|
|
} |
|
1026
|
|
|
$output = ob_get_contents(); |
|
1027
|
|
|
|
|
1028
|
|
|
ob_end_clean(); |
|
1029
|
|
|
|
|
1030
|
|
|
return $output; |
|
1031
|
|
|
} |
|
1032
|
|
|
|
|
1033
|
|
|
/** |
|
1034
|
|
|
* The geodirectory advanced search widget shortcode. |
|
1035
|
|
|
* |
|
1036
|
|
|
* This implements the functionality of the shortcode for displaying advanced search widget. |
|
1037
|
|
|
* |
|
1038
|
|
|
* @since 1.0.0 |
|
1039
|
|
|
* @package GeoDirectory |
|
1040
|
|
|
* @param array $atts { |
|
1041
|
|
|
* Attributes of the shortcode. |
|
1042
|
|
|
* |
|
1043
|
|
|
* @type string $before_widget HTML content to prepend to each widget's HTML output. Default. <section id="geodir_advanced_search-1" class="widget geodir-widget geodir_advanced_search_widget">. |
|
1044
|
|
|
* @type string $after_widget HTML content to append to each widget's HTML output. Default. </section>. |
|
1045
|
|
|
* @type string $before_title HTML content to prepend to the title when displayed. Default. <h3 class="widget-title">. |
|
1046
|
|
|
* @type string $after_title HTML content to append to the title when displayed. Default. </h3>. |
|
1047
|
|
|
* @type string $show_adv_search Show advanced search? Default. default. |
|
1048
|
|
|
* @type string $title Widget title. Default. Empty. |
|
1049
|
|
|
* |
|
1050
|
|
|
* } |
|
1051
|
|
|
* @return string Advanced search widget HTML. |
|
1052
|
|
|
*/ |
|
1053
|
|
|
function geodir_sc_advanced_search($atts) { |
|
1054
|
|
|
$defaults = array( |
|
1055
|
|
|
'title' => '', |
|
1056
|
|
|
'before_widget' => '<section id="geodir_advanced_search-1" class="widget geodir-widget geodir_advance_search_widget">', |
|
1057
|
|
|
'after_widget' => '</section>', |
|
1058
|
|
|
'before_title' => '<h3 class="widget-title">', |
|
1059
|
|
|
'after_title' => '</h3>', |
|
1060
|
|
|
'show_adv_search' => 'default', |
|
1061
|
|
|
'post_type' => '' |
|
1062
|
|
|
); |
|
1063
|
|
|
|
|
1064
|
|
|
$params = shortcode_atts($defaults, $atts); |
|
1065
|
|
|
|
|
1066
|
|
|
$show_adv_search = isset($params['show_adv_search']) && in_array($params['show_adv_search'], array('default', 'always', 'searched')) ? $params['show_adv_search'] : ''; |
|
1067
|
|
|
|
|
1068
|
|
|
if ($show_adv_search != '' ) { |
|
1069
|
|
|
$show_adv_class = 'geodir-advance-search-' . $show_adv_search . ' '; |
|
1070
|
|
|
if ($show_adv_search == 'searched' && geodir_is_page('search')) { |
|
1071
|
|
|
$show_adv_search = 'search'; |
|
1072
|
|
|
} |
|
1073
|
|
|
$show_adv_attrs = 'data-show-adv="' . $show_adv_search . '"'; |
|
1074
|
|
|
|
|
1075
|
|
|
$params['before_widget'] = str_replace('class="', $show_adv_attrs . ' class="' . $show_adv_class, $params['before_widget']); |
|
1076
|
|
|
} |
|
1077
|
|
|
|
|
1078
|
|
|
ob_start(); |
|
1079
|
|
|
|
|
1080
|
|
|
//geodir_get_template_part('listing', 'filter-form'); |
|
1081
|
|
|
the_widget('geodir_advance_search_widget', $params, $params ); |
|
1082
|
|
|
|
|
1083
|
|
|
$output = ob_get_contents(); |
|
1084
|
|
|
ob_end_clean(); |
|
1085
|
|
|
|
|
1086
|
|
|
return $output; |
|
1087
|
|
|
} |
|
1088
|
|
|
add_shortcode('gd_advanced_search', 'geodir_sc_advanced_search'); |
|
1089
|
|
|
|
|
1090
|
|
|
/** |
|
1091
|
|
|
* The best of widget shortcode. |
|
1092
|
|
|
* |
|
1093
|
|
|
* This implements the functionality of the best of widget shortcode for displaying |
|
1094
|
|
|
* top rated listing. |
|
1095
|
|
|
* |
|
1096
|
|
|
* @since 1.4.2 |
|
1097
|
|
|
* |
|
1098
|
|
|
* @param array $atts { |
|
1099
|
|
|
* Attributes of the shortcode. |
|
1100
|
|
|
* |
|
1101
|
|
|
* @type string $title The title of the widget displayed. |
|
1102
|
|
|
* @type string $post_type Post type of listing. Default gd_place. |
|
1103
|
|
|
* @type int $post_limit No. of post to display. Default 5. |
|
1104
|
|
|
* @type int $categ_limit No. of categories to display. Default 3. |
|
1105
|
|
|
* @type int $character_count The excerpt length |
|
1106
|
|
|
* @type int $use_viewing_post_type Filter viewing post type. Default 1. |
|
1107
|
|
|
* @type int $add_location_filter Filter current location. Default 1. |
|
1108
|
|
|
* @type string $tab_layout Tab layout to display listing. Default 'bestof-tabs-on-top'. |
|
1109
|
|
|
* @type string $before_widget HTML content to prepend to each widget's HTML output. |
|
1110
|
|
|
* Default is an opening list item element. |
|
1111
|
|
|
* @type string $after_widget HTML content to append to each widget's HTML output. |
|
1112
|
|
|
* Default is a closing list item element. |
|
1113
|
|
|
* @type string $before_title HTML content to prepend to the widget title when displayed. |
|
1114
|
|
|
* Default is an opening h3 element. |
|
1115
|
|
|
* @type string $after_title HTML content to append to the widget title when displayed. |
|
1116
|
|
|
* Default is a closing h3 element. |
|
1117
|
|
|
* } |
|
1118
|
|
|
* @param string $content The enclosed content. Optional. |
|
1119
|
|
|
* @return string HTML content to display best of listings. |
|
1120
|
|
|
*/ |
|
1121
|
|
|
function geodir_sc_bestof_widget($atts, $content = '') { |
|
1122
|
|
|
$defaults = array( |
|
1123
|
|
|
'title' => '', |
|
1124
|
|
|
'post_type' => 'gd_place', |
|
1125
|
|
|
'post_limit' => 5, |
|
1126
|
|
|
'categ_limit' => 3, |
|
1127
|
|
|
'character_count' => 20, |
|
1128
|
|
|
'use_viewing_post_type' => '1', |
|
1129
|
|
|
'add_location_filter' => '1', |
|
1130
|
|
|
'tab_layout' => 'bestof-tabs-on-top', |
|
1131
|
|
|
'before_widget' => '<section id="bestof_widget-1" class="widget geodir-widget geodir_bestof_widget geodir_sc_bestof_widget">', |
|
1132
|
|
|
'after_widget' => '</section>', |
|
1133
|
|
|
'before_title' => '<h3 class="widget-title">', |
|
1134
|
|
|
'after_title' => '</h3>', |
|
1135
|
|
|
); |
|
1136
|
|
|
$params = shortcode_atts($defaults, $atts); |
|
1137
|
|
|
|
|
1138
|
|
|
/** |
|
1139
|
|
|
* Validate our incoming params |
|
1140
|
|
|
*/ |
|
1141
|
|
|
|
|
1142
|
|
|
// Validate the selected post type, default to gd_place on fail |
|
1143
|
|
|
if (!(gdsc_is_post_type_valid($params['post_type']))) { |
|
1144
|
|
|
$params['post_type'] = 'gd_place'; |
|
1145
|
|
|
} |
|
1146
|
|
|
|
|
1147
|
|
|
// Post limit needs to be a positive integer |
|
1148
|
|
|
$params['post_limit'] = absint($params['post_limit']); |
|
1149
|
|
|
if (0 == $params['post_limit']) { |
|
1150
|
|
|
$params['post_limit'] = 5; |
|
1151
|
|
|
} |
|
1152
|
|
|
|
|
1153
|
|
|
// Category limit needs to be a positive integer |
|
1154
|
|
|
$params['categ_limit'] = absint($params['categ_limit']); |
|
1155
|
|
|
if (0 == $params['categ_limit']) { |
|
1156
|
|
|
$params['categ_limit'] = 3; |
|
1157
|
|
|
} |
|
1158
|
|
|
|
|
1159
|
|
|
// Tab layout validation |
|
1160
|
|
|
$params['tab_layout'] = $params['tab_layout']; |
|
1161
|
|
|
if (!in_array($params['tab_layout'], array('bestof-tabs-on-top', 'bestof-tabs-on-left', 'bestof-tabs-as-dropdown'))) { |
|
1162
|
|
|
$params['tab_layout'] = 'bestof-tabs-on-top'; |
|
1163
|
|
|
} |
|
1164
|
|
|
|
|
1165
|
|
|
// Validate character_count |
|
1166
|
|
|
$params['character_count'] = $params['character_count']; |
|
1167
|
|
|
|
|
1168
|
|
|
ob_start(); |
|
1169
|
|
|
the_widget('geodir_bestof_widget', $params, $params); |
|
1170
|
|
|
$output = ob_get_contents(); |
|
1171
|
|
|
ob_end_clean(); |
|
1172
|
|
|
|
|
1173
|
|
|
return $output; |
|
1174
|
|
|
} |
|
1175
|
|
|
add_shortcode('gd_bestof_widget', 'geodir_sc_bestof_widget'); |
|
1176
|
|
|
|
|
1177
|
|
|
/** |
|
1178
|
|
|
* The geodirectory listings shortcode. |
|
1179
|
|
|
* |
|
1180
|
|
|
* This implements the functionality of the shortcode for displaying geodirectory listings. |
|
1181
|
|
|
* |
|
1182
|
|
|
* @since 1.4.2 |
|
1183
|
|
|
* @since 1.5.9 New parameter "post_author" added. |
|
1184
|
|
|
* @since 1.6.5 tags parameter added. |
|
1185
|
|
|
* @since 1.6.18 New attributes added in gd_listings shortcode to filter user favorite listings. |
|
1186
|
|
|
* In [gd_listings] shortcode if category has no posts then it shows all the results - FIXED |
|
1187
|
|
|
* |
|
1188
|
|
|
* @global object $post The current post object. |
|
1189
|
|
|
* |
|
1190
|
|
|
* @param array $atts { |
|
1191
|
|
|
* Attributes of the shortcode. |
|
1192
|
|
|
* |
|
1193
|
|
|
* @type string $title The title to be displayed above listings. |
|
1194
|
|
|
* @type string $post_type Post type of listing. Default gd_place. |
|
1195
|
|
|
* @type string $category Category ids to filter listings. Ex: 1,3. Default empty. |
|
1196
|
|
|
* @type string $list_sort Sorting for listings. Should be from az, latest, featured, |
|
1197
|
|
|
high_review, high_rating.Default 'latest'. |
|
1198
|
|
|
* @type string $event_type Event type filter. Should today, upcoming, past, all. Default empty. |
|
1199
|
|
|
For post type gd_event only. |
|
1200
|
|
|
* @type int $post_number No. of post to display. Default 10. |
|
1201
|
|
|
* @type int|string $post_author Filter the posts by author. Either author ID or 'current'(it uses |
|
1202
|
|
|
the author ID of the current post. Default empty. |
|
1203
|
|
|
* @type string $layout Layout to display listing. Should be gridview_onehalf, gridview_onethird |
|
1204
|
|
|
gridview_onefourth, gridview_onefifth, list. Default 'gridview_onehalf'. |
|
1205
|
|
|
* @type string $listing_width Listing width. Optional |
|
1206
|
|
|
* @type int $character_count The excerpt length of content |
|
1207
|
|
|
* @type int|bool $add_location_filter Filter listings using current location. Default 1. |
|
1208
|
|
|
* @type int|bool $show_featured_only Display only featured listings. Default empty. |
|
1209
|
|
|
* @type int|bool $show_special_only Display only special offers listings. Default empty. |
|
1210
|
|
|
* @type int|bool $with_pics_only Display listings which has image available. Default empty. |
|
1211
|
|
|
* @type int|bool $with_videos_only Display listings which has video available. Default empty. |
|
1212
|
|
|
* @type int|bool $with_pagination Display pagination for listings. Default 1. |
|
1213
|
|
|
* @type int|bool $top_pagination Display pagination on top of listings. Default 0. |
|
1214
|
|
|
Required $with_pagination true. |
|
1215
|
|
|
* @type int|bool $bottom_pagination Display pagination on bottom of listings. Default 1. |
|
1216
|
|
|
Required $with_pagination true. |
|
1217
|
|
|
@type string $tags Post tags. Ex: "Tag1,TagB" Optional. |
|
1218
|
|
|
* @type int|bool $show_favorites_only Display listings which are favorited by user. Default empty. |
|
1219
|
|
|
* @type int|string $favorites_by_user Filter the posts favorites by user. Should be user ID or 'current' or empty. Default empty. |
|
1220
|
|
|
('current' uses the author Id of current viewing post, If empty then uses the current logged user ID). |
|
1221
|
|
|
* } |
|
1222
|
|
|
* @param string $content The enclosed content. Optional. |
|
1223
|
|
|
* @return string HTML content to display geodirectory listings. |
|
1224
|
|
|
*/ |
|
1225
|
|
|
function geodir_sc_gd_listings($atts, $content = '') { |
|
1226
|
|
|
global $post; |
|
1227
|
|
|
$defaults = array( |
|
1228
|
|
|
'title' => '', |
|
1229
|
|
|
'post_type' => 'gd_place', |
|
1230
|
|
|
'category' => 0, |
|
1231
|
|
|
'list_sort' => 'latest', |
|
1232
|
|
|
'event_type' => '', |
|
1233
|
|
|
'post_number' => 10, |
|
1234
|
|
|
'post_author' => '', |
|
1235
|
|
|
'layout' => 'gridview_onehalf', |
|
1236
|
|
|
'listing_width' => '', |
|
1237
|
|
|
'character_count' => 20, |
|
1238
|
|
|
'add_location_filter' => 1, |
|
1239
|
|
|
'show_featured_only' => '', |
|
1240
|
|
|
'show_special_only' => '', |
|
1241
|
|
|
'with_pics_only' => '', |
|
1242
|
|
|
'with_videos_only' => '', |
|
1243
|
|
|
'with_pagination' => '1', |
|
1244
|
|
|
'top_pagination' => '0', |
|
1245
|
|
|
'bottom_pagination' => '1', |
|
1246
|
|
|
'without_no_results' => 0, |
|
1247
|
|
|
'tags' => '', |
|
1248
|
|
|
'show_favorites_only' => '', |
|
1249
|
|
|
'favorites_by_user' => '', |
|
1250
|
|
|
); |
|
1251
|
|
|
$params = shortcode_atts($defaults, $atts); |
|
1252
|
|
|
|
|
1253
|
|
|
$params['title'] = wp_strip_all_tags($params['title']); |
|
1254
|
|
|
$params['post_type'] = gdsc_is_post_type_valid($params['post_type']) ? $params['post_type'] : 'gd_place'; |
|
1255
|
|
|
|
|
1256
|
|
|
// Validate the selected category/ies - Grab the current list based on post_type |
|
1257
|
|
|
$category_taxonomy = geodir_get_taxonomies($params['post_type']); |
|
1258
|
|
|
$categories = get_terms($category_taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'fields' => 'ids', 'hide_empty' => 0)); |
|
1259
|
|
|
|
|
1260
|
|
|
// Make sure we have an array |
|
1261
|
|
|
if (!(is_array($params['category']))) { |
|
1262
|
|
|
$params['category'] = explode(',', $params['category']); |
|
1263
|
|
|
} |
|
1264
|
|
|
|
|
1265
|
|
|
// Array_intersect returns only the items in $params['category'] that are also in our category list |
|
1266
|
|
|
// Otherwise it becomes empty and later on that will mean "All" |
|
1267
|
|
|
$params['category'] = array_intersect($params['category'], $categories); |
|
1268
|
|
|
|
|
1269
|
|
|
// Post_number needs to be a positive integer |
|
1270
|
|
|
$params['post_number'] = absint($params['post_number']); |
|
1271
|
|
|
$params['post_number'] = $params['post_number'] > 0 ? $params['post_number'] : 10; |
|
1272
|
|
|
|
|
1273
|
|
|
// Post_number needs to be a positive integer |
|
1274
|
|
|
if (!empty($params['post_author'])) { |
|
1275
|
|
|
// 'current' left for backwards compatibility |
|
1276
|
|
|
if ( $params['post_author'] == 'current' || $params['post_author'] == 'current_author') { |
|
1277
|
|
|
if (!empty($post) && $post->post_type != 'page' && isset($post->post_author)) { |
|
1278
|
|
|
$params['post_author'] = $post->post_author; |
|
1279
|
|
|
} else { |
|
1280
|
|
|
$params['post_author'] = -1; // Don't show any listings. |
|
1281
|
|
|
} |
|
1282
|
|
|
} else if ($params['post_author'] == 'current_user' ) { |
|
1283
|
|
|
if ($current_user_id = get_current_user_id()) { |
|
1284
|
|
|
$params['post_author'] = $current_user_id; |
|
1285
|
|
|
} else { |
|
1286
|
|
|
$params['post_author'] = -1; // If not logged in then don't show any listings. |
|
1287
|
|
|
} |
|
1288
|
|
|
} else if (absint($params['post_author']) > 0) { |
|
1289
|
|
|
$params['post_author'] = absint($params['post_author']); |
|
1290
|
|
|
} else { |
|
1291
|
|
|
$params['post_author'] = -1; // Don't show any listings. |
|
1292
|
|
|
} |
|
1293
|
|
|
} else { |
|
1294
|
|
|
unset($params['post_author']); |
|
1295
|
|
|
} |
|
1296
|
|
|
|
|
1297
|
|
|
// Validate character_count |
|
1298
|
|
|
//todo: is this necessary? |
|
1299
|
|
|
$params['character_count'] = $params['character_count']; |
|
1300
|
|
|
|
|
1301
|
|
|
// Validate our layout choice |
|
1302
|
|
|
// Outside of the norm, I added some more simple terms to match the existing |
|
1303
|
|
|
// So now I just run the switch to set it properly. |
|
1304
|
|
|
$params['layout'] = gdsc_validate_layout_choice($params['layout']); |
|
1305
|
|
|
|
|
1306
|
|
|
// Validate our sorting choice |
|
1307
|
|
|
$params['list_sort'] = gdsc_validate_sort_choice($params['list_sort'], $params['post_type']); |
|
1308
|
|
|
|
|
1309
|
|
|
// Validate Listing width, used in the template widget-listing-listview.php |
|
1310
|
|
|
// The context is in width=$listing_width% - So we need a positive number between 0 & 100 |
|
1311
|
|
|
$params['listing_width'] = gdsc_validate_listing_width($params['listing_width']); |
|
1312
|
|
|
|
|
1313
|
|
|
// Validate the checkboxes used on the widget |
|
1314
|
|
|
$params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']); |
|
1315
|
|
|
$params['show_featured_only'] = gdsc_to_bool_val($params['show_featured_only']); |
|
1316
|
|
|
$params['show_special_only'] = gdsc_to_bool_val($params['show_special_only']); |
|
1317
|
|
|
$params['with_pics_only'] = gdsc_to_bool_val($params['with_pics_only']); |
|
1318
|
|
|
$params['with_videos_only'] = gdsc_to_bool_val($params['with_videos_only']); |
|
1319
|
|
|
$params['with_pagination'] = gdsc_to_bool_val($params['with_pagination']); |
|
1320
|
|
|
$params['top_pagination'] = gdsc_to_bool_val($params['top_pagination']); |
|
1321
|
|
|
$params['bottom_pagination'] = gdsc_to_bool_val($params['bottom_pagination']); |
|
1322
|
|
|
|
|
1323
|
|
|
// User favorites |
|
1324
|
|
|
$params['show_favorites_only'] = gdsc_to_bool_val($params['show_favorites_only']); |
|
1325
|
|
|
if (!empty($params['show_favorites_only'])) { |
|
1326
|
|
|
if ( $params['favorites_by_user'] == 'current' || $params['favorites_by_user'] == 'current_author') { |
|
1327
|
|
|
if (!empty($post) && $post->post_type != 'page' && isset($post->post_author)) { |
|
1328
|
|
|
$params['favorites_by_user'] = $post->post_author; |
|
1329
|
|
|
} else { |
|
1330
|
|
|
$params['favorites_by_user'] = 0; |
|
1331
|
|
|
} |
|
1332
|
|
|
} else if ($params['favorites_by_user'] == 'current_user' || empty($params['favorites_by_user'])) { |
|
1333
|
|
|
if ($current_user_id = get_current_user_id()) { |
|
1334
|
|
|
$params['favorites_by_user'] = $current_user_id; |
|
1335
|
|
|
} else { |
|
1336
|
|
|
$params['favorites_by_user'] = 0; |
|
1337
|
|
|
} |
|
1338
|
|
|
} else if (absint($params['favorites_by_user']) > 0) { |
|
1339
|
|
|
$params['favorites_by_user'] = absint($params['favorites_by_user']); |
|
1340
|
|
|
} else { |
|
1341
|
|
|
$params['favorites_by_user'] = 0; |
|
1342
|
|
|
} |
|
1343
|
|
|
} |
|
1344
|
|
|
|
|
1345
|
|
|
// Clean tags |
|
1346
|
|
|
if (!empty($params['tags'])) { |
|
1347
|
|
|
if (!is_array($params['tags'])) { |
|
1348
|
|
|
$comma = _x(',', 'tag delimiter'); |
|
1349
|
|
|
if ( ',' !== $comma ) { |
|
1350
|
|
|
$params['tags'] = str_replace($comma, ',', $params['tags']); |
|
1351
|
|
|
} |
|
1352
|
|
|
$params['tags'] = explode(',', trim($params['tags'], " \n\t\r\0\x0B,")); |
|
1353
|
|
|
$params['tags'] = array_map('trim', $params['tags']); |
|
1354
|
|
|
} |
|
1355
|
|
|
} else { |
|
1356
|
|
|
$params['tags'] = array(); |
|
1357
|
|
|
} |
|
1358
|
|
|
|
|
1359
|
|
|
/** |
|
1360
|
|
|
* End of validation |
|
1361
|
|
|
*/ |
|
1362
|
|
|
if (isset($atts['geodir_ajax'])) { |
|
1363
|
|
|
$params['geodir_ajax'] = $atts['geodir_ajax']; |
|
1364
|
|
|
unset($atts['geodir_ajax']); |
|
1365
|
|
|
} |
|
1366
|
|
|
if (isset($atts['pageno'])) { |
|
1367
|
|
|
$params['pageno'] = $atts['pageno']; |
|
1368
|
|
|
unset($atts['pageno']); |
|
1369
|
|
|
} |
|
1370
|
|
|
|
|
1371
|
|
|
if ( !empty($atts['shortcode_content']) ) { |
|
1372
|
|
|
$content = $atts['shortcode_content']; |
|
1373
|
|
|
} |
|
1374
|
|
|
$params['shortcode_content'] = trim($content); |
|
1375
|
|
|
$atts['shortcode_content'] = trim($content); |
|
1376
|
|
|
|
|
1377
|
|
|
$params['shortcode_atts'] = $atts; |
|
1378
|
|
|
|
|
1379
|
|
|
$output = geodir_sc_gd_listings_output($params); |
|
1380
|
|
|
|
|
1381
|
|
|
return $output; |
|
1382
|
|
|
} |
|
1383
|
|
|
add_shortcode('gd_listings', 'geodir_sc_gd_listings'); |
|
1384
|
|
|
|
|
1385
|
|
|
/** |
|
1386
|
|
|
* The CPT categories widget shortcode. |
|
1387
|
|
|
* |
|
1388
|
|
|
* This implements the functionality of the CPT categories widget shortcode for displaying |
|
1389
|
|
|
* all geodirectory categories. |
|
1390
|
|
|
* |
|
1391
|
|
|
* @since 1.5.5 |
|
1392
|
|
|
* @since 1.6.6 New parameters $no_cpt_filter &no_cat_filter added. |
|
1393
|
|
|
* |
|
1394
|
|
|
* @param array $atts { |
|
1395
|
|
|
* Attributes of the shortcode. |
|
1396
|
|
|
* |
|
1397
|
|
|
* @type string $title The title of the widget displayed. |
|
1398
|
|
|
* @type string $post_type Post type of listing. Default empty. |
|
1399
|
|
|
* @type bool $hide_empty Hide empty categories? Default empty. |
|
1400
|
|
|
* @type bool $show_count Show category count? Default empty. |
|
1401
|
|
|
* @type bool $hide_icon Hide category icon? Default empty. |
|
1402
|
|
|
* @type bool $cpt_left Show CPT on same line? Default empty. |
|
1403
|
|
|
* @type string $sort_by Categories sort by. 'az' or 'count'. Default 'count'. |
|
1404
|
|
|
* @type string|int $max_count Max no of sub-categories count. Default 'all'. |
|
1405
|
|
|
* @type string|int $max_level Max level of sub-categories depth. Default 1. |
|
1406
|
|
|
* @type bool $no_cpt_filter Disable filter current viewing post type. Default empty. |
|
1407
|
|
|
* @type bool $no_cat_filter Disable filter current viewing category. Default empty. |
|
1408
|
|
|
* @type string $before_widget HTML content to prepend to each widget's HTML output. |
|
1409
|
|
|
* Default is an opening list item element. |
|
1410
|
|
|
* @type string $after_widget HTML content to append to each widget's HTML output. |
|
1411
|
|
|
* Default is a closing list item element. |
|
1412
|
|
|
* @type string $before_title HTML content to prepend to the widget title when displayed. |
|
1413
|
|
|
* Default is an opening h3 element. |
|
1414
|
|
|
* @type string $after_title HTML content to append to the widget title when displayed. |
|
1415
|
|
|
* Default is a closing h3 element. |
|
1416
|
|
|
* } |
|
1417
|
|
|
* @param string $content The enclosed content. Optional. |
|
1418
|
|
|
* @return string HTML content to display CPT categories. |
|
1419
|
|
|
*/ |
|
1420
|
|
|
function geodir_sc_cpt_categories_widget($atts, $content = '') { |
|
1421
|
|
|
$defaults = array( |
|
1422
|
|
|
'title' => '', |
|
1423
|
|
|
'post_type' => '', // NULL for all |
|
1424
|
|
|
'hide_empty' => '', |
|
1425
|
|
|
'show_count' => '', |
|
1426
|
|
|
'hide_icon' => '', |
|
1427
|
|
|
'cpt_left' => '', |
|
1428
|
|
|
'sort_by' => 'count', |
|
1429
|
|
|
'max_count' => 'all', |
|
1430
|
|
|
'max_level' => '1', |
|
1431
|
|
|
'no_cpt_filter' => '', |
|
1432
|
|
|
'no_cat_filter' => '', |
|
1433
|
|
|
'before_widget' => '<section id="geodir_cpt_categories_widget-1" class="widget geodir-widget geodir_cpt_categories_widget geodir_sc_cpt_categories_widget">', |
|
1434
|
|
|
'after_widget' => '</section>', |
|
1435
|
|
|
'before_title' => '<h3 class="widget-title">', |
|
1436
|
|
|
'after_title' => '</h3>', |
|
1437
|
|
|
); |
|
1438
|
|
|
$params = shortcode_atts($defaults, $atts); |
|
1439
|
|
|
|
|
1440
|
|
|
/** |
|
1441
|
|
|
* Validate our incoming params |
|
1442
|
|
|
*/ |
|
1443
|
|
|
// Make sure we have an array |
|
1444
|
|
|
$params['post_type'] = !is_array($params['post_type']) && trim($params['post_type']) != '' ? explode(',', trim($params['post_type'])) : array(); |
|
1445
|
|
|
|
|
1446
|
|
|
// Validate the checkboxes used on the widget |
|
1447
|
|
|
$params['hide_empty'] = gdsc_to_bool_val($params['hide_empty']); |
|
1448
|
|
|
$params['show_count'] = gdsc_to_bool_val($params['show_count']); |
|
1449
|
|
|
$params['hide_icon'] = gdsc_to_bool_val($params['hide_icon']); |
|
1450
|
|
|
$params['cpt_left'] = gdsc_to_bool_val($params['cpt_left']); |
|
1451
|
|
|
|
|
1452
|
|
|
if ($params['max_count'] != 'all') { |
|
1453
|
|
|
$params['max_count'] = absint($params['max_count']); |
|
1454
|
|
|
} |
|
1455
|
|
|
|
|
1456
|
|
|
if ($params['max_level'] != 'all') { |
|
1457
|
|
|
$params['max_level'] = absint($params['max_level']); |
|
1458
|
|
|
} |
|
1459
|
|
|
|
|
1460
|
|
|
$params['no_cpt_filter'] = gdsc_to_bool_val($params['no_cpt_filter']); |
|
1461
|
|
|
$params['no_cat_filter'] = gdsc_to_bool_val($params['no_cat_filter']); |
|
1462
|
|
|
|
|
1463
|
|
|
$params['sort_by'] = $params['sort_by'] == 'az' ? 'az' : 'count'; |
|
1464
|
|
|
|
|
1465
|
|
|
ob_start(); |
|
1466
|
|
|
the_widget('geodir_cpt_categories_widget', $params, $params); |
|
1467
|
|
|
$output = ob_get_contents(); |
|
1468
|
|
|
ob_end_clean(); |
|
1469
|
|
|
|
|
1470
|
|
|
return $output; |
|
1471
|
|
|
} |
|
1472
|
|
|
add_shortcode('gd_cpt_categories', 'geodir_sc_cpt_categories_widget'); |
|
1473
|
|
|
|
|
1474
|
|
|
/** |
|
1475
|
|
|
* Responsive videos shortcode. |
|
1476
|
|
|
* |
|
1477
|
|
|
* Responsive videos requires a wrapper. This shortcode adds a wrapper for the iframe code |
|
1478
|
|
|
* |
|
1479
|
|
|
* @since 1.6.6 |
|
1480
|
|
|
* @param array $atts Not being used. |
|
1481
|
|
|
* @param string $content The iframe video code. Required. |
|
1482
|
|
|
* @return string HTML code. |
|
1483
|
|
|
*/ |
|
1484
|
|
|
function geodir_sc_responsive_videos($atts, $content) { |
|
1485
|
|
|
return '<div class="geodir-video-wrapper">'.$content.'</div>'; |
|
1486
|
|
|
} |
|
1487
|
|
|
add_shortcode('gd_video', 'geodir_sc_responsive_videos'); |