PluginProbe
Download Manager Addons for Elementor / trunk
Download Manager Addons for Elementor vtrunk
trunk 1.0.5 1.2.3 1.2.5 1.3.0
wpdm-elementor / src / widgets / CategoryWidget.php

CategoryWidget.php in Download Manager Addons for Elementor trunk, at src/widgets/CategoryWidget.php

251 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDM\Elementor\Widgets;
4
5 /**
6 * Category Widget.
7 * Displays packages filtered by category.
8 */
9 class CategoryWidget extends BaseWidget
10 {
11 /**
12 * Expected settings keys for this widget.
13 */
14 private const SETTINGS_KEYS = [
15 'catid', 'operator', 'title', 'desc', 'items_per_page',
16 'orderby', 'order', 'template', 'author',
17 'cols', 'colspad', 'colsphone', 'toolbar', 'paging'
18 ];
19
20 /**
21 * Settings sanitization rules.
22 */
23 private const SANITIZERS = [
24 'operator' => 'text',
25 'title' => 'text',
26 'desc' => 'text',
27 'items_per_page' => 'int',
28 'orderby' => 'orderby',
29 'order' => 'order',
30 'template' => 'text',
31 'author' => 'text',
32 'cols' => 'int',
33 'colspad' => 'int',
34 'colsphone' => 'int',
35 'toolbar' => 'text',
36 'paging' => 'text',
37 ];
38
39 public function get_name()
40 {
41 return 'wpdmcategory';
42 }
43
44 public function get_title()
45 {
46 return __('Packages By Category', WPDM_ELEMENTOR);
47 }
48
49 public function get_icon()
50 {
51 return 'eicon-theme-builder';
52 }
53
54 protected function register_controls()
55 {
56 $this->start_controls_section(
57 'content_section',
58 [
59 'label' => __('Parameters', WPDM_ELEMENTOR),
60 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
61 ]
62 );
63
64 $this->add_control(
65 'catid',
66 [
67 'label' => __('Include Categories', WPDM_ELEMENTOR),
68 'type' => \Elementor\Controls_Manager::SELECT2,
69 'multiple' => true,
70 'options' => $this->getCategoryOptions(),
71 'default' => []
72 ]
73 );
74
75 $this->add_control(
76 'operator',
77 [
78 'label' => __('Operator', WPDM_ELEMENTOR),
79 'type' => \Elementor\Controls_Manager::SELECT2,
80 'options' => [
81 'IN' => 'IN',
82 'NOT IN' => 'NOT IN',
83 'AND' => 'AND',
84 'EXISTS' => 'EXISTS',
85 'NOT EXISTS' => 'NOT EXISTS'
86 ],
87 'default' => 'IN',
88 'description' => __('Use this parameter only when using multiple categories.', WPDM_ELEMENTOR)
89 ]
90 );
91
92 $this->add_control(
93 'title',
94 [
95 'label' => __('Title', WPDM_ELEMENTOR),
96 'type' => \Elementor\Controls_Manager::TEXT,
97 'input_type' => 'text',
98 'description' => __('Use "1" to show category title, or enter custom text', WPDM_ELEMENTOR),
99 'default' => '1'
100 ]
101 );
102
103 $this->add_control(
104 'desc',
105 [
106 'label' => __('Description', WPDM_ELEMENTOR),
107 'type' => \Elementor\Controls_Manager::TEXT,
108 'input_type' => 'text',
109 'description' => __('Use "1" to show category description, or enter custom text', WPDM_ELEMENTOR),
110 'default' => '1'
111 ]
112 );
113
114 $this->add_control(
115 'items_per_page',
116 [
117 'label' => __('Items Per Page', WPDM_ELEMENTOR),
118 'type' => \Elementor\Controls_Manager::NUMBER,
119 'min' => 1,
120 'max' => 100,
121 'default' => 10
122 ]
123 );
124
125 $this->add_control(
126 'orderby',
127 [
128 'label' => __('Order By', WPDM_ELEMENTOR),
129 'type' => \Elementor\Controls_Manager::SELECT2,
130 'options' => ['date' => __('Date', WPDM_ELEMENTOR), 'title' => __('Title', WPDM_ELEMENTOR)],
131 'default' => 'date',
132 ]
133 );
134
135 $this->add_control(
136 'order',
137 [
138 'label' => __('Order', WPDM_ELEMENTOR),
139 'type' => \Elementor\Controls_Manager::CHOOSE,
140 'options' => [
141 'ASC' => ['title' => __('Ascending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-up'],
142 'DESC' => ['title' => __('Descending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-down']
143 ],
144 'default' => 'DESC',
145 'toggle' => false
146 ]
147 );
148
149 $this->add_control(
150 'template',
151 [
152 'label' => __('Link Template', WPDM_ELEMENTOR),
153 'type' => \Elementor\Controls_Manager::SELECT2,
154 'options' => $this->getLinkTemplateOptions(),
155 'default' => 'link-template-default'
156 ]
157 );
158
159 $this->add_control(
160 'author',
161 [
162 'label' => __('Authors', WPDM_ELEMENTOR),
163 'type' => \Elementor\Controls_Manager::TEXT,
164 'input_type' => 'text',
165 'placeholder' => __('e.g: 1, 2, 3', WPDM_ELEMENTOR),
166 'description' => __('Author IDs separated by comma', WPDM_ELEMENTOR)
167 ]
168 );
169
170 $this->add_control(
171 'cols',
172 [
173 'label' => __('Columns (Desktop)', WPDM_ELEMENTOR),
174 'type' => \Elementor\Controls_Manager::NUMBER,
175 'min' => 1,
176 'max' => 6,
177 'default' => 3
178 ]
179 );
180
181 $this->add_control(
182 'colspad',
183 [
184 'label' => __('Columns (Tablet)', WPDM_ELEMENTOR),
185 'type' => \Elementor\Controls_Manager::NUMBER,
186 'min' => 1,
187 'max' => 4,
188 'default' => 2
189 ]
190 );
191
192 $this->add_control(
193 'colsphone',
194 [
195 'label' => __('Columns (Phone)', WPDM_ELEMENTOR),
196 'type' => \Elementor\Controls_Manager::NUMBER,
197 'min' => 1,
198 'max' => 2,
199 'default' => 1
200 ]
201 );
202
203 $this->add_control(
204 'toolbar',
205 [
206 'label' => __('Show Toolbar', WPDM_ELEMENTOR),
207 'type' => \Elementor\Controls_Manager::CHOOSE,
208 'options' => [
209 '1' => ['title' => __('Show', WPDM_ELEMENTOR), 'icon' => 'eicon-check'],
210 '0' => ['title' => __('Hide', WPDM_ELEMENTOR), 'icon' => 'eicon-close']
211 ],
212 'default' => '1',
213 ]
214 );
215
216 $this->add_control(
217 'paging',
218 [
219 'label' => __('Pagination', WPDM_ELEMENTOR),
220 'type' => \Elementor\Controls_Manager::CHOOSE,
221 'options' => [
222 '1' => ['title' => __('Show', WPDM_ELEMENTOR), 'icon' => 'eicon-check'],
223 '0' => ['title' => __('Hide', WPDM_ELEMENTOR), 'icon' => 'eicon-close']
224 ],
225 'default' => '0',
226 ]
227 );
228
229 $this->end_controls_section();
230 }
231
232 protected function render()
233 {
234 $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
235 $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
236
237 if (empty($settings['catid'])) {
238 return;
239 }
240
241 // Convert catid array to comma-separated id
242 $settings['id'] = is_array($settings['catid'])
243 ? implode(',', array_map('sanitize_text_field', $settings['catid']))
244 : sanitize_text_field($settings['catid']);
245
246 unset($settings['catid']);
247
248 echo WPDM()->categories->shortcode->listPackages($settings);
249 }
250 }
251