| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDM\Elementor\Widgets; |
| 4 |
|
| 5 |
/** |
| 6 |
* Packages Widget. |
| 7 |
* Displays multiple packages with filtering options. |
| 8 |
*/ |
| 9 |
class PackagesWidget extends BaseWidget |
| 10 |
{ |
| 11 |
/** |
| 12 |
* Expected settings keys for this widget. |
| 13 |
*/ |
| 14 |
private const SETTINGS_KEYS = [ |
| 15 |
'search', 'categories', 'include_children', 'tags', 'author', |
| 16 |
'orderby', 'order', 'items_per_page', 'template', |
| 17 |
'cols', 'colspad', 'colsphone', 'toolbar', 'paging', 'login', 'async' |
| 18 |
]; |
| 19 |
|
| 20 |
/** |
| 21 |
* Settings sanitization rules. |
| 22 |
*/ |
| 23 |
private const SANITIZERS = [ |
| 24 |
'search' => 'text', |
| 25 |
'include_children' => 'text', |
| 26 |
'author' => 'text', |
| 27 |
'orderby' => 'orderby', |
| 28 |
'order' => 'order', |
| 29 |
'items_per_page' => 'int', |
| 30 |
'template' => 'text', |
| 31 |
'cols' => 'int', |
| 32 |
'colspad' => 'int', |
| 33 |
'colsphone' => 'int', |
| 34 |
'toolbar' => 'text', |
| 35 |
'paging' => 'text', |
| 36 |
'login' => 'text', |
| 37 |
'async' => 'text', |
| 38 |
]; |
| 39 |
|
| 40 |
public function get_name() |
| 41 |
{ |
| 42 |
return 'wpdmpackages'; |
| 43 |
} |
| 44 |
|
| 45 |
public function get_title() |
| 46 |
{ |
| 47 |
return __('Packages', WPDM_ELEMENTOR); |
| 48 |
} |
| 49 |
|
| 50 |
public function get_icon() |
| 51 |
{ |
| 52 |
return 'eicon-posts-grid'; |
| 53 |
} |
| 54 |
|
| 55 |
protected function register_controls() |
| 56 |
{ |
| 57 |
$this->start_controls_section( |
| 58 |
'content_section', |
| 59 |
[ |
| 60 |
'label' => __('Parameters', WPDM_ELEMENTOR), |
| 61 |
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 62 |
] |
| 63 |
); |
| 64 |
|
| 65 |
$this->add_control( |
| 66 |
'search', |
| 67 |
[ |
| 68 |
'label' => __('Search Keywords', WPDM_ELEMENTOR), |
| 69 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 70 |
'input_type' => 'text', |
| 71 |
'placeholder' => __('search keywords', WPDM_ELEMENTOR), |
| 72 |
] |
| 73 |
); |
| 74 |
|
| 75 |
$this->add_control( |
| 76 |
'categories', |
| 77 |
[ |
| 78 |
'label' => __('Include Categories', WPDM_ELEMENTOR), |
| 79 |
'type' => \Elementor\Controls_Manager::SELECT2, |
| 80 |
'multiple' => true, |
| 81 |
'options' => $this->getCategoryOptions(), |
| 82 |
'default' => [] |
| 83 |
] |
| 84 |
); |
| 85 |
|
| 86 |
$this->add_control( |
| 87 |
'include_children', |
| 88 |
[ |
| 89 |
'label' => __('Include Children', WPDM_ELEMENTOR), |
| 90 |
'type' => \Elementor\Controls_Manager::CHOOSE, |
| 91 |
'options' => [ |
| 92 |
'0' => ['title' => __('No', WPDM_ELEMENTOR), 'icon' => 'eicon-close'], |
| 93 |
'1' => ['title' => __('Yes', WPDM_ELEMENTOR), 'icon' => 'eicon-check'] |
| 94 |
], |
| 95 |
'default' => '0' |
| 96 |
] |
| 97 |
); |
| 98 |
|
| 99 |
$tag_options = $this->getTagOptions(); |
| 100 |
if (!empty($tag_options)) { |
| 101 |
$this->add_control( |
| 102 |
'tags', |
| 103 |
[ |
| 104 |
'label' => __('Tags', WPDM_ELEMENTOR), |
| 105 |
'type' => \Elementor\Controls_Manager::SELECT2, |
| 106 |
'multiple' => true, |
| 107 |
'options' => $tag_options, |
| 108 |
'default' => [] |
| 109 |
] |
| 110 |
); |
| 111 |
} |
| 112 |
|
| 113 |
$this->add_control( |
| 114 |
'author', |
| 115 |
[ |
| 116 |
'label' => __('Authors', WPDM_ELEMENTOR), |
| 117 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 118 |
'input_type' => 'text', |
| 119 |
'placeholder' => __('1, 2, 3', WPDM_ELEMENTOR), |
| 120 |
'description' => __('Author IDs separated by comma', WPDM_ELEMENTOR) |
| 121 |
] |
| 122 |
); |
| 123 |
|
| 124 |
$this->add_control( |
| 125 |
'orderby', |
| 126 |
[ |
| 127 |
'label' => __('Order By', WPDM_ELEMENTOR), |
| 128 |
'type' => \Elementor\Controls_Manager::SELECT2, |
| 129 |
'options' => ['date' => __('Date', WPDM_ELEMENTOR), 'title' => __('Title', WPDM_ELEMENTOR)], |
| 130 |
'default' => 'date', |
| 131 |
] |
| 132 |
); |
| 133 |
|
| 134 |
$this->add_control( |
| 135 |
'order', |
| 136 |
[ |
| 137 |
'label' => __('Order', WPDM_ELEMENTOR), |
| 138 |
'type' => \Elementor\Controls_Manager::CHOOSE, |
| 139 |
'options' => [ |
| 140 |
'ASC' => ['title' => __('Ascending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-up'], |
| 141 |
'DESC' => ['title' => __('Descending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-down'] |
| 142 |
], |
| 143 |
'default' => 'DESC', |
| 144 |
'toggle' => false |
| 145 |
] |
| 146 |
); |
| 147 |
|
| 148 |
$this->add_control( |
| 149 |
'items_per_page', |
| 150 |
[ |
| 151 |
'label' => __('Items Per Page', WPDM_ELEMENTOR), |
| 152 |
'type' => \Elementor\Controls_Manager::NUMBER, |
| 153 |
'min' => 1, |
| 154 |
'max' => 100, |
| 155 |
'default' => 10 |
| 156 |
] |
| 157 |
); |
| 158 |
|
| 159 |
$this->add_control( |
| 160 |
'template', |
| 161 |
[ |
| 162 |
'label' => __('Link Template', WPDM_ELEMENTOR), |
| 163 |
'type' => \Elementor\Controls_Manager::SELECT2, |
| 164 |
'options' => $this->getLinkTemplateOptions(), |
| 165 |
'default' => 'link-template-default' |
| 166 |
] |
| 167 |
); |
| 168 |
|
| 169 |
$this->add_control( |
| 170 |
'cols', |
| 171 |
[ |
| 172 |
'label' => __('Columns (Desktop)', WPDM_ELEMENTOR), |
| 173 |
'type' => \Elementor\Controls_Manager::NUMBER, |
| 174 |
'min' => 1, |
| 175 |
'max' => 6, |
| 176 |
'default' => 3 |
| 177 |
] |
| 178 |
); |
| 179 |
|
| 180 |
$this->add_control( |
| 181 |
'colspad', |
| 182 |
[ |
| 183 |
'label' => __('Columns (Tablet)', WPDM_ELEMENTOR), |
| 184 |
'type' => \Elementor\Controls_Manager::NUMBER, |
| 185 |
'min' => 1, |
| 186 |
'max' => 4, |
| 187 |
'default' => 2 |
| 188 |
] |
| 189 |
); |
| 190 |
|
| 191 |
$this->add_control( |
| 192 |
'colsphone', |
| 193 |
[ |
| 194 |
'label' => __('Columns (Phone)', WPDM_ELEMENTOR), |
| 195 |
'type' => \Elementor\Controls_Manager::NUMBER, |
| 196 |
'min' => 1, |
| 197 |
'max' => 2, |
| 198 |
'default' => 1 |
| 199 |
] |
| 200 |
); |
| 201 |
|
| 202 |
$this->add_control( |
| 203 |
'toolbar', |
| 204 |
[ |
| 205 |
'label' => __('Show Toolbar', WPDM_ELEMENTOR), |
| 206 |
'type' => \Elementor\Controls_Manager::CHOOSE, |
| 207 |
'options' => [ |
| 208 |
'1' => ['title' => __('Show', WPDM_ELEMENTOR), 'icon' => 'eicon-check'], |
| 209 |
'0' => ['title' => __('Hide', WPDM_ELEMENTOR), 'icon' => 'eicon-close'] |
| 210 |
], |
| 211 |
'default' => '1', |
| 212 |
] |
| 213 |
); |
| 214 |
|
| 215 |
$this->add_control( |
| 216 |
'paging', |
| 217 |
[ |
| 218 |
'label' => __('Pagination', WPDM_ELEMENTOR), |
| 219 |
'type' => \Elementor\Controls_Manager::CHOOSE, |
| 220 |
'options' => [ |
| 221 |
'1' => ['title' => __('Show', WPDM_ELEMENTOR), 'icon' => 'eicon-check'], |
| 222 |
'0' => ['title' => __('Hide', WPDM_ELEMENTOR), 'icon' => 'eicon-close'] |
| 223 |
], |
| 224 |
'default' => '0', |
| 225 |
] |
| 226 |
); |
| 227 |
|
| 228 |
$this->add_control( |
| 229 |
'login', |
| 230 |
[ |
| 231 |
'label' => __('Require Login', WPDM_ELEMENTOR), |
| 232 |
'type' => \Elementor\Controls_Manager::CHOOSE, |
| 233 |
'options' => [ |
| 234 |
'0' => ['title' => __('No', WPDM_ELEMENTOR), 'icon' => 'eicon-close'], |
| 235 |
'1' => ['title' => __('Yes', WPDM_ELEMENTOR), 'icon' => 'eicon-check'] |
| 236 |
], |
| 237 |
'default' => '0' |
| 238 |
] |
| 239 |
); |
| 240 |
|
| 241 |
$this->add_control( |
| 242 |
'async', |
| 243 |
[ |
| 244 |
'label' => __('Async Loading', WPDM_ELEMENTOR), |
| 245 |
'type' => \Elementor\Controls_Manager::CHOOSE, |
| 246 |
'options' => [ |
| 247 |
'1' => ['title' => __('Enable', WPDM_ELEMENTOR), 'icon' => 'eicon-check'], |
| 248 |
'0' => ['title' => __('Disable', WPDM_ELEMENTOR), 'icon' => 'eicon-close'] |
| 249 |
], |
| 250 |
'default' => '1', |
| 251 |
] |
| 252 |
); |
| 253 |
|
| 254 |
$this->end_controls_section(); |
| 255 |
} |
| 256 |
|
| 257 |
protected function render() |
| 258 |
{ |
| 259 |
$settings = $this->getCleanSettings(self::SETTINGS_KEYS); |
| 260 |
$settings = $this->sanitizeSettings($settings, self::SANITIZERS); |
| 261 |
|
| 262 |
// Convert arrays to comma-separated strings |
| 263 |
$settings = $this->arraysToComma($settings, ['categories', 'tags']); |
| 264 |
|
| 265 |
echo WPDM()->package->shortCodes->packages($settings); |
| 266 |
} |
| 267 |
} |
| 268 |
|