public function add_link($link)
 {
     $meta = Utils_FileStorageCommon::meta($this->id, false);
     return Utils_FileStorageCommon::add_link($link, $meta['id']);
 }
if (!$files_checkpoint->is_done()) {
    if ($files_checkpoint->has('files')) {
        $files = $files_checkpoint->get('files');
    } else {
        $files = 0;
    }
    if ($files_checkpoint->has('files_qty')) {
        $files_qty = $files_checkpoint->get('files_qty');
    } else {
        $files_qty = DB::GetOne('SELECT count(*) FROM utils_attachment_file');
        $files_checkpoint->set('files_qty', $files_qty);
    }
    while ($ret = DB::SelectLimit('SELECT f.id,f.attach_id as aid,f.original FROM utils_attachment_file f ORDER BY f.id', 1, $files++)) {
        $row = $ret->FetchRow();
        if (!$row) {
            break;
        }
        if (file_exists(DATA_DIR . '/Utils_Attachment/' . $row['aid'] . '/' . $row['id'])) {
            Patch::set_message('Processing file: ' . $files . '/' . $files_qty);
            $files_checkpoint->require_time(2);
            $fsid = Utils_FileStorageCommon::write_file($row['original'], DATA_DIR . '/Utils_Attachment/' . $row['aid'] . '/' . $row['id'], 'attachment_file/' . $row['id']);
            unlink(DATA_DIR . '/Utils_Attachment/' . $row['aid'] . '/' . $row['id']);
            DB::Execute('UPDATE utils_attachment_file SET filestorage_id=%d WHERE id=%d', array($fsid, $row['id']));
        }
        $files_checkpoint->set('files', $files);
    }
    $files_checkpoint->done();
}
DB::Execute('DELETE FROM utils_attachment_download WHERE attach_file_id in (SELECT id FROM utils_attachment_file WHERE filestorage_id=0)');
DB::Execute('DELETE FROM utils_attachment_file WHERE filestorage_id=0');
DB::Execute('ALTER TABLE utils_attachment_file ADD FOREIGN KEY (filestorage_id) REFERENCES utils_filestorage_files(id)');
 public static function get_file_leightbox($row, &$view_link = '')
 {
     static $th;
     if (!isset($th)) {
         $th = Base_ThemeCommon::init_smarty();
     }
     if ($row['original'] === '') {
         return '';
     }
     $links = array();
     $lid = 'get_file_' . md5(serialize($row));
     $close_leightbox_js = 'leightbox_deactivate(\'' . $lid . '\');';
     $label = __('View');
     $th->assign('save_options_id', '');
     $script = 'get';
     $onclick = $close_leightbox_js;
     $th->assign('download_options_id', 'attachment_download_options_' . $row['id']);
     $view_link = 'modules/Utils/Attachment/' . $script . '.php?' . http_build_query(array('id' => $row['id'], 'cid' => CID, 'view' => 1));
     $links['view'] = '<a href="' . $view_link . '" target="_blank" onClick="' . $onclick . '">' . $label . '</a><br>';
     $links['download'] = '<a href="modules/Utils/Attachment/get.php?' . http_build_query(array('id' => $row['id'], 'cid' => CID)) . '" onClick="leightbox_deactivate(\'' . $lid . '\')">' . __('Download') . '</a><br>';
     load_js('modules/Utils/Attachment/remote.js');
     if (!$row['crypted']) {
         $links['link'] = '<a href="javascript:void(0)" onClick="utils_attachment_get_link(' . $row['id'] . ', ' . CID . ',\'get link\');leightbox_deactivate(\'' . $lid . '\')">' . __('Get link') . '</a><br>';
     }
     $th->assign('filename', $row['original']);
     $meta = Utils_FileStorageCommon::meta($row['filestorage_id']);
     $f_filename = $meta['file'];
     if (!file_exists($f_filename)) {
         return 'missing file: ' . $f_filename;
     }
     $th->assign('file_size', __('File size: %s', array(filesize_hr($f_filename))));
     $th->assign('labels', array('filename' => __('Filename'), 'file_size' => __('File size')));
     foreach ($links as $key => &$l) {
         $th->assign($key, $l);
         $l = Base_ThemeCommon::parse_links($key, $l);
     }
     $th->assign('__link', $links);
     $custom_getters = array();
     if (!$row['crypted']) {
         $getters = ModuleManager::call_common_methods('attachment_getters');
         foreach ($getters as $mod => $arr) {
             if (is_array($arr)) {
                 foreach ($arr as $caption => $func) {
                     $cus_id = md5($mod . $caption . serialize($func));
                     if (isset($_GET['utils_attachment_custom_getter']) && $_GET['utils_attachment_custom_getter'] == $cus_id) {
                         call_user_func_array(array($mod . 'Common', $func['func']), array($f_filename, $row['original'], $row['id']));
                     }
                     $custom_getters[] = array('open' => '<a href="javascript:void(0)" onClick="' . Epesi::escapeJS(Module::create_href_js(array('utils_attachment_custom_getter' => $cus_id)), true, false) . ';leightbox_deactivate(\'' . $lid . '\')">', 'close' => '</a>', 'text' => $caption, 'icon' => $func['icon']);
                 }
             }
         }
     }
     $th->assign('custom_getters', $custom_getters);
     ob_start();
     Base_ThemeCommon::display_smarty($th, 'Utils_Attachment', 'download');
     $c = ob_get_clean();
     Libs_LeightboxCommon::display($lid, $c, __('Attachment'));
     return Libs_LeightboxCommon::get_open_href($lid);
 }
