PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.4.1
Forumax – AI Powered Advanced Community Forum Plugin v2.4.1
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 2.4.1, at includes/Elementor/inc/forum-ajax.php

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