ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTemplate.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/UICore/lib/html-it/IT.php");
5 include_once("./Services/UICore/lib/html-it/ITX.php");
6 
14 {
19  public $vars;
20  //var $js_files = array(0 => "./Services/JavaScript/js/Basic.js"); // list of JS files that should be included
21  public $js_files = array(); // list of JS files that should be included
22  public $css_files = array(); // list of css files that should be included
23 
30  public $activeBlock;
31 
41  /*function ilTemplate($root)
42  {
43 
44  $this->callConstructor();
45 
46  $this->setRoot($root);
47 
48  return true;
49  }*/
50  public function __construct($file, $flag1, $flag2, $in_module = false, $vars = "DEFAULT")
51  {
52  $this->activeBlock = "__global__";
53  $this->vars = array();
54 
55  $fname = $this->getTemplatePath($file, $in_module);
56 
57  $this->tplName = basename($fname);
58  $this->tplPath = dirname($fname);
59  // set default content-type to text/html
60  $this->contenttype = "text/html";
61  if (!file_exists($fname)) {
62  die("template " . $fname . " was not found.");
63  return false;
64  }
65 
66  //$this->IntegratedTemplateExtension(dirname($fname));
68  //$this->loadTemplatefile(basename($fname), $flag1, $flag2);
69  $this->loadTemplatefile($fname, $flag1, $flag2);
70  //add tplPath to replacevars
71  $this->vars["TPLPATH"] = $this->tplPath;
72 
73  // set Options
74  if (method_exists($this, "setOption")) {
75  $this->setOption('use_preg', false);
76  }
77 
78  return true;
79  }
80 
84  public function printToString() : string
85  {
86  throw new ilException('not implemented');
87  }
88 
89 
98  public function getTemplatePath($a_tplname, $a_in_module = false, $a_plugin = false)
99  {
100  global $ilias, $ilCtrl;
101 
102  // if baseClass functionality is used (ilias.php):
103  // get template directory from ilCtrl
104  if (!empty($_GET["baseClass"]) && $a_in_module === true) {
105  $a_in_module = $ilCtrl->getModuleDir();
106  }
107 
108  if (strpos($a_tplname, "/") === false) {
109  $module_path = "";
110 
111  //$fname = $ilias->tplPath;
112  if ($a_in_module) {
113  if ($a_in_module === true) {
114  $module_path = ILIAS_MODULE . "/";
115  } else {
116  $module_path = $a_in_module . "/";
117  }
118  }
119 
120  if ($fname == "" || !file_exists($fname)) {
121  if ($a_in_module == "setup") {
122  $fname = "./" . $module_path . "templates/" . basename($a_tplname);
123  } else {
124  $fname = "./" . $module_path . "templates/default/" . basename($a_tplname);
125  }
126  }
127  } else {
128  $fname = $a_tplname;
129  }
130 
131  return $fname;
132  }
133 
134  public function addBlockFile($var, $block, $tplname, $in_module = false)
135  {
136  if (DEBUG) {
137  echo "<br/>Template '" . $this->tplPath . "/" . $tplname . "'";
138  }
139 
140  $tplfile = $this->getTemplatePath($tplname, $in_module);
141  if (file_exists($tplfile) == false) {
142  echo "<br/>Template '" . $tplfile . "' doesn't exist! aborting...";
143  return false;
144  }
145 
146  return parent::addBlockFile($var, $block, $tplfile);
147  }
148 
153  public function show($part = "DEFAULT")
154  {
155  header('Content-type: text/html; charset=UTF-8');
156 
157  $this->fillJavaScriptFiles();
158  $this->fillCssFiles();
159 
160  // ERROR HANDLER SETS $_GET["message"] IN CASE OF $error_obj->MESSAGE
161  $ms = array("info", "success", "failure", "question");
162  $out = "";
163 
164  foreach ($ms as $m) {
165  if ($m == "question") {
166  $m = "mess_question";
167  }
168 
169  $txt = (ilSession::get($m) != "")
170  ? ilSession::get($m)
171  : $this->message[$m];
172 
173  if ($m == "mess_question") {
174  $m = "question";
175  }
176 
177  if ($txt != "") {
178  $out .= $this->getMessageHTML($txt, $m);
179  }
180 
181  if ($m == "question") {
182  $m = "mess_question";
183  }
184 
185  if (ilSession::get($m)) {
186  ilSession::clear($m);
187  }
188  }
189 
190  if ($this->blockExists("MESSAGE") && $out != "") {
191  $this->setVariable("MESSAGE", $out);
192  }
193 
194  if ($part == "DEFAULT") {
195  parent::show();
196  } else {
197  parent::show($part);
198  }
199 
200  if (((substr(strrchr($_SERVER["PHP_SELF"], "/"), 1) != "error.php")
201  && (substr(strrchr($_SERVER["PHP_SELF"], "/"), 1) != "adm_menu.php"))) {
202  ilSession::set("post_vars", $_POST);
203 
204  // referer is modified if query string contains cmd=gateway and $_POST is not empty.
205  // this is a workaround to display formular again in case of error and if the referer points to another page
206  $url_parts = parse_url($_SERVER["REQUEST_URI"]);
207  if (!$url_parts) {
208  $protocol = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://';
209  $host = $_SERVER['HTTP_HOST'];
210  $path = $_SERVER['REQUEST_URI'];
211  $url_parts = @parse_url($protocol . $host . $path);
212  }
213 
214  if (preg_match("/cmd=gateway/", $url_parts["query"])) {
215  foreach ($_POST as $key => $val) {
216  if (is_array($val)) {
217  $val = key($val);
218  }
219 
220  $str .= "&" . $key . "=" . $val;
221  }
222 
224  "referer",
225  preg_replace("/cmd=gateway/", substr($str, 1), $_SERVER["REQUEST_URI"])
226  );
228  "referer_ref_id",
229  (int) $_GET['ref_id']
230  );
231  } else {
232  ilSession::set("referer", $_SERVER["REQUEST_URI"]);
234  "referer_ref_id",
235  (int) $_GET['ref_id']
236  );
237  }
238 
239  ilSession::clear("error_post_vars");
240  }
241  }
242 
246  public function getMessageHTML($a_txt, $a_type = "info")
247  {
248  global $lng;
249 
250  $mtpl = new ilTemplate("tpl.message.html", true, true, "Services/Utilities");
251  $mtpl->setCurrentBlock($a_type . "_message");
252  $mtpl->setVariable("TEXT", $a_txt);
253  $mtpl->setVariable("MESSAGE_HEADING", $lng->txt($a_type . "_message"));
254  $mtpl->parseCurrentBlock();
255 
256  return $mtpl->get();
257  }
258 
265  public function setCurrentBlock($part = "DEFAULT")
266  {
267  $this->activeBlock = $part;
268 
269  if ($part == "DEFAULT") {
270  return parent::setCurrentBlock();
271  } else {
272  return parent::setCurrentBlock($part);
273  }
274  }
275 
282  public function touchBlock($block)
283  {
284  $this->setCurrentBlock($block);
285  //$count = $this->fillVars();
286  $this->parseCurrentBlock();
287 
288  if ($count == 0) {
289  parent::touchBlock($block);
290  }
291  }
292 
299  public function parseCurrentBlock($part = "DEFAULT")
300  {
301  // Hier erst noch ein replace aufrufen
302  if ($part != "DEFAULT") {
303  $tmp = $this->activeBlock;
304  $this->activeBlock = $part;
305  }
306 
307  if ($part != "DEFAULT") {
308  $this->activeBlock = $tmp;
309  }
310 
311  //$this->fillVars();
312 
313  $this->activeBlock = "__global__";
314 
315  if ($part == "DEFAULT") {
316  return parent::parseCurrentBlock();
317  } else {
318  return parent::parseCurrentBlock($part);
319  }
320  }
325  public function setOnScreenMessage($a_type, $a_txt, $a_keep = false)
326  {
327  if (!in_array($a_type, array("info", "success", "failure", "question")) || $a_txt == "") {
328  return;
329  }
330  if ($a_type == "question") {
331  $a_type = "mess_question";
332  }
333  if (!$a_keep) {
334  $this->message[$a_type] = $a_txt;
335  } else {
336  ilSession::set($a_type, $a_txt);
337  }
338  }
339 
340  public function fillMessage()
341  {
342  global $lng;
343 
344  $ms = array("info", "success", "failure", "question");
345  $out = "";
346 
347  foreach ($ms as $m) {
348  if ($m == "question") {
349  $m = "mess_question";
350  }
351 
352  $txt = (ilSession::get($m) != "")
353  ? ilSession::get($m)
354  : $this->message[$m];
355 
356  if ($m == "mess_question") {
357  $m = "question";
358  }
359 
360  if ($txt != "") {
361  $mtpl = new ilTemplate("tpl.message.html", true, true, "Services/Utilities");
362  $mtpl->setCurrentBlock($m . "_message");
363  $mtpl->setVariable("TEXT", $txt);
364  $mtpl->setVariable("MESSAGE_HEADING", $lng->txt($m . "_message"));
365  $mtpl->parseCurrentBlock();
366  $out .= $mtpl->get();
367  }
368 
369  if ($m == "question") {
370  $m = "mess_question";
371  }
372 
373  if (ilSession::get($m)) {
374  ilSession::clear($m);
375  }
376  }
377 
378  if ($out != "") {
379  $this->setVariable("MESSAGE", $out);
380  }
381  }
382 
389  public function blockExists($a_blockname)
390  {
391  // added second evaluation to the return statement because the first one only works for the content block (Helmut Schottmüller, 2007-09-14)
392  return (isset($this->blockvariables["content"][$a_blockname]) ? true : false) | (isset($this->blockvariables[$a_blockname]) ? true : false);
393  }
394 
398  public function addJavaScript($a_js_file, $a_add_version_parameter = true, $a_batch = 2)
399  {
400  if (!in_array($a_js_file, $this->js_files)) {
401  $this->js_files[] = $a_js_file;
402  }
403  }
404 
405  public function fillJavaScriptFiles($force = true)
406  {
407  global $ilias,$ilTabs;
408  if ($this->blockExists("js_file")) {
409  foreach ($this->js_files as $file) {
410  if (is_file($file) || substr($file, 0, 4) == "http") {
411  $this->setCurrentBlock("js_file");
412  $this->setVariable("JS_FILE", $file);
413  $this->parseCurrentBlock();
414  }
415  }
416  }
417  }
418 
422  public function addCss($a_css_file, $media = "screen")
423  {
424  if (!array_key_exists($a_css_file . $media, $this->css_files)) {
425  $this->css_files[$a_css_file . $media] = array("file" => $a_css_file, "media" => $media);
426  }
427  }
428 
434  public function fillCssFiles($a_force = false)
435  {
436  if (!$this->blockExists("css_file")) {
437  return;
438  }
439  foreach ($this->css_files as $css) {
440  $filename = $css["file"];
441  if (strpos($filename, "?") > 0) {
442  $filename = substr($filename, 0, strpos($filename, "?"));
443  }
444  if (is_file($filename) || $a_force) {
445  $this->setCurrentBlock("css_file");
446  $this->setVariable("CSS_FILE", $css["file"]);
447  $this->setVariable("CSS_MEDIA", $css["media"]);
448  $this->parseCurrentBlock();
449  }
450  }
451  }
452 
453 
454  public function get($part = "DEFAULT")
455  {
456  if ($part == "DEFAULT") {
457  return parent::get();
458  } else {
459  return parent::get($part);
460  }
461  }
462 
463 
467  public function hideFooter()
468  {
469  // TODO: Implement hideFooter() method.
470  }
471 
472 
473 
474 
475 
479  public function addOnLoadCode($a_code, $a_batch = 2)
480  {
481  // TODO: Implement addOnLoadCode() method.
482  }
483 
484 
488  public function getOnLoadCodeForAsynch()
489  {
490  // TODO: Implement getOnLoadCodeForAsynch() method.
491  }
492 
493 
497  public function resetJavascript()
498  {
499  // TODO: Implement resetJavascript() method.
500  }
501 
502 
506  public function addInlineCss($a_css, $media = "screen")
507  {
508  // TODO: Implement addInlineCss() method.
509  }
510 
511 
512  public function setBodyClass($a_class = "")
513  {
514  // TODO: Implement setBodyClass() method.
515  }
516 
517 
521  public function loadStandardTemplate()
522  {
523  // TODO: Implement loadStandardTemplate() method.
524  }
525 
526 
530  public function setTitle($a_title, $hidden = false)
531  {
532  // TODO: Implement setTitle() method.
533  }
534 
535 
539  public function setDescription($a_descr)
540  {
541  // TODO: Implement setDescription() method.
542  }
543 
544 
548  public function setTitleIcon($a_icon_path, $a_icon_desc = "")
549  {
550  // TODO: Implement setTitleIcon() method.
551  }
552 
553 
557  public function setAlertProperties(array $a_props)
558  {
559  // TODO: Implement setAlertProperties() method.
560  }
561 
562 
566  public function clearHeader()
567  {
568  // TODO: Implement clearHeader() method.
569  }
570 
571 
575  public function setHeaderActionMenu($a_header)
576  {
577  // TODO: Implement setHeaderActionMenu() method.
578  }
579 
580 
584  public function setHeaderPageTitle($a_title)
585  {
586  // TODO: Implement setHeaderPageTitle() method.
587  }
588 
589 
593  public function setLocator()
594  {
595  // TODO: Implement setLocator() method.
596  }
597 
598 
602  public function setTabs($a_tabs_html)
603  {
604  // TODO: Implement setTabs() method.
605  }
606 
607 
611  public function setSubTabs($a_tabs_html)
612  {
613  // TODO: Implement setSubTabs() method.
614  }
615 
616 
620  public function setContent($a_html)
621  {
622  // TODO: Implement setContent() method.
623  }
624 
625 
629  public function setLeftContent($a_html)
630  {
631  // TODO: Implement setLeftContent() method.
632  }
633 
634 
638  public function setLeftNavContent($a_content)
639  {
640  // TODO: Implement setLeftNavContent() method.
641  }
642 
643 
647  public function setRightContent($a_html)
648  {
649  // TODO: Implement setRightContent() method.
650  }
651 
652 
653  public function setPageFormAction($a_action)
654  {
655  // TODO: Implement setPageFormAction() method.
656  }
657 
658 
662  public function setLoginTargetPar($a_val)
663  {
664  // TODO: Implement setLoginTargetPar() method.
665  }
666 
667 
671  public function getSpecial($part = "DEFAULT", $add_error_mess = false, $handle_referer = false, $add_ilias_footer = false, $add_standard_elements = false, $a_main_menu = true, $a_tabs = true)
672  {
673  // TODO: Implement getSpecial() method.
674  }
675 
676 
680  public function printToStdout($part = "DEFAULT", $a_fill_tabs = true, $a_skip_main_menu = false)
681  {
682  // TODO: Implement printToStdout() method.
683  }
684 
685 
689  public function setTreeFlatIcon($a_link, $a_mode)
690  {
691  // TODO: Implement setTreeFlatIcon() method.
692  }
693 
694 
698  public function addLightbox($a_html, $a_id)
699  {
700  // TODO: Implement addLightbox() method.
701  }
702 
703 
707  public function addAdminPanelToolbar(ilToolbarGUI $toolb, $a_bottom_panel = true, $a_arrow = false)
708  {
709  // TODO: Implement addAdminPanelToolbar() method.
710  }
711 
712 
713  public function setPermanentLink($a_type, $a_id, $a_append = "", $a_target = "", $a_title = "")
714  {
715  // TODO: Implement setPermanentLink() method.
716  }
717 
718 
722  public function resetHeaderBlock($a_reset_header_action = true)
723  {
724  // TODO: Implement resetHeaderBlock() method.
725  }
726 
727 
731  public function enableDragDropFileUpload($a_ref_id)
732  {
733  // TODO: Implement enableDragDropFileUpload() method.
734  }
735 }
getTemplatePath($a_tplname, $a_in_module=false, $a_plugin=false)
builds a full template path with template and module name
setTitleIcon($a_icon_path, $a_icon_desc="")
setDescription($a_descr)
addLightbox($a_html, $a_id)
setLoginTargetPar($a_val)
resetHeaderBlock($a_reset_header_action=true)
__construct($file, $flag1, $flag2, $in_module=false, $vars="DEFAULT")
constructor
$_GET["client_id"]
setAlertProperties(array $a_props)
static get($a_var)
Get a value.
static set($a_var, $a_val)
Set a value.
setLeftNavContent($a_content)
addAdminPanelToolbar(ilToolbarGUI $toolb, $a_bottom_panel=true, $a_arrow=false)
addInlineCss($a_css, $media="screen")
setHeaderActionMenu($a_header)
setPageFormAction($a_action)
setTabs($a_tabs_html)
setBodyClass($a_class="")
global $ilCtrl
Definition: ilias.php:18
const DEBUG
loadTemplatefile( $filename, $removeUnknownVariables=true, $removeEmptyBlocks=true)
Reads a template file from the disk.
$a_type
Definition: workflow.php:92
setPermanentLink($a_type, $a_id, $a_append="", $a_target="", $a_title="")
$a_content
Definition: workflow.php:93
addJavaScript($a_js_file, $a_add_version_parameter=true, $a_batch=2)
Add a javascript file that should be included in the header.
$lng
setTitle($a_title, $hidden=false)
touchBlock($block)
overwrites ITX::touchBlock.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
get(string $class_name)
printToStdout($part="DEFAULT", $a_fill_tabs=true, $a_skip_main_menu=false)
setSubTabs($a_tabs_html)
setOnScreenMessage($a_type, $a_txt, $a_keep=false)
Set message.
static clear($a_var)
Unset a value.
setVariable($variable, $value='')
addOnLoadCode($a_code, $a_batch=2)
$txt
Definition: error.php:13
fillJavaScriptFiles($force=true)
addBlockFile($var, $block, $tplname, $in_module=false)
overwrites ITX::addBlockFile
$filename
Definition: buildRTE.php:89
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
parseCurrentBlock()
Parses the current block.
Definition: IT.php:596
getMessageHTML($a_txt, $a_type="info")
Get HTML for a system message.
getSpecial($part="DEFAULT", $add_error_mess=false, $handle_referer=false, $add_ilias_footer=false, $add_standard_elements=false, $a_main_menu=true, $a_tabs=true)
setLeftContent($a_html)
fillCssFiles($a_force=false)
Fill in the css file tags.
blockExists($a_blockname)
check if block exists in actual template private
setRightContent($a_html)
__construct(Container $dic, ilPlugin $plugin)
setTreeFlatIcon($a_link, $a_mode)
const ILIAS_MODULE
Definition: server.php:14
setOption($option, $value)
Sets the option for the template class.
Definition: IT.php:399
enableDragDropFileUpload($a_ref_id)
addCss($a_css_file, $media="screen")
Add a css file that should be included in the header.
$_POST["username"]
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt public...
show($part="DEFAULT")
public
setContent($a_html)
setHeaderPageTitle($a_title)