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