Guest User

Untitled

a guest
Jan 9th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.96 KB | None | 0 0
  1. class avia_newsbox extends WP_Widget {
  2.  
  3.     var $avia_term = '';
  4.     var $avia_post_type = '';
  5.     var $avia_new_query = '';
  6.  
  7.     function __construct()
  8.     {
  9.         $widget_ops = array('classname' => 'newsbox', 'description' => __('A Sidebar widget to display latest post entries in your sidebar', 'avia_framework') );
  10.  
  11.         parent::__construct( 'newsbox', THEMENAME.' Latest News', $widget_ops );
  12.     }
  13.  
  14.     function widget($args, $instance)
  15.     {
  16.         global $avia_config;
  17.  
  18.         extract($args, EXTR_SKIP);
  19.         echo $before_widget;
  20.  
  21.         $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
  22.         $count = empty($instance['count']) ? '' : $instance['count'];
  23.         $cat = empty($instance['cat']) ? '' : $instance['cat'];
  24.         $excerpt = empty($instance['excerpt']) ? '' : $instance['excerpt'];
  25.         $image_size = isset($avia_config['widget_image_size']) ? $avia_config['widget_image_size'] : 'widget';
  26.  
  27.         if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
  28.  
  29.  
  30.         if(empty($this->avia_term))
  31.         {
  32.             $additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count);
  33.         }
  34.         else
  35.         {
  36.             $catarray = explode(',', $cat);
  37.  
  38.  
  39.             if(empty($catarray[0]))
  40.             {
  41.                 $new_query = array("posts_per_page"=>$count,"post_type"=>$this->avia_post_type);
  42.             }
  43.             else
  44.             {
  45.                 if($this->avia_new_query)
  46.                 {
  47.                     $new_query = $this->avia_new_query;
  48.                 }
  49.                 else
  50.                 {
  51.                     $new_query = array( "posts_per_page"=>$count, 'tax_query' => array(
  52.                                                     array( 'taxonomy' => $this->avia_term,
  53.                                                             'field' => 'id',
  54.                                                             'terms' => explode(',', $cat),
  55.                                                             'operator' => 'IN')
  56.                                                             )
  57.                                                     );
  58.                 }
  59.             }
  60.  
  61.             $additional_loop = new WP_Query($new_query);
  62.         }
  63.  
  64.         if($additional_loop->have_posts()) :
  65.  
  66.  
  67.  
  68.         echo '<ul class="news-wrap image_size_'.$image_size.'">';
  69.         while ($additional_loop->have_posts()) : $additional_loop->the_post();
  70.  
  71.         $format = "";
  72.         if(empty($this->avia_post_type))    $format = $this->avia_post_type;
  73.         if(empty($format))                  $format = get_post_format();
  74.         if(empty($format))                  $format = 'standard';
  75.        
  76.         $the_id = get_the_ID();
  77.         $link = get_post_meta( $the_id  ,'_portfolio_custom_link', true) != "" ? get_post_meta( $the_id ,'_portfolio_custom_link_url', true) : get_permalink();
  78.        
  79.        
  80.         echo '<li class="news-content post-format-'.$format.'">';
  81.  
  82.         //check for preview images:
  83.         $image = "";
  84.  
  85.         if(!current_theme_supports('force-post-thumbnails-in-widget'))
  86.         {
  87.             $slides = avia_post_meta(get_the_ID(), 'slideshow', true);
  88.  
  89.             if( $slides != "" && !empty( $slides[0]['slideshow_image'] ) )
  90.             {
  91.                 $image = avia_image_by_id($slides[0]['slideshow_image'], $image_size, 'image');
  92.             }
  93.         }
  94.  
  95.         if(current_theme_supports( 'post-thumbnails' ) && !$image )
  96.         {
  97.             $image = get_the_post_thumbnail( $the_id, $image_size );
  98.         }
  99.  
  100.         $time_format = apply_filters( 'avia_widget_time', get_option('date_format')." - ".get_option('time_format'), 'avia_newsbox' );
  101.  
  102.  
  103.         echo "<a class='news-link' title='".get_the_title()."' href='".$link."'>";
  104.  
  105.         $nothumb = (!$image) ? 'no-news-thumb' : '';
  106.  
  107.         echo "<span class='news-thumb $nothumb'>";
  108.         echo $image;
  109.         echo "</span>";
  110.         if(empty($avia_config['widget_image_size']) || 'display title and excerpt' != $excerpt)
  111.         {
  112.             echo "<strong class='news-headline'>".get_the_title();
  113.            
  114.             if($time_format)
  115.             {
  116.                 echo "<span class='news-time'>".get_post_meta(get_the_ID(), 'event_date', true)."</span>";
  117.             }
  118.            
  119.             echo "</strong>";
  120.         }
  121.         echo "</a>";
  122.  
  123.         if( 'display title and excerpt' == $excerpt )
  124.         {
  125.             echo "<div class='news-excerpt'>";
  126.  
  127.             if(!empty($avia_config['widget_image_size']))
  128.             {
  129.                 echo "<a class='news-link-inner' title='".get_the_title()."' href='".$link."'>";
  130.                 echo "<strong class='news-headline'>".get_the_title()."</strong>";
  131.                 echo "</a>";
  132.                 if($time_format)
  133.                 {
  134.                     echo "<span class='news-time'>".get_post_meta(get_the_ID(), 'event_date', true)."</span>";
  135.                 }
  136.  
  137.             }
  138.             the_excerpt();
  139.             echo "</div>";
  140.         }
  141.  
  142.         echo '</li>';
  143.  
  144.  
  145.         endwhile;
  146.         echo "</ul>";
  147.         wp_reset_postdata();
  148.         endif;
  149.  
  150.  
  151.         echo $after_widget;
  152.  
  153.     }
  154.  
  155.  
  156.     function update($new_instance, $old_instance)
  157.     {
  158.         $instance = $old_instance;
  159.         $instance['title'] = strip_tags($new_instance['title']);
  160.         $instance['count'] = strip_tags($new_instance['count']);
  161.         $instance['excerpt'] = strip_tags($new_instance['excerpt']);
  162.         $instance['cat'] = implode(',',$new_instance['cat']);
  163.         return $instance;
  164.     }
  165.  
  166.  
  167.  
  168.     function form($instance)
  169.     {
  170.         $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => '', 'cat' => '', 'excerpt'=>'' ) );
  171.         $title = strip_tags($instance['title']);
  172.         $count = strip_tags($instance['count']);
  173.         $excerpt = strip_tags($instance['excerpt']);
  174.  
  175.  
  176.         $elementCat = array("name"  => __("Which categories should be used for the portfolio?", 'avia_framework'),
  177.                             "desc"  => __("You can select multiple categories here", 'avia_framework'),
  178.                             "id"    => $this->get_field_name('cat')."[]",
  179.                             "type"  => "select",
  180.                             "std"   => strip_tags($instance['cat']),
  181.                             "class" => "",
  182.                             "multiple"=>6,
  183.                             "subtype" => "cat");
  184.         //check if a different taxonomy than the default is set
  185.         if(!empty($this->avia_term))
  186.         {
  187.             $elementCat['taxonomy'] = $this->avia_term;
  188.         }
  189.  
  190.  
  191.  
  192.  
  193.         $html = new avia_htmlhelper();
  194.  
  195. ?>
  196.         <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'avia_framework'); ?>
  197.         <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
  198.  
  199.         <p>
  200.             <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('How many entries do you want to display: ', 'avia_framework'); ?></label>
  201.             <select class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>">
  202.                 <?php
  203.                 $list = "";
  204.                 for ($i = 1; $i <= 20; $i++ )
  205.                 {
  206.                     $selected = "";
  207.                     if($count == $i) $selected = 'selected="selected"';
  208.  
  209.                     $list .= "<option $selected value='$i'>$i</option>";
  210.                 }
  211.                 $list .= "</select>";
  212.                 echo $list;
  213.                 ?>
  214.  
  215.  
  216.         </p>
  217.  
  218.         <p><label for="<?php echo $this->get_field_id('cat'); ?>"><?php _e('Choose the categories you want to display (multiple selection possible):', 'avia_framework'); ?>
  219.         <?php echo $html->select($elementCat); ?>
  220.         </label></p>
  221.  
  222.         <p>
  223.             <label for="<?php echo $this->get_field_id('excerpt'); ?>"><?php _e('Display title only or title &amp; excerpt', 'avia_framework'); ?></label>
  224.             <select class="widefat" id="<?php echo $this->get_field_id('excerpt'); ?>" name="<?php echo $this->get_field_name('excerpt'); ?>">
  225.                 <?php
  226.                 $list = "";
  227.                 $answers = array(
  228.                             'show title only'           =>  __( 'show title only', 'avia_framework' ),
  229.                             'display title and excerpt' =>  __('display title and excerpt', 'avia_framework')
  230.                             );
  231.                
  232.                 foreach ( $answers as $key => $answer )
  233.                 {
  234.                     $selected = "";
  235.                     if( $key == $excerpt ) $selected = 'selected="selected"';
  236.  
  237.                     $list .= "<option $selected value='$key'>$answer</option>";
  238.                 }
  239.                 $list .= "</select>";
  240.                 echo $list;
  241.                 ?>
  242.  
  243.  
  244.         </p>
  245.  
  246.  
  247. <?php
  248.     }
  249. }
Advertisement
Add Comment
Please, Sign In to add comment