17 include_once (
"FDL/Class.Doc.php");
18 include_once (
"FDL/Class.DocAttr.php");
19 include_once (
"FDL/Lib.Vault.php");
20 include_once (
"VAULT/Class.VaultFile.php");
28 $usage->setDefinitionText(
"Download document attached file");
29 $docid =
$usage->addOptionalParameter(
"docid",
"document identifier", null, 0);
31 $docid =
$usage->addHiddenParameter(
"id",
"document identifier");
34 $vid =
$usage->addHiddenParameter(
"vid",
"vault file identifier - used for tmp file");
35 $usage->addHiddenParameter(
"filename",
"vault file name - not used");
36 $attrid =
$usage->addOptionalParameter(
"attrid",
"attribute identifier");
37 $vaultid =
$usage->addOptionalParameter(
"vaultid",
"public file identifier");
39 if (!
$docid && $attrid ===
"-" && $vid > 0) {
42 $index =
$usage->addOptionalParameter(
"index",
"attribute index identifier");
43 $imgwidth =
$usage->addOptionalParameter(
"width",
"image width use only when file is image");
44 $inline = (
$usage->addOptionalParameter(
"inline",
"inline download", array(
48 $cache = (
$usage->addOptionalParameter(
"cache",
"use http cache", array(
52 $latest =
$usage->addOptionalParameter(
"latest",
"use latest revision", array(
56 $state =
$usage->addOptionalParameter(
"state",
"search doc in this state");
57 $type =
$usage->addOptionalParameter(
"type",
"transformation type", array(
61 $pngpage =
$usage->addOptionalParameter(
"page",
"page number if type=pdf");
63 $cvViewId =
$usage->addOptionalParameter(
"cvViewid",
"view control id");
65 $usage->setStrictMode(
false);
75 header(
'HTTP/1.0 404 Document Not Found');
76 $action->
exitError(sprintf(_(
"Document %s in %s state not found") ,
$doc->title, _($state)));
86 if (!
$doc->isAffected()) {
87 header(
'HTTP/1.0 404 Document Not Found');
93 header(
'HTTP/1.0 403 Forbidden');
94 $action->exiterror(
$err);
99 if ($attrid !==
"icon") {
100 $oa =
$doc->getAttribute($attrid);
102 header(
'HTTP/1.0 404 Attribute Not Found');
103 $action->
exitError(sprintf(_(
"attribute %s not found") , $attrid));
105 if ($oa->type !==
"file" && $oa->type !==
"image") {
106 header(
'HTTP/1.0 403 Incorrect Attribute');
107 $action->
exitError(sprintf(
"Not file attribute : %s ", $attrid));
110 if ($cvViewId !=
"" &&
$doc->cvid > 0) {
115 $cvdoc = clone $cvdoc;
120 $err = $cvdoc->control($cvViewId);
122 header(
'HTTP/1.0 403 Forbidden');
125 $tview = $cvdoc->getView($cvViewId);
127 $mask = $tview[
"CV_MSKID"];
129 $doc->applyMask($mask);
135 if ($oa->mvisibility ==
"I") {
136 header(
'HTTP/1.0 403 Forbidden');
137 $action->
exitError(sprintf(_(
"Cannot see attribute %s") , $attrid));
145 header(
'HTTP/1.0 404 File Not Found');
146 print (sprintf(_(
"no file referenced for %s document") ,
$doc->title));
150 if ($oa && $oa->getOption(
"preventfilechange") ==
"yes") {
160 $fileName = $reg[
"name"];
164 if ($fileName !== $fileInfo->name) {
184 if ($doc->doctype ==
"C") {
188 $ovalue = $doc->getParameterRawValue($attrid);
189 if (!$ovalue) $ovalue = $doc->getDefValue($attrid);
192 if (ctype_digit((
string)$index) && ((
int)$index >= 0)) {
193 $index = (int)$index;
195 if (!isset($tvalue[$index])) {
196 header(
'HTTP/1.0 404 File Not Found');
197 throw new Exception(sprintf(_(
"File not found at index '%s'") , $index));
199 $ovalue = $tvalue[$index];
202 if ($attrid !==
"icon") {
205 header(
'HTTP/1.0 404 Attribute Not Found');
206 throw new Exception(sprintf(_(
"attribute %s not found") , $attrid));
208 if ($oa->type !==
"file" && $oa->type !==
"image") {
209 header(
'HTTP/1.0 403 Incorrect Attribute');
210 throw new Exception(sprintf(
"Not file attribute : %s ", $attrid));
213 if ($oa->mvisibility ==
"I") {
214 header(
'HTTP/1.0 403 Forbidden');
215 throw new Exception(sprintf(_(
"Cannot see attribute %s") , $attrid));
219 $ovalue = $doc->icon;
231 if ($fileValue && preg_match(
PREGEXPFILE, $fileValue, $reg)) {
234 $filePath = $fileInfo->path;
250 if (!
$doc->isAffected()) {
251 $action->
exitError(sprintf(_(
"unknow document reference '%s'") ,
$docid));
253 $attr =
$doc->GetFirstFileAttributes();
254 if (!$attr) $action->exiterror(_(
"no attribute file found"));
256 setHttpVar(
"attrid", $attr->id);
269 if (
$type ==
"pdf") {
272 if (
$err !=
"")
$err = sprintf(_(
"PDF conversion not found")) .
"\n$err";
275 if (substr(
$info->mime_s, 0, 5) ==
"image") {
279 if (
$type ==
"png") {
283 $filecache = sprintf(
"%s/var/cache/file/vid-%s-%d.png",
DEFAULT_PUBDIR,
$info->id_file, $pngpage);
284 if (file_exists($filecache)) {
290 if ($imageSize ===
false) {
295 $owidth = $imageSize[0];
296 $oheight = $imageSize[1];
297 if ($owidth == 0 || $oheight == 0) {
303 $newheight = $oheight * ($width / $owidth);
305 $thumb = imagecreatetruecolor($newwidth, $newheight);
308 imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $owidth, $oheight);
310 header(
'Content-type: image/png');
320 if (!$width) $width = 150;
326 $cmd = sprintf(
"convert -strip -thumbnail %s -auto-orient -density %d %s[%d] %s 2>&1", escapeshellarg($width) , $quality, escapeshellarg(
$info->path) , $pngpage, escapeshellarg(
$cible));
336 if (file_exists(
$cible)) {
344 if ($imageSize ===
false) {
349 $owidth = $imageSize[0];
350 $oheight = $imageSize[1];
351 if ($owidth == 0 || $oheight == 0) {
356 list($owidth, $oheight) = getimagesize(
$filename);
358 $newheight = $oheight * ($width / $owidth);
360 $thumb = imagecreatetruecolor($newwidth, $newheight);
363 imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $owidth, $oheight);
365 header(
'Content-type: image/png');
373 }
else $err = sprintf(_(
"cannot get image transformation for %s") ,
$info->name) .
"\n$err";
377 if (
$info)
$err = sprintf(_(
"conversion png not found for %s") ,
$info->name) .
"\n$err";
381 if ((substr(
$info->mime_s, 0, 5) ==
"image") && ($width > 0)) {
395 if ($isControled || (
$info->public_access) || (
$info->id_tmp)) {
396 $vf->storage->updateAccessDate(
$info->id_file);
398 if ((
$mimetype !=
"image/jpeg") || ($width == 0)) {
399 if ($othername)
$info->name = $othername;
404 $name = str_replace(
'"',
'-',
$info->name);
405 $uName = iconv(
"UTF-8",
"ASCII//TRANSLIT", $name);
406 $name = rawurlencode($name);
409 $nav = $_SERVER[
'HTTP_USER_AGENT'];
410 $pos = strpos($nav,
"MSIE");
413 header(
"Content-Disposition: inline;filename=\"$uName\";filename*=UTF-8''$name;");
416 header(
"Content-Disposition: attachment;filename=\"$uName\";filename*=UTF-8''$name;");
421 header(
'Content-type: image/jpeg');
423 list($owidth, $oheight) = getimagesize(
$filename);
425 $newheight = $oheight * ($width / $owidth);
427 $thumb = imagecreatetruecolor($newwidth, $newheight);
428 $source = imagecreatefromjpeg(
$filename);
430 imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $owidth, $oheight);
435 if (!
$info->public_access) AddlogMsg(sprintf(_(
"%s has be sended") ,
$info->name));
437 $action->exiterror(_(
"file must be controlled : read permission needed"));
452 if (
seems_utf8($text)) $text = utf8_decode($text);
453 $ts = explode(
"\n", $text);
455 foreach ($ts as $string) {
456 $width = max($width, strlen($string));
459 $width = imagefontwidth($font_size) * $width;
461 $height = imagefontheight($font_size) * count($ts);
462 $el = imagefontheight($font_size);
463 $em = imagefontwidth($font_size);
465 $img = imagecreatetruecolor($width, $height);
467 $bg = imagecolorallocate($img, 0xAA, 0x00, 0x00);
469 imagefilledrectangle($img, 0, 0, $width, $height, $bg);
470 $color = imagecolorallocate($img, 255, 255, 255);
472 foreach ($ts as $k => $string) {
474 $len = strlen($string);
477 for ($i = 0; $i < $len; $i++) {
482 imagechar($img, $font_size, $xpos, $ypos, $string, $color);
484 $string = substr($string, 1);
488 header(
"Content-Type: image/png");
504 if (!file_exists(
$dest)) {
505 $cmd = sprintf(
"convert -strip -auto-orient -thumbnail %d %s %s",
$size, escapeshellarg($source) , escapeshellarg(
$dest));
516 if (file_exists(
$file) && ($vid > 0)) {
519 $nbpages = trim(shell_exec(sprintf(
'grep -c "/Type[[:space:]]*/Page>" %s', escapeshellarg(
$file))));
523 while (($f = readdir($dh)) !==
false) {
524 if ($f ==
'.' || $f ==
'..') {
527 if (preg_match(sprintf(
'/^vid-%s-/', preg_quote($vid,
'/')) , $f)) {
534 for ($i = 0; $i < $nbpages; $i++) {
536 $cmd[] = sprintf(
"nice convert -strip -interlace plane -thumbnail %d -density %d %s[%d] %s", $width, $density, escapeshellarg(
$file) , $i, escapeshellarg(
$cible));
vault_uniqname($idfile, $teng_name="")
newFreeVaultFile($dbaccess)
& getAttribute($idAttr, &$oa=null, $useMask=true)
exportfirstfile(Action &$action)
getExportFileDocumentValue(\Doc $doc, $attrid, $index=-1)
static rawValueToArray($v)
DownloadVault(Action &$action, $vaultid, $isControled, $mimetype="", $width="", $inline=false, $cache=true, $type="", $pngpage=0, $othername= '')
static getError($code, $args=null)
createPdf2Png($file, $vid)
exitError($texterr, $exit=true, $code="")
foreach($argv as $arg) $cmd
static getFileInfo($idfile, $teng_name="")
Verify arguments for action function.
new_Doc($dbaccess, $id= '', $latest=false)
Http_DownloadFile($filename, $name, $mime_type= '', $inline=false, $cache=true, $deleteafter=false)
static getArgument($k, $def= '')
getExportFileDocumentPath(\Doc $doc, $attrid, $index=-1)
rezizelocalimage($img, $size, $basedest)
bgexec($tcmd, &$result, &$err)
if($file) if($subject==""&&$file) if($subject=="") $err
getRawValue($idAttr, $def="")
control($aclname, $strict=false)