checks for files without extensions, from AtomicDryad
This commit is contained in:
parent
6ddd0b3e6f
commit
ead87d3934
@ -132,7 +132,25 @@ abstract class DataHandlerExtension implements Extension {
|
|||||||
public function receive_event(Event $event) {
|
public function receive_event(Event $event) {
|
||||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||||
|
|
||||||
if(($event instanceof DataUploadEvent) && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
|
if($event instanceof DataUploadEvent) {
|
||||||
|
$valid=FALSE; // TRUE = skip check_contents()
|
||||||
|
$USEHEADERSALWAYS=FALSE; //TRUE; // STUB - make option
|
||||||
|
if ( is_null($event->type) || ($event->type == "") || ( $USEHEADERSALWAYS ) ) {
|
||||||
|
if (is_callable(array($this,'find_ext'))) {
|
||||||
|
// find_ext should always return false or a valid str, so:
|
||||||
|
if(!$ext=$this->find_ext($event->tmpname)) return; // pass off to the next listener and avoid ext=NULL mysql insert
|
||||||
|
$valid=TRUE; // or avoid calling check_contents() needlessly
|
||||||
|
$event->type = $ext;
|
||||||
|
$event->metadata['extension']=$ext;
|
||||||
|
log_info("core-extension", get_class($this)." has renamed '".$event->metadata['filename']."' to '".$event->metadata['filename'].".$ext'");
|
||||||
|
$event->metadata['filename']=$event->metadata['filename'].".$ext";
|
||||||
|
} else { if(!$USEHEADERSALWAYS) return; } // no ext + valid check_contents = mysql error.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if( ($valid) || ($this->check_contents($event->tmpname)) ) {
|
||||||
|
|
||||||
if(!move_upload_to_archive($event)) return;
|
if(!move_upload_to_archive($event)) return;
|
||||||
send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
|
send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
|
||||||
$image = $this->create_image_from_data(warehouse_path("images", $event->hash), $event->metadata);
|
$image = $this->create_image_from_data(warehouse_path("images", $event->hash), $event->metadata);
|
||||||
@ -143,6 +161,7 @@ abstract class DataHandlerExtension implements Extension {
|
|||||||
send_event($iae);
|
send_event($iae);
|
||||||
$event->image_id = $iae->image->id;
|
$event->image_id = $iae->image->id;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) {
|
if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) {
|
||||||
$this->create_thumb($event->hash);
|
$this->create_thumb($event->hash);
|
||||||
|
@ -32,6 +32,17 @@ class PixelFileHandler extends DataHandlerExtension {
|
|||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function find_ext($file) {
|
||||||
|
$phpimgexts = array ( 1=> 'gif', 'jpg', 'png', 'swf', 'psd', 'bmp', 'tiff', 'tiff',
|
||||||
|
'jpc', 'jp2', 'jpf', 'jb2', 'swc', 'aiff', 'wbmp', 'xbm'); // const, do not change. Less overhead / PITA than image_type_to_extension($info[2])
|
||||||
|
|
||||||
|
if(!file_exists($file)) return false;
|
||||||
|
$info = getimagesize($file);
|
||||||
|
$exts = array("jpg", "jpeg", "gif", "png");
|
||||||
|
$ret=$phpimgexts[$info[2]];
|
||||||
|
return (in_array($ret,$exts)?$ret:false);
|
||||||
|
}
|
||||||
|
|
||||||
protected function check_contents($file) {
|
protected function check_contents($file) {
|
||||||
$valid = Array(IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG);
|
$valid = Array(IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG);
|
||||||
if(!file_exists($file)) return false;
|
if(!file_exists($file)) return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user