Platform  3.1
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  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Retrieve a file converted from source
9  *
10  * @author Anakeen 2008
11  * @version $Id: getfiletransformation.php,v 1.5 2008/10/09 16:12:21 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.Dir.php");
20 /**
21  * Retrieve file converted
22  * @param Action &$action current action
23  * @global id Http var : document identificator to see
24  * @global tid Http var : transformation is done : tid is set to give result
25  * @global zone Http var : specific representation where engine is set
26  * @global vid Http var : vault id file to convert if zone is not set
27  * @global idv Http var : view identificator to apply mask
28  */
30 {
31  $docid = GetHttpVars("id");
32  $tid = GetHttpVars("tid");
33  $zone = GetHttpVars("zone");
34  $vid = GetHttpVars("vid");
35  $idv = GetHttpVars("idv");
36  $dbaccess = $action->GetParam("FREEDOM_DB");
37 
38  if ($docid == "") $action->exitError(_("no document reference"));
39  if (!is_numeric($docid)) $docid = getIdFromName($dbaccess, $docid);
40  if (intval($docid) == 0) $action->exitError(sprintf(_("unknow logical reference '%s'") , GetHttpVars("id")));
42  if (!$doc->isAffected()) $action->exitError(sprintf(_("cannot see unknow reference %s") , $docid));
43 
44  if ($tid > 0) {
45  $err = downloadTid($tid, $doc->title);
46  if ($err == "") exit;
47  else $action->exitError($err);
48  } else {
49  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/FDL/Layout/getfiletransformation.js");
50  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/resizeimg.js");
51 
52  $err = $doc->control("view");
53  if ($err != "") $action->exitError($err);
54 
55  $action->lay->Set("TITLE", $doc->title);
56  $action->lay->Set("id", $docid);
57  $action->lay->Set("icon", $doc->getIcon());
58 
59  if ($zone == "") $zone = $doc->defaultview;
60  $zo = $doc->getZoneOption($zone);
61 
62  $engine = $doc->getZoneTransform($zone);
63  if ($engine) {
64  $tplfile = $doc->getZoneFile($zone);
65  if (($idv != "") && ($doc->cvid)) {
66  $cvdoc = new_Doc($dbaccess, $doc->cvid);
67  $err = $cvdoc->control(trim($idv)); // control special view
68  if ($err != "") $action->exitError("CV:" . $cvdoc->title . "\n" . $err);
69  $tview = $cvdoc->getView($idv);
70  if ($tview["CV_MSKID"]) $doc->setMask($tview["CV_MSKID"]);
71  }
72  if (preg_match('/\.odt/', $tplfile)) {
73  $target = "ooo";
74  $file = $doc->viewdoc($zone, $target, $ulink);
75  } else {
76  $file = uniqid(getTmpDir() . "/doc") . "-" . $doc->id . ".html";
77  if ($zo == "S") $view = $doc->viewdoc($zone, "te");
78  else $view = completeHTMLDoc($doc, $zone);
79  file_put_contents($file, preg_replace("/<script([^>]*)>.*?<\/script>/is", "", $view));
80  }
81 
82  $ulink = false;
83  $err = sendRequestForFileTransformation($file, $engine, $info);
84  //@unlink($file);
85  $action->lay->set("error", ($err != ""));
86  if ($err == "") {
87  $action->lay->set("tid", $info["tid"]);
88  $action->lay->set("status", $info["status"]);
89  $action->lay->set("message", $info["comment"]);
90  $action->lay->set("processtext", sprintf(_("processing <b>%s</b> transformation") , $engine));
91  } else {
92 
93  $action->lay->set("tid", "");
94  $action->lay->set("status", "K");
95  $action->lay->set("message", $err);
96  $action->lay->set("processtext", sprintf(_("cannot lauch <b>%s</b> transformation") , $engine));
97  }
98  }
99  }
100 }
101 
102 function completeHTMLDoc(&$doc, $zone)
103 {
104  global $action;
105  $layout = "singledoc.xml"; // the default
106  $docmail = new Layout(getLayoutFile("FDL", $layout) , $action);
107 
108  $docmail->Set("TITLE", $doc->title);
109  $docmail->Set("iconsrc", $doc->getIcon());
110  $docmail->Set("ID", $doc->id);
111  $docmail->Set("zone", $zone);
112  $docmail->Set("baseurl", dirname($action->getParam("TE_URLINDEX")) . "/");
113 
114  return $docmail->gen();
115 }
116 
118 {
119  $tea = getParam("TE_ACTIVATE");
120  if ($tea != "yes") return;
121  if (@include_once ("WHAT/Class.TEClient.php")) {
122  global $action;
123  include_once ("FDL/insertfile.php");
124 
125  $filename = uniqid(getTmpDir() . "/tid-" . $tid);
126  $err = getTEFile($tid, $filename, $info);
127  $mime = getSysMimeFile($filename, basename($filename));
128  $ext = getExtension($mime);
129  if ($ext == "") $ext = $infoout->teng_lname;
130  if ($err == "") {
131  Http_DownloadFile($filename, $title . ".$ext", $mime, false, false);
132  @unlink($filename);
133  }
134  } else {
135  AddWarningMsg(_("TE engine activate but TE-CLIENT not found"));
136  }
137 
138  return $err;
139 }
140 
141 function sendRequestForFileTransformation($filename, $engine, &$info)
142 {
143  if (file_exists($filename) && ($engine != "")) {
144 
145  $tea = getParam("TE_ACTIVATE");
146  if ($tea != "yes") return _("TE engine is not activate");
147  if (include_once ("WHAT/Class.TEClient.php")) {
148  global $action;
149  include_once ("FDL/Class.TaskRequest.php");
150 
151  $callback = "";
152  $ot = new TransformationEngine(getParam("TE_HOST") , getParam("TE_PORT"));
153  $err = $ot->sendTransformation($engine, $vid, $filename, $callback, $info);
154  if ($err == "") {
155  $dbaccess = GetParam("FREEDOM_DB");
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 }
173 ?>
← centre documentaire © anakeen - published under CC License - Dynacase