Advertisement
Guest User

Enfold Ajax Image Hover

a guest
Sep 4th, 2014
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 33.32 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['innerHtml'].= "<div class='avia-flex-element'>";
  207.                 $params['innerHtml'].=      __('This element will stretch across the whole screen by default.','avia_framework')."<br/>";
  208.                 $params['innerHtml'].=      __('If you put it inside a color section or column it will only take up the available space','avia_framework');
  209.                 $params['innerHtml'].= "    <div class='avia-flex-element-2nd'>".__('Currently:','avia_framework');
  210.                 $params['innerHtml'].= "    <span class='avia-flex-element-stretched'>&laquo; ".__('Stretch fullwidth','avia_framework')." &raquo;</span>";
  211.                 $params['innerHtml'].= "    <span class='avia-flex-element-content'>| ".__('Adjust to content width','avia_framework')." |</span>";
  212.                 $params['innerHtml'].= "</div></div>";
  213.                
  214.                 $params['content']   = NULL; //remove to allow content elements
  215.  
  216.                 return $params;
  217.             }
  218.  
  219.  
  220.  
  221.             /**
  222.              * Frontend Shortcode Handler
  223.              *
  224.              * @param array $atts array of attributes
  225.              * @param string $content text within enclosing form of shortcode element
  226.              * @param string $shortcodename the shortcode found, when == callback name
  227.              * @return string $output returns the modified html string
  228.              */
  229.             function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  230.             {
  231.                 $atts['class'] = !empty($meta['custom_class']) ? $meta['custom_class'] : "";
  232.                
  233.                 if(current_theme_supports('avia_template_builder_custom_post_type_grid'))
  234.                 {
  235.                     if(isset($atts['link']))
  236.                     {
  237.                         $atts['link'] = explode(',', $atts['link'], 2 );
  238.                         $atts['taxonomy'] = $atts['link'][0];
  239.                
  240.                         if(isset($atts['link'][1]))
  241.                         {
  242.                             $atts['categories'] = $atts['link'][1];
  243.                         }
  244.                     }
  245.                
  246.                     if(empty($atts['post_type']) || !current_theme_supports('add_avia_builder_post_type_option'))
  247.                     {
  248.                         $atts['post_type'] = get_post_types();
  249.                     }
  250.  
  251.                     if(is_string($atts['post_type'])) $atts['post_type'] = explode(',', $atts['post_type']);
  252.                 }
  253.                
  254.                 $atts['fullscreen'] = ShortcodeHelper::is_top_level();
  255.  
  256.                 $grid = new avia_post_grid($atts);
  257.                 $grid->query_entries();
  258.                 $portfolio_html = $grid->html();
  259.            
  260.                 if(!ShortcodeHelper::is_top_level())
  261.                 return $portfolio_html;
  262.                
  263.                
  264.                 $params['class'] = "main_color avia-no-border-styling avia-fullwidth-portfolio ".$meta['el_class'];
  265.                 $params['open_structure'] = false;
  266.                 $params['id'] = !empty($atts['id']) ? AviaHelper::save_string($atts['id'],'-') : "";
  267.                 $params['custom_markup'] = $meta['custom_markup'];
  268.                
  269.                 //we dont need a closing structure if the element is the first one or if a previous fullwidth element was displayed before
  270.                 if($meta['index'] == 0) $params['close'] = false;
  271.                 if(!empty($meta['siblings']['prev']['tag']) && in_array($meta['siblings']['prev']['tag'], AviaBuilder::$full_el_no_section )) $params['close'] = false;
  272.                    
  273.                 $output  =  avia_new_section($params);
  274.                 $output .= $portfolio_html;
  275.                 $output .= avia_section_after_element_content( $meta , 'after_portfolio' );
  276.                
  277.                 return $output;
  278.             }
  279.         }
  280. }
  281.  
  282.  
  283.  
  284.  
  285. if ( !class_exists( 'avia_post_grid' ) )
  286. {
  287.     class avia_post_grid
  288.     {
  289.         static  $grid = 0;
  290.         static  $preview_template = array();
  291.         protected $atts;
  292.         protected $entries;
  293.  
  294.         function __construct($atts = array())
  295.         {
  296.             $this->atts = shortcode_atts(array( 'style'     => '',
  297.                                                 'linking'   => '',
  298.                                                 'columns'   => '4',
  299.                                                 'items'     => '16',
  300.                                                 'contents'  => 'title',
  301.                                                 'sort'      => 'yes',
  302.                                                 'paginate'  => 'yes',
  303.                                                 'categories'=> '',
  304.                                                 'preview_mode' => 'auto',
  305.                                                 'image_size' => 'portfolio',
  306.                                                 'post_type' => 'portfolio',
  307.                                                 'taxonomy'  => 'portfolio_entries',
  308.                                                 'one_column_template' => 'special',
  309.                                                 'set_breadcrumb' => true, //no shortcode option for this, modifies the breadcrumb nav, must be false on taxonomy overview
  310.                                                 'class'     => "",
  311.                                                 'custom_markup' => '',
  312.                                                 'fullscreen'    => false,
  313.                                                 ), $atts, 'av_portfolio');
  314.  
  315.  
  316.  
  317.             if($this->atts['linking'] == 'ajax')
  318.                 add_action('wp_footer' , array($this, 'print_preview_templates'));
  319.         }
  320.  
  321.         //generates the html of the post grid
  322.         public function html()
  323.         {
  324.             if(empty($this->entries) || empty($this->entries->posts)) return;
  325.  
  326.             avia_post_grid::$grid ++;
  327.             extract($this->atts);
  328.  
  329.             $container_id       = avia_post_grid::$grid;
  330.             $extraClass         = 'first';
  331.             $grid               = 'one_fourth';
  332.             if($preview_mode == 'auto') $image_size = 'portfolio';
  333.             $post_loop_count    = 1;
  334.             $loop_counter       = 1;
  335.             $output             = "";
  336.             $style_class        = empty($style) ? 'no_margin' : $style;
  337.             $total              = $this->entries->post_count % 2 ? "odd" : "even";
  338.  
  339.             if($set_breadcrumb && is_page())
  340.             {
  341.                 $_SESSION["avia_{$post_type}"] = get_the_ID();
  342.             }
  343.  
  344.             switch($columns)
  345.             {
  346.                 case "1": $grid = 'av_fullwidth';  if($preview_mode == 'auto') $image_size = 'featured'; break;
  347.                 case "2": $grid = 'av_one_half';   break;
  348.                 case "3": $grid = 'av_one_third';  break;
  349.                 case "4": $grid = 'av_one_fourth'; if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  350.                 case "5": $grid = 'av_one_fifth';  if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  351.                 case "6": $grid = 'av_one_sixth';  if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  352.             }
  353.            
  354.             if($fullscreen && $preview_mode =='auto' && $image_size == "portfolio_small") $image_size = 'portfolio';
  355.  
  356.             $output .= $sort == "yes" ? $this->sort_buttons($this->entries->posts, $this->atts) : "";
  357.  
  358.             if($linking == "ajax")
  359.             {
  360.                 global $avia_config;
  361.                
  362.                 $container_class = $fullscreen ? "container" : "";
  363.                
  364.                 $output .= "<div class='portfolio_preview_container {$container_class}' data-portfolio-id='{$container_id}'>
  365.                                 <div class='ajax_controlls iconfont'>
  366.                                     <a href='#prev' class='ajax_previous'   ".av_icon_string('prev')."></a>
  367.                                     <a href='#next' class='ajax_next'       ".av_icon_string('next')."></a>
  368.                                     <a class='avia_close' href='#close'     ".av_icon_string('close')."></a>
  369.                                 </div>
  370.                                 <div class='portfolio-details-inner'></div>
  371.                             </div>";
  372.             }
  373.             $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}'>";
  374.  
  375.             foreach ($this->entries->posts as $entry)
  376.             {
  377.                 $the_id     = $entry->ID;
  378.                 $parity     = $post_loop_count % 2 ? 'odd' : 'even';
  379.                 $last       = $this->entries->post_count == $post_loop_count ? " post-entry-last " : "";
  380.                 $post_class = "post-entry post-entry-{$the_id} grid-entry-overview grid-loop-{$post_loop_count} grid-parity-{$parity} {$last}";
  381.                 $sort_class = $this->sort_cat_string($the_id, $this->atts);
  382.  
  383.                 switch($linking)
  384.                 {
  385.                     case "lightbox":  $link = wp_get_attachment_image_src(get_post_thumbnail_id($the_id), 'large'); $link = $link[0];   break;
  386.                     default:          $link = get_permalink($the_id); break;
  387.                 }
  388.  
  389.                 $title_link  = get_permalink($the_id);
  390.                 $custom_link = get_post_meta( $the_id ,'_portfolio_custom_link', true) != "" ? get_post_meta( $the_id ,'_portfolio_custom_link_url', true) : false;
  391.  
  392.                 if($custom_link)
  393.                 {
  394.                     $title_link = $link = $custom_link;
  395.                 }
  396.  
  397.                 $excerpt    = '';
  398.                 $title      = '';
  399.  
  400.                 switch($contents)
  401.                 {
  402.                     case "excerpt": $excerpt = $entry->post_excerpt; $title = $entry->post_title; break;
  403.                     case "title": $excerpt = ''; $title = $entry->post_title;  break;
  404.                     case "only_excerpt": $excerpt = $entry->post_excerpt; $title = ''; break;
  405.                     case "no": $excerpt = ''; $title = ''; break;
  406.                 }
  407.  
  408.                 $custom_overlay = apply_filters('avf_portfolio_custom_overlay', "", $entry);
  409.                 $link_markup    = apply_filters('avf_portfolio_custom_image_container', array("a href='{$link}' title='".esc_attr(strip_tags($title))."' ",'a'), $entry);
  410.  
  411.                 $title          = apply_filters('avf_portfolio_title', $title, $entry);
  412.                 $title_link     = apply_filters('avf_portfolio_title_link', $title_link, $entry);
  413.  
  414.                 if($columns == "1" && $one_column_template == 'special')
  415.                 {
  416.                     $extraClass .= ' special_av_fullwidth ';
  417.  
  418.                     $output .= "<div data-ajax-id='{$the_id}' class=' grid-entry flex_column isotope-item all_sort {$style_class} {$post_class} {$sort_class} {$grid} {$extraClass}'>";
  419.                     $output .= "<article class='main_color inner-entry' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup)).">";
  420.                     $output .= apply_filters('avf_portfolio_extra', "", $entry);
  421.  
  422.                     $output .= "<div class='av_table_col first portfolio-entry grid-content'>";
  423.  
  424.                     if(!empty($title))
  425.                     {
  426.                         $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  427.                         $output .= '<header class="entry-content-header">';
  428.                         $output .= "<h2 class='portfolio-grid-title entry-title' $markup><a href='{$title_link}'>".$title."</a></h2>";
  429.                         $output .= '</header>';
  430.                     }
  431.  
  432.                     if(!empty($excerpt))
  433.                     {
  434.                         $markup = avia_markup_helper(array('context' => 'entry_content','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  435.  
  436.                         $output .= "<div class='entry-content-wrapper'>";
  437.                         $output .= "<div class='grid-entry-excerpt entry-content' $markup>".$excerpt."</div>";
  438.                         $output .= "</div>";
  439.                     }
  440.                     $output .= '<div class="avia-arrow"></div>';
  441.                     $output .= "</div>";
  442.  
  443.                     $image = get_the_post_thumbnail( $the_id, $image_size );
  444.                     if(!empty($image))
  445.                     {
  446.                         $output .= "<div class='av_table_col portfolio-grid-image'>";
  447.                         $output .= "<".$link_markup[0]." data-rel='grid-".avia_post_grid::$grid."' class='grid-image avia-hover-fx sss'>".$custom_overlay.$image."</".$link_markup[1].">";
  448.                         $output .= "</div>";
  449.                     }
  450.                     $output .= '<footer class="entry-footer"></footer>';
  451.                     $output .= "</article>";
  452.                     $output .= "</div>";
  453.                 }
  454.                 else
  455.                 {
  456.                     $extraClass .= ' default_av_fullwidth ';
  457.  
  458.  
  459.                     // image patch
  460.                    
  461.                    
  462.                     $output .= '
  463.                    <style>
  464.                    .grid-image img {
  465.                
  466.                    -webkit-transition: opacity 0.2s ease-in-out;
  467.                    -moz-transition: opacity 0.2s ease-in-out;
  468.                    -o-transition: opacity 0.2s ease-in-out;
  469.                    transition: opacity 0.2s ease-in-out;
  470.                  }
  471.                  
  472.                  .grid-image img.top-image:hover {
  473.                    opacity:0;
  474.                  }
  475.                  .top-image{
  476.                    position:absolute;
  477.                    top:0px;
  478.                    left:0px;
  479.                  }
  480.                    </style>
  481.                    ';
  482.                    
  483.                     global $dynamic_featured_image;
  484.                     $out_data = $dynamic_featured_image->get_featured_images($the_id);
  485.                     $image_patch =  '<img  src="'.$out_data[0]['full'].'" class="attachment-no scaling wp-post-image top-image" >'; ;
  486.  
  487.                     $output .= "<div data-ajax-id='{$the_id}' class=' grid-entry flex_column isotope-item all_sort {$style_class} {$post_class} {$sort_class} {$grid} {$extraClass}'>";
  488.                     $output .= "<article class='main_color inner-entry' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup)).">";
  489.                     $output .= apply_filters('avf_portfolio_extra', "", $entry);
  490.                     $output .= "<".$link_markup[0]." data-rel='grid-".avia_post_grid::$grid."' class='grid-image avia-hover-fx fffaaa'>".$custom_overlay.get_the_post_thumbnail( $the_id, $image_size ).$image_patch."</".$link_markup[1].">";
  491.                     $output .= !empty($title) || !empty($excerpt) ? "<div class='grid-content'><div class='avia-arrow'></div>" : '';
  492.  
  493.                     if(!empty($title))
  494.                     {
  495.                         $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  496.                         $output .= '<header class="entry-content-header">';
  497.                         $output .= "<h3 class='grid-entry-title entry-title' $markup><a href='{$title_link}' title='".esc_attr(strip_tags($title))."'>".$title."</a></h3>";
  498.                         $output .= '</header>';
  499.                     }
  500.                     $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>" : '';
  501.                     $output .= !empty($title) || !empty($excerpt) ? "</div>" : '';
  502.                     $output .= '<footer class="entry-footer"></footer>';
  503.                     $output .= "</article>";
  504.                     $output .= "</div>";
  505.                 }
  506.  
  507.  
  508.                 $loop_counter ++;
  509.                 $post_loop_count ++;
  510.                 $extraClass = "";
  511.  
  512.                 if($loop_counter > $columns)
  513.                 {
  514.                     $loop_counter = 1;
  515.                     $extraClass = 'first';
  516.                 }
  517.             }
  518.  
  519.             $output .= "</div>";
  520.  
  521.             //append pagination
  522.             if($paginate == "yes" && $avia_pagination = avia_pagination($this->entries->max_num_pages, 'nav')) $output .= "<div class='pagination-wrap pagination-{$post_type}'>{$avia_pagination}</div>";
  523.  
  524.             return $output;
  525.         }
  526.  
  527.         //generates the html for the sort buttons
  528.         protected function sort_buttons($entries, $params)
  529.         {
  530.             //get all categories that are actually listed on the page
  531.             $categories = get_categories(array(
  532.                 'taxonomy'  => $params['taxonomy'],
  533.                 'hide_empty'=> 0
  534.             ));
  535.  
  536.             $current_page_cats  = array();
  537.             $cat_count          = array();
  538.             $display_cats       = is_array($params['categories']) ? $params['categories'] : array_filter(explode(',',$params['categories']));
  539.  
  540.             foreach ($entries as $entry)
  541.             {
  542.                 if($current_item_cats = get_the_terms( $entry->ID, $params['taxonomy'] ))
  543.                 {
  544.                     if(!empty($current_item_cats))
  545.                     {
  546.                         foreach($current_item_cats as $current_item_cat)
  547.                         {
  548.                             if(empty($display_cats) || in_array($current_item_cat->term_id, $display_cats))
  549.                             {
  550.                                 $current_page_cats[$current_item_cat->term_id] = $current_item_cat->term_id;
  551.  
  552.                                 if(!isset($cat_count[$current_item_cat->term_id] ))
  553.                                 {
  554.                                     $cat_count[$current_item_cat->term_id] = 0;
  555.                                 }
  556.  
  557.                                 $cat_count[$current_item_cat->term_id] ++;
  558.                             }
  559.                         }
  560.                     }
  561.                 }
  562.             }
  563.  
  564.             $output = "<div class='sort_width_container' data-portfolio-id='".avia_post_grid::$grid."' ><div id='js_sort_items' >";
  565.             $hide   = count($current_page_cats) <= 1 ? "hidden" : "";
  566.  
  567.  
  568.             $first_item_name = apply_filters('avf_portfolio_sort_first_label', __('All','avia_framework' ), $params);
  569.             $output .= apply_filters('avf_portfolio_sort_heading', "", $params);
  570.             $output .= "<div class='sort_by_cat {$hide} '>";
  571.             $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>';
  572.  
  573.  
  574.             foreach($categories as $category)
  575.             {
  576.                 if(in_array($category->term_id, $current_page_cats))
  577.                 {
  578.                     //fix for cyrillic, etc. characters - isotope does not support the % char
  579.                     $category->category_nicename = str_replace('%', '', $category->category_nicename);
  580.  
  581.                     $output .=  "<span class='text-sep ".$category->category_nicename."_sort_sep'>/</span>";
  582.                     $output .=      '<a href="#" data-filter="'.$category->category_nicename.'_sort" class="'.$category->category_nicename.'_sort_button" ><span class="inner_sort_button">';
  583.                     $output .=          "<span>".esc_html(trim($category->cat_name))."</span>";
  584.                     $output .=          "<small class='av-cat-count'> ".$cat_count[$category->term_id]." </small></span>";
  585.                     $output .=      "</a>";
  586.                 }
  587.             }
  588.  
  589.             $output .= "</div></div></div>";
  590.  
  591.             return $output;
  592.         }
  593.  
  594.  
  595.         //get the categories for each post and create a string that serves as classes so the javascript can sort by those classes
  596.         protected function sort_cat_string($the_id, $params)
  597.         {
  598.             $sort_classes = "";
  599.             $item_categories = get_the_terms( $the_id, $params['taxonomy']);
  600.  
  601.             if(is_object($item_categories) || is_array($item_categories))
  602.             {
  603.                 foreach ($item_categories as $cat)
  604.                 {
  605.                     //fix for cyrillic, etc. characters - isotope does not support the % char
  606.                     $cat->slug = str_replace('%', '', $cat->slug);
  607.                    
  608.                     $sort_classes .= $cat->slug.'_sort ';
  609.                 }
  610.             }
  611.  
  612.             return $sort_classes;
  613.         }
  614.  
  615.         protected function build_preview_template( $entry )
  616.         {
  617.             if(isset(avia_post_grid::$preview_template[$entry->ID])) return;
  618.             avia_post_grid::$preview_template[$entry->ID] = true;
  619.  
  620.             $id                     = $entry->ID;
  621.             $output                 = "";
  622.             $defaults               = array( 'ids' => get_post_thumbnail_id( $id ), 'text' => apply_filters( 'get_the_excerpt', $entry->post_excerpt) , "method" => 'gallery' , "auto" => "", "columns" => 5);
  623.             $params['ids']          = get_post_meta( $id ,'_preview_ids', true);
  624.             $params['text']         = get_post_meta( $id ,'_preview_text', true);
  625.             $params['method']       = get_post_meta( $id ,'_preview_display', true);
  626.             $params['interval']     = get_post_meta( $id ,'_preview_autorotation', true);
  627.             $params['columns']      = get_post_meta( $id ,'_preview_columns', true);
  628.             $params['preview_size'] = apply_filters('avf_ajax_preview_image_size',"gallery");
  629.             $params['autoplay']     = is_numeric($params['interval']) ? "true" : "false";
  630.  
  631.             $link = get_post_meta( $id ,'_portfolio_custom_link', true) != "" ? get_post_meta( $id ,'_portfolio_custom_link_url', true) : get_permalink($id);
  632.  
  633.  
  634.             //merge default and params array. remove empty params with array_filter
  635.             $params = array_merge($defaults, array_filter($params));
  636.            
  637.             $params = apply_filters('avf_portfolio_preview_template_params', $params, $entry);
  638.  
  639.             //set the content
  640.             $content = str_replace(']]>', ']]&gt;', apply_filters('the_content', $params['text'] )); unset($params['text']);
  641.  
  642.             //set images
  643.             $string = "";
  644.  
  645.             //set first class if preview images are deactivated
  646.             $nogalleryclass = '';
  647.             $params['ajax_request'] = true;
  648.             switch($params['method'])
  649.             {
  650.                 case 'gallery':
  651.  
  652.                     $params['style'] =  "big_thumb";
  653.                     foreach($params as $key => $param) $string .= $key."='".$param."' ";
  654.                     $images = do_shortcode("[av_gallery {$string}]");
  655.                 break;
  656.  
  657.                 case 'slideshow':
  658.                     $params['size'] = $params['preview_size'];
  659.                     foreach($params as $key => $param) $string .= $key."='".$param."' ";
  660.                     $images = do_shortcode("[av_slideshow {$string}]");
  661.                 break;
  662.  
  663.                 case 'list':
  664.                     $images = $this->post_images($params['ids']);
  665.                 break;
  666.  
  667.                 case 'no':
  668.                     $images = false;
  669.                     $nogalleryclass = ' no_portfolio_preview_gallery ';
  670.                 break;
  671.             }
  672.  
  673.             $output .= "<div class='ajax_slide ajax_slide_{$id}' data-slide-id='{$id}' >";
  674.  
  675.                 $output .= "<article class='inner_slide $nogalleryclass' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$id, 'custom_markup'=>$this->atts['custom_markup'])).">";
  676.  
  677.                 if(!empty($images))
  678.                 {
  679.                     $output .= "<div class='av_table_col first portfolio-preview-image'>";
  680.                     $output .= $images;
  681.                     $output .= "</div>";
  682.                 }
  683.  
  684.                 if(!empty($nogalleryclass)) $nogalleryclass .= ' first ';
  685.  
  686.                     $output .= "<div class='av_table_col $nogalleryclass portfolio-entry portfolio-preview-content'>";
  687.  
  688.                         $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$id, 'custom_markup'=>$this->atts['custom_markup']));
  689.                         $output .= '<header class="entry-content-header">';
  690.                         $output .= "<h2 class='portfolio-preview-title entry-title' $markup><a href='{$link}'>".$entry->post_title."</a></h2>";
  691.                         $output .= '</header>';
  692.  
  693.                         $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'])).">";
  694.                         $output .= $content;
  695.                         $output .= "</div>";
  696.                         $output .= "<span class='avia-arrow'></span>";
  697.                     $output .= "</div>";
  698.  
  699.                 $output .= '<footer class="entry-footer"></footer>';
  700.                 $output .= "</article>";
  701.  
  702.             $output .= "</div>";
  703.  
  704.         return "<script type='text/html' id='avia-tmpl-portfolio-preview-{$id}'>\n{$output}\n</script>\n\n";
  705.  
  706.         }
  707.  
  708.         protected function post_images($ids)
  709.         {
  710.             if(empty($ids)) return;
  711.  
  712.             $attachments = get_posts(array(
  713.                 'include' => $ids,
  714.                 'post_status' => 'inherit',
  715.                 'post_type' => 'attachment',
  716.                 'post_mime_type' => 'image',
  717.                 'order' => 'ASC',
  718.                 'orderby' => 'post__in')
  719.                 );
  720.  
  721.             $output = "";
  722.  
  723.             foreach($attachments as $attachment)
  724.             {
  725.                 $img     = wp_get_attachment_image_src($attachment->ID, 'large');
  726.  
  727.                 $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
  728.                 $alt = !empty($alt) ? esc_attr($alt) : '';
  729.                 $title = trim($attachment->post_title) ? esc_attr($attachment->post_title) : "";
  730.                 $description = trim($attachment->post_content) ? esc_attr($attachment->post_content) : "";
  731.  
  732.                 $output .= " <a href='".$img[0]."' class='portolio-preview-list-image' title='".$description."' ><img src='".$img[0]."' title='".$title."' alt='".$alt."' /></a>";
  733.             }
  734.  
  735.             return $output;
  736.         }
  737.  
  738.  
  739.  
  740.  
  741.         public function print_preview_templates()
  742.         {
  743.             foreach ($this->entries->posts as $entry)
  744.             {
  745.                 echo $this->build_preview_template( $entry );
  746.             }
  747.         }
  748.  
  749.  
  750.  
  751.         //fetch new entries
  752.         public function query_entries($params = array())
  753.         {
  754.             $query = array();
  755.             if(empty($params)) $params = $this->atts;
  756.  
  757.             if(!empty($params['categories']))
  758.             {
  759.                 //get the portfolio categories
  760.                 $terms  = explode(',', $params['categories']);
  761.             }
  762.  
  763.             $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' );
  764.             if(!$page || $params['paginate'] == 'no') $page = 1;
  765.  
  766.             //if we find categories perform complex query, otherwise simple one
  767.             if(isset($terms[0]) && !empty($terms[0]) && !is_null($terms[0]) && $terms[0] != "null")
  768.             {
  769.                 $query = array( 'orderby'   => 'post_date',
  770.                                 'order'     => 'DESC',
  771.                                 'paged'     => $page,
  772.                                 'posts_per_page' => $params['items'],
  773.                                 'post_type' => $params['post_type'],
  774.                                 'tax_query' => array(   array(  'taxonomy'  => $params['taxonomy'],
  775.                                                                 'field'     => 'id',
  776.                                                                 'terms'     => $terms,
  777.                                                                 'operator'  => 'IN')));
  778.             }
  779.             else
  780.             {
  781.                 $query = array( 'paged'=> $page, 'posts_per_page' => $params['items'], 'post_type' => $params['post_type']);
  782.             }
  783.  
  784.             $query = apply_filters('avia_post_grid_query', $query, $params);
  785.  
  786.             $this->entries = new WP_Query( $query );
  787.  
  788.         }
  789.  
  790.  
  791.         //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.
  792.         //Shortcode uses the query_entries function above
  793.         public function use_global_query()
  794.         {
  795.             global $wp_query;
  796.             $this->entries = $wp_query;
  797.         }
  798.  
  799.  
  800.  
  801.     }
  802. }
  803.  
  804.  
  805. /*
  806. Example: how to order posts randomly on page load. put this into functions.php
  807.  
  808. add_filter('avia_post_grid_query','avia_order_by_random');
  809. function avia_order_by_random($query)
  810. {
  811.     $query['orderby'] = 'rand';
  812.     return $query;
  813. }
  814. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement