ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilPreviewGUI Class Reference
+ Collaboration diagram for ilPreviewGUI:

Public Member Functions

 __construct ($a_node_id=null, $a_context=self::CONTEXT_REPOSITORY, $a_obj_id=null, $a_access_handler=null)
 Creates a new preview GUI. More...
 
executeCommand ()
 execute command More...
 
 getJSCall ($a_html_id)
 Gets the JavaScript code to show the preview. More...
 
 getPreviewHTML ()
 Gets the HTML that displays the preview. More...
 
 getInlineHTML ()
 Gets the HTML that is used for displaying the preview inline. More...
 
 renderPreview ()
 Renders the preview and returns the HTML code that displays the preview. More...
 
 deletePreview ()
 Deletes the preview and returns the HTML code that displays the preview. More...
 

Data Fields

const CONTEXT_REPOSITORY = 1
 
const CONTEXT_WORKSPACE = 2
 

Private Member Functions

 renderCommand ($tmpl, $a_cmd, $btn_topic, $loading_topic, $a_display_status)
 Renders a command to the specified template. More...
 
 getHtmlId ()
 Gets the HTML id for the preview. More...
 
 buildUrl ($a_cmd="", $a_async=true)
 Builds the URL to call the preview GUI. More...
 

Static Private Member Functions

static initPreview ()
 Initializes the preview and loads the needed javascripts and styles. More...
 
static jsonSafeString ($text)
 Makes the specified string safe for JSON. More...
 

Private Attributes

 $node_id = null
 
 $obj_id = null
 
 $preview = null
 
 $access_handler = null
 
 $context = null
 
 $ctrl = null
 
 $lng = null
 

Static Private Attributes

static $initialized = false
 

Detailed Description

Definition at line 15 of file class.ilPreviewGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilPreviewGUI::__construct (   $a_node_id = null,
  $a_context = self::CONTEXT_REPOSITORY,
  $a_obj_id = null,
  $a_access_handler = null 
)

Creates a new preview GUI.

Parameters
int$a_node_idThe node id.
int$a_contextThe context of the preview.
int$a_obj_idThe object id.
object$a_access_handlerThe access handler to use.

Definition at line 61 of file class.ilPreviewGUI.php.

62 {
63 global $ilCtrl, $lng, $ilAccess;
64
65 // if we are the base class, get the id's from the query string
66 if (strtolower($_GET["baseClass"]) == "ilpreviewgui")
67 {
68 $this->node_id = (int)$_GET["node_id"];
69 $this->context = (int)$_GET["context"];
70 $a_obj_id = (int)$_GET['obj_id'];
71 }
72 else
73 {
74 $this->node_id = $a_node_id;
75 $this->context = $a_context;
76 }
77
78 // assign values
79 $this->ctrl =& $ilCtrl;
80 $this->lng =& $lng;
81
82 // access handler NOT provided?
83 if ($a_access_handler == null)
84 {
85 if ($this->context == self::CONTEXT_WORKSPACE)
86 {
87 include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php");
88 $a_access_handler = new ilWorkspaceAccessHandler();
89 }
90 else
91 {
92 $a_access_handler = $ilAccess;
93 }
94 }
95 $this->access_handler = $a_access_handler;
96
97 // object id NOT provided?
98 if ($a_obj_id == null)
99 {
100 if ($this->context == self::CONTEXT_WORKSPACE)
101 $a_obj_id = $this->access_handler->getTree()->lookupObjectId($this->node_id);
102 else
103 $a_obj_id = ilObject::_lookupObjId($this->node_id);
104 }
105 $this->obj_id = $a_obj_id;
106
107 // create preview object
108 $this->preview = new ilPreview($this->obj_id);
109
110 // if the call is NOT async initialize our stuff
111 if (!$ilCtrl->isAsynch())
113 }
$_GET["client_id"]
static _lookupObjId($a_id)
static initPreview()
Initializes the preview and loads the needed javascripts and styles.
Access handler for personal workspace.
global $ilCtrl
Definition: ilias.php:18

