PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.1
Forumax – AI Powered Advanced Community Forum Plugin v2.5.1
2.5.1 2.5.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 All 31 releases
bbp-core / includes / Elementor / inc / forum-ajax.php

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

213 lines 6.1 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
7 defined( 'ABSPATH' ) || exit;
8
9 add_action( 'wp_ajax_forumax_ajax_forum', 'forumax_ajax_forum' );
10 add_action( 'wp_ajax_nopriv_forumax_ajax_forum', 'forumax_ajax_forum' );
11
12 /**
13 * AJAX handler for forum filtering
14 *
15 * @return void
16 */
17 function forumax_ajax_forum() {
18 check_ajax_referer( 'forumax-nonce', 'nonce' );
19
20 // received values from front end forum
21 $data_forum = isset( $_POST['data_forum'] ) ? sanitize_text_field( wp_unslash( $_POST['data_forum'] ) ) : '';
22
23 $args = [
24 'post_type' => 'topic',
25 'posts_per_page' => 9,
26 'no_found_rows' => true,
27 ];
28
29 if ( 'solved' === $data_forum ) {
30 $args['meta_query'] = [
31 [
32 'key' => '_bbp_topic_is_solved',
33 'value' => true,
34 ],
35 ];
36 } elseif ( 'unsolved' === $data_forum ) {
37 $args['meta_query'] = [
38 [
39 'key' => '_bbp_topic_is_solved',
40 'compare' => 'NOT EXISTS',
41 ],
42 ];
43 } elseif ( 'recent' === $data_forum ) {
44 $args['order'] = 'DESC';
45 } elseif ( 'loved' === $data_forum ) {
46 // Topics with positive vote counts (most loved)
47 $args['meta_query'] = [
48 [
49 'key' => 'bbpv-votes',
50 'value' => 0,
51 'compare' => '>',
52 'type' => 'NUMERIC',
53 ],
54 ];
55 $args['orderby'] = [
56 'meta_value_num' => 'DESC',
57 'comment_count' => 'DESC',
58 ];
59 } elseif ( 'unloved' === $data_forum ) {
60 // Topics without positive votes (no votes or zero)
61 $args['meta_query'] = [
62 'relation' => 'OR',
63 [
64 'key' => 'bbpv-votes',
65 'compare' => 'NOT EXISTS',
66 ],
67 [
68 'key' => 'bbpv-votes',
69 'value' => 0,
70 'compare' => '=',
71 'type' => 'NUMERIC',
72 ],
73 ];
74 } elseif ( 'popular' === $data_forum ) {
75 $args['meta_query'] = [
76 'relation' => 'OR',
77 [
78 'key' => '_btv_view_count',
79 'value' => 0,
80 'compare' => '>',
81 'type' => 'NUMERIC',
82 ],
83 [
84 'key' => '_bbp_reply_count',
85 'value' => 0,
86 'compare' => '>',
87 'type' => 'NUMERIC',
88 ],
89 [
90 'key' => 'bbpv-votes',
91 'value' => 0,
92 'compare' => '>',
93 'type' => 'NUMERIC',
94 ],
95 ];
96 $args['orderby'] = [
97 'meta_value_num' => 'DESC',
98 'comment_count' => 'DESC',
99 ];
100 } elseif ( 'featured' === $data_forum ) {
101
102 $super_stickies = bbp_get_super_stickies(); // Get global super sticky topics
103
104 // Get sticky topics from all forums in one query.
105 $stickies = forumax_get_all_forum_stickies( true );
106
107 // Merge both sticky types
108 $sticky_topics = array_merge( $super_stickies, $stickies );
109 $sticky_topics = array_unique( $sticky_topics );
110
111 if ( ! empty( $sticky_topics ) ) {
112 $args['post__in'] = $sticky_topics;
113 } else {
114 wp_send_json_error( __( 'No featured (sticky) topics found', 'forumax' ) );
115 }
116
117 }
118
119 // WP_Query arguments
120 $forum_topics = new WP_Query( $args );
121
122 if ( $forum_topics->have_posts() ) {
123 $i = 0;
124 while ( $forum_topics->have_posts() ):
125 $forum_topics->the_post();
126 $item_id = get_the_ID();
127 $author_id = get_post_field( 'post_author', $item_id );
128 $topic_id = $forum_topics->posts[ $i ]->ID;
129 $vote_count = get_post_meta( $topic_id, "bbpv-votes", true );
130 $forum_id = bbp_get_topic_forum_id();
131 ?>
132 <div class="single-forum-post-widget">
133 <div class="post-content">
134 <div class="post-title">
135 <h6><a href="<?php the_permalink(); ?>"> <?php the_title() ?> </a></h6>
136 </div>
137 <div class="post-info">
138 <div class="author">
139 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/user-circle-alt.svg' ); ?>" alt="<?php esc_attr_e( 'User circle icon', 'forumax' ); ?>">
140 <?php
141 echo wp_kses_post( bbp_get_topic_author_link(
142 [
143 'post_id' => $topic_id,
144 'type' => 'name'
145 ]
146 ) );
147 ?>
148 </div>
149
150 <div class="post-time">
151 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/time-outline.svg' ); ?>"
152 alt="<?php esc_attr_e( 'Time outline icon', 'forumax' ); ?>">
153 <?php bbp_forum_last_active_time( get_the_ID() ); ?>
154 </div>
155 </div>
156
157 <div class="post-category">
158 <a href="<?php echo esc_url( get_the_permalink( $forum_id ) ) ?>">
159 <?php echo get_the_post_thumbnail( $forum_id ); ?>
160 <?php echo esc_html( get_the_title( $forum_id ) ); ?>
161 </a>
162 </div>
163 </div>
164 <div class="post-reach">
165 <div class="post-view">
166 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/eye-outline.svg' ); ?>"
167 alt="<?php esc_attr_e( 'Eye outline icon', 'forumax' ); ?>">
168
169 <?php
170 forumax_topic_view_count( $topic_id );
171 echo '&nbsp;';
172 esc_html_e( 'Views', 'forumax' );
173 ?>
174
175 </div>
176 <div class="post-like">
177 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/thumbs-up-outline.svg' ); ?>"
178 alt="<?php esc_attr_e( 'Thumbs up icon', 'forumax' ); ?>">
179
180 <?php
181 if ( $vote_count ) {
182 echo esc_html( $vote_count );
183 } else {
184 echo "0";
185 }
186
187 echo '&nbsp;';
188 esc_html_e( 'Likes', 'forumax' );
189 ?>
190 </div>
191 <div class="post-comment">
192 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/chatbubbles-outline.svg' ); ?>"
193 alt="<?php esc_attr_e( 'Chatbubbles outline icon', 'forumax' ); ?>">
194
195 <?php
196 bbp_topic_reply_count( $topic_id );
197 echo '&nbsp;';
198 esc_html_e( 'Replies', 'forumax' );
199 ?>
200 </div>
201 </div>
202 </div>
203 <?php
204 $i ++;
205 endwhile;
206 } else {
207 esc_html_e( 'no posts found', 'forumax' );
208 }
209
210 wp_reset_postdata();
211 wp_die();
212 }
213