make res_limit work with the new upload system, and have a ratio limit
git-svn-id: file:///home/shish/svn/shimmie2/trunk@710 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
		
							parent
							
								
									21ee529256
								
							
						
					
					
						commit
						5ebc559595
					
				@ -8,12 +8,13 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class ResolutionLimit extends Extension {
 | 
					class ResolutionLimit extends Extension {
 | 
				
			||||||
	public function receive_event($event) {
 | 
						public function receive_event($event) {
 | 
				
			||||||
		if(is_a($event, 'UploadingImageEvent')) {
 | 
							if(is_a($event, 'ImageAdditionEvent')) {
 | 
				
			||||||
			global $config;
 | 
								global $config;
 | 
				
			||||||
			$min_w = $config->get_int("upload_min_width", -1);
 | 
								$min_w = $config->get_int("upload_min_width", -1);
 | 
				
			||||||
			$min_h = $config->get_int("upload_min_height", -1);
 | 
								$min_h = $config->get_int("upload_min_height", -1);
 | 
				
			||||||
			$max_w = $config->get_int("upload_max_width", -1);
 | 
								$max_w = $config->get_int("upload_max_width", -1);
 | 
				
			||||||
			$max_h = $config->get_int("upload_max_height", -1);
 | 
								$max_h = $config->get_int("upload_max_height", -1);
 | 
				
			||||||
 | 
								$ratios = explode(" ", $config->get_string("upload_ratios", ""));
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			$image = $event->image;
 | 
								$image = $event->image;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -21,6 +22,22 @@ class ResolutionLimit extends Extension {
 | 
				
			|||||||
			if($min_h > 0 && $image->height < $min_h) $event->veto("Image too small");
 | 
								if($min_h > 0 && $image->height < $min_h) $event->veto("Image too small");
 | 
				
			||||||
			if($max_w > 0 && $image->width > $min_w) $event->veto("Image too large");
 | 
								if($max_w > 0 && $image->width > $min_w) $event->veto("Image too large");
 | 
				
			||||||
			if($max_h > 0 && $image->height > $min_h) $event->veto("Image too large");
 | 
								if($max_h > 0 && $image->height > $min_h) $event->veto("Image too large");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if(count($ratios) > 0) {
 | 
				
			||||||
 | 
									$ok = false;
 | 
				
			||||||
 | 
									foreach($ratios as $ratio) {
 | 
				
			||||||
 | 
										$parts = explode(":", $ratio);
 | 
				
			||||||
 | 
										$width = $parts[0];
 | 
				
			||||||
 | 
										$height = $parts[1];
 | 
				
			||||||
 | 
										if($image->width / $width == $image->height / $height) {
 | 
				
			||||||
 | 
											$ok = true;
 | 
				
			||||||
 | 
											break;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									if(!$ok) {
 | 
				
			||||||
 | 
										$event->veto("Image needs to be in one of these ratios: ".html_escape($config->get_string("upload_ratios", "")));
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if(is_a($event, 'SetupBuildingEvent')) {
 | 
							if(is_a($event, 'SetupBuildingEvent')) {
 | 
				
			||||||
			$sb = new SetupBlock("Resolution Limits");
 | 
								$sb = new SetupBlock("Resolution Limits");
 | 
				
			||||||
@ -39,6 +56,10 @@ class ResolutionLimit extends Extension {
 | 
				
			|||||||
			
 | 
								
 | 
				
			||||||
			$sb->add_label("<br>(-1 for no limit)");
 | 
								$sb->add_label("<br>(-1 for no limit)");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								$sb->add_label("<br>Ratios ");
 | 
				
			||||||
 | 
								$sb->add_text_option("upload_ratios");
 | 
				
			||||||
 | 
								$sb->add_label("<br>(eg. '4:3 16:9', blank for no limit)");
 | 
				
			||||||
 | 
								
 | 
				
			||||||
			$event->panel->add_block($sb);
 | 
								$event->panel->add_block($sb);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user