ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
10class ilTemplate extends ilTemplateX
11{
16 var $vars;
17 //var $js_files = array(0 => "./Services/JavaScript/js/Basic.js"); // list of JS files that should be included
18 var $js_files = array(); // list of JS files that should be included
19 var $css_files = array(); // list of css files that should be included
20
27 var $activeBlock;
28
38 /*function ilTemplate($root)
39 {
40
41 $this->callConstructor();
42
43 $this->setRoot($root);
44
45 return true;
46 }*/
47 function ilTemplate($file,$flag1,$flag2,$in_module = false, $vars = "DEFAULT")
48 {
49 $this->activeBlock = "__global__";
50 $this->vars = array();
51
52 $fname = $this->getTemplatePath($file, $in_module);
53
54 $this->tplName = basename($fname);
55 $this->tplPath = dirname($fname);
56 // set default content-type to text/html
57 $this->contenttype = "text/html";
58 if (!file_exists($fname))
59 {
60 die("template ".$fname." was not found.");
61 return false;
62 }
63
64 //$this->IntegratedTemplateExtension(dirname($fname));
65 $this->callConstructor();
66 //$this->loadTemplatefile(basename($fname), $flag1, $flag2);
67 $this->loadTemplatefile($fname, $flag1, $flag2);
68 //add tplPath to replacevars
69 $this->vars["TPLPATH"] = $this->tplPath;
70
71 // set Options
72 if (method_exists($this, "setOption"))
73 {
74 $this->setOption('use_preg', false);
75 }
76
77 return true;
78 }
79
88 function getTemplatePath($a_tplname, $a_in_module = false, $a_plugin = false)
89 {
90 global $ilias, $ilCtrl;
91
92 // if baseClass functionality is used (ilias.php):
93 // get template directory from ilCtrl
94 if (!empty($_GET["baseClass"]) && $a_in_module === true)
95 {
96 $a_in_module = $ilCtrl->getModuleDir();
97 }
98
99 if (strpos($a_tplname,"/") === false)
100 {
101 $module_path = "";
102
103 //$fname = $ilias->tplPath;
104 if ($a_in_module)
105 {
106 if ($a_in_module === true)
107 {
108 $module_path = ILIAS_MODULE."/";
109 }
110 else
111 {
112 $module_path = $a_in_module."/";
113 }
114 }
115
116 if($fname == "" || !file_exists($fname))
117 {
118 if ($a_in_module == "setup")
119 {
120 $fname = "./".$module_path."templates/".basename($a_tplname);
121 }
122 else
123 {
124 $fname = "./".$module_path."templates/default/".basename($a_tplname);
125 }
126 }
127 }
128 else
129 {
130 $fname = $a_tplname;
131 }
132
133 return $fname;
134 }
135
136 function addBlockFile($var, $block, $tplname, $in_module = false)
137 {
138 if (DEBUG)
139 {
140 echo "<br/>Template '".$this->tplPath."/".$tplname."'";
141 }
142
143 $tplfile = $this->getTemplatePath($tplname, $in_module);
144 if (file_exists($tplfile) == false)
145 {
146 echo "<br/>Template '".$tplfile."' doesn't exist! aborting...";
147 return false;
148 }
149
150 return parent::addBlockFile($var, $block, $tplfile);
151 }
152
157 function show($part = "DEFAULT")
158 {
159 header('Content-type: text/html; charset=UTF-8');
160
161 $this->fillJavaScriptFiles();
162 $this->fillCssFiles();
163
164 // ERROR HANDLER SETS $_GET["message"] IN CASE OF $error_obj->MESSAGE
165 $ms = array("info", "success", "failure", "question");
166 $out = "";
167
168 foreach ($ms as $m)
169 {
170 if ($m == "question")
171 {
172 $m = "mess_question";
173 }
174
175 $txt = (ilSession::get($m) != "")
176 ? ilSession::get($m)
177 : $this->message[$m];
178
179 if ($m == "mess_question")
180 {
181 $m = "question";
182 }
183
184 if ($txt != "")
185 {
186 $out.= $this->getMessageHTML($txt, $m);
187 }
188
189 if ($m == "question")
190 {
191 $m = "mess_question";
192 }
193
194 if (ilSession::get($m))
195 {
197 }
198 }
199
200 if ($this->blockExists("MESSAGE") && $out != "")
201 {
202 $this->setVariable("MESSAGE", $out);
203 }
204
205 if ($part == "DEFAULT")
206 {
207 parent::show();
208 }
209 else
210 {
211 parent::show($part);
212 }
213
214 if (((substr(strrchr($_SERVER["PHP_SELF"],"/"),1) != "error.php")
215 && (substr(strrchr($_SERVER["PHP_SELF"],"/"),1) != "adm_menu.php")))
216 {
217 ilSession::set("post_vars", $_POST);
218
219 // referer is modified if query string contains cmd=gateway and $_POST is not empty.
220 // this is a workaround to display formular again in case of error and if the referer points to another page
221 $url_parts = parse_url($_SERVER["REQUEST_URI"]);
222 if(!$url_parts)
223 {
224 $protocol = (isset($_SERVER['HTTPS']) ? 'https' : 'http').'://';
225 $host = $_SERVER['HTTP_HOST'];
226 $path = $_SERVER['REQUEST_URI'];
227 $url_parts = @parse_url($protocol.$host.$path);
228 }
229
230 if (preg_match("/cmd=gateway/",$url_parts["query"]))
231 {
232 foreach ($_POST as $key => $val)
233 {
234 if (is_array($val))
235 {
236 $val = key($val);
237 }
238
239 $str .= "&".$key."=".$val;
240 }
241
242 ilSession::set("referer",
243 preg_replace("/cmd=gateway/",substr($str,1),$_SERVER["REQUEST_URI"]));
244 ilSession::set("referer_ref_id",
245 (int) $_GET['ref_id']);
246 }
247 else
248 {
249 ilSession::set("referer", $_SERVER["REQUEST_URI"]);
250 ilSession::set("referer_ref_id",
251 (int) $_GET['ref_id']);
252 }
253
254 ilSession::clear("error_post_vars");
255 }
256 }
257
261 public function getMessageHTML($a_txt, $a_type = "info")
262 {
263 global $lng;
264
265 $mtpl = new ilTemplate("tpl.message.html", true, true, "Services/Utilities");
266 $mtpl->setCurrentBlock($a_type."_message");
267 $mtpl->setVariable("TEXT", $a_txt);
268 $mtpl->setVariable("MESSAGE_HEADING", $lng->txt($a_type."_message"));
269 $mtpl->parseCurrentBlock();
270
271 return $mtpl->get();
272 }
273
280 function setCurrentBlock ($part = "DEFAULT")
281 {
282 $this->activeBlock = $part;
283
284 if ($part == "DEFAULT")
285 {
286 return parent::setCurrentBlock();
287 }
288 else
289 {
290 return parent::setCurrentBlock($part);
291 }
292 }
293
300 function touchBlock($block)
301 {
302 $this->setCurrentBlock($block);
303 //$count = $this->fillVars();
304 $this->parseCurrentBlock();
305
306 if ($count == 0)
307 {
308 parent::touchBlock($block);
309 }
310 }
311
318 function parseCurrentBlock($part = "DEFAULT")
319 {
320 // Hier erst noch ein replace aufrufen
321 if ($part != "DEFAULT")
322 {
323 $tmp = $this->activeBlock;
324 $this->activeBlock = $part;
325 }
326
327 if ($part != "DEFAULT")
328 {
329 $this->activeBlock = $tmp;
330 }
331
332 //$this->fillVars();
333
334 $this->activeBlock = "__global__";
335
336 if ($part == "DEFAULT")
337 {
338 return parent::parseCurrentBlock();
339 }
340 else
341 {
342 return parent::parseCurrentBlock($part);
343 }
344 }
349 function setMessage($a_type, $a_txt, $a_keep = false)
350 {
351 if (!in_array($a_type, array("info", "success", "failure", "question")) || $a_txt == "")
352 {
353 return;
354 }
355 if ($a_type == "question")
356 {
357 $a_type = "mess_question";
358 }
359 if (!$a_keep)
360 {
361 $this->message[$a_type] = $a_txt;
362 }
363 else
364 {
365 ilSession::set($a_type, $a_txt);
366 }
367 }
368
369 function fillMessage()
370 {
371 global $lng;
372
373 $ms = array("info", "success", "failure", "question");
374 $out = "";
375
376 foreach ($ms as $m)
377 {
378 if ($m == "question")
379 {
380 $m = "mess_question";
381 }
382
383 $txt = (ilSession::get($m) != "")
384 ? ilSession::get($m)
385 : $this->message[$m];
386
387 if ($m == "mess_question")
388 {
389 $m = "question";
390 }
391
392 if ($txt != "")
393 {
394 $mtpl = new ilTemplate("tpl.message.html", true, true, "Services/Utilities");
395 $mtpl->setCurrentBlock($m."_message");
396 $mtpl->setVariable("TEXT", $txt);
397 $mtpl->setVariable("MESSAGE_HEADING", $lng->txt($m."_message"));
398 $mtpl->parseCurrentBlock();
399 $out.= $mtpl->get();
400 }
401
402 if ($m == "question")
403 {
404 $m = "mess_question";
405 }
406
407 if (ilSession::get($m))
408 {
410 }
411 }
412
413 if ($out != "")
414 {
415 $this->setVariable("MESSAGE", $out);
416 }
417 }
418
425 function blockExists($a_blockname)
426 {
427 // added second evaluation to the return statement because the first one only works for the content block (Helmut Schottmüller, 2007-09-14)
428 return (isset($this->blockvariables["content"][$a_blockname]) ? true : false) | (isset($this->blockvariables[$a_blockname]) ? true : false);
429 }
430
434 function addJavaScript($a_js_file)
435 {
436 if (!in_array($a_js_file, $this->js_files))
437 {
438 $this->js_files[] = $a_js_file;
439 }
440 }
441
443 {
444 global $ilias,$ilTabs;
445 if ($this->blockExists("js_file"))
446 {
447 foreach($this->js_files as $file)
448 {
449 if (is_file($file) || substr($file, 0, 4) == "http")
450 {
451 $this->setCurrentBlock("js_file");
452 $this->setVariable("JS_FILE", $file);
453 $this->parseCurrentBlock();
454 }
455 }
456 }
457 }
458
462 function addCss($a_css_file, $media = "screen")
463 {
464 if (!array_key_exists($a_css_file . $media, $this->css_files))
465 {
466 $this->css_files[$a_css_file . $media] = array("file" => $a_css_file, "media" => $media);
467 }
468 }
469
475 function fillCssFiles($a_force = false)
476 {
477 if (!$this->blockExists("css_file"))
478 {
479 return;
480 }
481 foreach($this->css_files as $css)
482 {
483 $filename = $css["file"];
484 if (strpos($filename, "?") > 0) $filename = substr($filename, 0, strpos($filename, "?"));
485 if (is_file($filename) || $a_force)
486 {
487 $this->setCurrentBlock("css_file");
488 $this->setVariable("CSS_FILE", $css["file"]);
489 $this->setVariable("CSS_MEDIA", $css["media"]);
490 $this->parseCurrentBlock();
491 }
492 }
493 }
494
495
496 function get($part = "DEFAULT")
497 {
498 if ($part == "DEFAULT")
499 {
500 return parent::get();
501 }
502 else
503 {
504 return parent::get($part);
505 }
506 }
507
508
509}
510?>
print $file
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
setOption($option, $value)
Sets the option for the template class.
Definition: IT.php:397
parseCurrentBlock()
Parses the current block.
Definition: IT.php:607
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:626
show()
returns the content of IniFile @access public
static set($a_var, $a_val)
Set a value.
static clear($a_var)
Unset a value.
static get($a_var)
Get a value.
Dummy class that inherits from new ITX PEAR Class (see header.inc)
special template class to simplify handling of ITX/PEAR
touchBlock($block)
overwrites ITX::touchBlock.
show($part="DEFAULT")
@access public
loadTemplatefile( $filename, $removeUnknownVariables=true, $removeEmptyBlocks=true)
Reads a template file from the disk.
setMessage($a_type, $a_txt, $a_keep=false)
Set message.
blockExists($a_blockname)
check if block exists in actual template @access private
ilTemplate($file, $flag1, $flag2, $in_module=false, $vars="DEFAULT", $plugin=false, $a_use_cache=false)
constructor
addBlockFile($var, $block, $tplname, $in_module=false)
ilTemplate($file, $flag1, $flag2, $in_module=false, $vars="DEFAULT")
constructor
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt @access public.
fillCssFiles($a_force=false)
Fill in the css file tags.
addJavaScript($a_js_file)
Add a javascript file that should be included in the header.
getMessageHTML($a_txt, $a_type="info")
Get HTML for a system message.
addCss($a_css_file, $media="screen")
Add a css file that should be included in the header.
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
getTemplatePath($a_tplname, $a_in_module=false, $a_plugin=false)
builds a full template path with template and module name
$_POST['username']
Definition: cron.php:12
$txt
Definition: error.php:12
global $ilCtrl
Definition: ilias.php:18
const DEBUG
const ILIAS_MODULE
Definition: payment.php:15
global $lng
Definition: privfeed.php:40
$path
Definition: index.php:22
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']