Advertisement
cipher87

Magazine

Mar 14th, 2019
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 26.80 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Magazine
  4.  *
  5.  * Display entries in a magazine like fashion
  6.  * Element is in Beta and by default disabled. Todo: test with layerslider elements. currently throws error bc layerslider is only included if layerslider element is detected which is not the case with the post/page element
  7.  */
  8. if ( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  9.  
  10.  
  11. if ( !class_exists( 'avia_sc_magazine' ))
  12. {
  13.     class avia_sc_magazine extends aviaShortcodeTemplate
  14.     {
  15.  
  16.         /**
  17.          * Create the config array for the shortcode button
  18.          */
  19.         function shortcode_insert_button()
  20.         {
  21.             $this->config['self_closing']   =   'yes';
  22.            
  23.             $this->config['name']       = __('Magazine', 'avia_framework' );
  24.             $this->config['tab']        = __('Content Elements', 'avia_framework' );
  25.             $this->config['icon']       = AviaBuilder::$path['imagesURL']."sc-magazine.png";
  26.             $this->config['order']      = 39;
  27.             $this->config['target']     = 'avia-target-insert';
  28.             $this->config['shortcode']  = 'av_magazine';
  29.             $this->config['tooltip']    = __('Display entries in a magazine like fashion', 'avia_framework' );
  30.             $this->config['drag-level'] = 3;
  31.             $this->config['preview']    = 1;
  32.             $this->config['disabling_allowed'] = true;
  33.         }
  34.        
  35.         function extra_assets()
  36.         {
  37.             //load css
  38.             wp_enqueue_style( 'avia-module-magazine' , AviaBuilder::$path['pluginUrlRoot'].'avia-shortcodes/magazine/magazine.css' , array('avia-layout'), false );
  39.            
  40.             //load js
  41.             wp_enqueue_script( 'avia-module-magazine' , AviaBuilder::$path['pluginUrlRoot'].'avia-shortcodes/magazine/magazine.js' , array('avia-shortcodes'), false, TRUE );
  42.  
  43.        
  44.         }
  45.  
  46.         /**
  47.          * Popup Elements
  48.          *
  49.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  50.          * opens a modal window that allows to edit the element properties
  51.          *
  52.          * @return void
  53.          */
  54.         function popup_elements()
  55.         {
  56.             $this->elements = array(
  57.                 array(
  58.                             "type"  => "tab_container", 'nodescription' => true
  59.                         ),
  60.                        
  61.                 array(
  62.                         "type"  => "tab",
  63.                         "name"  => __("Content" , 'avia_framework'),
  64.                         'nodescription' => true
  65.                     ),
  66.                    
  67.                 array(
  68.                         "name"  => __("Which Entries?", 'avia_framework' ),
  69.                         "desc"  => __("Select which entries should be displayed by selecting a taxonomy", 'avia_framework' ),
  70.                         "id"    => "link",
  71.                         "fetchTMPL" => true,
  72.                         "type"  => "linkpicker",
  73.                         "subtype"  => array( __('Display Entries from:',  'avia_framework' )=>'taxonomy'),
  74.                         "multiple"  => 6,
  75.                         "std"   => "category"
  76.                 ),
  77.                
  78.                 array(
  79.                         "name"  => __("Number of entries", 'avia_framework' ),
  80.                         "desc"  => __("How many entries should be displayed?", 'avia_framework' ),
  81.                         "id"    => "items",
  82.                         "type"  => "select",
  83.                         "std"   => "5",
  84.                         "subtype" => AviaHtmlHelper::number_array(1,40,1, array('All'=>'-1'))),
  85.                
  86.                 array(
  87.                         "name"  => __("Offset Number", 'avia_framework' ),
  88.                         "desc"  => __("The offset determines where the query begins pulling posts. Useful if you want to remove a certain number of posts because you already query them with another blog or magazine element.", 'avia_framework' ),
  89.                         "id"    => "offset",
  90.                         "type"  => "select",
  91.                         "std"   => "0",
  92.                         "subtype" => AviaHtmlHelper::number_array(1,100,1, array(__('Deactivate offset','avia_framework')=>'0', __('Do not allow duplicate posts on the entire page (set offset automatically)', 'avia_framework' ) =>'no_duplicates'))),
  93.  
  94.  
  95.                
  96.                 array( 
  97.                         "name"  => __("Display Tabs for each category selected above?", 'avia_framework' ),
  98.                         "desc"  => __("If checked and you have selected more than one taxonomy above, a tab will be displayed for each of them", 'avia_framework' ) ."</small>" ,
  99.                         "id"    => "tabs",
  100.                         "std"   => "true",
  101.                         "type"  => "checkbox"),
  102.                
  103.                
  104.                 array( 
  105.                         "name"  => __("Display Thumbnails?", 'avia_framework' ),
  106.                         "desc"  => __("If checked all entries that got a feature image will show it", 'avia_framework' ) ."</small>" ,
  107.                         "id"    => "thumbnails",
  108.                         "std"   => "true",
  109.                         "type"  => "checkbox"),
  110.                
  111.                 array( 
  112.                         "name"  => __("Display Element Heading?", 'avia_framework' ),
  113.                         "desc"  => __("If checked you can enter a title with link for this element", 'avia_framework' ) ."</small>" ,
  114.                         "id"    => "heading_active",
  115.                         "std"   => "",
  116.                         "type"  => "checkbox"),
  117.                
  118.                 array( 
  119.                         "name"  => __("Heading Text", 'avia_framework' ),
  120.                         "id"    => "heading",
  121.                         "required"=> array('heading_active','not',''),
  122.                         "std"   => "",
  123.                         "type"  => "input"),
  124.                        
  125.                 array( 
  126.                         "name"  => __("Heading Link?", 'avia_framework' ),
  127.                         "desc"  => __("Where should the heading link to?", 'avia_framework' ),
  128.                         "id"    => "heading_link",
  129.                         "type"  => "linkpicker",
  130.                         "required"=> array('heading_active','not',''),
  131.                         "fetchTMPL" => true,
  132.                         "subtype" => array(
  133.                                             __('Set Manually', 'avia_framework' ) =>'manually',
  134.                                             __('Single Entry', 'avia_framework' ) =>'single',
  135.                                             __('Taxonomy Overview Page',  'avia_framework' ) =>'taxonomy',
  136.                                             ),
  137.                         "std"   => ""),
  138.                
  139.                 array( 
  140.                             "name"  => __("Heading Area Color", 'avia_framework' ),
  141.                             "desc"  => __("Choose a color for your heading area here", 'avia_framework' ),
  142.                             "id"    => "heading_color",
  143.                             "type"  => "select",
  144.                             "std"   => "theme-color",
  145.                             "required"=> array('heading_active','not',''),
  146.                             "subtype" => array(
  147.                                                 __('Theme Color', 'avia_framework' )=>'theme-color',
  148.                                                 __('Blue', 'avia_framework' )=>'blue',
  149.                                                 __('Red',  'avia_framework' )=>'red',
  150.                                                 __('Green', 'avia_framework' )=>'green',
  151.                                                 __('Orange', 'avia_framework' )=>'orange',
  152.                                                 __('Aqua', 'avia_framework' )=>'aqua',
  153.                                                 __('Teal', 'avia_framework' )=>'teal',
  154.                                                 __('Purple', 'avia_framework' )=>'purple',
  155.                                                 __('Pink', 'avia_framework' )=>'pink',
  156.                                                 __('Silver', 'avia_framework' )=>'silver',
  157.                                                 __('Grey', 'avia_framework' )=>'grey',
  158.                                                 __('Black', 'avia_framework' )=>'black',
  159.                                                 __('Custom Color', 'avia_framework' )=>'custom',
  160.                                                 )),
  161.                        
  162.                     array( 
  163.                             "name"  => __("Custom Font Color", 'avia_framework' ),
  164.                             "desc"  => __("Select a custom font color for your Heading area here", 'avia_framework' ),
  165.                             "id"    => "heading_custom_color",
  166.                             "type"  => "colorpicker",
  167.                             "std"   => "#ffffff",
  168.                             "required" => array('heading_color','equals','custom')
  169.                         ), 
  170.                
  171.                
  172.                 array( 
  173.                         "name"  => __("Should the first entry be displayed bigger?", 'avia_framework' ),
  174.                         "desc"  => __("If checked the first entry will stand out with big image", 'avia_framework' ) ."</small>" ,
  175.                         "id"    => "first_big",
  176.                         "std"   => "",
  177.                         "type"  => "checkbox"),
  178.                
  179.                 array(
  180.                         "name"  => __("First entry position", 'avia_framework' ),
  181.                         "desc"  => __("Where do you want to display the first entry?", 'avia_framework' ),
  182.                         "id"    => "first_big_pos",
  183.                         "type"  => "select",
  184.                         "std"   => "top",
  185.                         "required"=> array('first_big','not',''),
  186.                         "subtype" => array( __('Display the first entry at the top of the others','avia_framework' ) =>'top',
  187.                                             __('Display the first entry beside the others','avia_framework' ) =>'left')),
  188.                
  189.                
  190.                
  191.                 array(
  192.                             "type"  => "close_div",
  193.                             'nodescription' => true
  194.                         ),
  195.                        
  196.                        
  197.                                 array(
  198.                                     "type"  => "tab",
  199.                                     "name"  => __("Screen Options",'avia_framework' ),
  200.                                     'nodescription' => true
  201.                                 ),
  202.                                
  203.                                
  204.                                 array(
  205.                                 "name"  => __("Element Visibility",'avia_framework' ),
  206.                                 "desc"  => __("Set the visibility for this element, based on the device screensize.", 'avia_framework' ),
  207.                                 "type"  => "heading",
  208.                                 "description_class" => "av-builder-note av-neutral",
  209.                                 ),
  210.                            
  211.                                 array( 
  212.                                         "desc"  => __("Hide on large screens (wider than 990px - eg: Desktop)", 'avia_framework'),
  213.                                         "id"    => "av-desktop-hide",
  214.                                         "std"   => "",
  215.                                         "container_class" => 'av-multi-checkbox',
  216.                                         "type"  => "checkbox"),
  217.                                
  218.                                 array( 
  219.                                    
  220.                                         "desc"  => __("Hide on medium sized screens (between 768px and 989px - eg: Tablet Landscape)", 'avia_framework'),
  221.                                         "id"    => "av-medium-hide",
  222.                                         "std"   => "",
  223.                                         "container_class" => 'av-multi-checkbox',
  224.                                         "type"  => "checkbox"),
  225.                                        
  226.                                 array( 
  227.                                    
  228.                                         "desc"  => __("Hide on small screens (between 480px and 767px - eg: Tablet Portrait)", 'avia_framework'),
  229.                                         "id"    => "av-small-hide",
  230.                                         "std"   => "",
  231.                                         "container_class" => 'av-multi-checkbox',
  232.                                         "type"  => "checkbox"),
  233.                                        
  234.                                 array( 
  235.                                    
  236.                                         "desc"  => __("Hide on very small screens (smaller than 479px - eg: Smartphone Portrait)", 'avia_framework'),
  237.                                         "id"    => "av-mini-hide",
  238.                                         "std"   => "",
  239.                                         "container_class" => 'av-multi-checkbox',
  240.                                         "type"  => "checkbox"),
  241.                                    
  242.                                
  243.                              
  244.                
  245.                            
  246.                                
  247.                             array(
  248.                                     "type"  => "close_div",
  249.                                     'nodescription' => true
  250.                                 ), 
  251.                                
  252.                                
  253.                        
  254.                        
  255.                     array(
  256.                         "type"  => "close_div",
  257.                         'nodescription' => true
  258.                     ),
  259.                
  260.                
  261.  
  262.  
  263.                 );
  264.            
  265.             if(current_theme_supports('add_avia_builder_post_type_option'))
  266.             {
  267.                 $element = array(
  268.                 "name"  => __("Select Post Type", 'avia_framework' ),
  269.                 "desc"  => __("Select which post types should be used. Note that your taxonomy will be ignored if you do not select an assign post type.
  270.                           If you don't select post type all registered post types will be used", 'avia_framework' ),
  271.                 "id"    => "post_type",
  272.                 "type"  => "select",
  273.                 "multiple"  => 6,
  274.                 "std"   => "",
  275.                 "subtype" => AviaHtmlHelper::get_registered_post_type_array()
  276.                 );
  277.  
  278.                 array_splice($this->elements, 2, 0, array($element));
  279.             }
  280.            
  281.         }
  282.  
  283.         /**
  284.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  285.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  286.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  287.          *
  288.          *
  289.          * @param array $params this array holds the default values for $content and $args.
  290.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  291.          */
  292.         function editor_element($params)
  293.         {
  294.             $params['innerHtml'] = "<img src='".$this->config['icon']."' title='".$this->config['name']."' />";
  295.             $params['innerHtml'].= "<div class='avia-element-label'>".$this->config['name']."</div>";
  296.             $params['content']   = NULL; //remove to allow content elements
  297.             return $params;
  298.         }
  299.  
  300.  
  301.  
  302.         /**
  303.          * Frontend Shortcode Handler
  304.          *
  305.          * @param array $atts array of attributes
  306.          * @param string $content text within enclosing form of shortcode element
  307.          * @param string $shortcodename the shortcode found, when == callback name
  308.          * @return string $output returns the modified html string
  309.          */
  310.         function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  311.         {
  312.            
  313.             $atts['class'] = $meta['el_class'];
  314.             $atts['custom_markup'] = $meta['custom_markup'];
  315.  
  316.             $mag = new avia_magazine($atts);
  317.             $mag -> query_entries();
  318.             return $mag->html();
  319.            
  320.         }
  321.  
  322.     }
  323. }
  324.  
  325.  
  326.  
  327.  
  328.  
  329. if ( !class_exists( 'avia_magazine' ) )
  330. {
  331.     class avia_magazine
  332.     {
  333.         static  $magazine = 0;
  334.         protected $atts;
  335.         protected $entries;
  336.        
  337.         function __construct($atts = array())
  338.         {  
  339.             $this->screen_options = AviaHelper::av_mobile_sizes($atts);
  340.            
  341.             self::$magazine += 1;
  342.             $this->atts = shortcode_atts(array( 'class'                 => '',
  343.                                                 'custom_markup'         => "",
  344.                                                 'items'                 => '16',
  345.                                                 'tabs'                  => false,
  346.                                                 'thumbnails'            => true,
  347.                                                 'heading_active'        => false,
  348.                                                 'heading'               => "",
  349.                                                 'heading_link'          => "",
  350.                                                 'heading_color'         => "",
  351.                                                 'heading_custom_color'  => "",
  352.                                                 'first_big'             => false,
  353.                                                 'first_big_pos'         => 'top',
  354.                                                 'taxonomy'              => 'category',
  355.                                                 'link'                  => '',
  356.                                                 'categories'            => array(),
  357.                                                 'extra_categories'      => array(),
  358.                                 'post_type'         => array(),
  359.                                                 'offset'                => 0,
  360.                                                 'image_size'            => array( 'small'=> 'thumbnail', 'big' => 'magazine')
  361.                                                
  362.                                                 ), $atts, 'av_magazine');
  363.  
  364.             // fetch the taxonomy and the taxonomy ids
  365.             $this->extract_terms();                                    
  366.            
  367.             //convert checkbox to true/false
  368.             $this->atts['tabs'] = $this->atts['tabs'] === "aviaTBtabs" ? true : false;
  369.             $this->atts['thumbnails'] = $this->atts['thumbnails'] === "aviaTBthumbnails" ? true : false;
  370.            
  371.            
  372.             //filter the attributes
  373.             $this->atts = apply_filters('avf_magazine_settings', $this->atts, self::$magazine);
  374.            
  375.             //set small or big
  376.             if(empty($this->atts['first_big'])) $this->atts['first_big_pos'] = "";
  377.            
  378.             //set heading text
  379.             if(empty($this->atts['heading_active'])) $this->atts['heading'] = "";
  380.            
  381.             //set if top bar is active
  382.             $this->atts['top_bar'] = !empty($this->atts['heading']) || !empty($this->atts['tabs'])  ? "av-magazine-top-bar-active" : "";
  383.         }
  384.        
  385.         function extract_terms()
  386.         {
  387.             if(isset($this->atts['link']))
  388.             {
  389.                 $this->atts['link'] = explode(',', $this->atts['link'], 2 );
  390.                 $this->atts['taxonomy'] = $this->atts['link'][0];
  391.  
  392.                 if(isset($this->atts['link'][1]))
  393.                 {
  394.                     $this->atts['categories'] = $this->atts['link'][1];
  395.                 }
  396.                 else
  397.                 {
  398.                     $this->atts['categories'] = array();
  399.                 }
  400.             }
  401.         }
  402.        
  403.         function sort_buttons()
  404.         {
  405.             $term_args = array(
  406.                                 'taxonomy'      => $this->atts['taxonomy'],
  407.                                 'hide_empty'    => true
  408.                             );
  409.             /**
  410.              * To display private posts you need to set 'hide_empty' to false,
  411.              * otherwise a category with ONLY private posts will not be returned !!
  412.              *
  413.              * You also need to add post_status "private" to the query params with filter avf_magazine_entries_query.
  414.              *
  415.              * @since 4.4.2
  416.              * @added_by Günter
  417.              * @param array $term_args
  418.              * @param string $context
  419.              * @return array
  420.              */
  421.             $term_args = apply_filters( 'avf_av_magazine_term_args', $term_args, 'sort_button' );
  422.                
  423.             $sort_terms = AviaHelper::get_terms( $term_args );
  424.            
  425.             $current_page_terms = array();
  426.             $term_count         = array();
  427.             $display_terms      = is_array($this->atts['categories']) ? $this->atts['categories'] : array_filter(explode(',',$this->atts['categories']));
  428.  
  429.             $output = "<div class='av-magazine-sort ' data-magazine-id='".self::$magazine."' >";
  430.            
  431.             $first_item_name = apply_filters('avf_magazine_sort_first_label', __('All','avia_framework' ), $this->atts);
  432.             $output .= "<div class='av-sort-by-term'>";
  433.             $output .= '<a href="#" data-filter="sort_all" class="all_sort_button active_sort"><span class="inner_sort_button"><span>'.$first_item_name.'</span></span></a>';
  434.  
  435.             foreach($sort_terms as $term)
  436.             {  
  437.                 if (!in_array($term->term_id, $display_terms)) continue;
  438.                
  439.                 if(!isset($term_count[$term->term_id])) $term_count[$term->term_id] = 0;
  440.                 $term->slug = str_replace('%', '', $term->slug);
  441.                
  442.                 $output .=  "<span class='text-sep {$term->slug}_sort_sep'>/</span>";
  443.                 $output .=  '<a href="#" data-filter="sort_'.$term->term_id.'" class="'.$term->slug.'_sort_button " ><span class="inner_sort_button">';
  444.                 $output .=      "<span>".esc_html(trim($term->name))."</span>";
  445.                 $output .=      "</span>";
  446.                 $output .=  "</a>";
  447.                
  448.                 $this->atts['extra_categories'][] = $term->term_id;
  449.             }
  450.  
  451.             $output .= "</div></div>";
  452.            
  453.             if(count($this->atts['extra_categories']) <= 1) return "";
  454.            
  455.             return $output;
  456.        
  457.        
  458.         }
  459.        
  460.         //fetch new entries
  461.         public function query_entries($params = array(), $return = false)
  462.         {
  463.             global $avia_config;
  464.  
  465.             if(empty($params)) $params = $this->atts;
  466.  
  467.             if(empty($params['custom_query']))
  468.             {
  469.                 $query = array();
  470.  
  471.                 if(!empty($params['categories']))
  472.                 {
  473.                     //get the portfolio categories
  474.                     $terms  = explode(',', $params['categories']);
  475.                 }
  476.  
  477.                 $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' );
  478.                 if(!$page ) $page = 1;
  479.  
  480.                 //if we find no terms for the taxonomy fetch all taxonomy terms
  481.                 if(empty($terms[0]) || is_null($terms[0]) || $terms[0] === "null")
  482.                 {
  483.                     $term_args = array(
  484.                                 'taxonomy'      => $params['taxonomy'],
  485.                                 'hide_empty'    => true
  486.                             );
  487.                     /**
  488.                      * To display private posts you need to set 'hide_empty' to false,
  489.                      * otherwise a category with ONLY private posts will not be returned !!
  490.                      *
  491.                      * You also need to add post_status "private" to the query params with filter avf_magazine_entries_query.
  492.                      *
  493.                      * @since 4.4.2
  494.                      * @added_by Günter
  495.                      * @param array $term_args
  496.                      * @param string $context
  497.                      * @return array
  498.                      */
  499.                     $term_args = apply_filters( 'avf_av_magazine_term_args', $term_args, 'query_entries' );
  500.  
  501.                     $allTax = AviaHelper::get_terms( $term_args );
  502.  
  503.                     $terms = array();
  504.                     foreach( $allTax as $tax )
  505.                     {
  506.                         $terms[] = $tax->term_id;
  507.                     }
  508.                 }
  509.                
  510.                 if($params['offset'] == 'no_duplicates')
  511.                 {
  512.                     $params['offset'] = 0;
  513.                     if(empty($params['ignore_dublicate_rule'])) $no_duplicates = true;
  514.                 }
  515.                
  516.                
  517.                
  518.                     if(empty($params['post_type'])) $params['post_type'] = get_post_types();
  519.                     if(is_string($params['post_type'])) $params['post_type'] = explode(',', $params['post_type']);
  520.                                    
  521.                     $query = array( 'orderby'   => 'date',
  522.                                     'order'     => 'DESC',
  523.                                     'paged'     => $page,
  524.                                     'post_type' => $params['post_type'],
  525.                                     'post__not_in' => (!empty($no_duplicates)) ? $avia_config['posts_on_current_page'] : array(),
  526.                                     'offset'    => $params['offset'],
  527.                                     'posts_per_page' => $params['items'],
  528.                                     'tax_query' => array(   array(  'taxonomy'  => $params['taxonomy'],
  529.                                                                     'field'     => 'id',
  530.                                                                     'terms'     => $terms,
  531.                                                                     'operator'  => 'IN')));
  532.                
  533.                    
  534.                                                                
  535.                    
  536.             }
  537.             else
  538.             {
  539.                 $query = $params['custom_query'];
  540.             }
  541.  
  542.  
  543.             $query   = apply_filters('avf_magazine_entries_query', $query, $params);
  544.             $entries = get_posts( $query );
  545.            
  546.             if(!empty($entries) && empty($params['ignore_dublicate_rule']))
  547.             {
  548.                 foreach($entries as $entry)
  549.                 {
  550.                      $avia_config['posts_on_current_page'][] = $entry->ID;
  551.                 }
  552.             }
  553.            
  554.             if($return)
  555.             {
  556.                 return $entries;
  557.             }
  558.             else
  559.             {
  560.                 $this->entries = $entries;
  561.             }
  562.         }
  563.        
  564.         function html()
  565.         {
  566.             $output = "";
  567.             $class  = !empty($this->atts['first_big_pos'])   ? " av-magazine-hero-".$this->atts['first_big_pos'] : "";
  568.             $class  .= " ".$this->atts['top_bar'];
  569.             if(!empty($this->atts['tabs'])) $class  .= " av-magazine-tabs-active";
  570.            
  571.            
  572.             extract($this->screen_options); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  573.            
  574.            
  575.             $output .= "<div id='av-magazine-".self::$magazine."' class='av-magazine {$av_display_classes} ".$this->atts['class']." {$class}' >";
  576.            
  577.             if($this->atts['top_bar'])
  578.             {  
  579.                 $link    = AviaHelper::get_url($this->atts['heading_link']);
  580.                 $heading = $this->atts['heading'];
  581.                 $b_class = "";
  582.                 $b_style = "";
  583.                
  584.                 if($this->atts['heading_color'] != "theme-color")
  585.                 {
  586.                     if($this->atts['heading_color'] == "custom") $b_style = "style='color: ".$this->atts['heading_custom_color'].";'";
  587.                     $b_class .= "avia-font-color-".$this->atts['heading_color']." avia-inherit-font-color";
  588.                 }
  589.                
  590.                 $output .= "<div class='av-magazine-top-bar {$b_class}' {$b_style}>";
  591.                
  592.                 if($heading)
  593.                 {
  594.                     $output .= "<a href='{$link}' class='av-magazine-top-heading'>{$heading}</a>";
  595.                 }
  596.                
  597.                 if(!empty($this->atts['tabs']))
  598.                 {
  599.                     $output .= $this->sort_buttons();
  600.                 }
  601.                
  602.                 $output .="</div>";
  603.             }
  604.            
  605.            
  606.             //magazine main loop
  607.             $output .= $this->magazine_loop($this->entries);
  608.            
  609.            
  610.             //magazine sub loops
  611.             $output .= $this->magazine_sub_loop();
  612.            
  613.            
  614.             $output .="</div>";
  615.             return $output;
  616.         }
  617.        
  618.        
  619.         function magazine_sub_loop()
  620.         {
  621.             $output = "";
  622.            
  623.             if(!empty($this->atts['extra_categories']) && count($this->atts['extra_categories']) > 1)
  624.             {
  625.                 foreach($this->atts['extra_categories'] as $category)
  626.                 {
  627.                     $params = $this->atts;
  628.                     $params['ignore_dublicate_rule'] = true;
  629.                     $params['categories'] = $category;
  630.                     $params['sort_var'] = $category;       
  631.                    
  632.                     $entries = $this->query_entries($params, true);
  633.                     $output .= $this->magazine_loop($entries, $params);
  634.                    
  635.                 }
  636.             }
  637.            
  638.             return $output;
  639.         }
  640.        
  641.        
  642.        
  643.        
  644.         function magazine_loop($entries, $params = array())
  645.         {
  646.             $output = "";
  647.             $loop   = 0;
  648.             $grid   = $this->atts['first_big_pos'] == "left" ? "flex_column av_one_half " : "";
  649.             $html   = !empty($this->atts['first_big_pos'])   ? array("before"=>"<div class='av-magazine-hero first {$grid}'>","after"=>'</div>') : array("before"=>'',"after"=>'');
  650.             $css    = empty($params['sort_var']) ? "sort_all" : "av-hidden-mag sort_".$params['sort_var'];
  651.            
  652.             if(!empty($entries))
  653.             {
  654.                 $output .= "<div class='av-magazine-group {$css}'>";
  655.            
  656.                 foreach($entries as $entry)
  657.                 {
  658.                     $loop ++;
  659.                     $entry->loop = $loop;
  660.                    
  661.                     $style = ($loop === 1 && !empty($this->atts['first_big'])) ? "big" : "small";
  662.                     if($loop == 2 && !empty($html['before'])) $html = array("before"=>"<div class='av-magazine-sideshow {$grid}'>","after"=>'');
  663.                     if($loop == 3) $html = array("before"=>'',"after"=>'');
  664.                    
  665.                    
  666.                     $output .= $html['before'];
  667.                     $output .= $this->render_entry($entry, $style);
  668.                     $output .= $html['after'];
  669.                 }
  670.                
  671.                 if($loop !== 1 && !empty($this->atts['first_big_pos'])) $output .= "</div>";
  672.                
  673.                 $output .= "</div>";
  674.             }
  675.            
  676.             return $output;
  677.         }
  678.        
  679.        
  680.        
  681.         function render_entry($entry, $style)
  682.         {
  683.                
  684.             $output         = "";
  685.             $image          = get_the_post_thumbnail( $entry->ID, $this->atts['image_size'][$style] );
  686.             $link           = get_post_meta( $entry->ID ,'_portfolio_custom_link', true ) != "" ? get_post_meta( $entry->ID ,'_portfolio_custom_link_url', true ) : get_permalink( $entry->ID );
  687.             $titleAttr      = "title='".__('Link to:','avia_framework')." ".the_title_attribute(array('echo' => 0, 'post' => $entry->ID))."'";
  688.             $title          = "<a href='{$link}' {$titleAttr}>". apply_filters( 'avf_magazine_title', get_the_title( $entry->ID ), $entry ) ."</a>";
  689.             $titleTag       = "h3";
  690.             $excerpt        = "";
  691.             $time           = get_the_time(get_option('date_format'), $entry->ID);
  692.             $separator      = "<span class='av-magazine-text-sep text-sep-date'>/</span>";
  693.            
  694.             $author_link    = get_author_posts_url($entry->post_author);
  695.             $author_name    = apply_filters('avf_author_name', get_the_author_meta('display_name', $entry->post_author), $entry->post_author);
  696.             $author         = '<a href='.$author_link.' title="'.__('by','avia_framework').' '.$author_name.'" rel="author">'.$author_name.'</a>';
  697.             $author_output  = '<span class="av-magazine-author minor-meta">'.__('by','avia_framework')." ";
  698.             $author_output .= '<span class="av-magazine-author-link" '.avia_markup_helper(array('context' => 'author_name','echo'=>false)).'>';
  699.             $author_output .= "<span class='av-magazine-author meta-color vcard author'><span class='fn'>";
  700.             $author_output .= $author;
  701.             $author_output .= '</span></span>';
  702.             $author_output .= '</span>';
  703.             $author_output .= '</span>';
  704.  
  705.             $markupEntry    = avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$entry->ID, 'custom_markup'=>$this->atts['custom_markup']));
  706.             $markupTitle    = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$entry->ID, 'custom_markup'=>$this->atts['custom_markup']));
  707.             $markupContent  = avia_markup_helper(array('context' => 'entry_content','echo'=>false, 'id'=>$entry->ID, 'custom_markup'=>$this->atts['custom_markup']));
  708.             $markupTime     = avia_markup_helper(array('context' => 'entry_time','echo'=>false, 'id'=>$entry->ID, 'custom_markup'=>$this->atts['custom_markup']));
  709.             $format         = get_post_format($entry->ID) ? get_post_format($entry->ID) : 'standard';
  710.             $type           = get_post_type($entry->ID);
  711.             $icontype       = $type == 'post' ?  $format : $type;
  712.             $icon           =  "<a href='{$link}' {$titleAttr} class='iconfont av-magazine-entry-icon' ".av_icon_string($icontype)."></a>";
  713.             $extraClass     = "";
  714.            
  715.             if($style == 'small')
  716.             {
  717.                 if(empty($this->atts['thumbnails']))
  718.                 {
  719.                      $image = "";
  720.                      $extraClass = "av-magazine-no-thumb";
  721.                 }
  722.             }
  723.  
  724.             $permalink = '<div class="read-more-link"><a href="'.get_permalink($entry->ID).'" class="more-link">'.__('Read more','avia_framework').'<span class="more-link-arrow"></span></a></div>';
  725.             $excerpt = !empty($entry->post_excerpt) ? $entry->post_excerpt : avia_backend_truncate($entry->post_content, apply_filters( 'avf_magazine_excerpt_length' , 60) , apply_filters( 'avf_magazine_excerpt_delimiter' , " "), "…", true, '');    
  726.            
  727.             $output .= "<article class='hentry av-magazine-entry av-magazine-entry-id-".$entry->ID." av-magazine-format-{$format} av-magazine-type-{$type} av-magazine-entry-".$entry->loop." av-magazine-entry-".$style." {$extraClass}' {$markupEntry}>";
  728.            
  729.             if($this->atts['thumbnails'] || ($style == 'big' && $image))
  730.             {
  731.                             $output .="<div class='av-magazine-thumbnail'>";
  732.                 if($image)  $output .="<a href='{$link}' {$titleAttr} class='av-magazine-thumbnail-link '>{$image}</a>";
  733.                 if(!$image) $output .= $icon;
  734.                             $output .="</div>";
  735.             }
  736.        
  737.             $output .=      "<div class='av-magazine-content-wrap'>";
  738.             $output .=      "<header class='entry-content-header'>";
  739.             $output .=          "<time class='av-magazine-time updated' {$markupTime}>".$time."</time>";
  740.             $output .=          $separator.$author_output;
  741.             $output .=          "<{$titleTag} class='av-magazine-title entry-title' {$markupTitle}>{$title}</{$titleTag}>";
  742.             $output .=      "</header>";
  743.             $output .=      "<div class='av-magazine-content entry-content' {$markupContent}>{$excerpt}</div>";
  744.             $output .=      "<div class='av-magazine-read-more'>{$permalink}</div>";
  745.             $output .=      "</div>";
  746.             $output .=      "<footer class='entry-footer'></footer>";
  747.             $output .= "</article>";
  748.            
  749.             return $output;
  750.         }
  751.     }
  752. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement