-
Notifications
You must be signed in to change notification settings - Fork 30
/
custom_functions.php
3219 lines (2781 loc) · 111 KB
/
custom_functions.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
/**
* Custom functions
*
* @since 1.0.0
* @package GeoDirectory
*/
/**
* Front end listing view template selection.
*
* This function adds a drop down in front end listing page for selecting view template. Ex: list view, 2 column grid
* view, etc.
*
* @since 1.0.0
* @package GeoDirectory
*
* @global object $gd_session GeoDirectory Session object.
*/
function geodir_list_view_select() {
global $gd_session;
?>
<script type="text/javascript">
function geodir_list_view_select(list) {
//alert(listval);
val = list.value;
if (!val) {
return;
}
var listSel = jQuery(list).parent().parent().next('.geodir_category_list_view');
if (val != 1) {
jQuery(listSel).children('li').addClass('geodir-gridview');
jQuery(listSel).children('li').removeClass('geodir-listview');
} else {
jQuery(listSel).children('li').addClass('geodir-listview');
}
if (val == 1) {
jQuery(listSel).children('li').removeClass('geodir-gridview gridview_onehalf gridview_onethird gridview_onefourth gridview_onefifth');
}
else if (val == 2) {
jQuery(listSel).children('li').switchClass('gridview_onethird gridview_onefourth gridview_onefifth', 'gridview_onehalf', 600);
}
else if (val == 3) {
jQuery(listSel).children('li').switchClass('gridview_onehalf gridview_onefourth gridview_onefifth', 'gridview_onethird', 600);
}
else if (val == 4) {
jQuery(listSel).children('li').switchClass('gridview_onehalf gridview_onethird gridview_onefifth', 'gridview_onefourth', 600);
}
else if (val == 5) {
jQuery(listSel).children('li').switchClass('gridview_onehalf gridview_onethird gridview_onefourth', 'gridview_onefifth', 600);
}
jQuery.post("<?php echo geodir_get_ajax_url();?>&gd_listing_view=" + val, function (data) {
//alert(data );
});
}
</script>
<div class="geodir-list-view-select">
<select name="gd_list_view" id="gd_list_view" onchange="geodir_list_view_select(this);">
<?php $listing_view = (int) $gd_session->get( 'gd_listing_view' ); ?>
<option value=""><?php _e( 'View:', 'geodirectory' ); ?></option>
<option
value="1" <?php selected( 1, $listing_view ); ?>><?php _e( 'View: List', 'geodirectory' ); ?></option>
<option
value="2" <?php selected( 2, $listing_view ); ?>><?php _e( 'View: Grid 2', 'geodirectory' ); ?></option>
<option
value="3" <?php selected( 3, $listing_view ); ?>><?php _e( 'View: Grid 3', 'geodirectory' ); ?></option>
<option
value="4" <?php selected( 4, $listing_view ); ?>><?php _e( 'View: Grid 4', 'geodirectory' ); ?></option>
<option
value="5" <?php selected( 5, $listing_view ); ?>><?php _e( 'View: Grid 5', 'geodirectory' ); ?></option>
</select>
</div>
<?php
}
add_action( 'geodir_before_listing', 'geodir_list_view_select', 100 );
/**
* Limit the listing excerpt.
*
* This function limits excerpt characters and display "read more" link.
*
* @since 1.0.0
* @package GeoDirectory
*
* @param string|int $charlength The character length.
*
* @global object $post The current post object.
* @return string The modified excerpt.
*/
function geodir_max_excerpt( $charlength ) {
global $post;
if ( $charlength == '0' ) {
return;
}
$out = '';
$temp_post = $post;
$excerpt = get_the_excerpt();
$charlength ++;
$excerpt_more = function_exists( 'geodirf_excerpt_more' ) ? geodirf_excerpt_more( '' ) : geodir_excerpt_more( '' );
if ( geodir_utf8_strlen( $excerpt ) > $charlength ) {
if ( geodir_utf8_strlen( $excerpt_more ) > 0 && geodir_utf8_strpos( $excerpt, $excerpt_more ) !== false ) {
$excut = - ( geodir_utf8_strlen( $excerpt_more ) );
$subex = geodir_utf8_substr( $excerpt, 0, $excut );
if ( $charlength > 0 && geodir_utf8_strlen( $subex ) > $charlength ) {
$subex = geodir_utf8_substr( $subex, 0, $charlength );
}
$out .= $subex;
} else {
$subex = geodir_utf8_substr( $excerpt, 0, $charlength - 5 );
$exwords = explode( ' ', $subex );
$excut = - ( geodir_utf8_strlen( $exwords[ count( $exwords ) - 1 ] ) );
if ( $excut < 0 ) {
$out .= geodir_utf8_substr( $subex, 0, $excut );
} else {
$out .= $subex;
}
}
$out .= ' <a class="excerpt-read-more" href="' . get_permalink() . '" title="' . get_the_title() . '">';
/**
* Filter excerpt read more text.
*
* @since 1.0.0
*/
$out .= apply_filters( 'geodir_max_excerpt_end', __( 'Read more [...]', 'geodirectory' ) );
$out .= '</a>';
} else {
if ( geodir_utf8_strlen( $excerpt_more ) > 0 && geodir_utf8_strpos( $excerpt, $excerpt_more ) !== false ) {
$excut = - ( geodir_utf8_strlen( $excerpt_more ) );
$out .= geodir_utf8_substr( $excerpt, 0, $excut );
$out .= ' <a class="excerpt-read-more" href="' . get_permalink() . '" title="' . get_the_title() . '">';
/**
* Filter excerpt read more text.
*
* @since 1.0.0
*/
$out .= apply_filters( 'geodir_max_excerpt_end', __( 'Read more [...]', 'geodirectory' ) );
$out .= '</a>';
} else {
$out .= $excerpt;
}
}
$post = $temp_post;
return $out;
}
/**
* Returns package information as an objects.
*
* @since 1.0.0
* @package GeoDirectory
*
* @param array $package_info Package info array.
* @param object|string $post The post object.
* @param string $post_type The post type.
*
* @return object Returns filtered package info as an object.
*/
function geodir_post_package_info( $package_info, $post = '', $post_type = '' ) {
$package_info['pid'] = 0;
$package_info['days'] = 0;
$package_info['amount'] = 0;
$package_info['is_featured'] = 0;
$package_info['image_limit'] = '';
$package_info['google_analytics'] = 1;
$package_info['sendtofriend'] = 0; // @depreciated since 1.6.26
/**
* Filter listing package info.
*
* @since 1.0.0
*
* @param array $package_info {
* Attributes of the package_info.
*
* @type int $pid Package ID. Default 0.
* @type int $days Package validity in Days. Default 0.
* @type int $amount Package amount. Default 0.
* @type int $is_featured Is this featured package? Default 0.
* @type string $image_limit Image limit for this package. Default "".
* @type int $google_analytics Add analytics to this package. Default 1.
* @type int $sendtofriend Send to friend. Default 0.
*
* }
* @param object|string $post The post object.
* @param string $post_type The post type.
*/
return (object) apply_filters( 'geodir_post_package_info', $package_info, $post, $post_type );
}
/**
* Send enquiry to listing author
*
* This function let the user to send Enquiry to listing author. If listing author email not available, then admin
* email will be used. Email content will be used WP Admin -> Geodirectory -> Notifications -> Other Emails -> Email
* enquiry
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
*
* @param array $request {
* The submitted form fields as an array.
*
* @type string $sendact Enquiry type. Default "send_inqury".
* @type string $pid Post ID.
* @type string $inq_name Sender name.
* @type string $inq_email Sender mail.
* @type string $inq_phone Sender phone.
* @type string $inq_msg Email message.
*
* }
*/
function geodir_send_inquiry( $request ) {
global $wpdb;
// strip slashes from text
$request = ! empty( $request ) ? stripslashes_deep( $request ) : $request;
$yourname = sanitize_text_field($request['inq_name']);
$youremail = sanitize_email($request['inq_email']);
$inq_phone = sanitize_text_field($request['inq_phone']);
$frnd_comments = sanitize_text_field($request['inq_msg']);
$pid = absint($request['pid']);
$author_id = '';
if ( $pid && 'publish' == get_post_status ( $pid ) ) {
check_ajax_referer( 'send_inquiry_'.$pid );
$p_post = get_post($pid);
$author_id = $p_post->post_author;
}else{
gd_die();
}
$to_email = geodir_get_post_meta( $pid, 'geodir_email', true );
$to_name = geodir_get_client_name( $author_id );
if ( $to_email == '' ) {
$to_email = get_option( 'admin_email' );
}
/**
* Called after the send enquiry var have been set but before the email has been sent.
*
* @since 1.0.0
*
* @param array $request {
* The submitted form fields as an array.
*
* @type string $sendact Enquiry type. Default "send_inqury".
* @type string $pid Post ID.
* @type string $inq_name Sender name.
* @type string $inq_email Sender mail.
* @type string $inq_phone Sender phone.
* @type string $inq_msg Email message.
*
* }
* @param string $type The form type, default: `Enquiry`.
*/
do_action( 'geodir_after_send_enquiry', $request, 'Enquiry' );
$client_message = $frnd_comments;
$client_message .= '<br>' . __( 'From :', 'geodirectory' ) . ' ' . $yourname . '<br>' . __( 'Phone :', 'geodirectory' ) . ' ' . $inq_phone . '<br>' . __( 'Email :', 'geodirectory' ) . ' ' . $youremail . '<br><br>' . __( 'Sent from', 'geodirectory' ) . ' - <b><a href="' . trailingslashit( home_url() ) . '">' . get_option( 'blogname' ) . '</a></b>.';
/**
* Filter client message text.
*
* @since 1.0.0
*
* @param string $client_message Client message text.
*/
$client_message = apply_filters( 'geodir_inquiry_email_msg', $client_message );
/**
* Called before the send enquiry email is sent.
*
* @since 1.0.0
*
* @param array $request {
* The submitted form fields as an array.
*
* @type string $sendact Enquiry type. Default "send_inqury".
* @type string $pid Post ID.
* @type string $inq_name Sender name.
* @type string $inq_email Sender mail.
* @type string $inq_phone Sender phone.
* @type string $inq_msg Email message.
*
* }
*/
do_action( 'geodir_before_send_enquiry_email', $request );
if ( $to_email ) {
// strip slashes message
$client_message = stripslashes_deep( $client_message );
geodir_sendEmail( $youremail, $yourname, $to_email, $to_name, '', $client_message, $extra = '', 'send_enquiry', $request['pid'] );//To client email
}
/**
* Called after the send enquiry email is sent.
*
* @since 1.0.0
*
* @param array $request {
* The submitted form fields as an array.
*
* @type string $sendact Enquiry type. Default "send_inqury".
* @type string $pid Post ID.
* @type string $inq_name Sender name.
* @type string $inq_email Sender mail.
* @type string $inq_phone Sender phone.
* @type string $inq_msg Email message.
*
* }
*/
do_action( 'geodir_after_send_enquiry_email', $request );
$url = get_permalink( $pid );
if ( strstr( $url, '?' ) ) {
$url = $url . "&send_inquiry=success";
} else {
$url = $url . "?send_inquiry=success";
}
/**
* Filter redirect url after the send enquiry email is sent.
*
* @since 1.0.0
*
* @param string $url Redirect url.
*/
$url = apply_filters( 'geodir_send_enquiry_after_submit_redirect', $url );
wp_redirect( $url );
gd_die();
}
/**
* Send Email to a friend.
*
* This function let the user to send Email to a friend.
* Email content will be used WP Admin -> Geodirectory -> Notifications -> Other Emails -> Send to friend
*
* @since 1.0.0
* @package GeoDirectory
*
* @param array $request {
* The submitted form fields as an array.
*
* @type string $sendact Enquiry type. Default "email_frnd".
* @type string $pid Post ID.
* @type string $to_name Friend name.
* @type string $to_email Friend email.
* @type string $yourname Sender name.
* @type string $youremail Sender email.
* @type string $frnd_subject Email subject.
* @type string $frnd_comments Email Message.
*
* }
* @global object $wpdb WordPress Database object.
*
* @deprecated 1.6.26
*/
function geodir_send_friend( $request ) {
global $wpdb;
// strip slashes from text
$request = ! empty( $request ) ? stripslashes_deep( $request ) : $request;
$yourname = sanitize_text_field($request['yourname']);
$youremail = sanitize_email($request['youremail']);
$frnd_subject = sanitize_text_field($request['frnd_subject']);
$frnd_comments = sanitize_text_field($request['frnd_comments']);
$pid = absint($request['pid']);
$to_email = sanitize_email($request['to_email']);
$to_name = sanitize_text_field($request['to_name']);
if ( $pid && 'publish' == get_post_status ( $pid ) ) {
check_ajax_referer( 'send_to_frnd_'.$pid );
}else{
gd_die();
}
/**
* Called before the send to friend email is sent.
*
* @since 1.0.0
*
* @param array $request {
* The submitted form fields as an array.
*
* @type string $sendact Enquiry type. Default "email_frnd".
* @type string $pid Post ID.
* @type string $to_name Friend name.
* @type string $to_email Friend email.
* @type string $yourname Sender name.
* @type string $youremail Sender email.
* @type string $frnd_subject Email subject.
* @type string $frnd_comments Email Message.
*
* }
*/
do_action( 'geodir_before_send_to_friend_email', $request );
geodir_sendEmail( $youremail, $yourname, $to_email, $to_name, $frnd_subject, $frnd_comments, $extra = '', 'send_friend', $request['pid'] );//To client email
/**
* Called after the send to friend email is sent.
*
* @since 1.0.0
*
* @param array $request {
* The submitted form fields as an array.
*
* @type string $sendact Enquiry type. Default "email_frnd".
* @type string $pid Post ID.
* @type string $to_name Friend name.
* @type string $to_email Friend email.
* @type string $yourname Sender name.
* @type string $youremail Sender email.
* @type string $frnd_subject Email subject.
* @type string $frnd_comments Email Message.
*
* }
*/
do_action( 'geodir_after_send_to_friend_email', $request );
$url = get_permalink( $pid );
if ( strstr( $url, '?' ) ) {
$url = $url . "&sendtofrnd=success";
} else {
$url = $url . "?sendtofrnd=success";
}
/**
* Filter redirect url after the send to friend email is sent.
*
* @since 1.0.0
*
* @param string $url Redirect url.
*/
$url = apply_filters( 'geodir_send_to_friend_after_submit_redirect', $url );
wp_redirect( $url );
gd_die();
}
/**
* Adds open div before the tab content.
*
* This function adds open div before the tab content like post information, post images, reviews etc.
*
* @since 1.0.0
* @package GeoDirectory
*
* @param string $hash_key
*/
function geodir_before_tab_content( $hash_key ) {
switch ( $hash_key ) {
case 'post_info' :
echo '<div class="geodir-company_info field-group">';
break;
case 'post_images' :
/**
* Filter post gallery HTML id.
*
* @since 1.0.0
*/
echo ' <div id="' . apply_filters( 'geodir_post_gallery_id', 'geodir-post-gallery' ) . '" class="clearfix" >';
break;
case 'reviews' :
echo '<div id="reviews-wrap" class="clearfix"> ';
break;
case 'post_video':
echo ' <div id="post_video-wrap" class="clearfix">';
break;
case 'special_offers':
echo '<div id="special_offers-wrap" class="clearfix">';
break;
}
}
/**
* Adds closing div after the tab content.
*
* This function adds closing div after the tab content like post information, post images, reviews etc.
*
* @since 1.0.0
* @package GeoDirectory
*
* @param string $hash_key
*/
function geodir_after_tab_content( $hash_key ) {
switch ( $hash_key ) {
case 'post_info' :
echo '</div>';
break;
case 'post_images' :
echo '</div>';
break;
case 'reviews' :
echo '</div>';
break;
case 'post_video':
echo '</div>';
break;
case 'special_offers':
echo '</div>';
break;
}
}
/**
* Returns default sorting order of a post type.
*
* @since 1.0.0
* @package GeoDirectory
*
* @param string $post_type The post type.
*
* @global object $wpdb WordPress Database object.
* @return bool|null|string Returns default sort results, when the post type is valid. Otherwise returns false.
*/
function geodir_get_posts_default_sort( $post_type ) {
global $wpdb;
if ( $post_type != '' ) {
$all_postypes = geodir_get_posttypes();
if ( ! in_array( $post_type, $all_postypes ) ) {
return false;
}
$sort_field_info = $wpdb->get_var( $wpdb->prepare( "select default_order from " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " where post_type= %s and is_active=%d and is_default=%d", array(
$post_type,
1,
1
) ) );
if ( ! empty( $sort_field_info ) ) {
return $sort_field_info;
}
}
}
/**
* Returns sort options of a post type.
*
* @since 1.0.0
* @package GeoDirectory
*
* @param string $post_type The post type.
*
* @global object $wpdb WordPress Database object.
* @return bool|mixed|void Returns sort results, when the post type is valid. Otherwise returns false.
*/
function geodir_get_sort_options( $post_type ) {
global $wpdb;
if ( $post_type != '' ) {
$all_postypes = geodir_get_posttypes();
if ( ! in_array( $post_type, $all_postypes ) ) {
return false;
}
$sort_field_info = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " WHERE post_type=%s AND is_active=%d AND (sort_asc=1 || sort_desc=1 || field_type='random') AND field_type != 'address' ORDER BY sort_order ASC", array(
$post_type,
1
) ) );
/**
* Filter post sort options.
*
* @since 1.0.0
*
* @param array $sort_field_info Unfiltered sort field array.
* @param string $post_type Post type.
*/
return apply_filters( 'geodir_get_sort_options', $sort_field_info, $post_type );
}
}
/**
* Display list of sort options available in front end using dropdown.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wp_query WordPress Query object.
*/
function geodir_display_sort_options() {
global $wp_query;
/**
* On search pages there should be no sort options, sorting is done by search criteria.
*
* @since 1.4.4
*/
if ( is_search() ) {
return;
}
$sort_by = '';
if ( isset( $_REQUEST['sort_by'] ) ) {
$sort_by = $_REQUEST['sort_by'];
}
$gd_post_type = geodir_get_current_posttype();
$sort_options = geodir_get_sort_options( $gd_post_type );
$sort_field_options = '';
if ( ! empty( $sort_options ) ) {
foreach ( $sort_options as $sort ) {
$sort = stripslashes_deep( $sort ); // strip slashes
$label = __( $sort->site_title, 'geodirectory' );
if ( $sort->field_type == 'random' ) {
$key = $sort->field_type;
( $sort_by == $key || ( $sort->is_default == '1' && ! isset( $_REQUEST['sort_by'] ) ) ) ? $selected = 'selected="selected"' : $selected = '';
$sort_field_options .= '<option ' . $selected . ' value="' . esc_url( add_query_arg( 'sort_by', $key ) ) . '">' . __( $label, 'geodirectory' ) . '</option>';
}
if ( $sort->htmlvar_name == 'comment_count' ) {
$sort->htmlvar_name = 'rating_count';
}
if ( $sort->sort_asc ) {
$key = $sort->htmlvar_name . '_asc';
$label = $sort->site_title;
if ( $sort->asc_title ) {
$label = $sort->asc_title;
}
( $sort_by == $key || ( $sort->is_default == '1' && $sort->default_order == $key && ! isset( $_REQUEST['sort_by'] ) ) ) ? $selected = 'selected="selected"' : $selected = '';
$sort_field_options .= '<option ' . $selected . ' value="' . esc_url( add_query_arg( 'sort_by', $key ) ) . '">' . __( $label, 'geodirectory' ) . '</option>';
}
if ( $sort->sort_desc ) {
$key = $sort->htmlvar_name . '_desc';
$label = $sort->site_title;
if ( $sort->desc_title ) {
$label = $sort->desc_title;
}
( $sort_by == $key || ( $sort->is_default == '1' && $sort->default_order == $key && ! isset( $_REQUEST['sort_by'] ) ) ) ? $selected = 'selected="selected"' : $selected = '';
$sort_field_options .= '<option ' . $selected . ' value="' . esc_url( add_query_arg( 'sort_by', $key ) ) . '">' . __( $label, 'geodirectory' ) . '</option>';
}
}
}
if ( $sort_field_options != '' ) {
?>
<div class="geodir-tax-sort">
<select name="sort_by" id="sort_by" onchange="javascript:window.location=this.value;">
<option
value="<?php echo esc_url( add_query_arg( 'sort_by', '' ) ); ?>" <?php if ( $sort_by == '' ) {
echo 'selected="selected"';
} ?>><?php _e( 'Sort By', 'geodirectory' ); ?></option><?php
echo $sort_field_options; ?>
</select>
</div>
<?php
}
}
/**
* Removes the section title
*
* Removes the section title "Posts sort options", if the custom field type is multiselect or textarea or taxonomy.
* Can be found here. WP Admin -> Geodirectory -> Place settings -> Custom fields
*
* @since 1.0.0
* @package GeoDirectory
*
* @param string $title The section title.
* @param string $field_type The field type.
*
* @return string Returns the section title.
*/
function geodir_advance_customfields_heading( $title, $field_type ) {
if ( in_array( $field_type, array( 'multiselect', 'textarea', 'taxonomy' ) ) ) {
$title = '';
}
return $title;
}
/**
* Returns related listings of a listing.
*
* @since 1.0.0
* @package GeoDirectory
*
* @param array $request Related posts request array.
*
* @global object $wpdb WordPress Database object.
* @global object $post The current post object.
* @global string $gridview_columns_widget The girdview style of the listings.
* @global object $gd_session GeoDirectory Session object.
* @return string Returns related posts html.
*/
function geodir_related_posts_display( $request ) {
if ( ! empty( $request ) ) {
$before_title = ( isset( $request['before_title'] ) && ! empty( $request['before_title'] ) ) ? $request['before_title'] : '';
$after_title = ( isset( $request['after_title'] ) && ! empty( $request['after_title'] ) ) ? $request['after_title'] : '';
$title = ( isset( $request['title'] ) && ! empty( $request['title'] ) ) ? $request['title'] : __( 'Related Listings', 'geodirectory' );
$post_number = ( isset( $request['post_number'] ) && ! empty( $request['post_number'] ) ) ? $request['post_number'] : '5';
$relate_to = ( isset( $request['relate_to'] ) && ! empty( $request['relate_to'] ) ) ? $request['relate_to'] : 'category';
$layout = ( isset( $request['layout'] ) && ! empty( $request['layout'] ) ) ? $request['layout'] : 'gridview_onehalf';
$add_location_filter = ( isset( $request['add_location_filter'] ) && ! empty( $request['add_location_filter'] ) ) ? $request['add_location_filter'] : '0';
$listing_width = ( isset( $request['listing_width'] ) && ! empty( $request['listing_width'] ) ) ? $request['listing_width'] : '';
$list_sort = ( isset( $request['list_sort'] ) && ! empty( $request['list_sort'] ) ) ? $request['list_sort'] : 'latest';
$character_count = ( isset( $request['character_count'] ) && ! empty( $request['character_count'] ) ) ? $request['character_count'] : '';
global $wpdb, $post, $gd_session, $related_nearest, $related_parent_lat, $related_parent_lon;
$related_parent_lat = !empty($post->post_latitude) && geodir_is_page( 'detail' ) ? $post->post_latitude : '';
$related_parent_lon = !empty($post->post_longitude) && geodir_is_page( 'detail' ) ? $post->post_longitude : '';
$arr_detail_page_tabs = geodir_detail_page_tabs_list();
$related_listing_array = array();
if ( get_option( 'geodir_add_related_listing_posttypes' ) ) {
$related_listing_array = get_option( 'geodir_add_related_listing_posttypes' );
}
if ( isset($post->post_type) && in_array( $post->post_type, $related_listing_array ) ) {
$arr_detail_page_tabs['related_listing']['is_display'] = true;
}
$is_display = $arr_detail_page_tabs['related_listing']['is_display'];
$origi_post = $post;
$post_type = '';
$post_id = '';
$category_taxonomy = '';
$tax_field = 'id';
$category = array();
if ( isset( $_REQUEST['backandedit'] ) ) {
$post = (object) $gd_session->get( 'listing' );
$post_type = $post->listing_type;
if ( isset( $_REQUEST['pid'] ) && $_REQUEST['pid'] != '' ) {
$post_id = $_REQUEST['pid'];
}
} elseif ( isset( $_REQUEST['pid'] ) && $_REQUEST['pid'] != '' ) {
$post = geodir_get_post_info( $_REQUEST['pid'] );
$post_type = $post->post_type;
$post_id = $_REQUEST['pid'];
} elseif ( isset( $post->post_type ) && $post->post_type != '' ) {
$post_type = $post->post_type;
$post_id = $post->ID;
}
if ( $relate_to == 'category' ) {
$category_taxonomy = $post_type . $relate_to;
if ( isset( $post->{$category_taxonomy} ) && $post->{$category_taxonomy} != '' ) {
$category = explode( ',', trim( $post->{$category_taxonomy}, ',' ) );
}
} elseif ( $relate_to == 'tags' ) {
$category_taxonomy = $post_type . '_' . $relate_to;
if ( $post->post_tags != '' ) {
$category = explode( ',', trim( $post->post_tags, ',' ) );
}
$tax_field = 'name';
}
/* --- return false in invalid request --- */
if ( empty( $category ) ) {
return false;
}
$all_postypes = geodir_get_posttypes();
if ( ! in_array( $post_type, $all_postypes ) ) {
return false;
}
/* --- return false in invalid request --- */
$location_url = '';
if ( $add_location_filter != '0' ) {
$location_url = array();
$geodir_show_location_url = get_option( 'geodir_show_location_url' );
$gd_city = get_query_var( 'gd_city' );
if ( $gd_city ) {
$gd_country = get_query_var( 'gd_country' );
$gd_region = get_query_var( 'gd_region' );
} else {
$location = geodir_get_default_location();
$gd_country = isset( $location->country_slug ) ? $location->country_slug : '';
$gd_region = isset( $location->region_slug ) ? $location->region_slug : '';
$gd_city = isset( $location->city_slug ) ? $location->city_slug : '';
}
if ( $geodir_show_location_url == 'all' ) {
$location_url[] = $gd_country;
$location_url[] = $gd_region;
} else if ( $geodir_show_location_url == 'country_city' ) {
$location_url[] = $gd_country;
} else if ( $geodir_show_location_url == 'region_city' ) {
$location_url[] = $gd_region;
}
$location_url[] = $gd_city;
$location_url = implode( '/', $location_url );
}
if ( ! empty( $category ) ) {
global $geodir_add_location_url;
$geodir_add_location_url = '0';
if ( $add_location_filter != '0' ) {
$geodir_add_location_url = '1';
}
$viewall_url = get_term_link( (int) $category[0], $post_type . $category_taxonomy );
$geodir_add_location_url = null;
}
ob_start();
?>
<div class="geodir_locations geodir_location_listing">
<?php
if ( isset( $request['is_widget'] ) && $request['is_widget'] == '1' ) {
/** geodir_before_title filter Documented in geodirectory_widgets.php */
$before_title = isset( $before_title ) ? $before_title : apply_filters( 'geodir_before_title', '<h3 class="widget-title">' );
/** geodir_after_title filter Documented in geodirectory_widgets.php */
$after_title = isset( $after_title ) ? $after_title : apply_filters( 'geodir_after_title', '</h3>' );
?>
<div class="location_list_heading clearfix">
<?php echo $before_title . $title . $after_title; ?>
</div>
<?php
}
$query_args = array(
'posts_per_page' => $post_number,
'is_geodir_loop' => true,
'gd_location' => ( $add_location_filter ) ? true : false,
'post_type' => $post_type,
'order_by' => $list_sort,
'post__not_in' => array( $post_id ),
'excerpt_length' => $character_count,
'related_listings' => $is_display
);
$tax_query = array(
'taxonomy' => $category_taxonomy,
'field' => $tax_field,
'terms' => $category
);
$query_args['tax_query'] = array( $tax_query );
global $gridview_columns_widget, $post;
/**
* Filters related listing query args.
*
* @since 1.6.11
*
* @param array $query_args The query array.
* @param array $request Related posts request array.
*/
$query_args = apply_filters( 'geodir_related_posts_widget_query_args', $query_args, $request );
query_posts( $query_args );
if ( strstr( $layout, 'gridview' ) ) {
$listing_view_exp = explode( '_', $layout );
$gridview_columns_widget = $layout;
$layout = $listing_view_exp[0];
} else if ( $layout == 'list' ) {
$gridview_columns_widget = '';
}
$related_posts = true;
$related_nearest = false;
if ( $list_sort == 'nearest' ) {
$related_nearest = true;
}
$widget_listings = array();
while (have_posts()) : the_post();
global $post, $wpdb, $preview;
$widget_listings[] = $post;
endwhile;
/**
* Filters related listing listview template.
*
* @since 1.0.0
*/
$template = apply_filters( "geodir_template_part-related-listing-listview", geodir_locate_template( 'widget-listing-listview' ) );
/**
* Includes related listing listview template.
*
* @since 1.0.0
*/
include( $template );
wp_reset_query();
$post = $origi_post;
$related_nearest = false;
?>
</div>
<?php
return $html = ob_get_clean();
}
}
//add_action('wp_footer', 'geodir_category_count_script', 10);
/**
* Adds the category post count javascript code
*
* @since 1.0.0
* @package GeoDirectory
* @global string $geodir_post_category_str The geodirectory post category.
* @depreciated No longer needed.
*/
function geodir_category_count_script() {
global $geodir_post_category_str;
if ( ! empty( $geodir_post_category_str ) ) {
$geodir_post_category_str = serialize( $geodir_post_category_str );
}
$all_var['post_category_array'] = html_entity_decode( (string) $geodir_post_category_str, ENT_QUOTES, 'UTF-8' );
$script = "var post_category_array = " . json_encode( $all_var ) . ';';
echo '<script>';
echo $script;
echo '</script>';
}
/**
* Returns the default language of the map.
*
* @since 1.0.0
* @package GeoDirectory
* @return string Returns the default language.
*/
function geodir_get_map_default_language() {
$geodir_default_map_language = get_option( 'geodir_default_map_language' );
if ( empty( $geodir_default_map_language ) ) {
$geodir_default_map_language = 'en';
}
/**
* Filter default map language.
*
* @since 1.0.0
*
* @param string $geodir_default_map_language Default map language.
*/