References $_GET, $ilCtrl, $lng, ilObject\_lookupObjId(), and initPreview().

+ Here is the call graph for this function:

Member Function Documentation

◆ buildUrl()

ilPreviewGUI::buildUrl (   $a_cmd = "",
  $a_async = true 
)
private

Builds the URL to call the preview GUI.

Parameters
$a_cmdstring The command to call.
$a_asyncbool true, to create a URL to call asynchronous; otherwise, false.
Returns
string The created URL.

Definition at line 339 of file class.ilPreviewGUI.php.

340 {
341 $link = "ilias.php?baseClass=ilPreviewGUI&node_id={$this->node_id}&context={$this->context}&obj_id={$this->obj_id}";
342
343 if ($a_async)
344 $link .= "&cmdMode=asynch";
345
346 if (!empty($a_cmd))
347 $link .= "&cmd=$a_cmd";
348
349 return $link;
350 }

Referenced by getJSCall(), and renderCommand().

+ Here is the caller graph for this function:

◆ deletePreview()

ilPreviewGUI::deletePreview ( )

Deletes the preview and returns the HTML code that displays the preview.

Returns
string The HTML code that displays the preview.

Definition at line 311 of file class.ilPreviewGUI.php.

312 {
313 // has read access?
314 if ($this->access_handler->checkAccess("write", "", $this->node_id))
315 {
316 // get the preview
317 require_once("./Services/Preview/classes/class.ilPreview.php");
318 $this->preview->delete();
319 }
320
321 return $this->getPreviewHTML();
322 }
getPreviewHTML()
Gets the HTML that displays the preview.

References getPreviewHTML().

+ Here is the call graph for this function:

◆ executeCommand()

& ilPreviewGUI::executeCommand ( )

execute command

Definition at line 118 of file class.ilPreviewGUI.php.

119 {
120 $cmd = $this->ctrl->getCmd("getPreviewHTML");
121 $next_class = $this->ctrl->getNextClass($this);
122
123 switch($next_class)
124 {
125 default:
126 return $this->$cmd();
127 break;
128 }
129 }
$cmd
Definition: sahs_server.php:35

References $cmd.

◆ getHtmlId()

ilPreviewGUI::getHtmlId ( )
private

Gets the HTML id for the preview.

Returns
string The HTML id to use for the preview.

Definition at line 328 of file class.ilPreviewGUI.php.

329 {
330 return "preview_" . $this->node_id;
331 }

References $node_id.

Referenced by getPreviewHTML(), and renderCommand().

+ Here is the caller graph for this function:

◆ getInlineHTML()

ilPreviewGUI::getInlineHTML ( )

Gets the HTML that is used for displaying the preview inline.

Returns
string The HTML that is used for displaying the preview inline.

Definition at line 231 of file class.ilPreviewGUI.php.

