PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / trunk
Forumax – AI Powered Advanced Community Forum Plugin vtrunk
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 / Elementor / Forumax_Forums.php

Forumax_Forums.php in Forumax – AI Powered Advanced Community Forum Plugin trunk, at includes/Elementor/Forumax_Forums.php

523 lines 11.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Forumax Forums Widget
4 *
5 * @package Forumax
6 * @subpackage Elementor
7 */
8
9 namespace admin\Elementor;
10
11 use Elementor\Widget_Base;
12 use Elementor\Controls_Manager;
13 use Elementor\Group_Control_Background;
14 use Elementor\Group_Control_Border;
15 use Elementor\Group_Control_Box_Shadow;
16 use Elementor\Group_Control_Typography;
17 use WP_Query;
18
19 // Exit if accessed directly.
20 if (!defined('ABSPATH')) {
21 exit;
22 }
23
24 /**
25 * Class Forumax_Forums
26 * Forums widget from Docy theme
27 *
28 * @package admin\Elementor
29 */
30 class Forumax_Forums extends Widget_Base
31 {
32
33
34 /**
35 * Get widget name.
36 *
37 * @return string Widget name.
38 */
39 public function get_name()
40 {
41 $theme = wp_get_theme();
42 $theme_name = strtolower($theme->get('Name'));
43
44 if ('docy' === $theme_name) {
45 return 'docy_forums';
46 } elseif ('docly' === $theme_name) {
47 return 'Docly_forums';
48 }
49 return 'ama_forums';
50 }
51
52 /**
53 * Get widget title.
54 *
55 * @return string Widget title.
56 */
57 public function get_title()
58 {
59 return __('Forums (Forumax)', 'forumax');
60 }
61
62 /**
63 * Get widget icon.
64 *
65 * @return string Widget icon.
66 */
67 public function get_icon()
68 {
69 return 'eicon-comments';
70 }
71
72 /**
73 * Get widget categories.
74 *
75 * @return array Widget categories.
76 */
77 public function get_categories()
78 {
79 return ['forumax'];
80 }
81
82 /**
83 * Get script dependencies.
84 *
85 * @return array Script dependencies.
86 */
87 public function get_script_depends()
88 {
89 return ['bbpc-ajax'];
90 }
91
92 /**
93 * Get style dependencies.
94 *
95 * @return array Style dependencies.
96 */
97 public function get_style_depends()
98 {
99 return ['bbpc-el-widgets'];
100 }
101
102 /**
103 * Register widget controls.
104 *
105 * @return void
106 */
107 protected function register_controls()
108 {
109 // Select Style.
110 $this->start_controls_section(
111 'style_sec',
112 [
113 'label' => esc_html__('Preset Skins', 'forumax'),
114 ]
115 );
116
117 $this->add_control(
118 'style',
119 [
120 'label' => esc_html__('Forums Style', 'forumax'),
121 'type' => Controls_Manager::VISUAL_CHOICE,
122 'options' => [
123 '1' => [
124 'image' => FORUMAX_ASSETS . '/admin/images/skins/docy-forums-1.jpg',
125 'title' => esc_html__('01 : Forums', 'forumax'),
126 ],
127 '2' => [
128 'image' => FORUMAX_ASSETS . '/admin/images/skins/docy-forums-2.jpg',
129 'title' => esc_html__('02 : Forums', 'forumax'),
130 ],
131 '3' => [
132 'image' => FORUMAX_ASSETS . '/admin/images/skins/forums-3.png',
133 'title' => esc_html__('03 : Help Center', 'forumax'),
134 ],
135 ],
136 'default' => '1',
137 'label_block' => true,
138 ]
139 );
140
141 $this->end_controls_section(); // End Style.
142
143 // Filter Options.
144 $this->start_controls_section(
145 'filter_opt',[
146 'label' => __('Filter Options', 'forumax'),
147 ]
148 );
149
150 $this->add_control(
151 'ppp',
152 [
153 'label' => esc_html__('Show Forums', 'forumax'),
154 'description' => esc_html__('Show the forums count at the initial view. Default is 5 forums in a row.', 'forumax'),
155 'type' => Controls_Manager::NUMBER,
156 'default' => 6,
157 ]
158 );
159
160 $this->add_control(
161 'ppp2',
162 [
163 'label' => esc_html__('Hidden Forums', 'forumax'),
164 'description' => esc_html__('Hidden forums will show on clicking on the More button.', 'forumax'),
165 'type' => Controls_Manager::NUMBER,
166 'default' => 10,
167 'condition' => [
168 'style!' => '3',
169 ],
170 ]
171 );
172
173 $this->add_control(
174 'order',
175 [
176 'label' => esc_html__('Order', 'forumax'),
177 'type' => Controls_Manager::SELECT,
178 'options' => [
179 'ASC' => 'ASC',
180 'DESC' => 'DESC',
181 ],
182 'default' => 'ASC',
183 ]
184 );
185
186 $this->end_controls_section();
187
188 // --- Read More Options
189 $this->start_controls_section(
190 'button_opt',
191 [
192 'label' => __('Read More Options', 'forumax'),
193 'condition' => [
194 'style!' => '3',
195 ],
196 ]
197 );
198
199 $this->add_control(
200 'more_txt',
201 [
202 'label' => esc_html__('Read More Text', 'forumax'),
203 'type' => Controls_Manager::TEXT,
204 'label_block' => true,
205 'default' => 'More Communities',
206 ]
207 );
208
209 $this->add_control(
210 'less_txt',
211 [
212 'label' => esc_html__('Read Less Text', 'forumax'),
213 'type' => Controls_Manager::TEXT,
214 'label_block' => true,
215 'default' => 'Less Communities',
216 ]
217 );
218
219 $this->end_controls_section();
220
221 // Background shape Image.
222 $this->start_controls_section(
223 'style_shapes',
224 [
225 'label' => __('Shape Images', 'forumax'),
226 'tab' => Controls_Manager::TAB_STYLE,
227 'condition' => [
228 'style' => '1',
229 ],
230 ]
231 );
232
233 $this->add_control(
234 'shape1',
235 [
236 'label' => esc_html__('Shape', 'forumax'),
237 'type' => Controls_Manager::MEDIA,
238 'default' => [
239 'url' => plugins_url('inc/forums/images/shap_white.png', __FILE__),
240 ],
241 ]
242 );
243
244 $this->end_controls_section();
245
246 // ── Help Center: Content ────────────────────────────────────────────────
247 // Group 1 — Typography & text for all content elements.
248 $this->start_controls_section(
249 'style_contents',
250 [
251 'label' => esc_html__( 'Content', 'forumax' ),
252 'tab' => Controls_Manager::TAB_STYLE,
253 'condition' => [
254 'style' => '3',
255 ],
256 ]
257 );
258
259 // Title.
260 $this->add_control(
261 'title_head',
262 [
263 'label' => esc_html__( 'Title', 'forumax' ),
264 'type' => Controls_Manager::HEADING,
265 ]
266 );
267
268 $this->add_group_control(
269 Group_Control_Typography::get_type(),
270 [
271 'name' => 'title_typo',
272 'selector' => '{{WRAPPER}} .bbpc-hc-title',
273 ]
274 );
275
276 $this->add_control(
277 'title_color',
278 [
279 'label' => esc_html__( 'Color', 'forumax' ),
280 'type' => Controls_Manager::COLOR,
281 'selectors' => [ '{{WRAPPER}} .bbpc-hc-title' => 'color: {{VALUE}};' ],
282 ]
283 );
284
285 // Description.
286 $this->add_control(
287 'desc_head',
288 [
289 'label' => esc_html__( 'Description', 'forumax' ),
290 'type' => Controls_Manager::HEADING,
291 'separator' => 'before',
292 ]
293 );
294
295 $this->add_group_control(
296 Group_Control_Typography::get_type(),
297 [
298 'name' => 'desc_typo',
299 'selector' => '{{WRAPPER}} .bbpc-hc-desc',
300 ]
301 );
302
303 $this->add_control(
304 'desc_color',
305 [
306 'label' => esc_html__( 'Color', 'forumax' ),
307 'type' => Controls_Manager::COLOR,
308 'selectors' => [ '{{WRAPPER}} .bbpc-hc-desc' => 'color: {{VALUE}};' ],
309 ]
310 );
311
312 // Article Count.
313 $this->add_control(
314 'count_head',
315 [
316 'label' => esc_html__( 'Article Count', 'forumax' ),
317 'type' => Controls_Manager::HEADING,
318 'separator' => 'before',
319 ]
320 );
321
322 $this->add_group_control(
323 Group_Control_Typography::get_type(),
324 [
325 'name' => 'count_typo',
326 'selector' => '{{WRAPPER}} .bbpc-hc-count',
327 ]
328 );
329
330 $this->add_control(
331 'count_color',
332 [
333 'label' => esc_html__( 'Color', 'forumax' ),
334 'type' => Controls_Manager::COLOR,
335 'selectors' => [ '{{WRAPPER}} .bbpc-hc-count' => 'color: {{VALUE}};' ],
336 ]
337 );
338
339 $this->add_control(
340 'count_singular',
341 [
342 'label' => esc_html__( 'Singular Label', 'forumax' ),
343 'description' => esc_html__( 'Shown when count is 1, e.g. "article"', 'forumax' ),
344 'type' => Controls_Manager::TEXT,
345 'label_block' => true,
346 'default' => 'article',
347 'separator' => 'before',
348 'condition' => [
349 'style' => '3',
350 ],
351 ]
352 );
353
354 $this->add_control(
355 'count_plural',
356 [
357 'label' => esc_html__( 'Plural Label', 'forumax' ),
358 'description' => esc_html__( 'Shown when count is 0 or more than 1, e.g. "articles"', 'forumax' ),
359 'type' => Controls_Manager::TEXT,
360 'label_block' => true,
361 'default' => 'articles',
362 'condition' => [
363 'style' => '3',
364 ],
365 ]
366 );
367
368 $this->end_controls_section();
369
370 // ── Help Center: Background ──────────────────────────────────────────────
371 // Group 2 — Background, border, shadow and spacing for card & grid.
372 $this->start_controls_section(
373 'style_background',
374 [
375 'label' => esc_html__( 'Background', 'forumax' ),
376 'tab' => Controls_Manager::TAB_STYLE,
377 'condition' => [
378 'style' => '3'
379 ],
380 ]
381 );
382
383 // Card.
384 $this->add_control(
385 'card_head',
386 [
387 'label' => esc_html__( 'Card', 'forumax' ),
388 'type' => Controls_Manager::HEADING,
389 ]
390 );
391
392 $this->start_controls_tabs( 'card_bg_tabs' );
393
394 $this->start_controls_tab(
395 'card_bg_normal',
396 [ 'label' => esc_html__( 'Normal', 'forumax' ) ]
397 );
398
399 $this->add_group_control(
400 Group_Control_Background::get_type(),
401 [
402 'name' => 'card_bg',
403 'types' => [ 'classic', 'gradient' ],
404 'selector' => '{{WRAPPER}} .bbpc-hc-card',
405 ]
406 );
407
408 $this->end_controls_tab();
409
410 $this->start_controls_tab(
411 'card_bg_hover',
412 [ 'label' => esc_html__( 'Hover', 'forumax' ) ]
413 );
414
415 $this->add_group_control(
416 Group_Control_Background::get_type(),
417 [
418 'name' => 'card_bg_hover',
419 'types' => [ 'classic', 'gradient' ],
420 'selector' => '{{WRAPPER}} .bbpc-hc-card:hover',
421 ]
422 );
423
424 $this->end_controls_tab();
425
426 $this->end_controls_tabs();
427
428 $this->add_group_control(
429 Group_Control_Border::get_type(),
430 [
431 'name' => 'card_border',
432 'selector' => '{{WRAPPER}} .bbpc-hc-card',
433 'separator' => 'before',
434 ]
435 );
436
437 $this->add_control(
438 'card_radius',
439 [
440 'label' => esc_html__( 'Border Radius', 'forumax' ),
441 'type' => Controls_Manager::DIMENSIONS,
442 'size_units' => [ 'px', '%', 'em' ],
443 'selectors' => [
444 '{{WRAPPER}} .bbpc-hc-card' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
445 ],
446 ]
447 );
448
449 $this->add_group_control(
450 Group_Control_Box_Shadow::get_type(),
451 [
452 'name' => 'card_shadow',
453 'selector' => '{{WRAPPER}} .bbpc-hc-card',
454 ]
455 );
456
457 $this->add_control(
458 'item_padding',
459 [
460 'label' => esc_html__( 'Padding', 'forumax' ),
461 'type' => Controls_Manager::DIMENSIONS,
462 'size_units' => [ 'px', 'em', '%' ],
463 'selectors' => [
464 '{{WRAPPER}} .bbpc-hc-card' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
465 ],
466 ]
467 );
468
469 // Grid.
470 $this->add_control(
471 'grid_head_option',
472 [
473 'label' => esc_html__( 'Grid', 'forumax' ),
474 'type' => Controls_Manager::HEADING,
475 'separator' => 'before',
476 ]
477 );
478
479 $this->add_control(
480 'grid_gap_color',
481 [
482 'label' => esc_html__( 'Gap Color', 'forumax' ),
483 'description' => esc_html__( 'Color of the divider lines between cards.', 'forumax' ),
484 'type' => Controls_Manager::COLOR,
485 'selectors' => [ '{{WRAPPER}} .bbpc-hc-grid' => 'background-color: {{VALUE}};' ],
486 ]
487 );
488
489 $this->add_group_control(
490 Group_Control_Box_Shadow::get_type(),
491 [
492 'name' => 'grid_box_shadow',
493 'selector' => '{{WRAPPER}} .bbpc-hc-grid',
494 ]
495 );
496
497 $this->end_controls_section();
498 }
499
500 /**
501 * Render widget output.
502 *
503 * @return void
504 */
505 protected function render()
506 {
507 $settings = $this->get_settings();
508
509 $forums = new WP_Query(
510 [
511 'post_type' => 'forum',
512 'posts_per_page' => !empty($settings['ppp']) ? $settings['ppp'] : 5,
513 'order' => $settings['order'],
514 ]
515 );
516 // Whitelist valid style values to prevent Local File Inclusion.
517 $allowed_styles = ['1', '2', '3'];
518 $style = isset($settings['style']) && in_array($settings['style'], $allowed_styles, true) ? $settings['style'] : '1';
519 // File Include.
520 include __DIR__ . "/inc/forums/forums-{$style}.php";
521 }
522 }
523