function config_defaults($config = array())
 {
     $config['authentication'] = empty($config['authentication']) ? '' : $config['authentication'];
     $config['aws_access_key_id'] = empty($config['aws_access_key_id']) ? '' : $config['aws_access_key_id'];
     $config['aws_secret_access_key'] = empty($config['aws_secret_access_key']) ? '' : $config['aws_secret_access_key'];
     $config['export_audio_codec_audio'] = empty($config['export_audio_codec_audio']) ? 'libmp3lame' : $config['export_audio_codec_audio'];
     $config['export_audio_bitrate'] = empty($config['export_audio_bitrate']) ? '128' : $config['export_audio_bitrate'];
     $config['export_audio_codec'] = empty($config['export_audio_codec']) ? 'aac' : $config['export_audio_codec'];
     $config['export_audio_extension'] = empty($config['export_audio_extension']) ? 'mp3' : $config['export_audio_extension'];
     $config['export_audio_rate'] = empty($config['export_audio_rate']) ? '44100' : $config['export_audio_rate'];
     $config['export_dimensions'] = empty($config['export_dimensions']) ? '512x288' : $config['export_dimensions'];
     $config['export_extension'] = empty($config['export_extension']) ? 'mp4' : $config['export_extension'];
     $config['export_video_rate'] = empty($config['export_video_rate']) ? '30' : $config['export_video_rate'];
     $config['export_meta_title'] = empty($config['export_meta_title']) ? '' : $config['export_meta_title'];
     $config['export_video_bitrate'] = empty($config['export_video_bitrate']) ? '2000' : $config['export_video_bitrate'];
     $config['export_video_codec'] = empty($config['export_video_codec']) ? 'libx264' : $config['export_video_codec'];
     $config['web_root_directory'] = empty($config['web_root_directory']) ? $_SERVER['DOCUMENT_ROOT'] : $config['web_root_directory'];
     $config['temporary_directory'] = empty($config['temporary_directory']) ? sys_get_temp_dir() : $config['temporary_directory'];
     $config['queue_directory'] = empty($config['queue_directory']) ? path_concat($config['temporary_directory'], 'queue') : $config['queue_directory'];
     $config['import_audio_bitrate'] = empty($config['import_audio_bitrate']) ? '128' : $config['import_audio_bitrate'];
     $config['import_audio_extension'] = empty($config['import_audio_extension']) ? 'mp3' : $config['import_audio_extension'];
     $config['import_audio_basename'] = empty($config['import_audio_basename']) ? 'audio' : $config['import_audio_basename'];
     $config['import_audio_rate'] = empty($config['import_audio_rate']) ? '44100' : $config['import_audio_rate'];
     $config['import_dimensions'] = empty($config['import_dimensions']) ? '256x144' : $config['import_dimensions'];
     $config['import_extension'] = empty($config['import_extension']) ? 'jpg' : $config['import_extension'];
     $config['import_video_rate'] = empty($config['import_video_rate']) ? '10' : $config['import_video_rate'];
     $config['import_image_quality'] = empty($config['import_image_quality']) ? '1' : $config['import_image_quality'];
     $config['import_original_basename'] = empty($config['import_original_basename']) ? 'original' : $config['import_original_basename'];
     $config['import_waveform_backcolor'] = empty($config['import_waveform_backcolor']) ? 'FFFFFF' : $config['import_waveform_backcolor'];
     $config['import_waveform_basename'] = empty($config['import_waveform_basename']) ? 'waveform' : $config['import_waveform_basename'];
     $config['import_waveform_dimensions'] = empty($config['import_waveform_dimensions']) ? '8000x32' : $config['import_waveform_dimensions'];
     $config['import_waveform_extension'] = empty($config['import_waveform_extension']) ? 'png' : $config['import_waveform_extension'];
     $config['import_waveform_forecolor'] = empty($config['import_waveform_forecolor']) ? '000000' : $config['import_waveform_forecolor'];
     $config['module_host'] = empty($config['module_host']) ? $_SERVER['HTTP_HOST'] : http_get_contents($config['module_host']);
     $config['user_media_host'] = empty($config['user_media_host']) ? $_SERVER['HTTP_HOST'] : http_get_contents($config['user_media_host']);
     $config['callback_host'] = empty($config['callback_host']) ? $_SERVER['HTTP_HOST'] : http_get_contents($config['callback_host']);
     $config['log_request'] = empty($config['log_request']) ? '' : $config['log_request'];
     $config['log_response'] = empty($config['log_response']) ? '' : $config['log_response'];
     $config['log_api_request'] = empty($config['log_api_request']) ? '' : $config['log_api_request'];
     $config['log_api_response'] = empty($config['log_api_response']) ? '' : $config['log_api_response'];
     $config['max_meg_audio'] = empty($config['max_meg_audio']) ? '' : $config['max_meg_audio'];
     $config['max_meg_image'] = empty($config['max_meg_image']) ? '' : $config['max_meg_image'];
     $config['max_meg_video'] = empty($config['max_meg_video']) ? '' : $config['max_meg_video'];
     $config['log_file'] = empty($config['log_file']) ? '' : $config['log_file'];
     $config['callback_directory'] = empty($config['callback_directory']) ? substr(dirname(dirname(__FILE__)), strlen(path_add_slash_end($config['web_root_directory']))) : $config['callback_directory'];
     $config['install_directory'] = empty($config['install_directory']) ? substr(dirname(dirname(dirname(__FILE__))), strlen(path_add_slash_end($config['web_root_directory']))) : $config['install_directory'];
     $config['cgi_directory'] = empty($config['cgi_directory']) ? substr(dirname(dirname(__FILE__)), strlen(path_add_slash_end(path_concat($config['web_root_directory'], $config['install_directory'])))) : $config['cgi_directory'];
     $config['user_media_directory'] = isset($config['user_media_directory']) ? $config['user_media_directory'] : path_concat(substr(dirname(dirname(dirname(__FILE__))), strlen(path_add_slash_end(path_concat($config['web_root_directory'], $config['install_directory'])))), 'user');
     $config['user_media_url'] = isset($config['user_media_url']) ? $config['user_media_url'] : $config['user_media_directory'];
     $config['user_data_directory'] = isset($config['user_data_directory']) ? $config['user_data_directory'] : path_concat(substr(dirname(dirname(dirname(__FILE__))), strlen(path_add_slash_end($config['web_root_directory']))), 'user');
     $config['module_directory'] = empty($config['module_directory']) ? substr(dirname(dirname(dirname(__FILE__))), strlen(path_add_slash_end($config['web_root_directory']))) : $config['module_directory'];
     $config['s3_bucket'] = empty($config['s3_bucket']) ? '' : $config['s3_bucket'];
     $config['s3_region'] = empty($config['s3_region']) ? '' : $config['s3_region'];
     $config['sqs_queue_url'] = empty($config['sqs_queue_url']) ? '' : $config['sqs_queue_url'];
     $config['chmod_directory_new'] = isset($config['chmod_directory_new']) ? $config['chmod_directory_new'] : '0775';
     $config = service_config_defaults($config);
     ksort($config);
     return $config;
 }
