Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
insertfile.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Insert rendering file which comes from transformation engine
9  *
10  * @author Anakeen 2007
11  * @version $Id: insertfile.php,v 1.8 2007/12/10 09:15:03 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 
19 include_once ("FDL/Class.Doc.php");
20 include_once ("FDL/Class.TaskRequest.php");
21 include_once ("WHAT/Class.TEClient.php");
22 include_once ("Lib.FileMime.php");
23 /**
24  * Modify the attrid_txt attribute
25  * @param Action &$action current action
26  * @global docid Http var : document identificator to modify
27  * @global attrid Http var : the id of attribute to modify
28  * @global index Http var : the range in case of array
29  * @global tid Http var : task identificator
30  *
31  */
32 function insertfile(&$action)
33 {
34  $vidin = GetHttpVars("vidin");
35  $vidout = GetHttpVars("vidout");
36  $tid = GetHttpVars("tid");
37  $name = GetHttpVars("name");
38  $engine = GetHttpVars("engine");
39  $isimage = (GetHttpVars("isimage") != "");
40  $docid = GetHttpVars("docid");
41  $dbaccess = $action->GetParam("FREEDOM_DB");
42 
43  if (!$tid) $err = _("no task identificator found");
44  else {
45  $filename = uniqid(getTmpDir() . "/txt-" . $vidout . '-');
46  $err = getTEFile($tid, $filename, $info);
47  if ($err == "") {
48 
49  $outfile = $info["outfile"];
50  $status = $info["status"];
51 
52  if (($status == 'D') && ($outfile != '')) {
53 
55  $err = $vf->Retrieve($vidin, $infoin);
56  $err = $vf->Retrieve($vidout, $infoout);
57  $err = $vf->Save($filename, false, $vidout);
58  $err = $vf->Retrieve($vidout, $infoout); // relaod for mime
59  $ext = getExtension($infoout->mime_s);
60  if ($ext == "") $ext = $infoout->teng_lname;
61  // print_r($infoout);
62  // print_r($ext);
63  if ($name != "") {
64  $newname = $name;
65  } else {
66  $pp = strrpos($infoin->name, '.');
67  $newname = substr($infoin->name, 0, $pp) . '.' . $ext;
68  }
69 
70  $vf->Rename($vidout, $newname);
71  $vf->storage->teng_state = 1;
72  $vf->storage->modify();
73 
74  if ($engine == "pdf") {
75  //createPdf2Png($infoout->path,$vidout );
76 
77  }
78 
79  @unlink($filename);
80  } else {
82  $err = $vf->Retrieve($vidin, $infoin);
83  $err = $vf->Retrieve($vidout, $infoout);
84 
85  $filename = uniqid(getTmpDir() . "/txt-" . $vidout . '-');
86  $error = sprintf(_("Conversion as %s has failed ") , $infoout->teng_lname);
87  $error.= "\n== " . _("See below information about conversion") . "==\n" . print_r($info, true);
88  file_put_contents($filename, $error);
89  //$vf->rename($vidout,"toto.txt");
90  $vf->Retrieve($vidout, $infoout);
91  $err = $vf->Save($filename, false, $vidout);
92  $basename = _("conversion error") . ".txt";
93  $vf->Rename($vidout, $basename);
94  $vf->storage->teng_state = TransformationEngine::error_convert;
95  $vf->storage->modify();
96  if ($docid) {
97  $doc = new_doc($dbaccess, $docid);
98  if ($doc->isAlive()) {
99  $doc->addComment(sprintf(_("convert file %s as %s failed") , $infoin->name, $infoout->teng_lname) , HISTO_ERROR);
100  }
101  }
102  }
103  }
104  }
105 
106  if ($err != '') $action->lay->template = $err;
107  else $action->lay->template = "OK : " . sprintf(_("vid %d stored") , $vidout);
108 }
109 /**
110  * return filename where is stored produced file
111  * need to delete after use it
112  */
113 function getTEFile($tid, $filename, &$info)
114 {
115  global $action;
116  $dbaccess = $action->GetParam("FREEDOM_DB");
117  $ot = new TransformationEngine($action->getParam("TE_HOST") , $action->getParam("TE_PORT"));
118 
119  $err = $ot->getInfo($tid, $info);
120  if ($err == "") {
121  $tr = new TaskRequest($dbaccess, $tid);
122  if ($tr->isAffected()) {
123  $outfile = $info["outfile"];
124  $status = $info["status"];
125 
126  if (($status == 'D') && ($outfile != '')) {
127  $err = $ot->getTransformation($tid, $filename);
128  //$err=$ot->getAndLeaveTransformation($tid,$filename); // to debug
129 
130  }
131  } else {
132  $err = sprintf(_("task %s is not recorded") , $tid);
133  }
134  }
135  return $err;
136 }
137 function createPdf2Png($file, $vid)
138 {
139  if (file_exists($file) && ($vid > 0)) {
140  $density = 200;
141  $width = 1200;
142  $nbpages = trim(shell_exec(sprintf('grep -c "/Type[[:space:]]*/Page>" %s', escapeshellarg($file))));
143  $cmd[] = sprintf("/bin/rm -f %s/vid-%d*.png;", DEFAULT_PUBDIR . "/.img-resize", $vid);
144 
145  for ($i = 0; $i < $nbpages; $i++) {
146  $cible = DEFAULT_PUBDIR . "/.img-resize/vid-${vid}-${i}.png";
147  print $cible;
148  $cmd[] = sprintf("nice convert -interlace plane -thumbnail %d -density %d %s[%d] %s", $width, $density, $file, $i, $cible);
149  }
150  bgexec($cmd, $result, $err);
151  }
152 }
153 ?>
← centre documentaire © anakeen - published under CC License - Dynacase