function widget($args, $instance)
    {
        wp_enqueue_script('jquery-isotope');
        $cache = wp_cache_get('widget_popular_videos', 'widget');
        if (!is_array($cache)) {
            $cache = array();
        }
        if (!isset($argsxx['widget_id'])) {
            $argsxx['widget_id'] = $this->id;
        }
        if (isset($cache[$argsxx['widget_id']])) {
            echo $cache[$argsxx['widget_id']];
            return;
        }
        ob_start();
        extract($args);
        $conditions = empty($instance['conditions']) ? '' : $instance['conditions'];
        $show_likes = empty($instance['show_likes']) ? '' : $instance['show_likes'];
        $show_com = empty($instance['show_com']) ? '' : $instance['show_com'];
        $show_view = empty($instance['show_view']) ? '' : $instance['show_view'];
        $show_rate = empty($instance['show_rate']) ? '' : $instance['show_rate'];
        $show_excerpt = empty($instance['show_excerpt']) ? '' : $instance['show_excerpt'];
        $num_ex = empty($instance['num_ex']) ? '' : $instance['num_ex'];
        $ids = empty($instance['ids']) ? '' : $instance['ids'];
        $title = empty($instance['title']) ? '' : $instance['title'];
        $title = apply_filters('widget_title', $title);
        $link = empty($instance['link']) ? '' : $instance['link'];
        $sort_by = empty($instance['sort_by']) ? '' : $instance['sort_by'];
        $number = empty($instance['number']) ? '' : $instance['number'];
        $thumb = empty($instance['thumb']) ? '' : $instance['thumb'];
        $thumb_w = empty($instance['thumb_w']) ? '' : $instance['thumb_w'];
        $thumb_h = empty($instance['thumb_h']) ? '' : $instance['thumb_h'];
        $cates = empty($instance['cats']) ? '' : $instance['cats'];
        if ($link != '') {
            $before_title .= '<a href=' . $link . '>';
            $after_title = '</a>' . $after_title;
        }
        if (function_exists('ot_get_option')) {
            $themes_pur = ot_get_option('theme_purpose');
        }
        if ($conditions == 'most_liked' && $ids == '' && class_exists('CT_ContentHelper')) {
            global $wpdb;
            $show_count = 1;
            $time_range = 'all';
            //$show_type = $instance['show_type'];
            $order_by = 'ORDER BY like_count DESC, post_title';
            if ($number > 0) {
                $limit = "LIMIT " . $number;
            }
            $widget_data = $before_widget;
            $widget_data .= $before_title . $title . $after_title;
            $show_excluded_posts = get_option('wti_like_post_show_on_widget');
            $excluded_post_ids = explode(',', get_option('wti_like_post_excluded_posts'));
            if (!$show_excluded_posts && count($excluded_post_ids) > 0) {
                $where = "AND post_id NOT IN (" . get_option('wti_like_post_excluded_posts') . ")";
            }
            //getting the most liked posts
            $query = "SELECT post_id, SUM(value) AS like_count, post_title FROM `{$wpdb->prefix}wti_like_post` L, {$wpdb->prefix}posts P ";
            $query .= "WHERE L.post_id = P.ID AND post_status = 'publish' AND value > -1 {$where} GROUP BY post_id {$order_by} {$limit}";
            $posts = $wpdb->get_results($query);
            $item_loop_video = new CT_ContentHtml();
            $cates_ar = $cates;
            if (count($posts) > 0) {
                $widget_data .= '
			<div class="widget-content">
					<div class="list-rating-item row">';
                foreach ($posts as $post) {
                    $cat_cur = get_the_category($post->post_id);
                    $cat_s = $cat_cur[0]->cat_ID;
                    $p_data = $excerpt = '';
                    $post_title = stripslashes($post->post_title);
                    $permalink = get_permalink($post->post_id);
                    $like_count = $post->like_count;
                    $p_data = get_post($post->post_id);
                    $excerpt = strip_tags($p_data->post_content);
                    $excerpt = wp_trim_words($excerpt, $num_ex, $more = '');
                    if ($cates != '') {
                        foreach ($cates_ar as $categs) {
                            if ($categs == $cat_s) {
                                $widget_data .= $item_loop_video->tm_likes_html($post, $like_count, $themes_pur, $show_likes, $show_com, $show_rate, $show_view, $show_excerpt, $excerpt);
                            }
                        }
                    } else {
                        $widget_data .= $item_loop_video->tm_likes_html($post, $like_count, $themes_pur, $show_likes, $show_com, $show_rate, $show_view, $show_excerpt, $excerpt);
                    }
                }
                //$widget_data .= $show_count == '1' ? ' ('.$like_count.')' : '';
                $widget_data .= '</div>
			</div>';
            }
            $widget_data .= $after_widget;
            echo $widget_data;
            wp_reset_postdata();
            $cache[$argsxx['widget_id']] = ob_get_flush();
            wp_cache_set('widget_trending_videos', $cache, 'widget');
        } else {
            if (class_exists('CT_ContentHelper')) {
                $item_loop_video = new CT_ContentHelper();
                $tag = $categories = '';
                if ($ids == '') {
                    $categories = $cates;
                }
                $the_query = $item_loop_video->tm_get_popular_posts($conditions, $tag, $number, $ids, $sort_by, $categories, $args = array(), $themes_pur);
                //			if(count($cats) > 0){
                //				$args = array('category__in' => $cats, 'showposts' => $number);
                //			}
                $html = $before_widget;
                if ($title) {
                    $html .= $before_title . $title . $after_title;
                }
                if ($the_query->have_posts()) {
                    $html .= '
					<div class="widget-content">
					<div class="list-rating-item row">
				';
                    $i = 0;
                    $item_video = new CT_ContentHtml();
                    while ($the_query->have_posts()) {
                        $the_query->the_post();
                        $i++;
                        $excerpt = get_the_excerpt();
                        $excerpt = wp_trim_words($excerpt, $num_ex, $more = '');
                        $html .= $item_video->get_item_video_trending($conditions, $themes_pur, $show_likes, $show_com, $show_rate, $show_view, $show_excerpt, $excerpt);
                    }
                    $html .= '</div>
				</div>';
                }
                $html .= $after_widget;
                echo $html;
                wp_reset_postdata();
                $cache[$argsxx['widget_id']] = ob_get_flush();
                wp_cache_set('widget_popular_videos', $cache, 'widget');
            }
        }
    }
    function widget($args, $instance)
    {
        wp_enqueue_script('jquery-isotope');
        $cache = wp_cache_get('widget_trending_videos', 'widget');
        if (!is_array($cache)) {
            $cache = array();
        }
        if (!isset($argsxx['widget_id'])) {
            $argsxx['widget_id'] = $this->id;
        }
        if (isset($cache[$argsxx['widget_id']])) {
            echo $cache[$argsxx['widget_id']];
            return;
        }
        ob_start();
        extract($args);
        $conditions = empty($instance['conditions']) ? '' : $instance['conditions'];
        $title = empty($instance['title']) ? '' : $instance['title'];
        $title = apply_filters('widget_title', $title);
        $number = empty($instance['number']) ? '' : $instance['number'];
        $timerange = empty($instance['timerange']) ? '' : $instance['timerange'];
        $show_likes = empty($instance['show_likes']) ? '' : $instance['show_likes'];
        $show_com = empty($instance['show_com']) ? '' : $instance['show_com'];
        $link = empty($instance['link']) ? '' : $instance['link'];
        $show_view = empty($instance['show_view']) ? '' : $instance['show_view'];
        $show_rate = empty($instance['show_rate']) ? '' : $instance['show_rate'];
        $show_excerpt = empty($instance['show_excerpt']) ? '' : $instance['show_excerpt'];
        $num_ex = empty($instance['num_ex']) ? '' : $instance['num_ex'];
        if (function_exists('ot_get_option')) {
            $themes_pur = ot_get_option('theme_purpose');
        }
        if ($conditions == 'most_liked' && class_exists('CT_ContentHelper')) {
            global $wpdb;
            $show_count = 1;
            if ($timerange == 'day') {
                $time_range = '1';
            } else {
                if ($timerange == 'week') {
                    $time_range = '7';
                } else {
                    if ($timerange == 'month') {
                        $time_range = '1m';
                    } else {
                        if ($timerange == 'year') {
                            $time_range = '1y';
                        }
                    }
                }
            }
            //$time_range = $instance['time_range'];
            //$show_type = $instance['show_type'];
            $order_by = 'ORDER BY like_count DESC, post_title';
            if ($number > 0) {
                $limit = "LIMIT " . $number;
            }
            $widget_data = $before_widget;
            $widget_data .= $before_title . $title . $after_title;
            $show_excluded_posts = get_option('wti_like_post_show_on_widget');
            $excluded_post_ids = explode(',', get_option('wti_like_post_excluded_posts'));
            if (!$show_excluded_posts && count($excluded_post_ids) > 0) {
                $where = "AND post_id NOT IN (" . get_option('wti_like_post_excluded_posts') . ")";
            }
            if ($time_range != 'all') {
                $last_date = GetWtiLastDate($time_range);
                $where .= " AND date_time >= '{$last_date}'";
            }
            //getting the most liked posts
            $query = "SELECT post_id, SUM(value) AS like_count, post_title FROM `{$wpdb->prefix}wti_like_post` L, {$wpdb->prefix}posts P ";
            $query .= "WHERE L.post_id = P.ID AND post_status = 'publish' AND value > 0 {$where} GROUP BY post_id {$order_by} {$limit}";
            $posts = $wpdb->get_results($query);
            if (count($posts) > 0) {
                $item_loop_video = new CT_ContentHtml();
                $widget_data .= '
			<div class="widget-content">
					<div class="list-rating-item row">';
                foreach ($posts as $post) {
                    $p_data = $excerpt = '';
                    $post_title = stripslashes($post->post_title);
                    $permalink = get_permalink($post->post_id);
                    $like_count = $post->like_count;
                    $p_data = get_post($post->post_id);
                    $excerpt = strip_tags($p_data->post_content);
                    $excerpt = wp_trim_words($excerpt, $num_ex, $more = '');
                    $widget_data .= $item_loop_video->tm_likes_html($post, $like_count, $themes_pur, $show_likes, $show_com, $show_rate, $show_view, $show_excerpt, $excerpt);
                }
                $widget_data .= '</div>
			</div>';
            }
            $widget_data .= $after_widget;
            echo $widget_data;
        } else {
            if (class_exists('CT_ContentHelper')) {
                if ($conditions == 'most_viewed' || $conditions == '') {
                    if ($timerange == 'day') {
                        $args = array('post_type' => 'post', 'posts_per_page' => $number, 'meta_key' => '_count-views_day-' . date("Ymd"), 'orderby' => 'meta_value_num', 'order' => 'DESC', 'post_status' => 'publish');
                    } else {
                        if ($timerange == 'week') {
                            $args = array('post_type' => 'post', 'posts_per_page' => $number, 'meta_key' => '_count-views_week-' . date("YW"), 'orderby' => 'meta_value_num', 'order' => '', 'post_status' => 'publish');
                        } else {
                            if ($timerange == 'month') {
                                $args = array('post_type' => 'post', 'posts_per_page' => $number, 'meta_key' => '_count-views_month-' . date("Ym"), 'orderby' => 'meta_value_num', 'order' => '', 'post_status' => 'publish');
                            } else {
                                if ($timerange == 'year') {
                                    $args = array('post_type' => 'post', 'posts_per_page' => $number, 'meta_key' => '_count-views_year-' . date("Y"), 'orderby' => 'meta_value_num', 'order' => '', 'post_status' => 'publish');
                                }
                            }
                        }
                    }
                    if ($themes_pur != '0') {
                        $args['tax_query'] = array(array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => 'post-format-video'));
                    }
                    $the_query = new WP_Query($args);
                    $html = $before_widget;
                    if ($title) {
                        $html .= $before_title . $title . $after_title;
                    }
                    if ($the_query->have_posts()) {
                        $html .= '
						<div class="widget-content">
						<div class="list-rating-item row">
					';
                        $item_video = new CT_ContentHtml();
                        $i = 0;
                        while ($the_query->have_posts()) {
                            $the_query->the_post();
                            $i++;
                            $excerpt = get_the_excerpt();
                            $excerpt = wp_trim_words($excerpt, $num_ex, $more = '');
                            $html .= $item_video->get_item_video_trending($conditions, $themes_pur, $show_likes, $show_com, $show_rate, $show_view, $show_excerpt, $excerpt);
                        }
                        $html .= '</div>
					</div>';
                    }
                    $html .= $after_widget;
                    echo $html;
                } else {
                    if ($conditions == 'most_comments') {
                        wp_reset_postdata();
                        if ($timerange == 'day') {
                            $some_comments = get_comments(array('date_query' => array(array('after' => '1 day ago'))));
                        } else {
                            if ($timerange == 'week') {
                                $some_comments = get_comments(array('date_query' => array(array('after' => '1 week ago'))));
                            } else {
                                if ($timerange == 'month') {
                                    $some_comments = get_comments(array('date_query' => array(array('after' => '1 month ago'))));
                                } else {
                                    if ($timerange == 'year') {
                                        $some_comments = get_comments(array('date_query' => array(array('after' => '1 year ago'))));
                                    }
                                }
                            }
                        }
                        $html = $before_widget;
                        if ($title) {
                            $html .= $before_title . $title . $after_title;
                        }
                        $arr_id = array();
                        foreach ($some_comments as $comment) {
                            $arr_id[] = $comment->comment_post_ID;
                        }
                        $arr_id = array_unique($arr_id, SORT_REGULAR);
                        //$arr_id = implode(",", $arr_id);
                        $args = array('post_type' => 'post', 'posts_per_page' => $number, 'order' => $sort_by, 'post_status' => 'publish', 'post__in' => $arr_id, 'ignore_sticky_posts' => 1);
                        $query = new WP_Query($args);
                        if ($query->have_posts()) {
                            $html .= '
				<div class="widget-content">
					<div class="list-rating-item row">';
                            while ($query->have_posts()) {
                                $query->the_post();
                                $excerpt = get_the_excerpt();
                                $html .= '
						<div class="col-md-12 col-sm-4">
						  <div class="video-item">
							  <div class="videos-row">
									<div class="item-thumbnail">
										<a href="' . get_permalink(get_the_ID()) . '" title="' . get_the_title(get_the_ID()) . '">';
                                if (has_post_thumbnail(get_the_ID())) {
                                    $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'thumb_139x89', true);
                                } else {
                                    $thumbnail[0] = function_exists('tm_get_default_image') ? tm_get_default_image() : '';
                                }
                                $html .= '<img src="' . $thumbnail[0] . '" alt="' . the_title_attribute('echo=0') . '" title="' . the_title_attribute('echo=0') . '">';
                                //'.get_the_post_thumbnail(get_the_ID(), array(139,89) ).'
                                if ($themes_pur != '0') {
                                    $html .= '<div class="link-overlay fa fa-play "></div>';
                                }
                                $html .= '</a>';
                                if ($show_rate != 'hide_r') {
                                    $html .= tm_post_rating(get_the_ID());
                                }
                                $html .= '</div>
								  <div class="item-info">
									<div class="all-info">
									<h2 class="rt-article-title"> <a href="' . get_permalink(get_the_ID()) . '" title="' . get_the_title(get_the_ID()) . '">' . get_the_title(get_the_ID()) . '</a></h2>
									<div class="item-meta">';
                                if ($show_view != 'hide_v') {
                                    $html .= '<span class="pp-icon"><i class="fa fa-eye"></i> ' . get_post_meta(get_the_ID(), '_count-views_all', true) . '</span><br>';
                                }
                                if ($show_likes != 'hide_l' && function_exists('GetWtiLikeCount')) {
                                    $html .= '<span class="pp-icon iclike"><i class="fa fa-thumbs-up"></i> ' . str_replace('+', '', GetWtiLikeCount(get_the_ID())) . '</span><br>';
                                }
                                if ($show_com != 'hide_c') {
                                    $html .= '<span class="pp-icon"><i class="fa fa-comment"></i> ' . get_comments_number(get_the_ID()) . '</span><br>';
                                }
                                $html .= '
										</div>
										</div>
										</div>';
                                if ($show_excerpt != 'hide_ex') {
                                    $html .= '<div class="pp-exceprt">' . $excerpt . '</div>';
                                }
                                $html .= '
							   </div>
						  </div>
						</div>
						';
                            }
                            $html .= '</div>
				</div>';
                        }
                        $html .= $after_widget;
                        echo $html;
                    }
                }
                wp_reset_postdata();
                $cache[$argsxx['widget_id']] = ob_get_flush();
                wp_cache_set('widget_trending_videos', $cache, 'widget');
            }
        }
    }