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 / Single_forum.php

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

246 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace admin\Elementor;
3
4 use Elementor\Controls_Manager;
5 use Elementor\Group_Control_Border;
6 use Elementor\Group_Control_Typography;
7 use Elementor\Widget_Base;
8 use WP_Query;
9
10 // Exit if accessed directly
11 if (!defined('ABSPATH')) {
12 exit;
13 }
14
15 class Single_forum extends Widget_Base {
16
17 public function get_name() {
18 // return 'forumax_docy_single_forum';
19 $theme = wp_get_theme();
20 $theme_name = strtolower($theme->get('Name'));
21 if ($theme_name == 'docy') {
22 return 'docy_single_forum';
23 }
24 return 'ama_single_forum';
25 }
26
27 public function get_title ()
28 {
29 return __('Single Forum (Forumax)', 'forumax');
30 }
31
32 public function get_icon ()
33 {
34 return 'bbpc_icon_ama_single_forum eicon-folder-o';
35 }
36
37 public function get_categories ()
38 {
39 return [ 'forumax' ];
40 }
41
42 public function get_style_depends ()
43 {
44 return [ 'bbpc-el-widgets' ];
45 }
46
47 protected function register_controls ()
48 {
49
50 //-------- Select Style ---------- //
51 $this->start_controls_section(
52 'style_sec',
53 [
54 'label' => esc_html__('Preset Skins', 'forumax'),
55 ]
56 );
57
58 $this->add_control(
59 'forum_id', [
60 'label' => esc_html__('Select Forum', 'forumax'),
61 'type' => Controls_Manager::SELECT,
62 'options' => forumax_get_posts('forum')
63 ]
64 );
65
66 $this->add_control(
67 'style',
68 [
69 'label' => esc_html__('Forums Style', 'forumax'),
70 'type' => Controls_Manager::VISUAL_CHOICE,
71 'options' => [
72 '1' => [
73 'image' => FORUMAX_IMG . 'forums3.jpg',
74 'title' => esc_html__('01 : Single Forum With Topics', 'forumax'),
75 ],
76 '2' => [
77 'image' => FORUMAX_IMG . 'forums4.png',
78 'title' => esc_html__('02 : Single Forum', 'forumax'),
79 ],
80 ],
81 'default' => '1',
82 'toggle' => false,
83 'label_block' => true,
84 'separator' => 'before'
85 ]
86 );
87
88 $this->end_controls_section(); // End Style
89
90
91 $this->start_controls_section(
92 'forum_thumb', [
93 'label' => __('Thumbnail', 'forumax'),
94 ]
95 );
96
97 $this->add_control(
98 'cover_image', [
99 'label' => __('Custom Cover Image', 'forumax'),
100 'type' => Controls_Manager::MEDIA,
101 'description' => __('If this is not set, the featured image will be used by default', 'forumax')
102 ]
103 );
104
105 $this->end_controls_section();
106
107 // --- Filter Options
108 $this->start_controls_section(
109 'filter_opt', [
110 'label' => __('Filter Options', 'forumax'),
111 ]
112 );
113
114 $this->add_control(
115 'ppp', [
116 'label' => esc_html__('Topics', 'forumax'),
117 'description' => esc_html__('Maximum number of topics.', 'forumax'),
118 'type' => Controls_Manager::NUMBER,
119 'default' => 3
120 ]
121 );
122
123 $this->add_control(
124 'order', [
125 'label' => esc_html__('Order', 'forumax'),
126 'type' => Controls_Manager::SELECT,
127 'options' => [
128 'ASC' => 'ASC',
129 'DESC' => 'DESC'
130 ],
131 'default' => 'ASC'
132 ]
133 );
134
135 $this->add_control(
136 'word_length',
137 [
138 'label' => __('Number of Words', 'forumax'),
139 'type' => Controls_Manager::NUMBER,
140 'description' => __('Number of words to show as forum content', 'forumax'),
141 'default' => 12
142 ]
143 );
144
145 $this->add_control(
146 'read_more',
147 [
148 'label' => esc_html__('Read More Text', 'forumax'),
149 'type' => Controls_Manager::TEXT,
150 'label_block' => true,
151 'default' => __('View All', 'forumax'),
152 ]
153 );
154
155 $this->end_controls_section();
156
157 /**============== Background shape Image =====================**/
158 $this->start_controls_section(
159 'single_forum_style', [
160 'label' => __('Single Forum Style', 'forumax'),
161 'tab' => Controls_Manager::TAB_STYLE,
162 ]
163 );
164
165 $this->add_group_control(
166 Group_Control_Border::get_type(),
167 [
168 'name' => 'border',
169 'selector' => '{{WRAPPER}} .forum-card, {{WRAPPER}} .forum-with-topics .topic-table .topic-heading, {{WRAPPER}} .forum-with-topics .topic-table .topic-contents',
170 ]
171 );
172
173 $this->add_group_control(
174 Group_Control_Typography::get_type(),
175 [
176 'name' => 'title_typography',
177 'label' => __('Title Typography', 'forumax'),
178 'separator' => 'before',
179 'selector' => '{{WRAPPER}} .forum-with-topics .topic-table .topic-contents .title h3, {{WRAPPER}} .forum-card .card-title h3',
180 ]
181 );
182
183 $this->add_control(
184 'title_color',
185 [
186 'label' => __('Title Color', 'forumax'),
187 'type' => Controls_Manager::COLOR,
188 'separator' => 'after',
189 'selectors' => [
190 '{{WRAPPER}} .forum-with-topics .topic-table .topic-contents .title h3' => 'color: {{VALUE}}',
191 '{{WRAPPER}} .forum-card .card-title h3' => 'color: {{VALUE}}'
192 ],
193 ]
194 );
195
196 $this->add_group_control(
197 Group_Control_Typography::get_type(),
198 [
199 'name' => 'excerpt_typography',
200 'label' => __('Excerpt Typography', 'forumax'),
201 'selector' => '{{WRAPPER}} .forum-with-topics .topic-table .topic-contents .title p, {{WRAPPER}} .forum-card .card-body',
202 ]
203 );
204
205 $this->add_control(
206 'excerpt_color',
207 [
208 'label' => __('Excerpt Color', 'forumax'),
209 'type' => Controls_Manager::COLOR,
210 'selectors' => [
211 '{{WRAPPER}} .forum-with-topics .topic-table .topic-contents .title p' => 'color: {{VALUE}}',
212 '{{WRAPPER}} .forum-card .card-body' => 'color: {{VALUE}}'
213 ],
214 ]
215 );
216
217 $this->end_controls_section();
218 }
219
220 protected function render (): void
221 {
222 $settings = $this->get_settings();
223 $forum_id = !empty($settings[ 'forum_id' ]) ? $settings[ 'forum_id' ] : '';
224 $cover_image = $settings[ 'cover_image' ];
225 $post_thumbnail_url = !empty($cover_image[ 'url' ]) ? $cover_image[ 'url' ] : get_the_post_thumbnail_url($forum_id);
226
227 $topics = new WP_Query(array(
228 'post_type' => bbp_get_topic_post_type(),
229 'order' => !empty($settings['order']) ? $settings['order'] : 'DESC',
230 'posts_per_page' => !empty($settings['ppp']) ? $settings['ppp'] : 3,
231 'post_parent' => $forum_id,
232 ));
233
234 if ($forum_id) {
235 // Whitelist valid style values to prevent Local File Inclusion
236 $allowed_styles = array( '1', '2' );
237 $style = isset( $settings['style'] ) && in_array( $settings['style'], $allowed_styles, true ) ? $settings['style'] : '1';
238 include __DIR__ . "/inc/single-forum/single-forum-{$style}.php";
239 } else { ?>
240 <div class="alert alert-warning" role="alert">
241 <?php esc_html_e('Please select a forum.', 'forumax'); ?>
242 </div>
243 <?php
244 }
245 }
246 }