Advertisement
Guenni007

portfolio

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