ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilIndependentTemplate.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . '/../../../../../vendor/composer/vendor/autoload.php');
22 
23 // Do the require-dance for ilTemplate.
24 require_once(__DIR__ . '/../../../../../components/ILIAS/UICore/lib/html-it/IT.php');
25 require_once(__DIR__ . '/../../../../../components/ILIAS/UICore/lib/html-it/ITX.php');
26 require_once(__DIR__ . '/../../../../../components/ILIAS/UICore/classes/class.ilTemplate.php');
27 
28 class ilIndependentGlobalTemplate extends ilGlobalTemplate implements \ILIAS\UI\Implementation\Render\Template
29 {
30  public function __construct(
31  $file,
32  $flag1,
33  $flag2,
34  $in_module = '',
35  $vars = self::DEFAULT_BLOCK,
36  $plugin = false,
37  $a_use_cache = true
38  ) {
39  $this->setBodyClass("std");
40  $this->template = new ilIndependantTemplate($file, $flag1, $flag2, $in_module, $vars, $plugin, $a_use_cache);
41  }
42 
43  // Small adjustment to fit \ILIAS\UI\Implementation\Template and call to
44  public function get(
45  ?string $part = null,
46  bool $add_error_mess = false,
47  bool $handle_referer = false,
48  bool $add_ilias_footer = false,
49  bool $add_standard_elements = false,
50  bool $a_main_menu = true,
51  bool $a_tabs = true
52  ): string {
53  return $this->template->get($part);
54  }
55 }
56 
58 {
64  public function getFile(string $filename): string
65  {
66  if ($filename[0] === '/' && substr($this->fileRoot, -1) === '/') {
67  $filename = substr($filename, 1);
68  }
69 
70  $filename = $this->fileRoot . $filename;
71 
72  $this->real_filename = $filename;
73 
74  if (!($fh = @fopen($filename, 'rb'))) {
75  $this->err[] = (new PEAR())->raiseError(
76  $this->errorMessage(self::IT_TPL_NOT_FOUND) .
77  ': "' . $filename . '"',
78  self::IT_TPL_NOT_FOUND
79  );
80  return "";
81  }
82 
83  $fsize = filesize($filename);
84  if ($fsize < 1) {
85  fclose($fh);
86  return '';
87  }
88 
89  $content = fread($fh, $fsize);
90  fclose($fh);
91 
92  return preg_replace_callback(
93  "#<!-- INCLUDE (.*) -->#im",
94  function ($hit) {
95  return $this->getFile($hit[1]);
96  },
97  $content
98  );
99  }
100 
105  public function loadTemplatefile(
106  string $filename,
107  bool $removeUnknownVariables = true,
108  bool $removeEmptyBlocks = true
109  ): bool {
110  return HTML_Template_IT::loadTemplatefile($filename, $removeUnknownVariables, $removeEmptyBlocks);
111  }
112 
113  // Small adjustment to fit \ILIAS\UI\Implementation\Template and call to
114  public function get(?string $part = null): string
115  {
116  if ($part === null) {
117  $part = self::IT_DEFAULT_BLOCK;
118  }
119  if ($part === self::IT_DEFAULT_BLOCK && !$this->flagGlobalParsed) {
120  $this->parse(self::IT_DEFAULT_BLOCK);
121  }
122 
123  if (!isset($this->blocklist[$part])) {
124  throw (new ilTemplateException($this->errorMessage(self::IT_BLOCK_NOT_FOUND) .
125  '"' . $part . "'"));
126  }
127 
128  if (isset($this->blockdata[$part])) {
129  $ret = $this->blockdata[$part];
130  if ($this->clearCache) {
131  unset($this->blockdata[$part]);
132  }
133  if ($this->_options['preserve_data']) {
134  $ret = str_replace(
135  $this->openingDelimiter .
136  '%preserved%' . $this->closingDelimiter,
137  $this->openingDelimiter,
138  $ret
139  );
140  }
141  return $ret;
142  }
143 
144  return '';
145  }
146 }
special template class to simplify handling of ITX/PEAR
__construct( $file, $flag1, $flag2, $in_module='', $vars=self::DEFAULT_BLOCK, $plugin=false, $a_use_cache=true)
loadTemplatefile(string $filename, bool $removeUnknownVariables=true, bool $removeEmptyBlocks=true)
Reads a template file from the disk.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getFile(string $filename)
Reads a file from disk and returns its content.
setBodyClass(string $a_class="")
Sets the body-tags class.
$filename
Definition: buildRTE.php:78
loadTemplatefile(string $filename, bool $removeUnknownVariables=true, bool $removeEmptyBlocks=true)
Reads a template file from the disk.
Definition: IT.php:675