| @@ -1,492 +1,478 @@ | ||
| 1 | -<?php | |
| 2 | -namespace UiCoreElements; | |
| 3 | - | |
| 4 | -use Elementor\Controls_Manager; | |
| 5 | -use Elementor\Group_Control_Border; | |
| 6 | -use Elementor\Group_Control_Box_Shadow; | |
| 7 | -use Elementor\Group_Control_Typography; | |
| 8 | -use Elementor\Group_Control_Background; | |
| 9 | -use UiCoreElements\UiCoreWidget; | |
| 10 | - | |
| 11 | -use UiCore\Assets; | |
| 12 | -use UiCore\Portfolio; | |
| 13 | -use UiCore\Blog; | |
| 14 | -use UiCore\Helper; | |
| 15 | -use UiCoreElements\Controls\Post_Filter; | |
| 16 | -use UiCoreElements\Controls\Query; | |
| 17 | - | |
| 18 | -defined('ABSPATH') || exit(); | |
| 19 | - | |
| 20 | -/** | |
| 21 | - * Scripts and Styles Class | |
| 22 | - */ | |
| 23 | -class PostGrid extends UiCoreWidget | |
| 24 | -{ | |
| 25 | - private $_query; | |
| 26 | - | |
| 27 | - public function __construct($data = [], $args = null) | |
| 28 | - { | |
| 29 | - parent::__construct($data, $args); | |
| 30 | - } | |
| 31 | - public function get_name() | |
| 32 | - { | |
| 33 | - return 'uicore-post-grid'; | |
| 34 | - } | |
| 35 | - public function get_categories() | |
| 36 | - { | |
| 37 | - return ['uicore']; | |
| 38 | - } | |
| 39 | - public function get_title() | |
| 40 | - { | |
| 41 | - return __('Post Grid', 'uicore-elements'); | |
| 42 | - } | |
| 43 | - public function get_icon() | |
| 44 | - { | |
| 45 | - return 'eicon-gallery-grid ui-e-widget'; | |
| 46 | - } | |
| 47 | - public function get_keywords() | |
| 48 | - { | |
| 49 | - return ['post', 'grid', 'blog', 'recent', 'news']; | |
| 50 | - } | |
| 51 | - public function get_styles() | |
| 52 | - { | |
| 53 | - return []; | |
| 54 | - } | |
| 55 | - public function get_scripts() | |
| 56 | - { | |
| 57 | - return []; | |
| 58 | - } | |
| 59 | - | |
| 60 | - public function on_import($element) | |
| 61 | - { | |
| 62 | - if (!get_post_type_object($element['settings']['posts-filter_post_type'])) { | |
| 63 | - $element['settings']['posts-filter_post_type'] = 'post'; | |
| 64 | - } | |
| 65 | - | |
| 66 | - return $element; | |
| 67 | - } | |
| 68 | - public function on_export($element) | |
| 69 | - { | |
| 70 | - $element = Post_Filter::on_export_remove_setting_from_element($element, 'uicore-posts-filter'); | |
| 71 | - return $element; | |
| 72 | - } | |
| 73 | - | |
| 74 | - public function get_query() | |
| 75 | - { | |
| 76 | - return $this->_query; | |
| 77 | - } | |
| 78 | - | |
| 79 | - protected function register_controls() | |
| 80 | - { | |
| 81 | - | |
| 82 | - $default_columns = Helper::get_option('blog_col', 3); | |
| 83 | - | |
| 84 | - $this->start_controls_section('section_post_grid_def', [ | |
| 85 | - 'label' => esc_html__('Query', 'uicore-elements'), | |
| 86 | - ]); | |
| 87 | - | |
| 88 | - $this->add_group_control(Post_Filter::get_type(), [ | |
| 89 | - 'name' => 'posts-filter', | |
| 90 | - 'label' => esc_html__('Posts', 'uicore-elements'), | |
| 91 | - ]); | |
| 92 | - | |
| 93 | - $this->add_control('item_limit', [ | |
| 94 | - 'label' => esc_html__('Item Limit', 'uicore-elements'), | |
| 95 | - 'type' => Controls_Manager::SLIDER, | |
| 96 | - 'reder_type' => 'template', | |
| 97 | - 'range' => [ | |
| 98 | - 'px' => [ | |
| 99 | - 'min' => 1, | |
| 100 | - 'max' => 30, | |
| 101 | - ], | |
| 102 | - ], | |
| 103 | - 'default' => [ | |
| 104 | - 'size' => 3, | |
| 105 | - ], | |
| 106 | - ]); | |
| 107 | - $this->add_control('col_number', [ | |
| 108 | - 'label' => esc_html__('Columns Number', 'uicore-elements'), | |
| 109 | - 'type' => Controls_Manager::SLIDER, | |
| 110 | - 'reder_type' => 'template', | |
| 111 | - 'range' => [ | |
| 112 | - 'px' => [ | |
| 113 | - 'min' => 1, | |
| 114 | - 'max' => 4, | |
| 115 | - ], | |
| 116 | - ], | |
| 117 | - 'default' => [ | |
| 118 | - 'size' => $default_columns, | |
| 119 | - ], | |
| 120 | - ]); | |
| 121 | - | |
| 122 | - $this->end_controls_section(); | |
| 123 | - | |
| 124 | - $this->start_controls_section('section_post_grid_layout', [ | |
| 125 | - 'label' => esc_html__('Layout', 'uicore-elements'), | |
| 126 | - ]); | |
| 127 | - $this->add_control( | |
| 128 | - 'layout', | |
| 129 | - [ | |
| 130 | - 'label' => __( 'Item Style', 'uicore-elements' ), | |
| 131 | - 'type' => Controls_Manager::SELECT, | |
| 132 | - 'default' => 'default', | |
| 133 | - 'options' => [ | |
| 134 | - 'default' => __( 'Default', 'uicore-elements' ), | |
| 135 | - 'classic' => __( 'classic', 'uicore-elements' ), | |
| 136 | - 'grid' => __( 'Grid', 'uicore-elements' ), | |
| 137 | - 'horizontal' => __( 'Horizontal', 'uicore-elements' ), | |
| 138 | - 'masonry' => __( 'Masonry', 'uicore-elements' ), | |
| 139 | - ], | |
| 140 | - 'condition' => array( | |
| 141 | - 'posts-filter_post_type!' => 'portfolio', | |
| 142 | - ), | |
| 143 | - ] | |
| 144 | - ); | |
| 145 | - | |
| 146 | - $this->add_control( | |
| 147 | - 'box_style', | |
| 148 | - [ | |
| 149 | - 'label' => __( 'layout', 'uicore-elements' ), | |
| 150 | - 'type' => Controls_Manager::SELECT, | |
| 151 | - 'default' => 'default', | |
| 152 | - 'options' => [ | |
| 153 | - 'default' => __( 'Default', 'uicore-elements' ), | |
| 154 | - 'boxed' => __( 'Boxed', 'uicore-elements' ), | |
| 155 | - 'boxed-creative' => __( 'Boxed Creative', 'uicore-elements' ), | |
| 156 | - 'cover' => __( 'Cover', 'uicore-elements' ), | |
| 157 | - ], | |
| 158 | - 'condition' => array( | |
| 159 | - 'posts-filter_post_type!' => 'portfolio', | |
| 160 | - ), | |
| 161 | - ] | |
| 162 | - ); | |
| 163 | - | |
| 164 | - $this->add_control( | |
| 165 | - 'box_ratio', | |
| 166 | - [ | |
| 167 | - 'label' => __( 'Image Ratio', 'uicore-elements' ), | |
| 168 | - 'type' => Controls_Manager::SELECT, | |
| 169 | - 'default' => 'default', | |
| 170 | - 'options' => [ | |
| 171 | - 'default' => __( 'Default', 'uicore-elements' ), | |
| 172 | - 'square' => __( 'Square', 'uicore-elements' ), | |
| 173 | - 'landscape' => __( 'Landscape', 'uicore-elements' ), | |
| 174 | - 'portrait' => __( 'Portrait', 'uicore-elements' ), | |
| 175 | - ], | |
| 176 | - 'condition' => array( | |
| 177 | - 'posts-filter_post_type!' => 'portfolio', | |
| 178 | - ), | |
| 179 | - ] | |
| 180 | - ); | |
| 181 | - $this->add_control( | |
| 182 | - 'extra_author', | |
| 183 | - [ | |
| 184 | - 'label' => __( 'Author', 'uicore-elements' ), | |
| 185 | - 'type' => Controls_Manager::SWITCHER, | |
| 186 | - 'return_value' => 'yes', | |
| 187 | - 'default' => '', | |
| 188 | - 'reder_type' => 'template', | |
| 189 | - 'condition' => array( | |
| 190 | - 'posts-filter_post_type!' => 'portfolio', | |
| 191 | - ), | |
| 192 | - ] | |
| 193 | - ); | |
| 194 | - $this->add_control( | |
| 195 | - 'extra_date', | |
| 196 | - [ | |
| 197 | - 'label' => __( 'Date', 'uicore-elements' ), | |
| 198 | - 'type' => Controls_Manager::SWITCHER, | |
| 199 | - 'return_value' => 'yes', | |
| 200 | - 'default' => '', | |
| 201 | - 'reder_type' => 'template', | |
| 202 | - 'condition' => array( | |
| 203 | - 'posts-filter_post_type!' => 'portfolio', | |
| 204 | - ), | |
| 205 | - ] | |
| 206 | - ); | |
| 207 | - $this->add_control( | |
| 208 | - 'extra_excerpt', | |
| 209 | - [ | |
| 210 | - 'label' => __( 'Excerpt', 'uicore-elements' ), | |
| 211 | - 'type' => Controls_Manager::SWITCHER, | |
| 212 | - 'return_value' => 'yes', | |
| 213 | - 'default' => '', | |
| 214 | - 'reder_type' => 'template', | |
| 215 | - 'condition' => array( | |
| 216 | - 'posts-filter_post_type!' => 'portfolio', | |
| 217 | - ), | |
| 218 | - ] | |
| 219 | - ); | |
| 220 | - $this->add_control( | |
| 221 | - 'extra_category', | |
| 222 | - [ | |
| 223 | - 'label' => __( 'Category', 'uicore-elements' ), | |
| 224 | - 'type' => Controls_Manager::SWITCHER, | |
| 225 | - 'return_value' => 'yes', | |
| 226 | - 'default' => '', | |
| 227 | - 'reder_type' => 'template', | |
| 228 | - 'condition' => array( | |
| 229 | - 'posts-filter_post_type!' => 'portfolio', | |
| 230 | - ), | |
| 231 | - ] | |
| 232 | - ); | |
| 233 | - | |
| 234 | - $this->end_controls_section(); | |
| 235 | - | |
| 236 | - | |
| 237 | - $this->start_controls_section( | |
| 238 | - 'section_style_typo', | |
| 239 | - [ | |
| 240 | - 'label' => __( 'Content Style', 'uicore-elements' ), | |
| 241 | - 'tab' => Controls_Manager::TAB_STYLE, | |
| 242 | - ] | |
| 243 | - ); | |
| 244 | - | |
| 245 | - $this->add_control( | |
| 246 | - 'post_heading_title', | |
| 247 | - [ | |
| 248 | - 'label' => esc_html__( 'Post Title', 'uicore-elements' ), | |
| 249 | - 'type' => Controls_Manager::HEADING, | |
| 250 | - 'separator' => 'before', | |
| 251 | - ] | |
| 252 | - ); | |
| 253 | - | |
| 254 | - $this->add_control( | |
| 255 | - 'post_title_color', | |
| 256 | - [ | |
| 257 | - 'label' => esc_html__( 'Color', 'uicore-elements' ), | |
| 258 | - 'type' => Controls_Manager::COLOR, | |
| 259 | - 'default' => '', | |
| 260 | - 'selectors' => [ | |
| 261 | - '{{WRAPPER}} .uicore-post-title' => 'color: {{VALUE}};', | |
| 262 | - ], | |
| 263 | - ] | |
| 264 | - ); | |
| 265 | - | |
| 266 | - $this->add_group_control( | |
| 267 | - Group_Control_Typography::get_type(), | |
| 268 | - [ | |
| 269 | - 'name' => 'post_title_typography', | |
| 270 | - 'selector' => '{{WRAPPER}} .uicore-post-title, {{WRAPPER}} .uicore-post-title', | |
| 271 | - ] | |
| 272 | - ); | |
| 273 | - | |
| 274 | - | |
| 275 | - $this->add_control( | |
| 276 | - 'extra_excerpt_heading', | |
| 277 | - [ | |
| 278 | - 'label' => esc_html__( 'Excerpt', 'uicore-elements' ), | |
| 279 | - 'type' => Controls_Manager::HEADING, | |
| 280 | - 'separator' => 'before', | |
| 281 | - ] | |
| 282 | - ); | |
| 283 | - $this->add_responsive_control( | |
| 284 | - 'extra_excerpt_bottom_space', | |
| 285 | - [ | |
| 286 | - 'label' => esc_html__( 'Spacing', 'uicore-elements' ), | |
| 287 | - 'type' => Controls_Manager::SLIDER, | |
| 288 | - 'range' => [ | |
| 289 | - 'px' => [ | |
| 290 | - 'min' => 0, | |
| 291 | - 'max' => 100, | |
| 292 | - ], | |
| 293 | - ], | |
| 294 | - 'selectors' => [ | |
| 295 | - '{{WRAPPER}} .uicore-post-info-wrapper > p' => 'margin-top: {{SIZE}}{{UNIT}};', | |
| 296 | - ], | |
| 297 | - ] | |
| 298 | - ); | |
| 299 | - | |
| 300 | - $this->add_control( | |
| 301 | - 'extra_excerpt_color', | |
| 302 | - [ | |
| 303 | - 'label' => esc_html__( 'Color', 'uicore-elements' ), | |
| 304 | - 'type' => Controls_Manager::COLOR, | |
| 305 | - 'default' => '', | |
| 306 | - 'selectors' => [ | |
| 307 | - '{{WRAPPER}} .uicore-post-info-wrapper > p' => 'color: {{VALUE}};', | |
| 308 | - ], | |
| 309 | - ] | |
| 310 | - ); | |
| 311 | - | |
| 312 | - $this->add_group_control( | |
| 313 | - Group_Control_Typography::get_type(), | |
| 314 | - [ | |
| 315 | - 'name' => 'extra_excerpt_typography', | |
| 316 | - 'selector' => '{{WRAPPER}} .uicore-post-info-wrapper > p', | |
| 317 | - ] | |
| 318 | - ); | |
| 319 | - | |
| 320 | - | |
| 321 | - $this->add_responsive_control( | |
| 322 | - 'box_padding', | |
| 323 | - [ | |
| 324 | - 'label' => esc_html__( 'Content Padding', 'uicore-elements' ), | |
| 325 | - 'type' => Controls_Manager::DIMENSIONS, | |
| 326 | - 'size_units' => [ 'px', 'em', '%', 'rem' ], | |
| 327 | - 'separator' => 'before', | |
| 328 | - 'selectors' => [ | |
| 329 | - '{{WRAPPER}} .uicore-blog-grid .uicore-post .uicore-post-info' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;', | |
| 330 | - ], | |
| 331 | - ] | |
| 332 | - ); | |
| 333 | - | |
| 334 | - $this->add_group_control( | |
| 335 | - Group_Control_Background::get_type(), | |
| 336 | - [ | |
| 337 | - 'name' => 'box_background', | |
| 338 | - 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post', | |
| 339 | - ] | |
| 340 | - ); | |
| 341 | - | |
| 342 | - $this->add_group_control( | |
| 343 | - Group_Control_Border::get_type(), | |
| 344 | - [ | |
| 345 | - 'name' => 'box_border', | |
| 346 | - 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post', | |
| 347 | - 'separator' => 'before', | |
| 348 | - ] | |
| 349 | - ); | |
| 350 | - | |
| 351 | - $this->add_control( | |
| 352 | - 'box_border_radius', | |
| 353 | - [ | |
| 354 | - 'label' => esc_html__( 'Border Radius', 'uicore-elements' ), | |
| 355 | - 'type' => Controls_Manager::SLIDER, | |
| 356 | - 'range' => [ | |
| 357 | - 'px' => [ | |
| 358 | - 'min' => 0, | |
| 359 | - 'max' => 100, | |
| 360 | - ], | |
| 361 | - ], | |
| 362 | - 'selectors' => [ | |
| 363 | - '{{WRAPPER}} .uicore-blog-grid .uicore-post' => '--uicore-blog--radius: {{SIZE}}{{UNIT}};', | |
| 364 | - ], | |
| 365 | - ] | |
| 366 | - ); | |
| 367 | - | |
| 368 | - $this->add_group_control( | |
| 369 | - Group_Control_Box_Shadow::get_type(), | |
| 370 | - [ | |
| 371 | - 'name' => 'box_shadow_style', | |
| 372 | - 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post', | |
| 373 | - ] | |
| 374 | - ); | |
| 375 | - | |
| 376 | - | |
| 377 | - $this->end_controls_section(); | |
| 378 | - } | |
| 379 | - | |
| 380 | - public function query_posts($posts_per_page, $type = null) | |
| 381 | - { | |
| 382 | - $query_args = Query::get_query_args('posts-filter', $this->get_settings()); | |
| 383 | - | |
| 384 | - if($type === 'portfolio') { | |
| 385 | - $query_args['orderby'] = 'menu_order date'; | |
| 386 | - } | |
| 387 | - | |
| 388 | - $query_args['posts_per_page'] = $posts_per_page; | |
| 389 | - | |
| 390 | - $this->_query = new \WP_Query($query_args); | |
| 391 | - } | |
| 392 | - | |
| 393 | - protected function render() | |
| 394 | - { | |
| 395 | - $settings = $this->get_settings(); | |
| 396 | - | |
| 397 | - $col = $settings['col_number']['size']; | |
| 398 | - $type = $settings['posts-filter_post_type']; | |
| 399 | - | |
| 400 | - $blog_item_style = $settings['box_style']; | |
| 401 | - | |
| 402 | - if($type != 'portfolio'){ | |
| 403 | - | |
| 404 | - $type = str_replace(' ', '-', $blog_item_style); | |
| 405 | - if( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { | |
| 406 | - $content = ''; | |
| 407 | - | |
| 408 | - $content .= \file_get_contents( Assets::get_global('uicore-blog.css') ); | |
| 409 | - if($blog_item_style != 'default'){ | |
| 410 | - $content .= \file_get_contents(UICORE_ELEMENTS_ASSETS . '/css/post-grid.css'); | |
| 411 | - } | |
| 412 | - | |
| 413 | - ?> | |
| 414 | - <style> | |
| 415 | - <?php echo esc_html(wp_strip_all_tags($content)); ?> | |
| 416 | - </style> | |
| 417 | - <?php | |
| 418 | - } | |
| 419 | - else{ | |
| 420 | - if($blog_item_style != 'default'){ | |
| 421 | - wp_enqueue_style('uicore_blog_grid_'.$type, UICORE_ELEMENTS_ASSETS . '/css/post-grid.css', UICORE_ELEMENTS_VERSION); | |
| 422 | - } | |
| 423 | - } | |
| 424 | - | |
| 425 | - } | |
| 426 | - | |
| 427 | - $this->query_posts($settings['item_limit']['size'], $type); | |
| 428 | - $wp_query = $this->get_query(); | |
| 429 | - | |
| 430 | - if (!$wp_query->found_posts) { | |
| 431 | - echo 'No Posts Found!'; | |
| 432 | - return; | |
| 433 | - } | |
| 434 | - | |
| 435 | - | |
| 436 | - if ($type === 'portfolio') { | |
| 437 | - | |
| 438 | - if( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { | |
| 439 | - $content = ''; | |
| 440 | - $content .= \file_get_contents( Assets::get_global('uicore-portfolio.css') ); | |
| 441 | - ?> | |
| 442 | - <style> | |
| 443 | - <?php echo wp_strip_all_tags($content); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> | |
| 444 | - </style> | |
| 445 | - <?php | |
| 446 | - } | |
| 447 | - if(!class_exists('\UiCore\Portfolio\Frontend')){ | |
| 448 | - require_once UICORE_INCLUDES . '/portfolio/class-template.php'; | |
| 449 | - require_once UICORE_INCLUDES . '/portfolio/class-frontend.php'; | |
| 450 | - } | |
| 451 | - Portfolio\Frontend::frontend_css(true); | |
| 452 | - $portfolio = new Portfolio\Template('display'); | |
| 453 | - $portfolio->portfolio_layout($wp_query, null, $col); | |
| 454 | - | |
| 455 | - } else { | |
| 456 | - $layout = $settings['layout'] === 'default' ? null : $settings['layout']; | |
| 457 | - $style = $blog_item_style === 'default' ? null : $blog_item_style; | |
| 458 | - | |
| 459 | - if(isset($settings['box_ratio'])){ | |
| 460 | - $ratio = $settings['box_ratio'] === 'default' ? null : $settings['box_ratio']; | |
| 461 | - }else{//Fallback for older versions | |
| 462 | - $ratio = null; | |
| 463 | - } | |
| 464 | - if(isset($settings['extra_author'])){ | |
| 465 | - $extra = [ | |
| 466 | - 'author' => $settings['extra_author'] === 'yes' ? true : false, | |
| 467 | - 'date' => $settings['extra_date'] === 'yes' ? true : false, | |
| 468 | - 'excerpt' => $settings['extra_excerpt'] === 'yes' ? true : false, | |
| 469 | - 'category' => $settings['extra_category'] === 'yes' ? true : false | |
| 470 | - ]; | |
| 471 | - }else{ //Fallback for older versions | |
| 472 | - $extra = [ | |
| 473 | - 'author' => null, | |
| 474 | - 'date' => null, | |
| 475 | - 'excerpt' => null, | |
| 476 | - 'category' => null | |
| 477 | - ]; | |
| 478 | - } | |
| 479 | - | |
| 480 | - | |
| 481 | - if(!class_exists('\UiCore\Blog\Frontend')){ | |
| 482 | - require_once UICORE_INCLUDES . '/blog/class-template.php'; | |
| 483 | - require_once UICORE_INCLUDES . '/blog/class-frontend.php'; | |
| 484 | - } | |
| 485 | - Blog\Frontend::frontend_css(true); | |
| 486 | - $blog = new Blog\Template('display'); | |
| 487 | - $blog->blog_layout($wp_query, $layout, $col,null,$ratio,$extra, $style); | |
| 488 | - } | |
| 489 | - | |
| 490 | - } | |
| 491 | -} | |
| 492 | -\Elementor\Plugin::instance()->widgets_manager->register(new PostGrid()); | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace UiCoreElements; | |
| 4 | + | |
| 5 | +use Elementor\Controls_Manager; | |
| 6 | +use Elementor\Group_Control_Border; | |
| 7 | +use Elementor\Group_Control_Box_Shadow; | |
| 8 | +use Elementor\Group_Control_Typography; | |
| 9 | +use Elementor\Group_Control_Background; | |
| 10 | +use UiCoreElements\UiCoreWidget; | |
| 11 | + | |
| 12 | +use UiCore\Assets; | |
| 13 | +use UiCore\Portfolio; | |
| 14 | +use UiCore\Blog; | |
| 15 | +use UiCore\Helper; | |
| 16 | +use UiCoreElements\Controls\Post_Filter; | |
| 17 | +use UiCoreElements\Controls\Query; | |
| 18 | + | |
| 19 | +defined('ABSPATH') || exit(); | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * Post Grid | |
| 23 | + * | |
| 24 | + */ | |
| 25 | + | |
| 26 | +class PostGrid extends UiCoreWidget | |
| 27 | +{ | |
| 28 | + private $_query; | |
| 29 | + | |
| 30 | + public function __construct($data = [], $args = null) | |
| 31 | + { | |
| 32 | + parent::__construct($data, $args); | |
| 33 | + } | |
| 34 | + public function get_name() | |
| 35 | + { | |
| 36 | + return 'uicore-post-grid'; | |
| 37 | + } | |
| 38 | + public function get_categories() | |
| 39 | + { | |
| 40 | + return ['uicore']; | |
| 41 | + } | |
| 42 | + public function get_title() | |
| 43 | + { | |
| 44 | + return __('Post Grid', 'uicore-elements'); | |
| 45 | + } | |
| 46 | + public function get_icon() | |
| 47 | + { | |
| 48 | + return 'eicon-gallery-grid ui-e-widget'; | |
| 49 | + } | |
| 50 | + public function get_keywords() | |
| 51 | + { | |
| 52 | + return ['post', 'grid', 'blog', 'recent', 'news']; | |
| 53 | + } | |
| 54 | + public function get_styles() | |
| 55 | + { | |
| 56 | + return [ | |
| 57 | + 'post-grid', | |
| 58 | + // get framework assets | |
| 59 | + 'uicore-blog-st' => [ | |
| 60 | + 'external' => true, | |
| 61 | + ], | |
| 62 | + 'uicore-portfolio-st' => [ | |
| 63 | + 'external' => true, | |
| 64 | + 'condition' => [ | |
| 65 | + 'posts-filter_post_type' => 'portfolio', | |
| 66 | + ] | |
| 67 | + ] | |
| 68 | + ]; | |
| 69 | + } | |
| 70 | + public function get_scripts() | |
| 71 | + { | |
| 72 | + return []; | |
| 73 | + } | |
| 74 | + public function has_widget_inner_wrapper(): bool | |
| 75 | + { | |
| 76 | + // TODO: remove after Optmized Markup experiment is merged to the core | |
| 77 | + return ! \Elementor\Plugin::$instance->experiments->is_feature_active('e_optimized_markup'); | |
| 78 | + } | |
| 79 | + | |
| 80 | + public function on_import($element) | |
| 81 | + { | |
| 82 | + if (!get_post_type_object($element['settings']['posts-filter_post_type'])) { | |
| 83 | + $element['settings']['posts-filter_post_type'] = 'post'; | |
| 84 | + } | |
| 85 | + | |
| 86 | + return $element; | |
| 87 | + } | |
| 88 | + public function on_export($element) | |
| 89 | + { | |
| 90 | + $element = Post_Filter::on_export_remove_setting_from_element($element, 'uicore-posts-filter'); | |
| 91 | + return $element; | |
| 92 | + } | |
| 93 | + | |
| 94 | + public function get_query() | |
| 95 | + { | |
| 96 | + return $this->_query; | |
| 97 | + } | |
| 98 | + | |
| 99 | + protected function register_controls() | |
| 100 | + { | |
| 101 | + | |
| 102 | + $default_columns = Helper::get_option('blog_col', 3); | |
| 103 | + | |
| 104 | + $this->start_controls_section('section_post_grid_def', [ | |
| 105 | + 'label' => esc_html__('Query', 'uicore-elements'), | |
| 106 | + ]); | |
| 107 | + | |
| 108 | + $this->add_group_control(Post_Filter::get_type(), [ | |
| 109 | + 'name' => 'posts-filter', | |
| 110 | + 'label' => esc_html__('Posts', 'uicore-elements'), | |
| 111 | + ]); | |
| 112 | + | |
| 113 | + $this->add_control('item_limit', [ | |
| 114 | + 'label' => esc_html__('Item Limit', 'uicore-elements'), | |
| 115 | + 'type' => Controls_Manager::SLIDER, | |
| 116 | + 'reder_type' => 'template', | |
| 117 | + 'range' => [ | |
| 118 | + 'px' => [ | |
| 119 | + 'min' => 1, | |
| 120 | + 'max' => 30, | |
| 121 | + ], | |
| 122 | + ], | |
| 123 | + 'default' => [ | |
| 124 | + 'size' => 3, | |
| 125 | + ], | |
| 126 | + ]); | |
| 127 | + $this->add_control('col_number', [ | |
| 128 | + 'label' => esc_html__('Columns Number', 'uicore-elements'), | |
| 129 | + 'type' => Controls_Manager::SLIDER, | |
| 130 | + 'reder_type' => 'template', | |
| 131 | + 'range' => [ | |
| 132 | + 'px' => [ | |
| 133 | + 'min' => 1, | |
| 134 | + 'max' => 4, | |
| 135 | + ], | |
| 136 | + ], | |
| 137 | + 'default' => [ | |
| 138 | + 'size' => $default_columns, | |
| 139 | + ], | |
| 140 | + ]); | |
| 141 | + | |
| 142 | + $this->end_controls_section(); | |
| 143 | + | |
| 144 | + $this->start_controls_section('section_post_grid_layout', [ | |
| 145 | + 'label' => esc_html__('Layout', 'uicore-elements'), | |
| 146 | + ]); | |
| 147 | + $this->add_control( | |
| 148 | + 'layout', | |
| 149 | + [ | |
| 150 | + 'label' => __('Item Style', 'uicore-elements'), | |
| 151 | + 'type' => Controls_Manager::SELECT, | |
| 152 | + 'default' => 'default', | |
| 153 | + 'options' => [ | |
| 154 | + 'default' => __('Default', 'uicore-elements'), | |
| 155 | + 'classic' => __('classic', 'uicore-elements'), | |
| 156 | + 'grid' => __('Grid', 'uicore-elements'), | |
| 157 | + 'horizontal' => __('Horizontal', 'uicore-elements'), | |
| 158 | + 'masonry' => __('Masonry', 'uicore-elements'), | |
| 159 | + ], | |
| 160 | + 'condition' => array( | |
| 161 | + 'posts-filter_post_type!' => 'portfolio', | |
| 162 | + ), | |
| 163 | + ] | |
| 164 | + ); | |
| 165 | + | |
| 166 | + $this->add_control( | |
| 167 | + 'box_style', | |
| 168 | + [ | |
| 169 | + 'label' => __('layout', 'uicore-elements'), | |
| 170 | + 'type' => Controls_Manager::SELECT, | |
| 171 | + 'default' => 'default', | |
| 172 | + 'options' => [ | |
| 173 | + 'default' => __('Default', 'uicore-elements'), | |
| 174 | + 'boxed' => __('Boxed', 'uicore-elements'), | |
| 175 | + 'boxed-creative' => __('Boxed Creative', 'uicore-elements'), | |
| 176 | + 'cover' => __('Cover', 'uicore-elements'), | |
| 177 | + ], | |
| 178 | + 'condition' => array( | |
| 179 | + 'posts-filter_post_type!' => 'portfolio', | |
| 180 | + ), | |
| 181 | + ] | |
| 182 | + ); | |
| 183 | + | |
| 184 | + $this->add_control( | |
| 185 | + 'box_ratio', | |
| 186 | + [ | |
| 187 | + 'label' => __('Image Ratio', 'uicore-elements'), | |
| 188 | + 'type' => Controls_Manager::SELECT, | |
| 189 | + 'default' => 'default', | |
| 190 | + 'options' => [ | |
| 191 | + 'default' => __('Default', 'uicore-elements'), | |
| 192 | + 'square' => __('Square', 'uicore-elements'), | |
| 193 | + 'landscape' => __('Landscape', 'uicore-elements'), | |
| 194 | + 'portrait' => __('Portrait', 'uicore-elements'), | |
| 195 | + ], | |
| 196 | + 'condition' => array( | |
| 197 | + 'posts-filter_post_type!' => 'portfolio', | |
| 198 | + ), | |
| 199 | + ] | |
| 200 | + ); | |
| 201 | + $this->add_control( | |
| 202 | + 'extra_author', | |
| 203 | + [ | |
| 204 | + 'label' => __('Author', 'uicore-elements'), | |
| 205 | + 'type' => Controls_Manager::SWITCHER, | |
| 206 | + 'return_value' => 'yes', | |
| 207 | + 'default' => '', | |
| 208 | + 'reder_type' => 'template', | |
| 209 | + 'condition' => array( | |
| 210 | + 'posts-filter_post_type!' => 'portfolio', | |
| 211 | + ), | |
| 212 | + ] | |
| 213 | + ); | |
| 214 | + $this->add_control( | |
| 215 | + 'extra_date', | |
| 216 | + [ | |
| 217 | + 'label' => __('Date', 'uicore-elements'), | |
| 218 | + 'type' => Controls_Manager::SWITCHER, | |
| 219 | + 'return_value' => 'yes', | |
| 220 | + 'default' => '', | |
| 221 | + 'reder_type' => 'template', | |
| 222 | + 'condition' => array( | |
| 223 | + 'posts-filter_post_type!' => 'portfolio', | |
| 224 | + ), | |
| 225 | + ] | |
| 226 | + ); | |
| 227 | + $this->add_control( | |
| 228 | + 'extra_excerpt', | |
| 229 | + [ | |
| 230 | + 'label' => __('Excerpt', 'uicore-elements'), | |
| 231 | + 'type' => Controls_Manager::SWITCHER, | |
| 232 | + 'return_value' => 'yes', | |
| 233 | + 'default' => '', | |
| 234 | + 'reder_type' => 'template', | |
| 235 | + 'condition' => array( | |
| 236 | + 'posts-filter_post_type!' => 'portfolio', | |
| 237 | + ), | |
| 238 | + ] | |
| 239 | + ); | |
| 240 | + $this->add_control( | |
| 241 | + 'extra_category', | |
| 242 | + [ | |
| 243 | + 'label' => __('Category', 'uicore-elements'), | |
| 244 | + 'type' => Controls_Manager::SWITCHER, | |
| 245 | + 'return_value' => 'yes', | |
| 246 | + 'default' => '', | |
| 247 | + 'reder_type' => 'template', | |
| 248 | + 'condition' => array( | |
| 249 | + 'posts-filter_post_type!' => 'portfolio', | |
| 250 | + ), | |
| 251 | + ] | |
| 252 | + ); | |
| 253 | + | |
| 254 | + $this->end_controls_section(); | |
| 255 | + | |
| 256 | + | |
| 257 | + $this->start_controls_section( | |
| 258 | + 'section_style_typo', | |
| 259 | + [ | |
| 260 | + 'label' => __('Content Style', 'uicore-elements'), | |
| 261 | + 'tab' => Controls_Manager::TAB_STYLE, | |
| 262 | + ] | |
| 263 | + ); | |
| 264 | + | |
| 265 | + $this->add_control( | |
| 266 | + 'post_heading_title', | |
| 267 | + [ | |
| 268 | + 'label' => esc_html__('Post Title', 'uicore-elements'), | |
| 269 | + 'type' => Controls_Manager::HEADING, | |
| 270 | + 'separator' => 'before', | |
| 271 | + ] | |
| 272 | + ); | |
| 273 | + | |
| 274 | + $this->add_control( | |
| 275 | + 'post_title_color', | |
| 276 | + [ | |
| 277 | + 'label' => esc_html__('Color', 'uicore-elements'), | |
| 278 | + 'type' => Controls_Manager::COLOR, | |
| 279 | + 'default' => '', | |
| 280 | + 'selectors' => [ | |
| 281 | + '{{WRAPPER}} .uicore-post-title' => 'color: {{VALUE}};', | |
| 282 | + ], | |
| 283 | + ] | |
| 284 | + ); | |
| 285 | + | |
| 286 | + $this->add_group_control( | |
| 287 | + Group_Control_Typography::get_type(), | |
| 288 | + [ | |
| 289 | + 'name' => 'post_title_typography', | |
| 290 | + 'selector' => '{{WRAPPER}} .uicore-post-title, {{WRAPPER}} .uicore-post-title', | |
| 291 | + ] | |
| 292 | + ); | |
| 293 | + | |
| 294 | + | |
| 295 | + $this->add_control( | |
| 296 | + 'extra_excerpt_heading', | |
| 297 | + [ | |
| 298 | + 'label' => esc_html__('Excerpt', 'uicore-elements'), | |
| 299 | + 'type' => Controls_Manager::HEADING, | |
| 300 | + 'separator' => 'before', | |
| 301 | + ] | |
| 302 | + ); | |
| 303 | + $this->add_responsive_control( | |
| 304 | + 'extra_excerpt_bottom_space', | |
| 305 | + [ | |
| 306 | + 'label' => esc_html__('Spacing', 'uicore-elements'), | |
| 307 | + 'type' => Controls_Manager::SLIDER, | |
| 308 | + 'range' => [ | |
| 309 | + 'px' => [ | |
| 310 | + 'min' => 0, | |
| 311 | + 'max' => 100, | |
| 312 | + ], | |
| 313 | + ], | |
| 314 | + 'selectors' => [ | |
| 315 | + '{{WRAPPER}} .uicore-post-info-wrapper > p' => 'margin-top: {{SIZE}}{{UNIT}};', | |
| 316 | + ], | |
| 317 | + ] | |
| 318 | + ); | |
| 319 | + | |
| 320 | + $this->add_control( | |
| 321 | + 'extra_excerpt_color', | |
| 322 | + [ | |
| 323 | + 'label' => esc_html__('Color', 'uicore-elements'), | |
| 324 | + 'type' => Controls_Manager::COLOR, | |
| 325 | + 'default' => '', | |
| 326 | + 'selectors' => [ | |
| 327 | + '{{WRAPPER}} .uicore-post-info-wrapper > p' => 'color: {{VALUE}};', | |
| 328 | + ], | |
| 329 | + ] | |
| 330 | + ); | |
| 331 | + | |
| 332 | + $this->add_group_control( | |
| 333 | + Group_Control_Typography::get_type(), | |
| 334 | + [ | |
| 335 | + 'name' => 'extra_excerpt_typography', | |
| 336 | + 'selector' => '{{WRAPPER}} .uicore-post-info-wrapper > p', | |
| 337 | + ] | |
| 338 | + ); | |
| 339 | + | |
| 340 | + | |
| 341 | + $this->add_responsive_control( | |
| 342 | + 'box_padding', | |
| 343 | + [ | |
| 344 | + 'label' => esc_html__('Content Padding', 'uicore-elements'), | |
| 345 | + 'type' => Controls_Manager::DIMENSIONS, | |
| 346 | + 'size_units' => ['px', 'em', '%', 'rem'], | |
| 347 | + 'separator' => 'before', | |
| 348 | + 'selectors' => [ | |
| 349 | + '{{WRAPPER}} .uicore-blog-grid .uicore-post .uicore-post-info' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;', | |
| 350 | + ], | |
| 351 | + ] | |
| 352 | + ); | |
| 353 | + | |
| 354 | + $this->add_group_control( | |
| 355 | + Group_Control_Background::get_type(), | |
| 356 | + [ | |
| 357 | + 'name' => 'box_background', | |
| 358 | + 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post', | |
| 359 | + ] | |
| 360 | + ); | |
| 361 | + | |
| 362 | + $this->add_group_control( | |
| 363 | + Group_Control_Border::get_type(), | |
| 364 | + [ | |
| 365 | + 'name' => 'box_border', | |
| 366 | + 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post', | |
| 367 | + 'separator' => 'before', | |
| 368 | + ] | |
| 369 | + ); | |
| 370 | + | |
| 371 | + $this->add_control( | |
| 372 | + 'box_border_radius', | |
| 373 | + [ | |
| 374 | + 'label' => esc_html__('Border Radius', 'uicore-elements'), | |
| 375 | + 'type' => Controls_Manager::SLIDER, | |
| 376 | + 'range' => [ | |
| 377 | + 'px' => [ | |
| 378 | + 'min' => 0, | |
| 379 | + 'max' => 100, | |
| 380 | + ], | |
| 381 | + ], | |
| 382 | + 'selectors' => [ | |
| 383 | + '{{WRAPPER}} .uicore-blog-grid .uicore-post' => '--uicore-blog--radius: {{SIZE}}{{UNIT}};', | |
| 384 | + ], | |
| 385 | + ] | |
| 386 | + ); | |
| 387 | + | |
| 388 | + $this->add_group_control( | |
| 389 | + Group_Control_Box_Shadow::get_type(), | |
| 390 | + [ | |
| 391 | + 'name' => 'box_shadow_style', | |
| 392 | + 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post', | |
| 393 | + ] | |
| 394 | + ); | |
| 395 | + | |
| 396 | + | |
| 397 | + $this->end_controls_section(); | |
| 398 | + } | |
| 399 | + | |
| 400 | + public function query_posts($posts_per_page, $type = null) | |
| 401 | + { | |
| 402 | + $query_args = Query::get_query_args('posts-filter', $this->get_settings()); | |
| 403 | + | |
| 404 | + if ($type === 'portfolio') { | |
| 405 | + $query_args['orderby'] = 'menu_order date'; | |
| 406 | + } | |
| 407 | + | |
| 408 | + $query_args['posts_per_page'] = $posts_per_page; | |
| 409 | + | |
| 410 | + $this->_query = new \WP_Query($query_args); | |
| 411 | + } | |
| 412 | + | |
| 413 | + protected function render() | |
| 414 | + { | |
| 415 | + $settings = $this->get_settings(); | |
| 416 | + | |
| 417 | + $col = $settings['col_number']['size']; | |
| 418 | + $type = $settings['posts-filter_post_type']; | |
| 419 | + | |
| 420 | + if ($type != 'portfolio') { | |
| 421 | + $type = str_replace(' ', '-', $settings['box_style']); | |
| 422 | + } | |
| 423 | + | |
| 424 | + $this->query_posts($settings['item_limit']['size'], $type); | |
| 425 | + $wp_query = $this->get_query(); | |
| 426 | + | |
| 427 | + if (!$wp_query->found_posts) { | |
| 428 | + echo 'No Posts Found!'; | |
| 429 | + return; | |
| 430 | + } | |
| 431 | + | |
| 432 | + | |
| 433 | + if ($type === 'portfolio') { | |
| 434 | + | |
| 435 | + if (!class_exists('\UiCore\Portfolio\Frontend')) { | |
| 436 | + require_once UICORE_INCLUDES . '/portfolio/class-template.php'; | |
| 437 | + require_once UICORE_INCLUDES . '/portfolio/class-frontend.php'; | |
| 438 | + } | |
| 439 | + Portfolio\Frontend::frontend_css(true); | |
| 440 | + $portfolio = new Portfolio\Template('display'); | |
| 441 | + $portfolio->portfolio_layout($wp_query, null, $col); | |
| 442 | + } else { | |
| 443 | + $layout = $settings['layout'] === 'default' ? null : $settings['layout']; | |
| 444 | + $style = $settings['box_style'] === 'default' ? null : $settings['box_style']; | |
| 445 | + | |
| 446 | + if (isset($settings['box_ratio'])) { | |
| 447 | + $ratio = $settings['box_ratio'] === 'default' ? null : $settings['box_ratio']; | |
| 448 | + } else { //Fallback for older versions | |
| 449 | + $ratio = null; | |
| 450 | + } | |
| 451 | + if (isset($settings['extra_author'])) { | |
| 452 | + $extra = [ | |
| 453 | + 'author' => $this->is_option('extra_author', 'yes'), | |
| 454 | + 'date' => $this->is_option('extra_date', 'yes'), | |
| 455 | + 'excerpt' => $this->is_option('extra_excerpt', 'yes'), | |
| 456 | + 'category' => $this->is_option('extra_category', 'yes') | |
| 457 | + ]; | |
| 458 | + } else { //Fallback for older versions | |
| 459 | + $extra = [ | |
| 460 | + 'author' => null, | |
| 461 | + 'date' => null, | |
| 462 | + 'excerpt' => null, | |
| 463 | + 'category' => null | |
| 464 | + ]; | |
| 465 | + } | |
| 466 | + | |
| 467 | + | |
| 468 | + if (!class_exists('\UiCore\Blog\Frontend')) { | |
| 469 | + require_once UICORE_INCLUDES . '/blog/class-template.php'; | |
| 470 | + require_once UICORE_INCLUDES . '/blog/class-frontend.php'; | |
| 471 | + } | |
| 472 | + Blog\Frontend::frontend_css(true); | |
| 473 | + $blog = new Blog\Template('display'); | |
| 474 | + $blog->blog_layout($wp_query, $layout, $col, null, $ratio, $extra, $style); | |
| 475 | + } | |
| 476 | + } | |
| 477 | +} | |
| 478 | +\Elementor\Plugin::instance()->widgets_manager->register(new PostGrid()); | |