EduardET

Untitled

Jun 29th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 26.63 KB | None | 0 0
  1. <?php
  2. class WPC_ET_Builder_Module_Filterable_Portfolio extends ET_Builder_Module_Type_PostBased {
  3.     function init() {
  4.         $this->name       = esc_html__( 'WPC Filterable Portfolio', 'et_builder' );
  5.         $this->slug       = 'wpc_et_pb_filterable_portfolio';
  6.         $this->fb_support = false;
  7.  
  8.         $this->whitelisted_fields = array(
  9.             'fullwidth',
  10.             'posts_number',
  11.             'include_categories',
  12.             'show_title',
  13.             'show_categories',
  14.             'show_pagination',
  15.             'background_layout',
  16.             'admin_label',
  17.             'module_id',
  18.             'module_class',
  19.             'hover_icon',
  20.             'zoom_icon_color',
  21.             'hover_overlay_color',
  22.             'box_shadow_style_image',
  23.             'box_shadow_horizontal_image',
  24.             'box_shadow_vertical_image',
  25.             'box_shadow_blur_image',
  26.             'box_shadow_spread_image',
  27.             'box_shadow_color_image',
  28.             'box_shadow_position_image',
  29.         );
  30.  
  31.         $this->fields_defaults = array(
  32.             'fullwidth'         => array( 'on' ),
  33.             'posts_number'      => array( 10, 'add_default_setting' ),
  34.             'show_title'        => array( 'on' ),
  35.             'show_categories'   => array( 'on' ),
  36.             'show_pagination'   => array( 'on' ),
  37.             'background_layout' => array( 'light' ),
  38.         );
  39.  
  40.         $this->main_css_element = '%%order_class%%.et_pb_filterable_portfolio';
  41.  
  42.         $this->options_toggles = array(
  43.             'general'  => array(
  44.                 'toggles' => array(
  45.                     'main_content' => esc_html__( 'Content', 'et_builder' ),
  46.                     'elements'     => esc_html__( 'Elements', 'et_builder' ),
  47.                 ),
  48.             ),
  49.             'advanced' => array(
  50.                 'toggles' => array(
  51.                     'layout'  => esc_html__( 'Layout', 'et_builder' ),
  52.                     'overlay' => esc_html__( 'Overlay', 'et_builder' ),
  53.                     'text'    => array(
  54.                         'title'    => esc_html__( 'Text', 'et_builder' ),
  55.                         'priority' => 49,
  56.                     ),
  57.                     'image' => esc_html__( 'Image', 'et_builder' ),
  58.                 ),
  59.             ),
  60.         );
  61.  
  62.         $this->advanced_options = array(
  63.             'fonts' => array(
  64.                 'title'   => array(
  65.                     'label'    => esc_html__( 'Title', 'et_builder' ),
  66.                     'css'      => array(
  67.                         'main' => "{$this->main_css_element} h2, {$this->main_css_element} .et_pb_module_header",
  68.                         'plugin_main' => "{$this->main_css_element} h2, {$this->main_css_element} h2 a, {$this->main_css_element} h1.et_pb_module_header, {$this->main_css_element} h1.et_pb_module_header a, {$this->main_css_element} h3.et_pb_module_header, {$this->main_css_element} h3.et_pb_module_header a, {$this->main_css_element} h4.et_pb_module_header, {$this->main_css_element} h4.et_pb_module_header a, {$this->main_css_element} h5.et_pb_module_header, {$this->main_css_element} h5.et_pb_module_header a, {$this->main_css_element} h6.et_pb_module_header, {$this->main_css_element} h6.et_pb_module_header a",
  69.                         'important' => 'all',
  70.                     ),
  71.                     'header_level' => array(
  72.                         'default' => 'h2',
  73.                     ),
  74.                 ),
  75.                 'filter' => array(
  76.                     'label'    => esc_html__( 'Filter Criteria', 'et_builder' ),
  77.                     'hide_text_align' => true,
  78.                     'css'      => array(
  79.                         'main' => "{$this->main_css_element} .et_pb_portfolio_filter",
  80.                         'plugin_main' => "{$this->main_css_element} .et_pb_portfolio_filter, {$this->main_css_element} .et_pb_portfolio_filter a",
  81.                         'color' => "{$this->main_css_element} .et_pb_portfolio_filter a",
  82.                     ),
  83.                 ),
  84.                 'caption' => array(
  85.                     'label'    => esc_html__( 'Meta', 'et_builder' ),
  86.                     'css'      => array(
  87.                         'main' => "{$this->main_css_element} .post-meta, {$this->main_css_element} .post-meta a",
  88.                     ),
  89.                 ),
  90.                 'pagination' => array(
  91.                     'label'    => esc_html__( 'Pagination', 'et_builder' ),
  92.                     'css'      => array(
  93.                         'main' => "{$this->main_css_element} .et_pb_portofolio_pagination a",
  94.                         'text_align' => "{$this->main_css_element} .et_pb_portofolio_pagination ul",
  95.                     ),
  96.                     'text_align' => array(
  97.                         'options' => et_builder_get_text_orientation_options( array( 'justified' ), array() ),
  98.                     ),
  99.                 ),
  100.             ),
  101.             'background' => array(
  102.                 'settings' => array(
  103.                     'color' => 'alpha',
  104.                 ),
  105.             ),
  106.             'border' => array(
  107.                 'css' => array(
  108.                     'main' => array(
  109.                         'border_radii' => "{$this->main_css_element} .et_pb_portfolio_item",
  110.                         'border_styles' => "{$this->main_css_element} .et_pb_portfolio_item",
  111.                     ),
  112.                 ),
  113.             ),
  114.             'custom_margin_padding' => array(
  115.                 'css' => array(
  116.                     'important' => array( 'custom_margin' ), // needed to overwrite last module margin-bottom styling
  117.                 ),
  118.             ),
  119.             'max_width' => array(
  120.                 'css' => array(
  121.                     'module_alignment' => '%%order_class%%.et_pb_filterable_portfolio.et_pb_module',
  122.                 ),
  123.             ),
  124.             'text'      => array(),
  125.             'filters' => array(
  126.                 'css' => array(
  127.                     'main' => '%%order_class%%',
  128.                 ),
  129.                 'child_filters_target' => array(
  130.                     'tab_slug' => 'advanced',
  131.                     'toggle_slug' => 'image',
  132.                 ),
  133.             ),
  134.             'image' => array(
  135.                 'css' => array(
  136.                     'main' => '%%order_class%% .et_portfolio_image',
  137.                 ),
  138.             ),
  139.         );
  140.         $this->custom_css_options = array(
  141.             'portfolio_filters' => array(
  142.                 'label'    => esc_html__( 'Portfolio Filters', 'et_builder' ),
  143.                 'selector' => '.et_pb_filterable_portfolio .et_pb_portfolio_filters',
  144.                 'no_space_before_selector' => true,
  145.             ),
  146.             'active_portfolio_filter' => array(
  147.                 'label'    => esc_html__( 'Active Portfolio Filter', 'et_builder' ),
  148.                 'selector' => '.et_pb_filterable_portfolio .et_pb_portfolio_filters li a.active',
  149.                 'no_space_before_selector' => true,
  150.             ),
  151.             'portfolio_image' => array(
  152.                 'label'    => esc_html__( 'Portfolio Image', 'et_builder' ),
  153.                 'selector' => '.et_portfolio_image',
  154.             ),
  155.             'overlay' => array(
  156.                 'label'    => esc_html__( 'Overlay', 'et_builder' ),
  157.                 'selector' => '.et_overlay',
  158.             ),
  159.             'overlay_icon' => array(
  160.                 'label'    => esc_html__( 'Overlay Icon', 'et_builder' ),
  161.                 'selector' => '.et_overlay:before',
  162.             ),
  163.             'portfolio_title' => array(
  164.                 'label'    => esc_html__( 'Portfolio Title', 'et_builder' ),
  165.                 'selector' => '.et_pb_portfolio_item h2',
  166.             ),
  167.             'portfolio_post_meta' => array(
  168.                 'label'    => esc_html__( 'Portfolio Post Meta', 'et_builder' ),
  169.                 'selector' => '.et_pb_portfolio_item .post-meta',
  170.             ),
  171.             'portfolio_pagination' => array(
  172.                 'label'    => esc_html__( 'Portfolio Pagination', 'et_builder' ),
  173.                 'selector' => '.et_pb_portofolio_pagination',
  174.             ),
  175.             'portfolio_pagination_active' => array(
  176.                 'label'    => esc_html__( 'Pagination Active Page', 'et_builder' ),
  177.                 'selector' => '.et_pb_portofolio_pagination a.active',
  178.             ),
  179.         );
  180.     }
  181.  
  182.     function get_fields() {
  183.         $fields = array(
  184.             'fullwidth' => array(
  185.                 'label'           => esc_html__( 'Layout', 'et_builder' ),
  186.                 'type'            => 'select',
  187.                 'option_category' => 'layout',
  188.                 'options'         => array(
  189.                     'on'  => esc_html__( 'Fullwidth', 'et_builder' ),
  190.                     'off' => esc_html__( 'Grid', 'et_builder' ),
  191.                 ),
  192.                 'affects' => array(
  193.                     'hover_icon',
  194.                     'zoom_icon_color',
  195.                     'hover_overlay_color',
  196.                 ),
  197.                 'description'      => esc_html__( 'Choose your desired portfolio layout style.', 'et_builder' ),
  198.                 'computed_affects' => array(
  199.                     '__projects',
  200.                 ),
  201.                 'tab_slug'         => 'advanced',
  202.                 'toggle_slug'      => 'layout',
  203.             ),
  204.             'posts_number' => array(
  205.                 'label'            => esc_html__( 'Posts Number', 'et_builder' ),
  206.                 'type'             => 'text',
  207.                 'option_category'  => 'configuration',
  208.                 'description'      => esc_html__( 'Define the number of projects that should be displayed per page.', 'et_builder' ),
  209.                 'computed_affects' => array(
  210.                     '__projects',
  211.                 ),
  212.                 'toggle_slug'      => 'main_content',
  213.             ),
  214.             'include_categories' => array(
  215.                 'label'            => esc_html__( 'Include Categories', 'et_builder' ),
  216.                 'renderer'         => 'et_builder_include_categories_option',
  217.                 'option_category'  => 'basic_option',
  218.                 'description'      => esc_html__( 'Select the categories that you would like to include in the feed.', 'et_builder' ),
  219.                 'computed_affects' => array(
  220.                     '__project_terms',
  221.                     '__projects',
  222.                 ),
  223.                 'taxonomy_name'    => 'project_category',
  224.                 'toggle_slug'      => 'main_content',
  225.             ),
  226.             'show_title' => array(
  227.                 'label'             => esc_html__( 'Show Title', 'et_builder' ),
  228.                 'type'              => 'yes_no_button',
  229.                 'option_category'   => 'configuration',
  230.                 'options'           => array(
  231.                     'on'  => esc_html__( 'Yes', 'et_builder' ),
  232.                     'off' => esc_html__( 'No', 'et_builder' ),
  233.                 ),
  234.                 'toggle_slug'       => 'elements',
  235.                 'description'       => esc_html__( 'Turn project titles on or off.', 'et_builder' ),
  236.             ),
  237.             'show_categories' => array(
  238.                 'label'             => esc_html__( 'Show Categories', 'et_builder' ),
  239.                 'type'              => 'yes_no_button',
  240.                 'option_category'   => 'configuration',
  241.                 'options'           => array(
  242.                     'on'  => esc_html__( 'Yes', 'et_builder' ),
  243.                     'off' => esc_html__( 'No', 'et_builder' ),
  244.                 ),
  245.                 'toggle_slug'       => 'elements',
  246.                 'description'       => esc_html__( 'Turn the category links on or off.', 'et_builder' ),
  247.             ),
  248.             'show_pagination' => array(
  249.                 'label'             => esc_html__( 'Show Pagination', 'et_builder' ),
  250.                 'type'              => 'yes_no_button',
  251.                 'option_category'   => 'configuration',
  252.                 'options'           => array(
  253.                     'on'  => esc_html__( 'Yes', 'et_builder' ),
  254.                     'off' => esc_html__( 'No', 'et_builder' ),
  255.                 ),
  256.                 'toggle_slug'       => 'elements',
  257.                 'description'       => esc_html__( 'Enable or disable pagination for this feed.', 'et_builder' ),
  258.             ),
  259.             'background_layout' => array(
  260.                 'label'           => esc_html__( 'Text Color', 'et_builder' ),
  261.                 'type'            => 'select',
  262.                 'option_category' => 'color_option',
  263.                 'options' => array(
  264.                     'light'  => esc_html__( 'Dark', 'et_builder' ),
  265.                     'dark' => esc_html__( 'Light', 'et_builder' ),
  266.                 ),
  267.                 'tab_slug'        => 'advanced',
  268.                 'toggle_slug'     => 'text',
  269.                 'description'     => esc_html__( 'Here you can choose whether your text should be light or dark. If you are working with a dark background, then your text should be light. If your background is light, then your text should be set to dark.', 'et_builder' ),
  270.             ),
  271.             'hover_icon' => array(
  272.                 'label'               => esc_html__( 'Hover Icon Picker', 'et_builder' ),
  273.                 'type'                => 'text',
  274.                 'option_category'     => 'configuration',
  275.                 'class'               => array( 'et-pb-font-icon' ),
  276.                 'renderer'            => 'et_pb_get_font_icon_list',
  277.                 'renderer_with_field' => true,
  278.                 'depends_show_if'     => 'off',
  279.                 'tab_slug'            => 'advanced',
  280.                 'toggle_slug'         => 'overlay',
  281.             ),
  282.             'zoom_icon_color' => array(
  283.                 'label'             => esc_html__( 'Zoom Icon Color', 'et_builder' ),
  284.                 'type'              => 'color-alpha',
  285.                 'custom_color'      => true,
  286.                 'depends_show_if'   => 'off',
  287.                 'tab_slug'          => 'advanced',
  288.                 'toggle_slug'       => 'overlay',
  289.             ),
  290.             'hover_overlay_color' => array(
  291.                 'label'             => esc_html__( 'Hover Overlay Color', 'et_builder' ),
  292.                 'type'              => 'color-alpha',
  293.                 'custom_color'      => true,
  294.                 'depends_show_if'   => 'off',
  295.                 'tab_slug'          => 'advanced',
  296.                 'toggle_slug'       => 'overlay',
  297.             ),
  298.             '__project_terms' => array(
  299.                 'type'                => 'computed',
  300.                 'computed_callback'   => array( 'ET_Builder_Module_Filterable_Portfolio', 'get_portfolio_terms' ),
  301.                 'computed_depends_on' => array(
  302.                     'include_categories',
  303.                 ),
  304.             ),
  305.             '__projects' => array(
  306.                 'type'                => 'computed',
  307.                 'computed_callback'   => array( 'ET_Builder_Module_Filterable_Portfolio', 'get_portfolio_item' ),
  308.                 'computed_depends_on' => array(
  309.                     'show_pagination',
  310.                     'posts_number',
  311.                     'include_categories',
  312.                     'fullwidth',
  313.                 ),
  314.             ),
  315.             'disabled_on' => array(
  316.                 'label'           => esc_html__( 'Disable on', 'et_builder' ),
  317.                 'type'            => 'multiple_checkboxes',
  318.                 'options'         => array(
  319.                     'phone'   => esc_html__( 'Phone', 'et_builder' ),
  320.                     'tablet'  => esc_html__( 'Tablet', 'et_builder' ),
  321.                     'desktop' => esc_html__( 'Desktop', 'et_builder' ),
  322.                 ),
  323.                 'additional_att'  => 'disable_on',
  324.                 'option_category' => 'configuration',
  325.                 'description'     => esc_html__( 'This will disable the module on selected devices', 'et_builder' ),
  326.                 'tab_slug'        => 'custom_css',
  327.                 'toggle_slug'     => 'visibility',
  328.             ),
  329.             'admin_label' => array(
  330.                 'label'       => esc_html__( 'Admin Label', 'et_builder' ),
  331.                 'type'        => 'text',
  332.                 'description' => esc_html__( 'This will change the label of the module in the builder for easy identification.', 'et_builder' ),
  333.                 'toggle_slug' => 'admin_label',
  334.             ),
  335.             'module_id' => array(
  336.                 'label'           => esc_html__( 'CSS ID', 'et_builder' ),
  337.                 'type'            => 'text',
  338.                 'option_category' => 'configuration',
  339.                 'tab_slug'        => 'custom_css',
  340.                 'toggle_slug'     => 'classes',
  341.                 'option_class'    => 'et_pb_custom_css_regular',
  342.             ),
  343.             'module_class' => array(
  344.                 'label'           => esc_html__( 'CSS Class', 'et_builder' ),
  345.                 'type'            => 'text',
  346.                 'option_category' => 'configuration',
  347.                 'tab_slug'        => 'custom_css',
  348.                 'toggle_slug'     => 'classes',
  349.                 'option_class'    => 'et_pb_custom_css_regular',
  350.             ),
  351.         );
  352.  
  353.         $fields = array_merge( $fields, ET_Builder_Module_Fields_Factory::get( 'BoxShadow' )->get_fields( array(
  354.             'suffix'          => '_image',
  355.             'label'           => esc_html__( 'Image Box Shadow', 'et_builder' ),
  356.             'option_category' => 'layout',
  357.             'tab_slug'        => 'advanced',
  358.             'toggle_slug'     => 'image',
  359.         ) ) );
  360.  
  361.         return $fields;
  362.     }
  363.  
  364.     static function get_portfolio_item( $args = array(), $conditional_tags = array(), $current_page = array() ) {
  365.         global $et_fb_processing_shortcode_object;
  366.  
  367.         $global_processing_original_value = $et_fb_processing_shortcode_object;
  368.  
  369.         $defaults = array(
  370.             'show_pagination'    => 'on',
  371.             'include_categories' => '',
  372.             'fullwidth'          => 'on',
  373.             'nopaging'           => true,
  374.         );
  375.  
  376.         $query_args = array();
  377.  
  378.         $args = wp_parse_args( $args, $defaults );
  379.  
  380.         if ( '' !== $args['include_categories'] ) {
  381.             $query_args['tax_query'] = array(
  382.                 array(
  383.                     'taxonomy' => 'project_category',
  384.                     'field' => 'id',
  385.                     'terms' => explode( ',', $args['include_categories'] ),
  386.                     'operator' => 'IN',
  387.                 )
  388.             );
  389.         }
  390.  
  391.         $default_query_args = array(
  392.             'post_type'   => 'project',
  393.             'post_status' => 'publish',
  394.             'posts_per_page' => -1,
  395.             'orderby' => 'title',
  396.             'order' => 'ASC'
  397.         );
  398.  
  399.         $query_args = wp_parse_args( $query_args, $default_query_args );
  400.  
  401.         // Get portfolio query
  402.         $query = new WP_Query( $query_args );
  403.  
  404.         // Format portfolio output, and add supplementary data
  405.         $width     = 'on' === $args['fullwidth'] ?  1080 : 400;
  406.         $width     = (int) apply_filters( 'et_pb_portfolio_image_width', $width );
  407.         $height    = 'on' === $args['fullwidth'] ?  9999 : 284;
  408.         $height    = (int) apply_filters( 'et_pb_portfolio_image_height', $height );
  409.         $classtext = 'on' === $args['fullwidth'] ? 'et_pb_post_main_image' : '';
  410.         $titletext = get_the_title();
  411.  
  412.         // Loop portfolio item and add supplementary data
  413.         if( $query->have_posts() ) {
  414.             $post_index = 0;
  415.             while ( $query->have_posts() ) {
  416.                 $query->the_post();
  417.  
  418.                 $categories = array();
  419.  
  420.                 $category_classes = array( 'et_pb_portfolio_item' );
  421.  
  422.                 if ( 'on' !== $args['fullwidth'] ) {
  423.                     $category_classes[] = 'et_pb_grid_item';
  424.                 }
  425.  
  426.                 $categories_object = get_the_terms( get_the_ID(), 'project_category' );
  427.                 if ( ! empty( $categories_object ) ) {
  428.                     foreach ( $categories_object as $category ) {
  429.                         // Update category classes which will be used for post_class
  430.                         $category_classes[] = 'project_category_' . urldecode( $category->slug );
  431.  
  432.                         // Push category data
  433.                         $categories[] = array(
  434.                             'id'        => $category->term_id,
  435.                             'slug'      => $category->slug,
  436.                             'label'     => $category->name,
  437.                             'permalink' => get_term_link( $category ),
  438.                         );
  439.                     }
  440.                 }
  441.  
  442.                 // need to disable processnig to make sure get_thumbnail() doesn't generate errors
  443.                 $et_fb_processing_shortcode_object = false;
  444.  
  445.                 // Get thumbnail
  446.                 $thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
  447.  
  448.                 $et_fb_processing_shortcode_object = $global_processing_original_value;
  449.  
  450.                 // Append value to query post
  451.                 $query->posts[ $post_index ]->post_permalink    = get_permalink();
  452.                 $query->posts[ $post_index ]->post_thumbnail    = print_thumbnail( $thumbnail['thumb'], $thumbnail['use_timthumb'], $titletext, $width, $height, '', false, true );
  453.                 $query->posts[ $post_index ]->post_categories   = $categories;
  454.                 $query->posts[ $post_index ]->post_class_name   = array_merge( get_post_class( '', get_the_ID() ), $category_classes );
  455.  
  456.                 // Append category classes
  457.                 $category_classes = implode( ' ', $category_classes );
  458.  
  459.                 $post_index++;
  460.             }
  461.         } else if ( wp_doing_ajax() ) {
  462.             // This is for the VB
  463.             $query = array( 'posts' => self::get_no_results_template() );
  464.         }
  465.  
  466.         wp_reset_postdata();
  467.  
  468.         return $query;
  469.     }
  470.  
  471.     static function get_portfolio_terms( $args = array(), $conditional_tags = array(), $current_page = array() ) {
  472.         $portfolio = self::get_portfolio_item( $args, $conditional_tags, $current_page );
  473.  
  474.         $terms = array();
  475.  
  476.         if ( ! empty( $portfolio->posts ) ) {
  477.             foreach ( $portfolio->posts as $post ) {
  478.                 if ( ! empty( $post->post_categories ) ) {
  479.                     foreach ( $post->post_categories as $category ) {
  480.                         $terms[ $category['slug'] ] = $category;
  481.                     }
  482.                 }
  483.             }
  484.         }
  485.  
  486.         return $terms;
  487.     }
  488.  
  489.     function shortcode_callback( $atts, $content = null, $function_name ) {
  490.         $module_id          = $this->shortcode_atts['module_id'];
  491.         $module_class       = $this->shortcode_atts['module_class'];
  492.         $fullwidth          = $this->shortcode_atts['fullwidth'];
  493.         $posts_number       = $this->shortcode_atts['posts_number'];
  494.         $include_categories = $this->shortcode_atts['include_categories'];
  495.         $show_title         = $this->shortcode_atts['show_title'];
  496.         $show_categories    = $this->shortcode_atts['show_categories'];
  497.         $show_pagination    = $this->shortcode_atts['show_pagination'];
  498.         $background_layout  = $this->shortcode_atts['background_layout'];
  499.         $hover_icon          = $this->shortcode_atts['hover_icon'];
  500.         $zoom_icon_color     = $this->shortcode_atts['zoom_icon_color'];
  501.         $hover_overlay_color = $this->shortcode_atts['hover_overlay_color'];
  502.         $header_level        = $this->shortcode_atts['title_level'];
  503.  
  504.         $module_class = ET_Builder_Element::add_module_order_class( $module_class, $function_name );
  505.  
  506.         wp_enqueue_script( 'hashchange' );
  507.  
  508.         if ( '' !== $zoom_icon_color ) {
  509.             ET_Builder_Element::set_style( $function_name, array(
  510.                 'selector'    => '%%order_class%% .et_overlay:before',
  511.                 'declaration' => sprintf(
  512.                     'color: %1$s !important;',
  513.                     esc_html( $zoom_icon_color )
  514.                 ),
  515.             ) );
  516.         }
  517.  
  518.         if ( '' !== $hover_overlay_color ) {
  519.             ET_Builder_Element::set_style( $function_name, array(
  520.                 'selector'    => '%%order_class%% .et_overlay',
  521.                 'declaration' => sprintf(
  522.                     'background-color: %1$s;
  523.                     border-color: %1$s;',
  524.                     esc_html( $hover_overlay_color )
  525.                 ),
  526.             ) );
  527.         }
  528.  
  529.         $projects = self::get_portfolio_item( array(
  530.             'show_pagination'    => $show_pagination,
  531.             'posts_number'       => $posts_number,
  532.             'include_categories' => $include_categories,
  533.             'fullwidth'          => $fullwidth,
  534.         ) );
  535.  
  536.         $categories_included = array();
  537.         ob_start();
  538.         if( $projects->post_count > 0 ) {
  539.             while ( $projects->have_posts() ) {
  540.                 $projects->the_post();
  541.  
  542.                 $category_classes = array();
  543.                 $categories = get_the_terms( get_the_ID(), 'project_category' );
  544.                 if ( $categories ) {
  545.                     foreach ( $categories as $category ) {
  546.                         $category_classes[] = 'project_category_' . urldecode( $category->slug );
  547.                         $categories_included[] = $category->term_id;
  548.                     }
  549.                 }
  550.  
  551.                 $category_classes = implode( ' ', $category_classes );
  552.  
  553.                 $main_post_class = sprintf(
  554.                     'et_pb_portfolio_item%1$s %2$s',
  555.                     ( 'on' !== $fullwidth ? ' et_pb_grid_item' : '' ),
  556.                     $category_classes
  557.                 );
  558.  
  559.                 ?>
  560.                 <div id="post-<?php the_ID(); ?>" <?php post_class( $main_post_class ); ?>>
  561.                 <?php
  562.                     $thumb = '';
  563.  
  564.                     $width = 'on' === $fullwidth ?  1080 : 400;
  565.                     $width = (int) apply_filters( 'et_pb_portfolio_image_width', $width );
  566.  
  567.                     $height = 'on' === $fullwidth ?  9999 : 284;
  568.                     $height = (int) apply_filters( 'et_pb_portfolio_image_height', $height );
  569.                     $classtext = 'on' === $fullwidth ? 'et_pb_post_main_image' : '';
  570.                     $titletext = get_the_title();
  571.                     $permalink = get_permalink();
  572.                     $post_meta = get_the_term_list( get_the_ID(), 'project_category', '', ', ' );
  573.                     $thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
  574.                     $thumb = $thumbnail["thumb"];
  575.  
  576.  
  577.                     if ( '' !== $thumb ) : ?>
  578.                         <a href="<?php echo esc_url( $permalink ); ?>">
  579.                             <span class="et_portfolio_image">
  580.                                 <?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
  581.                         <?php if ( 'on' !== $fullwidth ) :
  582.  
  583.                                 $data_icon = '' !== $hover_icon
  584.                                     ? sprintf(
  585.                                         ' data-icon="%1$s"',
  586.                                         esc_attr( et_pb_process_font_icon( $hover_icon ) )
  587.                                     )
  588.                                     : '';
  589.  
  590.                                 printf( '<span class="et_overlay%1$s"%2$s></span>',
  591.                                     ( '' !== $hover_icon ? ' et_pb_inline_icon' : '' ),
  592.                                     $data_icon
  593.                                 );
  594.  
  595.                         ?>
  596.                         <?php endif; ?>
  597.                             </span>
  598.                         </a>
  599.                 <?php
  600.                     endif;
  601.                 ?>
  602.  
  603.                 <?php if ( 'on' === $show_title ) : ?>
  604.                     <<?php echo et_pb_process_header_level( $header_level, 'h2' ) ?> class="et_pb_module_header"><a href="<?php echo esc_url( $permalink ); ?>"><?php echo $titletext; ?></a></<?php echo et_pb_process_header_level( $header_level, 'h2' ) ?>>
  605.                 <?php endif; ?>
  606.  
  607.                 <?php if ( 'on' === $show_categories ) : ?>
  608.                     <p class="post-meta"><?php echo $post_meta; ?></p>
  609.                 <?php endif; ?>
  610.  
  611.                 </div><!-- .et_pb_portfolio_item -->
  612.                 <?php
  613.             }
  614.         }
  615.  
  616.         wp_reset_postdata();
  617.  
  618.         if ( ! $posts = ob_get_clean() ) {
  619.             $posts            = self::get_no_results_template();
  620.             $category_filters = '';
  621.         } else {
  622.             $categories_included = explode ( ',', $include_categories );
  623.             $terms_args = array(
  624.                 'include' => $categories_included,
  625.                 'orderby' => 'name',
  626.                 'order' => 'ASC',
  627.             );
  628.             $terms = get_terms( 'project_category', $terms_args );
  629.  
  630.             $category_filters = '<ul class="clearfix">';
  631.             $category_filters .= sprintf( '<li class="et_pb_portfolio_filter et_pb_portfolio_filter_all"><a href="#" class="active" data-category-slug="all">%1$s</a></li>',
  632.                 esc_html__( 'All', 'et_builder' )
  633.             );
  634.             foreach ( $terms as $term  ) {
  635.                 $category_filters .= sprintf( '<li class="et_pb_portfolio_filter"><a href="#" data-category-slug="%1$s">%2$s</a></li>',
  636.                     esc_attr( urldecode( $term->slug ) ),
  637.                     esc_html( $term->name )
  638.                 );
  639.             }
  640.             $category_filters .= '</ul>';
  641.         }
  642.  
  643.         $video_background = $this->video_background();
  644.         $parallax_image_background = $this->get_parallax_image_background();
  645.  
  646.         $class = " et_pb_module et_pb_bg_layout_{$background_layout}";
  647.  
  648.         // Images: Add CSS Filters and Mix Blend Mode rules (if set)
  649.         if ( isset( $this->advanced_options['image']['css'] ) ) {
  650.             $module_class .= $this->generate_css_filters(
  651.                 $function_name,
  652.                 'child_',
  653.                 self::$data_utils->array_get( $this->advanced_options['image']['css'], 'main', '%%order_class%%' )
  654.             );
  655.         }
  656.  
  657.         $output = sprintf(
  658.             '<div%5$s class="et_pb_filterable_portfolio et_pb_portfolio %1$s%4$s%6$s%11$s%13$s%15$s" data-posts-number="%7$d"%10$s>
  659.                 %14$s
  660.                 %12$s
  661.                 <div class="et_pb_portfolio_filters clearfix">%2$s</div><!-- .et_pb_portfolio_filters -->
  662.  
  663.                 <div class="et_pb_portfolio_items_wrapper %8$s">
  664.                     <div class="et_pb_portfolio_items">%3$s</div><!-- .et_pb_portfolio_items -->
  665.                 </div>
  666.                 %9$s
  667.             </div> <!-- .et_pb_filterable_portfolio -->',
  668.             ( 'on' === $fullwidth ? 'et_pb_filterable_portfolio_fullwidth' : 'et_pb_filterable_portfolio_grid clearfix' ),
  669.             $category_filters,
  670.             $posts,
  671.             esc_attr( $class ),
  672.             ( '' !== $module_id ? sprintf( ' id="%1$s"', esc_attr( $module_id ) ) : '' ),
  673.             ( '' !== $module_class ? sprintf( ' %1$s', esc_attr( $module_class ) ) : '' ),
  674.             esc_attr( $posts_number),
  675.             ('on' === $show_pagination ? 'clearfix' : 'no_pagination' ),
  676.             ('on' === $show_pagination ? '<div class="et_pb_portofolio_pagination"></div>' : '' ),
  677.             is_rtl() ? ' data-rtl="true"' : '',
  678.             '' !== $video_background ? ' et_pb_section_video et_pb_preload' : '',
  679.             $video_background,
  680.             '' !== $parallax_image_background ? ' et_pb_section_parallax' : '',
  681.             $parallax_image_background,
  682.             $this->get_text_orientation_classname()
  683.         );
  684.  
  685.         return $output;
  686.     }
  687.  
  688.     public function process_box_shadow( $function_name ) {
  689.         $boxShadow = ET_Builder_Module_Fields_Factory::get( 'BoxShadow' );
  690.  
  691.         self::set_style( $function_name, $boxShadow->get_style(
  692.             sprintf( '.%1$s .project .et_portfolio_image', self::get_module_order_class( $function_name ) ),
  693.             $this->shortcode_atts,
  694.             array( 'suffix' => '_image' )
  695.         ) );
  696.  
  697.         parent::process_box_shadow( $function_name );
  698.     }
  699.  
  700.     protected function _add_additional_border_fields() {
  701.         parent::_add_additional_border_fields();
  702.  
  703.         $suffix = 'image';
  704.         $tab_slug = 'advanced';
  705.         $toggle_slug = 'image';
  706.  
  707.         $this->_additional_fields_options = array_merge(
  708.             $this->_additional_fields_options,
  709.             ET_Builder_Module_Fields_Factory::get( 'Border' )->get_fields( array(
  710.                 'suffix'       => "_{$suffix}",
  711.                 'label_prefix' => esc_html__( 'Image', 'et_builder' ),
  712.                 'tab_slug'      => $tab_slug,
  713.                 'toggle_slug'   => $toggle_slug,
  714.             ) )
  715.         );
  716.  
  717.         $this->advanced_options["border_{$suffix}"]["border_radii_{$suffix}"] = $this->_additional_fields_options["border_radii_{$suffix}"];
  718.         $this->advanced_options["border_{$suffix}"]["border_styles_{$suffix}"] = $this->_additional_fields_options["border_styles_{$suffix}"];
  719.  
  720.         $this->advanced_options["border_{$suffix}"]['css'] = array(
  721.             'main' => array(
  722.                 'border_radii'  => "{$this->main_css_element} .et_portfolio_image",
  723.                 'border_styles' => "{$this->main_css_element} .et_portfolio_image",
  724.             )
  725.         );
  726.     }
  727.  
  728.     function process_advanced_border_options( $function_name ) {
  729.         parent::process_advanced_border_options( $function_name );
  730.  
  731.         $suffix = 'image';
  732.         /**
  733.          * @var ET_Builder_Module_Field_Border $border_field
  734.          */
  735.         $border_field = ET_Builder_Module_Fields_Factory::get( 'Border' );
  736.  
  737.         $css_selector = ! empty( $this->advanced_options["border_{$suffix}"]['css']['main']['border_radii'] ) ? $this->advanced_options["border_{$suffix}"]['css']['main']['border_radii'] : $this->main_css_element;
  738.         self::set_style( $function_name, array(
  739.             'selector'    => $css_selector,
  740.             'declaration' => $border_field->get_radii_style( $this->shortcode_atts, $this->advanced_options, "_{$suffix}" ),
  741.             'priority'    => $this->_style_priority,
  742.         ) );
  743.  
  744.         $css_selector = ! empty( $this->advanced_options["border_{$suffix}"]['css']['main']['border_styles'] ) ? $this->advanced_options["border_{$suffix}"]['css']['main']['border_styles'] : $this->main_css_element;
  745.         self::set_style( $function_name, array(
  746.             'selector'    => $css_selector,
  747.             'declaration' => $border_field->get_borders_style( $this->shortcode_atts, $this->advanced_options, "_{$suffix}" ),
  748.             'priority'    => $this->_style_priority,
  749.         ) );
  750.     }
  751. }
  752.  
  753. new WPC_ET_Builder_Module_Filterable_Portfolio;
Add Comment
Please, Sign In to add comment