Project

General

Profile

Feature #1134 » cac-featured-content-1134.diff

Boone Gorges, 2011-11-29 10:08 AM

View differences:

timthumb.php (working copy)
20 20
	a new version of timthumb.
21 21

  
22 22
*/
23
define ('VERSION', '2.8');										// Version of this script
23
define ('VERSION', '2.8');	
24
define( 'ALLOW_ALL_EXTERNAL_SITES', true );
25
// Version of this script
24 26
//Load a config file if it exists. Otherwise, use the values below.
25 27
if( file_exists('timthumb-config.php')) 	require_once('timthumb-config.php');
26 28
if(! defined( 'DEBUG_ON' ) ) 			define ('DEBUG_ON', false);				// Enable debug logging to web server error log (STDERR)
......
215 217
			return false;
216 218
			exit(0);
217 219
		}
220
		// Don't do this
221
		/*(
218 222
		if(preg_match('/https?:\/\/(?:www\.)?' . $this->myHost . '(?:$|\/)/i', $this->src)){
219 223
			$this->src = preg_replace('/https?:\/\/(?:www\.)?' . $this->myHost . '/i', '', $this->src);
220 224
		}
225
		*/
226
		
221 227
		if(preg_match('/^https?:\/\/[^\/]+/i', $this->src)){
222 228
			$this->debug(2, "Is a request for an external URL: " . $this->src);
223 229
			$this->isURL = true;
224 230
		} else {
225 231
			$this->debug(2, "Is a request for an internal file: " . $this->src);
226 232
		}
233
		
234
		// Manually set isURL to true
235
		$this->isURL = true;
236
		
227 237
		if($this->isURL && (! ALLOW_EXTERNAL)){
228 238
			$this->error("You are not allowed to fetch images from an external website.");
229 239
			return false;
cac-featured-content.php (working copy)
441 441
		$resource_title = $instance['resource_title'];
442 442
		$resource_image_source = $instance['resource_image_source'];
443 443
		
444
		$this->instance = $instance;
445
		
444 446
		/********************
445 447
		 *****Form Data******
446 448
		*********************/
......
507 509
			<?php
508 510
			echo $this->getBlogDomainField($blog_domain, true);
509 511
			?>
512
			
510 513
			<hr />
514
			
515
			<p><?php _e( 'Select an image to be shown in the widget. You may enter a URL, or select from the current blog\'s Media Library. If you leave this field blank, an image will be automatically pulled from the blog.', $this->pluginDomain ) ?></p>
511 516
		</div>
512 517
		
513 518
		<div class="cac-featured-resource">
......
523 528
			?>
524 529
			<p>You can choose to use an image with an external source, or select an image from the media library.</p>
525 530
			<hr />
526
			<p><label for="<?php echo $this->get_field_id('image'); ?>"><?php _e('Image from the media library:', $this->pluginDomain); ?></label>
531
		</div>
532
		
533
		<div class="cac-featured-image">
527 534
			<?php
528
				$media_upload_iframe_src = "media-upload.php?type=image&widget_id=".$this->id; //NOTE #1: the widget id is added here to allow uploader to only return array if this is used with image widget so that all other uploads are not harmed.
529
				$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src");
530
				$image_title = __(($instance['image'] ? 'Change Image' : 'Add Image'), $this->pluginDomain);
531
			?><br />
532
			<a href="<?php echo $image_upload_iframe_src; ?>&TB_iframe=true" id="add_image-<?php echo $this->get_field_id('image'); ?>" class="thickbox-cac-featured-content-widget" title='<?php echo $image_title; ?>' onClick="set_active_widget('<?php echo $this->id; ?>');return false;" style="text-decoration:none"><img src='images/media-button-image.gif' alt='<?php echo $image_title; ?>' align="absmiddle" /> <?php echo $image_title; ?></a>
533
			<div id="display-<?php echo $this->get_field_id('image'); ?>"><?php 
534
			if ($instance['imageurl']) {
535
				echo '<img src="'.get_bloginfo('wpurl').'/wp-content/plugins/cac-featured-content/timthumb.php?src='.$this->get_fully_qualified_image_path($instance['imageurl']).'&w=50&q=100" class="avatar" width="50" hight="50"/>';
536
				// echo "<img src=\"{$instance['imageurl']}\" alt=\"{$instance['image_title']}\" style=\"";
537
				// 					if ($instance['width'] && is_numeric($instance['width'])) {
538
				// 						echo "max-width: {$instance['width']}px;";
539
				// 					}
540
				// 					if ($instance['height'] && is_numeric($instance['height'])) {
541
				// 						echo "max-height: {$instance['height']}px;";
542
				// 					}
543
				// 					echo "\"";
544
				// 					if (!empty($instance['align']) && $instance['align'] != 'none') {
545
				// 						echo " class=\"align{$instance['align']}\"";
546
				// 					}
547
				// 					echo " />";
548
			}
535
			echo $this->getImageSelectionFields();
549 536
			?>
550
			<br />
551
			<a class="remove">Remove image</a>
552
			</div>
553
			<input id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" type="hidden" value="<?php echo $instance['image']; ?>" />
554
			</p>
555
			<?php
556
			echo $this->getResourceImageSourceField($resource_image_source, true);
557
			?>
558
			<?php
559
			echo $this->getImageCropRuleField($image_crop_rule, true);
560
			?>
561 537
		</div>
562 538
<?php
563 539
	}
