Example #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;
}
Example #2
0
$image_format = array('jpg' => NULL, 'jpeg' => NULL, 'png' => NULL, 'tif' => NULL, 'tiff' => NULL, 'bmp' => NULL, 'gif' => NULL);
$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);
Example #3
0
function ext_unzip_zipfile_of_dir($dir)
{
    //mylog('called', 'ext_unzip.txt');
    if (!is_dir($dir)) {
        throw new Exception('ext_unzip_zipfile_of_dir(): not directory.');
    }
    if (!($dir_handler = opendir($dir))) {
        throw new Exception('ext_unzip_zipfile_of_dir(): cannot open directory.');
    }
    while (($name = readdir($dir_handler)) !== false) {
        if (is_dir($name)) {
            continue;
        }
        $ext = extract_file_ext($name);
        if (empty($ext)) {
            continue;
        }
        if ($ext == 'zip' || $ext == 'ZIP') {
            $to_unzip = $dir . '/' . $name;
            if (ext_unzip($to_unzip)) {
                unlink($to_unzip);
            } else {
                throw new Exception('ext_unzip_zipfile_of_dir(): ext_unzip() error.');
            }
        }
    }
}
Example #4
0
function copy_file($slot_id)
{
    global $nodeinfo, $field_image_file, $field_image_file_name;
    if (!file_exists($field_image_file)) {
        return;
    }
    $ext = extract_file_ext($field_image_file_name);
    if ($ext == "") {
        $exts[] = ".gif";
        $exts[] = ".jpg";
        $exts[] = ".png";
        $arr = getimagesize($field_image_file);
        $ext = $exts[$arr[2] - 1];
    }
    remove_file($slot_id);
    //or else extension-changes would not get notified..
    copy($field_image_file, APPLICATION_HOME . "/html/img/slots/{$slot_id}" . $ext);
}