forked from sovware/directorist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirectorist-base.php
1528 lines (1362 loc) · 60.6 KB
/
directorist-base.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
/**
* Plugin Name: Directorist - Business Directory Plugin
* Plugin URI: https://wpwax.com
* Description: A comprehensive solution to create professional looking directory site of any kind. Like Yelp, Foursquare, etc.
* Version: 6.5.7
* Author: wpWax
* Author URI: https://wpwax.com
* Text Domain: directorist
* Domain Path: /languages
*/
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Copyright (c) 2020 wpWax (website: aazztech.com). All rights reserved.
*/
// prevent direct access to the file
defined('ABSPATH') || die('No direct script access allowed!');
/**
* Main Directorist_Base Class.
*
* @since 1.0
*/
final class Directorist_Base
{
/** Singleton *************************************************************/
/**
* @var Directorist_Base The one true Directorist_Base
* @since 1.0
*/
private static $instance;
/**
* ATBDP_Metabox Object.
*
* @var object|ATBDP_Metabox
* @since 1.0
*/
public $metabox;
/**
* ATBDP_Custom_Post Object.
*
* @var object|ATBDP_Custom_Post
* @since 1.0
*/
public $custom_post;
/**
* ATBDP_Custom_Taxonomy Object.
*
* @var object|ATBDP_Custom_Taxonomy
* @since 1.0
*/
public $taxonomy;
/**
* ATBDP_Enqueuer Object.
*
* @var object|ATBDP_Enqueuer
* @since 1.0
*/
public $enquirer;
/**
* ATBDP_Ajax_Handler Object.
*
* @var object|ATBDP_Ajax_Handler
* @since 1.0
*/
public $ajax_handler;
/**
* ATBDP_Shortcode Object.
*
* @var object|ATBDP_Shortcode
* @since 1.0
*/
public $shortcode;
/**
* ATBDP_Helper Object.
*
* @var object|ATBDP_Helper
* @since 1.0
*/
public $helper;
/**
* ATBDP_Review_Rating Object.
*
* @var object|ATBDP_Review_Rating
* @since 1.0
*/
public $review;
/**
* ATBDP_Listing Object.
*
* @var object|ATBDP_Listing
* @since 1.0
*/
public $listing;
/**
* ATBDP_User Object.
*
* @var object|ATBDP_User
* @since 1.0
*/
public $user;
/**
* ATBDP_Roles Object.
*
* @var object|ATBDP_Roles
* @since 3.0
*/
public $roles;
/**
* ATBDP_Gateway Object.
*
* @var ATBDP_Gateway
* @since 3.1.0
*/
public $gateway;
/**
* ATBDP_Order Object.
*
* @var ATBDP_Order
* @since 3.1.0
*/
public $custom_field;
/**
* ATBDP_Custom_Field Object.
*
* @var ATBDP_Custom_Field
* @since 3.1.6
*/
public $order;
/**
* ATBDP_Email Object.
*
* @var ATBDP_Email
* @since 3.1.0
*/
public $email;
/**
* ATBDP_SEO Object.
*
* @var ATBDP_SEO
* @since 4.7.0
*/
public $seo;
/**
* ATBDP_Tools Object.
*
* @var ATBDP_Tools
* @since 4.7.2
*/
public $tools;
/**
* ATBDP_Single_Templates Object.
*
* @var ATBDP_Single_Templates
* @since 5.0.5
*/
public $ATBDP_Single_Templates;
/**
* ATBDP_Review_Custom_Post Object.
*
* @var ATBDP_Review_Custom_Post
* @since 5.6.5
*/
public $ATBDP_Review_Custom_Post;
/**
* Main Directorist_Base Instance.
*
* Insures that only one instance of Directorist_Base exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @since 1.0
* @static
* @static_var array $instance
* @uses Directorist_Base::setup_constants() Setup the constants needed.
* @uses Directorist_Base::includes() Include the required files.
* @uses Directorist_Base::load_textdomain() load the language files.
* @see ATBDP()
* @return object|Directorist_Base The one true Directorist_Base
*/
public static function instance()
{
if (!isset(self::$instance) && !(self::$instance instanceof Directorist_Base)) {
self::$instance = new Directorist_Base;
self::$instance->setup_constants();
add_action('plugins_loaded', array(self::$instance, 'load_textdomain'));
add_action('plugins_loaded', array(self::$instance, 'add_polylang_swicher_support') );
add_action('widgets_init', array(self::$instance, 'register_widgets'));
add_action( 'template_redirect', [ self::$instance, 'check_single_listing_page_restrictions' ] );
add_action( 'atbdp_show_flush_messages', [ self::$instance, 'show_flush_messages' ] );
self::$instance->includes();
self::$instance->custom_post = new ATBDP_Custom_Post; // create custom post
self::$instance->taxonomy = new ATBDP_Custom_Taxonomy;
self::$instance->enquirer = new ATBDP_Enqueuer;
self::$instance->hooks = new ATBDP_Hooks;
self::$instance->metabox = new ATBDP_Metabox;
self::$instance->ajax_handler = new ATBDP_Ajax_Handler;
self::$instance->helper = new ATBDP_Helper;
self::$instance->listing = new ATBDP_Listing;
self::$instance->user = new ATBDP_User;
self::$instance->roles = new ATBDP_Roles;
self::$instance->gateway = new ATBDP_Gateway;
self::$instance->custom_field = new ATBDP_Custom_Field;
self::$instance->order = new ATBDP_Order;
self::$instance->shortcode = new ATBDP_Shortcode;
self::$instance->email = new ATBDP_Email;
self::$instance->seo = new ATBDP_SEO;
self::$instance->tools = new ATBDP_Tools;
self::$instance->announcement = new ATBDP_Announcement;
self::$instance->ATBDP_Single_Templates = new ATBDP_Single_Templates;
self::$instance->ATBDP_Review_Custom_Post = new ATBDP_Review_Custom_Post;
self::$instance->update_database();
// new settings
new ATBDP_Settings_Manager();
/*Extensions Link*/
/*initiate extensions link*/
new ATBDP_Extensions();
/*Initiate Review and Rating Features*/
self::$instance->review = new ATBDP_Review_Rating;
//activate rewrite api
new ATBDP_Rewrite;
//map custom capabilities
add_filter('map_meta_cap', array(self::$instance->roles, 'meta_caps'), 10, 4);
//add dtbdp custom body class
add_filter('body_class', array(self::$instance, 'atbdp_body_class'), 99);
// display related listings
add_action('atbdp_after_single_listing', array(self::$instance, 'show_related_listing'));
//review and rating
add_action('atbdp_after_map', array(self::$instance, 'show_review'));
// plugin deactivated popup
add_filter('plugin_action_links_' . plugin_basename(__FILE__), array(self::$instance, 'atbdp_plugin_link'));
add_action('admin_footer', array(self::$instance, 'atbdp_deactivate_popup'));
// Attempt to create listing related custom pages with plugin's custom shortcode to give user best experience.
// we can check the database if our custom pages have been installed correctly or not here first.
// This way we can minimize the adding of our custom function to the WordPress hooks.
if (get_option('atbdp_pages_version') < 1) {
add_action('wp_loaded', array(self::$instance, 'add_custom_directorist_pages'));
}
//fire up one time compatibility increasing function.
if (get_option('atbdp_meta_version') < 1) {
add_action('init', array(self::$instance, 'add_custom_meta_keys_for_old_listings'));
}
// init offline gateway
new ATBDP_Offline_Gateway;
// Init Cron jobs to run some periodic tasks
new ATBDP_Cron;
// add upgrade feature
new ATBDP_Upgrade;
// add uninstall menu
add_filter('atbdp_settings_menus', array(self::$instance, 'add_uninstall_menu'));
self::init_hooks();
}
return self::$instance;
}
// check_single_listing_page_restrictions
public function check_single_listing_page_restrictions() {
$restricted_for_logged_in_user = get_directorist_option( 'restrict_single_listing_for_logged_in_user', false );
$current_user_id = get_current_user_id();
if ( is_singular( ATBDP_POST_TYPE ) && ! empty( $restricted_for_logged_in_user ) && empty( $current_user_id ) ) {
atbdp_auth_guard();
}
}
// show_flush_messages
public function show_flush_messages() {
atbdp_get_flush_messages();
}
// add_polylang_swicher_support
public function add_polylang_swicher_support() {
add_filter('pll_the_language_link', function($url, $current_lang) {
// Adjust the category link
$category_url = $this->get_polylang_swicher_link_for_term([
'term_type' => 'category',
'term_default_page_id' => get_directorist_option('single_category_page'),
'term_query_var' => ( ! empty( $_GET['category'] ) ) ? $_GET['category'] : get_query_var('atbdp_category'),
'current_lang' => $current_lang,
'url' => $url,
]);
if ( ! empty( $category_url ) ) { return $category_url; }
// Adjust the location link
$location_url = $this->get_polylang_swicher_link_for_term([
'term_type' => 'location',
'term_default_page_id' => get_directorist_option('single_location_page'),
'term_query_var' => ( ! empty( $_GET['location'] ) ) ? $_GET['location'] : get_query_var('atbdp_location'),
'current_lang' => $current_lang,
'url' => $url,
]);
if ( ! empty( $location_url ) ) { return $location_url; }
return $url;
}, 10, 2);
}
// get_polylang_swicher_link_for_term
public function get_polylang_swicher_link_for_term( $args ) {
$default = [
'term_type' => '',
'term_query_var' => '',
'term_default_page_id' => '',
'current_lang' => '',
'url' => '',
];
$args = array_merge( $default, $args );
if ( empty( $args[ 'term_query_var' ] ) ) { return false; }
// Get language slug of the default page
$page_lang = pll_get_post_language( $args[ 'term_default_page_id' ] );
// If current lang slug != default page
// modyfy the url
if ( $args[ 'current_lang' ] !== $page_lang ) {
return $args['url'] ."?". $args['term_type'] ."=". $args['term_query_var'];
}
if ( $args[ 'current_lang' ] === $page_lang ) {
return $args['url'] . $args['term_query_var'];
}
return false;
}
/**
* Update Database
*
* @access private
* @since 6.4.4
* @return void
*/
private function update_database()
{
$this->update_review_table();
}
/**
* Init Hooks
*
* @access private
* @since 6.4.5
* @return void
*/
public static function init_hooks()
{
ATBDP_Cache_Helper::reset_cache();
}
/**
* Update Review Table
*
* @access private
* @since 6.4.4
* @return void
*/
private function update_review_table()
{
$current_charset_collate = get_option('atbdp_review_table_charset_collate');
$review_rating = new ATBDP_Review_Rating_DB();
$charset_collate = $review_rating->get_charset_collate();
if ( $charset_collate !== $current_charset_collate ) {
add_action('admin_init', array( $review_rating, 'update_table_collation'));
update_option('atbdp_review_table_charset_collate', $charset_collate);
}
}
/**
* Setup plugin constants.
*
* @access private
* @since 1.0
* @return void
*/
private function setup_constants()
{
// test
require_once plugin_dir_path(__FILE__) . '/config.php'; // loads constant from a file so that it can be available on all files.
}
/**
* Include required files.
*
* @access private
* @since 1.0
* @return void
*/
private function includes()
{
// $helper = new ATBDP_Helper;
require_once ATBDP_TEMPLATES_DIR . 'single-template-shortcode.php';
require_once ATBDP_LIB_DIR . 'vafpress/bootstrap.php'; // load option framework.
require_once ATBDP_INC_DIR . 'helper-functions.php';
load_dependencies('all', ATBDP_INC_DIR . 'data-store/');
load_dependencies('all', ATBDP_INC_DIR . 'hooks/');
load_dependencies('all', ATBDP_CLASS_DIR); // load all php files from ATBDP_CLASS_DIR
load_dependencies('all', ATBDP_LIB_DIR); // load all php files from ATBDP_LIB_DIR
/*LOAD Rating and Review functionality*/
load_dependencies('all', ATBDP_INC_DIR . 'review-rating/');
/*Load gateway related stuff*/
load_dependencies('all', ATBDP_INC_DIR . 'gateways/');
/*Load custom field related stuff*/
load_dependencies('all', ATBDP_INC_DIR . 'custom-fields/');
/*Load payment related stuff*/
load_dependencies('all', ATBDP_INC_DIR . 'payments/');
load_dependencies('all', ATBDP_INC_DIR . 'checkout/');
/*Load payment related stuff*/
require_once ATBDP_INC_DIR . 'custom-actions.php';
require_once ATBDP_INC_DIR . 'custom-filters.php';
/*Load Elementor Widgets*/
require_once ATBDP_INC_DIR . 'elementor/init.php';
/* Load system info */
require_once ATBDP_INC_DIR . 'system-status/class-system-status.php';
}
public static function prepare_plugin()
{
include ATBDP_INC_DIR . 'classes/class-installation.php';
ATBDP_Installation::install();
}
/**
* Throw error on object clone.
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @since 1.0
* @access public
* @return void
*/
public function __clone()
{
// Cloning instances of the class is forbidden.
_doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'directorist'), '1.0');
}
/**
* Disable unserializing of the class.
*
* @since 1.0
* @access public
* @return void
*/
public function __wakeup()
{
// Unserializing instances of the class is forbidden.
_doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'directorist'), '1.0');
}
/**
* It registers widgets and sidebar support
*
* @since 1.0
* @access public
* @return void
*/
public function register_widgets()
{
if (!is_registered_sidebar('right-sidebar-listing')) {
register_sidebar(array(
'name' => apply_filters('atbdp_right_sidebar_name', __('Directorist - Listing Right Sidebar', 'directorist')),
'id' => 'right-sidebar-listing',
'description' => __('Add widgets for the right sidebar on single listing page', 'directorist'),
'before_widget' => '<div class="widget atbd_widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="atbd_widget_title"><h4>',
'after_title' => '</h4></div>',
));
}
register_widget('BD_Popular_Listing_Widget');
register_widget('BD_video_Widget');
register_widget('BD_contact_form_Widget');
register_widget('BD_Submit_Item_Widget');
register_widget('BD_Login_Form_Widget');
register_widget('BD_Categories_Widget');
register_widget('BD_Locations_Widget');
register_widget('BD_Tags_Widget');
register_widget('BD_Search_Widget');
register_widget('BD_Map_Widget');
register_widget('BD_All_Map_Widget');
register_widget('BD_Similar_Listings_Widget');
register_widget('BD_Author_Info_Widget');
register_widget('BD_Featured_Listings_Widget');
}
public function load_textdomain()
{
load_plugin_textdomain('directorist', false, ATBDP_LANG_DIR);
if ( get_transient( '_directorist_setup_page_redirect' ) ) {
directorist_redirect_to_admin_setup_wizard();
}
}
/**
* It loads a template file from the Default template directory.
* @todo; Improve this method in future so that it lets user/developers to change/override any templates this plugin uses
* @param string $name Name of the file that should be loaded from the template directory.
* @param array $args Additional arguments that should be passed to the template file for rendering dynamic data.
* @param bool $return_path Whether to return the path instead of including it
* @return string|void
*/
public function load_template($name, $args = array(), $return_path = false)
{
global $post;
$path = ATBDP_TEMPLATES_DIR . $name . '.php';
if ($return_path) return $path;
include($path);
}
public function add_custom_directorist_pages()
{
$create_permission = apply_filters('atbdp_create_required_pages', true);
if ($create_permission){
atbdp_create_required_pages();
}
}
public function add_uninstall_menu($menus) {
$menus['uninstall_menu'] = array(
'title' => __('Uninstall', 'directorist'),
'name' => 'uninstall_menu',
'icon' => 'font-awesome:fa-window-close',
'controls' => apply_filters('atbdp_uninstall_settings_controls', array(
'currency_section' => array(
'type' => 'section',
'title' => __('Uninstall Settings', 'directorist'),
'fields' => get_uninstall_settings_submenus(),
),
)),
);
return $menus;
}
/**
* It displays popular listings
* @param int $count [optional] Number of popular listing to show. Default 5.
* If the count is more than one then it uses it, else the function will use the value from the settings page.
* Count variable is handy if we want to show different number of popular listings on different pages. For example, on different widgets place
* @todo Try to move popular listings related functionalities to a dedicated listing related class that handles popular listings, related listings etc. when have time.
*/
public function show_popular_listing($count = 5)
{
$popular_listings = $this->get_popular_listings($count);
if ($popular_listings->have_posts()) { ?>
<div class="atbd_categorized_listings">
<ul class="listings">
<?php foreach ($popular_listings->posts as $pop_post) {
// get only one parent or high level term object
$top_category = ATBDP()->taxonomy->get_one_high_level_term($pop_post->ID, ATBDP_CATEGORY);
$listing_img = get_post_meta($pop_post->ID, '_listing_img', true);
$listing_prv_img = get_post_meta($pop_post->ID, '_listing_prv_img', true);
$cats = get_the_terms($pop_post->ID, ATBDP_CATEGORY);
?>
<li>
<div class="atbd_left_img">
<?php
$disable_single_listing = get_directorist_option('disable_single_listing');
if (empty($disable_single_listing)){
?>
<a href="<?php echo esc_url(get_post_permalink($pop_post->ID)); ?>">
<?php
}
$default_image = get_directorist_option('default_preview_image', ATBDP_PUBLIC_ASSETS . 'images/grid.jpg');
if (!empty($listing_prv_img)) {
echo '<img src="' . esc_url(wp_get_attachment_image_url($listing_prv_img, array(90, 90))) . '" alt="' . esc_html($pop_post->post_title) . '">';
} elseif (!empty($listing_img[0]) && empty($listing_prv_img)) {
echo '<img src="' . esc_url(wp_get_attachment_image_url($listing_img[0], array(90, 90))) . '" alt="' . esc_html($pop_post->post_title) . '">';
} else {
echo '<img src="' . $default_image . '" alt="' . esc_html($pop_post->post_title) . '">';
}
if (empty($disable_single_listing)) {
echo '</a>';
}
?>
</div>
<div class="atbd_right_content">
<div class="cate_title">
<h4>
<?php
if (empty($disable_single_listing)) {
?>
<a href="<?php echo esc_url(get_post_permalink($pop_post->ID)); ?>"><?php echo esc_html($pop_post->post_title); ?></a>
<?php
} else {
echo esc_html($pop_post->post_title);
} ?>
</h4>
</div>
<?php if (!empty($cats)) {
$totalTerm = count($cats);
?>
<p class="directory_tag">
<span class="<?php atbdp_icon_type(true); ?>-tags"></span>
<span>
<a href="<?php echo ATBDP_Permalink::atbdp_get_category_page($cats[0]); ?>">
<?php echo esc_html($cats[0]->name); ?>
</a>
<?php
if ($totalTerm > 1) {
?>
<span class="atbd_cat_popup"> +<?php echo $totalTerm - 1; ?>
<span class="atbd_cat_popup_wrapper">
<?php
$output = array();
foreach (array_slice($cats, 1) as $cat) {
$link = ATBDP_Permalink::atbdp_get_category_page($cat);
$space = str_repeat(' ', 1);
$output [] = "{$space}<a href='{$link}'>{$cat->name}<span>,</span></a>";
} ?>
<span><?php echo join($output) ?></span>
</span>
</span>
<?php } ?>
</span>
</p>
<?php }
ATBDP()->show_static_rating($pop_post);
?>
</div>
</li>
<?php } // ends the loop
?>
</ul>
</div> <!--ends .categorized_listings-->
<?php }
}
/**
* It gets the popular listings of the given listing/post
*
* @param int $count [optional] Number of popular listing to show. If the count is more than one then it uses it,
* else the function will use the value from the settings page.
* Count variable is handy if we want to show different number of popular listings on different pages.
* For example, on different widgets place. Default 5.
* @return WP_Query It returns the popular listings if found.
*/
public function get_popular_listings($count = 5, $listing_id = '')
{
/*Popular post related stuff*/
$p_count = !empty($count) ? $count : 5;
$view_to_popular = get_directorist_option('views_for_popular');
/**
* It filters the number of the popular listing to display
* @since 1.0.0
* @param int $p_count The number of popular listing to show
*/
$p_count = apply_filters('atbdp_popular_listing_number', $p_count);
$args = array(
'post_type' => ATBDP_POST_TYPE,
'post_status' => 'publish',
'posts_per_page' => (int)$p_count,
);
$has_featured = get_directorist_option('enable_featured_listing');
if ($has_featured || is_fee_manager_active()) {
$has_featured = 1;
}
$listings = get_atbdp_listings_ids();
$rated = array();
$listing_popular_by = get_directorist_option('listing_popular_by');
$average_review_for_popular = get_directorist_option('average_review_for_popular', 4);
$view_to_popular = get_directorist_option('views_for_popular');
$meta_queries = array();
if ($has_featured) {
if ('average_rating' === $listing_popular_by) {
if ($listings->have_posts()) {
while ($listings->have_posts()) {
$listings->the_post();
$listing_id = get_the_ID();
$average = ATBDP()->review->get_average($listing_id);
if ($average_review_for_popular <= $average) {
$rated[] = get_the_ID();
}
}
$rating_id = array(
'post__in' => !empty($rated) ? $rated : array()
);
$args = array_merge($args, $rating_id);
}
} elseif ('view_count' === $listing_popular_by) {
$meta_queries['views'] = array(
'key' => '_atbdp_post_views_count',
'value' => $view_to_popular,
'type' => 'NUMERIC',
'compare' => '>=',
);
$args['orderby'] = array(
'_featured' => 'DESC',
'views' => 'DESC',
);
} else {
$meta_queries['views'] = array(
'key' => '_atbdp_post_views_count',
'value' => $view_to_popular,
'type' => 'NUMERIC',
'compare' => '>=',
);
$args['orderby'] = array(
'_featured' => 'DESC',
'views' => 'DESC',
);
if ($listings->have_posts()) {
while ($listings->have_posts()) {
$listings->the_post();
$listing_id = get_the_ID();
$average = ATBDP()->review->get_average($listing_id);
if ($average_review_for_popular <= $average) {
$rated[] = get_the_ID();
}
}
$rating_id = array(
'post__in' => !empty($rated) ? $rated : array()
);
$args = array_merge($args, $rating_id);
}
}
} else {
if ('average_rating' === $listing_popular_by) {
if ($listings->have_posts()) {
while ($listings->have_posts()) {
$listings->the_post();
$listing_id = get_the_ID();
$average = ATBDP()->review->get_average($listing_id);
if ($average_review_for_popular <= $average) {
$rated[] = get_the_ID();
}
}
$rating_id = array(
'post__in' => !empty($rated) ? $rated : array()
);
$args = array_merge($args, $rating_id);
}
} elseif ('view_count' === $listing_popular_by) {
$meta_queries['views'] = array(
'key' => '_atbdp_post_views_count',
'value' => $view_to_popular,
'type' => 'NUMERIC',
'compare' => '>=',
);
$args['orderby'] = array(
'views' => 'DESC',
);
} else {
$meta_queries['views'] = array(
'key' => '_atbdp_post_views_count',
'value' => (int)$view_to_popular,
'type' => 'NUMERIC',
'compare' => '>=',
);
$args['orderby'] = array(
'views' => 'DESC',
);
if ($listings->have_posts()) {
while ($listings->have_posts()) {
$listings->the_post();
$listing_id = get_the_ID();
$average = ATBDP()->review->get_average($listing_id);
if ($average_review_for_popular <= $average) {
$rated[] = get_the_ID();
}
}
$rating_id = array(
'post__in' => !empty($rated) ? $rated : array()
);
$args = array_merge($args, $rating_id);
}
}
}
$count_meta_queries = count($meta_queries);
if ($count_meta_queries) {
$args['meta_query'] = ($count_meta_queries > 1) ? array_merge(array('relation' => 'AND'), $meta_queries) : $meta_queries;
}
return new WP_Query(apply_filters('atbdp_popular_listing_args', $args));
}
/**
* It displays static rating of the given post
* @param object|WP_Post $post The current post object
*/
public function show_static_rating($post)
{
$enable_review = get_directorist_option('enable_review', 1);
if (!$enable_review) return; // vail if review is not enabled
$average = ATBDP()->review->get_average($post->ID);
?>
<div class="atbd_rated_stars">
<?php echo ATBDP()->review->print_static_rating($average); ?>
</div>
<?php
}
/**
* It displays related listings of the given post
* @param object|WP_Post $post The current post object
*/
public function show_related_listing($post)
{
/**
* @package Directorist
* @since 5.10.0
*/
do_action('atbdp_before_related_listing_start', $post);
$enable_rel_listing = get_directorist_option('enable_rel_listing', 1);
if (empty($enable_rel_listing)) return; // vail if related listing is not enabled
$related_listings = $this->get_related_listings($post);
$is_disable_price = get_directorist_option('disable_list_price');
$rel_listing_column = get_directorist_option('rel_listing_column', 3);
if ($related_listings->have_posts()) {
$templete = apply_filters('atbdp_related_listing_template', 'default');
related_listing_slider($related_listings, $pagenation = null, $is_disable_price, $templete);
} ?>
<script>
jQuery(document).ready(function ($) {
$('.related__carousel').slick({
dots: false,
arrows: false,
infinite: true,
speed: 300,
slidesToShow: <?php echo $rel_listing_column;?>,
slidesToScroll: 1,
autoplay: true,
rtl: <?php echo is_rtl() ? 'true' : 'false'; ?>,
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: <?php echo $rel_listing_column;?>,
slidesToScroll: 1,
infinite: true,
dots: false
}
},
{
breakpoint: 767,
settings: {
slidesToShow: 2,
slidesToScroll: 1
}
},
{
breakpoint: 575,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
]
});
});
</script>
<?php
}
/**
* It gets the related listings of the given listing/post
* @param object|WP_Post $post The WP Post Object of whose related listing we would like to show
* @return object|WP_Query It returns the related listings if found.
*/
public function get_related_listings($post)
{
$rel_listing_num = get_directorist_option('rel_listing_num', 2);
$atbd_cats = get_the_terms($post, ATBDP_CATEGORY);
$atbd_tags = get_the_terms($post, ATBDP_TAGS);
// get the tag ids of the listing post type
$atbd_cats_ids = array();
$atbd_tags_ids = array();
if (!empty($atbd_cats)) {
foreach ($atbd_cats as $atbd_cat) {
$atbd_cats_ids[] = $atbd_cat->term_id;
}
}
if (!empty($atbd_tags)) {
foreach ($atbd_tags as $atbd_tag) {
$atbd_tags_ids[] = $atbd_tag->term_id;
}
}
$relationship = get_directorist_option('rel_listings_logic','OR');
$args = array(
'post_type' => ATBDP_POST_TYPE,
'tax_query' => array(
'relation' => $relationship,
array(
'taxonomy' => ATBDP_CATEGORY,
'field' => 'term_id',
'terms' => $atbd_cats_ids,
),
array(
'taxonomy' => ATBDP_TAGS,
'field' => 'term_id',
'terms' => $atbd_tags_ids,
),
),
'posts_per_page' => (int)$rel_listing_num,
'post__not_in' => array($post->ID),
);
$meta_queries = array();
$meta_queries[] = array(
'relation' => 'OR',
array(
'key' => '_expiry_date',
'value' => current_time('mysql'),
'compare' => '>', // eg. expire date 6 <= current date 7 will return the post
'type' => 'DATETIME'
),
array(
'key' => '_never_expire',
'value' => 1,
)
);
$meta_queries = apply_filters('atbdp_related_listings_meta_queries', $meta_queries);
$count_meta_queries = count($meta_queries);
if ($count_meta_queries) {
$args['meta_query'] = ($count_meta_queries > 1) ? array_merge(array('relation' => 'AND'), $meta_queries) : $meta_queries;
}
return new WP_Query(apply_filters('atbdp_related_listing_args', $args));
}