Exemplo n.º 2
0
 function path_concat($s1, $s2)
 {
     if (is_null($s1) || empty($s1)) {
         $s1 = '';
     }
     if (is_null($s2) || empty($s2)) {
         $s2 = '';
     }
     if (is_null($s1) || empty($s1) || (is_null($s2) || empty($s2))) {
         $s1 .= $s2;
     } else {
         $s1 = path_add_slash_end($s1) . path_strip_slash_start($s2);
     }
     return $s1;
 }
Exemplo n.º 3
0
function s3_file_import_init($import, $config)
{
    $response = array();
    $err = '';
    if (!$err) {
        $response['api'] = array();
        $response['data'] = array();
        $response['method'] = 'put';
        $id = id_unique();
        $bucket = $config['s3_bucket'];
        $region = $config['s3_region'] ? $config['s3_region'] : 'us-east-1';
        $key = path_strip_slash_start($config['user_media_directory']);
        // remove bucket name from url if it's there
        if (substr($key, 0, strlen($bucket)) == $bucket) {
            $key = substr($key, strlen(path_add_slash_end($bucket)));
        }
        $key = path_concat(path_concat(path_concat($key, $import['uid']), $id), $config['import_original_basename'] . '.' . $import['extension']);
        $options_array = ['version' => 'latest', 'region' => $region];
        if ($config['aws_secret_access_key'] && $config['aws_access_key_id']) {
            $options_array['credentials'] = [];
            $options_array['credentials']['key'] = $config['aws_access_key_id'];
            $options_array['credentials']['secret'] = $config['aws_secret_access_key'];
        }
        try {
            $s3 = new Aws\S3\S3Client($options_array);
            $cmd = $s3->getCommand('PutObject', ['Bucket' => $config['s3_bucket'], 'Key' => $key, 'ACL' => $config['s3_acl'], 'ContentType' => $import['mime']]);
            $request = $s3->createPresignedRequest($cmd, $config['s3_expires']);
            // Get the actual presigned-url
            $response['endpoint'] = $presignedUrl = (string) $request->getUri();
        } catch (Exception $e) {
            $err = $e->getMessage();
        }
        // data key children all become part of the POST file upload request
        $response['api']['id'] = $id;
        $response['api']['type'] = $import['type'];
        $response['api']['extension'] = $import['extension'];
        $response['api']['label'] = $import['label'];
    }
    if ($err) {
        $response['error'] = $err;
    }
    return $response;
}
Exemplo n.º 4
0
 function data_search($options = array(), $config = array())
 {
     $found_obs = array();
     $json_obs = array();
     if (!$config) {
         $config = config_get();
     }
     if (!config_error($config)) {
         $dir_host = $config['web_root_directory'];
         $module_dir = path_concat(path_concat($dir_host, $config['module_directory']), 'module');
         $userid = empty($options['uid']) ? '' : $options['uid'];
         $group = empty($options['group']) ? '' : $options['group'];
         $index = empty($options['index']) ? 0 : $options['index'];
         $count = empty($options['count']) ? 1000 : $options['count'];
         $query = empty($options['query']) ? '' : $options['query'];
         if ($group) {
             switch ($group) {
                 // group parameter determines which xml file we search through
                 case 'mash':
                 case 'video':
                 case 'audio':
                 case 'image':
                     if ($userid) {
                         $path = path_concat(path_concat(path_concat($dir_host, $config['user_data_directory']), $userid), 'media_' . $group . '.json');
                         if (file_exists($path)) {
                             $json_obs = array_merge(json_array(file_get($path)), $json_obs);
                         }
                     }
                     break;
                 default:
                     // modules
                     // look for filenames ending in $group.json in first and second tiers of module directory
                     $base_path = path_add_slash_end($module_dir) . '*/*';
                     $glob_path = $base_path . $group . '.json';
                     $glob_files = glob($glob_path);
                     $glob_path = $base_path . '/*' . $group . '.json';
                     $glob_files = array_merge($glob_files, glob($glob_path));
                     foreach ($glob_files as $file_path) {
                         $obs = json_array(file_get($file_path));
                         $html_path = str_replace('.json', '.html', $file_path);
                         if (file_exists($html_path)) {
                             $html_path = substr($html_path, strlen(path_add_slash_end($dir_host)) - 1);
                             for ($i = 0; $i < sizeof($obs); $i++) {
                                 $obs[$i]['html'] = $html_path;
                             }
                         }
                         $json_obs = array_merge($obs, $json_obs);
                     }
             }
             if ($json_obs) {
                 foreach ($json_obs as $ob) {
                     $ok = 1;
                     if ($query) {
                         reset($query);
                         // loop through all parameters
                         foreach ($query as $k => $v) {
                             $test = (string) $ob[$k];
                             // will match if parameter is empty, equal to or (for label) within attribute
                             $ok = !$v || $v == $test || $k == 'label' && strpos(strtolower($test), strtolower($v)) !== FALSE;
                             if (!$ok) {
                                 break;
                             }
                         }
                     }
                     if ($ok) {
                         if ($index) {
                             $index--;
                         } else {
                             // only add tag if within specified range
                             $found_obs[] = $ob;
                             $count--;
                             if (!$count) {
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $found_obs;
 }
Exemplo n.º 5
0
 function api_import_data($response = array(), $config = array())
 {
     $media_data = array();
     if (!$config) {
         $config = config_get();
     }
     $err = config_error($config);
     if (!$err) {
         $id = empty($response['id']) ? '' : $response['id'];
         $uid = empty($response['uid']) ? '' : $response['uid'];
         if (!($id && $uid)) {
             $err = 'Parameters id, uid required';
         }
     }
     if (!$err) {
         // pull in other configuration and check for required input
         $import_video_rate = $config['import_video_rate'];
         $import_extension = $config['import_extension'];
         $media_url = service_import_url($response, $config);
         //log_file('api_import_data ' . $media_url . ' ' . print_r($response, 1), $config);
     }
     if (!$err) {
         $media_extension = empty($response['extension']) ? '' : $response['extension'];
         $type = empty($response['type']) ? '' : $response['type'];
         switch ($type) {
             case 'image':
                 $import_video_rate = '1';
                 $import_extension = $media_extension;
                 break;
             case 'video':
             case 'audio':
                 break;
             default:
                 $err = 'could not determine type of preprocessed upload';
         }
         if (!($import_extension && $type)) {
             $err = 'Could not determine type and extension';
         }
     }
     if (!$err) {
         $duration = empty($response['duration']) ? '' : $response['duration'];
         $label = empty($response['label']) ? '' : $response['label'];
         $media_data['id'] = $id;
         $media_data['label'] = $label;
         // add source with original for rendering
         $media_data['source'] = path_concat(path_concat($media_url, $id), $config['import_original_basename'] . '.' . $media_extension);
         $frame_path = path_concat(path_concat($media_url, $id), $config['import_dimensions'] . 'x' . $import_video_rate);
         $audio = 1;
         $did_icon = 0;
         $did_url = 0;
         switch ($type) {
             case 'image':
                 $frame_path = path_concat($frame_path, '0.' . $import_extension);
                 $media_data['url'] = $frame_path;
                 $media_data['icon'] = $frame_path;
                 break;
             case 'video':
                 $audio = !(empty($response['no_audio']) || 'false' == $response['no_audio'] ? '' : $response['no_audio']);
                 $video = !(empty($response['no_video']) || 'false' == $response['no_video'] ? '' : $response['no_video']);
                 if ($video) {
                     $frames = floor($duration * $import_video_rate);
                     $zero_padding = strlen($frames);
                     $media_data['url'] = path_add_slash_end($frame_path);
                     $media_data['video_rate'] = $import_video_rate;
                     $media_data['pattern'] = '%.' . $import_extension;
                     $media_data['icon'] = path_concat($frame_path, str_pad(ceil($frames / 2), $zero_padding, '0', STR_PAD_LEFT) . '.' . $import_extension);
                     $did_icon = 1;
                 } else {
                     $type = 'audio';
                     $did_url = 1;
                     $media_data['url'] = path_concat(path_concat($media_url, $id), $config['import_audio_basename'] . '.' . $config['import_audio_extension']);
                 }
                 // intentional fall through to audio
             case 'audio':
                 if (!$duration) {
                     $err = 'Could not determine duration';
                 } else {
                     $media_data['duration'] = $duration;
                     if ($audio) {
                         if (!$did_url) {
                             $media_data['audio'] = path_concat(path_concat($media_url, $id), $config['import_audio_basename'] . '.' . $config['import_audio_extension']);
                         }
                         $media_data['wave'] = path_concat(path_concat($media_url, $id), $config['import_waveform_basename'] . '.' . $config['import_waveform_extension']);
                         if (!$did_icon) {
                             $media_data['icon'] = $media_data['wave'];
                         }
                     } else {
                         $media_data['audio'] = '0';
                     }
                     // put in a zero to indicate that there is no audio
                 }
                 break;
         }
         $media_data['group'] = $media_data['type'] = $type;
     }
     if ($err) {
         $media_data['error'] = $err;
     }
     return $media_data;
 }
Exemplo n.º 6
0
 function files_in_dir($dir, $just_names = FALSE, $filter = 'files')
 {
     $result = FALSE;
     if ($dir && is_dir($dir)) {
         $dir = path_add_slash_end($dir);
         if ($handle = opendir($dir)) {
             $result = array();
             while (FALSE !== ($file = readdir($handle))) {
                 if ($file != "." && $file != "..") {
                     $full_path = $dir . $file;
                     if (!$just_names) {
                         $file = $full_path;
                     }
                     switch ($filter) {
                         case 'files':
                             if (is_file($full_path)) {
                                 $result[] = $file;
                             }
                             break;
                         case 'dirs':
                             if (is_dir($full_path)) {
                                 $result[] = $file;
                             }
                             break;
                         default:
                             $result[] = $file;
                     }
                 }
             }
             closedir($handle);
         }
     }
     return $result;
 }
Exemplo n.º 7
0
function __s3_key($id, $import, $config, $prefix = 's3')
{
    $bucket = $config[$prefix . '_bucket'];
    $key = path_strip_slash_start($config['user_media_directory']);
    // remove bucket name from url if it's there
    if (substr($key, 0, strlen($bucket)) == $bucket) {
        $key = substr($key, strlen(path_add_slash_end($bucket)));
    }
    $key = path_concat(path_concat(path_concat($key, $import['uid']), $id), $config['import_original_basename'] . '.' . $import['extension']);
    return $key;
}