PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 1.3.0
Forumax – AI Powered Advanced Community Forum Plugin v1.3.0
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / includes / Elementor / inc / forum-ajax.php

forum-ajax.php in Forumax – AI Powered Advanced Community Forum Plugin 1.3.0, at includes/Elementor/inc/forum-ajax.php

178 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Ajax Actions for forum filtering
4 * @since 0.0.1
5 */
6 add_action( 'wp_ajax_bbpc_ajax_forum', 'bbpc_ajax_forum' );
7 add_action( 'wp_ajax_nopriv_bbpc_ajax_forum', 'bbpc_ajax_forum' );
8
9 function bbpc_ajax_forum() {
10 // received values from front end forum
11 $data_forum = sanitize_text_field( $_POST['data_forum'] );
12
13 $args = array(
14 'post_type' => 'topic',
15 'posts_per_page' => 9,
16 );
17
18 if ( 'solved' === $data_forum ) {
19 $args['meta_query'] = array(
20 array(
21 'key' => '_bbp_topic_is_solved',
22 'value' => true,
23 ),
24 );
25 } elseif ( 'unsolved' === $data_forum ) {
26 $args['meta_query'] = array(
27 array(
28 'key' => '_bbp_topic_is_solved',
29 'compare' => 'NOT EXISTS',
30 ),
31 );
32 } elseif ( 'recent' === $data_forum ) {
33 $args['order'] = 'DESC';
34 } elseif ( 'popular' === $data_forum ) {
35 $args['meta_query'] = array(
36 'relation' => 'OR',
37 array(
38 'key' => '_btv_view_count',
39 'value' => 0,
40 'compare' => '>',
41 'type' => 'NUMERIC',
42 ),
43 array(
44 'key' => '_bbp_reply_count',
45 'value' => 0,
46 'compare' => '>',
47 'type' => 'NUMERIC',
48 ),
49 array(
50 'key' => 'bbpv-votes',
51 'value' => 0,
52 'compare' => '>',
53 'type' => 'NUMERIC',
54 ),
55 );
56 $args['orderby'] = array(
57 'meta_value_num' => 'DESC',
58 'comment_count' => 'DESC',
59 );
60 } elseif ( 'featured' === $data_forum ) {
61
62 $super_stickies = bbp_get_super_stickies(); // Get global super sticky topics
63
64 // Get sticky topics from all forums
65 $stickies = [];
66 $forums = get_posts([
67 'post_type' => 'forum',
68 'posts_per_page' => -1,
69 'fields' => 'ids',
70 ]);
71
72 foreach ($forums as $forum_id) {
73 $stickies = array_merge($stickies, bbp_get_stickies($forum_id));
74 }
75
76 // Merge both sticky types
77 $sticky_topics = array_merge($super_stickies, $stickies);
78 $sticky_topics = array_unique($sticky_topics);
79
80 if ( !empty($sticky_topics) ) {
81 $args['post__in'] = $sticky_topics;
82 } else {
83 wp_send_json_error(__('No featured (sticky) topics found', 'bbp-core'));
84 }
85
86 }
87
88 // WP_Query arguments
89 $forum_topics = new WP_Query( $args );
90
91 if ( $forum_topics->have_posts() ) {
92 $i = 0;
93 while ( $forum_topics->have_posts() ):
94 $forum_topics->the_post();
95 $item_id = get_the_ID();
96 $author_id = get_post_field( 'post_author', $item_id );
97 $topic_id = $forum_topics->posts[ $i ]->ID;
98 $vote_count = get_post_meta( $topic_id, "bbpv-votes", true );
99 $forum_id = bbp_get_topic_forum_id();
100 ?>
101 <div class="single-forum-post-widget">
102 <div class="post-content">
103 <div class="post-title">
104 <h6> <a href="<?php the_permalink(); ?>"> <?php the_title() ?> </a> </h6>
105 </div>
106 <div class="post-info">
107 <div class="author">
108 <img src="<?php echo BBPC_ASSETS . '/img/forum_tab/user-circle-alt.svg' ?>" alt="<?php esc_attr_e( 'User circle icon', 'bbpc-core' ); ?>">
109 <?php
110 echo bbp_get_topic_author_link(
111 array(
112 'post_id' => $topic_id,
113 'type' => 'name'
114 )
115 );
116 ?>
117 </div>
118
119 <div class="post-time">
120 <img src="<?php echo BBPC_ASSETS . '/img/forum_tab/time-outline.svg' ?>" alt="<?php esc_attr_e( 'Time outline icon', 'bbpc-core' ); ?>">
121 <?php bbp_forum_last_active_time( get_the_ID() ); ?>
122 </div>
123 </div>
124
125 <div class="post-category">
126 <a href="<?php echo get_the_permalink( $forum_id ) ?>">
127 <?php echo get_the_post_thumbnail( $forum_id ); ?>
128 <?php echo get_the_title( $forum_id ) ?>
129 </a>
130 </div>
131 </div>
132 <div class="post-reach">
133 <div class="post-view">
134 <img src="<?php echo BBPC_ASSETS . '/img/forum_tab/eye-outline.svg' ?>" alt="<?php esc_attr_e( 'Eye outline icon', 'bbpc-core'); ?>">
135
136 <?php
137 bbp_topic_view_count( $topic_id );
138 echo '&nbsp;';
139 esc_html_e( 'Views dddddd', 'bbp-core' );
140 ?>
141
142 </div>
143 <div class="post-like">
144 <img src="<?php echo BBPC_ASSETS . '/img/forum_tab/thumbs-up-outline.svg' ?>" alt="<?php esc_attr_e( 'Thumbs up icon', 'bbpc-core'); ?>">
145
146 <?php
147 if ( $vote_count ) {
148 echo $vote_count;
149 } else {
150 echo "0";
151 }
152
153 echo '&nbsp;';
154 _e( 'Likes', 'bbp-core' );
155 ?>
156 </div>
157 <div class="post-comment">
158 <img src="<?php echo BBPC_ASSETS . '/img/forum_tab/chatbubbles-outline.svg' ?>" alt="<?php esc_attr_e( 'Chatbubbles outline icon', 'bbpc-core' ); ?>">
159
160 <?php
161 bbp_topic_reply_count( $topic_id );
162 echo '&nbsp;';
163 _e( 'Replies', 'bbp-core' );
164 ?>
165 </div>
166 </div>
167 </div>
168 <?php
169 $i ++;
170 endwhile;
171 unset( $i );
172 } else {
173 esc_html_e('no posts found', 'bbp-core');
174 }
175
176 wp_reset_postdata();
177 wp_die();
178 }