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