232 {
233 $tmpl = new ilTemplate("tpl.preview_inline.html", true, true, "Services/Preview");
234 $tmpl->setVariable("PREVIEW", $this->getPreviewHTML());
235
236 // rendering allowed?
237 if ($this->access_handler->checkAccess("read", "", $this->node_id))
238 {
239 $this->renderCommand(
240 $tmpl,
241 "render",
242 "preview_create",
243 "preview_status_creating",
245 }
246
247 // delete allowed?
248 if ($this->access_handler->checkAccess("write", "", $this->node_id))
249 {
250 $this->renderCommand(
251 $tmpl,
252 "delete",
253 "preview_delete",
254 "preview_status_deleting",
256 }
257
258 return $tmpl->get();
259 }
renderCommand($tmpl, $a_cmd, $btn_topic, $loading_topic, $a_display_status)
Renders a command to the specified template.
const RENDER_STATUS_NONE
const RENDER_STATUS_FAILED
const RENDER_STATUS_CREATED
special template class to simplify handling of ITX/PEAR

References getPreviewHTML(), ilPreview\RENDER_STATUS_CREATED, ilPreview\RENDER_STATUS_FAILED, ilPreview\RENDER_STATUS_NONE, and renderCommand().

+ Here is the call graph for this function:

◆ getJSCall()

ilPreviewGUI::getJSCall (   $a_html_id)

Gets the JavaScript code to show the preview.

Parameters
$a_html_idstring The id of the HTML element that contains the preview.
Returns
string The JavaScript code to show the preview.

Definition at line 136 of file class.ilPreviewGUI.php.

137 {
138 $status = $this->preview->getRenderStatus();
139 $command = $status == ilPreview::RENDER_STATUS_NONE ? "renderPreview" : "";
140 $loading_text = self::jsonSafeString($this->lng->txt($status == ilPreview::RENDER_STATUS_NONE ? "preview_status_creating" : "preview_loading"));
141
142 // build the url
143 $link = $this->buildUrl($command);
144 return "il.Preview.toggle(event, { id: '{$this->node_id}', htmlId: '{$a_html_id}', url: '$link', status: '$status', loadingText: '$loading_text' });";
145 }
static jsonSafeString($text)
Makes the specified string safe for JSON.
buildUrl($a_cmd="", $a_async=true)
Builds the URL to call the preview GUI.

References buildUrl(), jsonSafeString(), and ilPreview\RENDER_STATUS_NONE.

+ Here is the call graph for this function:

◆ getPreviewHTML()

ilPreviewGUI::getPreviewHTML ( )

Gets the HTML that displays the preview.

Returns
string The HTML that displays the preview.

Definition at line 151 of file class.ilPreviewGUI.php.

152 {
153 require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
154 // load the template
155 $tmpl = new ilTemplate("tpl.preview.html", true, true, "Services/Preview");
156 $tmpl->setVariable("PREVIEW_ID", $this->getHtmlId());
157
158 // check for read access and get object id
159 $preview_status = $this->preview->getRenderStatus();
160
161 // has read access?
162 if ($this->access_handler->checkAccess("read", "", $this->node_id))
163 {
164 // preview images available?
165 $images = $this->preview->getImages();
166 if (count($images) > 0)
167 {
168 foreach ($images as $image)
169 {
170 $tmpl->setCurrentBlock("preview_item");
171 $tmpl->setVariable("IMG_URL", ilWACSignedPath::signFile($image["url"]));
172 $tmpl->setVariable("WIDTH", $image["width"]);
173 $tmpl->setVariable("HEIGHT", $image["height"]);
174 $tmpl->parseCurrentBlock();
175 }
176 }
177 else
178 {
179 // set text depending on the status
180 $tmpl->setCurrentBlock("no_preview");
181 switch ($preview_status)
182 {
184 $tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("preview_status_pending"));
185 break;
186
188 $tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("preview_status_failed"));
189 break;
190
191 default:
192 $tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("preview_status_missing"));
193 break;
194 }
195 $tmpl->parseCurrentBlock();
196 }
197 }
198 else
199 {
200 // display error message
201 $tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("no_access_item"));
202 }
203
204 // output
205 if ($this->ctrl->isAsynch())
206 {
207 include_once("./Services/JSON/classes/class.ilJsonUtil.php");
208
209 $response = new stdClass();
210 $response->html = $tmpl->get();
211 $response->status = $preview_status;
212
213 // send response object (don't use 'application/json' as IE wants to download it!)
214 header('Vary: Accept');
215 header('Content-type: text/plain');
216 echo ilJsonUtil::encode($response);
217
218 // no further processing!
219 exit;
220 }
221 else
222 {
223 return $tmpl->get();
224 }
225 }
static encode($mixed, $suppress_native=false)
getHtmlId()
Gets the HTML id for the preview.
const RENDER_STATUS_PENDING
static signFile($path_to_file)
exit
Definition: login.php:54