Exemple #4
0
    die('Permission denied');
}
$file = DB::GetRow('SELECT uaf.attach_id, uaf.original, uaf.filestorage_id FROM utils_attachment_file uaf WHERE uaf.id=%d', array($id));
$rec = Utils_RecordBrowserCommon::get_record('utils_attachment', $file['attach_id']);
if (!$rec) {
    die('Invalid attachment.');
}
$access_fields = Utils_RecordBrowserCommon::get_access('utils_attachment', 'view', $rec);
if (!isset($access_fields['note']) || !$access_fields['note']) {
    die('Access forbidden');
}
$original = $file['original'];
$local = $rec['id'];
$fsid = $file['filestorage_id'];
$crypted = $rec['crypted'];
$meta = Utils_FileStorageCommon::meta($fsid);
require_once 'mime.php';
if (headers_sent()) {
    die('Some data has already been output to browser, can\'t send file');
}
$password = '';
if ($crypted) {
    $password = $_SESSION['client']['cp' . $rec['id']];
}
$t = time();
$remote_address = get_client_ip_address();
$remote_host = gethostbyaddr($remote_address);
DB::Execute('INSERT INTO utils_attachment_download(attach_file_id,created_by,created_on,download_on,description,ip_address,host_name) VALUES (%d,%d,%T,%T,%s,%s,%s)', array($id, Acl::get_user(), $t, $t, $disposition, $remote_address, $remote_host));
if (isset($_REQUEST['thumbnail'])) {
    $o_filename = $meta['file'];
    $f_filename = $o_filename . '_thumbnail';
Exemple #5
0
$files = DB::GetAssoc('SELECT id, original, filestorage_id FROM utils_attachment_file uaf WHERE uaf.attach_id=%d AND uaf.deleted=0', array($id));
$zip_filename = tempnam("tmp", "zip");
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($zip_filename, ZIPARCHIVE::OVERWRITE) !== TRUE) {
    die("cannot open {$zip_filename} for writing - contact with administrator");
}
//add each files of $file_name array to archive
$t = time();
$remote_address = get_client_ip_address();
$remote_host = gethostbyaddr($remote_address);
$local = $rec['id'];
$size = 0;
foreach ($files as $fid => $row) {
    try {
        $meta = Utils_FileStorageCommon::meta($row['filestorage_id']);
    } catch (Exception $e) {
        continue;
    }
    $f_filename = $meta['file'];
    $size += filesize($f_filename);
    @ini_set('memory_limit', ceil($size * 2 / 1024 / 1024 + 64) . 'M');
    $buffer = file_get_contents($f_filename);
    if ($crypted) {
        $buffer = Utils_AttachmentCommon::decrypt($buffer, $password);
        if ($buffer === false) {
            continue;
        }
    }
    DB::Execute('INSERT INTO utils_attachment_download(attach_file_id,created_by,created_on,download_on,description,ip_address,host_name) VALUES (%d,%d,%T,%T,%s,%s,%s)', array($fid, Acl::get_user(), $t, $t, 'zip', $remote_address, $remote_host));
    $zip->addFromString($row['original'], $buffer);