getDataPath () . 'ckeditor_' . str_pad ($id, 19, '0', STR_PAD_LEFT);
}
public static function resize ($id, $type, $width = 0, $height = 0, $force = FALSE, $bw = FALSE)
{
$source = self::getFilePath ($id);
$cache = Instance::singleton ()->getCachePath ();
if (!file_exists ($cache . self::ENCODE_FOLDER) && !@mkdir ($cache . self::ENCODE_FOLDER, 0777))
throw new Exception ('Unable create cache directory!');
if (!file_exists ($cache . self::ENCODE_FOLDER . DIRECTORY_SEPARATOR .'.htaccess') && !file_put_contents ($cache . self::ENCODE_FOLDER . DIRECTORY_SEPARATOR .'.htaccess', 'deny from all'))
throw new Exception ('Impossible to enhance security for folder ['. $cache . self::CACHE_FOLDER .'].');
$destination = $cache . self::ENCODE_FOLDER . DIRECTORY_SEPARATOR .'resized_' . str_pad ($id, 19, '0', STR_PAD_LEFT) .'_'. $width .'x'. $height .'_'. ($force ? '1' : '0') .'_'. ($bw ? '1' : '0');
return EncodeMedia::resizeImage ($source, $type, $destination, $width, $height, $force, $bw);
}
public static function synopsis ($id, $hash)
{
$path = self::getFilePath ($id);
if (!file_exists ($path) || !is_readable ($path) || !(int) sizeof ($path))
throw new Exception (__ ('Invalid file!'));
try
{
$db = Database::singleton ();
$sth = $db->prepare ("SELECT * FROM _ckeditor WHERE _id = :id AND _hash = :hash");
$sth->bindParam (':id', $id, PDO::PARAM_INT);
$sth->bindParam (':hash', $hash, PDO::PARAM_STR, 32);
$sth->execute ();
$obj = $sth->fetch (PDO::FETCH_OBJ);
}
catch (PDOException $e)
{
toLog ('['. $e->getLine () .'] '. $e->getMessage ());
throw new Exception (__ ('There was a severe error when trying to load file! Please, contact your administrator.'));
}
if (!$obj)
throw new Exception (__ ('There is no associated file!'));
$archive = Archive::singleton ();
if (!$archive->isAcceptable ($obj->_mimetype))
throw new Exception (__ ('This type of file is not accepted by the system ([1])!', $obj->mime));
ob_start ();
switch ($archive->getAssume ($obj->_mimetype))
{
case Archive::IMAGE:
?>
_mimetype))
{
?>
= __ ('This video is not supported by native player of your browser and cannot be converted! Click here to download it directly to your computer to watch in player of your choice.') ?>
_mimetype))
{
?>
= __ ('This audio is not supported by native player of your browser and cannot be converted! Click here to download it directly to your computer to listen in player of your choice.') ?>
getCachePath ();
if (!file_exists ($cache . self::ENCODE_FOLDER) && !@mkdir ($cache . self::ENCODE_FOLDER, 0777))
throw new Exception ('Unable create cache directory!');
if (!file_exists ($cache . self::ENCODE_FOLDER . DIRECTORY_SEPARATOR .'.htaccess') && !file_put_contents ($cache . self::ENCODE_FOLDER . DIRECTORY_SEPARATOR .'.htaccess', 'deny from all'))
throw new Exception ('Impossible to enhance security for folder ['. $cache . self::CACHE_FOLDER .'].');
$playable = $cache . self::ENCODE_FOLDER . DIRECTORY_SEPARATOR . 'encoded_' . str_pad ($id, 19, '0', STR_PAD_LEFT);
return EncodeMedia::getHtml5PlayableFile ($source, $mimetype, $playable);
}
public static function getRandomHash ()
{
$hash = '';
while (strlen ($hash) < 32)
$hash .= substr ('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxwz', mt_rand (0, 61), 1);
return $hash;
}
public static function isReadyToPlay ($id, $mimetype)
{
if (!in_array (Archive::singleton ()->getAssume ($mimetype), array (Archive::VIDEO, Archive::AUDIO)))
return FALSE;
$convertible = EncodeMedia::getEncodableTypes ();
if (!array_key_exists ($mimetype, $convertible))
return TRUE;
$cache = Instance::singleton ()->getCachePath ();
$encoded = $cache . self::ENCODE_FOLDER . DIRECTORY_SEPARATOR .'encoded_' . str_pad ($id, 19, '0', STR_PAD_LEFT) .'.'. $convertible [$mimetype];
$control = $cache . self::ENCODE_FOLDER . DIRECTORY_SEPARATOR .'encoded_' . str_pad ($id, 19, '0', STR_PAD_LEFT) .'.encoding';
if (!file_exists ($encoded) || (!(int) filesize ($encoded) && (!file_exists ($control) || filemtime ($control) < strtotime ('-1 day'))))
return FALSE;
if (file_exists ($control))
return FALSE;
return TRUE;
}
}
?>