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
bbp-core / includes / Blocks / Render / forum-posts.php

forum-posts.php in Forumax – AI Powered Advanced Community Forum Plugin 2.2.0, at includes/Blocks/Render/forum-posts.php

419 lines 15.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace admin\Blocks\Render;
3
4 use WP_Query;
5
6 class Forum_Posts {
7 /**
8 * Render the Forum Posts block.
9 *
10 * @param array $attributes Block attributes.
11 * @param string $content Block content.
12 * @return string Rendered block HTML.
13 */
14 public function render_forum_posts($attributes, $content)
15 {
16 if (!wp_style_is('bbpc-el-widgets', 'registered')) {
17 if (defined('FORUMAX_FRONT_ASS')) {
18 wp_register_style('bbpc-el-widgets', FORUMAX_FRONT_ASS . 'css/el-widgets.css');
19 }
20 }
21 if (!wp_style_is('elegant-icon', 'registered')) {
22 wp_register_style('elegant-icon', FORUMAX_VEND . 'elegant-icon/style.css');
23 }
24 wp_enqueue_style('bbpc-el-widgets');
25 wp_enqueue_style('elegant-icon');
26
27 $ppp = isset($attributes['ppp']) ? $attributes['ppp'] : 5;
28 $order = isset($attributes['order']) ? $attributes['order'] : 'ASC';
29 $orderBy = isset($attributes['orderBy']) ? $attributes['orderBy'] : 'date';
30 $selectedForums = isset($attributes['selectedForums']) ? $attributes['selectedForums'] : [];
31 $layout = isset($attributes['layout']) ? $attributes['layout'] : 'list';
32 $columns = isset($attributes['columns']) ? $attributes['columns'] : 3;
33
34 $pagination_type = isset($attributes['pagination_type']) ? $attributes['pagination_type'] : 'none';
35
36 $show_meta = isset($attributes['show_meta']) ? $attributes['show_meta'] : true;
37 $showAvatar = isset($attributes['showAvatar']) ? $attributes['showAvatar'] : true;
38 $showExcerpt = isset($attributes['showExcerpt']) ? $attributes['showExcerpt'] : false;
39 $showForumLink = isset($attributes['showForumLink']) ? $attributes['showForumLink'] : false;
40
41 // Enforce free defaults when Pro is not active.
42 $is_pro_active = function_exists( 'forumax_is_premium' ) && forumax_is_premium();
43 if ( ! $is_pro_active ) {
44 $layout = 'list';
45 $pagination_type = 'none';
46 $showExcerpt = false;
47 $showForumLink = false;
48 $selectedForums = [];
49 }
50
51 $title_color = isset($attributes['title_color']) ? $attributes['title_color'] : '';
52 $meta_color = isset($attributes['meta_color']) ? $attributes['meta_color'] : '';
53 $bg_color = isset($attributes['bg_color']) ? $attributes['bg_color'] : '';
54
55 // Typography
56 $title_font_size = isset($attributes['title_font_size']) ? $attributes['title_font_size'] : '';
57 $title_font_weight = isset($attributes['title_font_weight']) ? $attributes['title_font_weight'] : '600';
58 $title_line_height = isset($attributes['title_line_height']) ? $attributes['title_line_height'] : '';
59 $meta_font_size = isset($attributes['meta_font_size']) ? $attributes['meta_font_size'] : '';
60 $meta_line_height = isset($attributes['meta_line_height']) ? $attributes['meta_line_height'] : '';
61
62 // Card Styling
63 $card_border = isset($attributes['card_border']) ? $attributes['card_border'] : array();
64 $card_border_width = isset($card_border['width']) ? $card_border['width'] : '1px';
65 $card_border_style = isset($card_border['style']) ? $card_border['style'] : 'solid';
66 $card_border_color = isset($card_border['color']) ? $card_border['color'] : '#eee';
67 $card_border_radius = isset($card_border['radius']) ? $card_border['radius'] : '8px';
68 $card_shadow = isset($attributes['card_shadow']) ? $attributes['card_shadow'] : '';
69 $card_padding = isset($attributes['card_padding']) ? $attributes['card_padding'] : array();
70 $card_padding_top = isset($card_padding['top']) ? $card_padding['top'] : '20px';
71 $card_padding_right = isset($card_padding['right']) ? $card_padding['right'] : '20px';
72 $card_padding_bottom = isset($card_padding['bottom']) ? $card_padding['bottom'] : '20px';
73 $card_padding_left = isset($card_padding['left']) ? $card_padding['left'] : '20px';
74 $card_gap = isset($attributes['card_gap']) ? $attributes['card_gap'] : 20;
75 $card_hover_bg = isset($attributes['card_hover_bg']) ? $attributes['card_hover_bg'] : '';
76 $card_hover_border = isset($attributes['card_hover_border']) ? $attributes['card_hover_border'] : '';
77
78 // Pagination Colors
79 $pagination_text_color = isset($attributes['pagination_text_color']) ? $attributes['pagination_text_color'] : '';
80 $pagination_active_bg = isset($attributes['pagination_active_bg']) ? $attributes['pagination_active_bg'] : '#2271b1';
81 $pagination_active_text = isset($attributes['pagination_active_text']) ? $attributes['pagination_active_text'] : '#ffffff';
82
83 $unique_id = uniqid('bbpc-forum-posts-');
84
85 $paged = (get_query_var('paged')) ? get_query_var('paged') : ((get_query_var('page')) ? get_query_var('page') : 1);
86
87 $query_args = array(
88 'post_type' => 'topic',
89 'posts_per_page' => $ppp,
90 'order' => $order,
91 'paged' => $paged,
92 );
93
94 // Handle Filtering by Forum
95 if (!empty($selectedForums)) {
96 $query_args['post_parent__in'] = $selectedForums;
97 }
98
99 // Handle Ordering
100 if ($orderBy === 'meta_value') {
101 $query_args['meta_key'] = '_bbp_last_active_time';
102 $query_args['orderby'] = 'meta_value';
103 } else {
104 $query_args['orderby'] = $orderBy;
105 }
106
107 $forum_posts = new WP_Query($query_args);
108
109 $wrapper_classes = [
110 'community-posts-wrapper',
111 'bbpc-layout-' . $layout
112 ];
113
114 $wrapper_attributes = get_block_wrapper_attributes([
115 'class' => implode(' ', $wrapper_classes),
116 'id' => $unique_id,
117 ]);
118
119 ob_start();
120 ?>
121 <style>
122 /* Layout Styles */
123 <?php if ($layout === 'grid'): ?>
124 #<?php echo esc_attr($unique_id); ?> .bbpc-posts-list {
125 display: grid;
126 grid-template-columns: repeat(<?php echo intval($columns); ?>, 1fr);
127 gap: <?php echo intval($card_gap); ?>px;
128 }
129 #<?php echo esc_attr($unique_id); ?> .bbpc-posts-list .community-post {
130 flex-direction: column;
131 align-items: flex-start;
132 border: <?php echo esc_attr($card_border_width); ?> <?php echo esc_attr($card_border_style); ?> <?php echo esc_attr($card_border_color); ?>;
133 padding-top: <?php echo esc_attr($card_padding_top); ?>;
134 padding-right: <?php echo esc_attr($card_padding_right); ?>;
135 padding-bottom: <?php echo esc_attr($card_padding_bottom); ?>;
136 padding-left: <?php echo esc_attr($card_padding_left); ?>;
137 border-radius: <?php echo esc_attr($card_border_radius); ?>;
138 background: <?php echo $bg_color ? esc_attr($bg_color) : '#fff'; ?>;
139 transition: all 0.3s ease;
140 <?php if ($card_shadow): ?>
141 box-shadow: <?php echo esc_attr($card_shadow); ?>;
142 <?php endif; ?>
143 }
144 #<?php echo esc_attr($unique_id); ?> .bbpc-posts-list .community-post:hover {
145 <?php if ($card_hover_bg): ?>
146 background-color: <?php echo esc_attr($card_hover_bg); ?>;
147 <?php else: ?>
148 box-shadow: 0 5px 15px rgba(0,0,0,0.05);
149 transform: translateY(-2px);
150 <?php endif; ?>
151 <?php if ($card_hover_border): ?>
152 border-color: <?php echo esc_attr($card_hover_border); ?>;
153 <?php endif; ?>
154 }
155 #<?php echo esc_attr($unique_id); ?> .bbpc-posts-list .community-post .post-content {
156 margin-bottom: 0;
157 width: 100%;
158 flex-direction: column;
159 align-items: flex-start;
160 }
161 #<?php echo esc_attr($unique_id); ?> .bbpc-posts-list .community-post .author-avatar {
162 margin-bottom: 12px;
163 margin-right: 20px;
164 }
165 #<?php echo esc_attr($unique_id); ?> .bbpc-posts-list .community-post .post-meta-wrapper {
166 margin-top: 15px;
167 width: 100%;
168 border-top: 1px solid #f5f5f5;
169 padding-top: 15px;
170 }
171 <?php else: ?>
172 /* List Layout */
173 #<?php echo esc_attr($unique_id); ?> .bbpc-posts-list .community-post {
174 margin-bottom: <?php echo intval($card_gap); ?>px;
175 border: <?php echo esc_attr($card_border_width); ?> <?php echo esc_attr($card_border_style); ?> <?php echo esc_attr($card_border_color); ?>;
176 padding-top: <?php echo esc_attr($card_padding_top); ?>;
177 padding-right: <?php echo esc_attr($card_padding_right); ?>;
178 padding-bottom: <?php echo esc_attr($card_padding_bottom); ?>;
179 padding-left: <?php echo esc_attr($card_padding_left); ?>;
180 border-radius: <?php echo esc_attr($card_border_radius); ?>;
181 background: <?php echo $bg_color ? esc_attr($bg_color) : 'transparent'; ?>;
182 transition: all 0.3s ease;
183 <?php if ($card_shadow): ?>
184 box-shadow: <?php echo esc_attr($card_shadow); ?>;
185 <?php endif; ?>
186 }
187 #<?php echo esc_attr($unique_id); ?> .bbpc-posts-list .community-post:hover {
188 <?php if ($card_hover_bg): ?>
189 background-color: <?php echo esc_attr($card_hover_bg); ?>;
190 <?php endif; ?>
191 <?php if ($card_hover_border): ?>
192 border-color: <?php echo esc_attr($card_hover_border); ?>;
193 <?php endif; ?>
194 }
195 <?php endif; ?>
196
197 /* Pagination Styles */
198 #<?php echo esc_attr($unique_id); ?> .bbpc-pagination {
199 margin-top: 40px;
200 padding-top: 30px;
201 border-top: 1px solid #f0f0f0;
202 text-align: center;
203 }
204 #<?php echo esc_attr($unique_id); ?> .bbpc-pagination ul {
205 display: inline-flex;
206 gap: 6px;
207 list-style: none;
208 padding: 0;
209 margin: 0;
210 flex-wrap: wrap;
211 justify-content: center;
212 }
213 #<?php echo esc_attr($unique_id); ?> .bbpc-pagination .page-numbers {
214 display: flex;
215 align-items: center;
216 justify-content: center;
217 min-width: 40px;
218 height: 40px;
219 padding: 0 12px;
220 color: <?php echo $pagination_text_color ? esc_attr($pagination_text_color) : '#666'; ?>;
221 text-decoration: none;
222 font-weight: 500;
223 font-size: 14px;
224 transition: all 0.25s ease;
225 }
226 #<?php echo esc_attr($unique_id); ?> .bbpc-pagination .page-numbers:hover {
227
228 color: #333;
229 transform: translateY(-1px);
230 }
231 #<?php echo esc_attr($unique_id); ?> .bbpc-pagination .page-numbers li {
232 border:1px solid #e0e0e0;
233 border-radius: 6px;
234 }
235 #<?php echo esc_attr($unique_id); ?> .bbpc-pagination .page-numbers.current {
236 background: <?php echo esc_attr($pagination_active_bg); ?>;
237 color: <?php echo esc_attr($pagination_active_text); ?>;
238 border-color: <?php echo esc_attr($pagination_active_bg); ?>;
239 box-shadow: 0 2px 4px rgba(34,113,177,0.3);
240 cursor: default;
241 border-radius: 6px;
242 }
243 #<?php echo esc_attr($unique_id); ?> .bbpc-pagination .page-numbers.current:hover {
244 transform: none;
245 }
246 #<?php echo esc_attr($unique_id); ?> .bbpc-pagination .page-numbers.dots {
247 border: none;
248 background: transparent;
249 box-shadow: none;
250 color: #999;
251 cursor: default;
252 }
253 #<?php echo esc_attr($unique_id); ?> .bbpc-pagination .page-numbers.dots:hover {
254 transform: none;
255 background: transparent;
256 }
257 #<?php echo esc_attr($unique_id); ?> .bbpc-pagination .page-numbers.prev,
258 #<?php echo esc_attr($unique_id); ?> .bbpc-pagination .page-numbers.next {
259 font-weight: 600;
260 }
261
262
263 /* Typography Styles */
264 <?php if ($title_font_size): ?>
265 #<?php echo esc_attr($unique_id); ?> .community-post .post-content .post-title,
266 #<?php echo esc_attr($unique_id); ?> .community-post .post-content .post-title a {
267 font-size: <?php echo intval($title_font_size); ?>px;
268 }
269 <?php endif; ?>
270
271 #<?php echo esc_attr($unique_id); ?> .community-post .post-content .post-title,
272 #<?php echo esc_attr($unique_id); ?> .community-post .post-content .post-title a {
273 font-weight: <?php echo esc_attr($title_font_weight); ?>;
274 <?php if ($title_line_height): ?>
275 line-height: <?php echo floatval($title_line_height); ?>;
276 <?php endif; ?>
277 }
278
279 <?php if ($meta_font_size): ?>
280 #<?php echo esc_attr($unique_id); ?> .community-post .post-content .entry-content,
281 #<?php echo esc_attr($unique_id); ?> .community-post .post-meta-wrapper .post-meta-info li a,
282 #<?php echo esc_attr($unique_id); ?> .community-post .post-date {
283 font-size: <?php echo intval($meta_font_size); ?>px;
284 }
285 <?php endif; ?>
286
287 <?php if ($meta_line_height): ?>
288 #<?php echo esc_attr($unique_id); ?> .community-post .post-content .entry-content,
289 #<?php echo esc_attr($unique_id); ?> .community-post .post-meta-wrapper .post-meta-info li a,
290 #<?php echo esc_attr($unique_id); ?> .community-post .post-date {
291 line-height: <?php echo floatval($meta_line_height); ?>;
292 }
293 <?php endif; ?>
294
295 <?php if ($title_color): ?>
296 #<?php echo esc_attr($unique_id); ?> .community-post .post-content .post-title a {
297 color:
298 <?php echo esc_attr($title_color); ?>
299 ;
300 }
301
302 <?php endif; ?>
303 <?php if ($meta_color): ?>
304 #<?php echo esc_attr($unique_id); ?> .community-post .post-content .entry-content,
305 #<?php echo esc_attr($unique_id); ?> .community-post .post-meta-wrapper .post-meta-info li a {
306 color:
307 <?php echo esc_attr($meta_color); ?>
308 ;
309 }
310
311 <?php endif; ?>
312 </style>
313 <div <?php echo $wrapper_attributes; ?>>
314 <div class="bbpc-posts-list">
315 <?php
316 while ($forum_posts->have_posts()):
317 $forum_posts->the_post();
318 $favoriters = bbp_get_topic_favoriters();
319 $favorite_count = !empty($favoriters) ? $favoriters[0] : '0';
320 ?>
321 <div class="community-post wow fadeInUp" data-wow-delay="0.5s">
322 <div class="post-content">
323 <?php if ($showAvatar): ?>
324 <div class="author-avatar">
325 <?php
326 echo wp_kses_post(bbp_get_topic_author_link(
327 array(
328 'post_id' => get_the_ID(),
329 'size' => 40,
330 'type' => 'avatar'
331 )
332 ));
333 ?>
334 </div>
335 <?php endif; ?>
336 <div class="entry-content">
337 <h3 class="post-title" style="margin-bottom: 5px;">
338 <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a>
339 </h3>
340
341 <?php if ($showForumLink): ?>
342 <div class="post-parent-forum" style="font-size: 0.85em; margin-bottom: 5px; opacity: 0.8;">
343 <?php
344 $forum_id = bbp_get_topic_forum_id();
345 echo esc_html__('In: ', 'forumax') . '<a href="' . esc_url(get_permalink($forum_id)) . '">' . esc_html(get_the_title($forum_id)) . '</a>';
346 ?>
347 </div>
348 <?php endif; ?>
349
350 <?php if ($showExcerpt): ?>
351 <div class="post-excerpt" style="font-size: 0.9em; margin-bottom: 10px;">
352 <?php bbp_topic_excerpt(); ?>
353 </div>
354 <?php endif; ?>
355
356 <div class="post-date">
357 <?php
358 esc_html_e('Last active: ', 'forumax');
359 echo esc_html(bbp_get_forum_last_active_time(get_the_ID()));
360 ?>
361 </div>
362
363 </div>
364 </div>
365 <?php if ($show_meta): ?>
366 <div class="post-meta-wrapper">
367 <ul class="post-meta-info">
368 <li>
369 <a href="<?php bbp_topic_permalink(); ?>">
370 <i class="icon_chat_alt"></i>
371 <?php bbp_show_lead_topic() ? bbp_topic_reply_count(get_the_ID()) : bbp_topic_post_count(get_the_ID()); ?>
372 </a>
373 </li>
374 <li>
375 <a href="<?php bbp_topic_permalink(); ?>">
376 <i class="icon_star_alt"></i> <?php echo esc_html($favorite_count); ?>
377 </a>
378 </li>
379 </ul>
380 </div>
381 <?php endif; ?>
382 </div>
383 <?php
384 endwhile;
385 ?>
386 </div>
387 <?php
388
389 // Pagination Logic
390 if ($pagination_type === 'numbers') {
391 $big = 999999999;
392 echo '<div class="bbpc-pagination">';
393 echo paginate_links(array(
394 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
395 'format' => '?paged=%#%',
396 'current' => max(1, $paged),
397 'total' => $forum_posts->max_num_pages,
398 'prev_text' => '&laquo;',
399 'next_text' => '&raquo;',
400 'type' => 'list',
401 ));
402 echo '</div>';
403 } elseif ($pagination_type === 'load_more' && $forum_posts->max_num_pages > $paged) {
404 // Basic Load More Button (Link to next page as fallback)
405 $next_page_link = get_next_posts_page_link($forum_posts->max_num_pages);
406 if ($next_page_link) {
407 echo '<div class="bbpc-load-more-wrapper" style="text-align: center; margin-top: 20px;">';
408 echo '<a href="' . esc_url($next_page_link) . '" class="bbpc-load-more-btn button" data-paged="' . ($paged + 1) . '" data-max-pages="' . $forum_posts->max_num_pages . '">' . esc_html__('Load More', 'forumax') . '</a>';
409 echo '</div>';
410 }
411 }
412
413 wp_reset_postdata();
414 ?>
415 </div>
416 <?php
417 return ob_get_clean();
418 }
419 }