References ilJsonUtil\encode(), exit, getHtmlId(), ilPreview\RENDER_STATUS_FAILED, ilPreview\RENDER_STATUS_PENDING, and ilWACSignedPath\signFile().

Referenced by deletePreview(), getInlineHTML(), and renderPreview().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initPreview()

static ilPreviewGUI::initPreview ( )
staticprivate

Initializes the preview and loads the needed javascripts and styles.

Definition at line 355 of file class.ilPreviewGUI.php.

356 {
357 if (self::$initialized)
358 return;
359
360 global $tpl, $lng, $ilCtrl;
361
362
363 // jquery
364 include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
366
367 // load qtip
368 include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
370
371 // needed scripts & styles
372 $tpl->addJavaScript("./Services/Preview/js/jquery.mousewheel.js");
373 $tpl->addJavaScript("./Services/Preview/js/ilPreview.js");
374 $tpl->addCss(ilUtil::getStyleSheetLocation("filesystem", "preview.css", "Services/Preview"));
375
376 // create loading template
377 $tmpl = new ilTemplate("tpl.preview.html", true, true, "Services/Preview");
378 $tmpl->setCurrentBlock("no_preview");
379 $tmpl->setVariable("TXT_NO_PREVIEW", "%%0%%");
380 $tmpl->parseCurrentBlock();
381
382 $initialHtml = str_replace(array("\r\n", "\r"), "\n", $tmpl->get());
383 $lines = explode("\n", $initialHtml);
384 $new_lines = array();
385 foreach ($lines as $i => $line)
386 {
387 if(!empty($line))
388 $new_lines[] = trim($line);
389 }
390 $initialHtml = implode($new_lines);
391
392 // add default texts and values
393 include_once("./Services/JSON/classes/class.ilJsonUtil.php");
394 $tpl->addOnLoadCode("il.Preview.texts.preview = \"" . self::jsonSafeString($lng->txt("preview")) . "\";");
395 $tpl->addOnLoadCode("il.Preview.texts.showPreview = \"" . self::jsonSafeString($lng->txt("preview_show")) . "\";");
396 $tpl->addOnLoadCode("il.Preview.texts.close = \"" . ilUtil::prepareFormOutput($lng->txt("close")) . "\";");
397 $tpl->addOnLoadCode("il.Preview.previewSize = " . ilPreviewSettings::getImageSize() . ";");
398 $tpl->addOnLoadCode("il.Preview.initialHtml = " . ilJsonUtil::encode($initialHtml) . ";");
399 $tpl->addOnLoadCode("il.Preview.highlightClass = \"ilContainerListItemOuterHighlight\";");
400 $tpl->addOnLoadCode("il.Preview.init();");
401
402 self::$initialized = true;
403 }
global $tpl
Definition: ilias.php:8
static getImageSize()
Gets the size of the preview images in pixels.
static initLibrary()
Initializes the needed tooltip libraries.
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
static initjQuery($a_tpl=null)
Init jQuery.

References $ilCtrl, $lng, $tpl, ilJsonUtil\encode(), ilPreviewSettings\getImageSize(), ilUtil\getStyleSheetLocation(), iljQueryUtil\initjQuery(), ilTooltipGUI\initLibrary(), and ilUtil\prepareFormOutput().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jsonSafeString()

static ilPreviewGUI::jsonSafeString (   $text)
staticprivate

Makes the specified string safe for JSON.

Parameters
string$textThe text to make JSON safe.
Returns
The JSON safe text.

Definition at line 411 of file class.ilPreviewGUI.php.

412 {
413 if (!is_string($text))
414 return $text;
415
416 $text = htmlentities($text, ENT_COMPAT | ENT_HTML401, "UTF-8");
417 $text = str_replace("'", "'", $text);
418 return $text;
419 }
$text

References $text.

