Advertisement
cipher87

Portfolio

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