564 540
	
541
	function getImageSelectionFields() {
542
		$instance = $this->instance;
543
		
544
		$media_upload_iframe_src = "media-upload.php?type=image&widget_id=".$this->id; //NOTE #1: the widget id is added here to allow uploader to only return array if this is used with image widget so that all other uploads are not harmed.
545
		$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src");
546
		$image_title = __(($instance['image'] ? 'Change Image' : 'Add Image'), $this->pluginDomain);
547
		
548
		$image_markup = !empty( $instance['imageurl'] ) ? '<img src="' . get_bloginfo('wpurl') . '/wp-content/plugins/cac-featured-content/timthumb.php?src=' . $this->get_fully_qualified_image_path( $instance['imageurl'] ) . '&w=50&q=100" class="avatar" width="50" hight="50" />' : '';
549
		
550
		$out = '<p><label for="' . $this->get_field_id('image') . '">' . __('Image from the media library:', $this->pluginDomain) . '</label>';
551
		$out .= '<br />';
552
		$out .= '<a href="' . $image_upload_iframe_src . '&TB_iframe=true" id="add_image-' . $this->get_field_id('image') . '" class="thickbox-cac-featured-content-widget" title="' . $image_title . '" onClick="set_active_widget(\'' . $this->id . '\');return false;" style="text-decoration:none"><img src="images/media-button-image.gif" alt="' . $image_title . '" align="absmiddle" />' . $image_title . '</a>';
553
		
554
		$out .= '<div id="display-' . $this->get_field_id('image') . '">';
555
		$out .= $image_markup;
556
		$out .= '<br /><a class="remove">Remove image</a>';
557
		$out .= '</div>';
558
		
559
		$out .=	'<input id="' . $this->get_field_id('image') . '" name="' . $this->get_field_name('image') . '" type="hidden" value="' . $instance['image'] . '" /></p>';
560
		
561
		$out .= $this->getResourceImageSourceField($instance['resource_image_source'], true);
562
		$out .= $this->getImageCropRuleField($instance['image_crop_rule'], true);
563
		
564
		return $out;
565
	}
566
	
