ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
ilIndependentTemplate.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . '/../../../../../vendor/composer/vendor/autoload.php');
22
23// Do the require-dance for ilTemplate.
24require_once(__DIR__ . '/../../../../../components/ILIAS/UICore/lib/html-it/IT.php');
25require_once(__DIR__ . '/../../../../../components/ILIAS/UICore/lib/html-it/ITX.php');
26require_once(__DIR__ . '/../../../../../components/ILIAS/UICore/classes/class.ilTemplate.php');
27
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 throw new ilTemplateException(
76 $this->errorMessage(self::IT_TPL_NOT_FOUND) . ': "' . $filename . '"'
77 );
78 }
79
80 $fsize = filesize($filename);
81 if ($fsize < 1) {
82 fclose($fh);
83 return '';
84 }
85
86 $content = fread($fh, $fsize);
87 fclose($fh);
88
89 return preg_replace_callback(
90 "#<!-- INCLUDE (.*) -->#im",
91 function ($hit) {
92 return $this->getFile($hit[1]);
93 },
94 $content
95 );
96 }
97
102 public function loadTemplatefile(
103 string $filename,
104 bool $removeUnknownVariables = true,
105 bool $removeEmptyBlocks = true
106 ): bool {
107 return HTML_Template_IT::loadTemplatefile($filename, $removeUnknownVariables, $removeEmptyBlocks);
108 }
109
110 // Small adjustment to fit \ILIAS\UI\Implementation\Template and call to
111 public function get(?string $part = null): string
112 {
113 if ($part === null) {
114 $part = self::IT_DEFAULT_BLOCK;
115 }
116 if ($part === self::IT_DEFAULT_BLOCK && !$this->flagGlobalParsed) {
117 $this->parse(self::IT_DEFAULT_BLOCK);
118 }
119
120 if (!isset($this->blocklist[$part])) {
121 throw (new ilTemplateException($this->errorMessage(self::IT_BLOCK_NOT_FOUND) .
122 '"' . $part . "'"));
123 }
124
125 if (isset($this->blockdata[$part])) {
126 $ret = $this->blockdata[$part];
127 if ($this->clearCache) {
128 unset($this->blockdata[$part]);
129 }
130 if ($this->_options['preserve_data']) {
131 $ret = str_replace(
132 $this->openingDelimiter .
133 '%preserved%' . $this->closingDelimiter,
134 $this->openingDelimiter,
135 $ret
136 );
137 }
138 return $ret;
139 }
140
141 return '';
142 }
143}
$filename
Definition: buildRTE.php:78
Integrated Template - IT Well there's not much to say about it.
Definition: IT.php:119
return true
special template class to simplify handling of ITX/PEAR
setBodyClass(string $a_class="")
Sets the body-tags class.
loadTemplatefile(string $filename, bool $removeUnknownVariables=true, bool $removeEmptyBlocks=true)
Reads a template file from the disk.
getFile(string $filename)
Reads a file from disk and returns its content.
__construct( $file, $flag1, $flag2, $in_module='', $vars=self::DEFAULT_BLOCK, $plugin=false, $a_use_cache=true)
special template class to simplify handling of ITX/PEAR
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface to templating as it is used in the UI framework.
Definition: Template.php:29