-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathgeodirectory_shortcodes.php
1487 lines (1306 loc) · 58.3 KB
/
geodirectory_shortcodes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Shortcode functions.
*
* @since 1.0.0
* @package GeoDirectory
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
require_once('geodirectory-functions/shortcode_functions.php');
add_shortcode('gd_add_listing', 'geodir_sc_add_listing');
/**
* The geodirectory add listing shortcode.
*
* This implements the functionality of the shortcode for displaying geodirectory add listing page form.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $atts {
* Attributes of the shortcode.
*
* @type string $pid Post ID. If passed post will be edited. Default empty.
* @type string $listing_type Post type of listing. Default gd_place.
* @type string $login_msg Message to display when user not logged in.
* @type bool $show_login Do you want to display login widget when user not logged in?. Default: false.
*
* }
* @return string Add listing page HTML.
*/
function geodir_sc_add_listing($atts)
{
ob_start();
$defaults = array(
'pid' => '',
'listing_type' => 'gd_place',
'login_msg' => __('You must login to post.', 'geodirectory'),
'show_login' => false,
);
$params = shortcode_atts($defaults, $atts);
foreach ($params as $key => $value) {
$_REQUEST[$key] = $value;
}
$user_id = get_current_user_id();
if (!$user_id) {
echo $params['login_msg'];
if ($params['show_login']) {
echo "<br />";
$defaults = array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
);
geodir_loginwidget_output($defaults, $defaults);
}
} else {
// Add listing page will be used if shortcode is detected in page content, no need to call it here
}
$output = ob_get_contents();
ob_end_clean();
return $output;
}
/**
* The geodirectory home page map shortcode.
*
* This implements the functionality of the shortcode for displaying map on home page.
*
* @since 1.0.0
* @since 1.5.2 Added TERRAIN map type.
* @package GeoDirectory
* @param array $atts {
* Attributes of the shortcode.
*
* @type string $width Map width in pixels. Default 960.
* @type string $height Map height in pixels. Default 425.
* @type string $maptype Map type. Default ROADMAP. Can be ROADMAP | SATELLITE | HYBRID | TERRAIN.
* @type string $zoom The zoom level of the map. Between 1-19. Default 13.
* @type string $autozoom True if the map should autozoom, false if not.
* @type string $child_collapse True if the map should collapse the categories, false if not.
* @type string $scrollwheel True to allow scroll wheel to scroll map or false if not.
* @type bool $marker_cluster Enable marker cluster? Default: false.
*
* }
* @return string Map HTML.
*/
function geodir_sc_home_map($atts)
{
ob_start();
$defaults = array(
'width' => '960',
'height' => '425',
'maptype' => 'ROADMAP',
'zoom' => '13',
'autozoom' => '',
'child_collapse' => '0',
'scrollwheel' => '0',
'marker_cluster' => false,
'latitude' => '',
'longitude' => ''
);
$params = shortcode_atts($defaults, $atts);
$params = gdsc_validate_map_args($params);
$map_args = array(
'map_canvas_name' => 'gd_home_map',
'latitude' => $params['latitude'],
'longitude' => $params['longitude'],
/**
* Filter the widget width of the map on home/listings page.
*
* @since 1.0.0
* @param mixed(string|int|float) $params['width'] The map width.
*/
'width' => apply_filters('widget_width', $params['width']),
/**
* Filter the widget height of the map on home/listings page.
*
* @since 1.0.0
* @param mixed(string|int|float) $params['height'] The map height.
*/
'height' => apply_filters('widget_heigh', $params['height']),
/**
* Filter the widget maptype of the map on home/listings page.
*
* @since 1.0.0
* @since 1.5.2 Added TERRAIN map type.
* @param string $params['maptype'] The map type. Can be ROADMAP | SATELLITE | HYBRID | TERRAIN.
*/
'maptype' => apply_filters('widget_maptype', $params['maptype']),
/**
* Filter the widget scrollwheel value of the map on home/listings page.
*
* Should the scrollwheel zoom the map or not.
*
* @since 1.0.0
* @param bool $params['scrollwheel'] True to allow scroll wheel to scroll map or false if not.
*/
'scrollwheel' => apply_filters('widget_scrollwheel', $params['scrollwheel']),
/**
* Filter the widget zoom level of the map on home/listings page.
*
* @since 1.0.0
* @param int $params['zoom'] The zoom level of the map. Between 1-19.
*/
'zoom' => apply_filters('widget_zoom', $params['zoom']),
/**
* Filter the widget auto zoom value of the map on home/listings page.
*
* If the map should autozoom to fit the markers shown.
*
* @since 1.0.0
* @param bool $params['autozoom'] True if the map should autozoom, false if not.
*/
'autozoom' => apply_filters('widget_autozoom', $params['autozoom']),
/**
* Filter the widget child_collapse value of the map on home/listings page.
*
* If the map should auto collapse the child categories if the category bar is present.
*
* @since 1.0.0
* @param bool $params['child_collapse'] True if the map should collapse the categories, false if not.
*/
'child_collapse' => apply_filters('widget_child_collapse', $params['child_collapse']),
'enable_cat_filters' => true,
'enable_text_search' => true,
'enable_post_type_filters' => true,
/**
* Filter the widget enable_location_filters value of the map on home/listings page.
*
* This is used when the location addon is used.
*
* @since 1.0.0
* @param bool $val True if location filters should be used, false if not.
*/
'enable_location_filters' => apply_filters('geodir_home_map_enable_location_filters', false),
'enable_jason_on_load' => false,
'enable_marker_cluster' => false,
'enable_map_resize_button' => true,
'map_class_name' => 'geodir-map-home-page',
'is_geodir_home_map_widget' => true,
);
// Add marker cluster
if (isset($params['marker_cluster']) && gdsc_to_bool_val($params['marker_cluster']) && defined('GDCLUSTER_VERSION')) {
$map_args['enable_marker_cluster'] = true;
if(get_option('geodir_marker_cluster_type')) {
if ($map_args['autozoom']) {
$map_args['enable_marker_cluster_no_reposition'] = false;
} else {
$map_args['enable_marker_cluster_no_reposition'] = true;
}
$map_args['enable_marker_cluster_server'] = true ;
}
} else {
$map_args['enable_marker_cluster'] = false;
}
// if lat and long set in shortcode, hack it so the map is not repositioned
if(!empty($params['latitude']) && !empty($params['longitude']) ){
$map_args['enable_marker_cluster_no_reposition'] = true;
}
geodir_draw_map($map_args);
add_action('wp_footer', 'geodir_home_map_add_script', 100);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode('gd_homepage_map', 'geodir_sc_home_map');
add_shortcode('gd_listing_map', 'geodir_sc_listing_map');
/**
* The geodirectory listing map shortcode.
*
* This implements the functionality of the shortcode for displaying listing map.
*
* @since 1.0.0
* @since 1.5.2 Added TERRAIN for $maptype attribute.
* @since 1.6.16 CHANGED: New parameters post_type, category & event_type added.
* @since 1.6.18 FIXED: For CPT other then "gd_place" not working.
* @package GeoDirectory
* @global object $post The current post object.
* @param array $atts {
* Attributes of the shortcode.
*
* @type string $width Map width in pixels. Default 294.
* @type string $height Map height in pixels. Default 370.
* @type string $maptype Map type. Default ROADMAP. Can be ROADMAP | SATELLITE | HYBRID | TERRAIN.
* @type string $zoom The zoom level of the map. Between 1-19. Default 13.
* @type string $autozoom True if the map should autozoom, false if not.
* @type bool $sticky True if should be sticky, false if not
* @type string $showall Show all listings on map? (not just page list). Default 0.
* @type string $child_collapse True if the map should collapse the categories, false if not.
* @type string $scrollwheel True to allow scroll wheel to scroll map or false if not.
* @type bool $marker_cluster Enable marker cluster? Default: false.
* @type string $post_type Post type of listing. Default. gd_place.
* @type string $category Category ids to filter listings. Ex: 1,3. Default. 0.
* @type string $event_type The events filter.(for gd_event CPT only) Default: all.
*
* }
* @return string Map HTML.
*/
function geodir_sc_listing_map($atts) {
// if some params are set then we need a new query, if not then we can use the main query
if( isset($atts['post_type']) || isset($atts['category']) || isset($atts['event_type']) ) {
global $add_post_in_marker_array, $gd_sc_map_params;
$backup_globals = array();
$backup_globals['add_post_in_marker_array'] = $add_post_in_marker_array;
$backup_globals['gd_sc_map_params'] = $gd_sc_map_params;
$defaults = array(
'width' => '294',
'height' => '370',
'zoom' => '13',
'autozoom' => '',
'sticky' => '',
'showall' => '0',
'scrollwheel' => '0',
'maptype' => 'ROADMAP',
'child_collapse' => 0,
'marker_cluster' => false,
'post_type' => 'gd_place',
'category' => '0',
'event_type' => 'all'
);
$params = shortcode_atts( $defaults, $atts );
if ( ! ( gdsc_is_post_type_valid( $params['post_type'] ) ) ) {
$params['post_type'] = 'gd_place';
}
// Validate the selected category/ies - Grab the current list based on post_type
$category_taxonomy = geodir_get_taxonomies( $params['post_type'] );
$categories = get_terms( $category_taxonomy, array(
'orderby' => 'count',
'order' => 'DESC',
'fields' => 'ids'
) );
// Make sure we have an array
if ( ! ( is_array( $params['category'] ) ) ) {
$params['category'] = explode( ',', $params['category'] );
}
// Array_intersect returns only the items in $params['category'] that are also in our category list
// Otherwise it becomes empty and later on that will mean "All"
$params['category'] = array_intersect( $params['category'], $categories );
if ( $params['post_type'] == 'gd_event' ) {
$params['event_type'] = gdsc_validate_list_filter_choice( $params['event_type'] );
}
$params = gdsc_validate_map_args( $params );
$gd_sc_map_params = $params;
$query_args = array(
'posts_per_page' => 1000000, //@todo kiran why was this added?
'is_geodir_loop' => true,
'gd_location' => false,
'post_type' => $params['post_type'],
);
if ( ! empty( $params['category'] ) && isset( $params['category'][0] ) && (int) $params['category'][0] != 0 ) {
$category_taxonomy = geodir_get_taxonomies( $params['post_type'] );
######### WPML #########
if ( geodir_wpml_is_taxonomy_translated( $category_taxonomy[0] ) ) {
$category = gd_lang_object_ids( $params['category'], $category_taxonomy[0] );
}
######### WPML #########
$tax_query = array(
'taxonomy' => $category_taxonomy[0],
'field' => 'id',
'terms' => $params['category']
);
$query_args['tax_query'] = array( $tax_query );
}
$add_post_in_marker_array = true;
if ( $params['post_type'] == 'gd_event' && function_exists( 'geodir_event_get_widget_events' ) ) {
global $geodir_event_widget_listview;
$geodir_event_widget_listview = true;
$query_args['geodir_event_type'] = $params['event_type'];
$listings = geodir_event_get_widget_events( $query_args );
$geodir_event_widget_listview = false;
} else {
$listings = geodir_get_widget_listings( $query_args );
}
if ( ! empty( $listings ) ) {
foreach ( $listings as $listing ) {
create_marker_jason_of_posts( $listing );
}
}
ob_start();
add_action( 'wp_head', 'init_listing_map_script' ); // Initialize the map object and marker array
add_action( 'the_post', 'create_list_jsondata' ); // Add marker in json array
add_action( 'wp_footer', 'show_listing_widget_map' ); // Show map for listings with markers
$default_location = geodir_get_default_location();
$map_args = array(
'map_canvas_name' => 'gd_listing_map',
'width' => $params['width'],
'height' => $params['height'],
'zoom' => $params['zoom'],
'autozoom' => $params['autozoom'],
'sticky' => $params['sticky'],
'showall' => $params['showall'],
'scrollwheel' => $params['scrollwheel'],
'maptype' => $params['maptype'],
'child_collapse' => 0,
'enable_cat_filters' => false,
'enable_text_search' => false,
'enable_post_type_filters' => false,
'enable_location_filters' => false,
'enable_jason_on_load' => true,
'ajax_url' => geodir_get_ajax_url(),
'latitude' => isset( $default_location->city_latitude ) ? $default_location->city_latitude : '',
'longitude' => isset( $default_location->city_longitude ) ? $default_location->city_longitude : '',
'streetViewControl' => true,
'showPreview' => '0',
'maxZoom' => 21,
'bubble_size' => 'small',
);
if ( is_single() ) {
global $post;
if ( isset( $post->post_latitude ) ) {
$map_args['latitude'] = $post->post_latitude;
$map_args['longitude'] = $post->post_longitude;
}
$map_args['map_class_name'] = 'geodir-map-listing-page-single';
} else {
$map_args['map_class_name'] = 'geodir-map-listing-page';
}
// Add marker cluster
if ( isset( $params['marker_cluster'] ) && gdsc_to_bool_val( $params['marker_cluster'] ) && defined( 'GDCLUSTER_VERSION' ) ) {
$map_args['enable_marker_cluster'] = true;
} else {
$map_args['enable_marker_cluster'] = false;
}
geodir_draw_map( $map_args );
$output = ob_get_contents();
ob_end_clean();
foreach ( $backup_globals as $global => $value ) {
${$global} = $value;
}
return $output;
}else{
ob_start();
add_action('wp_head', 'init_listing_map_script'); // Initialize the map object and marker array
add_action('the_post', 'create_list_jsondata'); // Add marker in json array
add_action('wp_footer', 'show_listing_widget_map'); // Show map for listings with markers
$defaults = array(
'width' => '294',
'height' => '370',
'zoom' => '13',
'autozoom' => '',
'sticky' => '',
'showall' => '0',
'scrollwheel' => '0',
'maptype' => 'ROADMAP',
'child_collapse' => 0,
'marker_cluster' => false
);
$params = shortcode_atts($defaults, $atts);
$params = gdsc_validate_map_args($params);
$map_args = array(
'map_canvas_name' => 'gd_listing_map',
'width' => $params['width'],
'height' => $params['height'],
'zoom' => $params['zoom'],
'autozoom' => $params['autozoom'],
'sticky' => $params['sticky'],
'showall' => $params['showall'],
'scrollwheel' => $params['scrollwheel'],
'child_collapse' => 0,
'enable_cat_filters' => false,
'enable_text_search' => false,
'enable_post_type_filters' => false,
'enable_location_filters' => false,
'enable_jason_on_load' => true,
);
if (is_single()) {
global $post;
$map_default_lat = $address_latitude = $post->post_latitude;
$map_default_lng = $address_longitude = $post->post_longitude;
$mapview = $post->post_mapview;
$map_args['zoom'] = $post->post_mapzoom;
$map_args['map_class_name'] = 'geodir-map-listing-page-single';
} else {
$default_location = geodir_get_default_location();
$map_default_lat = isset($default_location->city_latitude) ? $default_location->city_latitude : '';
$map_default_lng = isset($default_location->city_longitude) ? $default_location->city_longitude : '';
$map_args['map_class_name'] = 'geodir-map-listing-page';
if ( geodir_is_page( 'search' ) ) {
$map_default_lat = '';
$map_default_lng = '';
if ( isset( $_REQUEST['sgeo_lat'] ) && isset( $_REQUEST['sgeo_lon'] ) ) {
$map_default_lat = (float)sanitize_text_field( $_REQUEST['sgeo_lat'] );
$map_default_lng = (float)sanitize_text_field( $_REQUEST['sgeo_lon'] );
}
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' ) ) {
$location = geodir_get_location_by_id( '', (int)$_REQUEST['set_location_val'] );
if ( ! empty( $location ) ) {
$map_default_lat = $location->city_latitude;
$map_default_lng = $location->city_longitude;
}
}
}
}
if (empty($mapview)) {
$mapview = 'ROADMAP';
}
// Set default map options
$map_args['ajax_url'] = geodir_get_ajax_url();
$map_args['latitude'] = $map_default_lat;
$map_args['longitude'] = $map_default_lng;
$map_args['streetViewControl'] = true;
$map_args['maptype'] = $mapview;
$map_args['showPreview'] = '0';
$map_args['maxZoom'] = 21;
$map_args['bubble_size'] = 'small';
// Add marker cluster
if (isset($params['marker_cluster']) && gdsc_to_bool_val($params['marker_cluster']) && defined('GDCLUSTER_VERSION')) {
$map_args['enable_marker_cluster'] = true;
} else {
$map_args['enable_marker_cluster'] = false;
}
geodir_draw_map($map_args);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
}
add_shortcode('gd_listing_slider', 'geodir_sc_listing_slider');
/**
* The geodirectory listing slider shortcode.
*
* This implements the functionality of the shortcode for displaying listing slider.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $atts {
* Attributes of the shortcode.
*
* @type string $animation Controls the animation type, "fade" or "slide". Default. slide.
* @type int $animation_loop Gives the slider a seamless infinite loop. Default. 0.
* @type int $animation_speed Set the speed of animations, in milliseconds. Default. 600.
* @type string $category Filter by term. Can be any valid term. Default. 0.
* @type int $direction_nav Enable previous/next arrow navigation?. Can be 1 or 0. Default. 0.
* @type string $order_by Order by filter. Default. latest.
* @type string $post_number Number of listings to display. Default. 5.
* @type string $post_type Post type of listing. Default. gd_place.
* @type string $show_featured_only Do you want to display only featured listing? Can be 1 or 0. Default. Empty.
* @type string $show_title Do you want to display title? Can be 1 or 0. Default. Empty.
* @type string $slideshow Setup a slideshow for the slider to animate automatically. Default. 0.
* @type int $slideshow_speed Set the speed of the slideshow cycling, in milliseconds. Default. 5000.
* @type string $title Slider title. Default. Empty.
*
* }
* @return string Slider HTML.
*/
function geodir_sc_listing_slider($atts)
{
ob_start();
$defaults = array(
'post_type' => 'gd_place',
'category' => '0',
'post_number' => '5',
'slideshow' => '0',
'animation_loop' => 0,
'direction_nav' => 0,
'slideshow_speed' => 5000,
'animation_speed' => 600,
'animation' => 'slide',
'order_by' => 'latest',
'show_title' => '',
'show_featured_only' => '',
'title' => '',
);
$params = shortcode_atts($defaults, $atts);
/*
*
* Now we begin the validation of the attributes.
*/
// Check we have a valid post_type
if (!(gdsc_is_post_type_valid($params['post_type']))) {
$params['post_type'] = 'gd_place';
}
// Check we have a valid sort_order
$params['order_by'] = gdsc_validate_sort_choice($params['order_by']);
// Match the chosen animation to our options
$animation_list = array('slide', 'fade');
if (!(in_array($params['animation'], $animation_list))) {
$params['animation'] = 'slide';
}
// Post_number needs to be a positive integer
$params['post_number'] = absint($params['post_number']);
if (0 == $params['post_number']) {
$params['post_number'] = 1;
}
// Manage the entered categories
if (0 != $params['category'] || '' != $params['category']) {
$params['category'] = gdsc_manage_category_choice($params['post_type'], $params['category']);
}
// Convert show_title to a bool
$params['show_title'] = intval(gdsc_to_bool_val($params['show_title']));
// Convert show_featured_only to a bool
$params['show_featured_only'] = intval(gdsc_to_bool_val($params['show_featured_only']));
/*
* Hopefully all attributes are now valid, and safe to pass forward
*/
// redeclare vars after validation
if (isset($params['direction_nav'])) {
$params['directionNav'] = $params['direction_nav'];
}
if (isset($params['animation_loop'])) {
$params['animationLoop'] = $params['animation_loop'];
}
if (isset($params['slideshow_speed'])) {
$params['slideshowSpeed'] = $params['slideshow_speed'];
}
if (isset($params['animation_speed'])) {
$params['animationSpeed'] = $params['animation_speed'];
}
if (isset($params['order_by'])) {
$params['list_sort'] = $params['order_by'];
}
$query_args = array(
'post_number' => $params['post_number'],
'is_geodir_loop' => true,
'post_type' => $params['post_type'],
'order_by' => $params['order_by']
);
if (1 == $params['show_featured_only']) {
$query_args['show_featured_only'] = 1;
}
if (0 != $params['category'] && '' != $params['category']) {
$category_taxonomy = geodir_get_taxonomies($params['post_type']);
$tax_query = array(
'taxonomy' => $category_taxonomy[0],
'field' => 'id',
'terms' => $params['category'],
);
$query_args['tax_query'] = array($tax_query);
}
$defaults = array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
);
$query_args = array_merge($query_args, $params);
geodir_listing_slider_widget_output($defaults, $query_args);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode('gd_login_box', 'geodir_sc_login_box');
/**
* The geodirectory login box shortcode.
*
* This implements the functionality of the shortcode for displaying login box.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $atts {
* Attributes of the shortcode.
*
* @type string $before_widget HTML content to prepend to each widget's HTML output. Default. Empty.
* @type string $after_widget HTML content to append to each widget's HTML output. Default. Empty.
* @type string $before_title HTML content to prepend to the title when displayed. Default. Empty.
* @type string $after_title HTML content to append to the title when displayed. Default. Empty.
*
* }
* @return string Login box HTML.
*/
function geodir_sc_login_box($atts)
{
ob_start();
$defaults = array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
);
geodir_loginwidget_output($defaults, $defaults);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode('gd_popular_post_category', 'geodir_sc_popular_post_category');
/**
* The geodirectory popular post category shortcode.
*
* This implements the functionality of the shortcode for displaying popular post category.
*
* @since 1.0.0
* @since 1.5.1 Added default_post_type parameter.
* @since 1.6.9 Added parent_only parameter.
* @package GeoDirectory
* @global string $geodir_post_category_str The geodirectory post category.
* @param array $atts {
* Attributes of the shortcode.
*
* @type string $before_widget HTML content to prepend to each widget's HTML output. Default. Empty.
* @type string $after_widget HTML content to append to each widget's HTML output. Default. Empty.
* @type string $before_title HTML content to prepend to the title when displayed. Default. Empty.
* @type string $after_title HTML content to append to the title when displayed. Default. Empty.
* @type int $category_limit Number of categories to display. Default. 15.
* @type string $title Widget title. Default. Empty.
* @type string $default_post_type Default post type. Default. Empty.
* @type bool $parent_only True to show parent categories only. Default False.
*
* }
* @return string Popular post category HTML.
*/
function geodir_sc_popular_post_category($atts)
{
ob_start();
global $geodir_post_category_str;
$defaults = array(
'category_limit' => 15,
'category_restrict' => false,
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
'title' => '',
'default_post_type' => '',
'parent_only' => false,
);
$params = shortcode_atts($defaults, $atts, 'popular_post_category');
$params['category_limit'] = absint($params['category_limit']);
$params['default_post_type'] = gdsc_is_post_type_valid($params['default_post_type']) ? $params['default_post_type'] : '';
$params['parent_only'] = gdsc_to_bool_val($params['parent_only']);
geodir_popular_post_category_output($params, $params);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode('gd_popular_post_view', 'geodir_sc_popular_post_view');
/**
* The geodirectory popular post view shortcode.
*
* This implements the functionality of the shortcode for displaying popular post view.
*
* @since 1.0.0
* @since 1.6.18 [gd_popular_post_view] shortcode character_count=0 not working - FIXED
* @since 1.6.22 $hide_if_empty parameter added.
* @package GeoDirectory
* @param array $atts {
* Attributes of the shortcode.
*
* @type string $add_location_filter Filter listings using current location. Default 0.
* @type string $before_widget HTML content to prepend to each widget's HTML output. Default. Empty.
* @type string $after_widget HTML content to append to each widget's HTML output. Default. Empty.
* @type string $before_title HTML content to prepend to the title when displayed. Default. <h3 class="widget-title">.
* @type string $after_title HTML content to append to the title when displayed. Default. </h3>.
* @type string $category Category ids to filter listings. Ex: 1,3. Default. 0.
* @type string $category_title Category title. Default. Empty.
* @type string $character_count The excerpt length. Default. 20.
* @type string $layout Layout to display listing. Should be gridview_onehalf, gridview_onethird,
* gridview_onefourth, gridview_onefifth, list. Default 'gridview_onehalf'. Default. gridview_onehalf.
* @type string $list_sort Sort by. Default. latest.
* @type string $listing_width Width of the listing in %. Default. Empty.
* @type string $post_number No. of post to display. Default. 5.
* @type string $post_type Post type of listing. Default. gd_place.
* @type string $show_featured_only Display only featured listings. Default. 0.
* @type string $show_special_only Display only special offers listings. Default. 0.
* @type string $title Widget title. Default. Empty.
* @type string $use_viewing_post_type Filter using viewing post type. Default. 1.
* @type string $with_pics_only Only display listings which has image available. Default empty. Default. 0.
* @type string $with_videos_only Only display listings which has video available. Default. 0.
* @type string $hide_if_empty Hide widget if no listings found. Default. 0.
*
* }
* @return string Popular post view HTML.
*/
function geodir_sc_popular_post_view($atts)
{
ob_start();
$defaults = array(
'post_type' => 'gd_place',
'category' => '0',
'post_number' => '5',
'layout' => 'gridview_onehalf',
'add_location_filter' => '0',
'list_sort' => 'latest',
'use_viewing_post_type' => '1',
'character_count' => '20',
'listing_width' => '',
'show_featured_only' => '0',
'show_special_only' => '0',
'with_pics_only' => '0',
'with_videos_only' => '0',
'hide_if_empty' => '0',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
'title' => '',
'category_title' => '',
);
$params = shortcode_atts($defaults, $atts);
/**
* Validate our incoming params
*/
// Validate the selected post type, default to gd_place on fail
if (!(gdsc_is_post_type_valid($params['post_type']))) {
$params['post_type'] = 'gd_place';
}
// Validate the selected category/ies - Grab the current list based on post_type
$category_taxonomy = geodir_get_taxonomies($params['post_type']);
$categories = get_terms($category_taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'fields' => 'ids'));
// Make sure we have an array
if (!(is_array($params['category']))) {
$params['category'] = explode(',', $params['category']);
}
// Array_intersect returns only the items in $params['category'] that are also in our category list
// Otherwise it becomes empty and later on that will mean "All"
$params['category'] = array_intersect($params['category'], $categories);
// Post_number needs to be a positive integer
$params['post_number'] = absint($params['post_number']);
if (0 == $params['post_number']) {
$params['post_number'] = 1;
}
// Validate our layout choice
// Outside of the norm, I added some more simple terms to match the existing
// So now I just run the switch to set it properly.
$params['layout'] = gdsc_validate_layout_choice($params['layout']);
// Validate our sorting choice
$params['list_sort'] = gdsc_validate_sort_choice($params['list_sort'], $params['post_type']);
// Validate character_count
if ($params['character_count'] !== '') {
$params['character_count'] = absint($params['character_count']);
}
// Validate Listing width, used in the template widget-listing-listview.php
// The context is in width=$listing_width% - So we need a positive number between 0 & 100
$params['listing_width'] = gdsc_validate_listing_width($params['listing_width']);
// Validate the checkboxes used on the widget
$params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']);
$params['show_featured_only'] = gdsc_to_bool_val($params['show_featured_only']);
$params['show_special_only'] = gdsc_to_bool_val($params['show_special_only']);
$params['with_pics_only'] = gdsc_to_bool_val($params['with_pics_only']);
$params['with_videos_only'] = gdsc_to_bool_val($params['with_videos_only']);
$params['use_viewing_post_type'] = gdsc_to_bool_val($params['use_viewing_post_type']);
$params['hide_if_empty'] = gdsc_to_bool_val($params['hide_if_empty']);
/**
* End of validation
*/
geodir_popular_postview_output($params, $params);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode('gd_recent_reviews', 'geodir_sc_recent_reviews');
/**
* The geodirectory recent reviews shortcode.
*
* This implements the functionality of the shortcode for displaying recent reviews.
*
* @since 1.0.0
* @since 1.5.0 New title attribute added.
* @package GeoDirectory
* @param array $atts {
* Attributes of the shortcode.
*
* @type string $title The title displayed above recent reviews. Default empty.
* @type int $count Number of reviews you want to display. Default. 5.
*
* }
* @return string Recent reviews HTML.
*/
function geodir_sc_recent_reviews($atts) {
ob_start();
$defaults = array(
'title' => '',
'count' => 5,
);
$params = shortcode_atts($defaults, $atts);
$count = absint($params['count']);
if (0 == $count) {
$count = 1;
}
$title = !empty($params['title']) ? __($params['title'], 'geodirectory') : '';
$comments_li = geodir_get_recent_reviews(30, $count, 100, false);
if ($comments_li) {
if ($title != '') { ?>
<h3 class="geodir-sc-recent-reviews-title widget-title"><?php echo $title; ?></h3>
<?php } ?>
<div class="geodir_sc_recent_reviews_section">
<ul class="geodir_sc_recent_reviews"><?php echo $comments_li; ?></ul>
</div>
<?php
}
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode('gd_related_listings', 'geodir_sc_related_listings');
/**
* The geodirectory related listing widget shortcode.
*
* This implements the functionality of the shortcode for displaying related listing widget.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $atts {
* Attributes of the shortcode.
*
* @type int $add_location_filter Filter listings using current location. Default 0.
* @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>.
* @type int $character_count The excerpt length Default. 20.
* @type int $is_widget Is this a widget? Default. 1.
* @type string $layout Layout to display listing. Should be gridview_onehalf, gridview_onethird,
* gridview_onefourth, gridview_onefifth, list. Default 'gridview_onehalf'. Default. gridview_onehalf.
* @type string $list_sort Sort by. Default. latest.
* @type string $listing_width Width of the listing in %. Default. Empty.
* @type int $post_number No. of post to display. Default. 5.
* @type string $relate_to Type to use for making relation. Can be tags or category. Default. category.
*
* }
* @return string Related widget HTML.
*/
function geodir_sc_related_listings($atts)
{
ob_start();
$defaults = array(
'post_number' => 5,
'relate_to' => 'category',
'layout' => 'gridview_onehalf',
'add_location_filter' => 0,
'listing_width' => '',
'list_sort' => 'latest',
'character_count' => 20,
'is_widget' => 1,
'before_title' => '<style type="text/css">.geodir_category_list_view li{margin:0px!important}</style>',
);
// The "before_title" code is an ugly & terrible hack. But it works for now. I should enqueue a new stylesheet.
$params = shortcode_atts($defaults, $atts);
/**
* Begin validating parameters
*/
// Validate that post_number is a number and is 1 or higher
$params['post_number'] = absint($params['post_number']);
if (0 === $params['post_number']) {
$params['post_number'] = 1;
}
// Validate relate_to - only category or tags