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

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

134 lines 3.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 * Direct Link Widget.
7 * Creates a direct download link for a package.
8 */
9 class DirectLinkWidget extends BaseWidget
10 {
11 /**
12 * Expected settings keys for this widget.
13 */
14 private const SETTINGS_KEYS = ['pid', 'target', 'label', 'class', 'eid', 'style'];
15
16 /**
17 * Settings sanitization rules.
18 */
19 private const SANITIZERS = [
20 'pid' => 'int',
21 'target' => 'text',
22 'label' => 'text',
23 'class' => 'css_class',
24 'eid' => 'text',
25 'style' => 'css_style',
26 ];
27
28 public function get_name()
29 {
30 return 'wpdmdirectlink';
31 }
32
33 public function get_title()
34 {
35 return __('Direct download link', WPDM_ELEMENTOR);
36 }
37
38 public function get_icon()
39 {
40 return 'eicon-editor-link';
41 }
42
43 protected function register_controls()
44 {
45 $this->start_controls_section(
46 'content_section',
47 [
48 'label' => __('Parameters', WPDM_ELEMENTOR),
49 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
50 ]
51 );
52
53 $this->add_control(
54 'pid',
55 [
56 'label' => __('Package', WPDM_ELEMENTOR),
57 'type' => \Elementor\Controls_Manager::SELECT2,
58 'placeholder' => __('Package', WPDM_ELEMENTOR),
59 'select2options' => $this->getPackageSearchConfig()
60 ]
61 );
62
63 $this->add_control(
64 'target',
65 [
66 'label' => __('Link Target', WPDM_ELEMENTOR),
67 'type' => \Elementor\Controls_Manager::SELECT2,
68 'options' => ['_blank' => '_blank', '_self' => '_self'],
69 'default' => '_blank'
70 ]
71 );
72
73 $this->add_control(
74 'label',
75 [
76 'label' => __('Download link label', WPDM_ELEMENTOR),
77 'type' => \Elementor\Controls_Manager::TEXT,
78 'input_type' => 'text',
79 'default' => 'Download',
80 'placeholder' => __('Download', WPDM_ELEMENTOR),
81 ]
82 );
83
84 $this->add_control(
85 'class',
86 [
87 'label' => __('CSS class name', WPDM_ELEMENTOR),
88 'type' => \Elementor\Controls_Manager::TEXT,
89 'input_type' => 'text',
90 ]
91 );
92
93 $this->add_control(
94 'eid',
95 [
96 'label' => __('HTML element ID', WPDM_ELEMENTOR),
97 'type' => \Elementor\Controls_Manager::TEXT,
98 'input_type' => 'text',
99 ]
100 );
101
102 $this->add_control(
103 'style',
104 [
105 'label' => __('CSS Style', WPDM_ELEMENTOR),
106 'type' => \Elementor\Controls_Manager::TEXTAREA,
107 'rows' => 5,
108 'placeholder' => __('e.g., color: #3399ff;', WPDM_ELEMENTOR),
109 ]
110 );
111
112 $this->end_controls_section();
113 }
114
115 protected function render()
116 {
117 $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
118 $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
119
120 if (empty($settings['pid'])) {
121 return;
122 }
123
124 // Map pid to id for WPDM shortcode
125 $settings['id'] = $settings['pid'];
126 unset($settings['pid']);
127
128 echo $this->wrapOutput(
129 WPDM()->package->shortCodes->directLink($settings),
130 'direct-link-widget'
131 );
132 }
133 }
134