Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
getfiletransformation.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Retrieve a file converted from source
8  *
9  * @author Anakeen
10  * @version $Id: getfiletransformation.php,v 1.5 2008/10/09 16:12:21 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.Dir.php");
18 /**
19  * Retrieve file converted
20  * @param Action &$action current action
21  * @global string $id Http var : document identifier to see
22  * @global string $tid Http var : transformation is done : tid is set to give result
23  * @global string $zone Http var : specific representation where engine is set
24  * @global string $vid Http var : vault id file to convert if zone is not set
25  * @global string $idv Http var : view identifier to apply mask
26  */
28 {
29  $docid = $action->getArgument("id");
30  $tid = $action->getArgument("tid");
31  $zone = $action->getArgument("zone");
32  $vid = $action->getArgument("vid");
33  $idv = $action->getArgument("idv");
34  $dbaccess = $action->dbaccess;
35 
36  if ($docid == "") $action->exitError(_("no document reference"));
37  if (!is_numeric($docid)) $docid = getIdFromName($dbaccess, $docid);
38  if (intval($docid) == 0) $action->exitError(sprintf(_("unknow logical reference '%s'") , $action->getArgument("id")));
40  if (!$doc->isAffected()) $action->exitError(sprintf(_("cannot see unknow reference %s") , $docid));
41 
42  if ($tid > 0) {
43  $err = downloadTid($tid, $doc->title);
44  if ($err == "") exit;
45  else $action->exitError($err);
46  } else {
47  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/FDL/Layout/getfiletransformation.js");
48  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/resizeimg.js");
49 
50  $err = $doc->control("view");
51  if ($err != "") $action->exitError($err);
52 
53  $action->lay->Set("TITLE", $doc->getHtmltitle());
54  $action->lay->Set("id", $doc->id);
55  $action->lay->Set("icon", $doc->getIcon());
56 
57  if ($zone == "") $zone = $doc->defaultview;
58  $zo = $doc->getZoneOption($zone);
59 
60  $engine = $doc->getZoneTransform($zone);
61  if ($engine) {
62  $tplfile = $doc->getZoneFile($zone);
63  if (($idv != "") && ($doc->cvid)) {
64  /*
65  * @var CVDoc $cvdoc
66  */
67  $cvdoc = new_Doc($dbaccess, $doc->cvid);
68  $cvdoc->set($doc);
69  $err = $cvdoc->control(trim($idv)); // control special view
70  if ($err != "") $action->exitError("CV:" . $cvdoc->title . "\n" . $err);
71  $tview = $cvdoc->getView($idv);
72  if ($tview["CV_MSKID"]) $doc->setMask($tview["CV_MSKID"]);
73  }
74  if (preg_match('/\.odt/', $tplfile)) {
75  $target = "ooo";
76  $file = $doc->viewdoc($zone, $target, $ulink = false);
77  } else {
78  $file = uniqid(getTmpDir() . "/doc") . "-" . $doc->id . ".html";
79  if ($zo == "S") $view = $doc->viewdoc($zone, "te");
80  else $view = completeHTMLDoc($doc, $zone);
81  file_put_contents($file, preg_replace("/<script([^>]*)>.*?<\/script>/is", "", $view));
82  }
83 
84  $ulink = false;
86  //@unlink($file);
87  $action->lay->set("error", ($err != ""));
88  if ($err == "") {
89  $action->lay->set("tid", $info["tid"]);
90  $action->lay->set("status", $info["status"]);
91  $action->lay->eset("message", $info["comment"]);
92  $action->lay->set("processtext", sprintf(_("processing <b>%s</b> transformation") , $engine));
93  } else {
94 
95  $action->lay->set("tid", "");
96  $action->lay->set("status", "K");
97  $action->lay->eset("message", $err);
98  $action->lay->eset("processtext", sprintf(_("cannot lauch <b>%s</b> transformation") , $engine));
99  }
100  }
101  }
102 }
103 
104 function completeHTMLDoc(Doc & $doc, $zone)
105 {
106  global $action;
107  $layout = "singledoc.xml"; // the default
108  $docmail = new Layout(getLayoutFile("FDL", $layout) , $action);
109 
110  $docmail->Set("TITLE", $doc->title);
111  $docmail->Set("iconsrc", $doc->getIcon());
112  $docmail->Set("ID", $doc->id);
113  $docmail->Set("zone", $zone);
114  $docmail->Set("baseurl", dirname($action->getParam("TE_URLINDEX")) . "/");
115 
116  return $docmail->gen();
117 }
118 
120 {
121  $tea = getParam("TE_ACTIVATE");
122  $err = '';
123  if ($tea != "yes" || !\Dcp\Autoloader::classExists('Dcp\TransformationEngine\Client')) return '';
124  global $action;
125  include_once ("FDL/insertfile.php");
126 
127  $filename = uniqid(getTmpDir() . "/tid-" . $tid);
129  $mime = getSysMimeFile($filename, basename($filename));
130  $ext = getExtension($mime);
131  if ($ext) $ext = '.' . $ext;
132  if ($err == "") {
133  Http_DownloadFile($filename, $title . "$ext", $mime, false, false);
134  @unlink($filename);
135  }
136 
137  return $err;
138 }
139 
141 {
142  $err = '';
143  if (file_exists($filename) && ($engine != "")) {
144 
145  $tea = getParam("TE_ACTIVATE");
146  if ($tea != "yes") return _("TE engine is not activate");
147  if (\Dcp\Autoloader::classExists('Dcp\TransformationEngine\Client')) {
148  global $action;
149  include_once ("FDL/Class.TaskRequest.php");
150 
151  $callback = "";
152  $ot = new \Dcp\TransformationEngine\Client(getParam("TE_HOST") , getParam("TE_PORT"));
153  $err = $ot->sendTransformation($engine, $vid = 0, $filename, $callback, $info);
154  if ($err == "") {
155  $dbaccess = $action->dbaccess;
156  $tr = new TaskRequest($dbaccess);
157  $tr->tid = $info["tid"];
158  $tr->fkey = $vid;
159  $tr->status = $info["status"];
160  $tr->comment = $info["comment"];
161  $tr->uid = $action->user->id;
162  $tr->uname = $action->user->firstname . " " . $action->user->lastname;
163  $err = $tr->Add();
164  }
165  } else {
166  AddWarningMsg(_("TE engine activate but TE-CLIENT not found"));
167  }
168  } else {
169  $err = "no file filename ($filename) or engine ($engine)";
170  }
171  return $err;
172 }
Layout is a template generator.
global $action
getfiletransformation(Action &$action)
completeHTMLDoc(Doc &$doc, $zone)
sendRequestForFileTransformation($filename, $engine, &$info)
$filename
getIcon($idicon="", $size=null, $otherId=null)
Definition: Class.Doc.php:5817
getSysMimeFile($f, $fn="")
$file
Set($name, &$parent)
exitError($texterr, $exit=true, $code="")
$docid
Definition: cleanFamily.php:13
getLayoutFile($app, $layfile)
Definition: Lib.Common.php:258
getParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:193
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
switch($command) exit
Definition: checkVault.php:46
new_Doc($dbaccess, $id= '', $latest=false)
Http_DownloadFile($filename, $name, $mime_type= '', $inline=false, $cache=true, $deleteafter=false)
Definition: Lib.Http.php:225
static getArgument($k, $def= '')
$dbaccess
Definition: checkVault.php:17
$info
Definition: geticon.php:30
getIdFromName($dbaccess, $name)
getTEFile($tid, $filename, &$info)
Definition: insertfile.php:117
downloadTid($tid, $title)
getExtension($smime)
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen