EduardET

Untitled

Mar 15th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 26.58 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.         );
  396.  
  397.         $query_args = wp_parse_args( $query_args, $default_query_args );
  398.  
  399.         // Get portfolio query
  400.         $query = new WP_Query( $query_args );
  401.  
  402.         // Format portfolio output, and add supplementary data
  403.         $width     = 'on' === $args['fullwidth'] ?  1080 : 400;
  404.         $width     = (int) apply_filters( 'et_pb_portfolio_image_width', $width );
  405.         $height    = 'on' === $args['fullwidth'] ?  9999 : 284;
  406.         $height    = (int) apply_filters( 'et_pb_portfolio_image_height', $height );
  407.         $classtext = 'on' === $args['fullwidth'] ? 'et_pb_post_main_image' : '';
  408.         $titletext = get_the_title();
  409.  
  410.         // Loop portfolio item and add supplementary data
  411.         if( $query->have_posts() ) {
  412.             $post_index = 0;
  413.             while ( $query->have_posts() ) {
  414.                 $query->the_post();
  415.  
  416.                 $categories = array();
  417.  
  418.                 $category_classes = array( 'et_pb_portfolio_item' );
  419.  
  420.                 if ( 'on' !== $args['fullwidth'] ) {
  421.                     $category_classes[] = 'et_pb_grid_item';
  422.                 }
  423.  
  424.                 $categories_object = get_the_terms( get_the_ID(), 'project_category' );
  425.                 if ( ! empty( $categories_object ) ) {
  426.                     foreach ( $categories_object as $category ) {
  427.                         // Update category classes which will be used for post_class
  428.                         $category_classes[] = 'project_category_' . urldecode( $category->slug );
  429.  
  430.                         // Push category data
  431.                         $categories[] = array(
  432.                             'id'        => $category->term_id,
  433.                             'slug'      => $category->slug,
  434.                             'label'     => $category->name,
  435.                             'permalink' => get_term_link( $category ),
  436.                         );
  437.                     }
  438.                 }
  439.  
  440.                 // need to disable processnig to make sure get_thumbnail() doesn't generate errors
  441.                 $et_fb_processing_shortcode_object = false;
  442.  
  443.                 // Get thumbnail
  444.                 $thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
  445.  
  446.                 $et_fb_processing_shortcode_object = $global_processing_original_value;
  447.  
  448.                 // Append value to query post
  449.                 $query->posts[ $post_index ]->post_permalink    = get_permalink();
  450.                 $query->posts[ $post_index ]->post_thumbnail    = print_thumbnail( $thumbnail['thumb'], $thumbnail['use_timthumb'], $titletext, $width, $height, '', false, true );
  451.                 $query->posts[ $post_index ]->post_categories   = $categories;
  452.                 $query->posts[ $post_index ]->post_class_name   = array_merge( get_post_class( '', get_the_ID() ), $category_classes );
  453.  
  454.                 // Append category classes
  455.                 $category_classes = implode( ' ', $category_classes );
  456.  
  457.                 $post_index++;
  458.             }
  459.         } else if ( wp_doing_ajax() ) {
  460.             // This is for the VB
  461.             $query = array( 'posts' => self::get_no_results_template() );
  462.         }
  463.  
  464.         wp_reset_postdata();
  465.  
  466.         return $query;
  467.     }
  468.  
  469.     static function get_portfolio_terms( $args = array(), $conditional_tags = array(), $current_page = array() ) {
  470.         $portfolio = self::get_portfolio_item( $args, $conditional_tags, $current_page );
  471.  
  472.         $terms = array();
  473.  
  474.         if ( ! empty( $portfolio->posts ) ) {
  475.             foreach ( $portfolio->posts as $post ) {
  476.                 if ( ! empty( $post->post_categories ) ) {
  477.                     foreach ( $post->post_categories as $category ) {
  478.                         $terms[ $category['slug'] ] = $category;
  479.                     }
  480.                 }
  481.             }
  482.         }
  483.  
  484.         return $terms;
  485.     }
  486.  
  487.     function shortcode_callback( $atts, $content = null, $function_name ) {
  488.         $module_id          = $this->shortcode_atts['module_id'];
  489.         $module_class       = $this->shortcode_atts['module_class'];
  490.         $fullwidth          = $this->shortcode_atts['fullwidth'];
  491.         $posts_number       = $this->shortcode_atts['posts_number'];
  492.         $include_categories = $this->shortcode_atts['include_categories'];
  493.         $show_title         = $this->shortcode_atts['show_title'];
  494.         $show_categories    = $this->shortcode_atts['show_categories'];
  495.         $show_pagination    = $this->shortcode_atts['show_pagination'];
  496.         $background_layout  = $this->shortcode_atts['background_layout'];
  497.         $hover_icon          = $this->shortcode_atts['hover_icon'];
  498.         $zoom_icon_color     = $this->shortcode_atts['zoom_icon_color'];
  499.         $hover_overlay_color = $this->shortcode_atts['hover_overlay_color'];
  500.         $header_level        = $this->shortcode_atts['title_level'];
  501.  
  502.         $module_class = ET_Builder_Element::add_module_order_class( $module_class, $function_name );
  503.  
  504.         wp_enqueue_script( 'hashchange' );
  505.  
  506.         if ( '' !== $zoom_icon_color ) {
  507.             ET_Builder_Element::set_style( $function_name, array(
  508.                 'selector'    => '%%order_class%% .et_overlay:before',
  509.                 'declaration' => sprintf(
  510.                     'color: %1$s !important;',
  511.                     esc_html( $zoom_icon_color )
  512.                 ),
  513.             ) );
  514.         }
  515.  
  516.         if ( '' !== $hover_overlay_color ) {
  517.             ET_Builder_Element::set_style( $function_name, array(
  518.                 'selector'    => '%%order_class%% .et_overlay',
  519.                 'declaration' => sprintf(
  520.                     'background-color: %1$s;
  521.                     border-color: %1$s;',
  522.                     esc_html( $hover_overlay_color )
  523.                 ),
  524.             ) );
  525.         }
  526.  
  527.         $projects = self::get_portfolio_item( array(
  528.             'show_pagination'    => $show_pagination,
  529.             'posts_number'       => $posts_number,
  530.             'include_categories' => $include_categories,
  531.             'fullwidth'          => $fullwidth,
  532.         ) );
  533.  
  534.         $categories_included = array();
  535.         ob_start();
  536.         if( $projects->post_count > 0 ) {
  537.             while ( $projects->have_posts() ) {
  538.                 $projects->the_post();
  539.  
  540.                 $category_classes = array();
  541.                 $categories = get_the_terms( get_the_ID(), 'project_category' );
  542.                 if ( $categories ) {
  543.                     foreach ( $categories as $category ) {
  544.                         $category_classes[] = 'project_category_' . urldecode( $category->slug );
  545.                         $categories_included[] = $category->term_id;
  546.                     }
  547.                 }
  548.  
  549.                 $category_classes = implode( ' ', $category_classes );
  550.  
  551.                 $main_post_class = sprintf(
  552.                     'et_pb_portfolio_item%1$s %2$s',
  553.                     ( 'on' !== $fullwidth ? ' et_pb_grid_item' : '' ),
  554.                     $category_classes
  555.                 );
  556.  
  557.                 ?>
  558.                 <div id="post-<?php the_ID(); ?>" <?php post_class( $main_post_class ); ?>>
  559.                 <?php
  560.                     $thumb = '';
  561.  
  562.                     $width = 'on' === $fullwidth ?  1080 : 400;
  563.                     $width = (int) apply_filters( 'et_pb_portfolio_image_width', $width );
  564.  
  565.                     $height = 'on' === $fullwidth ?  9999 : 284;
  566.                     $height = (int) apply_filters( 'et_pb_portfolio_image_height', $height );
  567.                     $classtext = 'on' === $fullwidth ? 'et_pb_post_main_image' : '';
  568.                     $titletext = get_the_title();
  569.                     $permalink = get_permalink();
  570.                     $post_meta = get_the_term_list( get_the_ID(), 'project_category', '', ', ' );
  571.                     $thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
  572.                     $fi = get_the_post_thumbnail_url();
  573.                     $thumb = $thumbnail["thumb"];
  574.  
  575.  
  576.                     if ( '' !== $thumb ) : ?>
  577.                         <a href="<?php echo $fi ?>" class="et_pb_lightbox_image">
  578.                             <span class="et_portfolio_image">
  579.                                 <?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
  580.                         <?php if ( 'on' !== $fullwidth ) :
  581.  
  582.                                 $data_icon = '' !== $hover_icon
  583.                                     ? sprintf(
  584.                                         ' data-icon="%1$s"',
  585.                                         esc_attr( et_pb_process_font_icon( $hover_icon ) )
  586.                                     )
  587.                                     : '';
  588.  
  589.                                 printf( '<span class="et_overlay%1$s"%2$s></span>',
  590.                                     ( '' !== $hover_icon ? ' et_pb_inline_icon' : '' ),
  591.                                     $data_icon
  592.                                 );
  593.  
  594.                         ?>
  595.                         <?php endif; ?>
  596.                             </span>
  597.                         </a>
  598.                 <?php
  599.                     endif;
  600.                 ?>
  601.  
  602.                 <?php if ( 'on' === $show_title ) : ?>
  603.                     <<?php echo et_pb_process_header_level( $header_level, 'h2' ) ?> class="et_pb_module_header"><?php echo $titletext; ?></<?php echo et_pb_process_header_level( $header_level, 'h2' ) ?>>
  604.                 <?php endif; ?>
  605.  
  606.                 <?php if ( 'on' === $show_categories ) : ?>
  607.                     <p class="post-meta"><?php echo $post_meta; ?></p>
  608.                 <?php endif; ?>
  609.  
  610.                 </div><!-- .et_pb_portfolio_item -->
  611.                 <?php
  612.             }
  613.         }
  614.  
  615.         wp_reset_postdata();
  616.  
  617.         if ( ! $posts = ob_get_clean() ) {
  618.             $posts            = self::get_no_results_template();
  619.             $category_filters = '';
  620.         } else {
  621.             $categories_included = explode ( ',', $include_categories );
  622.             $terms_args = array(
  623.                 'include' => $categories_included,
  624.                 'orderby' => 'name',
  625.                 'order' => 'ASC',
  626.             );
  627.             $terms = get_terms( 'project_category', $terms_args );
  628.  
  629.             $category_filters = '<ul class="clearfix">';
  630.             $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>',
  631.                 esc_html__( 'All', 'et_builder' )
  632.             );
  633.             foreach ( $terms as $term  ) {
  634.                 $category_filters .= sprintf( '<li class="et_pb_portfolio_filter"><a href="#" data-category-slug="%1$s">%2$s</a></li>',
  635.                     esc_attr( urldecode( $term->slug ) ),
  636.                     esc_html( $term->name )
  637.                 );
  638.             }
  639.             $category_filters .= '</ul>';
  640.         }
  641.  
  642.         $video_background = $this->video_background();
  643.         $parallax_image_background = $this->get_parallax_image_background();
  644.  
  645.         $class = " et_pb_module et_pb_bg_layout_{$background_layout}";
  646.  
  647.         // Images: Add CSS Filters and Mix Blend Mode rules (if set)
  648.         if ( isset( $this->advanced_options['image']['css'] ) ) {
  649.             $module_class .= $this->generate_css_filters(
  650.                 $function_name,
  651.                 'child_',
  652.                 self::$data_utils->array_get( $this->advanced_options['image']['css'], 'main', '%%order_class%%' )
  653.             );
  654.         }
  655.  
  656.         $output = sprintf(
  657.             '<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>
  658.                 %14$s
  659.                 %12$s
  660.                 <div class="et_pb_portfolio_filters clearfix">%2$s</div><!-- .et_pb_portfolio_filters -->
  661.  
  662.                 <div class="et_pb_portfolio_items_wrapper %8$s">
  663.                     <div class="et_pb_portfolio_items">%3$s</div><!-- .et_pb_portfolio_items -->
  664.                 </div>
  665.                 %9$s
  666.             </div> <!-- .et_pb_filterable_portfolio -->',
  667.             ( 'on' === $fullwidth ? 'et_pb_filterable_portfolio_fullwidth' : 'et_pb_filterable_portfolio_grid clearfix' ),
  668.             $category_filters,
  669.             $posts,
  670.             esc_attr( $class ),
  671.             ( '' !== $module_id ? sprintf( ' id="%1$s"', esc_attr( $module_id ) ) : '' ),
  672.             ( '' !== $module_class ? sprintf( ' %1$s', esc_attr( $module_class ) ) : '' ),
  673.             esc_attr( $posts_number),
  674.             ('on' === $show_pagination ? 'clearfix' : 'no_pagination' ),
  675.             ('on' === $show_pagination ? '<div class="et_pb_portofolio_pagination"></div>' : '' ),
  676.             is_rtl() ? ' data-rtl="true"' : '',
  677.             '' !== $video_background ? ' et_pb_section_video et_pb_preload' : '',
  678.             $video_background,
  679.             '' !== $parallax_image_background ? ' et_pb_section_parallax' : '',
  680.             $parallax_image_background,
  681.             $this->get_text_orientation_classname()
  682.         );
  683.  
  684.         return $output;
  685.     }
  686.  
  687.     public function process_box_shadow( $function_name ) {
  688.         $boxShadow = ET_Builder_Module_Fields_Factory::get( 'BoxShadow' );
  689.  
  690.         self::set_style( $function_name, $boxShadow->get_style(
  691.             sprintf( '.%1$s .project .et_portfolio_image', self::get_module_order_class( $function_name ) ),
  692.             $this->shortcode_atts,
  693.             array( 'suffix' => '_image' )
  694.         ) );
  695.  
  696.         parent::process_box_shadow( $function_name );
  697.     }
  698.  
  699.     protected function _add_additional_border_fields() {
  700.         parent::_add_additional_border_fields();
  701.  
  702.         $suffix = 'image';
  703.         $tab_slug = 'advanced';
  704.         $toggle_slug = 'image';
  705.  
  706.         $this->_additional_fields_options = array_merge(
  707.             $this->_additional_fields_options,
  708.             ET_Builder_Module_Fields_Factory::get( 'Border' )->get_fields( array(
  709.                 'suffix'       => "_{$suffix}",
  710.                 'label_prefix' => esc_html__( 'Image', 'et_builder' ),
  711.                 'tab_slug'      => $tab_slug,
  712.                 'toggle_slug'   => $toggle_slug,
  713.             ) )
  714.         );
  715.  
  716.         $this->advanced_options["border_{$suffix}"]["border_radii_{$suffix}"] = $this->_additional_fields_options["border_radii_{$suffix}"];
  717.         $this->advanced_options["border_{$suffix}"]["border_styles_{$suffix}"] = $this->_additional_fields_options["border_styles_{$suffix}"];
  718.  
  719.         $this->advanced_options["border_{$suffix}"]['css'] = array(
  720.             'main' => array(
  721.                 'border_radii'  => "{$this->main_css_element} .et_portfolio_image",
  722.                 'border_styles' => "{$this->main_css_element} .et_portfolio_image",
  723.             )
  724.         );
  725.     }
  726.  
  727.     function process_advanced_border_options( $function_name ) {
  728.         parent::process_advanced_border_options( $function_name );
  729.  
  730.         $suffix = 'image';
  731.         /**
  732.          * @var ET_Builder_Module_Field_Border $border_field
  733.          */
  734.         $border_field = ET_Builder_Module_Fields_Factory::get( 'Border' );
  735.  
  736.         $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;
  737.         self::set_style( $function_name, array(
  738.             'selector'    => $css_selector,
  739.             'declaration' => $border_field->get_radii_style( $this->shortcode_atts, $this->advanced_options, "_{$suffix}" ),
  740.             'priority'    => $this->_style_priority,
  741.         ) );
  742.  
  743.         $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;
  744.         self::set_style( $function_name, array(
  745.             'selector'    => $css_selector,
  746.             'declaration' => $border_field->get_borders_style( $this->shortcode_atts, $this->advanced_options, "_{$suffix}" ),
  747.             'priority'    => $this->_style_priority,
  748.         ) );
  749.     }
  750. }
  751.  
  752. new WPC_ET_Builder_Module_Filterable_Portfolio;
Advertisement
Add Comment
Please, Sign In to add comment