/**
 *
 * exporting attachment files related to item.
 *
 * @param string $export_path storing directory name
 * @param resource $fhdl file handle that items are exported to.
 * @param int $item_id id of item with attachment files to export.
 * @return array( 'path' => $export_path,
 *                   'attachments' => array( file path of attachment1, file path of attachment2, ... ) )
 *            (relative path of $export_filepath)
 *         returns false if it failed
 */
function xnpExportFile($export_path, $fhdl, $item_id)
{
    $file = xnpGetFileInfo('t_file.file_id, t_file_type.name, t_file.original_file_name, t_file.file_size, t_file.mime_type, t_file.thumbnail_file, t_file.caption', "item_id = {$item_id} and is_deleted=0", $item_id);
    if (!$fhdl) {
        return false;
    }
    // create files directory under $export_path.
    $dir = $export_path . '/files';
    if (!file_exists($dir)) {
        if (!mkdir($dir)) {
            xoonips_error("can't make directory '{$dir}'");
            return false;
        }
    }
    // for absolete path of attachment file
    $files = array();
    foreach ($file as $f) {
        $file = array();
        list($file['file_id'], $file['file_type_name'], $file['original_file_name'], $file['file_size'], $file['mime_type'], $file['thumbnail_file'], $file['caption']) = $f;
        // copy atatchment file $file['file_id'] to $dir and renamed to original file name
        // output <file> to file handle $fhdl
        $hdl = fopen(xnpGetUploadFilePath($file['file_id']), 'rb');
        if (file_exists(xnpGetUploadFilePath($file['file_id']))) {
            if (!copy(xnpGetUploadFilePath($file['file_id']), $dir . '/' . $file['file_id'])) {
                xoonips_error('can\'t write a file \'' . $dir . '/' . $file['file_id'] . "' of the item(ID={$item_id})");
                return false;
            }
            if (!fwrite($fhdl, '<file' . " item_id=\"{$item_id}\"" . " file_type_name=\"{$file['file_type_name']}\"" . " original_file_name=\"{$file['original_file_name']}\"" . " file_name=\"files/{$file['file_id']}\"" . " file_size=\"{$file['file_size']}\"" . " mime_type=\"{$file['mime_type']}\"" . ">\n" . (isset($file['thumbnail_file']) ? '<thumbnail>' . base64_encode($file['thumbnail_file']) . "</thumbnail>\n" : '') . '<caption>' . $file['caption'] . "</caption>\n" . "</file>\n")) {
                fclose($hdl);
                xoonips_error("can't export <file> of the item(ID={$item_id})");
                return false;
            }
            $files[] = "files/{$file['file_id']}";
        }
    }
    return true;
}
Ejemplo n.º 2
0
function xnpurlGetUrlBannerFileConfirmBlock($item_id)
{
    $formdata =& xoonips_getutility('formdata');
    $name = 'url_banner_file';
    $url_banner_file = $formdata->getFile($name, false);
    if (!empty($url_banner_file['name'])) {
        // file has been Uploaded
        list($fileID, $errorMessage) = xnpUploadFile($name, false);
        if ($fileID == false) {
            $errorHTML = '<font color=\'#ff0000\'>' . htmlspecialchars($errorMessage) . '</font><br />';
            return array('name' => 'Attachment', 'value' => $errorHTML);
        } else {
            $sql = "t_file.file_id = {$fileID}";
        }
    } else {
        $attachmentFileID = $formdata->getValue('post', $name . 'FileID', 'i', false);
        if ($attachmentFileID == 0) {
            // no files should be attached
            $sql = ' 0 ';
        } else {
            $sql = "t_file.file_id = {$attachmentFileID}";
        }
    }
    $files = xnpGetFileInfo('t_file.file_id, t_file.original_file_name, t_file.file_size', "t_file_type.name='{$name}' and {$sql} ", $item_id);
    if (count($files) == 0) {
        $html = "<input type='hidden' name='{$name}FileID' value=''>";
    } else {
        // todo: to be downloadable
        list(list($fileID, $fileName, $fileSize)) = $files;
        $imageFileName = XOOPS_URL . "/modules/xoonips/image.php?file_id={$fileID}";
        $html = "<input type='hidden' name='{$name}FileID' value='{$fileID}'><img src='{$imageFileName}'>";
    }
    // generate html
    return array('name' => 'Attachment', 'value' => $html);
}
 /**
  * get total download count of specified file type of item.
  *
  * @param integer $item_id item id to get total download count
  * @param integer $file_type_nameid file id to get total download count
  * @param integer total donwload count
  */
 function getTotalDownloadCount($item_id, $file_type_name)
 {
     list($tmp) = xnpGetFileInfo('sum(t_file.download_count)', 't_file_type.name=\'' . addslashes($file_type_name) . '\' and sess_id is NULL ', $item_id);
     return $tmp[0];
 }
Ejemplo n.º 4
0
function xnpIsAttachmentModified($file_type, $item_id)
{
    //return true if uploaded successfully
    $formdata =& xoonips_getutility('formdata');
    $file = $formdata->getFile($file_type, false);
    if (isset($file) && $file['error'] == 0) {
        return true;
    }
    // get file_id of preview file before change
    $tmp = xnpGetFileInfo("t_file.file_id", "t_file_type.name='{$file_type}' and sess_id is NULL and is_deleted=0", $item_id);
    $old_files = array();
    $new_files = array();
    foreach ($tmp as $i) {
        $old_files[] = $i[0];
    }
    $fileID = $formdata->getValue('post', $file_type . 'FileID', 's', false);
    if (isset($fileID) && $fileID != '') {
        $new_files = explode(',', $fileID);
    }
    return count(array_diff($old_files, $new_files)) > 0 || count(array_diff($new_files, $old_files)) > 0;
}