ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilGlobalPageTemplate.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
30 
36 {
37  protected HTTPServices $http;
38  protected Services $gs;
39  protected UIServices $ui;
41  protected ilLanguage $lng;
43  protected Refinery $refinery;
44 
48  protected static array $ignored_blocks = [
49  self::DEFAULT_BLOCK,
50  'ContentStyle',
51  "SyntaxStyle",
52  "",
53  ];
54 
55 
59  public function __construct(Services $gs, UIServices $ui, HTTPServices $http)
60  {
61  global $DIC;
62  $this->lng = $DIC->language();
63  $this->ui = $ui;
64  $this->gs = $gs;
65  $this->http = $http;
66  $this->legacy_content_template = new PageContentGUI("tpl.page_content.html", true, true);
67  $this->il_settings = $DIC->settings();
68  $this->refinery = $DIC->refinery();
69  }
70 
71  protected function prepareOutputHeaders(): void
72  {
73  $this->http->saveResponse(
74  $this->http->response()->withAddedHeader(
75  'P3P',
76  'CP="CURa ADMa DEVa TAIa PSAa PSDa IVAa IVDa OUR BUS IND UNI COM NAV INT CNT STA PRE"'
77  )
78  );
79 
80  $this->http->saveResponse(
81  $this->http->response()->withAddedHeader('Content-type', 'text/html; charset=UTF-8')
82  );
83 
84  if (defined("ILIAS_HTTP_PATH")) {
85  $this->gs->layout()->meta()->setBaseURL(
86  (substr(ILIAS_HTTP_PATH, -1) === '/' ? ILIAS_HTTP_PATH : ILIAS_HTTP_PATH . '/')
87  );
88  }
89 
90  $this->gs->layout()->meta()->setTextDirection($this->lng->getTextDirection());
91  }
92 
96  protected function prepareBasicJS(): void
97  {
100  $this->gs->layout()->meta()->addJs("assets/js/Basic.js", true, 1);
103  GlobalPageHandler::initPage($this);
104 
105  $sessionReminder = new ilSessionReminderGUI(
107  $this,
108  $this->lng
109  );
110 
111  $sessionReminder->populatePage();
112  $onScreenNotifier = new ilNotificationOSDGUI($this, $this->lng);
113  $onScreenNotifier->populatePage();
114  }
115 
116  protected function prepareBasicCSS(): void
117  {
118  $this->gs->layout()->meta()->addCss(ilUtil::getStyleSheetLocation());
119  $this->gs->layout()->meta()->addCss(ilUtil::getNewContentStyleSheetLocation());
120  }
121 
122  public function printToStdout(
123  string $part = self::DEFAULT_BLOCK,
124  bool $a_fill_tabs = true,
125  bool $a_skip_main_menu = false
126  ): void {
127  $this->prepareOutputHeaders();
128  $this->prepareBasicJS();
129  $this->prepareBasicCSS();
130 
131  PageContentProvider::setContent($this->legacy_content_template->renderPage(self::DEFAULT_BLOCK, true));
132  $this->http->sendResponse();
133 
134  print $this->ui->renderer()->render($this->gs->collector()->layout()->getFinalPage());
135 
136  // save language usages as late as possible
138  }
139 
140  public function printToString(): string
141  {
142  $this->prepareOutputHeaders();
143  $this->prepareBasicJS();
144  $this->prepareBasicCSS();
145 
146  PageContentProvider::setContent($this->legacy_content_template->renderPage(self::DEFAULT_BLOCK, true));
147 
148  return $this->ui->renderer()->render($this->gs->collector()->layout()->getFinalPage());
149  }
150 
151  public function addJavaScript(string $a_js_file, bool $a_add_version_parameter = true, int $a_batch = 2): void
152  {
153  $this->gs->layout()->meta()->addJs($a_js_file, $a_add_version_parameter, $a_batch);
154  }
155 
156  public function addCss(string $a_css_file, string $media = "screen"): void
157  {
158  $this->gs->layout()->meta()->addCss($a_css_file, $media);
159  }
160 
161  public function addOnLoadCode(string $a_code, int $a_batch = 2): void
162  {
163  $this->gs->layout()->meta()->addOnloadCode($a_code, $a_batch);
164  }
165 
166  public function addInlineCss(string $a_css, string $media = "screen"): void
167  {
168  $this->gs->layout()->meta()->addInlineCss($a_css, $media);
169  }
170 
171  public function setContent(string $a_html): void
172  {
173  $this->legacy_content_template->setMainContent($a_html);
174  }
175 
176  public function setLeftContent(string $a_html): void
177  {
178  $this->legacy_content_template->setLeftContent($a_html);
179  }
180 
181  public function setRightContent(string $a_html): void
182  {
183  $this->legacy_content_template->setRightContent($a_html);
184  }
185 
186  public function setFilter(string $filter): void
187  {
188  $this->legacy_content_template->setFilter($filter);
189  }
190 
191  public function setTitle(string $a_title, bool $hidden = false): void
192  {
193  $this->legacy_content_template->setTitle($a_title, $hidden);
194 
195  $short_title = (string) $this->il_settings->get('short_inst_name');
196  if (trim($short_title) === "") {
197  $short_title = 'ILIAS';
198  }
199 
200  PageContentProvider::setShortTitle($short_title);
201  PageContentProvider::setViewTitle($a_title);
202  $header_title = ilObjSystemFolder::_getHeaderTitle();
203  PageContentProvider::setTitle($header_title);
204  }
205 
206  public function setDescription(string $a_descr): void
207  {
208  $this->legacy_content_template->setTitleDesc($a_descr);
209  }
210 
211  public function setTitleIcon(string $a_icon_path, string $a_icon_desc = ""): void
212  {
213  $this->legacy_content_template->setIconPath($a_icon_path);
214  $this->legacy_content_template->setIconDesc($a_icon_desc);
215  }
216 
217  public function setBanner(string $img_src): void
218  {
219  $this->legacy_content_template->setBanner($img_src);
220  }
221 
222  public function setAlertProperties(array $a_props): void
223  {
224  $this->legacy_content_template->setTitleAlerts($a_props);
225  }
226 
227  public function setOnScreenMessage(string $a_type, string $a_txt, bool $a_keep = false): void
228  {
229  $this->legacy_content_template->setOnScreenMessage($a_type, $a_txt, $a_keep);
230  }
231 
232  public function setFileUploadRefId(int $a_ref_id): void
233  {
234  $this->legacy_content_template->setFileUploadRefId($a_ref_id);
235  }
236 
237  public function setHeaderActionMenu(string $a_header): void
238  {
239  $this->legacy_content_template->setHeaderAction($a_header);
240  }
241 
242  public function setHeaderPageTitle(string $a_title): void
243  {
244  PageContentProvider::setViewTitle($a_title);
245  }
246 
247  public function setPageFormAction(string $a_action): void
248  {
249  $this->legacy_content_template->setPageFormAction($a_action);
250  }
251 
252  public function addAdminPanelToolbar(ilToolbarGUI $toolb, bool $a_bottom_panel = true, bool $a_arrow = false): void
253  {
254  $this->legacy_content_template->setAdminPanelCommandsToolbar($toolb);
255  $this->legacy_content_template->setAdminPanelArrow($a_arrow);
256  $this->legacy_content_template->setAdminPanelBottom($a_bottom_panel);
257  }
258 
259  public function setVariable(string $variable, $value = ''): void
260  {
261  if ($variable === "LOCATION_CONTENT_STYLESHEET" || $variable === "LOCATION_SYNTAX_STYLESHEET") {
262  $this->addCss($value);
263 
264  return;
265  }
266 
267  $this->legacy_content_template->setVariable(
268  $variable,
269  $this->refinery->kindlyTo()->string()->transform($value)
270  );
271  }
272 
273  public function resetJavascript(): void
274  {
275  $this->gs->layout()->meta()->getJs()->clear();
276  }
277 
278  public function get(string $part = self::DEFAULT_BLOCK): string
279  {
280  return $this->legacy_content_template->get($part);
281  }
282 
283  public function setCurrentBlock(string $blockname = self::DEFAULT_BLOCK): bool
284  {
285  if (in_array($blockname, self::$ignored_blocks)) {
286  return false;
287  }
288 
289  if ($this->blockExists($blockname)) {
290  return $this->legacy_content_template->setCurrentBlock($blockname);
291  }
292  throw new ilTemplateException("block " . var_export($blockname, true) . " not found");
293  }
294 
295  public function touchBlock(string $blockname): bool
296  {
297  if (in_array($blockname, self::$ignored_blocks)) {
298  return false;
299  }
300 
301  if ($this->blockExists($blockname)) {
302  $this->legacy_content_template->touchBlock($blockname);
303  return true;
304  }
305 
306  throw new ilTemplateException("block " . var_export($blockname, true) . " not found");
307  }
308 
309  public function parseCurrentBlock(string $blockname = self::DEFAULT_BLOCK): bool
310  {
311  if (in_array($blockname, self::$ignored_blocks)) {
312  return false; // TODO why is this needed?
313  }
314  if ($this->blockExists($blockname)) {
315  return $this->legacy_content_template->parseCurrentBlock($blockname);
316  }
317 
318  throw new ilTemplateException("block " . var_export($blockname, true) . " not found");
319  }
320 
321  public function addBlockFile(string $var, string $block, string $template_name, string $in_module = null): bool
322  {
323  if ($this->blockExists($block)) {
324  $this->legacy_content_template->removeBlockData($block);
325  }
326 
327  return $this->legacy_content_template->addBlockFile($var, $block, $template_name, $in_module);
328  }
329 
330  public function blockExists(string $blockname): bool
331  {
332  if (in_array($blockname, self::$ignored_blocks)) {
333  return false;
334  }
335 
336  return $this->legacy_content_template->blockExists($blockname);
337  }
338 
339  public function loadStandardTemplate(): void
340  {
341  // Nothing to do
342  }
343 
344  public function setLocator(): void
345  {
346  // Nothing to do
347  }
348 
349  public function setPermanentLink(
350  string $a_type,
351  ?int $a_id,
352  string $a_append = "",
353  string $a_target = "",
354  string $a_title = ""
355  ): void {
356  $href = ilLink::_getStaticLink($a_id, $a_type, true, $a_append);
357  PageContentProvider::setPermaLink($href);
358  }
359 
360  public function setTreeFlatIcon(string $a_link, string $a_mode): void
361  {
362  // Nothing to do
363  }
364 
365  public function hideFooter(): void
366  {
367  // Nothing to do
368  }
369 
370  public function setLeftNavContent(string $a_content): void
371  {
372  // Nothing to do, this should be handled in Slates later
373  }
374 
375  public function resetHeaderBlock(bool $a_reset_header_action = true): void
376  {
377  // Nothing to do
378  }
379 
380  public function setLoginTargetPar(string $a_val): void
381  {
382  // Nothing to do
383  }
384 
385  public function getOnLoadCodeForAsynch(): string
386  {
387  // see e.g. bug #26413
388  $js = "";
389  foreach ($this->gs->layout()->meta()->getOnLoadCode()->getItemsInOrderOfDelivery() as $code) {
390  $js .= $code->getContent() . "\n";
391  }
392  if ($js) {
393  return '<script type="text/javascript">' . "\n" .
394  $js .
395  '</script>' . "\n";
396  }
397  return "";
398  }
399 
400  public function fillJavaScriptFiles(bool $a_force = false): void
401  {
402  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
403  }
404 
405  public function setBodyClass(string $a_class = ""): void
406  {
407  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
408  }
409 
410  public function clearHeader(): void
411  {
412  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
413  }
414 
415  public function setTabs(string $a_tabs_html): void
416  {
417  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
418  }
419 
420  public function setSubTabs(string $a_tabs_html): void
421  {
422  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
423  }
424 
425  public function getSpecial(
426  string $part = self::DEFAULT_BLOCK,
427  bool $add_error_mess = false,
428  bool $handle_referer = false,
429  bool $add_ilias_footer = false,
430  bool $add_standard_elements = false,
431  bool $a_main_menu = true,
432  bool $a_tabs = true
433  ): string {
434  throw new NotImplementedException();
435  }
436 }
addOnLoadCode(string $a_code, int $a_batch=2)
Add on load code.
static getStyleSheetLocation(string $mode="output", string $a_css_name="")
get full style sheet file name (path inclusive) of current user
__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.
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
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.
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.
global $DIC
Definition: shib_login.php:25
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.
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.
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.