scratch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 115  →  ?path2? @ 116
/gallery.php
@@ -20,100 +20,108 @@
}
 
echo json_encode(
array_map(
function ($file) use ($config, $finfo) {
#### Get the file hash.
$fileHash = array_shift(explode('.', $file));
array_values(
array_filter(
array_map(
function ($file) use ($config, $finfo) {
#### Get the file hash.
$fileHash = array_shift(explode('.', $file));
#### Build the user path.
$userPath = join(
DIRECTORY_SEPARATOR,
array(
$config['STORE_FOLDER'],
$file
)
);
#### If the extension is not allowed then skip this file.
$fileExtension = pathinfo($userPath, PATHINFO_EXTENSION);
if (!isset($fileExtension) ||
!in_array(strtoupper($fileExtension),
array_map('strtoupper', $config['ALLOWED_FILE_EXTENSIONS']))) {
return;
}
#### Hook for various file extensions.
$opengraph = FALSE;
switch (strtoupper($fileExtension)) {
case "MP4":
### Generate a hash for the preview image.
$previewHash = strtolower(
PseudoCrypt::hash(
preg_replace(
'/\D/',
'',
hash(
'sha512',
$fileHash
)
),
$config['ASSET_HASH_SIZE']
)
);
### Build the user path.
$previewFile = join(
#### Build the user path.
$userPath = join(
DIRECTORY_SEPARATOR,
array(
$config['STORE_FOLDER'],
$previewHash
$file
)
);
#### If the extension is not allowed then skip this file.
$fileExtension = pathinfo($userPath, PATHINFO_EXTENSION);
if (!isset($fileExtension) ||
!in_array(strtoupper($fileExtension),
array_map('strtoupper', $config['ALLOWED_FILE_EXTENSIONS'])))
return null;
#### Hook for various file extensions.
$opengraph = FALSE;
switch (strtoupper($fileExtension)) {
case "MP4":
### Generate a hash for the preview image.
$previewHash = strtolower(
PseudoCrypt::hash(
preg_replace(
'/\D/',
'',
hash(
'sha512',
$fileHash
)
),
$config['ASSET_HASH_SIZE']
)
);
### Do not re-create the thumbnail if it already exists.
if (file_exists($previewFile.'.'.'jpg')) {
break;
### Build the user path.
$previewFile = join(
DIRECTORY_SEPARATOR,
array(
$config['STORE_FOLDER'],
$previewHash
)
);
### Do not re-create the thumbnail if it already exists.
if (file_exists($previewFile.'.'.'jpg')) {
break;
}
### Extract thumbnail.
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($userPath);
$frame = $video->frame(
FFMpeg\Coordinate\TimeCode::fromSeconds(
$config['VIDEO_PREVIEW_IMAGE_FRAME_SECOND']
)
);
$frame->save($previewFile.'.'.'jpg');
$opengraph = TRUE;
break;
case "GIF":
$opengraph = TRUE;
case "PNG":
case "HTML":
case "HTM":
case "TGA":
case "SVG":
case "JPEG":
$previewHash = $fileHash;
break;
default:
return null;
}
### Extract thumbnail.
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($userPath);
$frame = $video->frame(
FFMpeg\Coordinate\TimeCode::fromSeconds(
$config['VIDEO_PREVIEW_IMAGE_FRAME_SECOND']
)
return array(
'url' => $fileHash,
'type' => finfo_file($finfo, $userPath),
'preview' => $previewHash,
'opengraph' => $opengraph
);
$frame->save($previewFile.'.'.'jpg');
$opengraph = TRUE;
break;
case "GIF":
$opengraph = TRUE;
$previewHash = $fileHash;
break;
default:
$previewHash = $fileHash;
break;
}
return array(
'url' => $fileHash,
'type' => finfo_file($finfo, $userPath),
'preview' => $previewHash,
'opengraph' => $opengraph
);
},
array_values(
array_filter(scandir($config['STORE_FOLDER']),
function ($entry) use ($config) {
return !is_dir($entry) && filesize(
join(
DIRECTORY_SEPARATOR,
array(
$config['STORE_FOLDER'],
$entry
)
)
);
}
},
array_values(
array_filter(scandir($config['STORE_FOLDER']),
function ($entry) use ($config) {
return !is_dir($entry) && filesize(
join(
DIRECTORY_SEPARATOR,
array(
$config['STORE_FOLDER'],
$entry
)
)
);
}
)
)
)
)
)