<commit_before><?php
/*
Plugin Name: Ultimate Posts Widget
Plugin URI: http://pomelodesign.com/ultimate-posts-widget
Description: The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.
Version: 1.4.3
Author: <NAME>
Author URI: http://pomelodesign.com
License: GPL2

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
	
	class WP_Widget_Ultimate_Posts extends WP_Widget {
	
		function WP_Widget_Ultimate_Posts() {
			
			$widget_ops = array( 'classname' => 'widget_ultimate_posts', 'description' => __( 'The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.' ) );
			$this->WP_Widget( 'sticky-posts', __( 'Ultimate Posts' ), $widget_ops );
			$this->alt_option_name = 'widget_ultimate_posts';
	
			add_action( 'save_post', array( &$this, 'flush_widget_cache' ) );
			add_action( 'deleted_post', array( &$this, 'flush_widget_cache' ) );
			add_action( 'switch_theme', array( &$this, 'flush_widget_cache' ) );
			
		}
	
		function widget( $args, $instance ) {

			if( !function_exists(get_image_path) ) {
				function get_image_path($src) {
					global $blog_id;
					if(isset($blog_id) && $blog_id > 0) {
						$imageParts = explode('/files/' , $src);
						if(isset($imageParts[1])) {
							$src = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
						}
					}
					return $src;
				}
			}
			
			$cache = wp_cache_get( 'widget_ultimate_posts', 'widget' );
	
			if ( !is_array( $cache ) )
				$cache = array();
	
			if ( isset( $cache[$args['widget_id']] ) ) {
				echo $cache[$args['widget_id']];
				return;
			}
	
			ob_start();
			extract( $args );
	
			$title = apply_filters( 'widget_title', $instance['title'] );
			$number = $instance['number'];
			$cpt = $instance['types'];		
			if (!empty($cpt)) $types = explode(',', $cpt);
			$categories = $instance['cats'];		
			if (!empty($categories)) $cats = explode(',', $categories);
			$atcat = $instance['atcat'];
			$thumb_w = $instance['thumb_w'];
			$thumb_h = $instance['thumb_h'];
			$excerpt_length = $instance['excerpt_length'];
			$excerpt_readmore = $instance['excerpt_readmore'];
			$sticky = $instance['sticky'];
			$order = $instance['order'];

			// If $atcat true and in category
			if ($atcat && is_category()) {  
				$cats = get_query_var('cat');  
			}

			// If $atcat true and is single post
			if ($atcat && is_single()) {  
				$cats = '';  
				foreach (get_the_category() as $catt) {  
					$cats .= $catt->cat_ID.' ';   
				}  
				$cats = str_replace(" ", ",", trim($cats));  
			}

			// If sticky
			if ($sticky) {
				$sticky_option = get_option( 'sticky_posts' );
			}

			//Excerpt more filter
			$new_excerpt_more = create_function('$more', 'return " ";');	
			add_filter('excerpt_more', $new_excerpt_more);
			
			// Excerpt length filter
			$new_excerpt_length = create_function('$length', "return " . $excerpt_length . ";");
			if ( $instance["excerpt_length"] > 0 ) add_filter('excerpt_length', $new_excerpt_length);

			echo $before_widget;
			if ( $title ) echo $before_title . $title . $after_title;

			$args = array(
				'showposts' => $number,
				'orderby' => $order,
				'post__in' => $sticky_option,
				'category__in' => $cats,
				'post_type' => $types
			);

			$r = new WP_Query( $args );
			
			if ( $r->have_posts() ) :
				
				echo '<ul>';
				
				while ( $r->have_posts() ) : $r->the_post(); ?>
					
					<li>

						<?php
							if ( function_exists('the_post_thumbnail') &&
									 current_theme_supports("post-thumbnails") &&
									 $instance["show_thumbnail"] &&
									 has_post_thumbnail() ) :
							$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'full');
							$plugin_dir = 'ultimate-posts-widget';
						?>

						<div class="upw-image">
							<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
								<img src="<?php echo WP_PLUGIN_URL . '/ultimate-posts-widget/thumb.php?src='. get_image_path($thumbnail[0]) .'&h='.$thumb_h.'&w='.$thumb_w.'&&zc=2'; ?>" alt="<?php the_title_attribute(); ?>" width="<?php echo $thumb_w; ?>" height="<?php echo $thumb_h; ?>" />
							</a>
						</div>

						<?php endif; ?>

						<div class="upw-content">
							
							<?php if ( get_the_title() && $instance['show_title'] ) : ?>
								<a class="post-title" href="<?php the_permalink(); ?>" title="<?php echo esc_attr( get_the_title() ? get_the_title() : get_the_ID() ); ?>">
									<?php the_title(); ?>
								</a>
							<?php endif; ?>

							<?php if ( $instance['show_date'] ) : ?>
								<p class="post-date"><?php the_time("j M Y"); ?></p>
							<?php endif; ?>

							<?php if ( $instance['show_excerpt'] ) :
								if ( $instance['readmore'] ) : $linkmore = ' <a href="'.get_permalink().'" class="more-link">'.$excerpt_readmore.'</a>'; else: $linkmore =''; endif; ?>
								<p class="post-excerpt"><?php echo get_the_excerpt() . $linkmore; ?></p>
							<?php endif; ?><commit_msg>fixes #2<commit_after><?php
/*
Plugin Name: Ultimate Posts Widget
Plugin URI: http://pomelodesign.com/ultimate-posts-widget
Description: The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.
Version: 1.4.3
Author: <NAME>
Author URI: http://pomelodesign.com
License: GPL2

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
	
	class WP_Widget_Ultimate_Posts extends WP_Widget {
	
		function WP_Widget_Ultimate_Posts() {
			
			$widget_ops = array( 'classname' => 'widget_ultimate_posts', 'description' => __( 'The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.' ) );
			$this->WP_Widget( 'sticky-posts', __( 'Ultimate Posts' ), $widget_ops );
			$this->alt_option_name = 'widget_ultimate_posts';
	
			add_action( 'save_post', array( &$this, 'flush_widget_cache' ) );
			add_action( 'deleted_post', array( &$this, 'flush_widget_cache' ) );
			add_action( 'switch_theme', array( &$this, 'flush_widget_cache' ) );
			
		}
	
		function widget( $args, $instance ) {

			if( !function_exists(get_image_path) ) {
				function get_image_path($src) {
					global $blog_id;
					if(isset($blog_id) && $blog_id > 0) {
						$imageParts = explode('/files/' , $src);
						if(isset($imageParts[1])) {
							$src = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
						}
					}
					return $src;
				}
			}
			
			$cache = wp_cache_get( 'widget_ultimate_posts', 'widget' );
	
			if ( !is_array( $cache ) )
				$cache = array();
	
			if ( isset( $cache[$args['widget_id']] ) ) {
				echo $cache[$args['widget_id']];
				return;
			}
	
			ob_start();
			extract( $args );
	
			$title = apply_filters( 'widget_title', $instance['title'] );
			$number = $instance['number'];
			$cpt = $instance['types'];		
			if (!empty($cpt)) $types = explode(',', $cpt);
			$categories = $instance['cats'];		
			if (!empty($categories)) $cats = explode(',', $categories);
			$atcat = $instance['atcat'];
			$thumb_w = $instance['thumb_w'];
			$thumb_h = $instance['thumb_h'];
			$excerpt_length = $instance['excerpt_length'];
			$excerpt_readmore = $instance['excerpt_readmore'];
			$sticky = $instance['sticky'];
			$order = $instance['order'];

			// If $atcat true and in category
			if ($atcat && is_category()) {  
				$cats = get_query_var('cat');  
			}

			// If $atcat true and is single post
			if ($atcat && is_single()) {  
				$cats = '';  
				foreach (get_the_category() as $catt) {  
					$cats .= $catt->cat_ID.' ';   
				}  
				$cats = str_replace(" ", ",", trim($cats));  
			}

			// If sticky
			if ($sticky) {
				$sticky_option = get_option( 'sticky_posts' );
			}

			//Excerpt more filter
			$new_excerpt_more = create_function('$more', 'return "...";');	
			add_filter('excerpt_more', $new_excerpt_more);
			
			// Excerpt length filter
			$new_excerpt_length = create_function('$length', "return " . $excerpt_length . ";");
			if ( $instance["excerpt_length"] > 0 ) add_filter('excerpt_length', $new_excerpt_length);

			echo $before_widget;
			if ( $title ) echo $before_title . $title . $after_title;

			$args = array(
				'showposts' => $number,
				'orderby' => $order,
				'post__in' => $sticky_option,
				'category__in' => $cats,
				'post_type' => $types
			);

			$r = new WP_Query( $args );
			
			if ( $r->have_posts() ) :
				
				echo '<ul>';
				
				while ( $r->have_posts() ) : $r->the_post(); ?>
					
					<li>

						<?php
							if ( function_exists('the_post_thumbnail') &&
									 current_theme_supports("post-thumbnails") &&
									 $instance["show_thumbnail"] &&
									 has_post_thumbnail() ) :
							$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'full');
							$plugin_dir = 'ultimate-posts-widget';
						?>

						<div class="upw-image">
							<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
								<img src="<?php echo WP_PLUGIN_URL . '/ultimate-posts-widget/thumb.php?src='. get_image_path($thumbnail[0]) .'&h='.$thumb_h.'&w='.$thumb_w.'&&zc=2'; ?>" alt="<?php the_title_attribute(); ?>" width="<?php echo $thumb_w; ?>" height="<?php echo $thumb_h; ?>" />
							</a>
						</div>

						<?php endif; ?>

						<div class="upw-content">
							
							<?php if ( get_the_title() && $instance['show_title'] ) : ?>
								<a class="post-title" href="<?php the_permalink(); ?>" title="<?php echo esc_attr( get_the_title() ? get_the_title() : get_the_ID() ); ?>">
									<?php the_title(); ?>
								</a>
							<?php endif; ?>

							<?php if ( $instance['show_date'] ) : ?>
								<p class="post-date"><?php the_time("j M Y"); ?></p>
							<?php endif; ?>

							<?php if ( $instance['show_excerpt'] ) :
								if ( $instance['show_readmore'] ) : $linkmore = ' <a href="'.get_permalink().'" class="more-link">'.$excerpt_readmore.'</a>'; else: $linkmore =''; endif; ?>
								<p class="post-excerpt"><?php echo get_the_excerpt() . $linkmore; ?></p>
							<?php endif; ?>
{'fraction_non_alphanumeric': 0.17117117117117117, 'fraction_numerical': 0.00397456279809221, 'mean_word_length': 3.3617103235747305, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1277673', 'n_tokens_mistral': 4721, 'n_tokens_neox': 3776, 'n_words': 913}