ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilIndependentTemplate.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once("libs/composer/vendor/autoload.php");
6
7// Do the require-dance for ilTemplate.
8require_once("./Services/UICore/lib/html-it/IT.php");
9require_once("./Services/UICore/lib/html-it/ITX.php");
10require_once("./Services/UICore/classes/class.ilTemplate.php");
11
13{
14 // This makes PHP happy, baseclass needs that
15 protected $blockparents = null;
16
17 public function __construct(
18 $file,
19 $flag1,
20 $flag2,
21 $in_module = false,
22 $vars = "DEFAULT",
23 $plugin = false,
24 $a_use_cache = true
25 ) {
26 $this->setBodyClass("std");
27 $this->template = new ilIndependantTemplate($file, $flag1, $flag2, $in_module, $vars, $plugin, $a_use_cache);
28 }
29
30 // Small adjustment to fit \ILIAS\UI\Implementation\Template and call to
31 public function get(
32 $part = null,
33 $add_error_mess = false,
34 $handle_referer = false,
35 $add_ilias_footer = false,
36 $add_standard_elements = false,
37 $a_main_menu = true,
38 $a_tabs = true
39 ) {
40 return $this->template->get($part);
41 }
42}
43
45{
55 public function getFile($filename)
56 {
57 if ($filename[0] == '/' && substr($this->fileRoot, -1) == '/') {
58 $filename = substr($filename, 1);
59 }
60
61 $filename = $this->fileRoot . $filename;
62
63 require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
64 $this->real_filename = $filename;
65
66 if (!($fh = @fopen($filename, 'r'))) {
67 $this->err[] = PEAR::raiseError(
68 $this->errorMessage(IT_TPL_NOT_FOUND) .
69 ': "' . $filename . '"',
71 );
72 return "";
73 }
74
75 $fsize = filesize($filename);
76 if ($fsize < 1) {
77 fclose($fh);
78 return '';
79 }
80
81 $content = fread($fh, $fsize);
82 fclose($fh);
83
84 return preg_replace_callback(
85 "#<!-- INCLUDE (.*) -->#im",
86 function ($hit) {
87 return $this->getFile($hit[1]);
88 },
89 $content
90 );
91 } // end func getFile
92
106 public function loadTemplatefile(
107 $filename,
108 $removeUnknownVariables = true,
109 $removeEmptyBlocks = true
110 ) {
111 return HTML_Template_IT::loadTemplatefile($filename, $removeUnknownVariables, $removeEmptyBlocks);
112 }
113
114 // Small adjustment to fit \ILIAS\UI\Implementation\Template and call to
115 public function get($part = null)
116 {
117 if ($part === null) {
118 $part = "__global__";
119 }
120 if ($part == '__global__' && !$this->flagGlobalParsed) {
121 $this->parse('__global__');
122 }
123
124 if (!isset($this->blocklist[$part])) {
125 throw (new ilTemplateException($this->errorMessage(IT_BLOCK_NOT_FOUND) .
126 '"' . $block . "'"));
127 }
128
129 if (isset($this->blockdata[$part])) {
130 $ret = $this->blockdata[$part];
131 if ($this->clearCache) {
132 unset($this->blockdata[$part]);
133 }
134 if ($this->_options['preserve_data']) {
135 $ret = str_replace(
136 $this->openingDelimiter .
137 '%preserved%' . $this->closingDelimiter,
138 $this->openingDelimiter,
139 $ret
140 );
141 }
142 return $ret;
143 }
144
145 return '';
146 }
147}
const IT_TPL_NOT_FOUND
Definition: IT.php:25
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
$filename
Definition: buildRTE.php:89
An exception for terminatinating execution or to throw for unit testing.
loadTemplatefile( $filename, $removeUnknownVariables=true, $removeEmptyBlocks=true)
Reads a template file from the disk.
Definition: IT.php:780
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object's de...
Definition: PEAR.php:522
special template class to simplify handling of ITX/PEAR
getFile($filename)
Reads a file from disk and returns its content.
loadTemplatefile( $filename, $removeUnknownVariables=true, $removeEmptyBlocks=true)
Reads a template file from the disk.
__construct( $file, $flag1, $flag2, $in_module=false, $vars="DEFAULT", $plugin=false, $a_use_cache=true)
constructor
special template class to simplify handling of ITX/PEAR
Interface to templating as it is used in the UI framework.
Definition: Template.php:14
$ret
Definition: parser.php:6