Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 18.21 KB | None | 0 0
  1. <?php
  2. class Custom_ET_Builder_Module_Filterable_Portfolio extends ET_Builder_Module {
  3.     function init() {
  4.         $this->name = __( 'Filterable Portfolio', 'et_builder' );
  5.         $this->slug = 'et_pb_filterable_portfolio';
  6.  
  7.         $this->whitelisted_fields = array(
  8.             'fullwidth',
  9.             'posts_number',
  10.             'include_categories',
  11.             'show_title',
  12.             'show_categories',
  13.             'show_pagination',
  14.             'background_layout',
  15.             'admin_label',
  16.             'module_id',
  17.             'module_class',
  18.             'hover_icon',
  19.             'zoom_icon_color',
  20.             'hover_overlay_color',
  21.         );
  22.  
  23.         $this->fields_defaults = array(
  24.             'fullwidth'         => array( 'on' ),
  25.             'posts_number'      => array( 10, 'add_default_setting' ),
  26.             'show_title'        => array( 'on' ),
  27.             'show_categories'   => array( 'on' ),
  28.             'show_pagination'   => array( 'on' ),
  29.             'background_layout' => array( 'light' ),
  30.         );
  31.  
  32.         $this->main_css_element = '%%order_class%%.et_pb_filterable_portfolio';
  33.         $this->advanced_options = array(
  34.             'fonts' => array(
  35.                 'title'   => array(
  36.                     'label'    => __( 'Title', 'et_builder' ),
  37.                     'css'      => array(
  38.                         'main' => "{$this->main_css_element} h2",
  39.                         'important' => 'all',
  40.                     ),
  41.                 ),
  42.                 'caption' => array(
  43.                     'label'    => __( 'Meta', 'et_builder' ),
  44.                     'css'      => array(
  45.                         'main' => "{$this->main_css_element} .post-meta, {$this->main_css_element} .post-meta a",
  46.                     ),
  47.                 ),
  48.                 'filter' => array(
  49.                     'label'    => __( 'Filter', 'et_builder' ),
  50.                     'css'      => array(
  51.                         'main' => "{$this->main_css_element} .et_pb_portfolio_filter",
  52.                     ),
  53.                 ),
  54.             ),
  55.             'background' => array(
  56.                 'settings' => array(
  57.                     'color' => 'alpha',
  58.                 ),
  59.             ),
  60.             'border' => array(
  61.                 'css' => array(
  62.                     'main' => "{$this->main_css_element} .et_pb_portfolio_item",
  63.                 ),
  64.             ),
  65.         );
  66.         $this->custom_css_options = array(
  67.             'portfolio_filters' => array(
  68.                 'label'    => __( 'Portfolio Filters', 'et_builder' ),
  69.                 'selector' => '.et_pb_filterable_portfolio .et_pb_portfolio_filters',
  70.             ),
  71.             'active_portfolio_filter' => array(
  72.                 'label'    => __( 'Active Portfolio Filter', 'et_builder' ),
  73.                 'selector' => '.et_pb_filterable_portfolio .et_pb_portfolio_filters li a.active',
  74.             ),
  75.             'portfolio_image' => array(
  76.                 'label'    => __( 'Portfolio Image', 'et_builder' ),
  77.                 'selector' => '.et_portfolio_image',
  78.             ),
  79.             'overlay' => array(
  80.                 'label'    => __( 'Overlay', 'et_builder' ),
  81.                 'selector' => '.et_overlay',
  82.             ),
  83.             'overlay_icon' => array(
  84.                 'label'    => __( 'Overlay Icon', 'et_builder' ),
  85.                 'selector' => '.et_overlay:before',
  86.             ),
  87.             'portfolio_title' => array(
  88.                 'label'    => __( 'Portfolio Title', 'et_builder' ),
  89.                 'selector' => '.et_pb_portfolio_item h2',
  90.             ),
  91.             'portfolio_post_meta' => array(
  92.                 'label'    => __( 'Portfolio Post Meta', 'et_builder' ),
  93.                 'selector' => '.et_pb_portfolio_item .post-meta',
  94.             ),
  95.         );
  96.     }
  97.  
  98.     function get_fields() {
  99.         $fields = array(
  100.             'fullwidth' => array(
  101.                 'label'           => __( 'Layout', 'et_builder' ),
  102.                 'type'            => 'select',
  103.                 'option_category' => 'layout',
  104.                 'options'         => array(
  105.                     'on'  => __( 'Fullwidth', 'et_builder' ),
  106.                     'off' => __( 'Grid', 'et_builder' ),
  107.                 ),
  108.                 'description'        => __( 'Choose your desired portfolio layout style.', 'et_builder' ),
  109.             ),
  110.             'posts_number' => array(
  111.                 'label'             => __( 'Posts Number', 'et_builder' ),
  112.                 'type'              => 'text',
  113.                 'option_category'   => 'configuration',
  114.                 'description'       => __( 'Define the number of projects that should be displayed per page.', 'et_builder' ),
  115.             ),
  116.             'include_categories' => array(
  117.                 'label'           => __( 'Include Categories', 'et_builder' ),
  118.                 'renderer'        => 'et_builder_include_categories_option',
  119.                 'option_category' => 'basic_option',
  120.                 'description'     => __( 'Select the categories that you would like to include in the feed.', 'et_builder' ),
  121.             ),
  122.             'show_title' => array(
  123.                 'label'             => __( 'Show Title', 'et_builder' ),
  124.                 'type'              => 'yes_no_button',
  125.                 'option_category'   => 'configuration',
  126.                 'options'           => array(
  127.                     'on'  => __( 'Yes', 'et_builder' ),
  128.                     'off' => __( 'No', 'et_builder' ),
  129.                 ),
  130.                 'description'        => __( 'Turn project titles on or off.', 'et_builder' ),
  131.             ),
  132.             'show_categories' => array(
  133.                 'label'             => __( 'Show Categories', 'et_builder' ),
  134.                 'type'              => 'yes_no_button',
  135.                 'option_category'   => 'configuration',
  136.                 'options'           => array(
  137.                     'on'  => __( 'Yes', 'et_builder' ),
  138.                     'off' => __( 'No', 'et_builder' ),
  139.                 ),
  140.                 'description'        => __( 'Turn the category links on or off.', 'et_builder' ),
  141.             ),
  142.             'show_pagination' => array(
  143.                 'label'             => __( 'Show Pagination', 'et_builder' ),
  144.                 'type'              => 'yes_no_button',
  145.                 'option_category'   => 'configuration',
  146.                 'options'           => array(
  147.                     'on'  => __( 'Yes', 'et_builder' ),
  148.                     'off' => __( 'No', 'et_builder' ),
  149.                 ),
  150.                 'description'        => __( 'Enable or disable pagination for this feed.', 'et_builder' ),
  151.             ),
  152.             'background_layout' => array(
  153.                 'label'           => __( 'Text Color', 'et_builder' ),
  154.                 'type'            => 'select',
  155.                 'option_category' => 'color_option',
  156.                 'options' => array(
  157.                     'light'  => __( 'Dark', 'et_builder' ),
  158.                     'dark' => __( 'Light', 'et_builder' ),
  159.                 ),
  160.                 'description'        => __( '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' ),
  161.             ),
  162.             'admin_label' => array(
  163.                 'label'       => __( 'Admin Label', 'et_builder' ),
  164.                 'type'        => 'text',
  165.                 'description' => __( 'This will change the label of the module in the builder for easy identification.', 'et_builder' ),
  166.             ),
  167.             'module_id' => array(
  168.                 'label'           => __( 'CSS ID', 'et_builder' ),
  169.                 'type'            => 'text',
  170.                 'option_category' => 'configuration',
  171.                 'description'     => __( 'Enter an optional CSS ID to be used for this module. An ID can be used to create custom CSS styling, or to create links to particular sections of your page.', 'et_builder' ),
  172.             ),
  173.             'module_class' => array(
  174.                 'label'           => __( 'CSS Class', 'et_builder' ),
  175.                 'type'            => 'text',
  176.                 'option_category' => 'configuration',
  177.                 'description'     => __( 'Enter optional CSS classes to be used for this module. A CSS class can be used to create custom CSS styling. You can add multiple classes, separated with a space.', 'et_builder' ),
  178.             ),
  179.             'hover_icon' => array(
  180.                 'label'               => __( 'Hover Icon Picker', 'et_builder' ),
  181.                 'type'                => 'text',
  182.                 'option_category'     => 'configuration',
  183.                 'class'               => array( 'et-pb-font-icon' ),
  184.                 'renderer'            => 'et_pb_get_font_icon_list',
  185.                 'renderer_with_field' => true,
  186.                 'tab_slug'            => 'advanced',
  187.             ),
  188.             'zoom_icon_color' => array(
  189.                 'label'             => __( 'Zoom Icon Color', 'et_builder' ),
  190.                 'type'              => 'color',
  191.                 'custom_color'      => true,
  192.                 'tab_slug'          => 'advanced',
  193.             ),
  194.             'hover_overlay_color' => array(
  195.                 'label'             => __( 'Hover Overlay Color', 'et_builder' ),
  196.                 'type'              => 'color-alpha',
  197.                 'custom_color'      => true,
  198.                 'tab_slug'          => 'advanced',
  199.             ),
  200.         );
  201.         return $fields;
  202.     }
  203.  
  204.     function shortcode_callback( $atts, $content = null, $function_name ) {
  205.         $module_id          = $this->shortcode_atts['module_id'];
  206.         $module_class       = $this->shortcode_atts['module_class'];
  207.         $fullwidth          = $this->shortcode_atts['fullwidth'];
  208.         $posts_number       = $this->shortcode_atts['posts_number'];
  209.         $include_categories = $this->shortcode_atts['include_categories'];
  210.         $show_title         = $this->shortcode_atts['show_title'];
  211.         $show_categories    = $this->shortcode_atts['show_categories'];
  212.         $show_pagination    = $this->shortcode_atts['show_pagination'];
  213.         $background_layout  = $this->shortcode_atts['background_layout'];
  214.         $hover_icon          = $this->shortcode_atts['hover_icon'];
  215.         $zoom_icon_color     = $this->shortcode_atts['zoom_icon_color'];
  216.         $hover_overlay_color = $this->shortcode_atts['hover_overlay_color'];
  217.  
  218.         $module_class = ET_Builder_Element::add_module_order_class( $module_class, $function_name );
  219.  
  220.         wp_enqueue_script( 'hashchange' );
  221.  
  222.         $args = array();
  223.  
  224.         if ( '' !== $zoom_icon_color ) {
  225.             ET_Builder_Element::set_style( $function_name, array(
  226.                 'selector'    => '%%order_class%% .et_overlay:before',
  227.                 'declaration' => sprintf(
  228.                     'color: %1$s !important;',
  229.                     esc_html( $zoom_icon_color )
  230.                 ),
  231.             ) );
  232.         }
  233.  
  234.         if ( '' !== $hover_overlay_color ) {
  235.             ET_Builder_Element::set_style( $function_name, array(
  236.                 'selector'    => '%%order_class%% .et_overlay',
  237.                 'declaration' => sprintf(
  238.                     'background-color: %1$s;
  239.                    border-color: %1$s;',
  240.                     esc_html( $hover_overlay_color )
  241.                 ),
  242.             ) );
  243.         }
  244.  
  245.         if( 'on' === $show_pagination ) {
  246.             $args['nopaging'] = true;
  247.         } else {
  248.             $args['posts_per_page'] = (int) $posts_number;
  249.         }
  250.  
  251.         if ( '' !== $include_categories ) {
  252.             $args['tax_query'] = array(
  253.                 array(
  254.                     'taxonomy' => 'project_category',
  255.                     'field' => 'id',
  256.                     'terms' => explode( ',', $include_categories ),
  257.                     'operator' => 'IN',
  258.                 )
  259.             );
  260.         }
  261.  
  262.         $projects = et_divi_get_projects( $args );
  263.  
  264.         $categories_included = array();
  265.         ob_start();
  266.         if( $projects->post_count > 0 ) {
  267.             while ( $projects->have_posts() ) {
  268.                 $projects->the_post();
  269.  
  270.                 $category_classes = array();
  271.                 $categories = get_the_terms( get_the_ID(), 'project_category' );
  272.                 if ( $categories ) {
  273.                     foreach ( $categories as $category ) {
  274.                         $category_classes[] = 'project_category_' . urldecode( $category->slug );
  275.                         $categories_included[] = $category->term_id;
  276.                     }
  277.                 }
  278.  
  279.                 $category_classes = implode( ' ', $category_classes );
  280.  
  281.                 $main_post_class = sprintf(
  282.                     'et_pb_portfolio_item%1$s %2$s',
  283.                     ( 'on' !== $fullwidth ? ' et_pb_grid_item' : '' ),
  284.                     $category_classes
  285.                 );
  286.  
  287.                 ?>
  288.                 <div id="post-<?php the_ID(); ?>" <?php post_class( $main_post_class ); ?>>
  289.                 <?php
  290.                     $thumb = '';
  291.  
  292.                     $width = 'on' === $fullwidth ?  1080 : 400;
  293.                     $width = (int) apply_filters( 'et_pb_portfolio_image_width', $width );
  294.  
  295.                     $height = 'on' === $fullwidth ?  9999 : 284;
  296.                     $height = (int) apply_filters( 'et_pb_portfolio_image_height', $height );
  297.                     $classtext = 'on' === $fullwidth ? 'et_pb_post_main_image' : '';
  298.                     $titletext = get_the_title();
  299.                     $thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
  300.                     $thumb = $thumbnail["thumb"];
  301.  
  302.                     if ( '' !== $thumb ) : ?>
  303.                         <a href="<?php the_permalink(); ?>">
  304.  
  305.                         <?php if ( 'on' !== $fullwidth ) : ?>
  306.                             <span class="et_portfolio_image">
  307.                         <?php endif; ?>
  308.  
  309.  
  310.                                 <?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
  311.                         <?php if ( 'on' !== $fullwidth ) :
  312.  
  313.                                 $data_icon = '' !== $hover_icon
  314.                                     ? sprintf(
  315.                                         ' data-icon="%1$s"',
  316.                                         esc_attr( et_pb_process_font_icon( $hover_icon ) )
  317.                                     )
  318.                                     : '';
  319.  
  320.  
  321.                                 printf( '<span class="et_overlay%1$s"%2$s></span>',
  322.                                     ( '' !== $hover_icon ? ' et_pb_inline_icon' : '' ),
  323.                                     $data_icon
  324.                                 );
  325.  
  326.                         ?>
  327.                             </span>
  328.                         <?php endif; ?>
  329.  
  330.                         </a>
  331.                 <?php
  332.                     endif;
  333.                 ?>
  334.  
  335.  
  336.                 <?php if ( 'on' === $show_title ) : ?>
  337.                     <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  338.                 <?php endif; ?>
  339.  
  340.                
  341.  
  342.                 <?php if ( 'on' === $show_categories ) : ?>
  343.                     <p class="post-meta"><?php echo get_the_term_list( get_the_ID(), 'project_category', '', ', ' ); ?></p>
  344.                 <?php endif; ?>
  345.  
  346.                          <div class="clientlogo">
  347.                                            
  348.                                 <?php
  349.  
  350.                         $image = get_field('client_logo');
  351.                         $size = 'full'; // (thumbnail, medium, large, full or custom size)
  352.  
  353.                         if( $image ) {
  354.  
  355.                             echo wp_get_attachment_image( $image, $size );
  356.  
  357.                         }
  358.  
  359.                         ?>
  360.                         </div>
  361.  
  362.  
  363.                                 </div><!-- .et_pb_portfolio_item -->
  364.                 <?php
  365.             }
  366.         }
  367.  
  368.         wp_reset_postdata();
  369.  
  370.         $posts = ob_get_clean();
  371.  
  372.         $categories_included = explode ( ',', $include_categories );
  373.         $terms_args = array(
  374.             'include' => $categories_included,
  375.             'orderby' => 'name',
  376.             'order' => 'ASC',
  377.         );
  378.         $terms = get_terms( 'project_category', $terms_args );
  379.  
  380.         $category_filters = '<ul class="clearfix">';
  381.         $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>',
  382.             esc_html__( 'All', 'et_builder' )
  383.         );
  384.         foreach ( $terms as $term  ) {
  385.             $category_filters .= sprintf( '<li class="et_pb_portfolio_filter"><a href="#" data-category-slug="%1$s">%2$s</a></li>',
  386.                 esc_attr( urldecode( $term->slug ) ),
  387.                 esc_html( $term->name )
  388.             );
  389.         }
  390.         $category_filters .= '</ul>';
  391.  
  392.         $class = " et_pb_module et_pb_bg_layout_{$background_layout}";
  393.  
  394.         $output = sprintf(
  395.             '<div%5$s class="et_pb_filterable_portfolio %1$s%4$s%6$s" data-posts-number="%7$d"%10$s>
  396.                <div class="et_pb_portfolio_filters clearfix">%2$s</div><!-- .et_pb_portfolio_filters -->
  397.  
  398.                <div class="et_pb_portfolio_items_wrapper %8$s">
  399.                    <div class="et_pb_portfolio_items">%3$s</div><!-- .et_pb_portfolio_items -->
  400.                </div>
  401.                %9$s
  402.            </div> <!-- .et_pb_filterable_portfolio -->',
  403.             ( 'on' === $fullwidth ? 'et_pb_filterable_portfolio_fullwidth' : 'et_pb_filterable_portfolio_grid clearfix' ),
  404.             $category_filters,
  405.             $posts,
  406.             esc_attr( $class ),
  407.             ( '' !== $module_id ? sprintf( ' id="%1$s"', esc_attr( $module_id ) ) : '' ),
  408.             ( '' !== $module_class ? sprintf( ' %1$s', esc_attr( $module_class ) ) : '' ),
  409.             esc_attr( $posts_number),
  410.             ('on' === $show_pagination ? '' : 'no_pagination' ),
  411.             ('on' === $show_pagination ? '<div class="et_pb_portofolio_pagination"></div>' : '' ),
  412.             is_rtl() ? ' data-rtl="true"' : ''
  413.         );
  414.  
  415.         return $output;
  416.     }
  417. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement