4 require_once(
"./Services/Preview/classes/class.ilPreviewSettings.php");
5 require_once(
"./Services/Preview/classes/class.ilPreview.php");
37 public function __construct($a_node_id = null, $a_context = self::CONTEXT_REPOSITORY, $a_obj_id = null, $a_access_handler = null)
42 if (strtolower(
$_GET[
"baseClass"]) ==
"ilpreviewgui")
44 $this->node_id = (int)
$_GET[
"node_id"];
45 $this->context = (int)
$_GET[
"context"];
49 $this->node_id = $a_node_id;
50 $this->context = $a_context;
58 if ($a_access_handler == null)
60 if ($this->context == self::CONTEXT_WORKSPACE)
62 include_once(
"./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php");
67 $a_access_handler = $ilAccess;
70 $this->access_handler = $a_access_handler;
73 if ($a_obj_id == null)
75 if ($this->context == self::CONTEXT_WORKSPACE)
76 $a_obj_id = $this->access_handler->getTree()->lookupObjectId($this->node_id);
80 $this->obj_id = $a_obj_id;
83 $this->preview =
new ilPreview($this->obj_id);
86 if (!$ilCtrl->isAsynch())
95 $cmd = $this->ctrl->getCmd(
"getPreviewHTML");
96 $next_class = $this->ctrl->getNextClass($this);
101 return $this->
$cmd();
113 $status = $this->preview->getRenderStatus();
119 return "il.Preview.toggle(event, { id: '{$this->node_id}', htmlId: '{$a_html_id}', url: '$link', status: '$status', loadingText: '$loading_text' });";
129 $tmpl =
new ilTemplate(
"tpl.preview.html",
true,
true,
"Services/Preview");
130 $tmpl->setVariable(
"PREVIEW_ID", $this->
getHtmlId());
133 $preview_status = $this->preview->getRenderStatus();
136 if ($this->access_handler->checkAccess(
"read",
"", $this->node_id))
139 $images = $this->preview->getImages();
140 if (count($images) > 0)
142 foreach ($images as $image)
144 $tmpl->setCurrentBlock(
"preview_item");
145 $tmpl->setVariable(
"IMG_URL", $image[
"url"]);
146 $tmpl->setVariable(
"WIDTH", $image[
"width"]);
147 $tmpl->setVariable(
"HEIGHT", $image[
"height"]);
148 $tmpl->parseCurrentBlock();
154 $tmpl->setCurrentBlock(
"no_preview");
155 switch ($preview_status)
158 $tmpl->setVariable(
"TXT_NO_PREVIEW", $this->lng->txt(
"preview_status_pending"));
162 $tmpl->setVariable(
"TXT_NO_PREVIEW", $this->lng->txt(
"preview_status_failed"));
166 $tmpl->setVariable(
"TXT_NO_PREVIEW", $this->lng->txt(
"preview_status_missing"));
169 $tmpl->parseCurrentBlock();
175 $tmpl->setVariable(
"TXT_NO_PREVIEW", $this->lng->txt(
"no_access_item"));
179 if ($this->ctrl->isAsynch())
181 include_once(
"./Services/JSON/classes/class.ilJsonUtil.php");
183 $response =
new stdClass();
184 $response->html = $tmpl->get();
185 $response->status = $preview_status;
188 header(
'Vary: Accept');
189 header(
'Content-type: text/plain');
207 $tmpl =
new ilTemplate(
"tpl.preview_inline.html",
true,
true,
"Services/Preview");
211 if ($this->access_handler->checkAccess(
"read",
"", $this->node_id))
217 "preview_status_creating",
222 if ($this->access_handler->checkAccess(
"write",
"", $this->node_id))
228 "preview_status_deleting",
243 private function renderCommand($tmpl, $a_cmd, $btn_topic, $loading_topic, $a_display_status)
246 $preview_status = $this->preview->getRenderStatus();
249 $link = $this->
buildUrl($a_cmd .
"Preview");
250 $script_args =
"event, { id: '{$this->node_id}', htmlId: '$preview_html_id', url: '$link', loadingText: '$loading_text' }";
253 if (!is_array($a_display_status) || !in_array($preview_status, $a_display_status))
254 $action_class =
"ilPreviewActionHidden";
256 $tmpl->setCurrentBlock(
"preview_action");
257 $tmpl->setVariable(
"CLICK_ACTION",
"il.Preview.$a_cmd($script_args);");
258 $tmpl->setVariable(
"ACTION_CLASS",
"$action_class");
259 $tmpl->setVariable(
"ACTION_ID",
"preview_{$a_cmd}_" . $this->node_id);
260 $tmpl->setVariable(
"TXT_ACTION", $this->lng->txt($btn_topic));
261 $tmpl->parseCurrentBlock();
271 if ($this->access_handler->checkAccess(
"read",
"", $this->node_id))
275 $this->preview->create($obj);
288 if ($this->access_handler->checkAccess(
"write",
"", $this->node_id))
291 require_once(
"./Services/Preview/classes/class.ilPreview.php");
292 $this->preview->delete();
313 private function buildUrl($a_cmd =
"", $a_async =
true)
315 $link =
"ilias.php?baseClass=ilPreviewGUI&node_id={$this->node_id}&context={$this->context}";
318 $link .=
"&cmdMode=asynch";
321 $link .=
"&cmd=$a_cmd";
331 if (self::$initialized)
338 include_once(
"./Services/jQuery/classes/class.iljQueryUtil.php");
342 include_once(
"./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
346 $tpl->addJavaScript(
"./Services/Preview/js/jquery.mousewheel.js");
347 $tpl->addJavaScript(
"./Services/Preview/js/ilPreview.js");
351 $tmpl =
new ilTemplate(
"tpl.preview.html",
true,
true,
"Services/Preview");
352 $tmpl->setCurrentBlock(
"no_preview");
353 $tmpl->setVariable(
"TXT_NO_PREVIEW",
"%%0%%");
354 $tmpl->parseCurrentBlock();
356 $initialHtml = str_replace(array(
"\r\n",
"\r"),
"\n", $tmpl->get());
357 $lines = explode(
"\n", $initialHtml);
358 $new_lines = array();
359 foreach ($lines as $i => $line)
362 $new_lines[] = trim($line);
364 $initialHtml = implode($new_lines);
367 include_once(
"./Services/JSON/classes/class.ilJsonUtil.php");
368 $tpl->addOnLoadCode(
"il.Preview.texts.preview = \"" . self::jsonSafeString($lng->txt(
"preview")) .
"\";");
369 $tpl->addOnLoadCode(
"il.Preview.texts.showPreview = \"" . self::jsonSafeString($lng->txt(
"preview_show")) .
"\";");
370 $tpl->addOnLoadCode(
"il.Preview.texts.close = \"" . self::jsonSafeString($lng->txt(
"close")) .
"\";");
372 $tpl->addOnLoadCode(
"il.Preview.initialHtml = " .
ilJsonUtil::encode($initialHtml) .
";");
373 $tpl->addOnLoadCode(
"il.Preview.highlightClass = \"ilContainerListItemOuterHighlight\";");
374 $tpl->addOnLoadCode(
"il.Preview.init();");
376 self::$initialized =
true;
387 if (!is_string($text))
390 $text = htmlentities($text, ENT_COMPAT | ENT_HTML401,
"UTF-8");
391 $text = str_replace(
"'",
"'", $text);