| 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 Portfolio Grid |
|---|
| 24 | * |
|---|
| 25 | * Elementor widget for Portfolio Grid. |
|---|
| 26 | * |
|---|
| 27 | * @since 1.0.0 |
|---|
| 28 | */ |
|---|
| 29 | class Portfolio_Grid 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-portfolio-grid'; |
|---|
| 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 __( 'Portfolio Grid', '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-portfolio-grid'; |
|---|
| 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-portfolio-grid' ]; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | /** |
|---|
| 92 | * Register controls. |
|---|
| 93 | * |
|---|
| 94 | * @since 1.0.0 |
|---|
| 95 | * @access protected |
|---|
| 96 | */ |
|---|
| 97 | protected function register_controls() { |
|---|
| 98 | $this->register_portfolio_grid_controls(); |
|---|
| 99 | } |
|---|
| 100 | /** |
|---|
| 101 | * Register General Controls. |
|---|
| 102 | * |
|---|
| 103 | * @since 1.0.0 |
|---|
| 104 | * @access protected |
|---|
| 105 | */ |
|---|
| 106 | protected function register_portfolio_grid_controls() { |
|---|
| 107 | \COWIDGETS_Helpers::portfolioSelectionSection( $this ); |
|---|
| 108 | $this->start_controls_section( |
|---|
| 109 | 'section_content_style', |
|---|
| 110 | [ |
|---|
| 111 | 'label' => __( 'Item Layout/Style', 'cowidgets' ), |
|---|
| 112 | 'tab' => Controls_Manager::TAB_CONTENT, |
|---|
| 113 | ] |
|---|
| 114 | ); |
|---|
| 115 | |
|---|
| 116 | $this->add_control( |
|---|
| 117 | 'item_style', |
|---|
| 118 | [ |
|---|
| 119 | 'label' => __( 'Style', 'cowidgets' ), |
|---|
| 120 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 121 | 'default' => 'beas', |
|---|
| 122 | 'options' => apply_filters( 'ce_load_element_styles', [ |
|---|
| 123 | 'simple' => __( 'Simple', 'cowidgets' ), |
|---|
| 124 | 'beas' => __( 'Beas', 'cowidgets' ), |
|---|
| 125 | 'jasper' => __( 'Jasper', 'cowidgets' ), |
|---|
| 126 | 'ishmi' => __( 'Ishmi', 'cowidgets' ), |
|---|
| 127 | 'amber' => __( 'Amber', 'cowidgets' ), |
|---|
| 128 | 'erzen' => __( 'Erzen', 'cowidgets' ), |
|---|
| 129 | 'alder' => __( 'Alder', 'cowidgets' ), |
|---|
| 130 | 'remake' => __( 'Remake', 'cowidgets' ), |
|---|
| 131 | ] ), |
|---|
| 132 | ] |
|---|
| 133 | ); |
|---|
| 134 | |
|---|
| 135 | $this->add_control( |
|---|
| 136 | 'module', |
|---|
| 137 | [ |
|---|
| 138 | 'label' => __( 'Grid Module', 'cowidgets' ), |
|---|
| 139 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 140 | 'default' => 'isotope', |
|---|
| 141 | 'options' => [ |
|---|
| 142 | 'isotope' => __( 'Standard Isotope (with Filters)', 'cowidgets' ), |
|---|
| 143 | 'predefined' => __( 'Predefined Blocks (Parallax)', 'cowidgets' ), |
|---|
| 144 | 'justify' => __( 'Justify Gallery', 'cowidgets' ), |
|---|
| 145 | ], |
|---|
| 146 | ] |
|---|
| 147 | ); |
|---|
| 148 | |
|---|
| 149 | $this->add_group_control( |
|---|
| 150 | Group_Control_Image_Size::get_type(), |
|---|
| 151 | [ |
|---|
| 152 | 'name' => 'image_size', |
|---|
| 153 | 'label' => __( 'Image Size', 'cowidgets' ), |
|---|
| 154 | 'default' => 'medium', |
|---|
| 155 | ] |
|---|
| 156 | ); |
|---|
| 157 | $this->add_control( |
|---|
| 158 | 'icon', |
|---|
| 159 | [ |
|---|
| 160 | 'label' => __( 'Icon', 'text-domain' ), |
|---|
| 161 | 'type' => \Elementor\Controls_Manager::ICONS, |
|---|
| 162 | 'default' => [ |
|---|
| 163 | 'value' => 'fas fa-star', |
|---|
| 164 | 'library' => 'solid', |
|---|
| 165 | ], |
|---|
| 166 | 'condition' => [ |
|---|
| 167 | 'item_style' => ['alder'] |
|---|
| 168 | ] |
|---|
| 169 | ] |
|---|
| 170 | ); |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | $this->end_controls_section(); |
|---|
| 174 | |
|---|
| 175 | $this->start_controls_section( |
|---|
| 176 | 'section_content_module', |
|---|
| 177 | [ |
|---|
| 178 | 'label' => __( 'Module Options', 'cowidgets' ), |
|---|
| 179 | 'tab' => Controls_Manager::TAB_CONTENT, |
|---|
| 180 | ] |
|---|
| 181 | ); |
|---|
| 182 | |
|---|
| 183 | $this->add_control( |
|---|
| 184 | 'isotope_layout', |
|---|
| 185 | [ |
|---|
| 186 | 'label' => __( 'Isotope Layout', 'cowidgets' ), |
|---|
| 187 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 188 | 'default' => 'masonry', |
|---|
| 189 | 'options' => [ |
|---|
| 190 | 'masonry' => __( 'Masonry', 'cowidgets' ), |
|---|
| 191 | 'fitRows' => __( 'FitRows', 'cowidgets' ) |
|---|
| 192 | ], |
|---|
| 193 | 'render_type' => 'template', |
|---|
| 194 | 'condition' => [ |
|---|
| 195 | 'module' => 'isotope' |
|---|
| 196 | ] |
|---|
| 197 | ] |
|---|
| 198 | ); |
|---|
| 199 | |
|---|
| 200 | $this->add_control( |
|---|
| 201 | 'columns', |
|---|
| 202 | [ |
|---|
| 203 | 'label' => __( 'Columns', 'cowidgets' ), |
|---|
| 204 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 205 | 'default' => 3, |
|---|
| 206 | 'options' => [ |
|---|
| 207 | 1 => __( '1', 'cowidgets' ), |
|---|
| 208 | 2 => __( '2', 'cowidgets' ), |
|---|
| 209 | 3 => __( '3', 'cowidgets' ), |
|---|
| 210 | 4 => __( '4', 'cowidgets' ), |
|---|
| 211 | 5 => __( '5', 'cowidgets' ), |
|---|
| 212 | ], |
|---|
| 213 | 'render_type' => 'template', |
|---|
| 214 | 'condition' => [ |
|---|
| 215 | 'module' => ['isotope'] |
|---|
| 216 | ] |
|---|
| 217 | ] |
|---|
| 218 | ); |
|---|
| 219 | |
|---|
| 220 | $this->add_responsive_control( |
|---|
| 221 | 'space_between', |
|---|
| 222 | [ |
|---|
| 223 | 'label' => __( 'Space between items', 'cowidgets' ), |
|---|
| 224 | 'type' => Controls_Manager::SLIDER, |
|---|
| 225 | 'size_units' => ['px'], |
|---|
| 226 | 'range' => [ |
|---|
| 227 | 'px' => [ |
|---|
| 228 | 'max' => 500, |
|---|
| 229 | 'min' => 0, |
|---|
| 230 | ], |
|---|
| 231 | ], |
|---|
| 232 | 'default' => [ |
|---|
| 233 | 'unit' => 'px', |
|---|
| 234 | 'size' => 15 |
|---|
| 235 | ], |
|---|
| 236 | 'selectors' => [ |
|---|
| 237 | '{{WRAPPER}} .ce-portfolio-grid .ce-portfolio-item' => 'padding: {{SIZE}}{{UNIT}}', |
|---|
| 238 | '{{WRAPPER}} .ce-portfolio-grid' => 'margin-left: -{{SIZE}}{{UNIT}}; margin-right: -{{SIZE}}{{UNIT}}' |
|---|
| 239 | ], |
|---|
| 240 | 'render_type' => 'template', |
|---|
| 241 | 'condition' => [ |
|---|
| 242 | 'module' => 'isotope' |
|---|
| 243 | ] |
|---|
| 244 | ] |
|---|
| 245 | ); |
|---|
| 246 | $this->add_control( |
|---|
| 247 | 'isotope_filters', |
|---|
| 248 | [ |
|---|
| 249 | 'label' => __( 'Isotope Filters', 'cowidgets' ), |
|---|
| 250 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 251 | 'default' => 0, |
|---|
| 252 | 'options' => [ |
|---|
| 253 | 0 => __( 'No', 'cowidgets' ), |
|---|
| 254 | 1 => __( 'Yes', 'cowidgets' ) |
|---|
| 255 | ], |
|---|
| 256 | 'render_type' => 'template', |
|---|
| 257 | 'condition' => [ |
|---|
| 258 | 'module' => 'isotope' |
|---|
| 259 | ] |
|---|
| 260 | ] |
|---|
| 261 | ); |
|---|
| 262 | $this->add_control( |
|---|
| 263 | 'filters_style', |
|---|
| 264 | [ |
|---|
| 265 | 'label' => __( 'Filters Style', 'cowidgets' ), |
|---|
| 266 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 267 | 'default' => 'default', |
|---|
| 268 | 'options' => [ |
|---|
| 269 | 'default' => __( 'Default', 'cowidgets' ), |
|---|
| 270 | 'vertical' => __( 'Vertical', 'cowidgets' ) |
|---|
| 271 | |
|---|
| 272 | ], |
|---|
| 273 | 'render_type' => 'template', |
|---|
| 274 | 'condition' => [ |
|---|
| 275 | 'module' => 'isotope' |
|---|
| 276 | ] |
|---|
| 277 | ] |
|---|
| 278 | ); |
|---|
| 279 | $this->add_control( |
|---|
| 280 | 'filters_layout', |
|---|
| 281 | [ |
|---|
| 282 | 'label' => __( 'Isotope Filters Alingment', 'cowidgets' ), |
|---|
| 283 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 284 | 'default' => 0, |
|---|
| 285 | 'options' => [ |
|---|
| 286 | 'left' => __( 'Left', 'cowidgets' ), |
|---|
| 287 | 'right' => __( 'Right', 'cowidgets' ), |
|---|
| 288 | 'center' => __( 'Center', 'cowidgets' ) |
|---|
| 289 | |
|---|
| 290 | ], |
|---|
| 291 | 'render_type' => 'template', |
|---|
| 292 | 'condition' => [ |
|---|
| 293 | 'module' => 'isotope', |
|---|
| 294 | 'filters_style' => 'default' |
|---|
| 295 | ] |
|---|
| 296 | ] |
|---|
| 297 | ); |
|---|
| 298 | $this->add_control( |
|---|
| 299 | 'predefined_blocks', |
|---|
| 300 | [ |
|---|
| 301 | 'label' => __( 'Predefined Portfolio Blocks', 'cowidgets' ), |
|---|
| 302 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 303 | 'default' => 'block_1', |
|---|
| 304 | 'options' => [ |
|---|
| 305 | 'block_1' => __( 'Block 1', 'cowidgets' ), |
|---|
| 306 | 'block_2' => __( 'Block 2', 'cowidgets' ), |
|---|
| 307 | 'block_3' => __( 'Block 3', 'cowidgets' ), |
|---|
| 308 | 'block_4' => __( 'Block 4', 'cowidgets' ) |
|---|
| 309 | ], |
|---|
| 310 | 'render_type' => 'template', |
|---|
| 311 | 'condition' => [ |
|---|
| 312 | 'module' => 'predefined' |
|---|
| 313 | ] |
|---|
| 314 | ] |
|---|
| 315 | ); |
|---|
| 316 | |
|---|
| 317 | $this->add_control( |
|---|
| 318 | 'predefined_parallax', |
|---|
| 319 | [ |
|---|
| 320 | 'label' => __( 'Vertical Parallax', 'cowidgets' ), |
|---|
| 321 | 'type' => \Elementor\Controls_Manager::SELECT, |
|---|
| 322 | 'default' => 0, |
|---|
| 323 | 'options' => [ |
|---|
| 324 | 0 => __( 'No', 'cowidgets' ), |
|---|
| 325 | 1 => __( 'Yes', 'cowidgets' ) |
|---|
| 326 | ], |
|---|
| 327 | 'render_type' => 'template', |
|---|
| 328 | 'condition' => [ |
|---|
| 329 | 'module' => 'predefined' |
|---|
| 330 | ] |
|---|
| 331 | ] |
|---|
| 332 | ); |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | $this->end_controls_section(); |
|---|
| 336 | |
|---|
| 337 | $this->start_controls_section( |
|---|
| 338 | 'section_style', |
|---|
| 339 | [ |
|---|
| 340 | 'label' => __( 'Global', 'cowidgets' ), |
|---|
| 341 | 'tab' => Controls_Manager::TAB_STYLE |
|---|
| 342 | ] |
|---|
| 343 | ); |
|---|
| 344 | |
|---|
| 345 | $this->add_control( |
|---|
| 346 | 'global_important_note', |
|---|
| 347 | [ |
|---|
| 348 | 'type' => \Elementor\Controls_Manager::RAW_HTML, |
|---|
| 349 | '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' ), |
|---|
| 350 | 'content_classes' => 'important_note' |
|---|
| 351 | ] |
|---|
| 352 | ); |
|---|
| 353 | |
|---|
| 354 | $this->add_group_control( |
|---|
| 355 | \Elementor\Group_Control_Typography::get_type(), |
|---|
| 356 | [ |
|---|
| 357 | 'name' => 'item_title_typography', |
|---|
| 358 | 'label' => __( 'Item Title Typography', 'plugin-domain' ), |
|---|
| 359 | 'scheme' => Typography::TYPOGRAPHY_1, |
|---|
| 360 | 'selector' => '{{WRAPPER}} .ce-portfolio-item .portfolio-title, body.ce-portfolio-follow-erzen .ce-fixed-follow .portfolio-title', |
|---|
| 361 | ] |
|---|
| 362 | ); |
|---|
| 363 | |
|---|
| 364 | $this->add_group_control( |
|---|
| 365 | \Elementor\Group_Control_Typography::get_type(), |
|---|
| 366 | [ |
|---|
| 367 | 'name' => 'filter_links_typography', |
|---|
| 368 | 'label' => __( 'Filter Links Typography', 'plugin-domain' ), |
|---|
| 369 | 'scheme' => Typography::TYPOGRAPHY_1, |
|---|
| 370 | 'selector' => '{{WRAPPER}} .ce-filters button', |
|---|
| 371 | 'condition' => [ |
|---|
| 372 | 'module' => 'predefined' |
|---|
| 373 | ] |
|---|
| 374 | ] |
|---|
| 375 | ); |
|---|
| 376 | |
|---|
| 377 | $this->add_control( |
|---|
| 378 | 'item_title_color', |
|---|
| 379 | [ |
|---|
| 380 | 'label' => __( 'Item Title Color', 'cowidgets' ), |
|---|
| 381 | 'type' => \Elementor\Controls_Manager::COLOR, |
|---|
| 382 | |
|---|
| 383 | 'selectors' => [ |
|---|
| 384 | '{{WRAPPER}} .ce-portfolio-item .portfolio-title, body.ce-portfolio-follow-erzen .ce-fixed-follow .portfolio-title' => 'color: {{VALUE}}', |
|---|
| 385 | ], |
|---|
| 386 | ] |
|---|
| 387 | ); |
|---|
| 388 | |
|---|
| 389 | $this->add_group_control( |
|---|
| 390 | \Elementor\Group_Control_Typography::get_type(), |
|---|
| 391 | [ |
|---|
| 392 | 'name' => 'item_cats_typography', |
|---|
| 393 | 'label' => __( 'Item Categories Typography', 'plugin-domain' ), |
|---|
| 394 | 'scheme' => Typography::TYPOGRAPHY_1, |
|---|
| 395 | 'selector' => '{{WRAPPER}} .ce-portfolio-item .portfolio-categories, body.ce-portfolio-follow-erzen .ce-fixed-follow .portfolio-categories', |
|---|
| 396 | ] |
|---|
| 397 | ); |
|---|
| 398 | |
|---|
| 399 | $this->add_control( |
|---|
| 400 | 'item_cats_color', |
|---|
| 401 | [ |
|---|
| 402 | 'label' => __( 'Item Categories Color', 'cowidgets' ), |
|---|
| 403 | 'type' => \Elementor\Controls_Manager::COLOR, |
|---|
| 404 | |
|---|
| 405 | 'selectors' => [ |
|---|
| 406 | '{{WRAPPER}} .ce-portfolio-item .portfolio-categories, body.ce-portfolio-follow-erzen .ce-fixed-follow .portfolio-categories' => 'color: {{VALUE}}', |
|---|
| 407 | ], |
|---|
| 408 | ] |
|---|
| 409 | ); |
|---|
| 410 | |
|---|
| 411 | $this->end_controls_section(); |
|---|
| 412 | |
|---|
| 413 | $this->start_controls_section( |
|---|
| 414 | 'section_specific_style', |
|---|
| 415 | [ |
|---|
| 416 | 'label' => __( 'Style-specific', 'cowidgets' ), |
|---|
| 417 | 'tab' => Controls_Manager::TAB_STYLE, |
|---|
| 418 | ] |
|---|
| 419 | ); |
|---|
| 420 | |
|---|
| 421 | $this->add_control( |
|---|
| 422 | 'specific_important_note', |
|---|
| 423 | [ |
|---|
| 424 | 'type' => \Elementor\Controls_Manager::RAW_HTML, |
|---|
| 425 | 'raw' => __( 'This section contains style-specific options, these options may disappear when you change selected item-style', 'cowidgets' ), |
|---|
| 426 | 'content_classes' => 'important_note' |
|---|
| 427 | ] |
|---|
| 428 | ); |
|---|
| 429 | |
|---|
| 430 | do_action( 'ce_load_style_specific_options', $this ); |
|---|
| 431 | |
|---|
| 432 | $this->add_control( |
|---|
| 433 | 'beas_bg_color', |
|---|
| 434 | [ |
|---|
| 435 | 'label' => __( 'Beas Content BG Color', 'cowidgets' ), |
|---|
| 436 | 'type' => \Elementor\Controls_Manager::COLOR, |
|---|
| 437 | |
|---|
| 438 | 'selectors' => [ |
|---|
| 439 | '{{WRAPPER}} .ce-portfolio-item .entry-content' => 'background-color: {{VALUE}}', |
|---|
| 440 | ], |
|---|
| 441 | 'condition' => [ |
|---|
| 442 | 'item_style' => 'beas' |
|---|
| 443 | ] |
|---|
| 444 | ] |
|---|
| 445 | ); |
|---|
| 446 | |
|---|
| 447 | $this->add_control( |
|---|
| 448 | 'ishmi_number_color', |
|---|
| 449 | [ |
|---|
| 450 | 'label' => __( 'Ishmi Number Color', 'cowidgets' ), |
|---|
| 451 | 'type' => \Elementor\Controls_Manager::COLOR, |
|---|
| 452 | 'selectors' => [ |
|---|
| 453 | '{{WRAPPER}} .ce-portfolio-item .title .number' => 'color: {{VALUE}}', |
|---|
| 454 | ], |
|---|
| 455 | 'condition' => [ |
|---|
| 456 | 'item_style' => 'ishmi' |
|---|
| 457 | ] |
|---|
| 458 | ] |
|---|
| 459 | ); |
|---|
| 460 | |
|---|
| 461 | $this->add_control( |
|---|
| 462 | 'effect_bg_color', |
|---|
| 463 | [ |
|---|
| 464 | 'label' => __( 'Effect BG Color', 'cowidgets' ), |
|---|
| 465 | 'type' => \Elementor\Controls_Manager::COLOR, |
|---|
| 466 | 'selectors' => [ |
|---|
| 467 | '{{WRAPPER}} .ce-portfolio-item .entry-media .post-thumbnail:before' => 'background-color: {{VALUE}}', |
|---|
| 468 | ], |
|---|
| 469 | 'condition' => [ |
|---|
| 470 | 'item_style' => ['ishmi', 'erzen', 'amber'] |
|---|
| 471 | ] |
|---|
| 472 | ] |
|---|
| 473 | ); |
|---|
| 474 | |
|---|
| 475 | $this->add_control( |
|---|
| 476 | 'remake_preview_text', |
|---|
| 477 | [ |
|---|
| 478 | 'label' => __( 'Remake "Preview" text', 'cowidgets' ), |
|---|
| 479 | 'type' => \Elementor\Controls_Manager::TEXT, |
|---|
| 480 | |
|---|
| 481 | 'default' => esc_html( 'Preview', 'cowidgets' ), |
|---|
| 482 | 'condition' => [ |
|---|
| 483 | 'item_style' => 'remake' |
|---|
| 484 | ] |
|---|
| 485 | ] |
|---|
| 486 | ); |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | $this->end_controls_section(); |
|---|
| 490 | |
|---|
| 491 | \COWIDGETS_Helpers::animationSection( $this ); |
|---|
| 492 | } |
|---|
| 493 | |
|---|
| 494 | function set_source_type( $source ){ |
|---|
| 495 | $this->source_type = $source; |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | function get_source_type(){ |
|---|
| 499 | return $this->source_type; |
|---|
| 500 | } |
|---|
| 501 | |
|---|
| 502 | |
|---|
| 503 | function get_gallery_categories( $items ){ |
|---|
| 504 | $categories = []; |
|---|
| 505 | if( $items ){ |
|---|
| 506 | foreach( $items as $item ){ |
|---|
| 507 | $caption = wp_get_attachment_caption( $item ); |
|---|
| 508 | $cat_filtered = strtolower( str_replace( ' ', '-', $caption ) ); |
|---|
| 509 | if( ! isset( $categories[$cat_filtered]) ) |
|---|
| 510 | $categories[$cat_filtered] = $caption; |
|---|
| 511 | } |
|---|
| 512 | } |
|---|
| 513 | |
|---|
| 514 | return $categories; |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | /** |
|---|
| 518 | * Render Copyright output on the frontend. |
|---|
| 519 | * |
|---|
| 520 | * Written in PHP and used to generate the final HTML. |
|---|
| 521 | * |
|---|
| 522 | * @since 1.0.0 |
|---|
| 523 | * @access protected |
|---|
| 524 | */ |
|---|
| 525 | protected function render() { |
|---|
| 526 | $settings = $this->get_settings_for_display(); |
|---|
| 527 | |
|---|
| 528 | $this->set_source_type( $settings['source_type'] ); |
|---|
| 529 | |
|---|
| 530 | $this->add_render_attribute( 'ce-portfolio-grid', 'class', [ 'ce-portfolio-grid', 'ce-portfolio-style-' . $settings['item_style'] ] ); |
|---|
| 531 | $this->add_render_attribute( 'ce-portfolio-grid', 'data-columns', $settings['columns'] ); |
|---|
| 532 | $this->add_render_attribute( 'ce-portfolio-grid', 'data-module', $settings['module'] ); |
|---|
| 533 | $this->add_render_attribute( 'ce-portfolio-grid', 'data-style', $settings['item_style'] ); |
|---|
| 534 | |
|---|
| 535 | $this->add_render_attribute( 'ce-portfolio-grid', 'class', $settings['source_type'] . '-source_type' ); |
|---|
| 536 | |
|---|
| 537 | if( $settings['item_style'] == 'erzen' ) |
|---|
| 538 | $this->add_render_attribute( 'ce-portfolio-grid', 'data-follow', '1' ); |
|---|
| 539 | |
|---|
| 540 | $this->add_render_attribute( 'ce-portfolio-grid', 'data-parallax', $settings['predefined_parallax'] ); |
|---|
| 541 | |
|---|
| 542 | if( $settings['module'] == 'isotope' ){ |
|---|
| 543 | $this->add_render_attribute( 'ce-portfolio-grid', 'data-layout', $settings['isotope_layout'] ); |
|---|
| 544 | |
|---|
| 545 | $gallery_filters = []; |
|---|
| 546 | if( $settings['source_type'] == 'gallery' && $settings['isotope_filters'] ){ |
|---|
| 547 | $gallery_filters = $this->get_gallery_categories( $this->get_gallery_image_ids( $settings['items_gallery'] ) ); |
|---|
| 548 | } |
|---|
| 549 | $this->add_render_attribute( 'ce-portfolio-grid-wrapper', 'class', 'ce-portfolio-grid-wrapper' ); |
|---|
| 550 | $this->add_render_attribute( 'ce-portfolio-grid-wrapper', 'data-filters', $settings['isotope_filters'] ); |
|---|
| 551 | $this->add_render_attribute( 'ce-portfolio-grid-wrapper', 'data-filters-style', $settings['filters_style'] ); |
|---|
| 552 | } |
|---|
| 553 | |
|---|
| 554 | if( $settings['module'] == 'predefined' ){ |
|---|
| 555 | $this->add_render_attribute( 'ce-portfolio-grid', 'class', 'ce-portfolio-predefined--'.$settings['predefined_blocks'] ); |
|---|
| 556 | |
|---|
| 557 | if( $settings['predefined_parallax'] && $settings['predefined_blocks'] == 'block_2' ){ |
|---|
| 558 | $this->add_render_attribute( 'ce-portfolio-item', 'class', 'rellax' ); |
|---|
| 559 | $this->add_render_attribute( 'ce-portfolio-item', 'data-rellax-percentage', '0.5' ); |
|---|
| 560 | $this->add_render_attribute( 'ce-portfolio-item', 'data-rellax-min', '-100' ); |
|---|
| 561 | $this->add_render_attribute( 'ce-portfolio-item', 'data-rellax-max', '100' ); |
|---|
| 562 | } |
|---|
| 563 | |
|---|
| 564 | } |
|---|
| 565 | |
|---|
| 566 | $this->add_render_attribute( 'ce-portfolio-item', 'class', ['ce-portfolio-item'] ); |
|---|
| 567 | |
|---|
| 568 | if( $settings['ce_animation'] != 'none' ){ |
|---|
| 569 | $this->add_render_attribute( 'ce-portfolio-item', 'class', ['ce-animation', 'ce-animation--'.$settings['ce_animation'] ] ); |
|---|
| 570 | $this->add_render_attribute( 'ce-portfolio-item', 'data-speed', $settings['ce_animation_speed'] ); |
|---|
| 571 | if( $settings['module'] == 'isotope' ) |
|---|
| 572 | $this->add_render_attribute( 'ce-portfolio-item', 'class', 'ce-animation-manual' ); |
|---|
| 573 | } |
|---|
| 574 | |
|---|
| 575 | $final_image_size = $settings['image_size_size']; |
|---|
| 576 | |
|---|
| 577 | if($final_image_size == 'custom'){ |
|---|
| 578 | require_once ELEMENTOR_PATH . 'includes/libraries/bfi-thumb/bfi-thumb.php'; |
|---|
| 579 | |
|---|
| 580 | $image_dimension = $settings['image_size_custom_dimension']; |
|---|
| 581 | |
|---|
| 582 | $final_image_size = [ |
|---|
| 583 | // Defaults sizes. |
|---|
| 584 | 0 => null, // Width. |
|---|
| 585 | 1 => null, // Height. |
|---|
| 586 | |
|---|
| 587 | 'bfi_thumb' => true, |
|---|
| 588 | 'crop' => true, |
|---|
| 589 | ]; |
|---|
| 590 | |
|---|
| 591 | $has_custom_size = false; |
|---|
| 592 | if ( ! empty( $image_dimension['width'] ) ) { |
|---|
| 593 | $has_custom_size = true; |
|---|
| 594 | $final_image_size[0] = $image_dimension['width']; |
|---|
| 595 | } |
|---|
| 596 | |
|---|
| 597 | if ( ! empty( $image_dimension['height'] ) ) { |
|---|
| 598 | $has_custom_size = true; |
|---|
| 599 | $final_image_size[1] = $image_dimension['height']; |
|---|
| 600 | } |
|---|
| 601 | |
|---|
| 602 | if ( ! $has_custom_size ) { |
|---|
| 603 | $final_image_size = 'full'; |
|---|
| 604 | } |
|---|
| 605 | } |
|---|
| 606 | |
|---|
| 607 | ?> |
|---|
| 608 | |
|---|
| 609 | <div <?php echo wp_kses_post( $this->get_render_attribute_string( 'ce-portfolio-grid-wrapper' ) ); ?>> |
|---|
| 610 | |
|---|
| 611 | <?php |
|---|
| 612 | if ( $settings['isotope_filters'] ) : |
|---|
| 613 | // Define the path to the filter.php file |
|---|
| 614 | $file_path = COWIDGETS_DIR . '/inc/widgets-manager/widgets/content/partials/portfolio/filter.php'; |
|---|
| 615 | |
|---|
| 616 | // Validate the file path to ensure it's within the expected directory |
|---|
| 617 | if ( realpath($file_path) && strpos( realpath($file_path), realpath(COWIDGETS_DIR . '/inc/widgets-manager/widgets/content/partials/portfolio/') ) === 0 ) { |
|---|
| 618 | // Include the file if it exists and is within the expected directory |
|---|
| 619 | include( $file_path ); |
|---|
| 620 | } else { |
|---|
| 621 | // Handle the error, e.g., show a default message or log the error |
|---|
| 622 | echo 'Invalid file path'; |
|---|
| 623 | } |
|---|
| 624 | endif; |
|---|
| 625 | ?> |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | <div <?php echo wp_kses_post( $this->get_render_attribute_string( 'ce-portfolio-grid' ) ); ?>> |
|---|
| 629 | |
|---|
| 630 | <?php |
|---|
| 631 | |
|---|
| 632 | if( $settings['source_type'] == 'portfolio' ){ |
|---|
| 633 | $new_query = array( |
|---|
| 634 | 'posts_per_page' => (int) $settings['items_per_page'], |
|---|
| 635 | 'post_type' => 'portfolio' |
|---|
| 636 | ); |
|---|
| 637 | |
|---|
| 638 | if( $settings['items_orderby'] != 'none' ){ |
|---|
| 639 | $new_query['orderby'] = $settings['items_orderby']; |
|---|
| 640 | $new_query['order'] = $settings['items_order']; |
|---|
| 641 | } |
|---|
| 642 | |
|---|
| 643 | if( is_array( $settings['items_categories'] ) && !empty( $settings['items_categories'] ) ) { |
|---|
| 644 | |
|---|
| 645 | $new_query['tax_query'] = array( |
|---|
| 646 | |
|---|
| 647 | array( |
|---|
| 648 | 'taxonomy' => 'portfolio_entries', |
|---|
| 649 | 'field' => 'slug', |
|---|
| 650 | 'terms' => $settings['items_categories'], |
|---|
| 651 | 'operator' => 'IN' |
|---|
| 652 | ) |
|---|
| 653 | ); |
|---|
| 654 | } |
|---|
| 655 | |
|---|
| 656 | if( !empty( $settings['items_portfolio'] ) ){ |
|---|
| 657 | $new_query['ignore_sticky_posts'] = 1; |
|---|
| 658 | $new_query['post__in'] = $settings['items_portfolio']; |
|---|
| 659 | $new_query['ignore_custom_sort'] = true; |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | if( !empty( $settings['items_portfolio_exclude'] ) ){ |
|---|
| 663 | $new_query['ignore_sticky_posts'] = 1; |
|---|
| 664 | $new_query['post__not_in'] = $settings['items_portfolio_exclude']; |
|---|
| 665 | $new_query['ignore_custom_sort'] = true; |
|---|
| 666 | } |
|---|
| 667 | |
|---|
| 668 | }else if( $settings['source_type'] == 'all_post_types' ) { |
|---|
| 669 | $new_query['post__in'] = $settings['items_posts']; |
|---|
| 670 | |
|---|
| 671 | }else if( $settings['source_type'] == 'gallery' ){ |
|---|
| 672 | |
|---|
| 673 | $new_query = array( |
|---|
| 674 | 'post__in' => $this->get_gallery_image_ids( $settings['items_gallery'] ), |
|---|
| 675 | 'post_status' => 'any', |
|---|
| 676 | 'orderby' => 'post__in', |
|---|
| 677 | 'post_type' => 'attachment', |
|---|
| 678 | 'posts_per_page' => '-1' |
|---|
| 679 | ); |
|---|
| 680 | |
|---|
| 681 | |
|---|
| 682 | } |
|---|
| 683 | |
|---|
| 684 | |
|---|
| 685 | $the_query = new \WP_Query( $new_query ); |
|---|
| 686 | |
|---|
| 687 | if ( is_object( $the_query ) && $the_query->have_posts() ) : |
|---|
| 688 | $counter = 0; |
|---|
| 689 | |
|---|
| 690 | // used for separate items with columns in HTML |
|---|
| 691 | $column1 = $column2 = $column3 = ''; |
|---|
| 692 | |
|---|
| 693 | // Start loop |
|---|
| 694 | while ( $the_query->have_posts() ) : $the_query->the_post(); ?> |
|---|
| 695 | <?php |
|---|
| 696 | |
|---|
| 697 | $counter += 1; |
|---|
| 698 | $delay = ( $counter * (int) $settings['ce_animation_delay'] ); |
|---|
| 699 | if( $counter > $settings['columns'] ) |
|---|
| 700 | $delay = 0; |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | $this->add_render_attribute( 'ce-portfolio-item-'.get_the_ID(), 'data-delay', $delay ); |
|---|
| 704 | |
|---|
| 705 | if( $settings['predefined_parallax'] && $settings['predefined_blocks'] == 'block_2' ){ |
|---|
| 706 | $this->add_render_attribute( 'ce-portfolio-item-'.get_the_ID(), 'data-rellax-speed', wp_rand(-2,-1) ); |
|---|
| 707 | $this->add_render_attribute( 'ce-portfolio-item-'.get_the_ID(), 'data-rellax-mobile-speed', 0); |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | |
|---|
| 711 | if( $settings['source_type'] == 'gallery' && $settings['isotope_filters'] ) |
|---|
| 712 | $this->add_render_attribute( 'ce-portfolio-item-'.get_the_ID(), 'data-caption', strtolower( str_replace( ' ', '-', wp_get_attachment_caption( ) ) ) ); |
|---|
| 713 | |
|---|
| 714 | if( $settings['source_type'] != 'gallery' && $settings['isotope_filters'] ) |
|---|
| 715 | $this->add_render_attribute( 'ce-portfolio-item-'.get_the_ID(), 'data-category', strtolower( str_replace(' ', '-', esc_html( wp_strip_all_tags( get_the_term_list( get_the_ID(), 'portfolio_entries', '', ',', '' ) ) ) ) ) ); |
|---|
| 716 | ?> |
|---|
| 717 | <?php |
|---|
| 718 | if ( $settings['module'] == 'predefined' && $settings['predefined_blocks'] == 'block_3' ) { |
|---|
| 719 | ob_start(); |
|---|
| 720 | $sanitized_item_style = sanitize_file_name( $settings['item_style'] ); |
|---|
| 721 | $file_path = COWIDGETS_DIR . '/inc/widgets-manager/widgets/content/partials/portfolio/' . $sanitized_item_style . '.php'; |
|---|
| 722 | |
|---|
| 723 | if ( realpath($file_path) && strpos( realpath($file_path), realpath(COWIDGETS_DIR . '/inc/widgets-manager/widgets/content/partials/portfolio/') ) === 0 ) { |
|---|
| 724 | include( $file_path ); |
|---|
| 725 | } else { |
|---|
| 726 | // Handle the error, e.g., show a default message or log the error |
|---|
| 727 | echo 'Invalid file path'; |
|---|
| 728 | } |
|---|
| 729 | |
|---|
| 730 | if( $counter % 2 ) { |
|---|
| 731 | $column1 .= ob_get_clean(); |
|---|
| 732 | } else { |
|---|
| 733 | $column2 .= ob_get_clean(); |
|---|
| 734 | } |
|---|
| 735 | } else { |
|---|
| 736 | $sanitized_item_style = sanitize_file_name( $settings['item_style'] ); |
|---|
| 737 | $file_path = COWIDGETS_DIR . '/inc/widgets-manager/widgets/content/partials/portfolio/' . $sanitized_item_style . '.php'; |
|---|
| 738 | |
|---|
| 739 | if ( realpath($file_path) && strpos( realpath($file_path), realpath(COWIDGETS_DIR . '/inc/widgets-manager/widgets/content/partials/portfolio/') ) === 0 ) { |
|---|
| 740 | include( $file_path ); |
|---|
| 741 | } else { |
|---|
| 742 | // Handle the error, e.g., show a default message or log the error |
|---|
| 743 | echo 'Invalid file path'; |
|---|
| 744 | } |
|---|
| 745 | } |
|---|
| 746 | ?> |
|---|
| 747 | |
|---|
| 748 | <?php endwhile; ?> |
|---|
| 749 | <?php wp_reset_postdata(); ?> |
|---|
| 750 | |
|---|
| 751 | <?php if( $settings['module'] == 'predefined' & $settings['predefined_blocks'] == 'block_3' ){ |
|---|
| 752 | echo '<div class="column1 rellax" data-rellax-speed="-2">'; |
|---|
| 753 | echo wp_kses_post($column1); |
|---|
| 754 | echo '</div>'; |
|---|
| 755 | |
|---|
| 756 | echo '<div class="column2 rellax" data-rellax-speed="4">'; |
|---|
| 757 | echo wp_kses_post($column2); |
|---|
| 758 | echo '</div>'; |
|---|
| 759 | } ?> |
|---|
| 760 | |
|---|
| 761 | <?php endif; ?> |
|---|
| 762 | |
|---|
| 763 | </div> |
|---|
| 764 | |
|---|
| 765 | |
|---|
| 766 | </div> |
|---|
| 767 | |
|---|
| 768 | <?php |
|---|
| 769 | } |
|---|
| 770 | |
|---|
| 771 | |
|---|
| 772 | |
|---|
| 773 | function get_gallery_image_ids( $gallery ){ |
|---|
| 774 | $ids = []; |
|---|
| 775 | |
|---|
| 776 | if( $gallery ) |
|---|
| 777 | foreach( $gallery as $item ){ |
|---|
| 778 | $ids[] = $item['id']; |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| 781 | return $ids; |
|---|
| 782 | } |
|---|
| 783 | |
|---|
| 784 | |
|---|
| 785 | |
|---|
| 786 | /** |
|---|
| 787 | * Render shortcode widget output in the editor. |
|---|
| 788 | * |
|---|
| 789 | * Written as a Backbone JavaScript template and used to generate the live preview. |
|---|
| 790 | * |
|---|
| 791 | * @since 1.0.0 |
|---|
| 792 | * @access protected |
|---|
| 793 | */ |
|---|
| 794 | protected function content_template() {} |
|---|
| 795 | |
|---|
| 796 | /** |
|---|
| 797 | * Render shortcode output in the editor. |
|---|
| 798 | * |
|---|
| 799 | * Written as a Backbone JavaScript template and used to generate the live preview. |
|---|
| 800 | * |
|---|
| 801 | * Remove this after Elementor v3.3.0 |
|---|
| 802 | * |
|---|
| 803 | * @since 1.0.0 |
|---|
| 804 | * @access protected |
|---|
| 805 | */ |
|---|
| 806 | protected function _content_template() { |
|---|
| 807 | $this->content_template(); |
|---|
| 808 | } |
|---|
| 809 | } |
|---|