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_Topics.php

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

327 lines 7.0 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\Widget_Base;
5 use Elementor\Controls_Manager;
6 use Elementor\Group_Control_Typography;
7 use Elementor\Group_Control_Text_Shadow;
8 use WP_Query;
9 use WP_Post;
10
11 // Exit if accessed directly
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * Class Forumax_Topics
18 *
19 * Forum topics widget from Docy theme
20 *
21 * @package admin\Elementor
22 */
23 class Forumax_Topics extends Widget_Base {
24
25 /**
26 * Get widget name.
27 *
28 * @since 1.0.0
29 * @return string Widget name.
30 */
31 public function get_name() {
32 $theme = wp_get_theme();
33 $theme_name = strtolower( $theme->get( 'Name' ) );
34
35 if ( 'docy' === $theme_name ) {
36 return 'docy_forum_topics';
37 } elseif ( 'docly' === $theme_name ) {
38 return 'Docly_forum_posts';
39 }
40
41 return 'ama_forum_posts';
42 }
43
44 /**
45 * Get widget title.
46 *
47 * @since 1.0.0
48 * @return string Widget title.
49 */
50 public function get_title() {
51 return __( 'Topics Forum (Forumax)', 'forumax' );
52 }
53
54 /**
55 * Get widget icon.
56 *
57 * @since 1.0.0
58 * @return string Widget icon.
59 */
60 public function get_icon() {
61 return 'eicon-post-list';
62 }
63
64 /**
65 * Get style dependencies.
66 *
67 * @since 1.0.0
68 * @return array Style dependencies.
69 */
70 public function get_style_depends() {
71 return array( 'bbpc-el-widgets' );
72 }
73
74 /**
75 * Get widget keywords.
76 *
77 * @since 1.0.0
78 * @return array Widget keywords.
79 */
80 public function get_keywords() {
81 return array( 'topics', 'replies' );
82 }
83
84 /**
85 * Get widget categories.
86 *
87 * @since 1.0.0
88 * @return array Widget categories.
89 */
90 public function get_categories() {
91 return array( 'forumax' );
92 }
93
94 /**
95 * Register widget controls.
96 *
97 * @since 1.0.0
98 * @return void
99 */
100 protected function register_controls() {
101
102 // Preset Skins Section
103 $this->start_controls_section(
104 'style_sec',
105 array(
106 'label' => esc_html__( 'Preset Skins', 'forumax' ),
107 )
108 );
109
110 $this->add_control(
111 'style',
112 array(
113 'label' => esc_html__( 'Skin', 'forumax' ),
114 'type' => Controls_Manager::VISUAL_CHOICE,
115 'options' => array(
116 '1' => array(
117 'image' => FORUMAX_ASSETS . '/admin/images/skins/topic1.jpg',
118 'title' => esc_html__( 'List', 'forumax' ),
119 ),
120 '2' => array(
121 'image' => FORUMAX_ASSETS . '/admin/images/skins/topic2.jpg',
122 'title' => esc_html__( 'List with excerpt', 'forumax' ),
123 ),
124 ),
125 'default' => '1',
126 'toggle' => false,
127 )
128 );
129
130 $this->end_controls_section();
131
132 // Filter Options Section
133 $this->start_controls_section(
134 'filter_opt',
135 array(
136 'label' => __( 'Filter Options', 'forumax' ),
137 )
138 );
139
140 $this->add_control(
141 'ppp',
142 array(
143 'label' => esc_html__( 'Show Topics', 'forumax' ),
144 'type' => Controls_Manager::NUMBER,
145 'label_block' => true,
146 'default' => 5,
147 )
148 );
149
150 $this->add_control(
151 'author_avatar_count',
152 array(
153 'label' => esc_html__( 'Author Avatars', 'forumax' ),
154 'type' => Controls_Manager::NUMBER,
155 'label_block' => true,
156 'default' => 2,
157 'condition' => array(
158 'style' => array( '2' ),
159 ),
160 )
161 );
162
163 $this->add_control(
164 'excerpt_length',
165 array(
166 'label' => esc_html__( 'Excerpt Length', 'forumax' ),
167 'description' => esc_html__( 'Enter the excerpt length in words count.', 'forumax' ),
168 'type' => Controls_Manager::NUMBER,
169 'label_block' => true,
170 'default' => 12,
171 'condition' => array(
172 'style' => array( '2' ),
173 ),
174 )
175 );
176
177 $this->add_control(
178 'order',
179 array(
180 'label' => esc_html__( 'Order', 'forumax' ),
181 'type' => Controls_Manager::SELECT,
182 'options' => array(
183 'ASC' => 'ASC',
184 'DESC' => 'DESC',
185 ),
186 'default' => 'ASC',
187 )
188 );
189
190 $this->end_controls_section();
191
192 // Bottom Content Section
193 $this->start_controls_section(
194 'btm_content_sec',
195 array(
196 'label' => __( 'Bottom Content', 'forumax' ),
197 )
198 );
199
200 $this->add_control(
201 'btm_content',
202 array(
203 'label' => esc_html__( 'Bottom Text', 'forumax' ),
204 'type' => Controls_Manager::WYSIWYG,
205 )
206 );
207
208 $this->end_controls_section();
209
210 // Style Items Section
211 $this->start_controls_section(
212 'style_items',
213 array(
214 'label' => __( 'Style Items', 'forumax' ),
215 'tab' => Controls_Manager::TAB_STYLE,
216 )
217 );
218
219 $this->add_control(
220 'spacing-item',
221 array(
222 'label' => __( 'Spacing', 'forumax' ),
223 'description' => __( 'Spacing between the topic items', 'forumax' ),
224 'type' => Controls_Manager::SLIDER,
225 'range' => array(
226 'px' => array(
227 'min' => 0,
228 'max' => 100,
229 ),
230 ),
231 'selectors' => array(
232 '{{WRAPPER}} .topic-item' => 'margin-bottom: {{SIZE}}{{UNIT}};',
233 ),
234 )
235 );
236
237 $this->add_responsive_control(
238 'padding-item',
239 array(
240 'label' => __( 'Padding', 'elementor' ),
241 'type' => Controls_Manager::DIMENSIONS,
242 'size_units' => array( 'px', 'em', '%' ),
243 'selectors' => array(
244 '{{WRAPPER}} .topic-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
245 ),
246 )
247 );
248
249 $this->end_controls_section();
250
251 // Style Section
252 $this->start_controls_section(
253 'style_shapes',
254 array(
255 'label' => __( 'Style Section', 'forumax' ),
256 'tab' => Controls_Manager::TAB_STYLE,
257 )
258 );
259
260 $this->add_control(
261 'shape1',
262 array(
263 'label' => esc_html__( 'Shape 01', 'forumax' ),
264 'type' => Controls_Manager::MEDIA,
265 'default' => array(
266 'url' => plugins_url( 'inc/forum-topics/images/community_bg_shap_one.png', __FILE__ ),
267 ),
268 'condition' => array(
269 'style' => array( '2' ),
270 ),
271 )
272 );
273
274 $this->add_control(
275 'shape2',
276 array(
277 'label' => esc_html__( 'Shape 02', 'forumax' ),
278 'type' => Controls_Manager::MEDIA,
279 'default' => array(
280 'url' => plugins_url( 'inc/forum-topics/images/community_bg_shap_two.png', __FILE__ ),
281 ),
282 'condition' => array(
283 'style' => array( '2' ),
284 ),
285 )
286 );
287
288 $this->add_responsive_control(
289 'padding_sec',
290 array(
291 'label' => __( 'Section Padding', 'elementor' ),
292 'type' => Controls_Manager::DIMENSIONS,
293 'size_units' => array( 'px', 'em', '%' ),
294 'selectors' => array(
295 '{{WRAPPER}} .bew-topics' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
296 ),
297 )
298 );
299
300 $this->end_controls_section();
301 }
302
303 /**
304 * Render widget output on the frontend.
305 *
306 * @since 1.0.0
307 * @return void
308 */
309 protected function render() {
310 $settings = $this->get_settings();
311
312 $forum_posts = new WP_Query(
313 array(
314 'post_type' => 'topic',
315 'posts_per_page' => ! empty( $settings['ppp'] ) ? $settings['ppp'] : -1,
316 'order' => $settings['order'],
317 )
318 );
319
320 // Whitelist valid style values to prevent Local File Inclusion
321 $allowed_styles = array( '1', '2' );
322 $style = isset( $settings['style'] ) && in_array( $settings['style'], $allowed_styles, true ) ? $settings['style'] : '1';
323
324 include __DIR__ . "/inc/forum-topics/forum-topics-{$style}.php";
325 }
326 }
327