| @@ -1,564 +1,641 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * All Search results | |
| 5 | - */ | |
| 6 | -add_action( 'wp_ajax_forumax_search_data_fetch', 'forumax_search_data_fetch' ); | |
| 7 | -add_action( 'wp_ajax_nopriv_forumax_search_data_fetch', 'forumax_search_data_fetch' ); | |
| 8 | -function forumax_search_data_fetch() { | |
| 9 | - | |
| 10 | - $opt = get_option( 'bbpc_opt' ); | |
| 11 | - $is_ajax_search_tab = $opt['is_ajax_search_tab'] ?? ''; | |
| 12 | - global $post; | |
| 13 | - | |
| 14 | - if ( class_exists( 'bbPress' ) ) { | |
| 15 | - // All results query | |
| 16 | - $all_results = new WP_Query( array( | |
| 17 | - 'post_type' => ['forum', 'topic' ], | |
| 18 | - 's' => $_POST['keyword'] ?? '', | |
| 19 | - ) ); | |
| 20 | - $all_results_count = $all_results->found_posts; | |
| 21 | - if ( $all_results_count > 0 ) { | |
| 22 | - $all_nsoresult = 'data-result='; | |
| 23 | - } else { | |
| 24 | - $all_nsoresult = 'data-noresult='; | |
| 25 | - } | |
| 26 | - | |
| 27 | - // Forum query | |
| 28 | - $forum_query = new WP_Query( array( | |
| 29 | - 'post_type' => ['forum', 'topic'], | |
| 30 | - 's' => $_POST['keyword'] ?? '', | |
| 31 | - ) ); | |
| 32 | - $forum_count = $forum_query->found_posts; | |
| 33 | - if ( $forum_count > 0 ) { | |
| 34 | - $forum_nsoresult = 'data-result='; | |
| 35 | - } else { | |
| 36 | - $forum_nsoresult = 'data-noresult='; | |
| 37 | - } | |
| 38 | - | |
| 39 | - ?> | |
| 40 | - <div class="tab-item active all-active" <?php echo esc_attr( $all_nsoresult. 'No-Results-Found' ); ?>></div> | |
| 41 | - <?php | |
| 42 | - if ( class_exists( 'bbPress' ) ) : ?> | |
| 43 | - <div id="search-forum" <?php echo esc_attr( $forum_nsoresult. 'No-Results-Found' ); ?> class="tab-item" ></div> | |
| 44 | - <?php | |
| 45 | - endif; | |
| 46 | - } | |
| 47 | - | |
| 48 | - echo '<div class="bbpc-search-results-wrapper">'; | |
| 49 | - | |
| 50 | - // Forums query | |
| 51 | - if ( class_exists( 'bbPress' ) ) : | |
| 52 | - | |
| 53 | - echo '<div class="search-results-tab forum show" id="search-forum-results">'; | |
| 54 | - | |
| 55 | - $forum = new WP_Query( array( | |
| 56 | - 'post_type' => 'forum', | |
| 57 | - 's' => $_POST['keyword'] ?? '', | |
| 58 | - 'posts_per_page' => 5, | |
| 59 | - ) ); | |
| 60 | - | |
| 61 | - if ( $forum->have_posts() ) : | |
| 62 | - echo '<h2 class="bbpc-search-title">' . esc_html__( 'Forums', 'forumax' ) . '</h2>'; | |
| 63 | - while ( $forum->have_posts() ) : $forum->the_post(); | |
| 64 | - ?> | |
| 65 | - <div class="search-result-item forum" onclick="document.location='<?php echo esc_url( get_the_permalink(get_the_ID()) ); ?>'"> | |
| 66 | - <a href="<?php echo esc_url( get_the_permalink(get_the_ID()) ); ?>"> | |
| 67 | - <?php the_title(); ?> | |
| 68 | - </a> | |
| 69 | - </div> | |
| 70 | - <?php | |
| 71 | - endwhile; | |
| 72 | - wp_reset_postdata(); | |
| 73 | - endif; | |
| 74 | - | |
| 75 | - $topics = new WP_Query( array( | |
| 76 | - 'post_type' => 'topic', | |
| 77 | - 's' => $_POST['keyword'] ?? '', | |
| 78 | - 'posts_per_page' => 5, | |
| 79 | - ) ); | |
| 80 | - | |
| 81 | - if ( $topics->have_posts() ) : | |
| 82 | - echo '<h2 class="bbpc-search-title">' . esc_html__( 'Topics', 'forumax' ) . '</h2>'; | |
| 83 | - while ( $topics->have_posts() ) : $topics->the_post(); | |
| 84 | - ?> | |
| 85 | - <div class="search-result-item forum" onclick="document.location='<?php echo esc_url( get_the_permalink(get_the_ID()) ); ?>'"> | |
| 86 | - <a href="<?php echo esc_url( get_the_permalink(get_the_ID()) ); ?>"> | |
| 87 | - <?php the_title(); ?> | |
| 88 | - </a> | |
| 89 | - </div> | |
| 90 | - <?php | |
| 91 | - endwhile; | |
| 92 | - wp_reset_postdata(); | |
| 93 | - endif; | |
| 94 | - echo '</div>'; | |
| 95 | - endif; | |
| 96 | - | |
| 97 | - echo '<h5 class="not-found-text">' . esc_html__( 'Not Found Result!', 'forumax' ) . '</h5>'; | |
| 98 | - echo '</div>'; | |
| 99 | - die(); | |
| 100 | -} | |
| 101 | - | |
| 102 | -/** | |
| 103 | - * Forum Search results | |
| 104 | - */ | |
| 105 | -add_action( 'wp_ajax_forumax_search_data_forum', 'forumax_search_data_forum' ); | |
| 106 | -add_action( 'wp_ajax_nopriv_forumax_search_data_forum', 'forumax_search_data_forum' ); | |
| 107 | -function forumax_search_data_forum() { | |
| 108 | - | |
| 109 | - // Forums query | |
| 110 | - if ( class_exists( 'bbPress' ) ) : | |
| 111 | - | |
| 112 | - echo '<div class="search-results-tab show" id="search-forum-results">'; | |
| 113 | - | |
| 114 | - $forum = new WP_Query( array( | |
| 115 | - 'post_type' => 'forum', | |
| 116 | - 's' => $_POST['keyword'] ?? '', | |
| 117 | - 'posts_per_page' => 5, | |
| 118 | - ) ); | |
| 119 | - | |
| 120 | - if ( $forum->have_posts() ) : | |
| 121 | - echo '<h2 class="bbpc-search-title">' . esc_html__( 'Forums', 'forumax' ) . '</h2>'; | |
| 122 | - while ( $forum->have_posts() ) : $forum->the_post(); | |
| 123 | - ?> | |
| 124 | - <div class="search-result-item forum" onclick="document.location='<?php echo esc_url( get_the_permalink(get_the_ID()) ); ?>'"> | |
| 125 | - <a href="<?php echo esc_url( get_the_permalink(get_the_ID()) ); ?>"> | |
| 126 | - <?php the_title(); ?> | |
| 127 | - </a> | |
| 128 | - </div> | |
| 129 | - <?php | |
| 130 | - endwhile; | |
| 131 | - wp_reset_postdata(); | |
| 132 | - endif; | |
| 133 | - | |
| 134 | - $topics = new WP_Query( array( | |
| 135 | - 'post_type' => 'topic', | |
| 136 | - 's' => $_POST['keyword'] ?? '', | |
| 137 | - 'posts_per_page' => 5, | |
| 138 | - ) ); | |
| 139 | - | |
| 140 | - if ( $topics->have_posts() ) : | |
| 141 | - echo '<h2 class="bbpc-search-title">' . esc_html__( 'Topics', 'forumax' ) . '</h2>'; | |
| 142 | - while ( $topics->have_posts() ) : $topics->the_post(); | |
| 143 | - ?> | |
| 144 | - <div class="search-result-item forum" onclick="document.location='<?php echo esc_url( get_the_permalink(get_the_ID()) ); ?>'"> | |
| 145 | - <a href="<?php echo esc_url( get_the_permalink(get_the_ID()) ); ?>"> | |
| 146 | - <?php the_title(); ?> | |
| 147 | - </a> | |
| 148 | - </div> | |
| 149 | - <?php | |
| 150 | - endwhile; | |
| 151 | - wp_reset_postdata(); | |
| 152 | - endif; | |
| 153 | - echo '</div>'; | |
| 154 | - endif; | |
| 155 | - die(); | |
| 156 | -} | |
| 157 | - | |
| 158 | -/** | |
| 159 | - * AJAX handler to fetch forums for Gutenberg block editor | |
| 160 | - * Used by the Single Forum block to populate the forum selector dropdown | |
| 161 | - */ | |
| 162 | -add_action( 'wp_ajax_bbpc_get_forums', 'forumax_get_forums_ajax' ); | |
| 163 | -add_action( 'wp_ajax_nopriv_bbpc_get_forums', 'forumax_get_forums_ajax' ); | |
| 164 | -function forumax_get_forums_ajax() { | |
| 165 | - // Get all forums | |
| 166 | - $forums = new \WP_Query( array( | |
| 167 | - 'post_type' => 'forum', | |
| 168 | - 'posts_per_page' => -1, | |
| 169 | - 'orderby' => 'title', | |
| 170 | - 'order' => 'ASC', | |
| 171 | - ) ); | |
| 172 | - | |
| 173 | - $forum_list = array(); | |
| 174 | - | |
| 175 | - if ( $forums->have_posts() ) { | |
| 176 | - while ( $forums->have_posts() ) { | |
| 177 | - $forums->the_post(); | |
| 178 | - $forum_list[] = array( | |
| 179 | - 'id' => get_the_ID(), | |
| 180 | - 'title' => get_the_title(), | |
| 181 | - ); | |
| 182 | - } | |
| 183 | - wp_reset_postdata(); | |
| 184 | - } | |
| 185 | - | |
| 186 | - wp_send_json_success( $forum_list ); | |
| 187 | -} | |
| 188 | - | |
| 189 | - | |
| 190 | -/** | |
| 191 | - * Loading Post | |
| 192 | - * | |
| 193 | - * @return string | |
| 194 | - */ | |
| 195 | -add_action( 'wp_ajax_forumax_loading_post', 'forumax_loading_post' ); | |
| 196 | -add_action( 'wp_ajax_nopriv_forumax_loading_post', 'forumax_loading_post' ); | |
| 197 | - | |
| 198 | -/** | |
| 199 | - * Loading forum posts | |
| 200 | - */ | |
| 201 | -function forumax_loading_post() { | |
| 202 | - global $wpdb; | |
| 203 | - | |
| 204 | - $nonce = sanitize_text_field( $_POST['nonce'] ); | |
| 205 | - $type = sanitize_text_field( $_POST['type'] ); | |
| 206 | - $post_in = sanitize_text_field( $_POST['a_t_id'] ); | |
| 207 | - $count = sanitize_text_field( $_POST['count'] ); | |
| 208 | - $parent = sanitize_text_field( $_POST['parent'] ); | |
| 209 | - if ( ! wp_verify_nonce( $nonce, 'forumax-nonce' ) ) { | |
| 210 | - die( '-1' ); | |
| 211 | - } | |
| 212 | - $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; | |
| 213 | - $q = [ | |
| 214 | - 'post_type' => 'topic', | |
| 215 | - 'post_parent' => $parent, | |
| 216 | - 'order' => 'DESC', | |
| 217 | - 'orderby' => 'post_date', | |
| 218 | - 'post_status' => 'publish', | |
| 219 | - 'posts_per_page' => - 1, | |
| 220 | - 'ignore_sticky_posts' => 1, | |
| 221 | - ]; | |
| 222 | - if ( $type == 'author' ) { | |
| 223 | - $auth_ids = [ | |
| 224 | - 'author' => $post_in, | |
| 225 | - ]; | |
| 226 | - $q = array_merge( $q, $auth_ids ); | |
| 227 | - } elseif ( $type == 'tag' ) { | |
| 228 | - $tax_query[] = [ | |
| 229 | - 'taxonomy' => 'topic-tag', | |
| 230 | - 'field' => 'term_id', | |
| 231 | - 'terms' => $post_in, | |
| 232 | - ]; | |
| 233 | - } | |
| 234 | - $tax_query[] = [ | |
| 235 | - 'taxonomy' => 'post_format', | |
| 236 | - 'field' => 'slug', | |
| 237 | - 'terms' => [ 'post-format-quote', 'post-format-link' ], | |
| 238 | - 'operator' => 'NOT IN', | |
| 239 | - ]; | |
| 240 | - if ( ! empty( $tax_query ) ) { | |
| 241 | - $tax_query = array_merge( [ 'relation' => 'AND' ], $tax_query ); | |
| 242 | - $q = array_merge( $q, [ 'tax_query' => $tax_query ] ); | |
| 243 | - } | |
| 244 | - $query = new WP_Query( $q ); | |
| 245 | - | |
| 246 | - if ( $query->have_posts() ): | |
| 247 | - echo '<div class="community-posts-wrapper bb-radius">'; | |
| 248 | - while ( $query->have_posts() ): $query->the_post(); | |
| 249 | - global $post; | |
| 250 | - $author_id = $post->post_author; | |
| 251 | - $parent_post_id = $parent; | |
| 252 | - $favoriters = get_post_meta( get_the_ID(), '_bbp_favorite', true ); | |
| 253 | - $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0'; | |
| 254 | - $get_reply = get_post_meta( get_the_ID(), '_bbp_reply_count', true ); | |
| 255 | - $_reply_count = isset( $get_reply ) && ! empty( $get_reply ) ? $get_reply : 0; | |
| 256 | - ?> | |
| 257 | - <div class="community-post style-two <?php the_author_meta( 'user_nicename', $author_id ); ?>"> | |
| 258 | - <div class="post-content"> | |
| 259 | - <div class="author-avatar"> | |
| 260 | - <?php | |
| 261 | - echo bbp_get_topic_author_link( | |
| 262 | - array( | |
| 263 | - 'post_id' => get_the_ID(), | |
| 264 | - 'type' => 'avatar', | |
| 265 | - 'size' => 40 | |
| 266 | - ) | |
| 267 | - ); | |
| 268 | - ?> | |
| 269 | - </div> | |
| 270 | - <div class="entry-content"> | |
| 271 | - <?php the_title( sprintf( '<a href="%s" rel="bookmark"> <h3 class="post-title">', esc_url( get_permalink() ) ), '</h3></a>' ); ?> | |
| 272 | - <ul class="meta"> | |
| 273 | - <li> | |
| 274 | - <?php echo get_the_post_thumbnail( bbp_get_topic_forum_id(), array( 40, 40 ) ); ?> | |
| 275 | - <a href="<?php echo get_permalink( bbp_get_topic_forum_id() ); ?>"> | |
| 276 | - <?php echo get_the_title( bbp_get_topic_forum_id() ); ?> | |
| 277 | - </a> | |
| 278 | - </li> | |
| 279 | - <li><i class="icon_clock_alt"></i> <?php bbp_topic_post_date( get_the_ID() ); ?> </li> | |
| 280 | - </ul> | |
| 281 | - </div> | |
| 282 | - </div> | |
| 283 | - <div class="post-meta-wrapper"> | |
| 284 | - <ul class="post-meta-info"> | |
| 285 | - <li><a href="#"><i class="icon_chat_alt"></i><?php echo esc_html( $_reply_count ); ?></a></li> | |
| 286 | - <li><a href="#"><i class="icon_star"></i><?php echo esc_html( $favorite_count ); ?></a></li> | |
| 287 | - </ul> | |
| 288 | - </div> | |
| 289 | - </div> | |
| 290 | - <?php | |
| 291 | - endwhile; | |
| 292 | - wp_reset_postdata(); | |
| 293 | - | |
| 294 | - echo '</div>'; | |
| 295 | - else: | |
| 296 | - echo '<div class="community-post-error bug">'; | |
| 297 | - echo '<div class="error-content">'; | |
| 298 | - echo '<svg height="40" class="forumax-error error-icon" viewBox="0 0 24 24" version="1.1" width="40" aria-hidden="true"><path d="M12 7a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0112 7zm1 9a1 1 0 11-2 0 1 1 0 012 0z"></path><path fill-rule="evenodd" d="M12 1C5.925 1 1 5.925 1 12s4.925 11 11 11 11-4.925 11-11S18.075 1 12 1zM2.5 12a9.5 9.5 0 1119 0 9.5 9.5 0 01-19 0z"></path></svg>'; | |
| 299 | - echo '<h3 class="error">' . esc_html__( 'Oops! No results matched your search.', 'forumax' ) . '</h3>'; | |
| 300 | - echo '<p class="error">' . esc_html__( 'You could search again.', 'forumax' ) . '</p>'; | |
| 301 | - echo '</div>'; | |
| 302 | - echo '</div>'; | |
| 303 | - endif; | |
| 304 | - | |
| 305 | - die; | |
| 306 | -} | |
| 307 | - | |
| 308 | - | |
| 309 | - | |
| 310 | -/** | |
| 311 | - * Loading Post | |
| 312 | - * | |
| 313 | - * @return string | |
| 314 | - */ | |
| 315 | -add_action( 'wp_ajax_forumax_open_post', 'forumax_open_post' ); | |
| 316 | -add_action( 'wp_ajax_nopriv_forumax_open_post', 'forumax_open_post' ); | |
| 317 | - | |
| 318 | -function forumax_open_post() { | |
| 319 | - global $wpdb; | |
| 320 | - | |
| 321 | - $is_queried_obj = is_singular( 'forum' ) ? get_queried_object_id() : false; | |
| 322 | - $nonce = sanitize_text_field( $_POST['nonce'] ); | |
| 323 | - $type = sanitize_text_field( $_POST['type'] ); | |
| 324 | - $post_in = sanitize_text_field( $_POST['a_t_id'] ); | |
| 325 | - $count = sanitize_text_field( $_POST['count'] ); | |
| 326 | - $parent = sanitize_text_field( $_POST['parent'] ); | |
| 327 | - $userid = sanitize_text_field( $_POST['userid'] ); | |
| 328 | - | |
| 329 | - if ( ! wp_verify_nonce( $nonce, 'forumax-nonce' ) ) { | |
| 330 | - die( '-1' ); | |
| 331 | - } | |
| 332 | - | |
| 333 | - $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; | |
| 334 | - $q = [ | |
| 335 | - 'post_type' => 'topic', | |
| 336 | - 'post_parent' => $parent, | |
| 337 | - 'order' => 'DESC', | |
| 338 | - 'orderby' => 'post_date', | |
| 339 | - 'posts_per_page' => get_option( '_bbp_topics_per_page', 10 ), | |
| 340 | - 'ignore_sticky_posts' => 1, | |
| 341 | - 'author' => $userid | |
| 342 | - ]; | |
| 343 | - if ( $type == 'open' ) { | |
| 344 | - $status = [ | |
| 345 | - 'post_status' => 'publish', | |
| 346 | - ]; | |
| 347 | - $q = array_merge( $q, $status ); | |
| 348 | - } elseif ( $type == 'closed' ) { | |
| 349 | - $status = [ | |
| 350 | - 'post_status' => 'closed', | |
| 351 | - ]; | |
| 352 | - $q = array_merge( $q, $status ); | |
| 353 | - } | |
| 354 | - $tax_query[] = [ | |
| 355 | - 'taxonomy' => 'post_format', | |
| 356 | - 'field' => 'slug', | |
| 357 | - 'terms' => [ 'post-format-quote', 'post-format-link' ], | |
| 358 | - 'operator' => 'NOT IN', | |
| 359 | - ]; | |
| 360 | - if ( ! empty( $tax_query ) ) { | |
| 361 | - $tax_query = array_merge( [ 'relation' => 'AND' ], $tax_query ); | |
| 362 | - $q = array_merge( $q, [ 'tax_query' => $tax_query ] ); | |
| 363 | - } | |
| 364 | - $query = new WP_Query( $q ); | |
| 365 | - if ( $query->have_posts() ): | |
| 366 | - echo '<div class="community-posts-wrapper bb-radius">'; | |
| 367 | - while ( $query->have_posts() ): $query->the_post(); | |
| 368 | - global $post; | |
| 369 | - $author_id = $post->post_author; | |
| 370 | - //$parent_post_id = get_post_meta( get_the_ID(), '_bbp_topic_id', true ); | |
| 371 | - $parent_post_id = $parent; | |
| 372 | - $favoriters = get_post_meta( get_the_ID(), '_bbp_favorite', true ); | |
| 373 | - $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0'; | |
| 374 | - $get_reply = get_post_meta( get_the_ID(), '_bbp_reply_count', true ); | |
| 375 | - $_reply_count = isset( $get_reply ) && ! empty( $get_reply ) ? $get_reply : 0; | |
| 376 | - ?> | |
| 377 | - | |
| 378 | - <div class="community-post style-two <?php the_author_meta( 'user_nicename', $author_id ); ?>"> | |
| 379 | - <div class="post-content"> | |
| 380 | - <div class="author-avatar"> | |
| 381 | - <?php | |
| 382 | - echo bbp_get_topic_author_link( | |
| 383 | - array( | |
| 384 | - 'post_id' => get_the_ID(), | |
| 385 | - 'type' => 'avatar', | |
| 386 | - 'size' => 40 | |
| 387 | - ) | |
| 388 | - ); | |
| 389 | - ?> | |
| 390 | - </div> | |
| 391 | - <div class="entry-content"> | |
| 392 | - <?php the_title( sprintf( '<a href="%s" rel="bookmark"> <h3 class="post-title">', get_permalink() ), '</h3></a>' ); ?> | |
| 393 | - <ul class="meta"> | |
| 394 | - <li> | |
| 395 | - <?php echo get_the_post_thumbnail( bbp_get_topic_forum_id(), array( 40, 40 ) ); ?> | |
| 396 | - <a href="<?php echo get_permalink( bbp_get_topic_forum_id() ); ?>"> | |
| 397 | - <?php echo get_the_title( bbp_get_topic_forum_id() ); ?> | |
| 398 | - </a> | |
| 399 | - </li> | |
| 400 | - <li><i class="icon_clock_alt"></i> <?php bbp_topic_post_date( get_the_ID() ); ?> </li> | |
| 401 | - </ul> | |
| 402 | - </div> | |
| 403 | - </div> | |
| 404 | - <div class="post-meta-wrapper"> | |
| 405 | - <ul class="post-meta-info"> | |
| 406 | - <li><a href="#"><i class="icon_chat_alt"></i><?php echo esc_html( $_reply_count ); ?></a></li> | |
| 407 | - <li><a href="#"><i class="icon_star"></i><?php echo esc_html( $favorite_count ); ?></a></li> | |
| 408 | - </ul> | |
| 409 | - </div> | |
| 410 | - </div> | |
| 411 | - <?php | |
| 412 | - endwhile; | |
| 413 | - wp_reset_postdata(); | |
| 414 | - | |
| 415 | - echo '</div>'; | |
| 416 | - else: | |
| 417 | - echo '<div class="community-post-error bug">'; | |
| 418 | - echo '<div class="error-content">'; | |
| 419 | - echo '<svg height="40" class="forumax-error error-icon" viewBox="0 0 24 24" version="1.1" width="40" aria-hidden="true"><path d="M12 7a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0112 7zm1 9a1 1 0 11-2 0 1 1 0 012 0z"></path><path fill-rule="evenodd" d="M12 1C5.925 1 1 5.925 1 12s4.925 11 11 11 11-4.925 11-11S18.075 1 12 1zM2.5 12a9.5 9.5 0 1119 0 9.5 9.5 0 01-19 0z"></path></svg>'; | |
| 420 | - echo '<h3 class="error">' . esc_html__( 'Oops! No results matched your search.', 'forumax' ) . '</h3>'; | |
| 421 | - echo '<p class="error">' . esc_html__( 'You could search again.', 'forumax' ) . '</p>'; | |
| 422 | - echo '</div>'; | |
| 423 | - echo '</div>'; | |
| 424 | - endif; | |
| 425 | - die; | |
| 426 | -} | |
| 427 | - | |
| 428 | -add_action( 'wp_ajax_forumax_loading_sort_post', 'forumax_loading_sort_post' ); | |
| 429 | -add_action( 'wp_ajax_nopriv_forumax_loading_sort_post', 'forumax_loading_sort_post' ); | |
| 430 | - | |
| 431 | -function forumax_loading_sort_post() { | |
| 432 | - global $wpdb; | |
| 433 | - | |
| 434 | - $nonce = sanitize_text_field( $_POST['nonce'] ); | |
| 435 | - $sort = sanitize_text_field( $_POST['sort'] ); | |
| 436 | - $parent = sanitize_text_field( $_POST['parent'] ); | |
| 437 | - | |
| 438 | - if ( ! wp_verify_nonce( $nonce, 'forumax-nonce' ) ) { | |
| 439 | - die( '-1' ); | |
| 440 | - } | |
| 441 | - | |
| 442 | - $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; | |
| 443 | - $q = [ | |
| 444 | - 'post_type' => 'topic', | |
| 445 | - 'post_parent' => $parent, | |
| 446 | - 'post_status' => 'publish', | |
| 447 | - 'posts_per_page' => get_option( '_bbp_topics_per_page', 10 ), | |
| 448 | - 'ignore_sticky_posts' => 1, | |
| 449 | - ]; | |
| 450 | - if ( $sort == 'newest_posts' ) { | |
| 451 | - $newest_posts = [ | |
| 452 | - 'order' => 'DESC', | |
| 453 | - ]; | |
| 454 | - $q = array_merge( $q, $newest_posts ); | |
| 455 | - } elseif ( $sort == 'oldest_posts' ) { | |
| 456 | - $oldest_posts = [ | |
| 457 | - 'order' => 'ASC', | |
| 458 | - ]; | |
| 459 | - $q = array_merge( $q, $oldest_posts ); | |
| 460 | - } elseif ( $sort == 'comment_count' ) { | |
| 461 | - $comment_count = [ | |
| 462 | - 'meta_key' => '_bbp_reply_count', | |
| 463 | - 'orderby' => 'meta_value_num', | |
| 464 | - 'order' => 'DESC', | |
| 465 | - ]; | |
| 466 | - $q = array_merge( $q, $comment_count ); | |
| 467 | - } elseif ( $sort == 'comment_date' ) { | |
| 468 | - $comment_count = [ | |
| 469 | - 'meta_key' => '_bbp_reply_count', | |
| 470 | - 'meta_type' => 'NUMERIC', | |
| 471 | - 'orderby' => 'meta_value_num', | |
| 472 | - 'order' => 'ASC', | |
| 473 | - ]; | |
| 474 | - $q = array_merge( $q, $comment_count ); | |
| 475 | - } elseif ( $sort == 'recent_updated_post' ) { | |
| 476 | - $post_date = [ | |
| 477 | - 'orderby' => 'post_modified', | |
| 478 | - 'order' => 'DESC', | |
| 479 | - ]; | |
| 480 | - $q = array_merge( $q, $post_date ); | |
| 481 | - } elseif ( $sort == 'last_recent_updated_post' ) { | |
| 482 | - $post_modified = [ | |
| 483 | - 'orderby' => 'post_modified', | |
| 484 | - 'order' => 'ASC', | |
| 485 | - ]; | |
| 486 | - $q = array_merge( $q, $post_modified ); | |
| 487 | - } | |
| 488 | - $tax_query[] = [ | |
| 489 | - 'taxonomy' => 'post_format', | |
| 490 | - 'field' => 'slug', | |
| 491 | - 'terms' => [ 'post-format-quote', 'post-format-link' ], | |
| 492 | - 'operator' => 'NOT IN', | |
| 493 | - ]; | |
| 494 | - if ( ! empty( $tax_query ) ) { | |
| 495 | - $tax_query = array_merge( [ 'relation' => 'AND' ], $tax_query ); | |
| 496 | - $q = array_merge( $q, [ 'tax_query' => $tax_query ] ); | |
| 497 | - } | |
| 498 | - $query = new WP_Query( $q ); | |
| 499 | - if ( $query->have_posts() ): | |
| 500 | - echo '<div class="community-posts-wrapper bb-radius">'; | |
| 501 | - while ( $query->have_posts() ): $query->the_post(); | |
| 502 | - global $post; | |
| 503 | - | |
| 504 | - $author_id = $post->post_author; | |
| 505 | - $parent_post_id = $parent; | |
| 506 | - $favoriters = get_post_meta( get_the_ID(), '_bbp_favorite', true ); | |
| 507 | - $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0'; | |
| 508 | - $get_reply = get_post_meta( get_the_ID(), '_bbp_reply_count', true ); | |
| 509 | - $_reply_count = isset( $get_reply ) && ! empty( $get_reply ) ? $get_reply : 0; | |
| 510 | - ?> | |
| 511 | - <div class="community-post style-two <?php the_author_meta( 'user_nicename', $author_id ); ?>"> | |
| 512 | - <div class="post-content"> | |
| 513 | - <div class="author-avatar"> | |
| 514 | - <?php | |
| 515 | - echo bbp_get_topic_author_link( | |
| 516 | - array( | |
| 517 | - 'post_id' => get_the_ID(), | |
| 518 | - 'type' => 'avatar', | |
| 519 | - 'size' => 40 | |
| 520 | - ) | |
| 521 | - ); | |
| 522 | - ?> | |
| 523 | - </div> | |
| 524 | - <div class="entry-content"> | |
| 525 | - <?php the_title( sprintf( '<a href="%s" rel="bookmark"> <h3 class="post-title">', esc_url( get_permalink() ) ), '</h3></a>' ); ?> | |
| 526 | - <ul class="meta"> | |
| 527 | - <li> | |
| 528 | - <?php | |
| 529 | - if ( get_the_post_thumbnail_url( $parent_post_id ) ) : | |
| 530 | - ?> | |
| 531 | - <img src="<?php echo get_the_post_thumbnail_url( $parent_post_id ); ?>" | |
| 532 | - alt="<?php echo get_the_title( $parent_post_id ); ?>"> | |
| 533 | - <?php | |
| 534 | - endif; | |
| 535 | - ?> | |
| 536 | - <a href="<?php echo get_permalink( $parent_post_id ); ?>"> <?php echo get_the_title( $parent_post_id ); ?> </a> | |
| 537 | - </li> | |
| 538 | - <li><i class="icon_clock_alt"></i> <?php bbp_topic_post_date( get_the_ID() ); ?> </li> | |
| 539 | - </ul> | |
| 540 | - </div> | |
| 541 | - </div> | |
| 542 | - <div class="post-meta-wrapper"> | |
| 543 | - <ul class="post-meta-info"> | |
| 544 | - <li><a href="#"><i class="icon_chat_alt"></i><?php echo esc_html( $_reply_count ); ?></a></li> | |
| 545 | - <li><a href="#"><i class="icon_star"></i><?php echo esc_html( $favorite_count ); ?></a></li> | |
| 546 | - </ul> | |
| 547 | - </div> | |
| 548 | - </div> | |
| 549 | - <?php endwhile; | |
| 550 | - wp_reset_postdata(); | |
| 551 | - | |
| 552 | - echo '</div>'; | |
| 553 | - else: | |
| 554 | - echo '<div class="community-post-error bug">'; | |
| 555 | - echo '<div class="error-content">'; | |
| 556 | - echo '<svg height="40" class="forumax-error error-icon" viewBox="0 0 24 24" version="1.1" width="40" aria-hidden="true"><path d="M12 7a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0112 7zm1 9a1 1 0 11-2 0 1 1 0 012 0z"></path><path fill-rule="evenodd" d="M12 1C5.925 1 1 5.925 1 12s4.925 11 11 11 11-4.925 11-11S18.075 1 12 1zM2.5 12a9.5 9.5 0 1119 0 9.5 9.5 0 01-19 0z"></path></svg>'; | |
| 557 | - echo '<h3 class="error">' . esc_html__( 'Oops! No results matched your search.', 'forumax' ) . '</h3>'; | |
| 558 | - echo '<p class="error">' . esc_html__( 'You could search again.', 'forumax' ) . '</p>'; | |
| 559 | - echo '</div>'; | |
| 560 | - echo '</div>'; | |
| 561 | - endif; | |
| 562 | - | |
| 563 | - die; | |
| 564 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Ajax actions for Forumax | |
| 4 | + * | |
| 5 | + * @package Forumax | |
| 6 | + */ | |
| 7 | + | |
| 8 | +defined( 'ABSPATH' ) || exit; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * All Search results | |
| 12 | + */ | |
| 13 | +add_action( 'wp_ajax_forumax_search_data_fetch', 'forumax_search_data_fetch' ); | |
| 14 | +add_action( 'wp_ajax_nopriv_forumax_search_data_fetch', 'forumax_search_data_fetch' ); | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * Build the ancestor "breadcrumb" trail for a search result, mirroring the | |
| 18 | + * EazyDocs search UI (e.g. Forum › Topic for a reply). | |
| 19 | + * | |
| 20 | + * @param int $post_id Post ID. | |
| 21 | + * @param string $type Post type of the result. | |
| 22 | + * @return array List of ancestor titles, ordered from top-most down. | |
| 23 | + */ | |
| 24 | +function forumax_search_result_breadcrumb( $post_id, $type ) { | |
| 25 | + $crumbs = array(); | |
| 26 | + | |
| 27 | + if ( 'reply' === $type && function_exists( 'bbp_get_reply_forum_id' ) ) { | |
| 28 | + $forum_id = bbp_get_reply_forum_id( $post_id ); | |
| 29 | + $topic_id = bbp_get_reply_topic_id( $post_id ); | |
| 30 | + if ( $forum_id ) { | |
| 31 | + $crumbs[] = get_the_title( $forum_id ); | |
| 32 | + } | |
| 33 | + if ( $topic_id ) { | |
| 34 | + $crumbs[] = get_the_title( $topic_id ); | |
| 35 | + } | |
| 36 | + } elseif ( 'topic' === $type && function_exists( 'bbp_get_topic_forum_id' ) ) { | |
| 37 | + $forum_id = bbp_get_topic_forum_id( $post_id ); | |
| 38 | + if ( $forum_id ) { | |
| 39 | + $crumbs[] = get_the_title( $forum_id ); | |
| 40 | + } | |
| 41 | + } else { | |
| 42 | + // Generic hierarchy fallback (forums with parents, docs, pages, etc.). | |
| 43 | + foreach ( array_reverse( get_post_ancestors( $post_id ) ) as $ancestor_id ) { | |
| 44 | + $crumbs[] = get_the_title( $ancestor_id ); | |
| 45 | + } | |
| 46 | + } | |
| 47 | + | |
| 48 | + return array_values( array_filter( $crumbs ) ); | |
| 49 | +} | |
| 50 | + | |
| 51 | +/** | |
| 52 | + * Fetch search data. | |
| 53 | + */ | |
| 54 | +function forumax_search_data_fetch() { | |
| 55 | + | |
| 56 | + // Check nonce. | |
| 57 | + check_ajax_referer( 'forumax-nonce', 'nonce' ); | |
| 58 | + | |
| 59 | + // Sanitize keyword. | |
| 60 | + $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : ''; | |
| 61 | + $post_type = isset( $_POST['post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : ''; | |
| 62 | + | |
| 63 | + // Determine which post types to query. An explicit single post type narrows | |
| 64 | + // the search; 'all' (or no value) searches the whole forum: forums, topics | |
| 65 | + // and replies, so content matches from any of them are returned. | |
| 66 | + if ( ! empty( $post_type ) && 'all' !== $post_type ) { | |
| 67 | + $query_post_types = array( $post_type ); | |
| 68 | + } elseif ( class_exists( 'bbPress' ) ) { | |
| 69 | + $query_post_types = array( 'forum', 'topic', 'reply' ); | |
| 70 | + } else { | |
| 71 | + $query_post_types = array( 'post' ); | |
| 72 | + } | |
| 73 | + | |
| 74 | + // Determine which statuses to include. bbPress stores closed topics with the | |
| 75 | + // 'closed' post status (and uses 'private'/'hidden' for restricted forums), | |
| 76 | + // none of which are returned by WP_Query's default 'publish'-only behavior. | |
| 77 | + // Include the publicly viewable bbPress statuses so closed topics still match. | |
| 78 | + if ( class_exists( 'bbPress' ) ) { | |
| 79 | + $query_post_status = array( 'publish', 'closed', 'private', 'hidden' ); | |
| 80 | + } else { | |
| 81 | + $query_post_status = array( 'publish' ); | |
| 82 | + } | |
| 83 | + | |
| 84 | + // Force the search to match BOTH the title and the content. This overrides | |
| 85 | + // any other plugin/theme `posts_search` filter that may otherwise restrict | |
| 86 | + // matching to titles only, so content keywords return results too. | |
| 87 | + $bbpc_search_clause = static function ( $search, $wp_query ) use ( $keyword ) { | |
| 88 | + global $wpdb; | |
| 89 | + | |
| 90 | + if ( '' === $keyword || ! $wp_query->get( 'bbpc_ajax_search' ) ) { | |
| 91 | + return $search; | |
| 92 | + } | |
| 93 | + | |
| 94 | + $like = '%' . $wpdb->esc_like( $keyword ) . '%'; | |
| 95 | + | |
| 96 | + return $wpdb->prepare( | |
| 97 | + " AND ( {$wpdb->posts}.post_title LIKE %s OR {$wpdb->posts}.post_content LIKE %s ) ", | |
| 98 | + $like, | |
| 99 | + $like | |
| 100 | + ); | |
| 101 | + }; | |
| 102 | + | |
| 103 | + add_filter( 'posts_search', $bbpc_search_clause, 999, 2 ); | |
| 104 | + | |
| 105 | + // Main results query. | |
| 106 | + $results = new \WP_Query( array( | |
| 107 | + 'post_type' => $query_post_types, | |
| 108 | + 'post_status' => $query_post_status, | |
| 109 | + 's' => $keyword, | |
| 110 | + 'posts_per_page' => 10, | |
| 111 | + 'bbpc_ajax_search' => true, | |
| 112 | + ) ); | |
| 113 | + | |
| 114 | + remove_filter( 'posts_search', $bbpc_search_clause, 999 ); | |
| 115 | + | |
| 116 | + $results_count = $results->found_posts; | |
| 117 | + | |
| 118 | + if ( $results_count > 0 ) { | |
| 119 | + $nsoresult = 'data-result='; | |
| 120 | + } else { | |
| 121 | + $nsoresult = 'data-noresult='; | |
| 122 | + } | |
| 123 | + | |
| 124 | + ?> | |
| 125 | + <div class="tab-item active all-active" <?php echo esc_attr( $nsoresult . 'No-Results-Found' ); ?>></div> | |
| 126 | + <?php | |
| 127 | + | |
| 128 | + echo '<div class="bbpc-search-results-wrapper">'; | |
| 129 | + echo '<div class="search-results-tab forum show" id="search-forum-results">'; | |
| 130 | + | |
| 131 | + if ( $results->have_posts() ) : | |
| 132 | + // Group results by post type. | |
| 133 | + $grouped = array(); | |
| 134 | + while ( $results->have_posts() ) : | |
| 135 | + $results->the_post(); | |
| 136 | + $type = get_post_type(); | |
| 137 | + if ( ! isset( $grouped[ $type ] ) ) { | |
| 138 | + $grouped[ $type ] = array(); | |
| 139 | + } | |
| 140 | + $grouped[ $type ][] = array( | |
| 141 | + 'id' => get_the_ID(), | |
| 142 | + 'title' => get_the_title(), | |
| 143 | + 'url' => get_the_permalink(), | |
| 144 | + 'breadcrumb' => forumax_search_result_breadcrumb( get_the_ID(), $type ), | |
| 145 | + ); | |
| 146 | + endwhile; | |
| 147 | + wp_reset_postdata(); | |
| 148 | + | |
| 149 | + // Render grouped results. | |
| 150 | + $type_labels = array( | |
| 151 | + 'forum' => __( 'Forums', 'forumax' ), | |
| 152 | + 'topic' => __( 'Topics', 'forumax' ), | |
| 153 | + 'reply' => __( 'Replies', 'forumax' ), | |
| 154 | + 'docs' => __( 'Documentation', 'forumax' ), | |
| 155 | + 'post' => __( 'Posts', 'forumax' ), | |
| 156 | + ); | |
| 157 | + | |
| 158 | + // Document icon shared by every result row. | |
| 159 | + $result_icon = '<svg class="bbpc-result-icon" width="16" height="16" viewBox="0 0 17 17" fill="currentColor" role="img" aria-hidden="true"><path d="M14.72,0H2.28A2.28,2.28,0,0,0,0,2.28V14.72A2.28,2.28,0,0,0,2.28,17H14.72A2.28,2.28,0,0,0,17,14.72V2.28A2.28,2.28,0,0,0,14.72,0ZM2.28,1H14.72A1.28,1.28,0,0,1,16,2.28V5.33H1V2.28A1.28,1.28,0,0,1,2.28,1ZM1,14.72V6.33H5.33V16H2.28A1.28,1.28,0,0,1,1,14.72ZM14.72,16H6.33V6.33H16v8.39A1.28,1.28,0,0,1,14.72,16Z"></path></svg>'; | |
| 160 | + | |
| 161 | + // Result type tabs (All / Forums / Topics / Replies), mirroring EazyDocs. | |
| 162 | + ?> | |
| 163 | + <div class="bbpc-result-tabs"> | |
| 164 | + <button type="button" class="bbpc-tab active" data-tab="all"><?php esc_html_e( 'All', 'forumax' ); ?></button> | |
| 165 | + <?php foreach ( $grouped as $type => $posts ) : | |
| 166 | + $tab_label = isset( $type_labels[ $type ] ) ? $type_labels[ $type ] : ucfirst( $type ); | |
| 167 | + ?> | |
| 168 | + <button type="button" class="bbpc-tab" data-tab="<?php echo esc_attr( $type ); ?>"><?php echo esc_html( $tab_label ); ?></button> | |
| 169 | + <?php endforeach; ?> | |
| 170 | + </div> | |
| 171 | + <?php | |
| 172 | + | |
| 173 | + foreach ( $grouped as $type => $posts ) : | |
| 174 | + $label = isset( $type_labels[ $type ] ) ? $type_labels[ $type ] : ucfirst( $type ); | |
| 175 | + ?> | |
| 176 | + <div class="bbpc-result-group" data-type="<?php echo esc_attr( $type ); ?>"> | |
| 177 | + <div class="bbpc-result-group-label"><?php echo esc_html( $label ); ?></div> | |
| 178 | + <?php foreach ( $posts as $post_item ) : ?> | |
| 179 | + <div class="search-result-item" data-url="<?php echo esc_url( $post_item['url'] ); ?>" onclick="document.location='<?php echo esc_url( $post_item['url'] ); ?>'"> | |
| 180 | + <a href="<?php echo esc_url( $post_item['url'] ); ?>" class="bbpc-result-link"> | |
| 181 | + <?php echo $result_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static markup. ?> | |
| 182 | + <span class="bbpc-result-body"> | |
| 183 | + <span class="bbpc-result-title"><?php echo esc_html( $post_item['title'] ); ?></span> | |
| 184 | + <span class="bbpc-result-type"><?php echo esc_html( $label ); ?></span> | |
| 185 | + </span> | |
| 186 | + </a> | |
| 187 | + <?php if ( ! empty( $post_item['breadcrumb'] ) ) : ?> | |
| 188 | + <ol class="bbpc-result-breadcrumb"> | |
| 189 | + <?php foreach ( $post_item['breadcrumb'] as $crumb ) : ?> | |
| 190 | + <li class="bbpc-breadcrumb-item"><?php echo esc_html( $crumb ); ?></li> | |
| 191 | + <?php endforeach; ?> | |
| 192 | + </ol> | |
| 193 | + <?php endif; ?> | |
| 194 | + </div> | |
| 195 | + <?php endforeach; ?> | |
| 196 | + </div> | |
| 197 | + <?php | |
| 198 | + endforeach; | |
| 199 | + endif; | |
| 200 | + | |
| 201 | + echo '</div>'; | |
| 202 | + echo '</div>'; | |
| 203 | + wp_die(); | |
| 204 | +} | |
| 205 | + | |
| 206 | +/** | |
| 207 | + * AJAX handler to fetch forums for Gutenberg block editor | |
| 208 | + * Used by the Single Forum block to populate the forum selector dropdown | |
| 209 | + */ | |
| 210 | +add_action( 'wp_ajax_bbpc_get_forums', 'forumax_get_forums_ajax' ); | |
| 211 | + | |
| 212 | +/** | |
| 213 | + * Get forums ajax. | |
| 214 | + */ | |
| 215 | +function forumax_get_forums_ajax() { | |
| 216 | + // Verify nonce for security | |
| 217 | + check_ajax_referer( 'forumax-nonce', 'nonce' ); | |
| 218 | + | |
| 219 | + if ( ! current_user_can( 'edit_posts' ) ) { | |
| 220 | + wp_send_json_error( 'Unauthorized' ); | |
| 221 | + } | |
| 222 | + | |
| 223 | + // Get all forums | |
| 224 | + $forums = new \WP_Query( [ | |
| 225 | + 'post_type' => 'forum', | |
| 226 | + 'posts_per_page' => -1, | |
| 227 | + 'orderby' => 'title', | |
| 228 | + 'order' => 'ASC', | |
| 229 | + ] ); | |
| 230 | + | |
| 231 | + $forum_list = []; | |
| 232 | + | |
| 233 | + if ( $forums->have_posts() ) { | |
| 234 | + while ( $forums->have_posts() ) { | |
| 235 | + $forums->the_post(); | |
| 236 | + $forum_list[] = [ | |
| 237 | + 'id' => get_the_ID(), | |
| 238 | + 'title' => get_the_title(), | |
| 239 | + ]; | |
| 240 | + } | |
| 241 | + wp_reset_postdata(); | |
| 242 | + } | |
| 243 | + | |
| 244 | + wp_send_json_success( $forum_list ); | |
| 245 | +} | |
| 246 | + | |
| 247 | + | |
| 248 | +/** | |
| 249 | + * Loading Post | |
| 250 | + */ | |
| 251 | +add_action( 'wp_ajax_forumax_loading_post', 'forumax_loading_post' ); | |
| 252 | +add_action( 'wp_ajax_nopriv_forumax_loading_post', 'forumax_loading_post' ); | |
| 253 | + | |
| 254 | +/** | |
| 255 | + * Loading forum posts | |
| 256 | + * | |
| 257 | + * @return void | |
| 258 | + */ | |
| 259 | +function forumax_loading_post() { | |
| 260 | + // Check nonce | |
| 261 | + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'forumax-nonce' ) ) { | |
| 262 | + wp_die( '-1' ); | |
| 263 | + } | |
| 264 | + | |
| 265 | + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 266 | + $post_in = isset( $_POST['a_t_id'] ) ? sanitize_text_field( wp_unslash( $_POST['a_t_id'] ) ) : ''; | |
| 267 | + $count = isset( $_POST['count'] ) ? sanitize_text_field( wp_unslash( $_POST['count'] ) ) : ''; | |
| 268 | + $parent = isset( $_POST['parent'] ) ? sanitize_text_field( wp_unslash( $_POST['parent'] ) ) : ''; | |
| 269 | + | |
| 270 | + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; | |
| 271 | + $q = [ | |
| 272 | + 'post_type' => 'topic', | |
| 273 | + 'post_parent' => $parent, | |
| 274 | + 'order' => 'DESC', | |
| 275 | + 'orderby' => 'post_date', | |
| 276 | + 'post_status' => 'publish', | |
| 277 | + 'posts_per_page' => get_option( '_bbp_topics_per_page', 10 ), | |
| 278 | + 'ignore_sticky_posts' => 1, | |
| 279 | + ]; | |
| 280 | + | |
| 281 | + if ( 'author' === $type ) { | |
| 282 | + $auth_ids = [ | |
| 283 | + 'author' => $post_in, | |
| 284 | + ]; | |
| 285 | + $q = array_merge( $q, $auth_ids ); | |
| 286 | + } elseif ( 'tag' === $type ) { | |
| 287 | + $tax_query[] = [ | |
| 288 | + 'taxonomy' => 'topic-tag', | |
| 289 | + 'field' => 'term_id', | |
| 290 | + 'terms' => $post_in, | |
| 291 | + ]; | |
| 292 | + } | |
| 293 | + | |
| 294 | + $tax_query[] = [ | |
| 295 | + 'taxonomy' => 'post_format', | |
| 296 | + 'field' => 'slug', | |
| 297 | + 'terms' => [ 'post-format-quote', 'post-format-link' ], | |
| 298 | + 'operator' => 'NOT IN', | |
| 299 | + ]; | |
| 300 | + | |
| 301 | + if ( ! empty( $tax_query ) ) { | |
| 302 | + $tax_query = array_merge( [ 'relation' => 'AND' ], $tax_query ); | |
| 303 | + $q = array_merge( $q, [ 'tax_query' => $tax_query ] ); | |
| 304 | + } | |
| 305 | + | |
| 306 | + $query = new WP_Query( $q ); | |
| 307 | + | |
| 308 | + if ( $query->have_posts() ) : | |
| 309 | + echo '<div class="community-posts-wrapper bb-radius">'; | |
| 310 | + while ( $query->have_posts() ) : $query->the_post(); | |
| 311 | + global $post; | |
| 312 | + $author_id = $post->post_author; | |
| 313 | + $parent_post_id = $parent; | |
| 314 | + $favoriters = get_post_meta( get_the_ID(), '_bbp_favorite', true ); | |
| 315 | + $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0'; | |
| 316 | + $get_reply = get_post_meta( get_the_ID(), '_bbp_reply_count', true ); | |
| 317 | + $_reply_count = isset( $get_reply ) && ! empty( $get_reply ) ? $get_reply : 0; | |
| 318 | + ?> | |
| 319 | + <div class="community-post style-two <?php the_author_meta( 'user_nicename', $author_id ); ?>"> | |
| 320 | + <div class="post-content"> | |
| 321 | + <div class="author-avatar"> | |
| 322 | + <?php | |
| 323 | + echo bbp_get_topic_author_link( | |
| 324 | + [ | |
| 325 | + 'post_id' => get_the_ID(), | |
| 326 | + 'type' => 'avatar', | |
| 327 | + 'size' => 40, | |
| 328 | + ] | |
| 329 | + ); | |
| 330 | + ?> | |
| 331 | + </div> | |
| 332 | + <div class="entry-content"> | |
| 333 | + <?php the_title( sprintf( '<a href="%s" rel="bookmark"> <h3 class="post-title">', esc_url( get_permalink() ) ), '</h3></a>' ); ?> | |
| 334 | + <ul class="meta"> | |
| 335 | + <li> | |
| 336 | + <?php echo get_the_post_thumbnail( bbp_get_topic_forum_id(), [ 40, 40 ] ); ?> | |
| 337 | + <a href="<?php echo get_permalink( bbp_get_topic_forum_id() ); ?>"> | |
| 338 | + <?php echo get_the_title( bbp_get_topic_forum_id() ); ?> | |
| 339 | + </a> | |
| 340 | + </li> | |
| 341 | + <li><i class="icon_clock_alt"></i> <?php bbp_topic_post_date( get_the_ID() ); ?> </li> | |
| 342 | + </ul> | |
| 343 | + </div> | |
| 344 | + </div> | |
| 345 | + <div class="post-meta-wrapper"> | |
| 346 | + <ul class="post-meta-info"> | |
| 347 | + <li><a href="#"><i class="icon_chat_alt"></i><?php echo esc_html( $_reply_count ); ?></a></li> | |
| 348 | + <li><a href="#"><i class="icon_star"></i><?php echo esc_html( $favorite_count ); ?></a></li> | |
| 349 | + </ul> | |
| 350 | + </div> | |
| 351 | + </div> | |
| 352 | + <?php | |
| 353 | + endwhile; | |
| 354 | + wp_reset_postdata(); | |
| 355 | + | |
| 356 | + echo '</div>'; | |
| 357 | + else : | |
| 358 | + echo '<div class="community-post-error bug">'; | |
| 359 | + echo '<div class="error-content">'; | |
| 360 | + echo '<svg height="40" class="forumax-error error-icon" viewBox="0 0 24 24" version="1.1" width="40" aria-hidden="true"><path d="M12 7a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0112 7zm1 9a1 1 0 11-2 0 1 1 0 012 0z"></path><path fill-rule="evenodd" d="M12 1C5.925 1 1 5.925 1 12s4.925 11 11 11 11-4.925 11-11S18.075 1 12 1zM2.5 12a9.5 9.5 0 1119 0 9.5 9.5 0 01-19 0z"></path></svg>'; | |
| 361 | + echo '<h3 class="error">' . esc_html__( 'Oops! No results matched your search.', 'forumax' ) . '</h3>'; | |
| 362 | + echo '<p class="error">' . esc_html__( 'You could search again.', 'forumax' ) . '</p>'; | |
| 363 | + echo '</div>'; | |
| 364 | + echo '</div>'; | |
| 365 | + endif; | |
| 366 | + | |
| 367 | + wp_die(); | |
| 368 | +} | |
| 369 | + | |
| 370 | +/** | |
| 371 | + * Filter posts by status (open/closed) | |
| 372 | + * | |
| 373 | + * @return void | |
| 374 | + */ | |
| 375 | +add_action( 'wp_ajax_forumax_open_post', 'forumax_open_post' ); | |
| 376 | +add_action( 'wp_ajax_nopriv_forumax_open_post', 'forumax_open_post' ); | |
| 377 | + | |
| 378 | +/** | |
| 379 | + * Open post. | |
| 380 | + */ | |
| 381 | +function forumax_open_post() { | |
| 382 | + | |
| 383 | + // Check nonce | |
| 384 | + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'forumax-nonce' ) ) { | |
| 385 | + wp_die( '-1' ); | |
| 386 | + } | |
| 387 | + | |
| 388 | + $is_queried_obj = is_singular( 'forum' ) ? get_queried_object_id() : false; | |
| 389 | + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; | |
| 390 | + $post_in = isset( $_POST['a_t_id'] ) ? sanitize_text_field( wp_unslash( $_POST['a_t_id'] ) ) : ''; | |
| 391 | + $count = isset( $_POST['count'] ) ? sanitize_text_field( wp_unslash( $_POST['count'] ) ) : ''; | |
| 392 | + $parent = isset( $_POST['parent'] ) ? sanitize_text_field( wp_unslash( $_POST['parent'] ) ) : ''; | |
| 393 | + $userid = isset( $_POST['userid'] ) ? sanitize_text_field( wp_unslash( $_POST['userid'] ) ) : ''; | |
| 394 | + | |
| 395 | + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; | |
| 396 | + $q = [ | |
| 397 | + 'post_type' => 'topic', | |
| 398 | + 'post_parent' => $parent, | |
| 399 | + 'order' => 'DESC', | |
| 400 | + 'orderby' => 'post_date', | |
| 401 | + 'posts_per_page' => get_option( '_bbp_topics_per_page', 10 ), | |
| 402 | + 'ignore_sticky_posts' => 1, | |
| 403 | + 'author' => $userid, | |
| 404 | + ]; | |
| 405 | + | |
| 406 | + if ( 'open' === $type ) { | |
| 407 | + $status = [ | |
| 408 | + 'post_status' => 'publish', | |
| 409 | + ]; | |
| 410 | + $q = array_merge( $q, $status ); | |
| 411 | + } elseif ( 'closed' === $type ) { | |
| 412 | + $status = [ | |
| 413 | + 'post_status' => 'closed', | |
| 414 | + ]; | |
| 415 | + $q = array_merge( $q, $status ); | |
| 416 | + } | |
| 417 | + | |
| 418 | + $tax_query[] = [ | |
| 419 | + 'taxonomy' => 'post_format', | |
| 420 | + 'field' => 'slug', | |
| 421 | + 'terms' => [ 'post-format-quote', 'post-format-link' ], | |
| 422 | + 'operator' => 'NOT IN', | |
| 423 | + ]; | |
| 424 | + | |
| 425 | + if ( ! empty( $tax_query ) ) { | |
| 426 | + $tax_query = array_merge( [ 'relation' => 'AND' ], $tax_query ); | |
| 427 | + $q = array_merge( $q, [ 'tax_query' => $tax_query ] ); | |
| 428 | + } | |
| 429 | + | |
| 430 | + $query = new WP_Query( $q ); | |
| 431 | + if ( $query->have_posts() ) : | |
| 432 | + echo '<div class="community-posts-wrapper bb-radius">'; | |
| 433 | + while ( $query->have_posts() ) : $query->the_post(); | |
| 434 | + global $post; | |
| 435 | + $author_id = $post->post_author; | |
| 436 | + //$parent_post_id = get_post_meta( get_the_ID(), '_bbp_topic_id', true ); | |
| 437 | + $parent_post_id = $parent; | |
| 438 | + $favoriters = get_post_meta( get_the_ID(), '_bbp_favorite', true ); | |
| 439 | + $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0'; | |
| 440 | + $get_reply = get_post_meta( get_the_ID(), '_bbp_reply_count', true ); | |
| 441 | + $_reply_count = isset( $get_reply ) && ! empty( $get_reply ) ? $get_reply : 0; | |
| 442 | + ?> | |
| 443 | + | |
| 444 | + <div class="community-post style-two <?php the_author_meta( 'user_nicename', $author_id ); ?>"> | |
| 445 | + <div class="post-content"> | |
| 446 | + <div class="author-avatar"> | |
| 447 | + <?php | |
| 448 | + echo bbp_get_topic_author_link( | |
| 449 | + [ | |
| 450 | + 'post_id' => get_the_ID(), | |
| 451 | + 'type' => 'avatar', | |
| 452 | + 'size' => 40, | |
| 453 | + ] | |
| 454 | + ); | |
| 455 | + ?> | |
| 456 | + </div> | |
| 457 | + <div class="entry-content"> | |
| 458 | + <?php the_title( sprintf( '<a href="%s" rel="bookmark"> <h3 class="post-title">', get_permalink() ), '</h3></a>' ); ?> | |
| 459 | + <ul class="meta"> | |
| 460 | + <li> | |
| 461 | + <?php echo get_the_post_thumbnail( bbp_get_topic_forum_id(), [ 40, 40 ] ); ?> | |
| 462 | + <a href="<?php echo get_permalink( bbp_get_topic_forum_id() ); ?>"> | |
| 463 | + <?php echo get_the_title( bbp_get_topic_forum_id() ); ?> | |
| 464 | + </a> | |
| 465 | + </li> | |
| 466 | + <li><i class="icon_clock_alt"></i> <?php bbp_topic_post_date( get_the_ID() ); ?> </li> | |
| 467 | + </ul> | |
| 468 | + </div> | |
| 469 | + </div> | |
| 470 | + <div class="post-meta-wrapper"> | |
| 471 | + <ul class="post-meta-info"> | |
| 472 | + <li><a href="#"><i class="icon_chat_alt"></i><?php echo esc_html( $_reply_count ); ?></a></li> | |
| 473 | + <li><a href="#"><i class="icon_star"></i><?php echo esc_html( $favorite_count ); ?></a></li> | |
| 474 | + </ul> | |
| 475 | + </div> | |
| 476 | + </div> | |
| 477 | + <?php | |
| 478 | + endwhile; | |
| 479 | + wp_reset_postdata(); | |
| 480 | + | |
| 481 | + echo '</div>'; | |
| 482 | + else : | |
| 483 | + echo '<div class="community-post-error bug">'; | |
| 484 | + echo '<div class="error-content">'; | |
| 485 | + echo '<svg height="40" class="forumax-error error-icon" viewBox="0 0 24 24" version="1.1" width="40" aria-hidden="true"><path d="M12 7a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0112 7zm1 9a1 1 0 11-2 0 1 1 0 012 0z"></path><path fill-rule="evenodd" d="M12 1C5.925 1 1 5.925 1 12s4.925 11 11 11 11-4.925 11-11S18.075 1 12 1zM2.5 12a9.5 9.5 0 1119 0 9.5 9.5 0 01-19 0z"></path></svg>'; | |
| 486 | + echo '<h3 class="error">' . esc_html__( 'Oops! No results matched your search.', 'forumax' ) . '</h3>'; | |
| 487 | + echo '<p class="error">' . esc_html__( 'You could search again.', 'forumax' ) . '</p>'; | |
| 488 | + echo '</div>'; | |
| 489 | + echo '</div>'; | |
| 490 | + endif; | |
| 491 | + wp_die(); | |
| 492 | +} | |
| 493 | + | |
| 494 | +/** | |
| 495 | + * Sort posts | |
| 496 | + * | |
| 497 | + * @return void | |
| 498 | + */ | |
| 499 | +add_action( 'wp_ajax_forumax_loading_sort_post', 'forumax_loading_sort_post' ); | |
| 500 | +add_action( 'wp_ajax_nopriv_forumax_loading_sort_post', 'forumax_loading_sort_post' ); | |
| 501 | + | |
| 502 | +/** | |
| 503 | + * Loading sort post. | |
| 504 | + */ | |
| 505 | +function forumax_loading_sort_post() { | |
| 506 | + | |
| 507 | + // Check nonce | |
| 508 | + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'forumax-nonce' ) ) { | |
| 509 | + wp_die( '-1' ); | |
| 510 | + } | |
| 511 | + | |
| 512 | + $sort = isset( $_POST['sort'] ) ? sanitize_text_field( wp_unslash( $_POST['sort'] ) ) : ''; | |
| 513 | + $parent = isset( $_POST['parent'] ) ? sanitize_text_field( wp_unslash( $_POST['parent'] ) ) : ''; | |
| 514 | + | |
| 515 | + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; | |
| 516 | + $q = [ | |
| 517 | + 'post_type' => 'topic', | |
| 518 | + 'post_parent' => $parent, | |
| 519 | + 'post_status' => 'publish', | |
| 520 | + 'posts_per_page' => get_option( '_bbp_topics_per_page', 10 ), | |
| 521 | + 'ignore_sticky_posts' => 1, | |
| 522 | + ]; | |
| 523 | + | |
| 524 | + if ( 'newest_posts' === $sort ) { | |
| 525 | + $newest_posts = [ | |
| 526 | + 'order' => 'DESC', | |
| 527 | + ]; | |
| 528 | + $q = array_merge( $q, $newest_posts ); | |
| 529 | + } elseif ( 'oldest_posts' === $sort ) { | |
| 530 | + $oldest_posts = [ | |
| 531 | + 'order' => 'ASC', | |
| 532 | + ]; | |
| 533 | + $q = array_merge( $q, $oldest_posts ); | |
| 534 | + } elseif ( 'comment_count' === $sort ) { | |
| 535 | + $comment_count = [ | |
| 536 | + 'meta_key' => '_bbp_reply_count', | |
| 537 | + 'orderby' => 'meta_value_num', | |
| 538 | + 'order' => 'DESC', | |
| 539 | + ]; | |
| 540 | + $q = array_merge( $q, $comment_count ); | |
| 541 | + } elseif ( 'comment_date' === $sort ) { | |
| 542 | + $comment_count = [ | |
| 543 | + 'meta_key' => '_bbp_reply_count', | |
| 544 | + 'meta_type' => 'NUMERIC', | |
| 545 | + 'orderby' => 'meta_value_num', | |
| 546 | + 'order' => 'ASC', | |
| 547 | + ]; | |
| 548 | + $q = array_merge( $q, $comment_count ); | |
| 549 | + } elseif ( 'recent_updated_post' === $sort ) { | |
| 550 | + $post_date = [ | |
| 551 | + 'orderby' => 'post_modified', | |
| 552 | + 'order' => 'DESC', | |
| 553 | + ]; | |
| 554 | + $q = array_merge( $q, $post_date ); | |
| 555 | + } elseif ( 'last_recent_updated_post' === $sort ) { | |
| 556 | + $post_modified = [ | |
| 557 | + 'orderby' => 'post_modified', | |
| 558 | + 'order' => 'ASC', | |
| 559 | + ]; | |
| 560 | + $q = array_merge( $q, $post_modified ); | |
| 561 | + } | |
| 562 | + | |
| 563 | + $tax_query[] = [ | |
| 564 | + 'taxonomy' => 'post_format', | |
| 565 | + 'field' => 'slug', | |
| 566 | + 'terms' => [ 'post-format-quote', 'post-format-link' ], | |
| 567 | + 'operator' => 'NOT IN', | |
| 568 | + ]; | |
| 569 | + | |
| 570 | + if ( ! empty( $tax_query ) ) { | |
| 571 | + $tax_query = array_merge( [ 'relation' => 'AND' ], $tax_query ); | |
| 572 | + $q = array_merge( $q, [ 'tax_query' => $tax_query ] ); | |
| 573 | + } | |
| 574 | + | |
| 575 | + $query = new WP_Query( $q ); | |
| 576 | + if ( $query->have_posts() ) : | |
| 577 | + echo '<div class="community-posts-wrapper bb-radius">'; | |
| 578 | + while ( $query->have_posts() ) : $query->the_post(); | |
| 579 | + global $post; | |
| 580 | + | |
| 581 | + $author_id = $post->post_author; | |
| 582 | + $parent_post_id = $parent; | |
| 583 | + $favoriters = get_post_meta( get_the_ID(), '_bbp_favorite', true ); | |
| 584 | + $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0'; | |
| 585 | + $get_reply = get_post_meta( get_the_ID(), '_bbp_reply_count', true ); | |
| 586 | + $_reply_count = isset( $get_reply ) && ! empty( $get_reply ) ? $get_reply : 0; | |
| 587 | + ?> | |
| 588 | + <div class="community-post style-two <?php the_author_meta( 'user_nicename', $author_id ); ?>"> | |
| 589 | + <div class="post-content"> | |
| 590 | + <div class="author-avatar"> | |
| 591 | + <?php | |
| 592 | + echo bbp_get_topic_author_link( | |
| 593 | + [ | |
| 594 | + 'post_id' => get_the_ID(), | |
| 595 | + 'type' => 'avatar', | |
| 596 | + 'size' => 40, | |
| 597 | + ] | |
| 598 | + ); | |
| 599 | + ?> | |
| 600 | + </div> | |
| 601 | + <div class="entry-content"> | |
| 602 | + <?php the_title( sprintf( '<a href="%s" rel="bookmark"> <h3 class="post-title">', esc_url( get_permalink() ) ), '</h3></a>' ); ?> | |
| 603 | + <ul class="meta"> | |
| 604 | + <li> | |
| 605 | + <?php | |
| 606 | + if ( get_the_post_thumbnail_url( $parent_post_id ) ) : | |
| 607 | + ?> | |
| 608 | + <img src="<?php echo get_the_post_thumbnail_url( $parent_post_id ); ?>" | |
| 609 | + alt="<?php echo get_the_title( $parent_post_id ); ?>"> | |
| 610 | + <?php | |
| 611 | + endif; | |
| 612 | + ?> | |
| 613 | + <a href="<?php echo get_permalink( $parent_post_id ); ?>"> <?php echo get_the_title( $parent_post_id ); ?> </a> | |
| 614 | + </li> | |
| 615 | + <li><i class="icon_clock_alt"></i> <?php bbp_topic_post_date( get_the_ID() ); ?> </li> | |
| 616 | + </ul> | |
| 617 | + </div> | |
| 618 | + </div> | |
| 619 | + <div class="post-meta-wrapper"> | |
| 620 | + <ul class="post-meta-info"> | |
| 621 | + <li><a href="#"><i class="icon_chat_alt"></i><?php echo esc_html( $_reply_count ); ?></a></li> | |
| 622 | + <li><a href="#"><i class="icon_star"></i><?php echo esc_html( $favorite_count ); ?></a></li> | |
| 623 | + </ul> | |
| 624 | + </div> | |
| 625 | + </div> | |
| 626 | + <?php endwhile; | |
| 627 | + wp_reset_postdata(); | |
| 628 | + | |
| 629 | + echo '</div>'; | |
| 630 | + else : | |
| 631 | + echo '<div class="community-post-error bug">'; | |
| 632 | + echo '<div class="error-content">'; | |
| 633 | + echo '<svg height="40" class="forumax-error error-icon" viewBox="0 0 24 24" version="1.1" width="40" aria-hidden="true"><path d="M12 7a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0112 7zm1 9a1 1 0 11-2 0 1 1 0 012 0z"></path><path fill-rule="evenodd" d="M12 1C5.925 1 1 5.925 1 12s4.925 11 11 11 11-4.925 11-11S18.075 1 12 1zM2.5 12a9.5 9.5 0 1119 0 9.5 9.5 0 01-19 0z"></path></svg>'; | |
| 634 | + echo '<h3 class="error">' . esc_html__( 'Oops! No results matched your search.', 'forumax' ) . '</h3>'; | |
| 635 | + echo '<p class="error">' . esc_html__( 'You could search again.', 'forumax' ) . '</p>'; | |
| 636 | + echo '</div>'; | |
| 637 | + echo '</div>'; | |
| 638 | + endif; | |
| 639 | + | |
| 640 | + wp_die(); | |
| 641 | +} | |