ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
Init.php
Go to the documentation of this file.
1<?php
2
20
24class Init
25{
26 protected \ILIAS\DI\UIServices $ui;
27 protected \ilCtrl $ctrl;
28 protected \ilLanguage $lng;
29
30 public function __construct()
31 {
32 global $DIC;
33
34 $this->ctrl = $DIC->ctrl();
35 $this->lng = $DIC->language();
36 $this->ui = $DIC->ui();
37 }
38
39 public function initUI(
41 ): void {
42 $ctrl = $this->ctrl;
44
46
47 $lang_vars = ["cont_last_update", "cont_error", "cont_sel_el_cut_use_paste", "cont_sel_el_copied_use_paste",
48 "cont_ed_new_col_before", "cont_ed_new_col_after", "cont_ed_col_left", "cont_ed_col_right", "cont_ed_delete_col",
49 "cont_ed_new_row_before", "cont_ed_new_row_after", "cont_ed_row_up", "cont_ed_row_down", "cont_ed_delete_row", "cont_saving",
50 "cont_ed_nr_cols", "cont_ed_nr_rows",
51 "cont_merge_cells", "cont_split_cell"
52 ];
53
54 foreach ($lang_vars as $l) {
55 $lng->toJS($l);
56 }
57
58 if (DEVMODE == 1) {
59 $main_tpl->addJavaScript("node_modules/tinymce/tinymce.js");
60 } else {
61 $main_tpl->addJavaScript("node_modules/tinymce/tinymce.min.js");
62 }
63
64 $main_tpl->addJavaScript("assets/js/ilExplorer.js");
65
66 // ensure that form.js is loaded which is needed for file input (js that shows file names)
67 $dummy = new \ilPropertyFormGUI();
68 $dummy->getHTML();
69 // ensure modal.js from ui framework is loaded
70 $this->ui->renderer()->render(
71 $this->ui->factory()->modal()->roundtrip("", $this->ui->factory()->legacy()->content(""))
72 );
73 }
74
75 protected function sanitizeAttribute(string $attr): string
76 {
77 return str_replace(["<", ">", "'", "\""], "", $attr);
78 }
79
80 public function getInitHtml(
81 string $openPlaceHolderPcId = "",
82 string $openFormPcId = "",
83 string $openFormCName = ""
84 ): string {
85 $ctrl = $this->ctrl;
86
87 $p1 = $this->sanitizeAttribute(
88 ILIAS_HTTP_PATH . "/" . $ctrl->getLinkTargetByClass(["ilPageEditorGUI", "ilPageEditorServerAdapterGUI"], "invokeServer")
89 );
90 $p2 = $this->sanitizeAttribute($ctrl->getFormActionByClass("ilPageEditorGUI"));
91 $p3 = $this->sanitizeAttribute($openPlaceHolderPcId);
92 $p4 = $this->sanitizeAttribute($openFormPcId);
93 $p5 = $this->sanitizeAttribute($openFormCName);
94
95 $init_span = <<<EOT
96<span id='il-copg-init'
97 data-endpoint='$p1'
98 data-formaction='$p2'
99 data-open-place-holder-pc-id='$p3'
100 data-open-form-pc-id='$p4'
101 data-open-form-cname='$p5'
102></span>
103EOT;
104
105 $debug = "";
106 //$debug = ".";
107 $module_tag = <<<EOT
108<script type="module" src="$debug./components/ILIAS/COPage/Editor/js/src/editor.js"></script>
109EOT;
110 return $init_span . $module_tag;
111 }
112
113}
getInitHtml(string $openPlaceHolderPcId="", string $openFormPcId="", string $openFormCName="")
Definition: Init.php:80
sanitizeAttribute(string $attr)
Definition: Init.php:75
ILIAS DI UIServices $ui
Definition: Init.php:26
initUI(\ilGlobalTemplateInterface $main_tpl)
Definition: Init.php:39
toJS($a_lang_key, ?ilGlobalTemplateInterface $a_tpl=null)
Transfer text to Javascript.
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Init.php:19
form(?array $class_path, string $cmd, string $submit_caption="")
global $DIC
Definition: shib_login.php:26