2007-12-06 03:06:59 +00:00
|
|
|
<?php
|
2009-08-20 22:37:17 +00:00
|
|
|
/*
|
2010-01-05 10:32:39 +00:00
|
|
|
* Name: Handle Flash
|
2007-12-06 03:06:59 +00:00
|
|
|
* Author: Shish <webmaster@shishnet.org>
|
|
|
|
* Description: Handle Flash files
|
|
|
|
*/
|
|
|
|
|
2009-07-16 19:20:53 +00:00
|
|
|
class FlashFileHandler extends DataHandlerExtension {
|
|
|
|
protected function create_thumb($hash) {
|
|
|
|
$ha = substr($hash, 0, 2);
|
|
|
|
// FIXME: scale image, as not all boards use 192x192
|
|
|
|
copy("ext/handle_flash/thumb.jpg", "thumbs/$ha/$hash");
|
2007-12-06 03:06:59 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 19:20:53 +00:00
|
|
|
protected function supported_ext($ext) {
|
2008-04-08 15:41:11 +00:00
|
|
|
$exts = array("swf");
|
2009-06-05 19:53:00 +00:00
|
|
|
return in_array(strtolower($ext), $exts);
|
2008-04-08 15:41:11 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 19:20:53 +00:00
|
|
|
protected function create_image_from_data($filename, $metadata) {
|
2007-12-06 03:06:59 +00:00
|
|
|
global $config;
|
|
|
|
|
|
|
|
$image = new Image();
|
|
|
|
|
|
|
|
$image->filesize = $metadata['size'];
|
|
|
|
$image->hash = $metadata['hash'];
|
|
|
|
$image->filename = $metadata['filename'];
|
|
|
|
$image->ext = $metadata['extension'];
|
2009-01-24 19:05:07 +00:00
|
|
|
$image->tag_array = Tag::explode($metadata['tags']);
|
2007-12-06 03:06:59 +00:00
|
|
|
$image->source = $metadata['source'];
|
|
|
|
|
2008-06-14 11:18:41 +00:00
|
|
|
// redundant, since getimagesize() works on SWF o_O
|
|
|
|
// $rect = $this->swf_get_bounds($filename);
|
|
|
|
// if(is_null($rect)) {
|
|
|
|
// return $null;
|
|
|
|
// }
|
|
|
|
// $image->width = $rect[1];
|
|
|
|
// $image->height = $rect[3];
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2008-06-14 11:18:41 +00:00
|
|
|
if(!($info = getimagesize($filename))) return null;
|
|
|
|
|
|
|
|
$image->width = $info[0];
|
|
|
|
$image->height = $info[1];
|
2008-05-26 21:56:06 +00:00
|
|
|
|
2007-12-06 03:06:59 +00:00
|
|
|
return $image;
|
|
|
|
}
|
|
|
|
|
2009-07-16 19:20:53 +00:00
|
|
|
protected function check_contents($file) {
|
|
|
|
if(!file_exists($file)) return false;
|
|
|
|
|
|
|
|
$fp = fopen($file, "r");
|
|
|
|
$head = fread($fp, 3);
|
|
|
|
fclose($fp);
|
|
|
|
if(!in_array($head, array("CWS", "FWS"))) return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-05-26 21:56:06 +00:00
|
|
|
private function str_to_binarray($string) {
|
|
|
|
$binary = array();
|
|
|
|
for($j=0; $j<strlen($string); $j++) {
|
|
|
|
$c = ord($string[$j]);
|
|
|
|
for($i=7; $i>=0; $i--) {
|
|
|
|
$binary[] = ($c >> $i) & 0x01;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $binary;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function binarray_to_int($binarray, $start=0, $length=32) {
|
|
|
|
$int = 0;
|
|
|
|
for($i=$start; $i<$start + $length; $i++) {
|
|
|
|
$int = $int << 1;
|
|
|
|
$int = $int + ($binarray[$i] == "1" ? 1 : 0);
|
|
|
|
}
|
|
|
|
return $int;
|
|
|
|
}
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2008-05-26 21:56:06 +00:00
|
|
|
private function swf_get_bounds($filename) {
|
|
|
|
$fp = fopen($filename, "r");
|
|
|
|
$head = fread($fp, 3);
|
|
|
|
$version = fread($fp, 1);
|
|
|
|
$length = fread($fp, 4);
|
|
|
|
|
|
|
|
if($head == "FWS") {
|
|
|
|
$data = fread($fp, 16);
|
|
|
|
}
|
|
|
|
else if($head == "CWS") {
|
2008-05-26 22:02:23 +00:00
|
|
|
$data = fread($fp, 128*1024);
|
|
|
|
$data = gzuncompress($data);
|
|
|
|
$data = substr($data, 0, 16);
|
2008-05-26 21:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$bounds = array();
|
|
|
|
$rect_bin = $this->str_to_binarray($data);
|
|
|
|
$nbits = $this->binarray_to_int($rect_bin, 0, 5);
|
|
|
|
$bounds[] = $this->binarray_to_int($rect_bin, 5 + 0 * $nbits, $nbits) / 20;
|
|
|
|
$bounds[] = $this->binarray_to_int($rect_bin, 5 + 1 * $nbits, $nbits) / 20;
|
|
|
|
$bounds[] = $this->binarray_to_int($rect_bin, 5 + 2 * $nbits, $nbits) / 20;
|
|
|
|
$bounds[] = $this->binarray_to_int($rect_bin, 5 + 3 * $nbits, $nbits) / 20;
|
|
|
|
|
|
|
|
return $bounds;
|
|
|
|
}
|
2007-12-06 03:06:59 +00:00
|
|
|
}
|
2009-07-16 19:20:53 +00:00
|
|
|
add_event_listener(new FlashFileHandler());
|
2007-12-06 03:06:59 +00:00
|
|
|
?>
|