565 567
	function getCropLengthField($value, $pWrap = false) {
566 568
		$labelText = "<b>Crop length: </b>Please enter the length (in characters) that you want to crop text by: <br/>";
567 569
		$label = '<label for="'.$this->get_field_id('crop_length').'">'.$labelText.'</label>';
......
827 829
		
828 830
		if ( !$width = (int)$this->image_width )
829 831
			$width = '100';
832
			
833
		$imageurl = false;
834
		if ( $this->imageurl ) {
835
			$imageurl = $this->imageurl;
836
		} elseif( $this->resource_image_source ) {
837
			$imageurl = $this->resource_image_source;
838
		}
830 839
		
831
		$avatar = bp_core_fetch_avatar( array( 'item_id' => $author_id, 'type' => 'full', 'height' => $height , 'width' => $width, 'no_grav' => false ) );
840
		// Trimming escaped spaces
841
		$imageurl = trim( $imageurl, '&nbsp;' );
842

  
843
		$avatar = $imageurl ? $this->get_image_markup_from_url( $imageurl ) : bp_core_fetch_avatar( array( 'item_id' => $author_id, 'type' => 'full', 'height' => $height , 'width' => $width, 'no_grav' => false ) );
832 844
		
833 845
		/*************************
834 846
		******Switch Context******
......
853 865
		?>
854 866
		<h3><?php echo $header ?></h3>
855 867
			<div>
856
				<?php if($the_post_image_link): ?>
868
				<?php if($the_post_image_link && !$imageurl): ?>
857 869
					<?php echo $the_post_image_link ?>
858 870
					<!-- <img src="<?php echo get_bloginfo('wpurl');?>/wp-content/plugins/cac-featured-content/timthumb.php?src=<?php echo $the_post_image_link ?>&h=<?php echo $this->image_height ?>&w=<?php echo $this->image_width ?>&q=100&a=c" class="avatar" /> -->
859 871
				<?php else: ?>
......
899 911

  
900 912
			if ( !empty( $src ) ) {
901 913
				$src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
902
				$height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
903
				$width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
904 914

  
905 915
				if ( empty( $width ) || empty( $height ) ) {
906 916
					$width = 100;
907 917
					$height = 100;
918
				} else {	
919
					$height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
920
					$width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
908 921
				}
922

  
909 923
				// This was modified from the original so that the width gets set to whatever the user has selected in the plugin.
910 924
				if ( (int) $this->image_width ) {
911 925
					$ratio = (int)$height / (int)$width;
......
955 969
			$height = $this->image_height;
956 970
		} else {
957 971
			$height = '100';
958
		}		
972
		}
959 973
		
960
		$avatar = apply_filters( 'cac_featured_content_blog_avatar', bp_core_fetch_avatar( array( 'item_id' => $blog_admin_id, 'type' => 'full', 'height' => $height, 'width' => $width, 'no_grav' => false ) ), $blog_id );
974
		$imageurl = false;
975
		if ( $this->imageurl ) {
976
			$imageurl = $this->imageurl;
977
		} elseif( $this->resource_image_source ) {
978
			$imageurl = $this->resource_image_source;
979
		}
961 980
		
981
		// Trimming escaped spaces
982
		$imageurl = trim( $imageurl, '&nbsp;' );
983
		
984
		$avatar = $imageurl ? $this->get_image_markup_from_url( $imageurl ) : apply_filters( 'cac_featured_content_blog_avatar', bp_core_fetch_avatar( array( 'item_id' => $blog_admin_id, 'type' => 'full', 'height' => $height, 'width' => $width, 'no_grav' => false ) ), $blog_id, $imageurl );
985
		
962 986
		switch_to_blog($blog_id);
963 987
		$posts = get_posts();
964 988
		
......
1124 1148
	    </div>
1125 1149
	<?php
1126 1150
	}
1151
	
1152
	public function get_image_markup_from_url( $url ) {
1153
		if ( (int) $this->image_width ) {
1154
			$width = $this->image_width;
1155
		} else {
1156
			$width = '100';
1157
		}
1158
		
1159
		if ( (int) $this->image_height ) {
1160
			$height = $this->image_height;
1161
		} else {
1162
			$height = '100';
1163
		}
1164
		$out = '<img src="' . WP_PLUGIN_URL . '/cac-featured-content/timthumb.php?src=' .  $url . '&h=' . $height . '&w=' . $width . '&q=100&a=' . $this->image_crop_rule . '" class="avatar" />';
1165
		return $out;
1166
	}
1127 1167
}
1128 1168
?>
(2-2/2)