Referenced by getJSCall(), and renderCommand().

+ Here is the caller graph for this function:

◆ renderCommand()

ilPreviewGUI::renderCommand (   $tmpl,
  $a_cmd,
  $btn_topic,
  $loading_topic,
  $a_display_status 
)
private

Renders a command to the specified template.

Parameters
$tmplobject The template.
$a_cmdstring The command to create.
$btn_topicstring The topic to get the button text.
$loading_topicstring The topic to get the loading text.
$a_display_statusarray An array containing the statuses when the command should be visible.

Definition at line 269 of file class.ilPreviewGUI.php.

270 {
271 $preview_html_id = $this->getHtmlId();
272 $preview_status = $this->preview->getRenderStatus();
273 $loading_text = self::jsonSafeString($this->lng->txt($loading_topic));
274
275 $link = $this->buildUrl($a_cmd . "Preview");
276 $script_args = "event, { id: '{$this->node_id}', htmlId: '$preview_html_id', url: '$link', loadingText: '$loading_text' }";
277
278 $action_class = "";
279 if (!is_array($a_display_status) || !in_array($preview_status, $a_display_status))
280 $action_class = "ilPreviewActionHidden";
281
282 $tmpl->setCurrentBlock("preview_action");
283 $tmpl->setVariable("CLICK_ACTION", "il.Preview.$a_cmd($script_args);");
284 $tmpl->setVariable("ACTION_CLASS", "$action_class");
285 $tmpl->setVariable("ACTION_ID", "preview_{$a_cmd}_" . $preview_html_id);
286 $tmpl->setVariable("TXT_ACTION", $this->lng->txt($btn_topic));
287 $tmpl->parseCurrentBlock();
288 }

References buildUrl(), getHtmlId(), and jsonSafeString().

Referenced by getInlineHTML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderPreview()

ilPreviewGUI::renderPreview ( )

Renders the preview and returns the HTML code that displays the preview.

Returns
string The HTML code that displays the preview.

Definition at line 294 of file class.ilPreviewGUI.php.

295 {
296 // has read access?
297 if ($this->access_handler->checkAccess("read", "", $this->node_id))
298 {
299 // get the object
300 $obj = ilObjectFactory::getInstanceByObjId($this->obj_id);
301 $this->preview->create($obj);
302 }
303
304 return $this->getPreviewHTML();
305 }
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id

References ilObjectFactory\getInstanceByObjId(), and getPreviewHTML().

+ Here is the call graph for this function:

Field Documentation

◆ $access_handler

ilPreviewGUI::$access_handler = null
private

Definition at line 33 of file class.ilPreviewGUI.php.

◆ $context

ilPreviewGUI::$context = null
private

Definition at line 37 of file class.ilPreviewGUI.php.

◆ $ctrl

ilPreviewGUI::$ctrl = null
private

Definition at line 41 of file class.ilPreviewGUI.php.

◆ $initialized

ilPreviewGUI::$initialized = false
staticprivate

Definition at line 49 of file class.ilPreviewGUI.php.

◆ $lng

ilPreviewGUI::$lng = null
private

Definition at line 45 of file class.ilPreviewGUI.php.

Referenced by __construct(), and initPreview().

◆ $node_id

ilPreviewGUI::$node_id = null
private

Definition at line 21 of file class.ilPreviewGUI.php.

Referenced by getHtmlId().

◆ $obj_id

ilPreviewGUI::$obj_id = null
private

Definition at line 25 of file class.ilPreviewGUI.php.

◆ $preview

ilPreviewGUI::$preview = null
private

Definition at line 29 of file class.ilPreviewGUI.php.

◆ CONTEXT_REPOSITORY

const ilPreviewGUI::CONTEXT_REPOSITORY = 1

◆ CONTEXT_WORKSPACE

const ilPreviewGUI::CONTEXT_WORKSPACE = 2

The documentation for this class was generated from the following file: