Exemplo n.º 1
0
function get_nodes_from_zipfiles_in_dir($dir)
{
    if (!is_dir($dir)) {
        throw new Exception('get_nodes_from_zipfiles_in_dir(): not directory.');
    }
    if (!($dir_handler = opendir($dir))) {
        throw new Exception('get_nodes_from_zipfiles_in_dir(): cannot open directory.');
    }
    $nodes = array();
    while (($name = readdir($dir_handler)) !== false) {
        if ($name == '.' || $name == '..') {
            continue;
        }
        // should ignore all .xxx
        if (extract_file_ext($name) != 'zip') {
            continue;
        }
        $repository_id = filename_without_ext($name);
        $node_id = get_node_id_from_repository_id($repository_id);
        if ($node_id == 0) {
            watchdog('editcol', "get_node_id_from_repository_id({$repository_id}) fail");
        } else {
            $nodes[$repository_id] = $node_id;
        }
    }
    return $nodes;
}
Exemplo n.º 2
0
$video_format = array('mpg' => NULL, 'mpeg' => NULL, 'mp4' => NULL, 'm4p' => NULL, 'w4v' => NULL, 'mp2' => NULL, 'mpe' => NULL, 'mpv' => NULL, 'm2v' => NULL, 'm4v' => NULL, 'webm' => NULL, 'mkv' => NULL, 'flv' => NULL, 'ogv' => NULL, 'ogg' => NULL, 'mov' => NULL, 'qt' => NULL, 'avi' => NULL, 'wmv' => NULL, 'asf' => NULL, 'rm' => NULL, 'rmvb' => NULL, '3gp' => NULL, '3g2' => NULL);
foreach ($archives as $archive) {
    $store = $archive['store'];
    $collection_id = $archive['collection_id'];
    $files = $archive['files'];
    $store_dir = $store;
    $src_path = drupal_realpath('public://') . DIRECTORY_SEPARATOR . 'digicoll' . DIRECTORY_SEPARATOR . 'archive' . DIRECTORY_SEPARATOR . $store_dir;
    $target_path = drupal_realpath('public://') . DIRECTORY_SEPARATOR . 'digicoll' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . $store_dir;
    if (!file_exists($target_path)) {
        mkdir($target_path);
    }
    // make sure the target path
    $result = array();
    foreach ($files as $file_name) {
        $ext = strtolower(extract_file_ext($file_name));
        $file_name_no_ext = filename_without_ext($file_name);
        $src = $src_path . DIRECTORY_SEPARATOR . $file_name;
        if (array_key_exists($ext, $video_format)) {
            $target = $target_path . DIRECTORY_SEPARATOR . $file_name_no_ext . '.webm';
            $cmd = "/usr/bin/avconv -y -i {$src} -s '480x360' -f webm -bt 700k {$target} 2> /dev/null";
        } else {
            if (array_key_exists($ext, $image_format)) {
                $target = $target_path . DIRECTORY_SEPARATOR . $file_name_no_ext . '.jpg';
                $cmd = "/usr/bin/convert {$src} {$target} 2> /dev/null";
            } else {
                $cmd = NULL;
            }
        }
        if (!empty($cmd)) {
            exec($cmd, $output, $status);
            // blocking here until finish