ILIAS  release_8 Revision v8.23
class.ilGlobalPageTemplate.php
Go to the documentation of this file.
1 <?php
2 
3 
20 declare(strict_types=1);
21 
31 
37 {
38  protected HTTPServices $http;
39  protected Services $gs;
40  protected UIServices $ui;
42  protected ilLanguage $lng;
44  protected Refinery $refinery;
45 
49  protected static array $ignored_blocks = [
50  self::DEFAULT_BLOCK,
51  'ContentStyle',
52  "SyntaxStyle",
53  "",
54  ];
55 
56 
60  public function __construct(Services $gs, UIServices $ui, HTTPServices $http)
61  {
62  global $DIC;
63  $this->lng = $DIC->language();
64  $this->ui = $ui;
65  $this->gs = $gs;
66  $this->http = $http;
67  $this->legacy_content_template = new PageContentGUI("tpl.page_content.html", true, true);
68  $this->il_settings = $DIC->settings();
69  $this->refinery = $DIC->refinery();
70  }
71 
72  protected function prepareOutputHeaders(): void
73  {
74  $this->http->saveResponse(
75  $this->http->response()->withAddedHeader(
76  'P3P',
77  'CP="CURa ADMa DEVa TAIa PSAa PSDa IVAa IVDa OUR BUS IND UNI COM NAV INT CNT STA PRE"'
78  )
79  );
80 
81  $this->http->saveResponse(
82  $this->http->response()->withAddedHeader('Content-type', 'text/html; charset=UTF-8')
83  );
84 
85  if (defined("ILIAS_HTTP_PATH")) {
86  $this->gs->layout()->meta()->setBaseURL(
87  (substr(ILIAS_HTTP_PATH, -1) === '/' ? ILIAS_HTTP_PATH : ILIAS_HTTP_PATH . '/')
88  );
89  }
90 
91  $this->gs->layout()->meta()->setTextDirection($this->lng->getTextDirection());
92  }
93 
97  protected function prepareBasicJS(): void
98  {
101  $this->gs->layout()->meta()->addJs("./Services/JavaScript/js/Basic.js", true, 1);
102  ilUIFramework::init($this);
105  GlobalPageHandler::initPage($this);
106 
107  $sessionReminder = new ilSessionReminderGUI(
109  $this,
110  $this->lng
111  );
112 
113  $sessionReminder->populatePage();
114  $onScreenNotifier = new ilNotificationOSDGUI($this, $this->lng);
115  $onScreenNotifier->populatePage();
116  }
117 
118  protected function prepareBasicCSS(): void
119  {
120  $this->gs->layout()->meta()->addCss(ilUtil::getStyleSheetLocation());
121  $this->gs->layout()->meta()->addCss(ilUtil::getNewContentStyleSheetLocation());
122  }
123 
124  public function printToStdout(
125  string $part = self::DEFAULT_BLOCK,
126  bool $a_fill_tabs = true,
127  bool $a_skip_main_menu = false
128  ): void {
129  $this->prepareOutputHeaders();
130  $this->prepareBasicJS();
131  $this->prepareBasicCSS();
132 
133  PageContentProvider::setContent($this->legacy_content_template->renderPage(self::DEFAULT_BLOCK, true));
134  $this->http->sendResponse();
135 
136  print $this->ui->renderer()->render($this->gs->collector()->layout()->getFinalPage());
137 
138  // save language usages as late as possible
140  }
141 
142  public function printToString(): string
143  {
144  $this->prepareOutputHeaders();
145  $this->prepareBasicJS();
146  $this->prepareBasicCSS();
147 
148  PageContentProvider::setContent($this->legacy_content_template->renderPage(self::DEFAULT_BLOCK, true));
149 
150  return $this->ui->renderer()->render($this->gs->collector()->layout()->getFinalPage());
151  }
152 
153  public function addJavaScript(string $a_js_file, bool $a_add_version_parameter = true, int $a_batch = 2): void
154  {
155  $this->gs->layout()->meta()->addJs($a_js_file, $a_add_version_parameter, $a_batch);
156  }
157 
158  public function addCss(string $a_css_file, string $media = "screen"): void
159  {
160  $this->gs->layout()->meta()->addCss($a_css_file, $media);
161  }
162 
163  public function addOnLoadCode(string $a_code, int $a_batch = 2): void
164  {
165  $this->gs->layout()->meta()->addOnloadCode($a_code, $a_batch);
166  }
167 
168  public function addInlineCss(string $a_css, string $media = "screen"): void
169  {
170  $this->gs->layout()->meta()->addInlineCss($a_css, $media);
171  }
172 
173  public function setContent(string $a_html): void
174  {
175  $this->legacy_content_template->setMainContent($a_html);
176  }
177 
178  public function setLeftContent(string $a_html): void
179  {
180  $this->legacy_content_template->setLeftContent($a_html);
181  }
182 
183  public function setRightContent(string $a_html): void
184  {
185  $this->legacy_content_template->setRightContent($a_html);
186  }
187 
188  public function setFilter(string $filter): void
189  {
190  $this->legacy_content_template->setFilter($filter);
191  }
192 
193  public function setTitle(string $a_title, bool $hidden = false): void
194  {
195  $this->legacy_content_template->setTitle($a_title, $hidden);
196 
197  $short_title = (string) $this->il_settings->get('short_inst_name');
198  if (trim($short_title) === "") {
199  $short_title = 'ILIAS';
200  }
201 
202  PageContentProvider::setShortTitle($short_title);
203  PageContentProvider::setViewTitle($a_title);
204  $header_title = ilObjSystemFolder::_getHeaderTitle();
205  PageContentProvider::setTitle($header_title);
206  }
207 
208  public function setDescription(string $a_descr): void
209  {
210  $this->legacy_content_template->setTitleDesc($a_descr);
211  }
212 
213  public function setTitleIcon(string $a_icon_path, string $a_icon_desc = ""): void
214  {
215  $this->legacy_content_template->setIconPath($a_icon_path);
216  $this->legacy_content_template->setIconDesc($a_icon_desc);
217  }
218 
219  public function setBanner(string $img_src): void
220  {
221  $this->legacy_content_template->setBanner($img_src);
222  }
223 
224  public function setAlertProperties(array $a_props): void
225  {
226  $this->legacy_content_template->setTitleAlerts($a_props);
227  }
228 
229  public function setOnScreenMessage(string $a_type, string $a_txt, bool $a_keep = false): void
230  {
231  $this->legacy_content_template->setOnScreenMessage($a_type, $a_txt, $a_keep);
232  }
233 
234  public function setFileUploadRefId(int $a_ref_id): void
235  {
236  $this->legacy_content_template->setFileUploadRefId($a_ref_id);
237  }
238 
239  public function setHeaderActionMenu(string $a_header): void
240  {
241  $this->legacy_content_template->setHeaderAction($a_header);
242  }
243 
244  public function setHeaderPageTitle(string $a_title): void
245  {
246  PageContentProvider::setViewTitle($a_title);
247  }
248 
249  public function addLightbox(string $a_html, string $a_id): void
250  {
251  $this->legacy_content_template->addLightbox($a_html, $a_id);
252  }
253 
254  public function setPageFormAction(string $a_action): void
255  {
256  $this->legacy_content_template->setPageFormAction($a_action);
257  }
258 
259  public function addAdminPanelToolbar(ilToolbarGUI $toolb, bool $a_bottom_panel = true, bool $a_arrow = false): void
260  {
261  $this->legacy_content_template->setAdminPanelCommandsToolbar($toolb);
262  $this->legacy_content_template->setAdminPanelArrow($a_arrow);
263  $this->legacy_content_template->setAdminPanelBottom($a_bottom_panel);
264  }
265 
266  public function setVariable(string $variable, $value = ''): void
267  {
268  if ($variable === "LOCATION_CONTENT_STYLESHEET" || $variable === "LOCATION_SYNTAX_STYLESHEET") {
269  $this->addCss($value);
270 
271  return;
272  }
273 
274  $this->legacy_content_template->setVariable(
275  $variable,
276  $this->refinery->kindlyTo()->string()->transform($value)
277  );
278  }
279 
280  public function resetJavascript(): void
281  {
282  $this->gs->layout()->meta()->getJs()->clear();
283  }
284 
285  public function get(string $part = self::DEFAULT_BLOCK): string
286  {
287  return $this->legacy_content_template->get($part);
288  }
289 
290  public function setCurrentBlock(string $blockname = self::DEFAULT_BLOCK): bool
291  {
292  if (in_array($blockname, self::$ignored_blocks)) {
293  return false;
294  }
295 
296  if ($this->blockExists($blockname)) {
297  return $this->legacy_content_template->setCurrentBlock($blockname);
298  }
299  throw new ilTemplateException("block " . var_export($blockname, true) . " not found");
300  }
301 
302  public function touchBlock(string $blockname): bool
303  {
304  if (in_array($blockname, self::$ignored_blocks)) {
305  return false;
306  }
307 
308  if ($this->blockExists($blockname)) {
309  $this->legacy_content_template->touchBlock($blockname);
310  return true;
311  }
312 
313  throw new ilTemplateException("block " . var_export($blockname, true) . " not found");
314  }
315 
316  public function parseCurrentBlock(string $blockname = self::DEFAULT_BLOCK): bool
317  {
318  if (in_array($blockname, self::$ignored_blocks)) {
319  return false; // TODO why is this needed?
320  }
321  if ($this->blockExists($blockname)) {
322  return $this->legacy_content_template->parseCurrentBlock($blockname);
323  }
324 
325  throw new ilTemplateException("block " . var_export($blockname, true) . " not found");
326  }
327 
328  public function addBlockFile(string $var, string $block, string $template_name, string $in_module = null): bool
329  {
330  if ($this->blockExists($block)) {
331  $this->legacy_content_template->removeBlockData($block);
332  }
333 
334  return $this->legacy_content_template->addBlockFile($var, $block, $template_name, $in_module);
335  }
336 
337  public function blockExists(string $blockname): bool
338  {
339  if (in_array($blockname, self::$ignored_blocks)) {
340  return false;
341  }
342 
343  return $this->legacy_content_template->blockExists($blockname);
344  }
345 
346  public function loadStandardTemplate(): void
347  {
348  // Nothing to do
349  }
350 
351  public function setLocator(): void
352  {
353  // Nothing to do
354  }
355 
356  public function setPermanentLink(
357  string $a_type,
358  ?int $a_id,
359  string $a_append = "",
360  string $a_target = "",
361  string $a_title = ""
362  ): void {
363  $href = ilLink::_getStaticLink($a_id, $a_type, true, $a_append);
364  PageContentProvider::setPermaLink($href);
365  }
366 
367  public function setTreeFlatIcon(string $a_link, string $a_mode): void
368  {
369  // Nothing to do
370  }
371 
372  public function hideFooter(): void
373  {
374  // Nothing to do
375  }
376 
377  public function setLeftNavContent(string $a_content): void
378  {
379  // Nothing to do, this should be handled in Slates later
380  }
381 
382  public function resetHeaderBlock(bool $a_reset_header_action = true): void
383  {
384  // Nothing to do
385  }
386 
387  public function setLoginTargetPar(string $a_val): void
388  {
389  // Nothing to do
390  }
391 
392  public function getOnLoadCodeForAsynch(): string
393  {
394  // see e.g. bug #26413
395  $js = "";
396  foreach ($this->gs->layout()->meta()->getOnLoadCode()->getItemsInOrderOfDelivery() as $code) {
397  $js .= $code->getContent() . "\n";
398  }
399  if ($js) {
400  return '<script type="text/javascript">' . "\n" .
401  $js .
402  '</script>' . "\n";
403  }
404  return "";
405  }
406 
407  public function fillJavaScriptFiles(bool $a_force = false): void
408  {
409  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
410  }
411 
412  public function setBodyClass(string $a_class = ""): void
413  {
414  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
415  }
416 
417  public function clearHeader(): void
418  {
419  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
420  }
421 
422  public function setTabs(string $a_tabs_html): void
423  {
424  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
425  }
426 
427  public function setSubTabs(string $a_tabs_html): void
428  {
429  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
430  }
431 
432  public function getSpecial(
433  string $part = self::DEFAULT_BLOCK,
434  bool $add_error_mess = false,
435  bool $handle_referer = false,
436  bool $add_ilias_footer = false,
437  bool $add_standard_elements = false,
438  bool $a_main_menu = true,
439  bool $a_tabs = true
440  ): string {
441  throw new NotImplementedException();
442  }
443 }
addOnLoadCode(string $a_code, int $a_batch=2)
Add on load code.
__construct(Services $gs, UIServices $ui, HTTPServices $http)
setSubTabs(string $a_tabs_html)
sets subtabs in standard template
printToStdout(string $part=self::DEFAULT_BLOCK, bool $a_fill_tabs=true, bool $a_skip_main_menu=false)
setLoginTargetPar(string $a_val)
Set target parameter for login (public sector).
setCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Sets the template to the given block.
setLeftContent(string $a_html)
Sets content of left column.
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
setAlertProperties(array $a_props)
Set alert properties.
addCss(string $a_css_file, string $media="screen")
Add a css file that should be included in the header.
parseCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Parses the given block.
setLeftNavContent(string $a_content)
Sets content of left navigation column.
addBlockFile(string $var, string $block, string $template_name, string $in_module=null)
overwrites ITX::addBlockFile
static initializeFrontend(ilGlobalTemplateInterface $page)
This exception indicates that an UI component was accepted by the JF but is not backed by a real impl...
hideFooter()
Make the template hide the footer.
setPageFormAction(string $a_action)
Sets the pages form action.
resetHeaderBlock(bool $a_reset_header_action=true)
Reset all header properties: title, icon, description, alerts, action menu.
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
blockExists(string $blockname)
check if block exists in actual template
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.
setHeaderPageTitle(string $a_title)
Sets the title of the page (for browser window).
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNewContentStyleSheetLocation(string $mode="output")
get full style sheet file name (path inclusive) of current user
setBodyClass(string $a_class="")
Sets the body-tags class.
setFileUploadRefId(int $a_ref_id)
Enables the file upload into this object by dropping a file.
global $DIC
Definition: feed.php:28
Provides fluid interface to RBAC services.
Definition: UIServices.php:23
static http()
Fetches the global http state from ILIAS.
setRightContent(string $a_html)
Sets content of right column.
setTreeFlatIcon(string $a_link, string $a_mode)
Sets a tree or flat icon.
fillJavaScriptFiles(bool $a_force=false)
Probably adds javascript files.
static initjQueryUI(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components.txt for included components)
printToString()
Use this method to get the finally rendered page as string.
static initializeFrontend(ilGlobalTemplateInterface $page)
getSpecial(string $part=self::DEFAULT_BLOCK, bool $add_error_mess=false, bool $handle_referer=false, bool $add_ilias_footer=false, bool $add_standard_elements=false, bool $a_main_menu=true, bool $a_tabs=true)
Renders the page with specific elements enabled.
setHeaderActionMenu(string $a_header)
Set header action menu.
getOnLoadCodeForAsynch()
Get js onload code for ajax calls.
touchBlock(string $blockname)
overwrites ITX::touchBlock.
static init(ilGlobalTemplateInterface $template=null)
setOnScreenMessage(string $a_type, string $a_txt, bool $a_keep=false)
Set a message to be displayed to the user.
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
setDescription(string $a_descr)
Sets description below title in standard template.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addAdminPanelToolbar(ilToolbarGUI $toolb, bool $a_bottom_panel=true, bool $a_arrow=false)
Add admin panel commands as toolbar.
static _saveUsages()
Store the collected language variable usages in the user session This should be called as late as pos...
setTabs(string $a_tabs_html)
sets tabs in standard template
resetJavascript()
Reset javascript files.
addLightbox(string $a_html, string $a_id)
Add a lightbox html to the template.
loadStandardTemplate()
This loads the standard template "tpl.adm_content.html" and "tpl.statusline.html" the CONTENT and STA...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
setContent(string $a_html)
Sets content for standard template.
setPermanentLink(string $a_type, ?int $a_id, string $a_append="", string $a_target="", string $a_title="")
Generates and sets a permanent ilias link.
addInlineCss(string $a_css, string $media="screen")
Add a css file that should be included in the header.