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

156 lines 4.7 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 $q = array(
14 'post_type' => 'topic',
15 'posts_per_page' => 9,
16 );
17
18 if ( 'solved' === $data_forum ) {
19 $meta_query = [
20 'meta_query' => array(
21 array(
22 'key' => '_bbp_topic_is_solved',
23 'value' => true,
24 ),
25 ),
26 ];
27 $q = array_merge( $q, $meta_query );
28
29 } elseif ( 'unsolved' === $data_forum ) {
30 $meta_query = [
31 'meta_query' => array(
32 array(
33 'key' => '_bbp_topic_is_solved',
34 'compare' => 'NOT EXISTS',
35 ),
36 ),
37 ];
38
39 $q = array_merge( $q, $meta_query );
40
41 } elseif ( 'recent' === $data_forum ) {
42 $query = [
43 'order' => 'DESC',
44 ];
45
46 $q = array_merge( $q, $query );
47
48 } elseif ( 'popular' === $data_forum ) {
49 $query = [
50 'meta_key' => '_btv_view_count',
51 'orderby' => 'meta_value_num',
52 'order' => 'DESC'
53 ];
54
55 $q = array_merge( $q, $query );
56
57 } elseif ( 'featured' === $data_forum ) {
58 $query = array(
59 'show_stickies' => true,
60 'post__in' => bbp_get_super_stickies()
61 );
62
63 $q = array_merge( $q, $query );
64 }
65
66 // WP_Query arguments
67 $forum_topics = new WP_Query( $q );
68
69 if ( $forum_topics->have_posts() ) {
70 $i = 0;
71 while ( $forum_topics->have_posts() ):
72 $forum_topics->the_post();
73 $item_id = get_the_ID();
74 $author_id = get_post_field( 'post_author', $item_id );
75 $topic_id = $forum_topics->posts[ $i ]->ID;
76 $vote_count = get_post_meta( $topic_id, "bbpv-votes", true );
77 $forum_id = bbp_get_topic_forum_id();
78 ?>
79 <div class="single-forum-post-widget">
80 <div class="post-content">
81 <div class="post-title">
82 <h6> <a href="<?php the_permalink(); ?>"> <?php the_title() ?> </a> </h6>
83 </div>
84 <div class="post-info">
85 <div class="author">
86 <img src="<?php echo BBPC_ASSETS ?>/img/forum_tab/user-circle-alt.svg" alt="<?php esc_attr_e( 'User circle icon', 'bbpc-core' ); ?>">
87 <?php
88 echo bbp_get_topic_author_link(
89 array(
90 'post_id' => $topic_id,
91 'type' => 'name'
92 )
93 );
94 ?>
95 </div>
96
97 <div class="post-time">
98 <img src="<?php echo BBPC_ASSETS ?>/img/forum_tab/time-outline.svg" alt="<?php esc_attr_e( 'Time outline icon', 'bbpc-core' ); ?>">
99 <?php echo bbp_forum_last_active_time( get_the_ID() ); ?>
100 </div>
101 </div>
102
103 <div class="post-category">
104 <a href="<?php echo get_the_permalink( $forum_id ) ?>">
105 <?php echo get_the_post_thumbnail( $forum_id ); ?>
106 <?php echo get_the_title( $forum_id ) ?>
107 </a>
108 </div>
109 </div>
110 <div class="post-reach">
111 <div class="post-view">
112 <img src="<?php echo BBPC_ASSETS ?>/img/forum_tab/eye-outline.svg" alt="<?php esc_attr_e( 'Eye outline icon', 'bbpc-core' ); ?>">
113
114 <?php
115 bbp_topic_view_count( $topic_id );
116 echo '&nbsp;';
117 _e( 'Views', 'bbp-core' );
118 ?>
119
120 </div>
121 <div class="post-like">
122 <img src="<?php echo BBPC_ASSETS ?>/img/forum_tab/thumbs-up-outline.svg" alt="<?php esc_attr_e( 'Thumbs up icon', 'bbpc-core' ); ?>">
123
124 <?php
125 if ( $vote_count ) {
126 echo $vote_count;
127 } else {
128 echo "0";
129 }
130
131 echo '&nbsp;';
132 _e( 'Likes', 'bbp-core' );
133 ?>
134 </div>
135 <div class="post-comment">
136 <img src="<?php echo BBPC_ASSETS ?>/img/forum_tab/chatbubbles-outline.svg" alt="<?php esc_attr_e( 'Chatbubbles outline icon', 'bbpc-core' ); ?>">
137
138 <?php
139 echo bbp_topic_reply_count( $topic_id );
140 echo '&nbsp;';
141 _e( 'Replies', 'bbp-core' );
142 ?>
143 </div>
144 </div>
145 </div>
146 <?php
147 $i ++;
148 endwhile;
149 unset( $i );
150 } else {
151 echo 'no posts found';
152 }
153
154 wp_reset_postdata();
155 wp_die();
156 }