PluginProbe
WP Directory Kit / 1.2.3
WP Directory Kit v1.2.3
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 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.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
wpdirectorykit / elementor-elements / classes / wdk-locations-list.php

wdk-locations-list.php in WP Directory Kit 1.2.3, at elementor-elements/classes/wdk-locations-list.php

561 lines 20.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Wdk\Elementor\Widgets;
4
5 use Wdk\Elementor\Widgets\WdkElementorBase;
6 use Elementor\Widget_Base;
7 use Elementor\Controls_Manager;
8 use Elementor\Utils;
9 use Elementor\Typography;
10 use Elementor\Editor;
11 use Elementor\Plugin;
12 use Elementor\Repeater;
13 use Elementor\Core\Schemes;
14 use Elementor\Icons_Manager;
15 use Elementor\Group_Control_Typography;
16 use Elementor\Group_Control_Border;
17 use Elementor\Group_Control_Box_Shadow;
18
19 if (!defined('ABSPATH'))
20 exit; // Exit if accessed directly
21
22 /**
23 * @since 1.1.0
24 */
25 class WdkLocationsList extends WdkElementorBase {
26
27 public function __construct($data = array(), $args = null) {
28
29 \Elementor\Controls_Manager::add_tab(
30 'tab_conf',
31 esc_html__('Settings', 'wpdirectorykit')
32 );
33
34 \Elementor\Controls_Manager::add_tab(
35 'tab_layout',
36 esc_html__('Layout', 'wpdirectorykit')
37 );
38
39 \Elementor\Controls_Manager::add_tab(
40 'tab_content',
41 esc_html__('Main', 'wpdirectorykit')
42 );
43
44 if ($this->is_edit_mode_load()) {
45 $this->enqueue_styles_scripts();
46 }
47
48 parent::__construct($data, $args);
49 }
50
51 /**
52 * Retrieve the widget name.
53 *
54 * @since 1.1.0
55 *
56 * @access public
57 *
58 * @return string Widget name.
59 */
60 public function get_name() {
61 return 'wdk-locations-list';
62 }
63
64 /**
65 * Retrieve the widget title.
66 *
67 * @since 1.1.0
68 *
69 * @access public
70 *
71 * @return string Widget title.
72 */
73 public function get_title() {
74 return esc_html__('Wdk Location List', 'wpdirectorykit');
75 }
76
77 /**
78 * Retrieve the widget icon.
79 *
80 * @since 1.1.0
81 *
82 * @access public
83 *
84 * @return string Widget icon.
85 */
86 public function get_icon() {
87 return 'eicon-bullet-list';
88 }
89
90 /**
91 * Register the widget controls.
92 *
93 * Adds different input fields to allow the user to change and customize the widget settings.
94 *
95 * @since 1.1.0
96 *
97 * @access protected
98 */
99 protected function register_controls() {
100 $this->generate_controls_conf();
101 $this->generate_controls_layout();
102 $this->generate_controls_styles();
103 $this->generate_controls_content();
104
105 $this->insert_pro_message('1');
106 parent::register_controls();
107 }
108
109 /**
110 * Render the widget output on the frontend.
111 *
112 * Written in PHP and used to generate the final HTML.
113 *
114 * @since 1.1.0
115 *
116 * @access protected
117 */
118 protected function render() {
119 parent::render();
120 $this->data['id_element'] = $this->get_id();
121 $this->data['settings'] = $this->get_settings();
122
123 $controller = 'location';
124 $this->WMVC->model($controller.'_m');
125 $this->WMVC->model('listing_m');
126
127 $this->data['results'] = false;
128
129 if($this->data['settings']['conf_results_type'] == 'custom_locations') {
130
131 $locations_ids = array();
132 foreach($this->data['settings']['conf_custom_results'] as $location) {
133 if(isset($location['location_id']) && !empty($location['location_id'])) {
134 $locations_ids [] = $location['location_id'];
135 }
136 }
137
138 /* where in */
139 if(!empty($locations_ids)){
140
141 $this->WMVC->db->select($this->WMVC->{$controller.'_m'}->_table_name.'.*, COUNT('.$this->WMVC->listing_m->_table_name.'.post_id) AS listings_counter');
142 $this->WMVC->db->join($this->WMVC->listing_m->_table_name.' ON '.$this->WMVC->listing_m->_table_name.'.location_id = '.$this->WMVC->{$controller.'_m'}->_table_name.'.idlocation', TRUE, 'LEFT');
143 $this->WMVC->db->where($this->WMVC->{$controller.'_m'}->_table_name.'.idlocation IN(' . implode(',', $locations_ids) . ')', null, false);
144 $this->WMVC->db->order_by('FIELD('.$this->WMVC->{$controller.'_m'}->_table_name.'.idlocation, '. implode(',', $locations_ids) . ')');
145 $this->WMVC->db->group_by($this->WMVC->{$controller.'_m'}->_primary_key);
146
147 $this->data['results'] = $this->WMVC->{$controller.'_m'}->get();
148 }
149
150 } else {
151 $order_by = NULL;
152 if(!empty($this->data['settings']['conf_order_by']))
153 $order_by = $this->data['settings']['conf_order_by'].' '.$this->data['settings']['conf_order'];
154
155 $this->data['results'] = $this->WMVC->{$controller.'_m'}->get_pagination($this->data['settings']['conf_limit'], NULL, array(), $order_by);
156 }
157
158 $this->data['is_edit_mode']= false;
159 if(Plugin::$instance->editor->is_edit_mode())
160 $this->data['is_edit_mode']= true;
161
162 echo $this->view('wdk-locations-list', $this->data);
163 }
164
165
166 private function generate_controls_conf() {
167 $this->start_controls_section(
168 'tab_conf_main_section',
169 [
170 'label' => esc_html__('Main', 'wpdirectorykit'),
171 'tab' => '1',
172 ]
173 );
174
175 $pages = array('' => __('Not Selected', 'wpdirectorykit'));
176 foreach(get_pages(array('sort_column' => 'post_title')) as $page)
177 {
178 $pages[$page->ID] = $page->post_title.' #'.$page->ID;
179 }
180
181 $this->add_control(
182 'conf_link',
183 [
184 'label' => __( 'Open results on page', 'wpdirectorykit' ),
185 'type' => \Elementor\Controls_Manager::SELECT,
186 'default' => '',
187 'options' => $pages
188 ]
189 );
190
191 $this->add_control(
192 'conf_results_type',
193 [
194 'label' => __( 'Show type', 'wpdirectorykit' ),
195 'type' => \Elementor\Controls_Manager::SELECT,
196 'default' => 'results_locations',
197 'options' => [
198 'results_locations' => __( 'All Locations', 'wpdirectorykit' ),
199 'custom_locations' => __( 'Specific', 'wpdirectorykit' ),
200 ],
201 ]
202 );
203
204 $this->add_control(
205 'show_icon',
206 [
207 'label' => __( 'Enable Location Icons', 'wpdirectorykit' ),
208 'type' => \Elementor\Controls_Manager::SWITCHER,
209 'label_on' => __( 'On', 'wpdirectorykit' ),
210 'label_off' => __( 'Off', 'wpdirectorykit' ),
211 'return_value' => 'true',
212 'default' => '',
213 'separator' => 'after',
214 ]
215 );
216
217 $this->add_control(
218 'important_note',
219 [
220 'label' => '',
221 'type' => \Elementor\Controls_Manager::RAW_HTML,
222 'raw' => sprintf(__( 'Edit Locations <a href="%1$s" target="_blank"> open </a>', 'wpdirectorykit' ), admin_url('admin.php?page=wdk_location')),
223 'content_classes' => 'wdk_elementor_hint',
224 ]
225 );
226
227 $this->add_control(
228 'conf_limit',
229 [
230 'label' => __( 'Limit Locations', 'wpdirectorykit' ),
231 'type' => \Elementor\Controls_Manager::NUMBER,
232 'min' => 1,
233 'max' => 50,
234 'step' => 1,
235 'default' => 6,
236 'separator' => 'before',
237 'conditions' => [
238 'terms' => [
239 [
240 'name' => 'conf_results_type',
241 'operator' => '==',
242 'value' => 'results_locations',
243 ]
244 ],
245 ],
246 ]
247 );
248
249 $this->add_control(
250 'conf_order_by',
251 [
252 'label' => __('Order By Column', 'wpdirectorykit'),
253 'type' => Controls_Manager::SELECT,
254 'label_block' => true,
255 'options' => [
256 '' => __('None', 'wpdirectorykit'),
257 'location_title' => __('Title', 'wpdirectorykit'),
258 'idlocation' => __('Location id', 'wpdirectorykit'),
259 'order_index' => __('Order index', 'wpdirectorykit'),
260 'listings_counter' => __('Most Listings', 'wpdirectorykit'),
261 ],
262 'default' => 'order_index',
263 'conditions' => [
264 'terms' => [
265 [
266 'name' => 'conf_results_type',
267 'operator' => '==',
268 'value' => 'results_locations',
269 ]
270 ],
271 ],
272 ]
273 );
274
275 $this->add_control(
276 'conf_order',
277 [
278 'label' => __('Order', 'wpdirectorykit'),
279 'type' => Controls_Manager::SELECT,
280 'label_block' => true,
281 'options' => [
282 'asc' => __('Ascending', 'wpdirectorykit'),
283 'desc' => __('Descending', 'wpdirectorykit')
284 ],
285 'default' => 'desc',
286 'conditions' => [
287 'terms' => [
288 [
289 'name' => 'conf_results_type',
290 'operator' => '==',
291 'value' => 'results_locations',
292 ]
293 ],
294 ],
295 ]
296 );
297
298 if(true){
299 $repeater = new Repeater();
300 $repeater->start_controls_tabs( 'locations' );
301 $repeater->add_control(
302 'location_id',
303 [
304 'label' => __( 'ID Location', 'wpdirectorykit' ),
305 'type' => \Elementor\Controls_Manager::NUMBER,
306 'min' => 1,
307 'step' => 1,
308 ]
309 );
310 $repeater->end_controls_tabs();
311
312
313 $this->add_control(
314 'conf_custom_results',
315 [
316 'type' => Controls_Manager::REPEATER,
317 'fields' => $repeater->get_controls(),
318 'default' => [
319 ],
320 'title_field' => '{{{ location_id }}}',
321 'conditions' => [
322 'terms' => [
323 [
324 'name' => 'conf_results_type',
325 'operator' => '==',
326 'value' => 'custom_locations',
327 ]
328 ],
329 ],
330 ]
331 );
332
333 }
334
335 $this->end_controls_section();
336
337 }
338
339 private function generate_controls_layout() {
340 }
341
342 private function generate_controls_styles() {
343 $this->start_controls_section(
344 'sstyles_thmbn_section',
345 [
346 'label' => esc_html__('Main', 'wpdirectorykit'),
347 'tab' => Controls_Manager::TAB_STYLE,
348 ]
349 );
350
351 $this->add_responsive_control(
352 'row_gap',
353 [
354 'label' => esc_html__('Rows Gap', 'wpdirectorykit'),
355 'type' => Controls_Manager::SLIDER,
356 'default' => [
357 'size' => 10,
358 ],
359 'range' => [
360 'px' => [
361 'min' => 0,
362 'max' => 60,
363 ],
364 ],
365 'selectors' => [
366 '{{WRAPPER}} .wdk-locations .wdk-item' => 'margin-bottom: {{SIZE}}{{UNIT}};',
367 ],
368 ]
369 );
370
371 $this->end_controls_section();
372
373 $items = [
374 [
375 'key'=>'item_button',
376 'label'=> esc_html__('Item Box', 'wpdirectorykit'),
377 'selector'=>'.wdk-locations .wdk-link',
378 'selector_hover'=>'.wdk-locations .wdk-link%1$s',
379 'options'=>['color','background','border','border_radius','padding','shadow','transition'],
380 ],
381 [
382 'key'=>'item_icon',
383 'label'=> esc_html__('Item Icon', 'wpdirectorykit'),
384 'selector'=>'.wdk-locations .wdk-link i',
385 'selector_hover'=>'.wdk-locations .wdk-link%1$s i',
386 'options'=>['margin','color','background','border','border_radius','padding','shadow'],
387 ],
388 [
389 'key'=>'item_icon_tree',
390 'label'=> esc_html__('Item Icon', 'wpdirectorykit'),
391 'selector'=>'.wdk-locations .wdk-link .wdk-icon',
392 'selector_hover'=>'.wdk-locations .wdk-link%1$s .wdk-icon',
393 'options'=>['margin','background','border','border_radius','padding','shadow','transition','image_size_control', 'css_filters'],
394 ],
395 [
396 'key'=>'item_title',
397 'label'=> esc_html__('Item Title', 'wpdirectorykit'),
398 'selector'=>'.wdk-locations .wdk-link .wdk-title',
399 'selector_hover'=>'.wdk-locations .wdk-link%1$s .wdk-title',
400 'options'=>['margin','typo','color','background','border','border_radius','padding'],
401 ],
402 [
403 'key'=>'item_count',
404 'label'=> esc_html__('Item Count', 'wpdirectorykit'),
405 'selector'=>'.wdk-locations .wdk-link .wdk-count',
406 'selector_hover'=>'.wdk-locations .wdk-link%1$s .wdk-count',
407 'options'=>['margin','typo','color','background','border','border_radius','padding'],
408 ],
409 ];
410
411 foreach ($items as $item) {
412
413 if($item['key'] == 'item_icon_tree') {
414 $this->start_controls_section(
415 $item['key'].'_section',
416 [
417 'label' => $item['label'],
418 'tab' => Controls_Manager::TAB_STYLE,
419 'conditions' => [
420 'terms' => [
421 [
422 'name' => 'show_icon',
423 'operator' => '==',
424 'value' => 'true',
425 ]
426 ],
427 ],
428 ]
429 );
430 } elseif($item['key'] == 'item_icon') {
431 $this->start_controls_section(
432 $item['key'].'_section',
433 [
434 'label' => $item['label'],
435 'tab' => Controls_Manager::TAB_STYLE,
436 'conditions' => [
437 'terms' => [
438 [
439 'name' => 'show_icon',
440 'operator' => '!=',
441 'value' => 'true',
442 ]
443 ],
444 ],
445 ]
446 );
447 } else {
448 $this->start_controls_section(
449 $item['key'].'_section',
450 [
451 'label' => $item['label'],
452 'tab' => Controls_Manager::TAB_STYLE,
453 ]
454 );
455 }
456
457 $this->add_responsive_control(
458 $item['key'].'_hide',
459 [
460 'label' => esc_html__( 'Hide Element', 'wpdirectorykit' ),
461 'type' => Controls_Manager::SWITCHER,
462 'none' => esc_html__( 'Hide', 'wpdirectorykit' ),
463 'block' => esc_html__( 'Show', 'wpdirectorykit' ),
464 'return_value' => 'none',
465 'default' => '',
466 'selectors' => [
467 '{{WRAPPER}} '.$item['selector'] => 'display: {{VALUE}};',
468 ],
469 ]
470 );
471 $selectors = array(
472 'normal' => '{{WRAPPER}} '.$item['selector'],
473 'hover'=>'{{WRAPPER}} '.$item['selector_hover'],
474 );
475 $this->generate_renders_tabs($selectors, $item['key'].'_dynamic', $item['options']);
476
477 /* special for some elements */
478 if($item['key'] == 'item_icon') {
479 $this->add_control(
480 $item['key'].'_i',
481 [
482 'label' => esc_html__('Icon', 'wpdirectorykit'),
483 'type' => Controls_Manager::ICONS,
484 'label_block' => true,
485 'default' => [
486 'value' => 'fa fa-angle-right',
487 'library' => 'solid',
488 ],
489 ]
490 );
491 $this->add_responsive_control(
492 $item['key'].'_size',
493 [
494 'label' => __( 'Size', 'wpdirectorykit' ),
495 'type' => Controls_Manager::SLIDER,
496 'size_units' => [ 'px'],
497 'range' => [
498 'px' => [
499 'min' => 1,
500 'max' => 60,
501 'step' => 1,
502 ],
503 ],
504 'default' => [
505 'unit' => 'px',
506 'size' => 14,
507 ],
508 'selectors' => [
509 '{{WRAPPER}} '.$item['selector'] => 'font-size: {{SIZE}}{{UNIT}};',
510 ],
511 ]
512 );
513
514 }
515 if($item['key'] == 'item_count') {
516 $this->add_responsive_control(
517 $item['key'].'_align',
518 [
519 'label' => __( 'Position', 'wpdirectorykit' ),
520 'type' => Controls_Manager::CHOOSE,
521 'options' => [
522 'left' => [
523 'title' => esc_html__( 'Left', 'wpdirectorykit' ),
524 'icon' => 'eicon-text-align-left',
525 ],
526 'center' => [
527 'title' => esc_html__( 'Center', 'wpdirectorykit' ),
528 'icon' => 'eicon-text-align-center',
529 ],
530 'right' => [
531 'title' => esc_html__( 'Right', 'wpdirectorykit' ),
532 'icon' => 'eicon-text-align-right',
533 ],
534
535 ],
536 'render_type' => 'ui',
537 'selectors_dictionary' => [
538 'left' => 'text-align: left;',
539 'center' => 'text-alig: center;',
540 'right' => 'text-align: right;',
541 ],
542 'selectors' => [
543 '{{WRAPPER}} '.$item['selector'] => '{{VALUE}};',
544 ],
545 ]
546 );
547 }
548 $this->end_controls_section();
549 }
550 }
551
552 private function generate_controls_content() {
553
554 }
555
556 public function enqueue_styles_scripts() {
557 wp_enqueue_style('wdk-locations-list');
558
559 }
560 }
561