| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDM\Elementor\Widgets; |
| 4 |
|
| 5 |
/** |
| 6 |
* Tag Widget. |
| 7 |
* Displays packages filtered by tags. |
| 8 |
* Note: This widget is currently disabled in Main.php |
| 9 |
*/ |
| 10 |
class TagWidget extends BaseWidget |
| 11 |
{ |
| 12 |
/** |
| 13 |
* Expected settings keys for this widget. |
| 14 |
*/ |
| 15 |
private const SETTINGS_KEYS = [ |
| 16 |
'tagid', 'title', 'desc', 'items_per_page', |
| 17 |
'orderby', 'order', 'template', |
| 18 |
'cols', 'colspad', 'colsphone', 'toolbar' |
| 19 |
]; |
| 20 |
|
| 21 |
/** |
| 22 |
* Settings sanitization rules. |
| 23 |
*/ |
| 24 |
private const SANITIZERS = [ |
| 25 |
'title' => 'text', |
| 26 |
'desc' => 'text', |
| 27 |
'items_per_page' => 'int', |
| 28 |
'orderby' => 'orderby', |
| 29 |
'order' => 'order', |
| 30 |
'template' => 'text', |
| 31 |
'cols' => 'int', |
| 32 |
'colspad' => 'int', |
| 33 |
'colsphone' => 'int', |
| 34 |
'toolbar' => 'text', |
| 35 |
]; |
| 36 |
|
| 37 |
public function get_name() |
| 38 |
{ |
| 39 |
return 'wpdmtag'; |
| 40 |
} |
| 41 |
|
| 42 |
public function get_title() |
| 43 |
{ |
| 44 |
return __('Packages By Tags', WPDM_ELEMENTOR); |
| 45 |
} |
| 46 |
|
| 47 |
public function get_icon() |
| 48 |
{ |
| 49 |
return 'eicon-tags'; |
| 50 |
} |
| 51 |
|
| 52 |
protected function register_controls() |
| 53 |
{ |
| 54 |
$this->start_controls_section( |
| 55 |
'content_section', |
| 56 |
[ |
| 57 |
'label' => __('Parameters', WPDM_ELEMENTOR), |
| 58 |
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 59 |
] |
| 60 |
); |
| 61 |
|
| 62 |
$this->add_control( |
| 63 |
'tagid', |
| 64 |
[ |
| 65 |
'label' => __('Tags', WPDM_ELEMENTOR), |
| 66 |
'type' => \Elementor\Controls_Manager::SELECT2, |
| 67 |
'multiple' => true, |
| 68 |
'options' => $this->getTagOptions(), |
| 69 |
'default' => [] |
| 70 |
] |
| 71 |
); |
| 72 |
|
| 73 |
$this->add_control( |
| 74 |
'title', |
| 75 |
[ |
| 76 |
'label' => __('Title', WPDM_ELEMENTOR), |
| 77 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 78 |
'input_type' => 'text', |
| 79 |
'description' => __('Use "1" to show tag title, or enter custom text', WPDM_ELEMENTOR), |
| 80 |
'default' => '1' |
| 81 |
] |
| 82 |
); |
| 83 |
|
| 84 |
$this->add_control( |
| 85 |
'desc', |
| 86 |
[ |
| 87 |
'label' => __('Description', WPDM_ELEMENTOR), |
| 88 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 89 |
'input_type' => 'text', |
| 90 |
'description' => __('Use "1" to show tag description, or enter custom text', WPDM_ELEMENTOR), |
| 91 |
'default' => '1' |
| 92 |
] |
| 93 |
); |
| 94 |
|
| 95 |
$this->add_control( |
| 96 |
'items_per_page', |
| 97 |
[ |
| 98 |
'label' => __('Items Per Page', WPDM_ELEMENTOR), |
| 99 |
'type' => \Elementor\Controls_Manager::NUMBER, |
| 100 |
'min' => 1, |
| 101 |
'max' => 100, |
| 102 |
'default' => 10 |
| 103 |
] |
| 104 |
); |
| 105 |
|
| 106 |
$this->add_control( |
| 107 |
'orderby', |
| 108 |
[ |
| 109 |
'label' => __('Order By', WPDM_ELEMENTOR), |
| 110 |
'type' => \Elementor\Controls_Manager::SELECT2, |
| 111 |
'options' => ['date' => __('Date', WPDM_ELEMENTOR), 'title' => __('Title', WPDM_ELEMENTOR)], |
| 112 |
'default' => 'date', |
| 113 |
] |
| 114 |
); |
| 115 |
|
| 116 |
$this->add_control( |
| 117 |
'order', |
| 118 |
[ |
| 119 |
'label' => __('Order', WPDM_ELEMENTOR), |
| 120 |
'type' => \Elementor\Controls_Manager::CHOOSE, |
| 121 |
'options' => [ |
| 122 |
'ASC' => ['title' => __('Ascending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-up'], |
| 123 |
'DESC' => ['title' => __('Descending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-down'] |
| 124 |
], |
| 125 |
'default' => 'DESC', |
| 126 |
'toggle' => false |
| 127 |
] |
| 128 |
); |
| 129 |
|
| 130 |
$this->add_control( |
| 131 |
'template', |
| 132 |
[ |
| 133 |
'label' => __('Link Template', WPDM_ELEMENTOR), |
| 134 |
'type' => \Elementor\Controls_Manager::SELECT2, |
| 135 |
'options' => get_wpdm_link_templates(), |
| 136 |
'default' => 'link-template-default' |
| 137 |
] |
| 138 |
); |
| 139 |
|
| 140 |
$this->add_control( |
| 141 |
'cols', |
| 142 |
[ |
| 143 |
'label' => __('Columns (Desktop)', WPDM_ELEMENTOR), |
| 144 |
'type' => \Elementor\Controls_Manager::NUMBER, |
| 145 |
'min' => 1, |
| 146 |
'max' => 6, |
| 147 |
'default' => 3 |
| 148 |
] |
| 149 |
); |
| 150 |
|
| 151 |
$this->add_control( |
| 152 |
'colspad', |
| 153 |
[ |
| 154 |
'label' => __('Columns (Tablet)', WPDM_ELEMENTOR), |
| 155 |
'type' => \Elementor\Controls_Manager::NUMBER, |
| 156 |
'min' => 1, |
| 157 |
'max' => 4, |
| 158 |
'default' => 2 |
| 159 |
] |
| 160 |
); |
| 161 |
|
| 162 |
$this->add_control( |
| 163 |
'colsphone', |
| 164 |
[ |
| 165 |
'label' => __('Columns (Phone)', WPDM_ELEMENTOR), |
| 166 |
'type' => \Elementor\Controls_Manager::NUMBER, |
| 167 |
'min' => 1, |
| 168 |
'max' => 2, |
| 169 |
'default' => 1 |
| 170 |
] |
| 171 |
); |
| 172 |
|
| 173 |
$this->add_control( |
| 174 |
'toolbar', |
| 175 |
[ |
| 176 |
'label' => __('Show Toolbar', WPDM_ELEMENTOR), |
| 177 |
'type' => \Elementor\Controls_Manager::CHOOSE, |
| 178 |
'options' => [ |
| 179 |
'1' => ['title' => __('Show', WPDM_ELEMENTOR), 'icon' => 'eicon-check'], |
| 180 |
'0' => ['title' => __('Hide', WPDM_ELEMENTOR), 'icon' => 'eicon-close'] |
| 181 |
], |
| 182 |
'default' => '1', |
| 183 |
] |
| 184 |
); |
| 185 |
|
| 186 |
$this->end_controls_section(); |
| 187 |
} |
| 188 |
|
| 189 |
protected function render() |
| 190 |
{ |
| 191 |
$settings = $this->getCleanSettings(self::SETTINGS_KEYS); |
| 192 |
$settings = $this->sanitizeSettings($settings, self::SANITIZERS); |
| 193 |
|
| 194 |
if (empty($settings['tagid'])) { |
| 195 |
return; |
| 196 |
} |
| 197 |
|
| 198 |
// Convert tagid array to comma-separated id |
| 199 |
$settings['id'] = is_array($settings['tagid']) |
| 200 |
? implode(',', array_map('sanitize_text_field', $settings['tagid'])) |
| 201 |
: sanitize_text_field($settings['tagid']); |
| 202 |
|
| 203 |
unset($settings['tagid']); |
| 204 |
|
| 205 |
echo WPDM()->package->shortCodes->packagesByTag($settings); |
| 206 |
} |
| 207 |
} |
| 208 |
|