Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 38.83 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Sidebar
  4.  * Displays one of the registered Widget Areas of the theme
  5.  */
  6.  
  7. if ( !class_exists( 'avia_sc_portfolio' ) )
  8. {
  9.     class avia_sc_portfolio extends aviaShortcodeTemplate
  10.     {
  11.             /**
  12.              * Create the config array for the shortcode button
  13.              */
  14.             function shortcode_insert_button()
  15.             {
  16.                 $this->config['name']       = __('Portfolio Grid', 'avia_framework' );
  17.                 $this->config['tab']        = __('Content Elements', 'avia_framework' );
  18.                 $this->config['icon']       = AviaBuilder::$path['imagesURL']."sc-portfolio.png";
  19.                 $this->config['order']      = 38;
  20.                 $this->config['target']     = 'avia-target-insert';
  21.                 $this->config['shortcode']  = 'av_portfolio';
  22.                 $this->config['tooltip']    = __('Creates a grid of portfolio excerpts', 'avia_framework' );
  23.             }
  24.  
  25.             function extra_assets()
  26.             {
  27.                 if(!is_admin() && !current_theme_supports('avia_no_session_support') && !session_id()) session_start();
  28.             }
  29.  
  30.             /**
  31.              * Popup Elements
  32.              *
  33.              * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  34.              * opens a modal window that allows to edit the element properties
  35.              *
  36.              * @return void
  37.              */
  38.             function popup_elements()
  39.             {
  40.                 $this->elements = array(
  41.  
  42.                 array(
  43.                         "type"  => "tab_container", 'nodescription' => true
  44.                     ),
  45.  
  46.                 array(
  47.                         "type"  => "tab",
  48.                         "name"  => __("Content" , 'avia_framework'),
  49.                         'nodescription' => true
  50.                     ),
  51.  
  52.  
  53.                     array(  "name"      => __("Which categories should be used for the portfolio?", 'avia_framework' ),
  54.                             "desc"      => __("You can select multiple categories here. The Page will then show posts from only those categories.", 'avia_framework' ),
  55.                             "id"        => "categories",
  56.                             "type"      => "select",
  57.                             "multiple"  => 6,
  58.                             "taxonomy"  => "portfolio_entries",
  59.                             "subtype"   => "cat"),
  60.                     /*
  61.                         array(
  62.                             "name"  => __("Style?", 'avia_framework' ),
  63.                             "desc"  => __("Choose the style of the entries here", 'avia_framework' ),
  64.                             "id"    => "style",
  65.                             "type"  => "select",
  66.                             "std"   => "",
  67.                             "subtype" => array( __('Default Style', 'avia_framework' ) => '',
  68.                                                 __('Circle Image Stlye',  'avia_framework' )=>'grid-circle')),
  69.                     */
  70.  
  71.                     array(
  72.                             "name"  => __("Columns", 'avia_framework' ),
  73.                             "desc"  => __("How many columns should be displayed?", 'avia_framework' ),
  74.                             "id"    => "columns",
  75.                             "type"  => "select",
  76.                             "std"   => "4",
  77.                             "subtype" => array( __('1 Column',  'avia_framework' )=>'1',
  78.                                                 __('2 Columns', 'avia_framework' )=>'2',
  79.                                                 __('3 Columns', 'avia_framework' )=>'3',
  80.                                                 __('4 Columns', 'avia_framework' )=>'4',
  81.                                                 __('5 Columns', 'avia_framework' )=>'5',
  82.                                                 __('6 Columns', 'avia_framework' )=>'6',
  83.                                                 )),
  84.  
  85.                     array(
  86.                         "name"  => __("1 Column layout", 'avia_framework' ),
  87.                         "desc"  => __("Choose the 1 column layout", 'avia_framework' ),
  88.                         "id"    => "one_column_template",
  89.                         "type"  => "select",
  90.                         "required"  => array('columns','equals','1'),
  91.                         "std"   => "special",
  92.                         "subtype" => array(
  93.                             __('Use special 1 column layout (side by side)',  'avia_framework' ) =>'special',
  94.                             __('Use default portfolio layout',  'avia_framework' ) =>'default')),
  95.  
  96.                     array(
  97.                             "name"  => __("Post Number", 'avia_framework' ),
  98.                             "desc"  => __("How many items should be displayed per page?", 'avia_framework' ),
  99.                             "id"    => "items",
  100.                             "type"  => "select",
  101.                             "std"   => "16",
  102.                             "subtype" => AviaHtmlHelper::number_array(1,100,1, array('All'=>'-1'))),
  103.  
  104.                     array(
  105.                             "name"  => __("Excerpt", 'avia_framework' ),
  106.                             "desc"  => __("Display Excerpt and Title below the preview image?", 'avia_framework' ),
  107.                             "id"    => "contents",
  108.                             "type"  => "select",
  109.                             "std"   => "yes",
  110.                             "subtype" => array(
  111.                                 __('Title and Excerpt',  'avia_framework' ) =>'excerpt',
  112.                                 __('Only Title',  'avia_framework' ) =>'title',
  113.                                 __('Only excerpt',  'avia_framework' ) =>'only_excerpt',
  114.                                 __('No Title and no excerpt',  'avia_framework' ) =>'no')),
  115.  
  116.                     array(
  117.                         "name"  => __("Portfolio Grid Image Size", 'avia_framework' ),
  118.                         "desc"  => __("Set the image size of the Portfolio Grid images", 'avia_framework' ),
  119.                         "id"    => "preview_mode",
  120.                         "type"  => "select",
  121.                         "std"   => "auto",
  122.                         "subtype" => array(__('Set the Portfolio Grid image size automatically based on column or layout width','avia_framework' ) =>'auto',__('Choose the Portfolio Grid image size manually (select thumbnail size)','avia_framework' ) =>'custom')),
  123.  
  124.                     array(
  125.                         "name"  => __("Select custom image size", 'avia_framework' ),
  126.                         "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>",
  127.                         "id"    => "image_size",
  128.                         "type"  => "select",
  129.                         "required"  => array('preview_mode','equals','custom'),
  130.                         "std"   => "portfolio",
  131.                         "subtype" =>  AviaHelper::get_registered_image_sizes(array('logo','thumbnail','widget'))
  132.                     ),
  133.  
  134.                     array(
  135.                             "name"  => __("Link Handling", 'avia_framework' ),
  136.                             "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' ),
  137.                             "id"    => "linking",
  138.                             "type"  => "select",
  139.                             "std"   => "",
  140.                             "subtype" => array(
  141.                                 __('Open the entry on a new page',  'avia_framework' ) =>'',
  142.                                 __('Open a preview of the entry (known as AJAX Portfolio)',  'avia_framework' ) =>'ajax',
  143.                                 __('Display the big image in a lightbox',  'avia_framework' ) =>'lightbox')),
  144.  
  145.                     array(
  146.                             "name"  => __("Sortable?", 'avia_framework' ),
  147.                             "desc"  => __("Should the sorting options based on categories be displayed?", 'avia_framework' ),
  148.                             "id"    => "sort",
  149.                             "type"  => "select",
  150.                             "std"   => "yes",
  151.                             "subtype" => array(
  152.                             __('Yes, display sort options',  'avia_framework' ) => 'yes',
  153.                             __('Yes, display sort options and currently active categories',  'avia_framework' ) => 'yes-tax',
  154.                             __('No, do not display sort options',  'avia_framework' )  => 'no')),
  155.  
  156.                     array(
  157.                             "name"  => __("Pagination", 'avia_framework' ),
  158.                             "desc"  => __("Should a pagination be displayed?", 'avia_framework' ),
  159.                             "id"    => "paginate",
  160.                             "type"  => "select",
  161.                             "std"   => "yes",
  162.                             "subtype" => array(
  163.                                 __('yes',  'avia_framework' ) =>'yes',
  164.                                 __('no',  'avia_framework' ) =>'no')),
  165.  
  166.                     array(
  167.                             "name" => __("Order by",'avia_framework' ),
  168.                             "desc"  => __("You can order the result by various attributes like creation date, title, author etc", 'avia_framework' ),
  169.                             "id"   => "query_orderby",
  170.                             "type"  => "select",
  171.                             "std"   => "date",
  172.                             "subtype" => array(
  173.                                 __('Date',  'avia_framework' ) =>'date',
  174.                                 __('Title',  'avia_framework' ) =>'title',
  175.                                 __('Random',  'avia_framework' ) =>'rand',
  176.                                 __('Author',  'avia_framework' ) =>'author',
  177.                                 __('Name (Post Slug)',  'avia_framework' ) =>'name',
  178.                                 __('Last modified',  'avia_framework' ) =>'modified',
  179.                                 __('Comment Count',  'avia_framework' ) =>'comment_count',
  180.                                 __('Page Order',  'avia_framework' ) =>'menu_order')
  181.                         ),
  182.  
  183.                         array(
  184.                           "name" => __("Display order",'avia_framework' ),
  185.                           "desc"    => __("Display the results either in ascending or descending order", 'avia_framework' ),
  186.                           "id"   => "query_order",
  187.                           "type"    => "select",
  188.                           "std"     => "DESC",
  189.                           "subtype" => array(
  190.                               __('Ascending Order',  'avia_framework' ) =>'ASC',
  191.                               __('Descending Order',  'avia_framework' ) =>'DESC')
  192.                         ),
  193.  
  194.                         array(
  195.                             "type"  => "close_div",
  196.                             'nodescription' => true
  197.                         ),
  198.  
  199.  
  200.                                 array(
  201.                                     "type"  => "tab",
  202.                                     "name"  => __("Screen Options",'avia_framework' ),
  203.                                     'nodescription' => true
  204.                                 ),
  205.  
  206.  
  207.                                 array(
  208.                                 "name"  => __("Element Visibility",'avia_framework' ),
  209.                                 "desc"  => __("Set the visibility for this element, based on the device screensize.", 'avia_framework' ),
  210.                                 "type"  => "heading",
  211.                                 "description_class" => "av-builder-note av-neutral",
  212.                                 ),
  213.  
  214.                                 array(
  215.                                         "desc"  => __("Hide on large screens (wider than 990px - eg: Desktop)", 'avia_framework'),
  216.                                         "id"    => "av-desktop-hide",
  217.                                         "std"   => "",
  218.                                         "container_class" => 'av-multi-checkbox',
  219.                                         "type"  => "checkbox"),
  220.  
  221.                                 array(
  222.  
  223.                                         "desc"  => __("Hide on medium sized screens (between 768px and 989px - eg: Tablet Landscape)", 'avia_framework'),
  224.                                         "id"    => "av-medium-hide",
  225.                                         "std"   => "",
  226.                                         "container_class" => 'av-multi-checkbox',
  227.                                         "type"  => "checkbox"),
  228.  
  229.                                 array(
  230.  
  231.                                         "desc"  => __("Hide on small screens (between 480px and 767px - eg: Tablet Portrait)", 'avia_framework'),
  232.                                         "id"    => "av-small-hide",
  233.                                         "std"   => "",
  234.                                         "container_class" => 'av-multi-checkbox',
  235.                                         "type"  => "checkbox"),
  236.  
  237.                                 array(
  238.  
  239.                                         "desc"  => __("Hide on very small screens (smaller than 479px - eg: Smartphone Portrait)", 'avia_framework'),
  240.                                         "id"    => "av-mini-hide",
  241.                                         "std"   => "",
  242.                                         "container_class" => 'av-multi-checkbox',
  243.                                         "type"  => "checkbox"),
  244.  
  245.                             array(
  246.                                 "name"  => __("Element Columns",'avia_framework' ),
  247.                                 "desc"  =>
  248.                                 __("Set the column count for this element, based on the device screensize.", 'avia_framework' )
  249.                                 ,
  250.                                 "type"  => "heading",
  251.                                 "description_class" => "av-builder-note av-neutral",
  252.                                 ),
  253.  
  254.  
  255.                                 array(  "name"  => __("Column count for medium sized screens", 'avia_framework' ),
  256.                                     "id"    => "av-medium-columns",
  257.                                     "type"  => "select",
  258.                                     "subtype" => AviaHtmlHelper::number_array(1,4,1, array( __("Default", 'avia_framework' )=>'')),
  259.                                     "std" => ""),
  260.  
  261.                                     array(  "name"  => __("Column count for small screens", 'avia_framework' ),
  262.                                     "id"    => "av-small-columns",
  263.                                     "type"  => "select",
  264.                                     "subtype" => AviaHtmlHelper::number_array(1,4,1, array( __("Default", 'avia_framework' )=>'')),
  265.                                     "std" => ""),
  266.  
  267.                                     array(  "name"  => __("Column count for very small screens", 'avia_framework' ),
  268.                                     "id"    => "av-mini-columns",
  269.                                     "type"  => "select",
  270.                                     "subtype" => AviaHtmlHelper::number_array(1,4,1, array( __("Default", 'avia_framework' )=>'')),
  271.                                     "std" => ""),
  272.  
  273.  
  274.  
  275.  
  276.                             array(
  277.                                     "type"  => "close_div",
  278.                                     'nodescription' => true
  279.                                 ),
  280.  
  281.  
  282.  
  283.  
  284.                     array(
  285.                         "type"  => "close_div",
  286.                         'nodescription' => true
  287.                     ),
  288.  
  289.  
  290.                 );
  291.  
  292.  
  293.                     if(current_theme_supports('avia_template_builder_custom_post_type_grid'))
  294.                     {
  295.                         $this->elements[2] = array(
  296.                                 "name"  => __("Which Entries?", 'avia_framework' ),
  297.                                 "desc"  => __("Select which entries should be displayed by selecting a taxonomy", 'avia_framework' ),
  298.                                 "id"    => "link",
  299.                                 "fetchTMPL" => true,
  300.                                 "type"  => "linkpicker",
  301.                                 "subtype"  => array( __('Display Entries from:',  'avia_framework' )=>'taxonomy'),
  302.                                 "multiple"  => 6,
  303.                                 "std"   => "category");
  304.  
  305.  
  306.                         if(current_theme_supports('add_avia_builder_post_type_option'))
  307.                         {
  308.                            $element = array(
  309.                                 "name"  => __("Select Post Type", 'avia_framework' ),
  310.                                 "desc"  => __("Select which post types should be used. Note that your taxonomy will be ignored if you do not select an assign post type.
  311.                                               If yo don't select post type all registered post types will be used", 'avia_framework' ),
  312.                                 "id"    => "post_type",
  313.                                 "type"  => "select",
  314.                                 "multiple"  => 6,
  315.                                 "std"   => "",
  316.                                 "subtype" => AviaHtmlHelper::get_registered_post_type_array()
  317.                             );
  318.  
  319.                             array_splice($this->elements, 2, 0, array($element));
  320.  
  321.                         }
  322.                     }
  323.  
  324.  
  325.  
  326.             }
  327.  
  328.  
  329.  
  330.             /**
  331.              * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  332.              * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  333.              * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  334.              *
  335.              *
  336.              * @param array $params this array holds the default values for $content and $args.
  337.              * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  338.              */
  339.             function editor_element($params)
  340.             {
  341.                 $params['innerHtml'] = "<img src='".$this->config['icon']."' title='".$this->config['name']."' />";
  342.                 $params['innerHtml'].= "<div class='avia-element-label'>".$this->config['name']."</div>";
  343.                 $params['innerHtml'].= "<div class='avia-flex-element'>";
  344.                 $params['innerHtml'].=      __('This element will stretch across the whole screen by default.','avia_framework')."<br/>";
  345.                 $params['innerHtml'].=      __('If you put it inside a color section or column it will only take up the available space','avia_framework');
  346.                 $params['innerHtml'].= "    <div class='avia-flex-element-2nd'>".__('Currently:','avia_framework');
  347.                 $params['innerHtml'].= "    <span class='avia-flex-element-stretched'>&laquo; ".__('Stretch fullwidth','avia_framework')." &raquo;</span>";
  348.                 $params['innerHtml'].= "    <span class='avia-flex-element-content'>| ".__('Adjust to content width','avia_framework')." |</span>";
  349.                 $params['innerHtml'].= "</div></div>";
  350.  
  351.                 $params['content']   = NULL; //remove to allow content elements
  352.  
  353.                 return $params;
  354.             }
  355.  
  356.  
  357.  
  358.             /**
  359.              * Frontend Shortcode Handler
  360.              *
  361.              * @param array $atts array of attributes
  362.              * @param string $content text within enclosing form of shortcode element
  363.              * @param string $shortcodename the shortcode found, when == callback name
  364.              * @return string $output returns the modified html string
  365.              */
  366.             function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  367.             {
  368.                 extract(AviaHelper::av_mobile_sizes($atts)); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  369.  
  370.                 $atts['class'] = !empty($meta['custom_class']) ? $meta['custom_class'] : "";
  371.  
  372.                 if(current_theme_supports('avia_template_builder_custom_post_type_grid'))
  373.                 {
  374.                     if(isset($atts['link']))
  375.                     {
  376.                         $atts['link'] = explode(',', $atts['link'], 2 );
  377.                         $atts['taxonomy'] = $atts['link'][0];
  378.  
  379.                         if(isset($atts['link'][1]))
  380.                         {
  381.                             $atts['categories'] = $atts['link'][1];
  382.                         }
  383.                     }
  384.  
  385.                     if(empty($atts['post_type']) || !current_theme_supports('add_avia_builder_post_type_option'))
  386.                     {
  387.                         $atts['post_type'] = get_post_types();
  388.                     }
  389.  
  390.                     if(is_string($atts['post_type'])) $atts['post_type'] = explode(',', $atts['post_type']);
  391.                 }
  392.  
  393.                 $atts['fullscreen'] = ShortcodeHelper::is_top_level();
  394.  
  395.                 $grid = new avia_post_grid($atts);
  396.                 $grid->query_entries();
  397.                 $portfolio_html = $grid->html();
  398.  
  399.                 if(!ShortcodeHelper::is_top_level())
  400.                 return $portfolio_html;
  401.  
  402.  
  403.                 $params['class'] = "main_color avia-no-border-styling avia-fullwidth-portfolio {$av_display_classes} ".$meta['el_class'];
  404.                 $params['open_structure'] = false;
  405.                 $params['id'] = !empty($atts['id']) ? AviaHelper::save_string($atts['id'],'-') : "";
  406.                 $params['custom_markup'] = $meta['custom_markup'];
  407.  
  408.                 //we dont need a closing structure if the element is the first one or if a previous fullwidth element was displayed before
  409.                 if(isset($meta['index']) && $meta['index'] == 0) $params['close'] = false;
  410.                 if(!empty($meta['siblings']['prev']['tag']) && in_array($meta['siblings']['prev']['tag'], AviaBuilder::$full_el_no_section )) $params['close'] = false;
  411.  
  412.                 $output  =  avia_new_section($params);
  413.                 $output .= $portfolio_html;
  414.                 $output .= avia_section_after_element_content( $meta , 'after_portfolio' );
  415.  
  416.                 return $output;
  417.             }
  418.         }
  419. }
  420.  
  421.  
  422.  
  423.  
  424. if ( !class_exists( 'avia_post_grid' ) )
  425. {
  426.     class avia_post_grid
  427.     {
  428.         static  $grid = 0;
  429.         static  $preview_template = array();
  430.         protected $atts;
  431.         protected $entries;
  432.  
  433.         function __construct($atts = array())
  434.         {
  435.             $this->screen_options = AviaHelper::av_mobile_sizes($atts);
  436.  
  437.             $this->atts = shortcode_atts(array( 'style'     => '',
  438.                                                 'linking'   => '',
  439.                                                 'columns'   => '4',
  440.                                                 'items'     => '16',
  441.                                                 'contents'  => 'title',
  442.                                                 'sort'      => 'yes',
  443.                                                 'paginate'  => 'yes',
  444.                                                 'categories'=> '',
  445.                                                 'preview_mode' => 'auto',
  446.                                                 'image_size' => 'portfolio',
  447.                                                 'post_type' => 'portfolio',
  448.                                                 'taxonomy'  => 'portfolio_entries',
  449.                                                 'one_column_template' => 'special',
  450.                                                 'set_breadcrumb' => true, //no shortcode option for this, modifies the breadcrumb nav, must be false on taxonomy overview
  451.                                                 'class'     => "",
  452.                                                 'custom_markup' => '',
  453.                                                 'fullscreen'    => false,
  454.                                                 'query_orderby' => 'date',
  455.                                                 'query_order' => 'DESC',
  456.                                                 ), $atts, 'av_portfolio');
  457.  
  458.  
  459.  
  460.             if($this->atts['linking'] == 'ajax')
  461.                 add_action('wp_footer' , array($this, 'print_preview_templates'));
  462.         }
  463.  
  464.         //generates the html of the post grid
  465.         public function html()
  466.         {
  467.             if(empty($this->entries) || empty($this->entries->posts)) return;
  468.  
  469.             avia_post_grid::$grid ++;
  470.             extract($this->atts);
  471.             extract($this->screen_options); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  472.  
  473.             $container_id       = avia_post_grid::$grid;
  474.             $extraClass         = 'first';
  475.             $grid               = 'one_fourth';
  476.             if($preview_mode == 'auto') $image_size = 'portfolio';
  477.             $post_loop_count    = 1;
  478.             $loop_counter       = 1;
  479.             $output             = "";
  480.             $style_class        = empty($style) ? 'no_margin' : $style;
  481.             $total              = $this->entries->post_count % 2 ? "odd" : "even";
  482.  
  483.             if($set_breadcrumb && is_page())
  484.             {
  485.                 $_SESSION["avia_{$post_type}"] = get_the_ID();
  486.             }
  487.  
  488.             switch($columns)
  489.             {
  490.                 case "1": $grid = 'av_fullwidth';  if($preview_mode == 'auto') $image_size = 'featured'; break;
  491.                 case "2": $grid = 'av_one_half';   break;
  492.                 case "3": $grid = 'av_one_third';  break;
  493.                 case "4": $grid = 'av_one_fourth'; if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  494.                 case "5": $grid = 'av_one_fifth';  if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  495.                 case "6": $grid = 'av_one_sixth';  if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  496.             }
  497.  
  498.             if($fullscreen && $preview_mode =='auto' && $image_size == "portfolio_small") $image_size = 'portfolio';
  499.  
  500.             $output .= $sort != "no" ? $this->sort_buttons($this->entries->posts, $this->atts) : "";
  501.  
  502.             if($linking == "ajax")
  503.             {
  504.                 global $avia_config;
  505.  
  506.                 $container_class = $fullscreen ? "container" : "";
  507.  
  508.                 $output .= "<div class='portfolio_preview_container {$container_class}' data-portfolio-id='{$container_id}'>
  509.                                 <div class='ajax_controlls iconfont'>
  510.                                     <a href='#prev' class='ajax_previous'   ".av_icon_string('prev')."></a>
  511.                                     <a href='#next' class='ajax_next'       ".av_icon_string('next')."></a>
  512.                                     <a class='avia_close' href='#close'     ".av_icon_string('close')."></a>
  513.                                 </div>
  514.                                 <div class='portfolio-details-inner'></div>
  515.                             </div>";
  516.             }
  517.             $output .= "<div 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}'>";
  518.  
  519.             foreach ($this->entries->posts as $entry)
  520.             {
  521.                 $the_id     = $entry->ID;
  522.                 $parity     = $post_loop_count % 2 ? 'odd' : 'even';
  523.                 $last       = $this->entries->post_count == $post_loop_count ? " post-entry-last " : "";
  524.                 $post_class = "post-entry post-entry-{$the_id} grid-entry-overview grid-loop-{$post_loop_count} grid-parity-{$parity} {$last}";
  525.                 $sort_class = $this->sort_cat_string($the_id, $this->atts);
  526.  
  527.                 switch($linking)
  528.                 {
  529.                     case "lightbox":  $link = aviaHelper::get_url('lightbox', get_post_thumbnail_id($the_id));  break;
  530.                     default:          $link = get_permalink($the_id); break;
  531.                 }
  532.  
  533.                 $title_link  = get_permalink($the_id);
  534.                 $custom_link = get_post_meta( $the_id ,'_portfolio_custom_link', true) != "" ? get_post_meta( $the_id ,'_portfolio_custom_link_url', true) : false;
  535.  
  536.                 if($custom_link)
  537.                 {
  538.                     $title_link = "";
  539.                     $link = $custom_link;
  540.                 }
  541.  
  542.                 $excerpt    = '';
  543.                 $title      = '';
  544.  
  545.                 switch($contents)
  546.                 {
  547.                     case "excerpt": $excerpt = $entry->post_excerpt; $title = $entry->post_title; break;
  548.                     case "title": $excerpt = ''; $title = $entry->post_title;  break;
  549.                     case "only_excerpt": $excerpt = $entry->post_excerpt; $title = ''; break;
  550.                     case "no": $excerpt = ''; $title = ''; break;
  551.                 }
  552.  
  553.                 $custom_overlay = apply_filters('avf_portfolio_custom_overlay', "", $entry);
  554.                 $link_markup    = apply_filters('avf_portfolio_custom_image_container', array("a href='{$link}' title='".esc_attr(strip_tags($title))."' ",'a'), $entry);
  555.  
  556.                 $title          = apply_filters('avf_portfolio_title', $title, $entry);
  557.                 $title_link     = apply_filters('avf_portfolio_title_link', $title_link, $entry);
  558.                 $image_attrs    = apply_filters('avf_portfolio_image_attrs', array(), $entry);
  559.  
  560.  
  561.  
  562.                 if($columns == "1" && $one_column_template == 'special')
  563.                 {
  564.                     $extraClass .= ' special_av_fullwidth ';
  565.  
  566.                     $output .= "<div data-ajax-id='{$the_id}' class=' grid-entry flex_column isotope-item all_sort {$style_class} {$post_class} {$sort_class} {$grid} {$extraClass}'>";
  567.                     $output .= "<article class='main_color inner-entry' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup)).">";
  568.                     $output .= apply_filters('avf_portfolio_extra', "", $entry);
  569.  
  570.                     $output .= "<div class='av_table_col first portfolio-entry grid-content'>";
  571.  
  572.                     if(!empty($title))
  573.                     {
  574.                         $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  575.                         $output .= '<header class="entry-content-header">';
  576.                         $output .= "<h2 class='portfolio-grid-title entry-title' $markup>";
  577.  
  578.                         if(!empty($title_link))
  579.                         {
  580.                             $output .= "<a href='{$title_link}'>".$title."</a>";
  581.                         }
  582.                         else
  583.                         {
  584.                             $output .= "".$title."";
  585.                         }
  586.                         $output .= '</h2></header>';
  587.                     }
  588.  
  589.                     if(!empty($excerpt))
  590.                     {
  591.                         $markup = avia_markup_helper(array('context' => 'entry_content','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  592.  
  593.                         $output .= "<div class='entry-content-wrapper'>";
  594.                         $output .= "<div class='grid-entry-excerpt entry-content' $markup>".do_shortcode($excerpt)."</div>";
  595.                         $output .= "</div>";
  596.                     }
  597.                     $output .= '<div class="avia-arrow"></div>';
  598.                     $output .= "</div>";
  599.  
  600.                     $image = get_the_post_thumbnail( $the_id, $image_size, $image_attrs );
  601.                     if(!empty($image))
  602.                     {
  603.                         $output .= "<div class='av_table_col portfolio-grid-image'>";
  604.                         $output .= "<".$link_markup[0]." data-rel='grid-".avia_post_grid::$grid."' class='grid-image avia-hover-fx'>".$custom_overlay.$image."</".$link_markup[1].">";
  605.                         $output .= "</div>";
  606.                     }
  607.                     $output .= '<footer class="entry-footer"></footer>';
  608.                     $output .= "</article>";
  609.                     $output .= "</div>";
  610.                 }
  611.                 else
  612.                 {
  613.                     $extraClass .= ' default_av_fullwidth ';
  614.  
  615.                     $output .= "<div data-ajax-id='{$the_id}' class=' grid-entry flex_column isotope-item all_sort {$style_class} {$post_class} {$sort_class} {$grid} {$extraClass}'>";
  616.                     $output .= "<article class='main_color inner-entry' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup)).">";
  617.                     $output .= apply_filters('avf_portfolio_extra', "", $entry);
  618.                     $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].">";
  619.                     $output .= !empty($title) || !empty($excerpt) ? "<div class='grid-content'><div class='avia-arrow'></div>" : '';
  620.  
  621.                     if(!empty($title))
  622.                     {
  623.                         $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  624.                         $output .= '<header class="entry-content-header">';
  625.                         $output .= "<h3 class='grid-entry-title entry-title' $markup>";
  626.  
  627.                         if(!empty($title_link))
  628.                         {
  629.                             $output .= "<a href='{$title_link}' title='".esc_attr(strip_tags($title))."'>".$title."</a>";
  630.                         }
  631.                         else
  632.                         {
  633.                             $output .= "".$title."";
  634.                         }
  635.  
  636.                         $output .= '</h3></header>';
  637.                     }
  638.                     $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)).">".do_shortcode($excerpt)."</div>" : '';
  639.                     $output .= !empty($title) || !empty($excerpt) ? "</div>" : '';
  640.                     $output .= '<footer class="entry-footer"></footer>';
  641.                     $output .= "</article>";
  642.                     $output .= "</div>";
  643.                 }
  644.  
  645.  
  646.                 $loop_counter ++;
  647.                 $post_loop_count ++;
  648.                 $extraClass = "";
  649.  
  650.                 if($loop_counter > $columns)
  651.                 {
  652.                     $loop_counter = 1;
  653.                     $extraClass = 'first';
  654.                 }
  655.             }
  656.  
  657.             $output .= "</div>";
  658.  
  659.             //append pagination
  660.             if($paginate == "yes" && $avia_pagination = avia_pagination($this->entries->max_num_pages, 'nav')) $output .= "<div class='pagination-wrap pagination-{$post_type}'>{$avia_pagination}</div>";
  661.  
  662.             return $output;
  663.         }
  664.  
  665.         //generates the html for the sort buttons
  666.         protected function sort_buttons($entries, $params)
  667.         {
  668.             //get all categories that are actually listed on the page
  669.             $categories = get_categories(array(
  670.                 'taxonomy'  => $params['taxonomy'],
  671.                 'hide_empty'=> 0
  672.             ));
  673.  
  674.             $current_page_cats  = array();
  675.             $cat_count          = array();
  676.             $display_cats       = is_array($params['categories']) ? $params['categories'] : array_filter(explode(',',$params['categories']));
  677.  
  678.             foreach ($entries as $entry)
  679.             {
  680.                 if($current_item_cats = get_the_terms( $entry->ID, $params['taxonomy'] ))
  681.                 {
  682.                     if(!empty($current_item_cats))
  683.                     {
  684.                         foreach($current_item_cats as $current_item_cat)
  685.                         {
  686.                             if(empty($display_cats) || in_array($current_item_cat->term_id, $display_cats))
  687.                             {
  688.                                 $current_page_cats[$current_item_cat->term_id] = $current_item_cat->term_id;
  689.  
  690.                                 if(!isset($cat_count[$current_item_cat->term_id] ))
  691.                                 {
  692.                                     $cat_count[$current_item_cat->term_id] = 0;
  693.                                 }
  694.  
  695.                                 $cat_count[$current_item_cat->term_id] ++;
  696.                             }
  697.                         }
  698.                     }
  699.                 }
  700.             }
  701.  
  702.             extract($this->screen_options); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  703.  
  704.             $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' >";
  705.             $hide   = count($current_page_cats) <= 1 ? "hidden" : "";
  706.  
  707.  
  708.             $first_item_name = apply_filters('avf_portfolio_sort_first_label', __('All','avia_framework' ), $params);
  709.             $first_item_html = '<span class="inner_sort_button"><span>'.$first_item_name.'</span><small class="av-cat-count"> '.count($entries).' </small></span>';
  710.             $output .= apply_filters('avf_portfolio_sort_heading', "", $params);
  711.  
  712.  
  713.             if(strpos($this->atts['sort'], 'tax') !== false) $output .= "<div class='av-current-sort-title'>{$first_item_html}</div>";
  714.             $output .= "<div class='sort_by_cat {$hide} '>";
  715.             $output .= '<a href="#" data-filter="all_sort" class="all_sort_button active_sort">'.$first_item_html.'</a>';
  716.  
  717.  
  718.             foreach($categories as $category)
  719.             {
  720.                 if(in_array($category->term_id, $current_page_cats))
  721.                 {
  722.                     //fix for cyrillic, etc. characters - isotope does not support the % char
  723.                     $category->category_nicename = str_replace('%', '', $category->category_nicename);
  724.  
  725.                     $output .=  "<span class='text-sep ".$category->category_nicename."_sort_sep'>/</span>";
  726.                     $output .=      '<a href="#" data-filter="'.$category->category_nicename.'_sort" class="'.$category->category_nicename.'_sort_button" ><span class="inner_sort_button">';
  727.                     $output .=          "<span>".esc_html(trim($category->cat_name))."</span>";
  728.                     $output .=          "<small class='av-cat-count'> ".$cat_count[$category->term_id]." </small></span>";
  729.                     $output .=      "</a>";
  730.                 }
  731.             }
  732.  
  733.             $output .= "</div></div></div>";
  734.  
  735.             return $output;
  736.         }
  737.  
  738.  
  739.         //get the categories for each post and create a string that serves as classes so the javascript can sort by those classes
  740.         protected function sort_cat_string($the_id, $params)
  741.         {
  742.             $sort_classes = "";
  743.             $item_categories = get_the_terms( $the_id, $params['taxonomy']);
  744.  
  745.             if(is_object($item_categories) || is_array($item_categories))
  746.             {
  747.                 foreach ($item_categories as $cat)
  748.                 {
  749.                     //fix for cyrillic, etc. characters - isotope does not support the % char
  750.                     $cat->slug = str_replace('%', '', $cat->slug);
  751.  
  752.                     $sort_classes .= $cat->slug.'_sort ';
  753.                 }
  754.             }
  755.  
  756.             return $sort_classes;
  757.         }
  758.  
  759.         protected function build_preview_template( $entry )
  760.         {
  761.             if(isset(avia_post_grid::$preview_template[$entry->ID])) return;
  762.             avia_post_grid::$preview_template[$entry->ID] = true;
  763.  
  764.             $id                     = $entry->ID;
  765.             $output                 = "";
  766.             $defaults               = array( 'ids' => get_post_thumbnail_id( $id ), 'text' => apply_filters( 'get_the_excerpt', $entry->post_excerpt) , "method" => 'gallery' , "auto" => "", "columns" => 5);
  767.             $params['ids']          = get_post_meta( $id ,'_preview_ids', true);
  768.             $params['text']         = get_post_meta( $id ,'_preview_text', true);
  769.             $params['method']       = get_post_meta( $id ,'_preview_display', true);
  770.             $params['interval']     = get_post_meta( $id ,'_preview_autorotation', true);
  771.             $params['columns']      = get_post_meta( $id ,'_preview_columns', true);
  772.             $params['preview_size'] = apply_filters('avf_ajax_preview_image_size',"gallery");
  773.             $params['autoplay']     = is_numeric($params['interval']) ? "true" : "false";
  774.  
  775.             $link = get_post_meta( $id ,'_portfolio_custom_link', true) != "" ? get_post_meta( $id ,'_portfolio_custom_link_url', true) : get_permalink($id);
  776.  
  777.  
  778.             //merge default and params array. remove empty params with array_filter
  779.             $params = array_merge($defaults, array_filter($params));
  780.  
  781.             $params = apply_filters('avf_portfolio_preview_template_params', $params, $entry);
  782.  
  783.             //set the content
  784.             $content = str_replace(']]>', ']]&gt;', apply_filters('the_content', $params['text'] )); unset($params['text']);
  785.  
  786.             //set images
  787.             $string = "";
  788.  
  789.             //set first class if preview images are deactivated
  790.             $nogalleryclass = '';
  791.             $params['ajax_request'] = true;
  792.             switch($params['method'])
  793.             {
  794.                 case 'gallery':
  795.  
  796.                     $params['style'] =  "big_thumb";
  797.                     $params['thumb_size'] =  "square";
  798.                     foreach($params as $key => $param) $string .= $key."='".$param."' ";
  799.                     $images = do_shortcode("[av_gallery {$string}]");
  800.                 break;
  801.  
  802.                 case 'slideshow':
  803.                     $params['size'] = $params['preview_size'];
  804.                     foreach($params as $key => $param) $string .= $key."='".$param."' ";
  805.                     $images = do_shortcode("[av_slideshow {$string}]");
  806.                 break;
  807.  
  808.                 case 'list':
  809.                     $images = $this->post_images($params['ids']);
  810.                 break;
  811.  
  812.                 case 'no':
  813.                     $images = false;
  814.                     $nogalleryclass = ' no_portfolio_preview_gallery ';
  815.                 break;
  816.             }
  817.  
  818.             $output .= "<div class='ajax_slide ajax_slide_{$id}' data-slide-id='{$id}' >";
  819.  
  820.                 $output .= "<article class='inner_slide $nogalleryclass' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$id, 'custom_markup'=>$this->atts['custom_markup'])).">";
  821.  
  822.                 if(!empty($images))
  823.                 {
  824.                     $output .= "<div class='av_table_col first portfolio-preview-image'>";
  825.                     $output .= $images;
  826.                     $output .= "</div>";
  827.                 }
  828.  
  829.                 if(!empty($nogalleryclass)) $nogalleryclass .= ' first ';
  830.  
  831.                     $output .= "<div class='av_table_col $nogalleryclass portfolio-entry portfolio-preview-content'>";
  832.  
  833.                         $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$id, 'custom_markup'=>$this->atts['custom_markup']));
  834.                         $output .= '<header class="entry-content-header">';
  835.                         $output .= "<h2 class='portfolio-preview-title entry-title' $markup><a href='{$link}'>".$entry->post_title."</a></h2>";
  836.                         $output .= '</header>';
  837.  
  838.                         $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'])).">";
  839.                         $output .= $content;
  840.                         $output .= "</div>";
  841.                         $output .= "<span class='avia-arrow'></span>";
  842.                     $output .= "</div>";
  843.  
  844.                 $output .= '<footer class="entry-footer"></footer>';
  845.                 $output .= "</article>";
  846.  
  847.             $output .= "</div>";
  848.  
  849.         return "<script type='text/html' id='avia-tmpl-portfolio-preview-{$id}'>\n{$output}\n</script>\n\n";
  850.  
  851.         }
  852.  
  853.         protected function post_images($ids)
  854.         {
  855.             if(empty($ids)) return;
  856.  
  857.             $attachments = get_posts(array(
  858.                 'include' => $ids,
  859.                 'post_status' => 'inherit',
  860.                 'post_type' => 'attachment',
  861.                 'post_mime_type' => 'image',
  862.                 'order' => 'ASC',
  863.                 'orderby' => 'post__in')
  864.                 );
  865.  
  866.             $output = "";
  867.  
  868.             foreach($attachments as $attachment)
  869.             {
  870.                 $img     = wp_get_attachment_image_src($attachment->ID, 'large');
  871.  
  872.                 $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
  873.                 $alt = !empty($alt) ? esc_attr($alt) : '';
  874.                 $title = trim($attachment->post_title) ? esc_attr($attachment->post_title) : "";
  875.                 $description = trim($attachment->post_content) ? esc_attr($attachment->post_content) : "";
  876.  
  877.                 $output .= " <a href='".$img[0]."' class='portolio-preview-list-image' title='".$description."' ><img src='".$img[0]."' title='".$title."' alt='".$alt."' /></a>";
  878.             }
  879.  
  880.             return $output;
  881.         }
  882.  
  883.  
  884.  
  885.  
  886.         public function print_preview_templates()
  887.         {
  888.             foreach ($this->entries->posts as $entry)
  889.             {
  890.                 echo $this->build_preview_template( $entry );
  891.             }
  892.         }
  893.  
  894.  
  895.  
  896.         //fetch new entries
  897.         public function query_entries($params = array())
  898.         {
  899.  
  900.  
  901.             $query = array();
  902.             if(empty($params)) $params = $this->atts;
  903.  
  904.             if(!empty($params['categories']))
  905.             {
  906.                 //get the portfolio categories
  907.                 $terms  = explode(',', $params['categories']);
  908.             }
  909.  
  910.             $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' );
  911.             if(!$page || $params['paginate'] == 'no') $page = 1;
  912.  
  913.             //if we find categories perform complex query, otherwise simple one
  914.             if(isset($terms[0]) && !empty($terms[0]) && !is_null($terms[0]) && $terms[0] != "null")
  915.             {
  916.                 $query = array( 'orderby'   => $params['query_orderby'],
  917.                                 'order'     => $params['query_order'],
  918.                                 'paged'     => $page,
  919.                                 'posts_per_page' => $params['items'],
  920.                                 'post_type' => $params['post_type'],
  921.                                 'tax_query' => array(   array(  'taxonomy'  => $params['taxonomy'],
  922.                                                                 'field'     => 'id',
  923.                                                                 'terms'     => $terms,
  924.                                                                 'operator'  => 'IN')));
  925.             }
  926.             else
  927.             {
  928.                 $query = array( 'orderby'   => $params['query_orderby'],
  929.                                 'order'     => $params['query_order'],
  930.                                 'paged'     => $page,
  931.                                 'posts_per_page' => $params['items'],
  932.                                 'post_type' => $params['post_type']);
  933.             }
  934.  
  935.             $query = apply_filters('avia_post_grid_query', $query, $params);
  936.  
  937.             $this->entries = new WP_Query( $query );
  938.  
  939.         }
  940.  
  941.  
  942.         //function that 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.
  943.         //Shortcode uses the query_entries function above
  944.         public function use_global_query()
  945.         {
  946.             global $wp_query;
  947.             $this->entries = $wp_query;
  948.         }
  949.  
  950.  
  951.  
  952.     }
  953. }
  954.  
  955.  
  956. /*
  957. Example: how to order posts randomly on page load. put this into functions.php
  958.  
  959. add_filter('avia_post_grid_query','avia_order_by_random');
  960. function avia_order_by_random($query)
  961. {
  962.     $query['orderby'] = 'rand';
  963.     return $query;
  964. }
  965. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement