Advertisement
cipher87

Portfolio

Feb 9th, 2021
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 49.66 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Portfolio Grid
  4.  *
  5.  * Creates a grid of portfolio excerpts
  6.  */
  7. if ( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  8.  
  9.  
  10. if ( ! class_exists( 'avia_sc_portfolio' ) )
  11. {
  12.     class avia_sc_portfolio extends aviaShortcodeTemplate
  13.     {
  14.         /**
  15.          * Needed for unique ID if no id specified
  16.          *
  17.          * @since 4.5.7.2
  18.          * @var int
  19.          */
  20.         static protected $portfolio_count = 0;
  21.  
  22.         /**
  23.          * Create the config array for the shortcode button
  24.          */
  25.         function shortcode_insert_button()
  26.         {
  27.             $this->config['version']        = '1.0';
  28.             $this->config['is_fullwidth']   = 'yes';
  29.             $this->config['self_closing']   = 'yes';
  30.             $this->config['base_element']   = 'yes';
  31.  
  32.             $this->config['name']           = __( 'Portfolio Grid', 'avia_framework' );
  33.             $this->config['tab']            = __( 'Content Elements', 'avia_framework' );
  34.             $this->config['icon']           = AviaBuilder::$path['imagesURL'] . 'sc-portfolio.png';
  35.             $this->config['order']          = 38;
  36.             $this->config['target']         = 'avia-target-insert';
  37.             $this->config['shortcode']      = 'av_portfolio';
  38.             $this->config['tooltip']        = __( 'Creates a grid of portfolio excerpts', 'avia_framework' );
  39.             $this->config['disabling_allowed'] = true;
  40.             $this->config['id_name']        = 'id';
  41.             $this->config['id_show']        = 'yes';
  42.             $this->config['linkpickers']    = array( 'link' );      //needed when theme support avia_template_builder_custom_post_type_grid
  43.         }
  44.  
  45.         function extra_assets()
  46.         {
  47.             //start sessions - only necessary for correct breadcrumb nav on single portfolio pages
  48.             if( ! is_admin() && ! current_theme_supports( 'avia_no_session_support' ) && ! session_id() )
  49.             {
  50.                 session_start();
  51.             }
  52.  
  53.             //load css
  54.             wp_enqueue_style( 'avia-module-portfolio', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/portfolio/portfolio.css', array( 'avia-layout' ), false );
  55.  
  56.             //load js
  57.             wp_enqueue_script( 'avia-module-isotope', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/portfolio/isotope.js', array( 'avia-shortcodes' ), false , true );
  58.             wp_enqueue_script( 'avia-module-portfolio', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/portfolio/portfolio.js', array( 'avia-shortcodes' ), false , true );
  59.         }
  60.  
  61.         /**
  62.          * Popup Elements
  63.          *
  64.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  65.          * opens a modal window that allows to edit the element properties
  66.          *
  67.          * @return void
  68.          */
  69.         function popup_elements()
  70.         {
  71.             $this->elements = array(
  72.                    
  73.                 array(
  74.                         'type'  => 'tab_container',
  75.                         'nodescription' => true
  76.                     ),
  77.                        
  78.                 array(
  79.                         'type'  => 'tab',
  80.                         'name'  => __( 'Content', 'avia_framework' ),
  81.                         'nodescription' => true
  82.                     ),
  83.                
  84.                     array(
  85.                             'type'          => 'template',
  86.                             'template_id'   => 'toggle_container',
  87.                             'templates_include' => array(
  88.                                                     $this->popup_key( 'content_entries' ),
  89.                                                     $this->popup_key( 'content_filter' ),
  90.                                                     $this->popup_key( 'content_sorting' ),
  91.                                                     $this->popup_key( 'content_excerpt' )
  92.                                                 ),
  93.                             'nodescription' => true
  94.                         ),
  95.                
  96.                 array(
  97.                         'type'  => 'tab_close',
  98.                         'nodescription' => true
  99.                     ),
  100.  
  101.                 array(
  102.                         'type'  => 'tab',
  103.                         'name'  => __( 'Styling', 'avia_framework' ),
  104.                         'nodescription' => true
  105.                     ),
  106.                
  107.                     array(
  108.                             'type'          => 'template',
  109.                             'template_id'   => 'toggle_container',
  110.                             'templates_include' => array(
  111.                                                     $this->popup_key( 'styling_grid' ),
  112.                                                     $this->popup_key( 'styling_columns' ),
  113.                                                     $this->popup_key( 'styling_pagination' )
  114.                                                 ),
  115.                             'nodescription' => true
  116.                         ),
  117.                
  118.                 array(
  119.                         'type'  => 'tab_close',
  120.                         'nodescription' => true
  121.                     ),
  122.                
  123.                 array(
  124.                         'type'  => 'tab',
  125.                         'name'  => __( 'Advanced', 'avia_framework' ),
  126.                         'nodescription' => true
  127.                     ),
  128.                
  129.                     array(
  130.                             'type'  => 'toggle_container',
  131.                             'nodescription' => true
  132.                         ),
  133.                
  134.                         array( 
  135.                                 'type'          => 'template',
  136.                                 'template_id'   => $this->popup_key( 'advanced_link' )
  137.                             ),
  138.                
  139.                         array(
  140.                                 'type'          => 'template',
  141.                                 'template_id'   => 'lazy_loading_toggle',
  142.                                 'lockable'      => true
  143.                             ),
  144.                
  145.                         array( 
  146.                                 'type'          => 'template',
  147.                                 'template_id'   => 'screen_options_toggle',
  148.                                 'lockable'      => true
  149.                             ),
  150.                
  151.                         array( 
  152.                                 'type'          => 'template',
  153.                                 'template_id'   => 'developer_options_toggle',
  154.                                 'args'          => array( 'sc' => $this )
  155.                             ),
  156.                
  157.                     array(
  158.                             'type'  => 'toggle_container_close',
  159.                             'nodescription' => true
  160.                         ),
  161.                
  162.                 array(
  163.                         'type'  => 'tab_close',
  164.                         'nodescription' => true
  165.                     ),
  166.                
  167.                 array( 
  168.                         'type'          => 'template',
  169.                         'template_id'   => 'element_template_selection_tab',
  170.                         'args'          => array( 'sc' => $this )
  171.                     ),
  172.  
  173.                 array(
  174.                         'type'  => 'tab_container_close',
  175.                         'nodescription' => true
  176.                     )
  177.  
  178.                 );
  179.         }
  180.        
  181.         /**
  182.          * Create and register templates for easier maintainance
  183.          *
  184.          * @since 4.6.4
  185.          */
  186.         protected function register_dynamic_templates()
  187.         {
  188.            
  189.             /**
  190.              * Content Tab
  191.              * ===========
  192.              */
  193.            
  194.             if( ! current_theme_supports( 'avia_template_builder_custom_post_type_grid' ) )
  195.             {
  196.                 $c = array(
  197.                         array( 
  198.                             'name'      => __( 'Which categories should be used for the portfolio?', 'avia_framework' ),
  199.                             'desc'      => __( 'You can select multiple categories here. The Page will then show posts from only those categories.', 'avia_framework' ),
  200.                             'id'        => 'categories',
  201.                             'type'      => 'select',
  202.                             'multiple'  => 6,
  203.                             'lockable'  => true,
  204.                             'taxonomy'  => 'portfolio_entries',
  205.                             'subtype'   => 'cat'
  206.                         )
  207.                 );
  208.             }
  209.             else
  210.             {
  211.                 $c = array(
  212.                         array(
  213.                             'name'  => __( 'Which Entries?', 'avia_framework' ),
  214.                             'desc'  => __( 'Select which entries should be displayed by selecting a taxonomy', 'avia_framework' ),
  215.                             'id'    => 'link',
  216.                             'type'  => 'linkpicker',
  217.                             'multiple'  => 6,
  218.                             'fetchTMPL' => true,
  219.                             'std'       => 'category',
  220.                             'lockable'  => true,
  221.                             'subtype'   => array( __( 'Display Entries from:', 'avia_framework' ) => 'taxonomy' )
  222.                         )
  223.                     );
  224.  
  225.  
  226.                 if( current_theme_supports( 'add_avia_builder_post_type_option' ) )
  227.                 {
  228.                     $element = array(  
  229.                                 'type'          => 'template',
  230.                                 'template_id'   => 'avia_builder_post_type_option',
  231.                                 'lockable'      => true,
  232.                             );
  233.                        
  234.                     array_unshift( $c, $element );
  235.                 }
  236.             }
  237.            
  238.            
  239.             $template = array(
  240.                             array( 
  241.                                 'type'          => 'template',
  242.                                 'template_id'   => 'toggle',
  243.                                 'title'         => __( 'Select Entries', 'avia_framework' ),
  244.                                 'content'       => $c
  245.                             ),
  246.                     );
  247.            
  248.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_entries' ), $template );
  249.            
  250.             $c = array(
  251.                         array( 
  252.                             'type'          => 'template',
  253.                             'template_id'   => 'date_query',
  254.                             'lockable'      => true,
  255.                         ),
  256.                
  257.                 );
  258.            
  259.             $template = array(
  260.                             array( 
  261.                                 'type'          => 'template',
  262.                                 'template_id'   => 'toggle',
  263.                                 'title'         => __( 'Filter', 'avia_framework' ),
  264.                                 'content'       => $c
  265.                             ),
  266.                     );
  267.            
  268.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_filter' ), $template );
  269.            
  270.             $c = array(
  271.                         array(
  272.                             'name'  => __( 'Sortable?', 'avia_framework' ),
  273.                             'desc'  => __( 'Should the sorting options based on categories be displayed?', 'avia_framework' ),
  274.                             'id'    => 'sort',
  275.                             'type'  => 'select',
  276.                             'std'   => 'yes',
  277.                             'lockable'  => true,
  278.                             'subtype'   => array(
  279.                                                 __( 'Yes, display sort options', 'avia_framework' )         => 'yes',
  280.                                                 __( 'Yes, display sort options and currently active categories', 'avia_framework' ) => 'yes-tax',
  281.                                                 __( 'No, do not display sort options', 'avia_framework' )   => 'no'
  282.                                             )
  283.                         ),
  284.                
  285.                         array(
  286.                             'name'  => __( 'Order by', 'avia_framework' ),
  287.                             'desc'  => __( 'You can order the result by various attributes like creation date, title, author etc', 'avia_framework' ),
  288.                             'id'    => 'query_orderby',
  289.                             'type'  => 'select',
  290.                             'std'   => 'date',
  291.                             'lockable'  => true,
  292.                             'subtype'   => array(
  293.                                                 __( 'Date', 'avia_framework' )              => 'date',
  294.                                                 __( 'Title', 'avia_framework' )             => 'title',
  295.                                                 __( 'Random', 'avia_framework' )            => 'rand',
  296.                                                 __( 'Author', 'avia_framework' )            => 'author',
  297.                                                 __( 'Name (Post Slug)', 'avia_framework' )  => 'name',
  298.                                                 __( 'Last modified', 'avia_framework' )     => 'modified',
  299.                                                 __( 'Comment Count', 'avia_framework' )     => 'comment_count',
  300.                                                 __( 'Page Order', 'avia_framework' )        => 'menu_order'
  301.                                             )
  302.                         ),
  303.                        
  304.                         array(
  305.                             'name'  => __( 'Display order', 'avia_framework' ),
  306.                             'desc'  => __( 'Display the results either in ascending or descending order', 'avia_framework' ),
  307.                             'id'    => 'query_order',
  308.                             'type'  => 'select',
  309.                             'std'   => 'DESC',
  310.                             'lockable'  => true,
  311.                             'subtype'   => array(
  312.                                                 __( 'Ascending Order', 'avia_framework' )   => 'ASC',
  313.                                                 __( 'Descending Order', 'avia_framework' )  => 'DESC'
  314.                                             )
  315.                         )
  316.                 );
  317.            
  318.             $template = array(
  319.                             array( 
  320.                                 'type'          => 'template',
  321.                                 'template_id'   => 'toggle',
  322.                                 'title'         => __( 'Sorting', 'avia_framework' ),
  323.                                 'content'       => $c
  324.                             ),
  325.                     );
  326.            
  327.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_sorting' ), $template );
  328.            
  329.             $c = array(
  330.                         array(
  331.                             'name'  => __( 'Excerpt', 'avia_framework' ),
  332.                             'desc'  => __( 'Display Excerpt and Title below the preview image?', 'avia_framework' ),
  333.                             'id'    => 'contents',
  334.                             'type'  => 'select',
  335.                             'std'   => 'title',
  336.                             'lockable'  => true,
  337.                             'subtype'   => array(
  338.                                                 __( 'Title and Excerpt', 'avia_framework' )         => 'excerpt',
  339.                                                 __( 'Only Title', 'avia_framework' )                => 'title',
  340.                                                 __( 'Only excerpt', 'avia_framework' )              => 'only_excerpt',
  341.                                                 __( 'No Title and no excerpt', 'avia_framework' )   => 'no'
  342.                                             )
  343.                         )
  344.  
  345.                     );
  346.            
  347.             $template = array(
  348.                             array( 
  349.                                 'type'          => 'template',
  350.                                 'template_id'   => 'toggle',
  351.                                 'title'         => __( 'Excerpt', 'avia_framework' ),
  352.                                 'content'       => $c
  353.                             ),
  354.                     );
  355.            
  356.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_excerpt' ), $template );
  357.            
  358.             /**
  359.              * Styling Tab
  360.              * ===========
  361.              */
  362.            
  363.             $c = array(
  364.                
  365. //                 
  366. //                  array(
  367. //                      'name'  => __( 'Style?', 'avia_framework' ),
  368. //                      'desc'  => __( 'Choose the style of the entries here', 'avia_framework' ),
  369. //                      'id'    => 'style',
  370. //                      'type'  => 'select',
  371. //                      'std'   => '',
  372. //                      'subtype'   => array(
  373. //                                          __( 'Default Style', 'avia_framework' )         => '',
  374. //                                          __( 'Circle Image Stlye', 'avia_framework' )    => 'grid-circle'
  375. //                                      )
  376. //                  ),
  377. //                 
  378.                     array(
  379.                         'name'  => __( 'Portfolio Grid Image Size', 'avia_framework' ),
  380.                         'desc'  => __( 'Set the image size of the Portfolio Grid images', 'avia_framework' ),
  381.                         'id'    => 'preview_mode',
  382.                         'type'  => 'select',
  383.                         'std'   => 'auto',
  384.                         'lockable'  => true,
  385.                         'subtype'   => array(
  386.                                             __( 'Set the Portfolio Grid image size automatically based on column or layout width', 'avia_framework' )   => 'auto',
  387.                                             __( 'Choose the Portfolio Grid image size manually (select thumbnail size)', 'avia_framework' )             => 'custom'
  388.                                         )
  389.                     ),
  390.  
  391.                     array(
  392.                         'name'  => __( 'Select custom image size', 'avia_framework' ),
  393.                         'desc'  => __( 'Choose image size for Portfolio Grid Images', 'avia_framework' ) . '<br/><small>' . __( '(Note: Images will be scaled to fit for the amount of columns chosen above)', 'avia_framework' ) . '</small>',
  394.                         'id'    => 'image_size',
  395.                         'type'  => 'select',
  396.                         'std'       => 'portfolio',
  397.                         'lockable'  => true,
  398.                         'required'  => array( 'preview_mode', 'equals', 'custom' ),
  399.                         'subtype'   =>  AviaHelper::get_registered_image_sizes( array( 'logo', 'thumbnail', 'widget' ) )
  400.                     )
  401.                
  402.                 );
  403.            
  404.             $template = array(
  405.                             array( 
  406.                                 'type'          => 'template',
  407.                                 'template_id'   => 'toggle',
  408.                                 'title'         => __( 'Grid Settings', 'avia_framework' ),
  409.                                 'content'       => $c
  410.                             ),
  411.                     );
  412.            
  413.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_grid' ), $template );
  414.            
  415.             $responsive = array(
  416.                                     __( 'Use Default', 'avia_framework' )   => '',
  417.                                     __( '1 Column', 'avia_framework' )      => '1',
  418.                                     __( '2 Columns', 'avia_framework' )     => '2',
  419.                                     __( '3 Columns', 'avia_framework' )     => '3',
  420.                                     __( '4 Columns', 'avia_framework' )     => '4'
  421.                                 );
  422.            
  423.             $subtype = array(
  424.                             'default'   => array(
  425.                                                 __( '1 Column', 'avia_framework' )  => '1',
  426.                                                 __( '2 Columns', 'avia_framework' ) => '2',
  427.                                                 __( '3 Columns', 'avia_framework' ) => '3',
  428.                                                 __( '4 Columns', 'avia_framework' ) => '4',
  429.                                                 __( '5 Columns', 'avia_framework' ) => '5',
  430.                                                 __( '6 Columns', 'avia_framework' ) => '6'
  431.                                             ),
  432.                             'medium'    => $responsive,    
  433.                             'small'     => $responsive,
  434.                             'mini'      => $responsive
  435.                         );
  436.            
  437.             $c = array(
  438.  
  439.                         array( 
  440.                                 'type'          => 'template',
  441.                                 'template_id'   => 'columns_count_icon_switcher',
  442.                                 'lockable'      => true,
  443.                                 'subtype'       => $subtype,
  444.                                 'std'           => array(
  445.                                                         'default'   => '4',
  446.                                                         'medium'    => '',
  447.                                                         'small'     => '',
  448.                                                         'mini'      => ''
  449.                                                     )
  450.                             ),
  451.                
  452.                          array(
  453.                                 'name'  => __( '1 Column layout', 'avia_framework' ),
  454.                                 'desc'  => __( 'Choose the 1 column layout', 'avia_framework' ),
  455.                                 'id'    => 'one_column_template',
  456.                                 'type'  => 'select',
  457.                                 'std'   => 'special',
  458.                                 'lockable'  => true,
  459.                                 'required'  => array( 'columns', 'equals', '1' ),
  460.                                 'subtype'   => array(
  461.                                                     __( 'Use special 1 column layout (side by side)', 'avia_framework' )    => 'special',
  462.                                                     __( 'Use default portfolio layout', 'avia_framework' )                  => 'default'
  463.                                                 )
  464.                             )
  465.                 );
  466.            
  467.             $template = array(
  468.                             array( 
  469.                                 'type'          => 'template',
  470.                                 'template_id'   => 'toggle',
  471.                                 'title'         => __( 'Columns', 'avia_framework' ),
  472.                                 'content'       => $c
  473.                             ),
  474.                     );
  475.            
  476.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_columns' ), $template );
  477.            
  478.             $c = array(
  479.                         array(
  480.                             'name'  => __( 'Post Number', 'avia_framework' ),
  481.                             'desc'  => __( 'How many items should be displayed per page?', 'avia_framework' ),
  482.                             'id'    => 'items',
  483.                             'type'  => 'select',
  484.                             'std'   => '16',
  485.                             'lockable'  => true,
  486.                             'subtype'   => AviaHtmlHelper::number_array( 1, 100, 1, array( 'All' => '-1' ) )
  487.                         ),
  488.  
  489.                         array(
  490.                             'name'  => __( 'Pagination', 'avia_framework' ),
  491.                             'desc'  => __( 'Should a pagination be displayed?', 'avia_framework' ),
  492.                             'id'    => 'paginate',
  493.                             'type'  => 'select',
  494.                             'std'   => 'yes',
  495.                             'lockable'  => true,
  496.                             'subtype'   => array(
  497.                                                 __( 'yes', 'avia_framework' )   => 'yes',
  498.                                                 __( 'no', 'avia_framework' )    => 'no'
  499.                                             )
  500.                         ),
  501.  
  502.                 );
  503.            
  504.             $template = array(
  505.                             array( 
  506.                                 'type'          => 'template',
  507.                                 'template_id'   => 'toggle',
  508.                                 'title'         => __( 'Pagination', 'avia_framework' ),
  509.                                 'content'       => $c
  510.                             ),
  511.                     );
  512.            
  513.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_pagination' ), $template );
  514.            
  515.             /**
  516.              * Advanced Tab
  517.              * ============
  518.              */
  519.            
  520.             $c = array(
  521.                         array(
  522.                             'name'  => __( 'Link Handling', 'avia_framework' ),
  523.                             'desc'  => __( 'When clicking on a portfolio item you can choose to open the link to the single entry, open a preview (aka AJAX Portfolio) or show a bigger version of the image in a lightbox overlay', 'avia_framework' ),
  524.                             'id'    => 'linking',
  525.                             'type'  => 'select',
  526.                             'std'   => '',
  527.                             'lockable'  => true,
  528.                             'subtype'   => array(
  529.                                                 __( 'Open the entry on a new page', 'avia_framework' )                          => '',
  530.                                                 __( 'Open a preview of the entry (known as AJAX Portfolio)', 'avia_framework' ) => 'ajax',
  531.                                                 __( 'Display the big image in a lightbox', 'avia_framework' )                   => 'lightbox'
  532.                                             )
  533.                         ),
  534.  
  535.                 );
  536.            
  537.             $template = array(
  538.                             array( 
  539.                                 'type'          => 'template',
  540.                                 'template_id'   => 'toggle',
  541.                                 'title'         => __( 'Link Setting', 'avia_framework' ),
  542.                                 'content'       => $c
  543.                             ),
  544.                     );
  545.            
  546.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_link' ), $template );
  547.            
  548.            
  549.         }
  550.  
  551.  
  552.         /**
  553.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  554.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  555.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  556.          *
  557.          *
  558.          * @param array $params this array holds the default values for $content and $args.
  559.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  560.          */
  561.         function editor_element( $params )
  562.         {
  563.            
  564.             $params = parent::editor_element( $params );
  565.             $params['innerHtml'] .= AviaPopupTemplates()->get_html_template( 'alb_element_fullwidth_stretch' );
  566.  
  567.             $params['content']   = null; //remove to allow content elements
  568.  
  569.             return $params;
  570.         }
  571.  
  572.  
  573.  
  574.         /**
  575.          * Frontend Shortcode Handler
  576.          *
  577.          * @param array $atts array of attributes
  578.          * @param string $content text within enclosing form of shortcode element
  579.          * @param string $shortcodename the shortcode found, when == callback name
  580.          * @return string $output returns the modified html string
  581.          */
  582.         function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  583.         {
  584.             $default = avia_post_grid::get_defaults();
  585.            
  586.             $locked = array();
  587.             Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content );
  588.             Avia_Element_Templates()->add_template_class( $meta, $atts, $default );
  589.            
  590.             extract( AviaHelper::av_mobile_sizes( $atts ) ); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  591.            
  592.             $atts = array_merge( $default, $atts );
  593.            
  594.             if( current_theme_supports( 'avia_template_builder_custom_post_type_grid' ) )
  595.             {
  596.                 if( isset( $atts['link'] ) )
  597.                 {
  598.                     $atts['link'] = explode( ',', $atts['link'], 2 );
  599.                     $atts['taxonomy'] = $atts['link'][0];
  600.  
  601.                     if( isset( $atts['link'][1] ) )
  602.                     {
  603.                         $atts['categories'] = $atts['link'][1];
  604.                     }
  605.                 }
  606.  
  607.                 if( empty( $atts['post_type'] ) || ! current_theme_supports( 'add_avia_builder_post_type_option' ) )
  608.                 {
  609.                     $atts['post_type'] = get_post_types();
  610.                 }
  611.  
  612.                 if( is_string( $atts['post_type'] ) )
  613.                 {
  614.                     $atts['post_type'] = explode( ',', $atts['post_type'] );
  615.                 }
  616.             }
  617.             else
  618.             {
  619.                 /**
  620.                  * @used_by             config-wpml\config.php      avia_translate_object_ids()
  621.                  * @since 4.6.4
  622.                  * @param string
  623.                  * @param string
  624.                  * @param avia_sc_portfolio $this
  625.                  * @return string
  626.                  */
  627.                 $atts['categories'] = apply_filters( 'avf_alb_taxonomy_values', $atts['categories'], 'portfolio_entries' );
  628.             }
  629.                
  630.             self::$portfolio_count ++;
  631.  
  632.             $el_id = ! empty( $meta['custom_el_id'] ) ? $meta['custom_el_id'] : ' id="av-sc-portfolio-' . self::$portfolio_count . '" ';
  633.             $atts['class'] = ! empty( $meta['custom_class'] ) ? $meta['custom_class'] : '';
  634.             $atts['el_id'] = '';
  635.             $atts['fullscreen'] = ShortcodeHelper::is_top_level();
  636.             if( ! $atts['fullscreen'] )
  637.             {
  638.                 $atts['el_id'] = $el_id;
  639.             }
  640.  
  641.             $grid = new avia_post_grid( $atts );
  642.             $grid->query_entries();
  643.             $portfolio_html = $grid->html();
  644.            
  645.             $portfolio_html = Av_Responsive_Images()->make_content_images_responsive( $portfolio_html );
  646.  
  647.             if( ! ShortcodeHelper::is_top_level() )
  648.             {
  649.                 return $portfolio_html;
  650.             }
  651.                
  652.             $params['class'] = "main_color avia-no-border-styling avia-fullwidth-portfolio {$av_display_classes} {$meta['el_class']}";
  653.             $params['open_structure'] = false;
  654.             $params['id'] = AviaHelper::save_string( $meta['custom_id_val'] , '-', 'av-sc-portfolio-' . self::$portfolio_count );
  655.             $params['custom_markup'] = $meta['custom_markup'];
  656.  
  657.             //we dont need a closing structure if the element is the first one or if a previous fullwidth element was displayed before
  658.             if( isset( $meta['index'] ) && $meta['index'] == 0 )
  659.             {
  660.                 $params['close'] = false;
  661.             }
  662.            
  663.             if( ! empty( $meta['siblings']['prev']['tag'] ) && in_array( $meta['siblings']['prev']['tag'], AviaBuilder::$full_el_no_section ) )
  664.             {
  665.                 $params['close'] = false;
  666.             }
  667.  
  668.             $output  = avia_new_section( $params );
  669.             $output .= $portfolio_html;
  670.             $output .= avia_section_after_element_content( $meta , 'after_portfolio' );
  671.  
  672.             return $output;
  673.         }
  674.     }
  675. }
  676.  
  677.  
  678.  
  679.  
  680. if ( ! class_exists( 'avia_post_grid' ) )
  681. {
  682.     class avia_post_grid
  683.     {
  684.         /**
  685.          *
  686.          * @var int
  687.          */
  688.         static protected $grid = 0;
  689.        
  690.         /**
  691.          *
  692.          * @var array
  693.          */
  694.         static protected $preview_template = array();
  695.        
  696.         /**
  697.          *
  698.          * @var array
  699.          */
  700.         protected $atts;
  701.        
  702.         /**
  703.          *
  704.          * @var WP_Query
  705.          */
  706.         protected $entries;
  707.        
  708.         /**
  709.          *
  710.          * @var array
  711.          */
  712.         protected $screen_options;
  713.        
  714.         /**
  715.          *
  716.          * @since 4.7.6.4
  717.          * @var int
  718.          */
  719.         protected $current_page;
  720.  
  721.         /**
  722.          *
  723.          * @param type $atts
  724.          */
  725.         public function __construct( $atts = array() )
  726.         {
  727.             $this->entries = null;
  728.             $this->screen_options = AviaHelper::av_mobile_sizes( $atts );
  729.             $this->current_page = 1;
  730.            
  731.             $this->atts = shortcode_atts( avia_post_grid::get_defaults(), $atts, 'av_portfolio' );
  732.  
  733.             if( $this->atts['linking'] == 'ajax' )
  734.             {
  735.                 add_action( 'wp_footer' , array( $this, 'print_preview_templates' ) );
  736.             }
  737.         }
  738.        
  739.         /**
  740.          *
  741.          * @since 4.5.7.2
  742.          */
  743.         public function __destruct()
  744.         {
  745.             unset( $this->atts );
  746.             unset( $this->screen_options );
  747.             unset( $this->entries );
  748.         }
  749.        
  750.         /**
  751.          * Returns the default array for this class
  752.          *
  753.          * @since 4.8
  754.          * @return array
  755.          */
  756.         static public function get_defaults()
  757.         {
  758.             $default = array(
  759.                         'style'                 => '',
  760.                         'linking'               => '',
  761.                         'columns'               => '4',
  762.                         'items'                 => '16',
  763.                         'contents'              => 'title',
  764.                         'sort'                  => 'yes',
  765.                         'paginate'              => 'yes',
  766.                         'categories'            => '',
  767.                         'preview_mode'          => 'auto',
  768.                         'image_size'            => 'portfolio',
  769.                         'post_type'             => 'portfolio',
  770.                         'taxonomy'              => 'portfolio_entries',
  771.                         'one_column_template'   => 'special',
  772.                         'set_breadcrumb'        => true, //no shortcode option for this, modifies the breadcrumb nav, must be false on taxonomy overview
  773.                         'class'                 => '',
  774.                         'el_id'                 => '',
  775.                         'custom_markup'         => '',
  776.                         'fullscreen'            => false,
  777.                         'query_orderby'         => 'date',
  778.                         'query_order'           => 'DESC',
  779.                         'date_filter'           => '', 
  780.                         'date_filter_start'     => '',
  781.                         'date_filter_end'       => '',
  782.                         'date_filter_format'    => 'yy/mm/dd',      //  'yy/mm/dd' | 'dd-mm-yy' | yyyymmdd
  783.                         'lazy_loading'          => 'disabled'
  784.             );
  785.            
  786.             return $default;
  787.         }
  788.  
  789.         /**
  790.          * enerates the html of the post grid
  791.          *
  792.          * @since < 4.0
  793.          * @since 4.8               added $query_var_page
  794.          * @param string $query_var_page            set to '' to use stamdard WP pagination query var (e.g. from taxonomy-portfolio_entries.php)
  795.          * @return string
  796.          */
  797.         public function html( $query_var_page = 'avia-element-paging' )
  798.         {
  799.             if( empty( $this->entries ) || empty( $this->entries->posts ) )
  800.             {
  801.                 return '';
  802.             }
  803.            
  804.             avia_post_grid::$grid ++;
  805.            
  806.             extract( $this->screen_options ); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  807.             extract( $this->atts );
  808.              
  809.            
  810.             $container_id = avia_post_grid::$grid;
  811.             $extraClass = 'first';
  812.             $grid = 'one_fourth';
  813.            
  814.             if( $preview_mode == 'auto' )
  815.             {
  816.                 $image_size = 'portfolio';
  817.             }
  818.            
  819.             $post_loop_count    = 1;
  820.             $loop_counter       = 1;
  821.             $output             = '';
  822.             $style_class        = empty( $style ) ? 'no_margin' : $style;
  823.             $total              = $this->entries->post_count % 2 ? 'odd' : 'even';
  824.             $post_type_paginate = array();
  825.  
  826.             if( $set_breadcrumb && is_page() )
  827.             {
  828.                 if( ! is_array( $post_type ) )
  829.                 {
  830.                     $_SESSION["avia_{$post_type}"] = get_the_ID();
  831.                     $post_type_paginate[] = $post_type;
  832.                 }
  833.                 else
  834.                 {
  835.                     $filtered = array();
  836.                     foreach( $this->entries->posts as $entry )
  837.                     {
  838.                         if( ! $entry instanceof WP_Post )
  839.                         {
  840.                             continue;
  841.                         }
  842.                        
  843.                         if( ! in_array( $entry->post_type, $filtered ) )
  844.                         {
  845.                             $filtered[] = $entry->post_type;
  846.                         }
  847.                     }
  848.                    
  849.                     foreach( $filtered as $pt )
  850.                     {
  851.                         $_SESSION[ "avia_{$pt}" ] = get_the_ID();
  852.                         $post_type_paginate[] = $pt;
  853.                     }
  854.                 }
  855.             }
  856.  
  857.             switch( $columns )
  858.             {
  859.                 case '1':
  860.                     $grid = 'av_fullwidth';  
  861.                     if( $preview_mode == 'auto' )
  862.                     {
  863.                         $image_size = 'featured';
  864.                     }
  865.                     break;
  866.                 case '2':
  867.                     $grid = 'av_one_half';  
  868.                     break;
  869.                 case '3':
  870.                     $grid = 'av_one_third';  
  871.                     break;
  872.                 case '4':
  873.                     $grid = 'av_one_fourth';
  874.                     if( $preview_mode == 'auto' )
  875.                     {
  876.                         $image_size = 'portfolio_small';
  877.                     }
  878.                     break;
  879.                 case '5':
  880.                     $grid = 'av_one_fifth';  
  881.                     if( $preview_mode == 'auto' )
  882.                     {
  883.                         $image_size = 'portfolio_small';
  884.                     }
  885.                     break;
  886.                 case '6':
  887.                     $grid = 'av_one_sixth';  
  888.                     if( $preview_mode == 'auto' )
  889.                     {
  890.                         $image_size = 'portfolio_small';
  891.                     }
  892.                     break;
  893.             }
  894.            
  895.             if( $fullscreen && $preview_mode =='auto' && $image_size == 'portfolio_small' )
  896.             {
  897.                 $image_size = 'portfolio';
  898.             }
  899.  
  900.             if( $sort != 'no' )
  901.             {
  902.                 $output .= '<div ' . $el_id . ' class="av-portfolio-grid-sorting-container">';
  903.                 $el_id = '';
  904.             }
  905.            
  906.             $output .= $sort != 'no' ? $this->sort_buttons( $this->entries->posts, $this->atts ) : '';
  907.  
  908.             if( $linking == 'ajax' )
  909.             {
  910.                 $container_class = $fullscreen ? 'container' : '';
  911.                
  912.                 $output .= "<div class='portfolio_preview_container {$container_class}' data-portfolio-id='{$container_id}'>
  913.                                 <div class='ajax_controlls iconfont'>
  914.                                     <a href='#prev' class='ajax_previous'   " . av_icon_string('prev') . "></a>
  915.                                     <a href='#next' class='ajax_next'       " . av_icon_string('next') . "></a>
  916.                                     <a class='avia_close' href='#close'     " . av_icon_string('close') . "></a>
  917.                                 </div>
  918.                                 <div class='portfolio-details-inner'></div>
  919.                             </div>";
  920.             }
  921.            
  922.             $output .= "<div {$el_id} class='{$class} grid-sort-container isotope {$av_display_classes} {$av_column_classes} {$style_class}-container with-{$contents}-container grid-total-{$total} grid-col-{$columns} grid-links-{$linking}' data-portfolio-id='{$container_id}'>";
  923.  
  924.             foreach( $this->entries->posts as $index => $entry )
  925.             {
  926.                 $the_id = $entry->ID;
  927.                 $parity = $post_loop_count % 2 ? 'odd' : 'even';
  928.                 $last = $this->entries->post_count == $post_loop_count ? ' post-entry-last ' : '';
  929.                 $post_class = "post-entry post-entry-{$the_id} grid-entry-overview grid-loop-{$post_loop_count} grid-parity-{$parity} {$last}";
  930.                 $sort_class = $this->sort_cat_string( $the_id, $this->atts );
  931.                 $post_thumbnail_id = get_post_thumbnail_id( $the_id );
  932.                
  933.                 if( $lazy_loading != 'enabled' )
  934.                 {
  935.                     Av_Responsive_Images()->add_attachment_id_to_not_lazy_loading( $post_thumbnail_id );
  936.                 }
  937.  
  938.                 switch( $linking )
  939.                 {
  940.                     case 'lightbox':  
  941.                         $link = AviaHelper::get_url( 'lightbox', $post_thumbnail_id ); 
  942.                         break;
  943.                     default:         
  944.                         $link = get_permalink( $the_id );
  945.                         break;
  946.                 }
  947.  
  948.                 $title_link  = get_permalink( $the_id );
  949.                 $custom_link = get_post_meta( $the_id, '_portfolio_custom_link', true ) != '' ? get_post_meta( $the_id, '_portfolio_custom_link_url', true ) : false;
  950.  
  951.                 if( $custom_link )
  952.                 {
  953.                     $title_link = '';
  954.                     $link = $custom_link;
  955.                 }
  956.  
  957.                 $excerpt = '';
  958.                 $title = '';
  959.  
  960.                 switch( $contents )
  961.                 {
  962.                     case 'excerpt':
  963.                         $excerpt = $entry->post_excerpt;
  964.                         $title = avia_wp_get_the_title( $entry );
  965.                         break;
  966.                     case 'title':
  967.                         $excerpt = '';
  968.                         $title = avia_wp_get_the_title( $entry );  
  969.                         break;
  970.                     case 'only_excerpt':
  971.                         $excerpt = $entry->post_excerpt;
  972.                         $title = '';
  973.                         break;
  974.                     case 'no':
  975.                         $excerpt = '';
  976.                         $title = '';
  977.                         break;
  978.                 }
  979.  
  980.                 $custom_overlay = apply_filters( 'avf_portfolio_custom_overlay', '', $entry );
  981.                 $link_markup = apply_filters( 'avf_portfolio_custom_image_container', array( "a href='{$link}' title='" . esc_attr( strip_tags( $title ) ) . "' ",'a'), $entry );
  982.  
  983.                 $title = apply_filters( 'avf_portfolio_title', $title, $entry );
  984.                 $title_link = apply_filters( 'avf_portfolio_title_link', $title_link, $entry );
  985.                 $image_attrs = apply_filters( 'avf_portfolio_image_attrs', array(), $entry );
  986.  
  987.                 if( $columns == '1' && $one_column_template == 'special' )
  988.                 {
  989.                     $extraClass .= ' special_av_fullwidth ';
  990.  
  991.                     $output .= "<div data-ajax-id='{$the_id}' class=' grid-entry flex_column isotope-item all_sort {$style_class} {$post_class} {$sort_class} {$grid} {$extraClass}'>";
  992.                     $output .= "<article class='main_color inner-entry' " . avia_markup_helper( array( 'context' => 'entry', 'echo' => false, 'id' => $the_id, 'custom_markup' => $custom_markup ) ) . ">";
  993.  
  994.                     $output .= apply_filters( 'avf_portfolio_extra', '', $entry );
  995.  
  996.                     $output .= "<div class='av_table_col first portfolio-entry grid-content'>";
  997.  
  998.                     if( ! empty( $title ) )
  999.                     {
  1000.                         $markup = avia_markup_helper( array( 'context' => 'entry_title', 'echo' => false, 'id' => $the_id, 'custom_markup' => $custom_markup ) );
  1001.                        
  1002.                         $default_heading = 'h2';
  1003.                         $args = array(
  1004.                                     'heading'       => $default_heading,
  1005.                                     'extra_class'   => ''
  1006.                                 );
  1007.                        
  1008.                         $extra_args = array( $this, $index, 'one_column_template_special' );
  1009.  
  1010.                         /**
  1011.                          * @since 4.5.5
  1012.                          * @return array
  1013.                          */
  1014.                         $args = apply_filters( 'avf_customize_heading_settings', $args, __CLASS__, $extra_args );
  1015.  
  1016.                         $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  1017.                         $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  1018.                        
  1019.                         $output .= '<header class="entry-content-header">';
  1020.                         $output .= "<{$heading} class='portfolio-grid-title entry-title {$css}' {$markup}>";
  1021.                        
  1022.                         if( ! empty( $title_link ) )
  1023.                         {
  1024.                             $output .= "<a href='{$title_link}'>{$title}</a>";
  1025.                         }
  1026.                         else
  1027.                         {
  1028.                             $output .= $title;
  1029.                         }
  1030.                         $output .= "</{$heading}></header>";
  1031.                     }
  1032.  
  1033.                     if( ! empty( $excerpt ) )
  1034.                     {
  1035.                         $markup = avia_markup_helper( array( 'context' => 'entry_content', 'echo' => false, 'id' => $the_id, 'custom_markup' => $custom_markup ) );
  1036.  
  1037.                         $output .= "<div class='entry-content-wrapper'>";
  1038.                         $output .=      "<div class='grid-entry-excerpt entry-content' {$markup}>{$excerpt}</div>";
  1039.                         $output .= '</div>';
  1040.                     }
  1041.                     $output .= '<div class="avia-arrow"></div>';
  1042.                     $output .= '</div>';
  1043.  
  1044.                     $image = get_the_post_thumbnail( $the_id, $image_size, $image_attrs );
  1045.                     if( ! empty( $image ) )
  1046.                     {
  1047.                         $output .= "<div class='av_table_col portfolio-grid-image'>";
  1048.                         $output .= "<{$link_markup[0]} data-rel='grid-" . avia_post_grid::$grid . "' class='grid-image avia-hover-fx'>{$custom_overlay} {$image}</{$link_markup[1]}>";
  1049.                         $output .= '</div>';
  1050.                     }
  1051.                     $output .= '<footer class="entry-footer"></footer>';
  1052.                     $output .= '</article>';
  1053.                     $output .= '</div>';
  1054.                 }
  1055.                 else
  1056.                 {
  1057.                     $extraClass .= ' default_av_fullwidth ';
  1058.  
  1059.                     $output .= "<div data-ajax-id='{$the_id}' class=' grid-entry flex_column isotope-item all_sort {$style_class} {$post_class} {$sort_class} {$grid} {$extraClass}'>";
  1060.                     $output .= "<article class='main_color inner-entry' " . avia_markup_helper( array( 'context' => 'entry', 'echo' => false, 'id' => $the_id, 'custom_markup' => $custom_markup ) ) . '>';
  1061.                     $output .= apply_filters( 'avf_portfolio_extra', '', $entry );
  1062.                     $output .= "<{$link_markup[0]} data-rel='grid-" . avia_post_grid::$grid.  "' class='grid-image avia-hover-fx'>{$custom_overlay} " . get_the_post_thumbnail( $the_id, $image_size, $image_attrs ) . "</{$link_markup[1]}>";
  1063.                     $output .= ! empty( $title ) || ! empty( $excerpt ) ? "<div class='grid-content'><div class='avia-arrow'></div>" : '';
  1064.  
  1065.                     if( ! empty( $title ) )
  1066.                     {
  1067.                         $markup = avia_markup_helper( array( 'context' => 'entry_title', 'echo' => false, 'id' => $the_id, 'custom_markup' => $custom_markup ) );
  1068.                        
  1069.                         $default_heading = 'h3';
  1070.                         $args = array(
  1071.                                     'heading'       => $default_heading,
  1072.                                     'extra_class'   => ''
  1073.                                 );
  1074.                        
  1075.                         $extra_args = array( $this, $index, 'not_one_column_template_special' );
  1076.  
  1077.                         /**
  1078.                          * @since 4.5.5
  1079.                          * @return array
  1080.                          */
  1081.                         $args = apply_filters( 'avf_customize_heading_settings', $args, __CLASS__, $extra_args );
  1082.  
  1083.                         $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  1084.                         $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  1085.                        
  1086.                         $output .= '<header class="entry-content-header">';
  1087.                         $output .= "<{$heading} class='grid-entry-title entry-title {$css}' $markup>";
  1088.                        
  1089.                         if( ! empty( $title_link ) )
  1090.                         {
  1091.                             $output .= "<a href='{$title_link}' title='" . esc_attr( strip_tags( $title ) ) . "'>" . $title . "</a>";
  1092.                         }
  1093.                         else
  1094.                         {
  1095.                             $output .= $title;
  1096.                         }
  1097.                        
  1098.                         $output .= "</{$heading}></header>";
  1099.                     }
  1100.                     $output .= ! empty( $excerpt ) ? "<div class='grid-entry-excerpt entry-content' ".avia_markup_helper(array('context'=>'entry_content','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup)).">".$excerpt."</div>" : '';
  1101.                     $output .= ! empty( $title ) || ! empty( $excerpt ) ? "</div>" : '';
  1102.                     $output .= '<footer class="entry-footer"></footer>';
  1103.                     $output .= '</article>';
  1104.                     $output .= '</div>';
  1105.                 }
  1106.  
  1107.                 $loop_counter ++;
  1108.                 $post_loop_count ++;
  1109.                 $extraClass = '';
  1110.  
  1111.                 if( $loop_counter > $columns )
  1112.                 {
  1113.                     $loop_counter = 1;
  1114.                     $extraClass = 'first';
  1115.                 }
  1116.             }
  1117.  
  1118.             $output .= '</div>';
  1119.            
  1120.             if( $sort != 'no' )
  1121.             {
  1122.                 $output .= '</div>   <!--   class="av-portfolio-grid-sorting-container"  -->';
  1123.             }
  1124.  
  1125.             //append pagination
  1126.             if( $paginate == 'yes' && $avia_pagination = avia_pagination( $this->entries->max_num_pages, 'nav', $query_var_page, $this->current_page ) )
  1127.             {
  1128.                 $post_type_paginate = array_map( function( $value ) { return 'pagination-' . $value; }, $post_type_paginate );
  1129.                 $post_type_paginate = implode( ' ', $post_type_paginate );
  1130.                
  1131.                 $output .= "<div class='pagination-wrap {$post_type_paginate} {$av_display_classes}'>{$avia_pagination}</div>";
  1132.             }
  1133.  
  1134.             return $output;
  1135.         }
  1136.  
  1137.  
  1138.         /**
  1139.          * Generates the html for the sort buttons
  1140.          *
  1141.          * @param array $entries
  1142.          * @param array $params
  1143.          * @return string
  1144.          */
  1145.         protected function sort_buttons( $entries, $params )
  1146.         {
  1147.             //get all categories that are actually listed on the page
  1148.             $categories = get_categories( array(
  1149.                                 'taxonomy'      => $params['taxonomy'],
  1150.                                 'hide_empty'    => 0
  1151.                             ) );
  1152.  
  1153.             $current_page_cats  = array();
  1154.             $cat_count          = array();
  1155.             $display_cats       = is_array( $params['categories'] ) ? $params['categories'] : array_filter( explode( ',', $params['categories'] ) );
  1156.  
  1157.             foreach( $entries as $entry )
  1158.             {
  1159.                 $current_item_cats = get_the_terms( $entry->ID, $params['taxonomy'] );
  1160.                
  1161.                 if( is_array( $current_item_cats ) && ! empty( $current_item_cats ) )
  1162.                 {
  1163.                     foreach( $current_item_cats as $current_item_cat )
  1164.                     {
  1165.                         if( empty( $display_cats ) || in_array( $current_item_cat->term_id, $display_cats ) )
  1166.                         {
  1167.                             $current_page_cats[ $current_item_cat->term_id ] = $current_item_cat->term_id;
  1168.  
  1169.                             if( ! isset( $cat_count[ $current_item_cat->term_id ] ) )
  1170.                             {
  1171.                                 $cat_count[ $current_item_cat->term_id ] = 0;
  1172.                             }
  1173.  
  1174.                             $cat_count[ $current_item_cat->term_id ] ++;
  1175.                         }
  1176.                     }
  1177.                 }
  1178.                
  1179.             }
  1180.            
  1181.             extract( $this->screen_options ); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  1182.  
  1183.             $output = "<div class='sort_width_container {$av_display_classes} av-sort-" . $this->atts['sort'] . "' data-portfolio-id='" . avia_post_grid::$grid . "' ><div id='js_sort_items' >";
  1184.             $hide = count( $current_page_cats ) <= 1 ? 'hidden' : '';
  1185.  
  1186.  
  1187.             $first_item_name = apply_filters( 'avf_portfolio_sort_first_label', __( 'All', 'avia_framework' ), $params );
  1188.             $first_item_html = '<span class="inner_sort_button"><span>' . $first_item_name . '</span><small class="av-cat-count"> ' . count( $entries ) . ' </small></span>';
  1189.             $output .= apply_filters( 'avf_portfolio_sort_heading', '', $params );
  1190.            
  1191.            
  1192.             if( strpos( $this->atts['sort'], 'tax' ) !== false )
  1193.             {
  1194.                 $output .= "<div class='av-current-sort-title'>{$first_item_html}</div>";
  1195.             }
  1196.            
  1197.             $output .= "<div class='sort_by_cat {$hide} '>";
  1198.             $output .= '<a href="#" data-filter="all_sort" class="all_sort_button active_sort">' . $first_item_html . '</a>';
  1199.  
  1200.  
  1201.             foreach( $categories as $category )
  1202.             {
  1203.                 if( in_array( $category->term_id, $current_page_cats ) )
  1204.                 {
  1205.                     //fix for cyrillic, etc. characters - isotope does not support the % char
  1206.                     $category->category_nicename = str_replace( '%', '', $category->category_nicename );
  1207.  
  1208.                     $output .=  "<span class='text-sep " . $category->category_nicename . "_sort_sep'>/</span>";
  1209.                     $output .=      '<a href="#" data-filter="' . $category->category_nicename . '_sort" class="' . $category->category_nicename . '_sort_button" ><span class="inner_sort_button">';
  1210.                     $output .=          "<span>" . esc_html( trim( $category->cat_name ) ) . "</span>";
  1211.                     $output .=          "<small class='av-cat-count'> " . $cat_count[ $category->term_id ] . " </small></span>";
  1212.                     $output .=      '</a>';
  1213.                 }
  1214.             }
  1215.  
  1216.             $output .= '</div></div></div>';
  1217.  
  1218.             return $output;
  1219.         }
  1220.  
  1221.  
  1222.         //
  1223.        
  1224.         /**
  1225.          * Get the categories for each post and create a string that serves as classes so the javascript can sort by those classes
  1226.          *
  1227.          * @param int $the_id
  1228.          * @param array $params
  1229.          * @return string
  1230.          */
  1231.         protected function sort_cat_string( $the_id, $params )
  1232.         {
  1233.             $sort_classes = '';
  1234.             $item_categories = get_the_terms( $the_id, $params['taxonomy'] );
  1235.  
  1236.             if( is_object( $item_categories ) || is_array( $item_categories ) )
  1237.             {
  1238.                 foreach( $item_categories as $cat )
  1239.                 {
  1240.                     //fix for cyrillic, etc. characters - isotope does not support the % char
  1241.                     $cat->slug = str_replace('%', '', $cat->slug );
  1242.                    
  1243.                     $sort_classes .= $cat->slug . '_sort ';
  1244.                 }
  1245.             }
  1246.  
  1247.             return $sort_classes;
  1248.         }
  1249.  
  1250.         /**
  1251.          *
  1252.          * @param WP_Post $entry
  1253.          * @return string
  1254.          */
  1255.         protected function build_preview_template( $entry )
  1256.         {
  1257.             if( isset( avia_post_grid::$preview_template[ $entry->ID ] ) )
  1258.             {
  1259.                 return '';
  1260.             }
  1261.            
  1262.             avia_post_grid::$preview_template[ $entry->ID ] = true;
  1263.  
  1264.             $id                     = $entry->ID;
  1265.             $output                 = '';
  1266.             $defaults = array(
  1267.                             'ids'       => get_post_thumbnail_id( $id ),
  1268.                             'text'      => apply_filters( 'get_the_excerpt', $entry->post_excerpt ),
  1269.                             'method'    => 'gallery',
  1270.                             'auto'      => '',
  1271.                             'columns'   => 5
  1272.                         );
  1273.            
  1274.             $params['ids']          = get_post_meta( $id , '_preview_ids', true );
  1275.             $params['text']         = get_post_meta( $id , '_preview_text', true );
  1276.             $params['method']       = get_post_meta( $id , '_preview_display', true );
  1277.             $params['interval']     = get_post_meta( $id , '_preview_autorotation', true );
  1278.             $params['columns']      = get_post_meta( $id , '_preview_columns', true );
  1279.            
  1280.             $params['preview_size'] = apply_filters( 'avf_ajax_preview_image_size', 'gallery' );
  1281.             $params['autoplay']     = is_numeric( $params['interval'] ) ? 'true' : 'false';
  1282.  
  1283.             $link = get_post_meta( $id ,'_portfolio_custom_link', true ) != '' ? get_post_meta( $id , '_portfolio_custom_link_url', true ) : get_permalink( $id );
  1284.  
  1285.  
  1286.             //merge default and params array. remove empty params with array_filter
  1287.             $params = array_merge( $defaults, array_filter( $params ) );
  1288.            
  1289.             $params = apply_filters( 'avf_portfolio_preview_template_params', $params, $entry );
  1290.  
  1291.             global $avia_config;
  1292.            
  1293.             /**
  1294.              * Fullwidth shortcodes like "Fullwidth Button" will break layout because they create an own section.
  1295.              * This allows to return without creating new sections
  1296.              *
  1297.              * @since 4.7.6.4
  1298.              */
  1299.             if( ! isset( $avia_config['portfolio_preview_template'] ) )
  1300.             {
  1301.                 $avia_config['portfolio_preview_template'] = 0;
  1302.             }
  1303.            
  1304.             $avia_config['portfolio_preview_template'] ++;
  1305.            
  1306.             //set the content
  1307.             $content = str_replace( ']]>', ']]&gt;', apply_filters( 'the_content', $params['text'] ) );
  1308.             unset( $params['text'] );
  1309.            
  1310.             if( isset( $avia_config['portfolio_preview_template'] ) )
  1311.             {
  1312.                 $avia_config['portfolio_preview_template'] --;
  1313.                
  1314.                 if( $avia_config['portfolio_preview_template'] <= 0 )
  1315.                 {
  1316.                     unset( $avia_config['portfolio_preview_template'] );
  1317.                 }
  1318.             }
  1319.            
  1320.             //set images
  1321.             $string = '';
  1322.  
  1323.             //set first class if preview images are deactivated
  1324.             $nogalleryclass = '';
  1325.             $params['ajax_request'] = true;
  1326.            
  1327.             switch( $params['method'] )
  1328.             {
  1329.                 case 'gallery':
  1330.                     $params['style'] = 'big_thumb';
  1331.                     $params['thumb_size'] = 'square';
  1332.                     foreach( $params as $key => $param )
  1333.                     {
  1334.                         $string .= $key . "='" . $param . "' ";
  1335.                     }
  1336.                     $images = do_shortcode( "[av_gallery {$string}]" );
  1337.                 break;
  1338.  
  1339.                 case 'slideshow':
  1340.                     $params['size'] = $params['preview_size'];
  1341.                     foreach( $params as $key => $param )
  1342.                     {
  1343.                         $string .= $key . "='" . $param . "' ";
  1344.                     }
  1345.                     $images = do_shortcode( "[av_slideshow {$string}]" );
  1346.                 break;
  1347.  
  1348.                 case 'list':
  1349.                     $images = $this->post_images( $params['ids'] );
  1350.                 break;
  1351.  
  1352.                 case 'no':
  1353.                     $images = false;
  1354.                     $nogalleryclass = ' no_portfolio_preview_gallery ';
  1355.                 break;
  1356.             }
  1357.  
  1358.             $output .= "<div class='ajax_slide ajax_slide_{$id}' data-slide-id='{$id}' >";
  1359.  
  1360.                 $output .= "<article class='inner_slide {$nogalleryclass}' " . avia_markup_helper( array( 'context' => 'entry', 'echo' => false, 'id' => $id, 'custom_markup' => $this->atts['custom_markup'] ) ) . ">";
  1361.  
  1362.                 if( ! empty( $images ) )
  1363.                 {
  1364.                     $output .= "<div class='av_table_col first portfolio-preview-image'>";
  1365.                     $output .=      $images;
  1366.                     $output .= '</div>';
  1367.                 }
  1368.  
  1369.                 if( ! empty( $nogalleryclass ) )
  1370.                 {
  1371.                     $nogalleryclass .= ' first ';
  1372.                 }
  1373.                
  1374.                 $markup = avia_markup_helper( array( 'context' => 'entry_title', 'echo' => false, 'id' => $id, 'custom_markup' => $this->atts['custom_markup'] ) );
  1375.                
  1376.                 $default_heading = 'h2';
  1377.                 $args = array(
  1378.                             'heading'       => $default_heading,
  1379.                             'extra_class'   => ''
  1380.                         );
  1381.  
  1382.                 $extra_args = array( $this, $entry, __METHOD__ );
  1383.  
  1384.                 /**
  1385.                  * @since 4.5.5
  1386.                  * @return array
  1387.                  */
  1388.                 $args = apply_filters( 'avf_customize_heading_settings', $args, __CLASS__, $extra_args );
  1389.  
  1390.                 $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  1391.                 $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  1392.                        
  1393.  
  1394.                 $output .=  "<div class='av_table_col $nogalleryclass portfolio-entry portfolio-preview-content'>";
  1395.  
  1396.                 $output .=      '<header class="entry-content-header">';
  1397.                 $output .=          "<{$heading} class='portfolio-preview-title entry-title {$css}' {$markup}><a href='{$link}'>" . avia_wp_get_the_title( $entry ) . "</a></{$heading}>";
  1398.                 $output .=      '</header>';
  1399.  
  1400.                 $output .=      "<div class='entry-content-wrapper entry-content' " . avia_markup_helper( array( 'context' => 'entry_content', 'echo' => false, 'id' => $id, 'custom_markup' => $this->atts['custom_markup'] ) ) . ">";
  1401.                 $output .=          $content;
  1402.                 $output .=      '</div>';
  1403.                 $output .=      "<span class='avia-arrow'></span>";
  1404.                
  1405.                 $output .=  '</div>';
  1406.  
  1407.                 $output .=  '<footer class="entry-footer"></footer>';
  1408.                 $output .= '</article>';
  1409.  
  1410.             $output .= '</div>';
  1411.  
  1412.             return "<script type='text/html' id='avia-tmpl-portfolio-preview-{$id}'>\n{$output}\n</script>\n\n";
  1413.  
  1414.         }
  1415.  
  1416.         /**
  1417.          *
  1418.          * @param string $ids
  1419.          * @return string
  1420.          */
  1421.         protected function post_images( $ids )
  1422.         {
  1423.             if( empty( $ids ) )
  1424.             {
  1425.                 return;
  1426.             }
  1427.  
  1428.             $attachments = get_posts( array(
  1429.                                     'include'           => $ids,
  1430.                                     'post_status'       => 'inherit',
  1431.                                     'post_type'         => 'attachment',
  1432.                                     'post_mime_type'    => 'image',
  1433.                                     'order'             => 'ASC',
  1434.                                     'orderby'           => 'post__in'
  1435.                                 )
  1436.                             );
  1437.  
  1438.             $output = '';
  1439.  
  1440.             foreach( $attachments as $attachment )
  1441.             {
  1442.                 $img = wp_get_attachment_image_src( $attachment->ID, 'large' );
  1443.  
  1444.                 $alt = get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true );
  1445.                 $alt = ! empty( $alt ) ? esc_attr( $alt ) : '';
  1446.                 $title = trim( $attachment->post_title ) ? esc_attr( $attachment->post_title ) : '';
  1447.                 $description = trim( $attachment->post_content ) ? esc_attr( $attachment->post_content ) : '';
  1448.                
  1449.                 $img_tag = "<img src='{$img[0]}' title='{$title}' alt='{$alt}' />";
  1450.                 $img_tag = Av_Responsive_Images()->prepare_single_image( $img_tag, $attachment->ID, $this->atts['lazy_loading'] );
  1451.  
  1452.                 $output .= "<a href='{$img[0]}' class='portolio-preview-list-image' title='{$description}' >";
  1453.                 $output .=      $img_tag;
  1454.                 $output .= '</a>';
  1455.             }
  1456.  
  1457.             return $output;
  1458.         }
  1459.  
  1460.  
  1461.  
  1462.         /**
  1463.          * Output the preview templates in footer
  1464.          *
  1465.          */
  1466.         public function print_preview_templates()
  1467.         {
  1468.             foreach( $this->entries->posts as $entry )
  1469.             {
  1470.                 echo $this->build_preview_template( $entry );
  1471.             }
  1472.         }
  1473.  
  1474.  
  1475.  
  1476.         /**
  1477.          * Get the entries and add to local variable
  1478.          *
  1479.          * @param array $params
  1480.          */
  1481.         public function query_entries( $params = array() )
  1482.         {
  1483.            
  1484.             $query = array();
  1485.             if( empty( $params ) )
  1486.             {
  1487.                 $params = $this->atts;
  1488.             }
  1489.  
  1490.             if( ! empty( $params['categories'] ) )
  1491.             {
  1492.                 //get the portfolio categories
  1493.                 $terms = explode( ',', $params['categories'] );
  1494.             }
  1495.  
  1496.             $this->current_page = ( $params['paginate'] != 'no' ) ? avia_get_current_pagination_number( 'avia-element-paging' ) : 1;
  1497.            
  1498.             $date_query = array();
  1499.             if( 'date_filter' == $params['date_filter'] )
  1500.             {
  1501.                 $date_query = AviaHelper::add_date_query( $date_query, $params['date_filter_start'], $params['date_filter_end'], $params['date_filter_format'] );
  1502.             }
  1503.  
  1504.             //if we find categories perform complex query, otherwise simple one
  1505.             if( isset( $terms[0] ) && ! empty( $terms[0] ) && ! is_null( $terms[0] ) && $terms[0] != 'null' )
  1506.             {
  1507.                 $query = array(
  1508.                                 'orderby'       => $params['query_orderby'],
  1509.                                 'order'         => $params['query_order'],
  1510.                                 'paged'         => $this->current_page,
  1511.                                 'posts_per_page' => $params['items'],
  1512.                                 'post_type'     => $params['post_type'],
  1513.                                 'date_query'    => $date_query,
  1514.                                 'tax_query'     => array(  
  1515.                                                         array(  
  1516.                                                                 'taxonomy'  => $params['taxonomy'],
  1517.                                                                 'field'     => 'id',
  1518.                                                                 'terms'     => $terms,
  1519.                                                                 'operator'  => 'IN'
  1520.                                                             )
  1521.                                                     )
  1522.                             );
  1523.             }
  1524.             else
  1525.             {
  1526.                 $query = array(
  1527.                                 'orderby'       => $params['query_orderby'],
  1528.                                 'order'         => $params['query_order'],
  1529.                                 'paged'         => $this->current_page,
  1530.                                 'posts_per_page' => $params['items'],
  1531.                                 'post_type'     => $params['post_type'],
  1532.                                 'date_query'    => $date_query,
  1533.                             );
  1534.             }
  1535.  
  1536.             /**
  1537.              *
  1538.              * @since < 4.0
  1539.              * @param array $query
  1540.              * @param array $params
  1541.              * @return array
  1542.              */
  1543.             $query = apply_filters( 'avia_post_grid_query', $query, $params );
  1544.  
  1545.             $this->entries = new WP_Query( $query );
  1546.  
  1547.         }
  1548.  
  1549.         /**
  1550.          * Allows to set the query to an existing post query. usually only needed on pages that already did a query for the entries, like taxonomy archive pages.
  1551.          * Shortcode uses the query_entries function above
  1552.          *
  1553.          */
  1554.         public function use_global_query()
  1555.         {
  1556.             global $wp_query;
  1557.            
  1558.             $this->entries = $wp_query;
  1559.         }
  1560.  
  1561.     }
  1562. }
  1563.  
  1564.  
  1565. /*
  1566. Example: how to order posts randomly on page load. put this into functions.php
  1567.  
  1568. add_filter('avia_post_grid_query','avia_order_by_random');
  1569. function avia_order_by_random($query)
  1570. {
  1571.     $query['orderby'] = 'rand';
  1572.     return $query;
  1573. }
  1574. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement