Advertisement
Guest User

portfolio.php

a guest
Jun 25th, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 30.23 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(  "name"      => __("Which categories should be used for the portfolio?", 'avia_framework' ),
  43.                             "desc"      => __("You can select multiple categories here. The Page will then show posts from only those categories.", 'avia_framework' ),
  44.                             "id"        => "categories",
  45.                             "type"      => "select",
  46.                             "multiple"  => 6,
  47.                             "taxonomy"  => "portfolio_entries",
  48.                             "subtype"   => "cat"),
  49.                     /*
  50.                         array(
  51.                             "name"  => __("Style?", 'avia_framework' ),
  52.                             "desc"  => __("Choose the style of the entries here", 'avia_framework' ),
  53.                             "id"    => "style",
  54.                             "type"  => "select",
  55.                             "std"   => "",
  56.                             "subtype" => array( __('Default Style', 'avia_framework' ) => '',
  57.                                                 __('Circle Image Stlye',  'avia_framework' )=>'grid-circle')),
  58.                     */
  59.  
  60.                     array(
  61.                             "name"  => __("Columns", 'avia_framework' ),
  62.                             "desc"  => __("How many columns should be displayed?", 'avia_framework' ),
  63.                             "id"    => "columns",
  64.                             "type"  => "select",
  65.                             "std"   => "4",
  66.                             "subtype" => array( __('1 Column',  'avia_framework' )=>'1',
  67.                                                 __('2 Columns', 'avia_framework' )=>'2',
  68.                                                 __('3 Columns', 'avia_framework' )=>'3',
  69.                                                 __('4 Columns', 'avia_framework' )=>'4',
  70.                                                 __('5 Columns', 'avia_framework' )=>'5',
  71.                                                 /*__('6 Columns', 'avia_framework' )=>'6',*/
  72.                                                 )),
  73.  
  74.                     array(
  75.                         "name"  => __("1 Column layout", 'avia_framework' ),
  76.                         "desc"  => __("Choose the 1 column layout", 'avia_framework' ),
  77.                         "id"    => "one_column_template",
  78.                         "type"  => "select",
  79.                         "required"  => array('columns','equals','1'),
  80.                         "std"   => "special",
  81.                         "subtype" => array(
  82.                             __('Use special 1 column layout (side by side)',  'avia_framework' ) =>'special',
  83.                             __('Use default portfolio layout',  'avia_framework' ) =>'default')),
  84.  
  85.                     array(
  86.                             "name"  => __("Post Number", 'avia_framework' ),
  87.                             "desc"  => __("How many items should be displayed per page?", 'avia_framework' ),
  88.                             "id"    => "items",
  89.                             "type"  => "select",
  90.                             "std"   => "16",
  91.                             "subtype" => AviaHtmlHelper::number_array(1,100,1, array('All'=>'-1'))),
  92.  
  93.                     array(
  94.                             "name"  => __("Excerpt", 'avia_framework' ),
  95.                             "desc"  => __("Display Excerpt and Title below the preview image?", 'avia_framework' ),
  96.                             "id"    => "contents",
  97.                             "type"  => "select",
  98.                             "std"   => "yes",
  99.                             "subtype" => array(
  100.                                 __('Title and Excerpt',  'avia_framework' ) =>'excerpt',
  101.                                 __('Only Title',  'avia_framework' ) =>'title',
  102.                                 __('Only excerpt',  'avia_framework' ) =>'only_excerpt',
  103.                                 __('No Title and no excerpt',  'avia_framework' ) =>'no')),
  104.  
  105.                     array(
  106.                         "name"  => __("Portfolio Grid Image Size", 'avia_framework' ),
  107.                         "desc"  => __("Set the image size of the Portfolio Grid images", 'avia_framework' ),
  108.                         "id"    => "preview_mode",
  109.                         "type"  => "select",
  110.                         "std"   => "auto",
  111.                         "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')),
  112.  
  113.                     array(
  114.                         "name"  => __("Select custom image size", 'avia_framework' ),
  115.                         "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>",
  116.                         "id"    => "image_size",
  117.                         "type"  => "select",
  118.                         "required"  => array('preview_mode','equals','custom'),
  119.                         "std"   => "portfolio",
  120.                         "subtype" =>  AviaHelper::get_registered_image_sizes(array('logo','thumbnail','widget'))
  121.                     ),
  122.  
  123.                     array(
  124.                             "name"  => __("Link Handling", 'avia_framework' ),
  125.                             "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' ),
  126.                             "id"    => "linking",
  127.                             "type"  => "select",
  128.                             "std"   => "",
  129.                             "subtype" => array(
  130.                                 __('Open the entry on a new page',  'avia_framework' ) =>'',
  131.                                 __('Open a preview of the entry (known as AJAX Portfolio)',  'avia_framework' ) =>'ajax',
  132.                                 __('Display the big image in a lightbox',  'avia_framework' ) =>'lightbox')),
  133.  
  134.                     array(
  135.                             "name"  => __("Sortable?", 'avia_framework' ),
  136.                             "desc"  => __("Should the sorting options based on categories be displayed?", 'avia_framework' ),
  137.                             "id"    => "sort",
  138.                             "type"  => "select",
  139.                             "std"   => "yes",
  140.                             "subtype" => array(
  141.                                 __('yes',  'avia_framework' ) => 'yes',
  142.                                 __('no',  'avia_framework' )  => 'no')),
  143.  
  144.                     array(
  145.                             "name"  => __("Pagination", 'avia_framework' ),
  146.                             "desc"  => __("Should a pagination be displayed?", 'avia_framework' ),
  147.                             "id"    => "paginate",
  148.                             "type"  => "select",
  149.                             "std"   => "yes",
  150.                             "subtype" => array(
  151.                                 __('yes',  'avia_framework' ) =>'yes',
  152.                                 __('no',  'avia_framework' ) =>'no')),
  153.  
  154.                 );
  155.                
  156.                
  157.                     if(current_theme_supports('avia_template_builder_custom_post_type_grid'))
  158.                     {
  159.                         $this->elements[0] = array(
  160.                                 "name"  => __("Which Entries?", 'avia_framework' ),
  161.                                 "desc"  => __("Select which entries should be displayed by selecting a taxonomy", 'avia_framework' ),
  162.                                 "id"    => "link",
  163.                                 "fetchTMPL" => true,
  164.                                 "type"  => "linkpicker",
  165.                                 "subtype"  => array( __('Display Entries from:',  'avia_framework' )=>'taxonomy'),
  166.                                 "multiple"  => 6,
  167.                                 "std"   => "category");
  168.  
  169.  
  170.                         if(current_theme_supports('add_avia_builder_post_type_option'))
  171.                         {
  172.                             $element = array(
  173.                                 "name"  => __("Select Post Type", 'avia_framework' ),
  174.                                 "desc"  => __("Select which post types should be used. Note that your taxonomy will be ignored if you do not select an assign post type.
  175.                                               If yo don't select post type all registered post types will be used", 'avia_framework' ),
  176.                                 "id"    => "post_type",
  177.                                 "type"  => "select",
  178.                                 "multiple"  => 6,
  179.                                 "std"   => "",
  180.                                 "subtype" => AviaHtmlHelper::get_registered_post_type_array()
  181.                             );
  182.  
  183.                             array_unshift($this->elements, $element);
  184.                         }
  185.                     }
  186.  
  187.  
  188.  
  189.             }
  190.  
  191.  
  192.  
  193.             /**
  194.              * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  195.              * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  196.              * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  197.              *
  198.              *
  199.              * @param array $params this array holds the default values for $content and $args.
  200.              * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  201.              */
  202.             function editor_element($params)
  203.             {
  204.                 $params['innerHtml'] = "<img src='".$this->config['icon']."' title='".$this->config['name']."' />";
  205.                 $params['innerHtml'].= "<div class='avia-element-label'>".$this->config['name']."</div>";
  206.                 $params['content']   = NULL; //remove to allow content elements
  207.  
  208.                 return $params;
  209.             }
  210.  
  211.  
  212.  
  213.             /**
  214.              * Frontend Shortcode Handler
  215.              *
  216.              * @param array $atts array of attributes
  217.              * @param string $content text within enclosing form of shortcode element
  218.              * @param string $shortcodename the shortcode found, when == callback name
  219.              * @return string $output returns the modified html string
  220.              */
  221.             function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  222.             {
  223.                 $atts['class'] = !empty($meta['custom_class']) ? $meta['custom_class'] : "";
  224.                
  225.                 if(current_theme_supports('avia_template_builder_custom_post_type_grid'))
  226.                 {
  227.                     if(isset($atts['link']))
  228.                     {
  229.                         $atts['link'] = explode(',', $atts['link'], 2 );
  230.                         $atts['taxonomy'] = $atts['link'][0];
  231.                
  232.                         if(isset($atts['link'][1]))
  233.                         {
  234.                             $atts['categories'] = $atts['link'][1];
  235.                         }
  236.                     }
  237.                
  238.                     if(empty($atts['post_type']) || !current_theme_supports('add_avia_builder_post_type_option'))
  239.                     {
  240.                         $atts['post_type'] = get_post_types();
  241.                     }
  242.  
  243.                     if(is_string($atts['post_type'])) $atts['post_type'] = explode(',', $atts['post_type']);
  244.                 }
  245.  
  246.  
  247.                 $grid = new avia_post_grid($atts);
  248.                 $grid->query_entries();
  249.                 return $grid->html();
  250.             }
  251.         }
  252. }
  253.  
  254.  
  255.  
  256.  
  257. if ( !class_exists( 'avia_post_grid' ) )
  258. {
  259.     class avia_post_grid
  260.     {
  261.         static  $grid = 0;
  262.         static  $preview_template = array();
  263.         protected $atts;
  264.         protected $entries;
  265.  
  266.         function __construct($atts = array())
  267.         {
  268.             $this->atts = shortcode_atts(array( 'style'     => '',
  269.                                                 'linking'   => '',
  270.                                                 'columns'   => '4',
  271.                                                 'items'     => '16',
  272.                                                 'contents'  => 'title',
  273.                                                 'sort'      => 'yes',
  274.                                                 'paginate'  => 'yes',
  275.                                                 'categories'=> '',
  276.                                                 'preview_mode' => 'auto',
  277.                                                 'image_size' => 'portfolio',
  278.                                                 'post_type' => 'portfolio',
  279.                                                 'taxonomy'  => 'portfolio_entries',
  280.                                                 'one_column_template' => 'special',
  281.                                                 'set_breadcrumb' => true, //no shortcode option for this, modifies the breadcrumb nav, must be false on taxonomy overview
  282.                                                 'class'     => "",
  283.                                                 'custom_markup' => ''
  284.                                                 ), $atts, 'av_portfolio');
  285.  
  286.  
  287.  
  288.             if($this->atts['linking'] == 'ajax')
  289.                 add_action('wp_footer' , array($this, 'print_preview_templates'));
  290.         }
  291.  
  292.         //generates the html of the post grid
  293.         public function html()
  294.         {
  295.             if(empty($this->entries) || empty($this->entries->posts)) return;
  296.  
  297.             avia_post_grid::$grid ++;
  298.             extract($this->atts);
  299.  
  300.             $container_id       = avia_post_grid::$grid;
  301.             $extraClass         = 'first';
  302.             $grid               = 'one_fourth';
  303.             if($preview_mode == 'auto') $image_size = 'portfolio';
  304.             $post_loop_count    = 1;
  305.             $loop_counter       = 1;
  306.             $output             = "";
  307.             $style_class        = empty($style) ? 'no_margin' : $style;
  308.             $total              = $this->entries->post_count % 2 ? "odd" : "even";
  309.  
  310.             if($set_breadcrumb && is_page())
  311.             {
  312.                 $_SESSION["avia_{$post_type}"] = get_the_ID();
  313.             }
  314.  
  315.             switch($columns)
  316.             {
  317.                 case "1": $grid = 'av_fullwidth';  if($preview_mode == 'auto') $image_size = 'featured'; break;
  318.                 case "2": $grid = 'av_one_half';   break;
  319.                 case "3": $grid = 'av_one_third';  break;
  320.                 case "4": $grid = 'av_one_fourth'; if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  321.                 case "5": $grid = 'av_one_fifth';  if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  322.                 case "6": $grid = 'av_one_sixth';  if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  323.             }
  324.  
  325.             $output .= $sort == "yes" ? $this->sort_buttons($this->entries->posts, $this->atts) : "";
  326.  
  327.             if($linking == "ajax")
  328.             {
  329.             global $avia_config;
  330.  
  331.             $output .= "<div class='portfolio_preview_container' data-portfolio-id='{$container_id}'>
  332.                             <div class='ajax_controlls iconfont'>
  333.                                 <a href='#prev' class='ajax_previous'   ".av_icon_string('prev')."></a>
  334.                                 <a href='#next' class='ajax_next'       ".av_icon_string('next')."></a>
  335.                                 <a class='avia_close' href='#close'     ".av_icon_string('close')."></a>
  336.                             </div>
  337.                             <div class='portfolio-details-inner'></div>
  338.                         </div>";
  339.             }
  340.             $output .= "<div class='{$class} grid-sort-container isotope {$style_class}-container with-{$contents}-container grid-total-{$total} grid-col-{$columns} grid-links-{$linking}' data-portfolio-id='{$container_id}'>";
  341.  
  342.             foreach ($this->entries->posts as $entry)
  343.             {
  344.                 $the_id     = $entry->ID;
  345.                 $parity     = $post_loop_count % 2 ? 'odd' : 'even';
  346.                 $last       = $this->entries->post_count == $post_loop_count ? " post-entry-last " : "";
  347.                 $post_class = "post-entry post-entry-{$the_id} grid-entry-overview grid-loop-{$post_loop_count} grid-parity-{$parity} {$last}";
  348.                 $sort_class = $this->sort_cat_string($the_id, $this->atts);
  349.  
  350.                 switch($linking)
  351.                 {
  352.                     case "lightbox":  $link = wp_get_attachment_image_src(get_post_thumbnail_id($the_id), 'large'); $link = $link[0];   break;
  353.                     default:          $link = get_permalink($the_id); break;
  354.                 }
  355.  
  356.                 $title_link  = get_permalink($the_id);
  357.                 $custom_link = get_post_meta( $the_id ,'_portfolio_custom_link', true) != "" ? get_post_meta( $the_id ,'_portfolio_custom_link_url', true) : false;
  358.  
  359.                 if($custom_link)
  360.                 {
  361.                     $title_link = $link = $custom_link;
  362.                 }
  363.  
  364.                 $excerpt    = '';
  365.                 $title      = '';
  366.  
  367.                 switch($contents)
  368.                 {
  369.                     case "excerpt": $excerpt = $entry->post_excerpt; $title = $entry->post_title; break;
  370.                     case "title": $excerpt = ''; $title = $entry->post_title;  break;
  371.                     case "only_excerpt": $excerpt = $entry->post_excerpt; $title = ''; break;
  372.                     case "no": $excerpt = ''; $title = ''; break;
  373.                 }
  374.  
  375.                 $custom_overlay = apply_filters('avf_portfolio_custom_overlay', "", $entry);
  376.                 $link_markup    = apply_filters('avf_portfolio_custom_image_container', array("a href='{$link}' title='".esc_attr(strip_tags($title))."' ",'a'), $entry);
  377.  
  378.                 $title          = apply_filters('avf_portfolio_title', $title, $entry);
  379.                 $title_link     = apply_filters('avf_portfolio_title_link', $title_link, $entry);
  380.  
  381.                 if($columns == "1" && $one_column_template == 'special')
  382.                 {
  383.                     $extraClass .= ' special_av_fullwidth ';
  384.  
  385.                     $output .= "<div data-ajax-id='{$the_id}' class=' grid-entry flex_column isotope-item all_sort {$style_class} {$post_class} {$sort_class} {$grid} {$extraClass}'>";
  386.                     $output .= "<article class='main_color inner-entry' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup)).">";
  387.                     $output .= apply_filters('avf_portfolio_extra', "", $entry);
  388.  
  389.                     $image = get_the_post_thumbnail( $the_id, $image_size );
  390.                     if(!empty($image))
  391.                     {
  392.                         $output .= "<div class='av_table_col first portfolio-grid-image'>";
  393.                         $output .= "<".$link_markup[0]." data-rel='grid-".avia_post_grid::$grid."' class='grid-image avia-hover-fx'>".$custom_overlay.$image."</".$link_markup[1].">";
  394.                         $output .= "</div>";
  395.                     }
  396.                    
  397.                      $output .= "<div class='av_table_col portfolio-entry grid-content'>";
  398.  
  399.                     if(!empty($title))
  400.                     {
  401.                         $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  402.                         $output .= '<header class="entry-content-header">';
  403.                         $output .= "<h2 class='portfolio-grid-title entry-title' $markup><a href='{$title_link}'>".$title."</a></h2>";
  404.                         $output .= '</header>';
  405.                     }
  406.  
  407.                     if(!empty($excerpt))
  408.                     {
  409.                         $markup = avia_markup_helper(array('context' => 'entry_content','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  410.  
  411.                         $output .= "<div class='entry-content-wrapper'>";
  412.                         $output .= "<div class='grid-entry-excerpt entry-content' $markup>".$excerpt."</div>";
  413.                         $output .= "</div>";
  414.                     }
  415.                     $output .= '<div class="avia-arrow"></div>';
  416.                     $output .= "</div>";
  417.                     $output .= '<footer class="entry-footer"></footer>';
  418.                     $output .= "</article>";
  419.                     $output .= "</div>";
  420.                 }
  421.                 else
  422.                 {
  423.                     $extraClass .= ' default_av_fullwidth ';
  424.  
  425.                     $output .= "<div data-ajax-id='{$the_id}' class=' grid-entry flex_column isotope-item all_sort {$style_class} {$post_class} {$sort_class} {$grid} {$extraClass}'>";
  426.                     $output .= "<article class='main_color inner-entry' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup)).">";
  427.                     $output .= apply_filters('avf_portfolio_extra', "", $entry);
  428.                     $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 )."</".$link_markup[1].">";
  429.                     $output .= !empty($title) || !empty($excerpt) ? "<div class='grid-content'><div class='avia-arrow'></div>" : '';
  430.  
  431.                     if(!empty($title))
  432.                     {
  433.                         $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  434.                         $output .= '<header class="entry-content-header">';
  435.                         $output .= "<h3 class='grid-entry-title entry-title' $markup><a href='{$title_link}' title='".esc_attr(strip_tags($title))."'>".$title."</a></h3>";
  436.                         $output .= '</header>';
  437.                     }
  438.                     $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>" : '';
  439.                     $output .= !empty($title) || !empty($excerpt) ? "</div>" : '';
  440.                     $output .= '<footer class="entry-footer"></footer>';
  441.                     $output .= "</article>";
  442.                     $output .= "</div>";
  443.                 }
  444.  
  445.  
  446.                 $loop_counter ++;
  447.                 $post_loop_count ++;
  448.                 $extraClass = "";
  449.  
  450.                 if($loop_counter > $columns)
  451.                 {
  452.                     $loop_counter = 1;
  453.                     $extraClass = 'first';
  454.                 }
  455.             }
  456.  
  457.             $output .= "</div>";
  458.  
  459.             //append pagination
  460.             if($paginate == "yes" && $avia_pagination = avia_pagination($this->entries->max_num_pages, 'nav')) $output .= "<div class='pagination-wrap pagination-{$post_type}'>{$avia_pagination}</div>";
  461.  
  462.             return $output;
  463.         }
  464.  
  465.         //generates the html for the sort buttons
  466.         protected function sort_buttons($entries, $params)
  467.         {
  468.             //get all categories that are actually listed on the page
  469.             $categories = get_categories(array(
  470.                 'taxonomy'  => $params['taxonomy'],
  471.                 'hide_empty'=> 0
  472.             ));
  473.  
  474.             $current_page_cats  = array();
  475.             $cat_count          = array();
  476.             $display_cats       = is_array($params['categories']) ? $params['categories'] : array_filter(explode(',',$params['categories']));
  477.  
  478.             foreach ($entries as $entry)
  479.             {
  480.                 if($current_item_cats = get_the_terms( $entry->ID, $params['taxonomy'] ))
  481.                 {
  482.                     if(!empty($current_item_cats))
  483.                     {
  484.                         foreach($current_item_cats as $current_item_cat)
  485.                         {
  486.                             if(empty($display_cats) || in_array($current_item_cat->term_id, $display_cats))
  487.                             {
  488.                                 $current_page_cats[$current_item_cat->term_id] = $current_item_cat->term_id;
  489.  
  490.                                 if(!isset($cat_count[$current_item_cat->term_id] ))
  491.                                 {
  492.                                     $cat_count[$current_item_cat->term_id] = 0;
  493.                                 }
  494.  
  495.                                 $cat_count[$current_item_cat->term_id] ++;
  496.                             }
  497.                         }
  498.                     }
  499.                 }
  500.             }
  501.  
  502.             $output = "<div class='sort_width_container' data-portfolio-id='".avia_post_grid::$grid."' ><div id='js_sort_items' >";
  503.             $hide   = count($current_page_cats) <= 1 ? "hidden" : "";
  504.  
  505.  
  506.             $first_item_name = apply_filters('avf_portfolio_sort_first_label', __('All','avia_framework' ), $params);
  507.             $output .= apply_filters('avf_portfolio_sort_heading', "", $params);
  508.             $output .= "<div class='sort_by_cat {$hide} '>";
  509.             $output .= '<a href="#" data-filter="all_sort" class="all_sort_button active_sort"><span class="inner_sort_button"><span>'.$first_item_name.'</span><small class="av-cat-count"> '.count($entries).' </small></span></a>';
  510.  
  511.  
  512.             foreach($categories as $category)
  513.             {
  514.                 if(in_array($category->term_id, $current_page_cats))
  515.                 {
  516.                     //fix for cyrillic, etc. characters - isotope does not support the % char
  517.                     $category->category_nicename = str_replace('%', '', $category->category_nicename);
  518.  
  519.                     $output .=  "<span class='text-sep ".$category->category_nicename."_sort_sep'>/</span>";
  520.                     $output .=      '<a href="#" data-filter="'.$category->category_nicename.'_sort" class="'.$category->category_nicename.'_sort_button" ><span class="inner_sort_button">';
  521.                     $output .=          "<span>".esc_html(trim($category->cat_name))."</span>";
  522.                     $output .=          "<small class='av-cat-count'> ".$cat_count[$category->term_id]." </small></span>";
  523.                     $output .=      "</a>";
  524.                 }
  525.             }
  526.  
  527.             $output .= "</div></div></div>";
  528.  
  529.             return $output;
  530.         }
  531.  
  532.  
  533.         //get the categories for each post and create a string that serves as classes so the javascript can sort by those classes
  534.         protected function sort_cat_string($the_id, $params)
  535.         {
  536.             $sort_classes = "";
  537.             $item_categories = get_the_terms( $the_id, $params['taxonomy']);
  538.  
  539.             if(is_object($item_categories) || is_array($item_categories))
  540.             {
  541.                 foreach ($item_categories as $cat)
  542.                 {
  543.                     //fix for cyrillic, etc. characters - isotope does not support the % char
  544.                     $cat->slug = str_replace('%', '', $cat->slug);
  545.                    
  546.                     $sort_classes .= $cat->slug.'_sort ';
  547.                 }
  548.             }
  549.  
  550.             return $sort_classes;
  551.         }
  552.  
  553.         protected function build_preview_template( $entry )
  554.         {
  555.             if(isset(avia_post_grid::$preview_template[$entry->ID])) return;
  556.             avia_post_grid::$preview_template[$entry->ID] = true;
  557.  
  558.             $id                     = $entry->ID;
  559.             $output                 = "";
  560.             $defaults               = array( 'ids' => get_post_thumbnail_id( $id ), 'text' => apply_filters( 'get_the_excerpt', $entry->post_excerpt) , "method" => 'gallery' , "auto" => "", "columns" => 5);
  561.             $params['ids']          = get_post_meta( $id ,'_preview_ids', true);
  562.             $params['text']         = get_post_meta( $id ,'_preview_text', true);
  563.             $params['method']       = get_post_meta( $id ,'_preview_display', true);
  564.             $params['interval']     = get_post_meta( $id ,'_preview_autorotation', true);
  565.             $params['columns']      = get_post_meta( $id ,'_preview_columns', true);
  566.             $params['preview_size'] = apply_filters('avf_ajax_preview_image_size',"gallery");
  567.             $params['autoplay']     = is_numeric($params['interval']) ? "true" : "false";
  568.  
  569.             $link = get_post_meta( $id ,'_portfolio_custom_link', true) != "" ? get_post_meta( $id ,'_portfolio_custom_link_url', true) : get_permalink($id);
  570.  
  571.  
  572.             //merge default and params array. remove empty params with array_filter
  573.             $params = array_merge($defaults, array_filter($params));
  574.            
  575.             $params = apply_filters('avf_portfolio_preview_template_params', $params, $entry);
  576.  
  577.             //set the content
  578.             $content = str_replace(']]>', ']]&gt;', apply_filters('the_content', $params['text'] )); unset($params['text']);
  579.  
  580.             //set images
  581.             $string = "";
  582.  
  583.             //set first class if preview images are deactivated
  584.             $nogalleryclass = '';
  585.             $params['ajax_request'] = true;
  586.             switch($params['method'])
  587.             {
  588.                 case 'gallery':
  589.  
  590.                     $params['style'] =  "big_thumb";
  591.                     foreach($params as $key => $param) $string .= $key."='".$param."' ";
  592.                     $images = do_shortcode("[av_gallery {$string}]");
  593.                 break;
  594.  
  595.                 case 'slideshow':
  596.                     $params['size'] = $params['preview_size'];
  597.                     foreach($params as $key => $param) $string .= $key."='".$param."' ";
  598.                     $images = do_shortcode("[av_slideshow {$string}]");
  599.                 break;
  600.  
  601.                 case 'list':
  602.                     $images = $this->post_images($params['ids']);
  603.                 break;
  604.  
  605.                 case 'no':
  606.                     $images = false;
  607.                     $nogalleryclass = ' no_portfolio_preview_gallery ';
  608.                 break;
  609.             }
  610.  
  611.             $output .= "<div class='ajax_slide ajax_slide_{$id}' data-slide-id='{$id}' >";
  612.  
  613.                 $output .= "<article class='inner_slide $nogalleryclass' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$id, 'custom_markup'=>$this->atts['custom_markup'])).">";
  614.  
  615.                 if(!empty($images))
  616.                 {
  617.                     $output .= "<div class='av_table_col first portfolio-preview-image'>";
  618.                     $output .= $images;
  619.                     $output .= "</div>";
  620.                 }
  621.  
  622.                 if(!empty($nogalleryclass)) $nogalleryclass .= ' first ';
  623.  
  624.                     $output .= "<div class='av_table_col $nogalleryclass portfolio-entry portfolio-preview-content'>";
  625.  
  626.                         $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$id, 'custom_markup'=>$this->atts['custom_markup']));
  627.                         $output .= '<header class="entry-content-header">';
  628.                         $output .= "<h2 class='portfolio-preview-title entry-title' $markup><a href='{$link}'>".$entry->post_title."</a></h2>";
  629.                         $output .= '</header>';
  630.  
  631.                         $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'])).">";
  632.                         $output .= $content;
  633.                         $output .= "</div>";
  634.                         $output .= "<span class='avia-arrow'></span>";
  635.                     $output .= "</div>";
  636.  
  637.                 $output .= '<footer class="entry-footer"></footer>';
  638.                 $output .= "</article>";
  639.  
  640.             $output .= "</div>";
  641.  
  642.         return "<script type='text/html' id='avia-tmpl-portfolio-preview-{$id}'>\n{$output}\n</script>\n\n";
  643.  
  644.         }
  645.  
  646.         protected function post_images($ids)
  647.         {
  648.             if(empty($ids)) return;
  649.  
  650.             $attachments = get_posts(array(
  651.                 'include' => $ids,
  652.                 'post_status' => 'inherit',
  653.                 'post_type' => 'attachment',
  654.                 'post_mime_type' => 'image',
  655.                 'order' => 'ASC',
  656.                 'orderby' => 'post__in')
  657.                 );
  658.  
  659.             $output = "";
  660.  
  661.             foreach($attachments as $attachment)
  662.             {
  663.                 $img     = wp_get_attachment_image_src($attachment->ID, 'large');
  664.  
  665.                 $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
  666.                 $alt = !empty($alt) ? esc_attr($alt) : '';
  667.                 $title = trim($attachment->post_title) ? esc_attr($attachment->post_title) : "";
  668.                 $description = trim($attachment->post_content) ? esc_attr($attachment->post_content) : "";
  669.  
  670.                 $output .= " <a href='".$img[0]."' class='portolio-preview-list-image' title='".$description."' ><img src='".$img[0]."' title='".$title."' alt='".$alt."' /></a>";
  671.             }
  672.  
  673.             return $output;
  674.         }
  675.  
  676.  
  677.  
  678.  
  679.         public function print_preview_templates()
  680.         {
  681.             foreach ($this->entries->posts as $entry)
  682.             {
  683.                 echo $this->build_preview_template( $entry );
  684.             }
  685.         }
  686.  
  687.  
  688.  
  689.         //fetch new entries
  690.         public function query_entries($params = array())
  691.         {
  692.             $query = array();
  693.             if(empty($params)) $params = $this->atts;
  694.  
  695.             if(!empty($params['categories']))
  696.             {
  697.                 //get the portfolio categories
  698.                 $terms  = explode(',', $params['categories']);
  699.             }
  700.  
  701.             $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' );
  702.             if(!$page || $params['paginate'] == 'no') $page = 1;
  703.  
  704.             //if we find categories perform complex query, otherwise simple one
  705.             if(isset($terms[0]) && !empty($terms[0]) && !is_null($terms[0]) && $terms[0] != "null")
  706.             {
  707.                 $query = array( 'orderby'   => 'post_date',
  708.                                 'order'     => 'DESC',
  709.                                 'paged'     => $page,
  710.                                 'posts_per_page' => $params['items'],
  711.                                 'post_type' => $params['post_type'],
  712.                                 'tax_query' => array(   array(  'taxonomy'  => $params['taxonomy'],
  713.                                                                 'field'     => 'id',
  714.                                                                 'terms'     => $terms,
  715.                                                                 'operator'  => 'IN')));
  716.             }
  717.             else
  718.             {
  719.                 $query = array( 'paged'=> $page, 'posts_per_page' => $params['items'], 'post_type' => $params['post_type']);
  720.             }
  721.  
  722.             $query = apply_filters('avia_post_grid_query', $query, $params);
  723.  
  724.             $this->entries = new WP_Query( $query );
  725.  
  726.         }
  727.  
  728.  
  729.         //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.
  730.         //Shortcode uses the query_entries function above
  731.         public function use_global_query()
  732.         {
  733.             global $wp_query;
  734.             $this->entries = $wp_query;
  735.         }
  736.  
  737.  
  738.  
  739.     }
  740. }
  741.  
  742.  
  743. /*
  744. Example: how to order posts randomly on page load. put this into functions.php
  745.  
  746. add_filter('avia_post_grid_query','avia_order_by_random');
  747. function avia_order_by_random($query)
  748. {
  749.     $query['orderby'] = 'rand';
  750.     return $query;
  751. }
  752. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement