Advertisement
Guest User

Themler Post SLider

a guest
Nov 16th, 2016
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.88 KB | None | 0 0
  1. /**
  2.     * Plugin Name: Bootstrap Carousel 2x Post Widget
  3.     * Plugin URI: http://plugin.bdwebteam.com/bootstrap-carousel-2x-post-widget
  4.     * Description: Adds a widget that shows the most recent posts of your site with excerpt, featured image by sorting & ordering feature
  5.     * Author: Mahabub Hasan
  6.     * Author URI: http://bdwebteam.com/
  7.     * Version: 1.0.1
  8.     * Text Domain: bdwebteam
  9.     * Domain Path: /languages
  10.     * License: MIT License
  11.     * License URI: http://opensource.org/licenses/MIT
  12. */
  13.  
  14. /**
  15.    *
  16.    * @package   bootstrap-carousel-2x-post-widget
  17.    * @author    Md. Mahabub Masan Manik <m.manik01@gmail.com>
  18.    * @license   MIT License
  19.    * @link      http://plugin.bdwebteam.com/bootstrap-carousel-2x-post-widget
  20.    * @copyright 2015 Mahabub Hasan
  21.    *
  22.  */
  23.  
  24.  
  25. if ( ! defined( 'WPINC' ) ) {
  26.     die;
  27. }
  28. if (!defined('PLUGIN_ROOT')) {
  29.     define('PLUGIN_ROOT', dirname(__FILE__) . '/');
  30.     define('PLUGIN_NAME', basename(dirname(__FILE__)) . '/' . basename(__FILE__));
  31. }
  32. if (! defined ( 'WP_CONTENT_URL' ))
  33.     define ( 'WP_CONTENT_URL', get_option ( 'siteurl' ) . '/wp-content' );
  34. if (! defined ( 'WP_CONTENT_DIR' ))
  35.     define ( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
  36. if (! defined ( 'WP_PLUGIN_URL' ))
  37.     define ( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' );
  38.     add_action('widgets_init', create_function('', 'return register_widget("bootstrap_carousel_2x_post");'));
  39. class bootstrap_carousel_2x_post extends WP_Widget {
  40.              
  41.     //  @var string (The plugin version)       
  42.     var $version = '1.0.1';
  43.     //  @var string $localizationDomain (Domain used for localization)
  44.     var $localizationDomain = 'bdwebteam';
  45.     //  @var string $pluginurl (The url to this plugin)
  46.     var $pluginurl = '';
  47.     //  @var string $pluginpath (The path to this plugin)      
  48.     var $pluginpath = '';  
  49.  
  50.     function bootstrap_carousel_2x_post() {
  51.         $this->__construct();
  52.     }
  53.    
  54.     function __construct() {
  55.         $name = dirname ( plugin_basename ( __FILE__ ) );
  56.         $this->pluginurl = WP_PLUGIN_URL . "/$name/";
  57.         $this->pluginpath = WP_PLUGIN_DIR . "/$name/";
  58.         // add_action ( 'wp_print_styles', array (&$this, 'bdwebteam_carousel_2x_post_css' ) );
  59.        
  60.         $widget_ops = array ('classname' => 'bdwebteam-carousel-2x-post-widget', 'description' => __ ( 'Show recent posts from selected category. Includes advanced options.', $this->localizationDomain ) );
  61.         $this->WP_Widget ( 'bdwebteam-carousel-2x-post-widget', __ ( 'bdwebteam-carousel-2x-post-widget', $this->localizationDomain ), $widget_ops );
  62.     }  
  63.     function bdwebteam_carousel_2x_post_css() {
  64.         $name = "bdwebteam-carousel-2x-post-widget.css";
  65.         if (false !== @file_exists ( TEMPLATEPATH . "/$name" )) {
  66.             $css = get_template_directory_uri () . "/$name";
  67.         } else {
  68.             $css = $this->pluginurl . $name;
  69.         }
  70.         wp_enqueue_style ( 'bdwebteam-carousel-2x-post-widget', $css, false, $this->version, 'screen' );
  71.     }  
  72.     function widget($args, $instance) {
  73.         extract( $args );
  74.         $instance['title']?NULL:$instance['title']='';
  75.          $widget_id = $this->id = $widget_id;        
  76.        $post_type='post';    
  77.            
  78.         $cat_id=$instance['posts_cat_id'];
  79.         $cat_name= get_cat_name( $cat_id );
  80.         $category_link = get_category_link($cat_id);
  81.         $title = apply_filters('widget_title',$instance['title']);
  82.         $output = $before_widget."\n";  
  83.     $output .= '<div class="panel  panel-warning carousel-2x-post top-border">';
  84.    
  85.     if($instance['x_header']=='1'):
  86.         $output .= '<div class="panel-heading">';
  87.         if($title) {
  88.             $output .= '<a href="'.$instance['title_url'].'" class="pull-right x-view-all"><i class="icon-lines fa fa-dashcube"></i> View all</a> <h4> '. $title.'</h4>'.$after_title;
  89.         } elseif($cat_id) {
  90.             $output .= '<a  style="color:'.$borderTopColor.'" href="'.$category_link.'" class="pull-right x-view-all"><i class="icon-lines fa fa-dashcube"></i> View all</a> <h4> '. $cat_name.'</h4>';
  91.         }
  92.         else{
  93.  
  94.             $output .= '<a style="color:'.$borderTopColor.'" href="#" class="pull-right x-view-all"><i class="icon-lines fa fa-dashcube"></i> View all</a> <h4>  bdwebteam Carousel 2x Post Widget</h4>';
  95.         }
  96.       $output .='</div>';
  97.       endif;
  98.      
  99.         ob_start();
  100.         $posts = new WP_Query( array(
  101.             'post_type'     => array($post_type),
  102.             'showposts'     => $instance['posts_num'],
  103.             'cat'           => $instance['posts_cat_id'],
  104.             'ignore_sticky_posts'   => true,
  105.             'orderby'       => $instance['posts_orderby'],
  106.             'order'         => 'dsc',
  107.             'date_query' => array(
  108.                 array(
  109.                     'after' => $instance['posts_time'],
  110.                 ),
  111.             ),
  112.         ) );        
  113.         $output .= '<div class="panel-body">';        
  114.         $output .= '<div id="carousel-example-generic'.$widget_id.'" class="carousel slide carousel-fade" data-ride="carousel">';          
  115.          $count_data = 0;
  116.          
  117.          if($instance['pagination']=='1'):
  118.          $output .= '<ol class="carousel-indicators">';
  119.         while ($posts->have_posts()): $posts->the_post();                            
  120.                 $count_data++;
  121.                 $active = ($count_data == 1 ? 'active' : '');            
  122.                 $output .= '<li data-target="#carousel-example-generic'.$widget_id.'" data-slide-to="'.($count_data -1).'" class="'.$active.'"></li>';
  123.             endwhile;            
  124.             $output .= '</ol>';
  125.             endif;
  126.             $output .= '<div class="carousel-inner">';
  127.             $count_data_info = 0;            
  128.             while ($posts->have_posts()): $posts->the_post();
  129.             $show_title_limit=$instance['word_posts_title'];
  130.                 $post_title = get_the_title(get_the_ID($post->ID));
  131.                 $trimmed_title = wp_trim_words( $post_title,$show_title_limit);
  132.                 $post_permalink=get_the_permalink(get_the_ID($post->ID));
  133.                 $author_posts_url=get_author_posts_url(get_the_author_meta('ID'));
  134.                 $the_author=get_the_author(get_the_ID($post->ID));              
  135.                 $show_content_limit=$instance['word_posts_content'];
  136.                 $content = get_the_content(get_the_ID($post->ID));
  137.                 $trimmed_content = wp_trim_words( $content,$show_content_limit);
  138.             $count_data_info++;
  139.             $active = ($count_data_info == 1 ? 'active' : '');  
  140.                 $output .= '<div class="item ' .$active.'">';                                  
  141.                    $trainer_thumb   = get_post_thumbnail_id($post->ID);
  142.                     $trainer_img_url = wp_get_attachment_url( $trainer_thumb,'carousel-large' );
  143.                        
  144.                         if ( has_post_thumbnail() ):
  145.                             $output .= '<img src="'. $trainer_img_url. '" alt="' .$title .'" />';  
  146.                        endif;                      
  147.                     $output .= '<div class="header-text hidden-xs">';
  148.                          
  149.                          $output .= '<div class="text-center">';                            
  150.                             if($instance['posts_title']=='1'):
  151.                             $output .= '<h2>';
  152.                                 $output .= '<span>'.$trimmed_title.'</span>';
  153.                             $output .= '</h2>';
  154.                             endif;
  155.                             $output .= '<br>';
  156.                              if($instance['posts_content']=='1'):  
  157.                             $output .= '<p>';                            
  158.                                 $output .= '<span>'.$trimmed_content.'</span>';
  159.                             $output .= '</p>';
  160.                             endif;
  161.                             $output .= '<br>';
  162.                             if($instance['x-read-more']=='1'):                            
  163.                             $output .= '<div class="">';
  164.                                $output .= ' <a class="btn btn-theme btn-sm btn-min-block x-read-more" href="#">Read more</a></div>';
  165.                                endif;
  166.                         $output .= '</div>';
  167.                        
  168.                     $output .= '</div><!-- /header-text -->';
  169.                 $output .= '</div>';               
  170.        
  171.         endwhile;
  172.             $output .= '</div>';
  173.                 if($instance['navigation']=='1'):      
  174.                     $output .= '<a class="icon-arrow-angle-left left carousel-control" href="#carousel-example-generic'.$widget_id.'" data-slide="prev">';
  175.                     $output .= '<i class="fa fa-caret-left"></i>';
  176.                     $output .= '</a>';
  177.                     $output .= '<a class="icon-arrow-angle-right right carousel-control" href="#carousel-example-generic'.$widget_id.'" data-slide="next">';
  178.                     $output .= '<i class="fa fa-caret-right"></i>';
  179.                     $output .= '</a>';
  180.                 endif;            
  181.         $output .= '</div><!-- /carousel --> ';
  182.     $output .= '</div>';
  183.         $output .= ob_get_clean();
  184.         $output .= $after_widget."\n";
  185.         echo $output;
  186.     }
  187.  
  188. /*  Widget update
  189. /* ------------------------------------ */
  190.     public function update($new,$old) {
  191.         $instance = $old;
  192.         $instance['title'] = strip_tags($new['title']);        
  193.         $instance['title_url'] = strip_tags($new['title_url']);        
  194.         $instance['posts_title'] = $new['posts_title']?1:0;
  195.         $instance['word_posts_title'] = strip_tags($new['word_posts_title']);
  196.         $instance['posts_content'] = $new['posts_content']?1:0;        
  197.         $instance['word_posts_content'] = strip_tags($new['word_posts_content']);        
  198.         $instance['posts_cat_id'] = strip_tags($new['posts_cat_id']);
  199.         $instance['posts_orderby'] = strip_tags($new['posts_orderby']);
  200.         $instance['navigation'] = $new['navigation']?1:0;
  201.         $instance['pagination'] = $new['pagination']?1:0;
  202.          $instance['x-read-more-txt'] = strip_tags($new['x-read-more-txt']);
  203.         $instance['x-read-more'] = $new['x-read-more']?1:0;
  204.         $instance['x_header'] = $new['x_header']?1:0;
  205.         $instance['posts_time'] = strip_tags($new['posts_time']);  
  206.          $instance['posts_num'] = strip_tags($new['posts_num']);    
  207.      
  208.         return $instance;
  209.     }
  210.  
  211. /*  Widget form
  212. /* ------------------------------------ */
  213.     public function form($instance) {
  214.         $bordercolor         = esc_attr($instance['bordercolor']);
  215.         // Default widget settings
  216.         $defaults = array(
  217.             'title'              => '',
  218.             'title_url'    => '',
  219.              'posts_title'   => '1',
  220.                 'word_posts_title' => '20',
  221.             'posts_content'      => '1',
  222.                 'word_posts_content' => '20',
  223.             'posts_num'          => '5',            
  224.             'posts_cat_id'       => '0',
  225.             'posts_orderby'      => 'date',
  226.             'show_date'          => '1',
  227.             'navigation'         => '1',  
  228.             'pagination'         => '1',
  229.             'x-read-more-txt'   =>  'Read More',
  230.             'x-read-more'        => '1',
  231.             'x_header'           => '1',
  232.             'posts_time'         => '0',
  233.            
  234.         );
  235.         $instance = wp_parse_args( (array) $instance, $defaults );
  236. ?>
  237.    
  238.     <div class="bdwebteam_carousel_2x_post-options-posts">
  239.         <p style="padding-right: 0;">
  240.             <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title :', 'bdwebteam'); ?></label>
  241.             <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($instance["title"]); ?>" />
  242.         </p>          
  243.         <p>
  244.             <label for="<?php echo $this->get_field_id('title_url'); ?>"><?php _e('Title URL :', 'bdwebteam'); ?></label>
  245.             <input class="widefat" id="<?php echo $this->get_field_id('title_url'); ?>" name="<?php echo $this->get_field_name('title_url'); ?>" type="text" value="<?php echo esc_attr($instance["title_url"]); ?>"  placeholder="<?php echo esc_attr( 'http://test.com/cat' ); ?>" />
  246.         </p>  
  247.         <p>
  248.             <input type="checkbox" class="checkbox checkboxcontent" id="<?php echo $this->get_field_id('posts_title'); ?>" name="<?php echo $this->get_field_name('posts_title'); ?>" <?php checked( (bool) $instance["posts_title"], true ); ?>>
  249.             <label for="<?php echo $this->get_field_id('posts_title'); ?>"><?php _e('Show Posts Title:', 'bdwebteam'); ?></label>
  250.         </p>
  251.         <p style="padding-left: 20px;" class="content_show_box">
  252.             <label style="width: 55%; display: inline-block;" for="<?php echo $this->get_field_id("word_posts_title"); ?>"><?php _e('Words to show:', 'bdwebteam'); ?></label>
  253.             <input style="width:20%;" id="<?php echo $this->get_field_id("word_posts_title"); ?>" name="<?php echo $this->get_field_name("word_posts_title"); ?>" type="text" value="<?php echo absint($instance["word_posts_title"]); ?>" size='3' />
  254.         </p>
  255.         <hr />
  256.         <p>
  257.             <input type="checkbox" class="checkbox checkboxcontent" id="<?php echo $this->get_field_id('posts_content'); ?>" name="<?php echo $this->get_field_name('posts_content'); ?>" <?php checked( (bool) $instance["posts_content"], true ); ?>>
  258.             <label for="<?php echo $this->get_field_id('posts_content'); ?>"><?php _e('Posts Content:', 'bdwebteam'); ?></label>
  259.         </p>
  260.         <p style="padding-left: 20px;" class="content_show_box">
  261.             <label style="width: 55%; display: inline-block;" for="<?php echo $this->get_field_id("word_posts_content"); ?>"><?php _e('Words to show:', 'bdwebteam'); ?></label>
  262.             <input style="width:20%;" id="<?php echo $this->get_field_id("word_posts_content"); ?>" name="<?php echo $this->get_field_name("word_posts_content"); ?>" type="text" value="<?php echo absint($instance["word_posts_content"]); ?>" size='3' />
  263.         </p>
  264.          <hr />
  265.         <p class="img_show_box">
  266.             <label style="width: 55%; display: inline-block;" for="<?php echo $this->get_field_id("posts_num"); ?>"><?php _e('Items to show:', 'bdwebteam'); ?></label>
  267.             <input style="width:20%;" id="<?php echo $this->get_field_id("posts_num"); ?>" name="<?php echo $this->get_field_name("posts_num"); ?>" type="text" value="<?php echo absint($instance["posts_num"]); ?>" size='3' />
  268.         </p>        
  269.              <hr />
  270.         <p>
  271.             <label style="width: 100%; display: inline-block;" for="<?php echo $this->get_field_id("posts_cat_id"); ?>"><?php _e('Category:', 'bdwebteam'); ?></label>
  272.             <?php wp_dropdown_categories( array( 'name' => $this->get_field_name("posts_cat_id"), 'selected' => $instance["posts_cat_id"], 'show_option_all' => 'All', 'show_count' => true ) ); ?>    
  273.         </p>
  274.         <p style="padding-top: 0.3em;">
  275.             <label style="width: 100%; display: inline-block;" for="<?php echo $this->get_field_id("posts_orderby"); ?>"><?php _e('Order by:', 'bdwebteam'); ?></label>
  276.             <select style="width: 100%;" id="<?php echo $this->get_field_id("posts_orderby"); ?>" name="<?php echo $this->get_field_name("posts_orderby"); ?>">
  277.               <option value="date"<?php selected( $instance["posts_orderby"], "date" ); ?>><?php _e('Most recent', 'bdwebteam'); ?></option>
  278.               <option value="comment_count"<?php selected( $instance["posts_orderby"], "comment_count" ); ?>><?php _e('Most commented', 'bdwebteam'); ?></option>
  279.               <option value="rand"<?php selected( $instance["posts_orderby"], "rand" ); ?>><?php _e('Random', 'bdwebteam'); ?></option>
  280.             </select>  
  281.         </p>
  282.         <p style="padding-top: 0.3em;">
  283.             <label style="width: 100%; display: inline-block;" for="<?php echo $this->get_field_id("posts_time"); ?>"><?php _e('Posts from:', 'bdwebteam'); ?></label>
  284.             <select style="width: 100%;" id="<?php echo $this->get_field_id("posts_time"); ?>" name="<?php echo $this->get_field_name("posts_time"); ?>">
  285.               <option value="0"<?php selected( $instance["posts_time"], "0" ); ?>><?php _e('All time', 'bdwebteam'); ?></option>
  286.               <option value="1 year ago"<?php selected( $instance["posts_time"], "1 year ago" ); ?>><?php _e('This year', 'bdwebteam'); ?></option>
  287.               <option value="1 month ago"<?php selected( $instance["posts_time"], "1 month ago" ); ?>><?php _e('This month', 'bdwebteam'); ?></option>
  288.               <option value="1 week ago"<?php selected( $instance["posts_time"], "1 week ago" ); ?>><?php _e('This week', 'bdwebteam'); ?></option>
  289.               <option value="1 day ago"<?php selected( $instance["posts_time"], "1 day ago" ); ?>><?php _e('Past 24 hours', 'bdwebteam'); ?></option>
  290.             </select>  
  291.         </p>       
  292.         <p>
  293.             <input type="checkbox" class="checkbox checkboxcontent" id="<?php echo $this->get_field_id('navigation'); ?>" name="<?php echo $this->get_field_name('navigation'); ?>" <?php checked( (bool) $instance["navigation"], true ); ?>>
  294.             <label for="<?php echo $this->get_field_id('navigation'); ?>"><?php _e('Navigation On/Off:', 'bdwebteam'); ?></label>
  295.         </p>
  296.          <p>
  297.             <input type="checkbox" class="checkbox checkboxcontent" id="<?php echo $this->get_field_id('pagination'); ?>" name="<?php echo $this->get_field_name('pagination'); ?>" <?php checked( (bool) $instance["pagination"], true ); ?>>
  298.             <label for="<?php echo $this->get_field_id('pagination'); ?>"><?php _e('Pagination On/Off:', 'bdwebteam'); ?></label>
  299.         </p>
  300.         <p>
  301.             <input type="checkbox" class="checkbox checkboxcontent" id="<?php echo $this->get_field_id('x-read-more'); ?>" name="<?php echo $this->get_field_name('x-read-more'); ?>" <?php checked( (bool) $instance["x-read-more"], true ); ?>>
  302.             <label for="<?php echo $this->get_field_id('x-read-more'); ?>"><?php _e('Read More On/Off:', 'bdwebteam'); ?></label>
  303.         </p>
  304.          <p class="img_show_box">
  305.             <label style="width: 55%; display: inline-block;" for="<?php echo $this->get_field_id("x-read-more-txt"); ?>"><?php _e('Read More Text:', 'bdwebteam'); ?></label>
  306.             <input style="width:20%;" id="<?php echo $this->get_field_id("x-read-more-txt"); ?>" name="<?php echo $this->get_field_name("x-read-more-txt"); ?>" type="text" value="<?php echo absint($instance["x-read-more-txt"]); ?>" size='3' />
  307.         </p>    
  308.         <p>
  309.             <input type="checkbox" class="checkbox checkboxcontent" id="<?php echo $this->get_field_id('x_header'); ?>" name="<?php echo $this->get_field_name('x_header'); ?>" <?php checked( (bool) $instance["x_header"], true ); ?>>
  310.             <label for="<?php echo $this->get_field_id('x_header'); ?>"><?php _e('X Header On/Off:', 'bdwebteam'); ?></label>
  311.         </p>
  312.     </div>
  313. <?php
  314.     }
  315. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement