PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.0.0
Forumax – AI Powered Advanced Community Forum Plugin v2.0.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 / Blocks / Blocks_Register.php

Blocks_Register.php in Forumax – AI Powered Advanced Community Forum Plugin 2.0.0, at includes/Blocks/Blocks_Register.php

1,092 lines 43.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace admin\Blocks;
3
4 use WP_Query;
5
6 class Blocks_Register {
7 public function __construct() {
8 add_action( 'init', [ $this, 'blocks_init' ] );
9 add_filter( 'block_categories_all', [ $this, 'register_block_category' ], 10, 2 );
10 add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_editor_assets' ] );
11 }
12
13 public function register_block_category( $categories, $post ) {
14 return array_merge(
15 $categories,
16 [
17 [
18 'slug' => 'forumax',
19 'title' => __( 'Forumax', 'forumax' ),
20 ],
21 ]
22 );
23 }
24
25 /**
26 * Enqueue assets for the Gutenberg block editor
27 * This ensures the AJAX URL is available for block scripts
28 */
29 public function enqueue_editor_assets() {
30 $is_pro_active = class_exists( 'Forumax_Pro' );
31 wp_localize_script( 'wp-edit-post', 'bbpc_editor_config', [
32 'ajaxurl' => admin_url( 'admin-ajax.php' ),
33 ] );
34 wp_localize_script( 'wp-edit-post', 'bbpc_upsell_config', [
35 'is_pro_active' => $is_pro_active,
36 'upsell_image_url' => defined( 'FORUMAX_IMG' ) ? FORUMAX_IMG . 'upsell-forum-ajax.png' : '',
37 'upgrade_url' => admin_url( 'admin.php?page=forumax-pricing' ),
38 ] );
39 }
40
41 public function blocks_init() {
42
43
44 register_block_type( __DIR__ . '/../../build/forum-posts', [
45 'render_callback' => [ $this, 'render_forum_posts' ],
46 ] );
47
48 register_block_type( __DIR__ . '/../../build/forum-tab', [
49 'render_callback' => [ $this, 'render_forum_tab' ],
50 ] );
51
52 register_block_type( __DIR__ . '/../../build/forums', [
53 'render_callback' => [ $this, 'render_forums' ],
54 ] );
55
56 register_block_type( __DIR__ . '/../../build/search', [
57 'render_callback' => [ $this, 'render_search' ],
58 ] );
59
60 register_block_type( __DIR__ . '/../../build/single-forum', [
61 'render_callback' => [ $this, 'render_single_forum' ],
62 ] );
63
64 register_block_type( __DIR__ . '/../../build/forum-ajax', [
65 'render_callback' => [ $this, 'render_forum_ajax' ],
66 ] );
67 }
68
69
70
71 public function render_forum_posts( $attributes, $content ) {
72 if ( ! wp_style_is( 'bbpc-el-widgets', 'registered' ) ) {
73 if ( defined( 'FORUMAX_FRONT_ASS' ) ) {
74 wp_register_style( 'bbpc-el-widgets', FORUMAX_FRONT_ASS . 'css/el-widgets.css' );
75 }
76 }
77 if ( ! wp_style_is( 'elegant-icon', 'registered' ) ) {
78 wp_register_style( 'elegant-icon', FORUMAX_VEND . 'elegant-icon/style.css' );
79 }
80 wp_enqueue_style( 'bbpc-el-widgets' );
81 wp_enqueue_style( 'elegant-icon' );
82
83 $ppp = isset( $attributes['ppp'] ) ? $attributes['ppp'] : 5;
84 $order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC';
85 $show_meta = isset( $attributes['show_meta'] ) ? $attributes['show_meta'] : true;
86
87 $title_color = isset( $attributes['title_color'] ) ? $attributes['title_color'] : '';
88 $meta_color = isset( $attributes['meta_color'] ) ? $attributes['meta_color'] : '';
89 $bg_color = isset( $attributes['bg_color'] ) ? $attributes['bg_color'] : '';
90
91 $unique_id = uniqid( 'bbpc-forum-posts-' );
92
93 $forum_posts = new WP_Query( array(
94 'post_type' => 'topic',
95 'posts_per_page' => $ppp,
96 'order' => $order,
97 ) );
98
99 $wrapper_attributes = get_block_wrapper_attributes( [
100 'class' => 'community-posts-wrapper',
101 'id' => $unique_id,
102 ] );
103
104 ob_start();
105 ?>
106 <style>
107 <?php if ( $title_color ) : ?>
108 #<?php echo esc_attr( $unique_id ); ?> .community-post .post-content .post-title a { color: <?php echo esc_attr( $title_color ); ?>; }
109 <?php endif; ?>
110 <?php if ( $meta_color ) : ?>
111 #<?php echo esc_attr( $unique_id ); ?> .community-post .post-content .entry-content,
112 #<?php echo esc_attr( $unique_id ); ?> .community-post .post-meta-wrapper .post-meta-info li a { color: <?php echo esc_attr( $meta_color ); ?>; }
113 <?php endif; ?>
114 <?php if ( $bg_color ) : ?>
115 #<?php echo esc_attr( $unique_id ); ?> .community-post { background-color: <?php echo esc_attr( $bg_color ); ?>; }
116 <?php endif; ?>
117 </style>
118 <div <?php echo $wrapper_attributes; ?>>
119 <?php
120 while ( $forum_posts->have_posts() ) : $forum_posts->the_post();
121 $favoriters = bbp_get_topic_favoriters();
122 $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0';
123 ?>
124 <div class="community-post wow fadeInUp" data-wow-delay="0.5s">
125 <div class="post-content">
126 <div class="author-avatar">
127 <?php
128 echo wp_kses_post( bbp_get_topic_author_link(
129 array(
130 'post_id' => get_the_ID(),
131 'size' => 40,
132 'type' => 'avatar'
133 )
134 ) );
135 ?>
136 </div>
137 <div class="entry-content">
138 <h3 class="post-title">
139 <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a>
140 </h3>
141
142 <?php
143 esc_html_e( 'Last active: ', 'forumax' );
144 echo esc_html( bbp_get_forum_last_active_time( get_the_ID() ) );
145 ?>
146
147 </div>
148 </div>
149 <?php if ( $show_meta ) : ?>
150 <div class="post-meta-wrapper">
151 <ul class="post-meta-info">
152 <li>
153 <a href="<?php bbp_topic_permalink(); ?>">
154 <i class="icon_chat_alt"></i>
155 <?php bbp_show_lead_topic() ? bbp_topic_reply_count( get_the_ID() ) : bbp_topic_post_count( get_the_ID() ); ?>
156 </a>
157 </li>
158 <li>
159 <a href="<?php bbp_topic_permalink(); ?>">
160 <i class="icon_star_alt"></i> <?php echo esc_html( $favorite_count ); ?>
161 </a>
162 </li>
163 </ul>
164 </div>
165 <?php endif; ?>
166 </div>
167 <?php
168 endwhile;
169 wp_reset_postdata();
170 ?>
171 </div>
172 <?php
173 return ob_get_clean();
174 }
175
176 public function render_forum_tab( $attributes, $content ) {
177 $forum_tab_title = ! empty( $attributes['forum_tab_title'] ) ? $attributes['forum_tab_title'] : __( 'Show Forum', 'forumax' );
178 $topics_tab_title = ! empty( $attributes['topics_tab_title'] ) ? $attributes['topics_tab_title'] : __( 'Show Topics', 'forumax' );
179 $ppp = ! empty( $attributes['ppp'] ) ? $attributes['ppp'] : 9;
180 $ppp2 = ! empty( $attributes['ppp2'] ) ? $attributes['ppp2'] : 6;
181 $order = ! empty( $attributes['order'] ) ? $attributes['order'] : 'ASC';
182 $order2 = ! empty( $attributes['order2'] ) ? $attributes['order2'] : 'ASC';
183 $settings = $attributes; // Used in template
184
185 // Inline Styles
186 if( ! empty( $attributes['forum_tab_title_color'] ) ) {
187 $unique_id = isset($attributes['uniqueId']) ? $attributes['uniqueId'] : uniqid(); // We don't have uniqueId attribute yet but good practice
188 // We need a unique ID for the style, let's use the one generated for the tab
189 // But for now, we will rely on a generated unique ID in the template or wrapper
190 }
191
192 $forums = new WP_Query( array(
193 'post_type' => 'forum',
194 'posts_per_page' => $ppp,
195 'order' => $order,
196 ) );
197
198 $topics = new WP_Query( array(
199 'post_type' => 'topic',
200 'posts_per_page' => $ppp2,
201 'order' => $order2,
202 ) );
203
204 $unique_id = uniqid();
205 $this_get_id = $unique_id;
206
207 // Enqueue styles/scripts for forum tab (ensure script is available on frontend)
208 if ( ! wp_style_is( 'bbpc-el-widgets', 'registered' ) ) {
209 wp_register_style( 'bbpc-el-widgets', FORUMAX_FRONT_ASS . 'css/el-widgets.css' );
210 }
211 if ( ! wp_style_is( 'elegant-icon', 'registered' ) ) {
212 wp_register_style( 'elegant-icon', FORUMAX_VEND . 'elegant-icon/style.css' );
213 }
214 if ( ! wp_script_is( 'bbpc_js', 'registered' ) ) {
215 wp_register_script( 'bbpc_js', FORUMAX_FRONT_ASS . 'js/forumTab.js', array( 'jquery' ), FORUMAX_VERSION, true );
216 }
217
218 wp_enqueue_style( 'bbpc-el-widgets' );
219 wp_enqueue_style( 'elegant-icon' );
220 wp_enqueue_script( 'bbpc_js' );
221
222 ob_start();
223 ?>
224 <section class="community-area" id="forumTab-<?php echo esc_attr( $this_get_id ); ?>">
225 <ul class="nav nav-tabs tab-buttons" role="tablist">
226 <li class="nav-item" role="presentation">
227 <button class="nav-link active tab-button tab" onclick="forumTab(event, 'forumTab-<?php echo esc_attr( $this_get_id ); ?>', 'forum-<?php echo esc_attr( $this_get_id ); ?>')">
228 <?php echo esc_html( $forum_tab_title ); ?>
229 </button>
230
231 </li>
232 <li class="nav-item" role="presentation">
233 <button class="nav-link tab-button tab" onclick="forumTab(event, 'forumTab-<?php echo esc_attr( $this_get_id ); ?>', 'topics-<?php echo esc_attr( $this_get_id ); ?>')">
234 <?php echo esc_html( $topics_tab_title ); ?>
235 </button>
236 </li>
237 </ul>
238 <div id="forum-<?php echo esc_attr( $this_get_id ); ?>" class="tab-content show active">
239 <div class="gy-4 bbpc-community-topic-widget-main-wrapper">
240 <?php
241 while ( $forums->have_posts() ) : $forums->the_post();
242 $item_id = get_the_ID();
243 $author_id = get_post_field( 'post_author', $item_id );
244 ?>
245 <div class="col-md-6 col-lg-4 bbpc-community-topic-widget-wrapper">
246 <div class="community-topic-widget-box">
247 <?php the_post_thumbnail( 'full' ); ?>
248 <div class="box-content">
249 <h5>
250 <a href="<?php the_permalink() ?>"><?php the_title() ?></a>
251 </h5>
252 <span><?php bbp_forum_topic_count( $item_id ); esc_html_e( ' Posts', 'forumax' ); ?></span>
253 <span class="vr-line">|</span>
254 <span><?php bbp_forum_reply_count( $item_id ); esc_html_e( ' Replies', 'forumax' ); ?></span>
255 </div>
256 </div>
257 </div>
258 <?php
259 endwhile;
260 wp_reset_postdata();
261 ?>
262 </div>
263
264 <?php if ( isset($settings['is_forum_tab_btn']) && $settings['is_forum_tab_btn'] ) : ?>
265 <div class="text-center bbpc-show-more-btn-wrapper">
266 <a href="<?php echo esc_url( $settings['more_url'] ?? '#' ); ?>" class="dbl-arrow-upper show-more-btn show-more-round mt-70">
267 <div class="arrow-cont">
268 <svg width="13px" height="13px" class="first" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h48v48H0z" fill="none"></path><polygon points="24,29.171 9.414,14.585 6.586,17.413 24,34.827 41.414,17.413 38.586,14.585"></polygon> </g> </g></svg>
269 <svg width="13px" height="13px" class="second" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h48v48H0z" fill="none"></path><polygon points="24,29.171 9.414,14.585 6.586,17.413 24,34.827 41.414,17.413 38.586,14.585"></polygon> </g> </g></svg>
270 </div>
271 <?php echo esc_html( $settings['more_txt'] ?? '' ); ?>
272 </a>
273 </div>
274 <?php endif; ?>
275
276 </div>
277
278 <div id="topics-<?php echo esc_attr( $this_get_id ); ?>" class="tab-content ">
279 <?php
280 $i = 0;
281 while ( $topics->have_posts() ) : $topics->the_post();
282 $topic_id = $topics->posts[ $i ]->ID;
283 $vote_count = get_post_meta( $topic_id, "bbpv-votes", true );
284 $forum_id = bbp_get_topic_forum_id();
285 ?>
286 <div class="single-forum-post-widget">
287 <div class="post-content">
288 <div class="post-title">
289 <h6> <a href="<?php the_permalink(); ?>"> <?php the_title() ?> </a> </h6>
290 </div>
291 <div class="post-info">
292 <div class="author">
293 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/user-circle-alt.svg' ) ?>" alt="<?php esc_attr_e( 'User circle', 'forumax' );
294 ?>">
295 <?php
296 echo wp_kses_post( bbp_get_topic_author_link(
297 array(
298 'post_id' => $topic_id,
299 'type' => 'name'
300 )
301 ) );
302 ?>
303 </div>
304
305 <div class="post-time">
306 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/time-outline.svg' ) ?>" alt="<?php esc_attr_e( 'Time outline', 'forumax' );
307 ?>">
308 <?php bbp_forum_last_active_time( get_the_ID() ); ?>
309 </div>
310
311 <div class="post-category">
312 <a href="<?php echo esc_url( get_the_permalink( $forum_id ) ) ?>">
313 <?php echo get_the_post_thumbnail( $forum_id ); ?>
314 <?php echo esc_html( get_the_title( $forum_id ) ) ?>
315 </a>
316 </div>
317 </div>
318 <?php
319 bbp_topic_tag_list( '',
320 array(
321 'before' => '<div class="post-tags">',
322 'after' => '</div>',
323 'sep' => ''
324 )
325 );
326 ?>
327 </div>
328 <div class="post-reach">
329 <div class="post-view">
330 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/eye-outline.svg' ) ?>" alt="<?php esc_attr_e( 'View icon', 'forumax' ); ?>">
331 <?php forumax_topic_view_count( $topic_id );
332 esc_html_e( ' Views', 'forumax' ); ?>
333 </div>
334 <div class="post-like">
335 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/thumbs-up-outline.svg' ) ?>" alt="<?php esc_attr_e( 'Like icon', 'forumax' ); ?>">
336 <?php
337 if ( $vote_count ) {
338 echo esc_html( $vote_count );
339 } else {
340 echo "0";
341 }
342 esc_html_e( ' Likes', 'forumax' ); ?>
343 </div>
344 <div class="post-comment">
345 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/chatbubbles-outline.svg' ) ?>" alt="<?php esc_attr_e( 'Comment icon', 'forumax' ); ?>">
346 <?php
347 bbp_topic_reply_count( $topic_id );
348 esc_html_e( ' Replies', 'forumax' )
349 ?>
350 </div>
351 </div>
352 </div>
353 <?php
354 $i ++;
355 endwhile;
356 unset( $i );
357 wp_reset_postdata();
358 ?>
359
360 <?php if ( isset($settings['is_topic_tab_btn']) && $settings['is_topic_tab_btn'] ) : ?>
361 <div class="row">
362 <div class="text-center bbpc-show-more-btn-wrapper">
363 <a href="<?php echo esc_url( $settings['more_url2'] ?? '#' ); ?>" class="dbl-arrow-upper show-more-btn show-more-round mt-70">
364 <div class="arrow-cont">
365 <svg width="13px" height="13px" class="first" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h48v48H0z" fill="none"></path><polygon points="24,29.171 9.414,14.585 6.586,17.413 24,34.827 41.414,17.413 38.586,14.585"></polygon> </g> </g></svg>
366 <svg width="13px" height="13px" class="second" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg"> <path d="M0 0h48v48H0z" fill="none"></path><polygon points="24,29.171 9.414,14.585 6.586,17.413 24,34.827 41.414,17.413 38.586,14.585"></polygon> </g> </g> </svg>
367 </div>
368 <?php echo esc_html( $settings['more_txt2'] ?? '' ); ?>
369 </a>
370 </div>
371 </div>
372 <?php endif; ?>
373
374 </div>
375 </section>
376 <?php
377 // Sanitize color values (allow hex and rgba formats)
378 $sanitize_css_color = function( $color ) {
379 $color = trim( (string) $color );
380 if ( empty( $color ) ) {
381 return '';
382 }
383
384 // Allow hex colors like #fff or #ffffff
385 if ( preg_match( '/^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$/', $color ) ) {
386 return $color;
387 }
388
389 // Allow rgb() or rgba() formats
390 if ( preg_match( '/^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+(?:\s*,\s*(0|1|0?\.\d+))?\s*\)$/', $color ) ) {
391 return $color;
392 }
393
394 // Fallback: empty (reject any other values)
395 return '';
396 };
397
398 $forum_tab_title_color = isset( $attributes['forum_tab_title_color'] ) ? $sanitize_css_color( $attributes['forum_tab_title_color'] ) : '';
399 $topics_tab_title_color = isset( $attributes['topics_tab_title_color'] ) ? $sanitize_css_color( $attributes['topics_tab_title_color'] ) : '';
400 $forum_tab_content_color = isset( $attributes['forum_tab_content_color'] ) ? $sanitize_css_color( $attributes['forum_tab_content_color'] ) : '';
401 $topics_tab_content_color = isset( $attributes['topics_tab_content_color'] ) ? $sanitize_css_color( $attributes['topics_tab_content_color'] ) : '';
402
403 if ( $forum_tab_title_color || $topics_tab_title_color || $forum_tab_content_color || $topics_tab_content_color ) :
404 ?>
405 <style>
406 <?php if ( $forum_tab_title_color ) : ?>
407 #forumTab-<?php echo esc_attr( $this_get_id ); ?> .nav-tabs .nav-item:first-child button { color: <?php echo esc_attr( $forum_tab_title_color ); ?>; }
408 <?php endif; ?>
409
410 <?php if ( $topics_tab_title_color ) : ?>
411 #forumTab-<?php echo esc_attr( $this_get_id ); ?> .nav-tabs .nav-item:nth-child(2) button { color: <?php echo esc_attr( $topics_tab_title_color ); ?>; }
412 <?php endif; ?>
413
414 <?php if ( $forum_tab_content_color ) : ?>
415 #forum-<?php echo esc_attr( $this_get_id ); ?> .community-topic-widget-box .box-content,
416 #forum-<?php echo esc_attr( $this_get_id ); ?> .community-topic-widget-box .box-content a { color: <?php echo esc_attr( $forum_tab_content_color ); ?>; }
417 <?php endif; ?>
418
419 <?php if ( $topics_tab_content_color ) : ?>
420 #topics-<?php echo esc_attr( $this_get_id ); ?> .single-forum-post-widget .post-content,
421 #topics-<?php echo esc_attr( $this_get_id ); ?> .single-forum-post-widget .post-content a { color: <?php echo esc_attr( $topics_tab_content_color ); ?>; }
422 <?php endif; ?>
423 </style>
424 <?php endif; ?>
425 <?php
426 return ob_get_clean();
427 }
428
429 public function render_forums( $attributes, $content ) {
430 if ( ! wp_script_is( 'bbpc-ajax', 'registered' ) ) {
431 wp_register_script( 'bbpc-ajax', FORUMAX_FRONT_ASS . 'js/ajax.js', array( 'jquery' ), FORUMAX_VERSION, true );
432 }
433 if ( ! wp_style_is( 'bbpc-el-widgets', 'registered' ) ) {
434 wp_register_style( 'bbpc-el-widgets', FORUMAX_FRONT_ASS . 'css/el-widgets.css');
435 }
436
437 wp_enqueue_script( 'bbpc-ajax' );
438 wp_enqueue_style( 'bbpc-el-widgets' );
439
440 $ppp = ! empty( $attributes['ppp'] ) ? $attributes['ppp'] : 5;
441 $ppp2 = ! empty( $attributes['ppp2'] ) ? $attributes['ppp2'] : 10;
442 $order = ! empty( $attributes['order'] ) ? $attributes['order'] : 'ASC';
443 $more_txt = ! empty( $attributes['more_txt'] ) ? $attributes['more_txt'] : __( 'More Communities', 'forumax' );
444 $unique_id = uniqid( 'bbpc-forums-' );
445
446 $forums = new WP_Query( array(
447 'post_type' => 'forum',
448 'posts_per_page' => $ppp,
449 'order' => $order,
450 ) );
451
452 ob_start();
453 ?>
454 <div id="<?php echo esc_attr( $unique_id ); ?>">
455 <div class="communities-boxes">
456 <?php
457 while ( $forums->have_posts() ) : $forums->the_post();
458 ?>
459 <div class="com-box wow fadeInRight" data-wow-delay="0.5s">
460 <div class="icon-container">
461 <?php the_post_thumbnail( 'full' ); ?>
462 </div>
463 <div class="com-box-content">
464 <h3 class="title">
465 <a href="<?php the_permalink(); ?>"> <?php the_title() ?> </a>
466 </h3>
467 <p class="total-post"> <?php bbp_forum_topic_count( get_the_ID() ); ?> <?php esc_html_e( ' Posts', 'forumax' ) ?> </p>
468 </div>
469 <!-- /.ama-com-box-content -->
470 </div>
471 <!-- /.ama-com-box -->
472 <?php
473 endwhile;
474 wp_reset_postdata();
475 ?>
476 </div>
477 <!-- /.communities-boxes -->
478
479 <div class="more-communities" data_id="<?php echo esc_attr( $unique_id );?>">
480
481 <a href="#more-category" class="collapse-btn-wrap">
482 <?php echo esc_html( $more_txt ); ?>
483
484 <svg fill="#000000" width="16px" height="16px" viewBox="0 0 24 24" id="minus" data-name="Line Color" xmlns="http://www.w3.org/2000/svg" class="icon line-color icon_minus"> <line id="primary" x1="19" y1="12" x2="5" y2="12" style="fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2;"></line> </svg>
485
486 <svg fill="#000000" width="16px" height="16px" viewBox="0 0 24 24" id="plus" data-name="Line Color" xmlns="http://www.w3.org/2000/svg" class="icon line-color icon_plus"><path id="secondary" d="M5,12H19M12,5V19" style="fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2;"></path></svg>
487 </a>
488
489 <div class="collapse-wrap" id="more-category" data_id="<?php echo esc_attr( $unique_id );?>">
490 <div class="communities-boxes">
491 <?php
492 $forums2 = new WP_Query( array(
493 'post_type' => 'forum',
494 'posts_per_page' => $ppp2,
495 'offset' => $ppp,
496 'order' => $order,
497 ) );
498 while ( $forums2->have_posts() ) : $forums2->the_post();
499 ?>
500 <div class="com-box">
501 <div class="icon-container">
502 <?php the_post_thumbnail( 'full' ); ?>
503 </div>
504 <div class="com-box-content">
505 <h3 class="title">
506 <a href="<?php the_permalink(); ?>"> <?php the_title() ?> </a>
507 </h3>
508 <p class="total-post"> <?php bbp_forum_topic_count( get_the_ID() ); ?> <?php esc_html_e( ' Posts', 'forumax' ); ?> </p>
509 </div>
510 <!-- /.ama-com-box-content -->
511 </div>
512 <!-- /.ama-com-box -->
513 <?php
514 endwhile;
515 wp_reset_postdata();
516 ?>
517 </div>
518 <!-- /.communities-boxes -->
519 </div>
520 <!-- /.collapse-wrap -->
521 </div>
522 </div>
523 <!-- /.more-communities -->
524 <?php if( ! empty( $attributes['more_text_color'] ) || ! empty( $attributes['title_color'] ) || ! empty( $attributes['content_color'] ) ): ?>
525 <style>
526 <?php if( ! empty( $attributes['more_text_color'] ) ): ?>
527 #<?php echo esc_attr( $unique_id ); ?> .collapse-btn-wrap {
528 color: <?php echo esc_attr( $attributes['more_text_color'] ); ?>;
529 }
530 #<?php echo esc_attr( $unique_id ); ?> .more-communities .collapse-btn-wrap svg path {
531 stroke: <?php echo esc_attr( $attributes['more_text_color'] ); ?>;
532 }
533 #<?php echo esc_attr( $unique_id ); ?> .more-communities .collapse-btn-wrap svg line {
534 stroke: <?php echo esc_attr( $attributes['more_text_color'] ); ?>;
535 }
536 <?php endif; ?>
537
538 <?php if( ! empty( $attributes['title_color'] ) ): ?>
539 #<?php echo esc_attr( $unique_id ); ?> .com-box-content .title a {
540 color: <?php echo esc_attr( $attributes['title_color'] ); ?>;
541 }
542 <?php endif; ?>
543
544 <?php if( ! empty( $attributes['content_color'] ) ): ?>
545 #<?php echo esc_attr( $unique_id ); ?> .com-box-content .total-post {
546 color: <?php echo esc_attr( $attributes['content_color'] ); ?>;
547 }
548 <?php endif; ?>
549 </style>
550 <?php endif; ?>
551 <?php
552 return ob_get_clean();
553 }
554
555 public function render_search( $attributes, $content ) {
556 $placeholder = isset( $attributes['placeholder'] ) ? $attributes['placeholder'] : 'Search for Topics....';
557 $submit_btn_type = isset( $attributes['submit_btn_type'] ) ? $attributes['submit_btn_type'] : 'icon';
558 $submit_btn_text = isset( $attributes['submit_btn_text'] ) ? $attributes['submit_btn_text'] : __( 'Search', 'forumax' );
559 $submit_btn_align = isset( $attributes['submit_btn_align'] ) ? $attributes['submit_btn_align'] : 'left';
560 $submit_btn_icon = isset( $attributes['submit_btn_icon'] ) ? $attributes['submit_btn_icon'] : [ 'value' => 'fas fa-search', 'library' => 'solid' ];
561 $is_keywords = isset( $attributes['is_keywords'] ) ? $attributes['is_keywords'] : true;
562 $keywords_label = isset( $attributes['keywords_label'] ) ? $attributes['keywords_label'] : 'Popular:';
563 $keywords_align = isset( $attributes['keywords_align'] ) ? $attributes['keywords_align'] : 'center';
564 $keywords = isset( $attributes['keywords'] ) ? $attributes['keywords'] : [ [ 'title' => 'Keyword #1' ], [ 'title' => 'Keyword #2' ] ];
565
566 $unique_id = uniqid( 'bbpc-search-' );
567
568 $cross_position = $submit_btn_align == 'right' ? 'left' : 'right';
569
570 // Include dependencies
571 if ( ! wp_style_is( 'bbpc-el-widgets', 'registered' ) ) {
572 wp_register_style( 'bbpc-el-widgets', FORUMAX_FRONT_ASS . 'css/el-widgets.css' );
573 }
574 wp_enqueue_style( 'bbpc-el-widgets' );
575
576 wp_enqueue_script( 'bbpc-frontend-js', FORUMAX_FRONT_ASS . 'js/frontend.js', array( 'jquery' ), FORUMAX_VERSION, true );
577
578 $wrapper_attributes = get_block_wrapper_attributes( [
579 'id' => $unique_id,
580 ] );
581
582 ob_start();
583 ?>
584 <div <?php echo $wrapper_attributes; ?>>
585 <div class="bbpc-search-overlay"></div>
586
587 <form action="<?php echo esc_url( home_url( '/' ) ) ?>" role="search" method="get" class="bbpc_search_form_wrapper">
588 <div class="form-group">
589 <div class="input-wrapper <?php echo esc_attr( $cross_position ); ?>">
590
591 <span class="submit-btn-<?php echo esc_attr( $submit_btn_align ); ?>">
592 <button type="submit">
593 <?php
594 if ( $submit_btn_type == 'icon' ) {
595 // Simple render icon function replacement or manual render
596 if( is_array( $submit_btn_icon ) && ! empty( $submit_btn_icon['value'] ) ) {
597 echo '<i class="' . esc_attr( $submit_btn_icon['value'] ) . '"></i>';
598 } else {
599 echo '<i class="fas fa-search"></i>';
600 }
601 } else {
602 echo esc_html( $submit_btn_text );
603 }
604 ?>
605 </button>
606 </span>
607
608 <input type='search' id="searchInput" autocomplete="off" name="s" placeholder="<?php echo esc_attr( $placeholder ) ?>">
609
610 <!-- Ajax Search Loading Spinner -->
611 <div class="spinner">
612 <div class="bounce1"></div>
613 <div class="bounce2"></div>
614 <div class="bounce3"></div>
615 </div>
616
617 <!-- WPML Language Code -->
618 <?php if ( defined( 'ICL_LANGUAGE_CODE' ) ) : ?>
619 <input type="hidden" name="lang" value="<?php echo esc_attr( ICL_LANGUAGE_CODE ); ?>"/>
620 <?php endif; ?>
621
622 <input type="hidden" id="hidden_post_type" name="post_type" value="docs"/>
623 </div>
624 </div>
625 <div id="datafetch"></div>
626
627 <?php if ( $is_keywords ) : ?>
628 <?php if ( class_exists( 'Forumax_Pro' ) ) : ?>
629 <div class="bbpc-search-keyword">
630 <div class="bbpc-keywords-wrapper" style="text-align: <?php echo esc_attr( $keywords_align ); ?>">
631 <?php if ( ! empty( $keywords_label ) ) : ?>
632 <span class="bbpc-search-keywords-label"><?php echo esc_html( $keywords_label ); ?></span>
633 <?php endif; ?>
634 <ul>
635 <?php foreach ( $keywords as $keyword ) : ?>
636 <li><a href="<?php echo esc_url( home_url( '/?s=' . $keyword['title'] . '&post_type=topic' ) ); ?>"> <?php echo esc_html( $keyword['title'] ); ?> </a></li>
637 <?php endforeach; ?>
638 </ul>
639 </div>
640 </div>
641 <?php else : ?>
642 <?php
643 // Show only in Editor (via ServerSideRender or admin page)
644 if ( ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || is_admin() ) :
645 $upsell_img = FORUMAX_FRONT_ASS . 'img/upsell-search-keywords.png';
646 $upgrade_url = admin_url( 'admin.php?page=forumax-pricing' );
647 ?>
648 <div class="bbpc-search-keyword-upsell">
649 <img src="<?php echo esc_url( $upsell_img ); ?>" alt="<?php esc_attr_e( 'Upgrade to Pro', 'forumax' ); ?>">
650 <div class="upsell-btn-wrapper bbpc-upgrade-btn">
651 <a href="<?php echo esc_url( $upgrade_url ); ?>" target="_blank" rel="noopener noreferrer">
652 <?php esc_html_e( 'Upgrade to Pro', 'forumax' ); ?>
653 </a>
654 </div>
655 </div>
656 <?php endif; ?>
657 <?php endif; ?>
658 <?php endif; ?>
659 </form>
660 </div>
661
662 <style>
663 <?php if( ! empty( $attributes['color_text'] ) ): ?>
664 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input { color: <?php echo esc_attr( $attributes['color_text'] ); ?>; }
665 <?php endif; ?>
666 <?php if( ! empty( $attributes['color_placeholder'] ) ): ?>
667 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input::placeholder { color: <?php echo esc_attr( $attributes['color_placeholder'] ); ?>; }
668 <?php endif; ?>
669 <?php if( ! empty( $attributes['input_bg_color'] ) ): ?>
670 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input { background-color: <?php echo esc_attr( $attributes['input_bg_color'] ); ?>; }
671 <?php endif; ?>
672 <?php if( ! empty( $attributes['color_icon'] ) ): ?>
673 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper button { color: <?php echo esc_attr( $attributes['color_icon'] ); ?>; }
674 <?php endif; ?>
675 <?php if( ! empty( $attributes['search_bg'] ) ): ?>
676 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper button { background: <?php echo esc_attr( $attributes['search_bg'] ); ?>; }
677 <?php endif; ?>
678
679 /* Keywords Styles */
680 <?php if( ! empty( $attributes['color_keywords_label'] ) ): ?>
681 #<?php echo esc_attr( $unique_id ); ?> .bbpc-search-keyword span.bbpc-search-keywords-label { color: <?php echo esc_attr( $attributes['color_keywords_label'] ); ?>; }
682 <?php endif; ?>
683 <?php if( ! empty( $attributes['bbpc_color_keywords'] ) ): ?>
684 #<?php echo esc_attr( $unique_id ); ?> .bbpc-search-keyword ul li a { color: <?php echo esc_attr( $attributes['bbpc_color_keywords'] ); ?>; }
685 <?php endif; ?>
686 <?php if( ! empty( $attributes['bbpc_color_keywords_bg'] ) ): ?>
687 #<?php echo esc_attr( $unique_id ); ?> .bbpc-search-keyword ul li a { background: <?php echo esc_attr( $attributes['bbpc_color_keywords_bg'] ); ?>; }
688 <?php endif; ?>
689 <?php if( ! empty( $attributes['bbpc_color_keywords_hover'] ) ): ?>
690 #<?php echo esc_attr( $unique_id ); ?> .bbpc-search-keyword ul li a:hover { color: <?php echo esc_attr( $attributes['bbpc_color_keywords_hover'] ); ?>; }
691 <?php endif; ?>
692 <?php if( ! empty( $attributes['bbpc_color_keywords_bg_hover'] ) ): ?>
693 #<?php echo esc_attr( $unique_id ); ?> .bbpc-search-keyword ul li a:hover { background: <?php echo esc_attr( $attributes['bbpc_color_keywords_bg_hover'] ); ?>; }
694 <?php endif; ?>
695 </style>
696 <?php
697 return ob_get_clean();
698 }
699
700 public function render_single_forum( $attributes, $content ) {
701 $settings = $attributes;
702 $settings['style'] = !empty($attributes['style']) ? $attributes['style'] : '1';
703 $settings['ppp'] = !empty($attributes['ppp']) ? $attributes['ppp'] : 3;
704 $settings['order'] = !empty($attributes['order']) ? $attributes['order'] : 'ASC';
705 $settings['word_length'] = !empty($attributes['word_length']) ? $attributes['word_length'] : 12;
706 $settings['read_more'] = !empty($attributes['read_more']) ? $attributes['read_more'] : 'View All';
707
708 $forum_id = !empty($settings[ 'forum_id' ]) ? $settings[ 'forum_id' ] : '';
709
710 $cover_image = isset($settings[ 'cover_image' ]) ? $settings[ 'cover_image' ] : '';
711 $url = '';
712 if ( is_array($cover_image) && isset($cover_image['url']) ) {
713 $url = $cover_image['url'];
714 } elseif ( is_object($cover_image) && isset($cover_image->url) ) {
715 $url = $cover_image->url;
716 }
717
718 $post_thumbnail_url = !empty($url) ? $url : get_the_post_thumbnail_url($forum_id);
719
720 $topics = new \WP_Query(array(
721 'post_type' => bbp_get_topic_post_type(),
722 'order' => !empty($settings['order']) ? $settings['order'] : 'DESC',
723 'posts_per_page' => !empty($settings['ppp']) ? $settings['ppp'] : 3,
724 'post_parent' => $forum_id,
725 ));
726
727 $unique_id = uniqid('bbpc-single-forum-');
728
729 if ( ! wp_style_is( 'bbpc-el-widgets', 'registered' ) ) {
730 wp_register_style( 'bbpc-el-widgets', FORUMAX_FRONT_ASS . 'css/el-widgets.css' );
731 }
732 wp_enqueue_style( 'bbpc-el-widgets' );
733
734 ob_start();
735
736 echo '<div id="' . esc_attr($unique_id) . '">';
737
738 if ($forum_id) {
739 $template_path = __DIR__ . '/../Elementor/inc/single-forum/single-forum-' . $settings['style'] . '.php';
740 if ( file_exists( $template_path ) ) {
741 include $template_path;
742 }
743 } else {
744 ?>
745 <div class="alert alert-warning" role="alert">
746 <?php esc_html_e('Please select a forum.', 'forumax'); ?>
747 </div>
748 <?php
749 }
750
751 echo '</div>';
752
753 ?>
754 <style>
755 <?php if( ! empty( $attributes['title_color'] ) ): ?>
756 #<?php echo esc_attr( $unique_id ); ?> .forum-with-topics .topic-table .topic-contents .title h3,
757 #<?php echo esc_attr( $unique_id ); ?> .forum-card .card-title h3 { color: <?php echo esc_attr( $attributes['title_color'] ); ?>; }
758 <?php endif; ?>
759 <?php if( ! empty( $attributes['excerpt_color'] ) ): ?>
760 #<?php echo esc_attr( $unique_id ); ?> .forum-with-topics .topic-table .topic-contents .title p,
761 #<?php echo esc_attr( $unique_id ); ?> .forum-card .card-body { color: <?php echo esc_attr( $attributes['excerpt_color'] ); ?>; }
762 <?php endif; ?>
763 </style>
764 <?php
765
766 return ob_get_clean();
767 }
768
769
770 public function render_forum_ajax( $attributes, $content ) {
771 // Upsell logic for frontend when Pro is not active
772 if ( ! class_exists( 'Forumax_Pro' ) ) {
773 $upsell_img = defined( 'FORUMAX_IMG' ) ? FORUMAX_IMG . 'upsell-forum-ajax.png' : '';
774 $upgrade_url = admin_url( 'admin.php?page=forumax-pricing' );
775
776 ob_start();
777 ?>
778 <style>
779 .bbpc-upsell-container {
780 position: relative;
781 display: flex;
782 justify-content: center;
783 align-items: center;
784 min-height: 300px;
785 background: #f5f5f5;
786 border: 1px dashed #ccc;
787 overflow: hidden;
788 border-radius: 8px;
789 margin: 20px 0;
790 }
791 .bbpc-upsell-container img {
792 max-width: 100%;
793 height: auto;
794 display: block;
795 opacity: 0.5;
796 }
797 .bbpc-upsell-btn-wrapper {
798 position: absolute;
799 top: 50%;
800 left: 50%;
801 transform: translate(-50%, -50%);
802 z-index: 10;
803 }
804 .bbpc-upgrade-btn-frontend {
805 background: linear-gradient(90deg, #172473 0%, #0fa2d0 100%) !important;
806 border: none !important;
807 color: #fff !important;
808 padding: 15px 20px !important;
809 font-size: 18px !important;
810 font-weight: 500 !important;
811 border-radius: 4px !important;
812 text-decoration: none !important;
813 box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2) !important;
814 transition: all 0.3s ease !important;
815 display: inline-block !important;
816 line-height: 1 !important;
817 }
818 .bbpc-upgrade-btn-frontend:hover {
819 transform: translate(-2px, -2px);
820 box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3) !important;
821 color: #fff !important;
822 background: linear-gradient(80deg, #0fa2d0 0%, #172473 100%) !important;
823 }
824 </style>
825 <div class="bbpc-upsell-container">
826 <?php if ( $upsell_img ) : ?>
827 <img src="<?php echo esc_url( $upsell_img ); ?>" alt="<?php esc_attr_e( 'Upgrade to Pro', 'forumax' ); ?>">
828 <?php endif; ?>
829 <div class="bbpc-upsell-btn-wrapper">
830 <a href="<?php echo esc_url( $upgrade_url ); ?>" class="bbpc-upgrade-btn-frontend">
831 <?php esc_html_e( 'Upgrade to Pro', 'forumax' ); ?>
832 </a>
833 </div>
834 </div>
835 <?php
836 return ob_get_clean();
837 }
838
839 try {
840 if ( ! wp_style_is( 'bbpc-el-widgets', 'registered' ) ) {
841 if ( defined( 'FORUMAX_FRONT_ASS' ) ) {
842 wp_register_style( 'bbpc-el-widgets', FORUMAX_FRONT_ASS . 'css/el-widgets.css' );
843 }
844 }
845
846 wp_enqueue_style( 'bbpc-el-widgets' );
847
848 $ppp2 = isset( $attributes['ppp2'] ) ? $attributes['ppp2'] : 9;
849 $order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC';
850 $filter_btns = isset( $attributes['filter_btns'] ) ? $attributes['filter_btns'] : true;
851
852 // Styling attributes
853 $forum_title_color = isset( $attributes['forum_title_color'] ) ? $attributes['forum_title_color'] : '';
854 $forum_title_hover_color = isset( $attributes['forum_title_hover_color'] ) ? $attributes['forum_title_hover_color'] : '';
855 $forum_meta_color = isset( $attributes['forum_meta_color'] ) ? $attributes['forum_meta_color'] : '';
856 $parent_forum_color = isset( $attributes['parent_forum_color'] ) ? $attributes['parent_forum_color'] : '';
857 $parent_forum_color_hover = isset( $attributes['parent_forum_color_hover'] ) ? $attributes['parent_forum_color_hover'] : '';
858
859 // Sanitize color values (allow hex and rgba formats)
860 $sanitize_css_color = function( $color ) {
861 $color = trim( (string) $color );
862 if ( empty( $color ) ) {
863 return '';
864 }
865 if ( preg_match( '/^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$/', $color ) ) {
866 return $color;
867 }
868 if ( preg_match( '/^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+(?:\s*,\s*(0|1|0?\.\d+))?\s*\)$/', $color ) ) {
869 return $color;
870 }
871 return '';
872 };
873
874 $forum_title_color = $sanitize_css_color( $forum_title_color );
875 $forum_title_hover_color = $sanitize_css_color( $forum_title_hover_color );
876 $forum_meta_color = $sanitize_css_color( $forum_meta_color );
877 $parent_forum_color = $sanitize_css_color( $parent_forum_color );
878 $parent_forum_color_hover = $sanitize_css_color( $parent_forum_color_hover );
879
880 $unique_id = uniqid( 'bbpc-forum-' );
881
882 // Check constants
883 if ( ! defined( 'FORUMAX_VEND' ) || ! defined( 'FORUMAX_FRONT_ASS' ) || ! defined( 'FORUMAX_VERSION' ) ) {
884 return 'Constants missing';
885 } else {
886 // Enqueue styles/scripts
887 if ( ! wp_style_is( 'elegant-icon', 'registered' ) ) {
888 wp_register_style( 'elegant-icon', FORUMAX_VEND . '/elegant-icon/style.css' );
889 }
890 if ( ! wp_script_is( 'bbpc-ajax', 'registered' ) ) {
891 // Use Free path
892 wp_register_script( 'bbpc-ajax', FORUMAX_FRONT_ASS . 'js/ajax.js', array( 'jquery' ), FORUMAX_VERSION, true );
893 }
894
895 wp_enqueue_style( 'elegant-icon' );
896 wp_enqueue_script( 'bbpc-ajax' );
897 }
898
899 // Inline Styles
900 $style = "<style>";
901 if ( $forum_title_color ) {
902 $style .= "#{$unique_id} .single-forum-post-widget .post-title a { color: {$forum_title_color}; }";
903 }
904 if ( $forum_title_hover_color ) {
905 $style .= "#{$unique_id} .single-forum-post-widget .post-title a:hover { color: {$forum_title_hover_color}; }";
906 }
907 if ( $forum_meta_color ) {
908 $style .= "#{$unique_id} .single-forum-post-widget .post-info .author, #{$unique_id} .single-forum-post-widget .post-info .post-time { color: {$forum_meta_color}; }";
909 }
910 if ( $parent_forum_color ) {
911 $style .= "#{$unique_id} .post-content .post-category a { color: {$parent_forum_color}; }";
912 }
913 if ( $parent_forum_color_hover ) {
914 $style .= "#{$unique_id} .post-content .post-category a:hover { color: {$parent_forum_color_hover}; }";
915 }
916 $style .= "</style>";
917
918 $topics = new WP_Query( array(
919 'post_type' => 'topic',
920 'posts_per_page' => $ppp2,
921 'order' => $order,
922 ) );
923
924 $wrapper_attributes = get_block_wrapper_attributes( [
925 'class' => 'forum-post-widget',
926 'id' => $unique_id,
927 ] );
928
929 ob_start();
930 echo $style;
931 ?>
932
933 <div <?php echo $wrapper_attributes; ?> data_id="<?php echo esc_attr( $unique_id ); ?>">
934
935 <?php if ( $filter_btns ) : ?>
936 <div class="post-filter-widget mb-20">
937 <div class="single-filter-item">
938 <a href="#" id="all_filt" data-forum="all" class="data-active">
939 <i class="icon_grid-2x2"></i><?php esc_html_e( 'All', 'forumax' ) ?>
940 </a>
941 </div>
942 <div class="single-filter-item">
943 <a href="#" id="populer_filt" data-forum="popular">
944 <i class="icon_easel"></i><?php esc_html_e( 'Popular', 'forumax' ) ?>
945 </a>
946 </div>
947 <div class="single-filter-item">
948 <a href="#" id="featured_filt" data-forum="featured">
949 <i class="icon_ribbon_alt"></i><?php esc_html_e( 'Featured', 'forumax' ) ?>
950 </a>
951 </div>
952 <div class="single-filter-item">
953 <a href="#" id="recent_filt" data-forum="recent">
954 <i class="icon_clock_alt"></i><?php esc_html_e( 'Recent', 'forumax' ) ?>
955 </a>
956 </div>
957 <div class="single-filter-item">
958 <a href="#" id="unloved_filt" data-forum="unloved">
959 <i class="icon_close_alt2"></i><?php esc_html_e( 'Unloved', 'forumax' ) ?>
960 </a>
961 </div>
962 <div class="single-filter-item">
963 <a href="#" id="loved_filt" data-forum="loved">
964 <i class="icon_check_alt2"></i><?php esc_html_e( 'Loved', 'forumax' ) ?>
965 </a>
966 </div>
967 </div>
968 <?php endif; ?>
969
970 <div id="aj-post-filter-widget">
971 <?php
972 $i = 0;
973 while ( $topics->have_posts() ) : $topics->the_post();
974 $topic_id = $topics->posts[ $i ]->ID;
975 $vote_count = get_post_meta( $topic_id, "bbpv-votes", true );
976
977 // Safe get forum ID
978 $forum_id = function_exists('bbp_get_topic_forum_id') ? bbp_get_topic_forum_id() : 0;
979 // Safe get forum title
980 $forum_title = '';
981 if ( function_exists('bbp_get_topic_forum_title') ) {
982 $forum_title = bbp_get_topic_forum_title();
983 } elseif ( function_exists('bbp_get_forum_title') ) {
984 $forum_title = bbp_get_forum_title( $forum_id );
985 }
986 ?>
987 <div class="single-forum-post-widget">
988 <div class="post-content">
989 <div class="post-title">
990 <h6><a href="<?php the_permalink(); ?>"> <?php the_title() ?> </a></h6>
991 </div>
992 <div class="post-info">
993 <div class="author">
994 <?php if ( defined('FORUMAX_IMG') ): ?>
995 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/user-circle-alt.svg' ); ?>" alt="<?php esc_attr_e( 'User circle alt icon', 'forumax' ); ?>">
996 <?php endif; ?>
997 <?php
998 if ( function_exists('bbp_get_topic_author_link') ) {
999 echo wp_kses_post( bbp_get_topic_author_link(
1000 array(
1001 'post_id' => $topic_id,
1002 'type' => 'name'
1003 )
1004 ) );
1005 }
1006 ?>
1007 </div>
1008
1009 <div class="post-time">
1010 <?php if ( defined('FORUMAX_IMG') ): ?>
1011 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/time-outline.svg' ); ?>"
1012 alt="<?php esc_attr_e( 'Time outline icon', 'forumax' ); ?>">
1013 <?php endif; ?>
1014 <?php
1015 // Use topic last active time, fallback to forum last active time, checking existence
1016 if ( function_exists('bbp_topic_last_active_time') ) {
1017 bbp_topic_last_active_time( get_the_ID() );
1018 } elseif ( function_exists('bbp_forum_last_active_time') ) {
1019 bbp_forum_last_active_time( get_the_ID() );
1020 }
1021 ?>
1022 </div>
1023 </div>
1024
1025 <div class="post-category">
1026 <a href="<?php echo esc_url( get_the_permalink( $forum_id ) ); ?>">
1027 <?php echo get_the_post_thumbnail( $forum_id ); ?>
1028 <?php echo esc_html( $forum_title ); ?>
1029 </a>
1030 </div>
1031 </div>
1032 <div class="post-reach">
1033 <div class="post-view">
1034 <?php if ( defined('FORUMAX_IMG') ): ?>
1035 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/eye-outline.svg' ); ?>" alt="<?php esc_attr_e( 'Eye outline icon', 'forumax' ); ?>">
1036 <?php endif; ?>
1037
1038 <?php
1039 if ( function_exists('forumax_topic_view_count') ) {
1040 forumax_topic_view_count( $topic_id );
1041 }
1042 echo '&nbsp;';
1043 esc_html_e( 'Views', 'forumax' );
1044 ?>
1045 </div>
1046 <div class="post-like">
1047 <?php if ( defined('FORUMAX_IMG') ): ?>
1048 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/thumbs-up-outline.svg' ); ?>"
1049 alt="<?php esc_attr_e( 'Thumbs-up outline icon', 'forumax' ); ?>">
1050 <?php endif; ?>
1051
1052 <?php
1053 if ( $vote_count ) {
1054 echo esc_html( $vote_count );
1055 } else {
1056 echo "0";
1057 }
1058
1059 echo '&nbsp;';
1060 esc_html_e( 'Likes', 'forumax' );
1061 ?>
1062 </div>
1063 <div class="post-comment">
1064 <?php if ( defined('FORUMAX_IMG') ): ?>
1065 <img src="<?php echo esc_url( FORUMAX_IMG . 'forum_tab/chatbubbles-outline.svg' ); ?>"
1066 alt="<?php esc_attr_e( 'Chat bubbles icon', 'forumax' ); ?>">
1067 <?php endif; ?>
1068 <?php
1069 if ( function_exists('bbp_topic_reply_count') ) {
1070 bbp_topic_reply_count( $topic_id );
1071 }
1072 echo '&nbsp;';
1073 esc_html_e( 'Replies', 'forumax' );
1074 ?>
1075 </div>
1076 </div>
1077 </div>
1078 <?php
1079 $i ++;
1080 endwhile;
1081 wp_reset_postdata();
1082 ?>
1083 </div>
1084 </div>
1085 <?php
1086 return ob_get_clean();
1087 } catch ( \Throwable $e ) {
1088 return '<div>Error rendering block: ' . esc_html( $e->getMessage() ) . '</div>';
1089 }
1090 }
1091 }
1092