function get_acceptable_mime_types()
 {
     static $mime_types_from_extension;
     if (!isset($mime_types_from_extension)) {
         foreach ($this->recognized_extensions as $extension) {
             $mime_type = mime_type_from_extension($extension);
             if (!empty($mime_type)) {
                 $mime_types[$mime_type] = $mime_type;
             }
         }
         $mime_types_from_extension = isset($mime_types) ? array_values($mime_types) : array();
     }
     $acceptable_mime_types = array_merge($this->acceptable_mime_types, $mime_types_from_extension);
     return array_unique($acceptable_mime_types);
 }
 function api_job_import($input = array(), $output = array(), $config = array())
 {
     $result = array('callbacks' => array(), 'inputs' => array(), 'outputs' => array());
     if (!$config) {
         $config = config_get();
     }
     $err = config_error($config);
     if (!$err) {
         // check for required input
         if (empty($input['uid'])) {
             $input['uid'] = auth_userid();
         }
         // make sure required input parameters have been set
         $id = empty($input['id']) ? '' : $input['id'];
         $extension = empty($input['extension']) ? '' : $input['extension'];
         $type = empty($input['type']) ? mime_type_from_extension($extension) : $input['type'];
         $label = empty($input['label']) ? $id : $input['label'];
         if (!($id && $extension && $type)) {
             $err = 'Required parameter omitted';
         }
     }
     if (!$err) {
         // create job for transcoder
         $input_tag = array('type' => $type);
         if ($type != 'audio') {
             $input_tag['fill'] = 'none';
         }
         // DESTINATION
         $result['destination'] = service_destination($input, $config);
         // CALLBACKS
         $progress_callback_payload = array('job' => '{job.id}', 'progress' => '{job.progress}');
         $complete_callback_payload = array('job' => '{job.id}', 'id' => $id, 'uid' => $input['uid'], 'extension' => $extension, 'type' => $type, 'label' => $label, 'error' => '{job.error}', 'log' => '{job.log}', 'commands' => '{job.commands}', 'no_audio' => '{job.inputs.0.no_audio}', 'no_video' => '{job.inputs.0.no_video}');
         if ('image' != $type) {
             $complete_callback_payload['duration'] = '{job.duration}';
         }
         if (!empty($output['include_progress'])) {
             $result['callbacks'][] = service_import_progress_callback($progress_callback_payload, $config);
         }
         $result['callbacks'][] = service_import_complete_callback($complete_callback_payload, $config);
         $input_tag['source'] = service_source($input, $config);
         $result['inputs'][] = $input_tag;
         // OUTPUTS
         if ($type == 'image') {
             // add output for image file
             $result['outputs'][] = array('type' => 'image', 'name' => '0', 'path' => $config['import_dimensions'] . 'x1', 'dimensions' => $config['import_dimensions'], 'extension' => $extension, 'quality' => $config['import_image_quality']);
         } else {
             // add output for audio/video file
             $result['outputs'][] = array('type' => 'audio', 'precision' => 0, 'audio_bitrate' => $config['import_audio_bitrate'], 'name' => $config['import_audio_basename'], 'extension' => $config['import_audio_extension'], 'audio_rate' => $config['import_audio_rate']);
             // add output for waveform file
             $result['outputs'][] = array('type' => 'waveform', 'forecolor' => $config['import_waveform_forecolor'], 'backcolor' => $config['import_waveform_backcolor'], 'name' => $config['import_waveform_basename'], 'dimensions' => $config['import_waveform_dimensions'], 'extension' => $config['import_waveform_extension']);
         }
         if ($type == 'video') {
             // add output for sequence files
             $result['outputs'][] = array('type' => 'sequence', 'video_rate' => $config['import_video_rate'], 'quality' => $config['import_image_quality'], 'extension' => $config['import_extension'], 'dimensions' => $config['import_dimensions'], 'path' => '{output.dimensions}x{output.video_rate}');
         }
     }
     if ($err) {
         $result['error'] = $err;
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * Determines the MIME type of the asset based on its file extension.
  * Requires the {@link APACHE_MIME_TYPES} constant to be properly defined.
  * @param string $fileext
  * @return string the asset's MIME type, or an empty string if it could
  *         not be determined
  * @uses mime_type_from_extension
  */
 function get_mime_type($fileext = '')
 {
     if ($this->asset && is_object($this->asset) && $this->asset->has_value('mime_type')) {
         return $this->asset->get_value('mime_type');
     }
     $fileext = empty($fileext) ? $this->asset->get_value('file_type') : $fileext;
     return mime_type_from_extension($fileext, '');
 }
Esempio n. 4
0
/**
 * Determines the MIME type of an actual file using any available techniques:
 * <code>getimagesize()</code>, the PHP Fileinfo extension, the UNIX
 * <code>file(1)</code> utility, or the mime.types file.
 * 
 * @param string $path the path to the file whose MIME types is desired
 * @param string $default what to return if the type cannot be determined
 * @param string $filename if <code>$path</code> does not reflect the actual
 *        name of the file (e.g., the path has no file extension), pass the
 *        true filename here
 * @return string the determined MIME type, or <code>$default</code> if the
 *         type could not be determined
 */
function get_mime_type($path, $default = null, $filename = null)
{
    $type = _get_mime_type_fileinfo($path);
    if (!$type || $type == 'application/octet-stream') {
        $type = _get_mime_type_unix($path);
    }
    if (!$filename) {
        $filename = basename($path);
    }
    $extension = strtolower(ltrim(strrchr($filename, '.'), '.'));
    $type = _sanity_check_mime_type($extension, $type);
    if (!$type || $type == 'application/octet-stream') {
        if (!$filename) {
            $filename = $path;
        }
        $type = mime_type_from_extension($extension);
    }
    if (!$type || mime_type_matches('image/*', $type)) {
        // If we detected an image type, verify it using getimageinfo().
        // If the image was not valid, the type will be reset to NULL.
        $type = _get_mime_type_image($path);
    }
    return $type ? $type : $default;
}