| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Elementor Classes. |
|---|
| 4 | * |
|---|
| 5 | * @package CoWidgets |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | namespace COWIDGETS\WidgetsManager\Widgets; |
|---|
| 9 | |
|---|
| 10 | use Elementor\Controls_Manager; |
|---|
| 11 | use Elementor\Utils; |
|---|
| 12 | use Elementor\Group_Control_Typography; |
|---|
| 13 | use Elementor\Core\Schemes\Typography; |
|---|
| 14 | use Elementor\Core\Schemes\Color; |
|---|
| 15 | use Elementor\Widget_Base; |
|---|
| 16 | use Elementor\Group_Control_Image_Size; |
|---|
| 17 | |
|---|
| 18 | if ( ! defined( 'ABSPATH' ) ) { |
|---|
| 19 | exit; // Exit if accessed directly. |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | /** |
|---|
| 23 | * Elementor Posts Carousel |
|---|
| 24 | * |
|---|
| 25 | * Elementor widget for Posts Carousel. |
|---|
| 26 | * |
|---|
| 27 | * @since 1.0.0 |
|---|
| 28 | */ |
|---|
| 29 | class Posts_Carousel extends Widget_Base { |
|---|
| 30 | |
|---|
| 31 | private $source_type; |
|---|
| 32 | |
|---|
| 33 | /** |
|---|
| 34 | * Retrieve the widget name. |
|---|
| 35 | * |
|---|
| 36 | * @since 1.0.0 |
|---|
| 37 | * |
|---|
| 38 | * @access public |
|---|
| 39 | * |
|---|
| 40 | * @return string Widget name. |
|---|
| 41 | */ |
|---|
| 42 | public function get_name() { |
|---|
| 43 | return 'ce-posts-carousel'; |
|---|
| 44 | } |
|---|
| 45 | /** |
|---|
| 46 | * Retrieve the widget title. |
|---|
| 47 | * |
|---|
| 48 | * @since 1.0.0 |
|---|
| 49 | * |
|---|
| 50 | * @access public |
|---|
| 51 | * |
|---|
| 52 | * @return string Widget title. |
|---|
| 53 | */ |
|---|
| 54 | public function get_title() { |
|---|
| 55 | return __( 'Posts Carousel', 'cowidgets' ); |
|---|
| 56 | } |
|---|
| 57 | /** |
|---|
| 58 | * Retrieve the widget icon. |
|---|
| 59 | * |
|---|
| 60 | * @since 1.0.0 |
|---|
| 61 | * |
|---|
| 62 | * @access public |
|---|
| 63 | * |
|---|
| 64 | * @return string Widget icon. |
|---|
| 65 | */ |
|---|
| 66 | public function get_icon() { |
|---|
| 67 | return 'ce-icon-posts-carousel'; |
|---|
| 68 | } |
|---|
| 69 | /** |
|---|
| 70 | * Retrieve the list of categories the widget belongs to. |
|---|
| 71 | * |
|---|
| 72 | * Used to determine where to display the widget in the editor. |
|---|
| 73 | * |
|---|
| 74 | * Note that currently Elementor supports only one category. |
|---|
| 75 | * When multiple categories passed, Elementor uses the first one. |
|---|
| 76 | * |
|---|
| 77 | * @since 1.0.0 |
|---|
| 78 | * |
|---|
| 79 | * @access public |
|---|
| 80 | * |
|---|
| 81 | * @return array Widget categories. |
|---|
| 82 | */ |
|---|
| 83 | public function get_categories() { |
|---|
| 84 | return [ 'ce-content-widgets' ]; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | public function get_script_depends() { |
|---|
| 88 | return [ 'ce-posts-carousel', 'tiny-slider' ]; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | public function get_style_depends() { |
|---|
| 92 | return [ 'tiny-slider' ]; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | /** |
|---|
| 96 | * Register controls. |
|---|
| 97 | * |
|---|
| 98 | * @since 1.0.0 |
|---|
| 99 | * @access protected |
|---|
| 100 | */ |
|---|
| 101 | protected function register_controls() { |
|---|
| 102 | $this->register_posts_carousel_controls(); |
|---|
| 103 | } |
|---|
| 104 | /** |
|---|
| 105 | * Register General Controls. |
|---|
| 106 | * |
|---|
| 107 | * @since 1.0.0 |
|---|
| 108 | * @access protected |
|---|
| 109 | */ |
|---|
| 110 | protected function register_posts_carousel_controls() { |
|---|
| 111 | \COWIDGETS_Helpers::postsSelectionSection( $this ); |
|---|
| 112 | $this->start_controls_section( |
|---|
| 113 | 'section_content_style', |
|---|
| 114 | [ |
|---|
| 115 | 'label' => __( 'Item Layout/Style', 'cowidgets' ), |
|---|
| 116 | 'tab' => Controls_Manager::TAB_CONTENT, |
|---|
| 117 | ] |
|---|
| 118 | ); |
|---|
| 119 | |
|---|
| 120 | $this->add_control( |
|---|
| 121 | 'item_style', |
|---|
| 122 | [ |
|---|
| 123 | 'label' => __( 'Style', 'cowidgets' ), |
|---|
| 124 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 125 | 'default' => 'adair', |
|---|
| 126 | 'options' => apply_filters( 'ce_load_element_styles', [ |
|---|
| 127 | 'adair' => __( 'Adair', 'cowidgets' ), |
|---|
| 128 | 'colm' => __( 'Colm', 'cowidgets' ), |
|---|
| 129 | 'birk' => __( 'Birk', 'cowidgets' ), |
|---|
| 130 | 'rowan' => __( 'Rowan', 'cowidgets' ), |
|---|
| 131 | 'box' => __( 'Box', 'cowidgets' ), |
|---|
| 132 | 'vernon' => __( 'Vernon', 'cowidgets' ) |
|---|
| 133 | ] ), |
|---|
| 134 | ] |
|---|
| 135 | ); |
|---|
| 136 | |
|---|
| 137 | $this->add_group_control( |
|---|
| 138 | Group_Control_Image_Size::get_type(), |
|---|
| 139 | [ |
|---|
| 140 | 'name' => 'image_size', |
|---|
| 141 | 'label' => __( 'Image Size', 'cowidgets' ), |
|---|
| 142 | 'default' => 'medium', |
|---|
| 143 | ] |
|---|
| 144 | ); |
|---|
| 145 | |
|---|
| 146 | $this->add_control( |
|---|
| 147 | 'columns', |
|---|
| 148 | [ |
|---|
| 149 | 'label' => __( 'Columns', 'cowidgets' ), |
|---|
| 150 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 151 | 'default' => '3', |
|---|
| 152 | 'options' => [ |
|---|
| 153 | 1 => __( '1', 'cowidgets' ), |
|---|
| 154 | 2 => __( '2', 'cowidgets' ), |
|---|
| 155 | 3 => __( '3', 'cowidgets' ), |
|---|
| 156 | 4 => __( '4', 'cowidgets' ), |
|---|
| 157 | 5 => __( '5', 'cowidgets' ), |
|---|
| 158 | 6 => __( '6', 'cowidgets' ), |
|---|
| 159 | 7 => __( '7', 'cowidgets' ), |
|---|
| 160 | ], |
|---|
| 161 | 'render_type' => 'template' |
|---|
| 162 | ] |
|---|
| 163 | ); |
|---|
| 164 | |
|---|
| 165 | $this->add_control( |
|---|
| 166 | 'height', |
|---|
| 167 | [ |
|---|
| 168 | 'label' => __( 'Height', 'cowidgets' ), |
|---|
| 169 | 'type' => Controls_Manager::SLIDER, |
|---|
| 170 | 'size_units' => ['px'], |
|---|
| 171 | 'range' => [ |
|---|
| 172 | 'px' => [ |
|---|
| 173 | 'max' => 2500, |
|---|
| 174 | 'min' => 100, |
|---|
| 175 | ], |
|---|
| 176 | ], |
|---|
| 177 | 'default' => [ |
|---|
| 178 | 'size' => 700, |
|---|
| 179 | 'unit' => 'px', |
|---|
| 180 | ], |
|---|
| 181 | 'render_type' => 'template', |
|---|
| 182 | 'selectors' => [ |
|---|
| 183 | '{{WRAPPER}} .ce-posts-carousel article' => 'height: {{SIZE}}{{UNIT}}', |
|---|
| 184 | '{{WRAPPER}} .ce-posts-carousel article .post-thumbnail' => 'height: {{SIZE}}{{UNIT}}', |
|---|
| 185 | ], |
|---|
| 186 | 'condition' => [ |
|---|
| 187 | 'item_style' => 'rowan' |
|---|
| 188 | ] |
|---|
| 189 | ] |
|---|
| 190 | ); |
|---|
| 191 | |
|---|
| 192 | $this->add_control( |
|---|
| 193 | 'entry_content', |
|---|
| 194 | [ |
|---|
| 195 | 'label' => __( 'Content?', 'cowidgets' ), |
|---|
| 196 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 197 | 'default' => 'excerpt', |
|---|
| 198 | 'options' => [ |
|---|
| 199 | 'excerpt' => __( 'Excerpt', 'cowidgets' ), |
|---|
| 200 | 'content' => __( 'Content', 'cowidgets' ), |
|---|
| 201 | 'none' => __( 'None', 'cowidgets' ), |
|---|
| 202 | ], |
|---|
| 203 | 'render_type' => 'template' |
|---|
| 204 | ] |
|---|
| 205 | ); |
|---|
| 206 | |
|---|
| 207 | $this->add_control( |
|---|
| 208 | 'entry_readmore', |
|---|
| 209 | [ |
|---|
| 210 | 'label' => __( '"Continue Reading"?', 'cowidgets' ), |
|---|
| 211 | 'description' => __( 'Works only when style has a "Continue Reading" button by default', 'cowidgets' ), |
|---|
| 212 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 213 | 'default' => 1, |
|---|
| 214 | 'options' => [ |
|---|
| 215 | 0 => __( 'No', 'cowidgets' ), |
|---|
| 216 | 1 => __( 'Yes', 'cowidgets' ) |
|---|
| 217 | ], |
|---|
| 218 | 'render_type' => 'template' |
|---|
| 219 | ] |
|---|
| 220 | ); |
|---|
| 221 | |
|---|
| 222 | $this->add_control( |
|---|
| 223 | 'user_icon', |
|---|
| 224 | [ |
|---|
| 225 | 'label' => __( 'User Icon', 'cowidgets' ), |
|---|
| 226 | 'type' => Controls_Manager::ICONS, |
|---|
| 227 | 'label_block' => 'true', |
|---|
| 228 | 'default' => [ |
|---|
| 229 | 'value' => 'feather feather-user', |
|---|
| 230 | 'library' => 'feather', |
|---|
| 231 | ], |
|---|
| 232 | ] |
|---|
| 233 | ); |
|---|
| 234 | |
|---|
| 235 | $this->add_control( |
|---|
| 236 | 'date_icon', |
|---|
| 237 | [ |
|---|
| 238 | 'label' => __( 'Date Icon', 'cowidgets' ), |
|---|
| 239 | 'type' => Controls_Manager::ICONS, |
|---|
| 240 | 'label_block' => 'true', |
|---|
| 241 | 'default' => [ |
|---|
| 242 | 'value' => 'feather feather-clock', |
|---|
| 243 | 'library' => 'feather', |
|---|
| 244 | ], |
|---|
| 245 | ] |
|---|
| 246 | ); |
|---|
| 247 | |
|---|
| 248 | $this->end_controls_section(); |
|---|
| 249 | |
|---|
| 250 | $this->start_controls_section( |
|---|
| 251 | 'section_content_carousel', |
|---|
| 252 | [ |
|---|
| 253 | 'label' => __( 'Carousel Options', 'cowidgets' ), |
|---|
| 254 | 'tab' => Controls_Manager::TAB_CONTENT, |
|---|
| 255 | ] |
|---|
| 256 | ); |
|---|
| 257 | |
|---|
| 258 | $this->add_control( |
|---|
| 259 | 'slide_by', |
|---|
| 260 | [ |
|---|
| 261 | 'label' => __( 'Slide By', 'cowidgets' ), |
|---|
| 262 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 263 | 'default' => 1, |
|---|
| 264 | 'options' => [ |
|---|
| 265 | '1' => __( '1', 'cowidgets' ), |
|---|
| 266 | 'page' => __( 'Page', 'cowidgets' ), |
|---|
| 267 | ], |
|---|
| 268 | ] |
|---|
| 269 | ); |
|---|
| 270 | |
|---|
| 271 | $this->add_control( |
|---|
| 272 | 'autoplay', |
|---|
| 273 | [ |
|---|
| 274 | 'label' => __( 'Autoplay', 'cowidgets' ), |
|---|
| 275 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 276 | 'default' => 0, |
|---|
| 277 | 'options' => [ |
|---|
| 278 | 0 => __( 'No', 'cowidgets' ), |
|---|
| 279 | 1 => __( 'Yes', 'cowidgets' ), |
|---|
| 280 | ], |
|---|
| 281 | ] |
|---|
| 282 | ); |
|---|
| 283 | |
|---|
| 284 | $this->add_control( |
|---|
| 285 | 'loop', |
|---|
| 286 | [ |
|---|
| 287 | 'label' => __( 'Loop', 'cowidgets' ), |
|---|
| 288 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 289 | 'default' => 0, |
|---|
| 290 | 'options' => [ |
|---|
| 291 | 0 => __( 'No', 'cowidgets' ), |
|---|
| 292 | 1 => __( 'Yes', 'cowidgets' ), |
|---|
| 293 | ], |
|---|
| 294 | ] |
|---|
| 295 | ); |
|---|
| 296 | |
|---|
| 297 | $this->add_control( |
|---|
| 298 | 'center', |
|---|
| 299 | [ |
|---|
| 300 | 'label' => __( 'Center', 'cowidgets' ), |
|---|
| 301 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 302 | 'default' => 0, |
|---|
| 303 | 'options' => [ |
|---|
| 304 | 0 => __( 'No', 'cowidgets' ), |
|---|
| 305 | 1 => __( 'Yes', 'cowidgets' ), |
|---|
| 306 | ], |
|---|
| 307 | ] |
|---|
| 308 | ); |
|---|
| 309 | |
|---|
| 310 | $this->add_control( |
|---|
| 311 | 'mouse_drag', |
|---|
| 312 | [ |
|---|
| 313 | 'label' => __( 'Mouse Drag', 'cowidgets' ), |
|---|
| 314 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 315 | 'default' => 1, |
|---|
| 316 | 'options' => [ |
|---|
| 317 | 0 => __( 'No', 'cowidgets' ), |
|---|
| 318 | 1 => __( 'Yes', 'cowidgets' ), |
|---|
| 319 | ], |
|---|
| 320 | ] |
|---|
| 321 | ); |
|---|
| 322 | |
|---|
| 323 | $this->add_control( |
|---|
| 324 | 'carousel_controls', |
|---|
| 325 | [ |
|---|
| 326 | 'label' => __( 'Prev/Next Buttons', 'cowidgets' ), |
|---|
| 327 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 328 | 'default' => 0, |
|---|
| 329 | 'options' => [ |
|---|
| 330 | 0 => __( 'No', 'cowidgets' ), |
|---|
| 331 | 1 => __( 'Yes', 'cowidgets' ), |
|---|
| 332 | ], |
|---|
| 333 | ] |
|---|
| 334 | ); |
|---|
| 335 | |
|---|
| 336 | $this->add_control( |
|---|
| 337 | 'vertical_align', |
|---|
| 338 | [ |
|---|
| 339 | 'label' => __( 'Items Vertical Align', 'cowidgets' ), |
|---|
| 340 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 341 | 'default' => 'top', |
|---|
| 342 | 'options' => [ |
|---|
| 343 | 'top' => __( 'Top', 'cowidgets' ), |
|---|
| 344 | 'middle' => __( 'Middle', 'cowidgets' ), |
|---|
| 345 | 'bottom' => __( 'Bottom', 'cowidgets' ), |
|---|
| 346 | ], |
|---|
| 347 | 'selectors' => [ |
|---|
| 348 | '{{WRAPPER}} .ce-posts-carousel .tns-item' => 'vertical-align: {{VALUE}}', |
|---|
| 349 | ], |
|---|
| 350 | |
|---|
| 351 | 'render_type' => 'template' |
|---|
| 352 | ] |
|---|
| 353 | ); |
|---|
| 354 | |
|---|
| 355 | $this->add_control( |
|---|
| 356 | 'start_index', |
|---|
| 357 | [ |
|---|
| 358 | 'label' => __( 'Start Index', 'cowidgets' ), |
|---|
| 359 | 'type' => \Elementor\Controls_Manager::TEXT, |
|---|
| 360 | 'default' => '0', |
|---|
| 361 | ] |
|---|
| 362 | ); |
|---|
| 363 | |
|---|
| 364 | $this->add_control( |
|---|
| 365 | 'gutter', |
|---|
| 366 | [ |
|---|
| 367 | 'label' => __( 'Space between items', 'cowidgets' ), |
|---|
| 368 | 'type' => Controls_Manager::SLIDER, |
|---|
| 369 | 'size_units' => ['px'], |
|---|
| 370 | 'range' => [ |
|---|
| 371 | 'px' => [ |
|---|
| 372 | 'max' => 500, |
|---|
| 373 | 'min' => 0, |
|---|
| 374 | ], |
|---|
| 375 | ], |
|---|
| 376 | 'default' => [ |
|---|
| 377 | 'size' => 15, |
|---|
| 378 | 'unit' => 'px', |
|---|
| 379 | ], |
|---|
| 380 | 'render_type' => 'template', |
|---|
| 381 | ] |
|---|
| 382 | ); |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | $this->add_control( |
|---|
| 387 | 'edge_padding', |
|---|
| 388 | [ |
|---|
| 389 | 'label' => __( 'Space on the outside', 'cowidgets' ), |
|---|
| 390 | 'type' => Controls_Manager::SLIDER, |
|---|
| 391 | 'size_units' => ['px'], |
|---|
| 392 | 'range' => [ |
|---|
| 393 | 'px' => [ |
|---|
| 394 | 'max' => 500, |
|---|
| 395 | 'min' => 0, |
|---|
| 396 | ], |
|---|
| 397 | ], |
|---|
| 398 | 'default' => [], |
|---|
| 399 | 'render_type' => 'template', |
|---|
| 400 | ] |
|---|
| 401 | ); |
|---|
| 402 | |
|---|
| 403 | $this->add_control( |
|---|
| 404 | 'edge_padding_side', |
|---|
| 405 | [ |
|---|
| 406 | 'label' => __( 'Space on the outside only one side', 'cowidgets' ), |
|---|
| 407 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 408 | 'default' => 0, |
|---|
| 409 | 'options' => [ |
|---|
| 410 | 0 => __( 'No', 'cowidgets' ), |
|---|
| 411 | 1 => __( 'Yes', 'cowidgets' ), |
|---|
| 412 | ], |
|---|
| 413 | ] |
|---|
| 414 | ); |
|---|
| 415 | |
|---|
| 416 | $this->end_controls_section(); |
|---|
| 417 | |
|---|
| 418 | $this->start_controls_section( |
|---|
| 419 | 'section_style', |
|---|
| 420 | [ |
|---|
| 421 | 'label' => __( 'Global', 'cowidgets' ), |
|---|
| 422 | 'tab' => Controls_Manager::TAB_STYLE |
|---|
| 423 | ] |
|---|
| 424 | ); |
|---|
| 425 | |
|---|
| 426 | $this->add_control( |
|---|
| 427 | 'global_important_note', |
|---|
| 428 | [ |
|---|
| 429 | 'type' => \Elementor\Controls_Manager::RAW_HTML, |
|---|
| 430 | 'raw' => __( 'This section contains global styling options of this element. Some of this options should not work on specific selected styles. Please check the section below for style-specific options.', 'cowidgets' ), |
|---|
| 431 | 'content_classes' => 'important_note' |
|---|
| 432 | ] |
|---|
| 433 | ); |
|---|
| 434 | |
|---|
| 435 | $this->add_group_control( |
|---|
| 436 | \Elementor\Group_Control_Typography::get_type(), |
|---|
| 437 | [ |
|---|
| 438 | 'name' => 'item_title_typography', |
|---|
| 439 | 'label' => __( 'Item Title Typography', 'plugin-domain' ), |
|---|
| 440 | 'scheme' => Typography::TYPOGRAPHY_1, |
|---|
| 441 | 'selector' => '{{WRAPPER}} .ce-post-item .entry-title', |
|---|
| 442 | ] |
|---|
| 443 | ); |
|---|
| 444 | |
|---|
| 445 | $this->add_control( |
|---|
| 446 | 'item_title_color', |
|---|
| 447 | [ |
|---|
| 448 | 'label' => __( 'Item Title Color', 'cowidgets' ), |
|---|
| 449 | 'type' => \Elementor\Controls_Manager::COLOR, |
|---|
| 450 | |
|---|
| 451 | 'selectors' => [ |
|---|
| 452 | '{{WRAPPER}} .ce-post-item .entry-title' => 'color: {{VALUE}}', |
|---|
| 453 | ], |
|---|
| 454 | ] |
|---|
| 455 | ); |
|---|
| 456 | |
|---|
| 457 | $this->add_group_control( |
|---|
| 458 | \Elementor\Group_Control_Typography::get_type(), |
|---|
| 459 | [ |
|---|
| 460 | 'name' => 'item_meta_typography', |
|---|
| 461 | 'label' => __( 'Item Meta Typography', 'cowidgets' ), |
|---|
| 462 | 'scheme' => Typography::TYPOGRAPHY_1, |
|---|
| 463 | 'selector' => '{{WRAPPER}} .ce-post-item .entry-meta-single', |
|---|
| 464 | ] |
|---|
| 465 | ); |
|---|
| 466 | |
|---|
| 467 | $this->add_control( |
|---|
| 468 | 'item_meta_color', |
|---|
| 469 | [ |
|---|
| 470 | 'label' => __( 'Item Meta Color', 'cowidgets' ), |
|---|
| 471 | 'type' => \Elementor\Controls_Manager::COLOR, |
|---|
| 472 | |
|---|
| 473 | 'selectors' => [ |
|---|
| 474 | '{{WRAPPER}} .ce-post-item .entry-meta-single' => 'color: {{VALUE}}', |
|---|
| 475 | ], |
|---|
| 476 | ] |
|---|
| 477 | ); |
|---|
| 478 | |
|---|
| 479 | $this->add_group_control( |
|---|
| 480 | \Elementor\Group_Control_Typography::get_type(), |
|---|
| 481 | [ |
|---|
| 482 | 'name' => 'item_content_typography', |
|---|
| 483 | 'label' => __( 'Item Content Typography', 'cowidgets' ), |
|---|
| 484 | 'scheme' => Typography::TYPOGRAPHY_1, |
|---|
| 485 | 'selector' => '{{WRAPPER}} .ce-post-item .entry-content', |
|---|
| 486 | ] |
|---|
| 487 | ); |
|---|
| 488 | |
|---|
| 489 | $this->add_control( |
|---|
| 490 | 'item_content_color', |
|---|
| 491 | [ |
|---|
| 492 | 'label' => __( 'Item Content Color', 'cowidgets' ), |
|---|
| 493 | 'type' => \Elementor\Controls_Manager::COLOR, |
|---|
| 494 | |
|---|
| 495 | 'selectors' => [ |
|---|
| 496 | '{{WRAPPER}} .ce-post-item .entry-content' => 'color: {{VALUE}}', |
|---|
| 497 | ], |
|---|
| 498 | ] |
|---|
| 499 | ); |
|---|
| 500 | |
|---|
| 501 | $this->add_group_control( |
|---|
| 502 | \Elementor\Group_Control_Typography::get_type(), |
|---|
| 503 | [ |
|---|
| 504 | 'name' => 'item_readmore_typography', |
|---|
| 505 | 'label' => __( '"Continue Reading" Typography', 'cowidgets' ), |
|---|
| 506 | 'scheme' => Typography::TYPOGRAPHY_1, |
|---|
| 507 | 'selector' => '{{WRAPPER}} .ce-post-item .entry-readmore', |
|---|
| 508 | ] |
|---|
| 509 | ); |
|---|
| 510 | |
|---|
| 511 | $this->add_control( |
|---|
| 512 | 'item_readmore_color', |
|---|
| 513 | [ |
|---|
| 514 | 'label' => __( '"Continue Reading" Color', 'cowidgets' ), |
|---|
| 515 | 'type' => \Elementor\Controls_Manager::COLOR, |
|---|
| 516 | |
|---|
| 517 | 'selectors' => [ |
|---|
| 518 | '{{WRAPPER}} .ce-post-item a.entry-readmore' => 'color: {{VALUE}}', |
|---|
| 519 | ], |
|---|
| 520 | ] |
|---|
| 521 | ); |
|---|
| 522 | |
|---|
| 523 | |
|---|
| 524 | $this->end_controls_section(); |
|---|
| 525 | |
|---|
| 526 | $this->start_controls_section( |
|---|
| 527 | 'section_specific_style', |
|---|
| 528 | [ |
|---|
| 529 | 'label' => __( 'Style-specific', 'cowidgets' ), |
|---|
| 530 | 'tab' => Controls_Manager::TAB_STYLE, |
|---|
| 531 | ] |
|---|
| 532 | ); |
|---|
| 533 | |
|---|
| 534 | $this->add_control( |
|---|
| 535 | 'specific_important_note', |
|---|
| 536 | [ |
|---|
| 537 | 'type' => \Elementor\Controls_Manager::RAW_HTML, |
|---|
| 538 | 'raw' => __( 'This section contains style-specific options, these options may disappear when you change selected item-style', 'cowidgets' ), |
|---|
| 539 | 'content_classes' => 'important_note' |
|---|
| 540 | ] |
|---|
| 541 | ); |
|---|
| 542 | |
|---|
| 543 | $this->add_control( |
|---|
| 544 | 'adair_social_color', |
|---|
| 545 | [ |
|---|
| 546 | 'label' => __( 'Adair Socials Color', 'cowidgets' ), |
|---|
| 547 | 'type' => \Elementor\Controls_Manager::COLOR, |
|---|
| 548 | |
|---|
| 549 | 'selectors' => [ |
|---|
| 550 | '{{WRAPPER}} .ce-post-item .ce-share-buttons' => 'color: {{VALUE}}', |
|---|
| 551 | ], |
|---|
| 552 | 'condition' => [ |
|---|
| 553 | 'item_style' => 'adair' |
|---|
| 554 | ] |
|---|
| 555 | ] |
|---|
| 556 | ); |
|---|
| 557 | |
|---|
| 558 | $this->add_control( |
|---|
| 559 | 'adair_footer_borders', |
|---|
| 560 | [ |
|---|
| 561 | 'label' => __( 'Adair Footer Border Color', 'cowidgets' ), |
|---|
| 562 | 'type' => \Elementor\Controls_Manager::COLOR, |
|---|
| 563 | |
|---|
| 564 | 'selectors' => [ |
|---|
| 565 | '{{WRAPPER}} .ce-post-item .entry-footer' => 'border-color: {{VALUE}}', |
|---|
| 566 | ], |
|---|
| 567 | 'condition' => [ |
|---|
| 568 | 'item_style' => 'adair' |
|---|
| 569 | ] |
|---|
| 570 | ] |
|---|
| 571 | ); |
|---|
| 572 | |
|---|
| 573 | $this->add_control( |
|---|
| 574 | 'birk_wrapper_bg', |
|---|
| 575 | [ |
|---|
| 576 | 'label' => __( 'Birk Wrapper BG', 'cowidgets' ), |
|---|
| 577 | 'type' => \Elementor\Controls_Manager::COLOR, |
|---|
| 578 | |
|---|
| 579 | 'selectors' => [ |
|---|
| 580 | '{{WRAPPER}} .ce-post-item .entry-wrapper-content' => 'background-color: {{VALUE}}', |
|---|
| 581 | ], |
|---|
| 582 | 'condition' => [ |
|---|
| 583 | 'item_style' => 'birk' |
|---|
| 584 | ] |
|---|
| 585 | ] |
|---|
| 586 | ); |
|---|
| 587 | |
|---|
| 588 | $this->end_controls_section(); |
|---|
| 589 | |
|---|
| 590 | \COWIDGETS_Helpers::animationSection( $this ); |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | function set_source_type( $source ){ |
|---|
| 594 | $this->source_type = $source; |
|---|
| 595 | } |
|---|
| 596 | |
|---|
| 597 | function get_source_type(){ |
|---|
| 598 | return $this->source_type; |
|---|
| 599 | } |
|---|
| 600 | |
|---|
| 601 | /** |
|---|
| 602 | * Render Copyright output on the frontend. |
|---|
| 603 | * |
|---|
| 604 | * Written in PHP and used to generate the final HTML. |
|---|
| 605 | * |
|---|
| 606 | * @since 1.0.0 |
|---|
| 607 | * @access protected |
|---|
| 608 | */ |
|---|
| 609 | protected function render() { |
|---|
| 610 | $settings = $this->get_settings_for_display(); |
|---|
| 611 | |
|---|
| 612 | $this->add_render_attribute( 'ce-posts-carousel', 'class', [ 'ce-posts-carousel', 'ce-post-style-' . $settings['item_style'] ] ); |
|---|
| 613 | $this->add_render_attribute( 'ce-posts-carousel', 'data-columns', $settings['columns'] ); |
|---|
| 614 | $this->add_render_attribute( 'ce-posts-carousel', 'data-autoplay', $settings['autoplay'] ); |
|---|
| 615 | $this->add_render_attribute( 'ce-posts-carousel', 'data-slide-by', ( $settings['slide_by'] == 'page' ? $settings['columns'] : $settings['slide_by'] ) ); |
|---|
| 616 | $this->add_render_attribute( 'ce-posts-carousel', 'data-loop', $settings['loop'] ); |
|---|
| 617 | $this->add_render_attribute( 'ce-posts-carousel', 'data-gutter', $settings['gutter']['size'] ); |
|---|
| 618 | $this->add_render_attribute( 'ce-posts-carousel', 'data-center', $settings['center'] ); |
|---|
| 619 | $this->add_render_attribute( 'ce-posts-carousel', 'data-mouse-drag', $settings['mouse_drag'] ); |
|---|
| 620 | $this->add_render_attribute( 'ce-posts-carousel', 'data-edge-padding-side', $settings['edge_padding_side'] ); |
|---|
| 621 | $this->add_render_attribute( 'ce-posts-carousel', 'data-carousel-controls', $settings['carousel_controls'] ); |
|---|
| 622 | |
|---|
| 623 | $this->add_render_attribute( 'ce-post-item', 'class', ['ce-post-item'] ); |
|---|
| 624 | |
|---|
| 625 | if( $settings['ce_animation'] != 'none' ){ |
|---|
| 626 | $this->add_render_attribute( 'ce-post-item', 'class', ['ce-animation', 'ce-animation--'.$settings['ce_animation'], 'ce-animation-manual' ] ); |
|---|
| 627 | $this->add_render_attribute( 'ce-post-item', 'data-speed', $settings['ce_animation_speed'] ); |
|---|
| 628 | |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | if( isset( $settings['edge_padding'] ) && !empty( $settings['edge_padding'] ) ) |
|---|
| 632 | $this->add_render_attribute( 'ce-posts-carousel', 'data-edge-padding', $settings['edge_padding']['size'] ); |
|---|
| 633 | |
|---|
| 634 | if( isset( $settings['start_index'] ) && !empty( $settings['start_index'] ) ) |
|---|
| 635 | $this->add_render_attribute( 'ce-posts-carousel', 'data-start-index', $settings['start_index'] ); |
|---|
| 636 | |
|---|
| 637 | $final_image_size = $settings['image_size_size']; |
|---|
| 638 | |
|---|
| 639 | if($final_image_size == 'custom'){ |
|---|
| 640 | require_once ELEMENTOR_PATH . 'includes/libraries/bfi-thumb/bfi-thumb.php'; |
|---|
| 641 | |
|---|
| 642 | $image_dimension = $settings['image_size_custom_dimension']; |
|---|
| 643 | |
|---|
| 644 | $final_image_size = [ |
|---|
| 645 | // Defaults sizes. |
|---|
| 646 | 0 => null, // Width. |
|---|
| 647 | 1 => null, // Height. |
|---|
| 648 | |
|---|
| 649 | 'bfi_thumb' => true, |
|---|
| 650 | 'crop' => true, |
|---|
| 651 | ]; |
|---|
| 652 | |
|---|
| 653 | $has_custom_size = false; |
|---|
| 654 | if ( ! empty( $image_dimension['width'] ) ) { |
|---|
| 655 | $has_custom_size = true; |
|---|
| 656 | $final_image_size[0] = $image_dimension['width']; |
|---|
| 657 | } |
|---|
| 658 | |
|---|
| 659 | if ( ! empty( $image_dimension['height'] ) ) { |
|---|
| 660 | $has_custom_size = true; |
|---|
| 661 | $final_image_size[1] = $image_dimension['height']; |
|---|
| 662 | } |
|---|
| 663 | |
|---|
| 664 | if ( ! $has_custom_size ) { |
|---|
| 665 | $final_image_size = 'full'; |
|---|
| 666 | } |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | ?> |
|---|
| 670 | <?php if( $settings['carousel_controls'] ){ ?> |
|---|
| 671 | <div class="ce-carousel-head"> |
|---|
| 672 | <div class="ce-posts-carousel-controls"> |
|---|
| 673 | <a href="#" class="ce-prev"><i class="feather feather-arrow-left"></i></a> |
|---|
| 674 | <a href="#" class="ce-next"><i class="feather feather-arrow-right"></i></a> |
|---|
| 675 | </div> |
|---|
| 676 | </div> |
|---|
| 677 | <?php } ?> |
|---|
| 678 | <div <?php echo wp_kses_post( $this->get_render_attribute_string( 'ce-posts-carousel' ) ); ?>> |
|---|
| 679 | |
|---|
| 680 | <?php |
|---|
| 681 | |
|---|
| 682 | |
|---|
| 683 | $new_query = array( |
|---|
| 684 | 'posts_per_page' => (int) $settings['items_per_page'], |
|---|
| 685 | ); |
|---|
| 686 | |
|---|
| 687 | if( $settings['items_orderby'] != 'none' ){ |
|---|
| 688 | $new_query['orderby'] = $settings['items_orderby']; |
|---|
| 689 | $new_query['order'] = $settings['items_order']; |
|---|
| 690 | } |
|---|
| 691 | |
|---|
| 692 | if( is_array( $settings['items_categories'] ) && !empty( $settings['items_categories'] ) ) { |
|---|
| 693 | |
|---|
| 694 | $new_query['tax_query'] = array( |
|---|
| 695 | |
|---|
| 696 | array( |
|---|
| 697 | 'taxonomy' => 'category', |
|---|
| 698 | 'field' => 'slug', |
|---|
| 699 | 'terms' => $settings['items_categories'], |
|---|
| 700 | 'operator' => 'IN' |
|---|
| 701 | ) |
|---|
| 702 | ); |
|---|
| 703 | } |
|---|
| 704 | |
|---|
| 705 | if( !empty( $settings['posts'] ) ){ |
|---|
| 706 | $new_query['ignore_sticky_posts'] = 1; |
|---|
| 707 | $new_query['post__in'] = $settings['posts']; |
|---|
| 708 | $new_query['ignore_custom_sort'] = true; |
|---|
| 709 | } |
|---|
| 710 | |
|---|
| 711 | |
|---|
| 712 | $the_query = new \WP_Query( $new_query ); |
|---|
| 713 | |
|---|
| 714 | if ( is_object( $the_query ) && $the_query->have_posts() ) : |
|---|
| 715 | $counter = 0; |
|---|
| 716 | // Start loop |
|---|
| 717 | while ( $the_query->have_posts() ) : $the_query->the_post(); ?> |
|---|
| 718 | <?php |
|---|
| 719 | $counter += 1; |
|---|
| 720 | $delay = ( $counter * (int) $settings['ce_animation_delay'] ); |
|---|
| 721 | if( $counter > $settings['columns'] ) |
|---|
| 722 | $delay = 0; |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | $this->add_render_attribute( 'ce-post-item-'.get_the_ID(), 'data-delay', $delay ); |
|---|
| 726 | ?> |
|---|
| 727 | <?php |
|---|
| 728 | // Sanitize the item_style parameter |
|---|
| 729 | $sanitized_item_style = sanitize_file_name( $settings['item_style'] ); |
|---|
| 730 | |
|---|
| 731 | // Construct the file path |
|---|
| 732 | $file_path = COWIDGETS_DIR . '/inc/widgets-manager/widgets/content/partials/post/' . $sanitized_item_style . '.php'; |
|---|
| 733 | |
|---|
| 734 | // Validate the file path to ensure it's within the expected directory |
|---|
| 735 | if ( realpath($file_path) && strpos( realpath($file_path), realpath(COWIDGETS_DIR . '/inc/widgets-manager/widgets/content/partials/post/') ) === 0 ) { |
|---|
| 736 | // Include the file if it exists and is within the expected directory |
|---|
| 737 | include( $file_path ); |
|---|
| 738 | } else { |
|---|
| 739 | // Handle the error, e.g., show a default message or log the error |
|---|
| 740 | echo 'Invalid file path'; |
|---|
| 741 | } |
|---|
| 742 | ?> |
|---|
| 743 | |
|---|
| 744 | <?php endwhile; ?> |
|---|
| 745 | <?php wp_reset_postdata(); ?> |
|---|
| 746 | <?php endif; ?> |
|---|
| 747 | |
|---|
| 748 | |
|---|
| 749 | |
|---|
| 750 | |
|---|
| 751 | </div> |
|---|
| 752 | <?php |
|---|
| 753 | } |
|---|
| 754 | |
|---|
| 755 | |
|---|
| 756 | |
|---|
| 757 | /** |
|---|
| 758 | * Render shortcode widget output in the editor. |
|---|
| 759 | * |
|---|
| 760 | * Written as a Backbone JavaScript template and used to generate the live preview. |
|---|
| 761 | * |
|---|
| 762 | * @since 1.0.0 |
|---|
| 763 | * @access protected |
|---|
| 764 | */ |
|---|
| 765 | protected function content_template() {} |
|---|
| 766 | |
|---|
| 767 | /** |
|---|
| 768 | * Render shortcode output in the editor. |
|---|
| 769 | * |
|---|
| 770 | * Written as a Backbone JavaScript template and used to generate the live preview. |
|---|
| 771 | * |
|---|
| 772 | * Remove this after Elementor v3.3.0 |
|---|
| 773 | * |
|---|
| 774 | * @since 1.0.0 |
|---|
| 775 | * @access protected |
|---|
| 776 | */ |
|---|
| 777 | protected function _content_template() { |
|---|
| 778 | $this->content_template(); |
|---|
| 779 | } |
|---|
| 780 | } |
|---|