ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Init.php
Go to the documentation of this file.
1 <?php
2 
20 
24 class 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(
40  \ilGlobalTemplateInterface $main_tpl
41  ): void {
42  $ctrl = $this->ctrl;
43  $lng = $this->lng;
44 
45  \ILIAS\Repository\Form\FormAdapterGUI::initJavascript();
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 
65  $main_tpl->addJavaScript("assets/js/ilExplorer.js");
66 
67  // ensure that form.js is loaded which is needed for file input (js that shows file names)
68  $dummy = new \ilPropertyFormGUI();
69  $dummy->getHTML();
70  // ensure modal.js from ui framework is loaded
71  $this->ui->renderer()->render(
72  $this->ui->factory()->modal()->roundtrip("", $this->ui->factory()->legacy()->content(""))
73  );
74  }
75 
76  protected function sanitizeAttribute(string $attr): string
77  {
78  return str_replace(["<", ">", "'", "\""], "", $attr);
79  }
80 
81  public function getInitHtml(
82  string $openPlaceHolderPcId = "",
83  string $openFormPcId = "",
84  string $openFormCName = ""
85  ): string {
86  $ctrl = $this->ctrl;
87 
88  $p1 = $this->sanitizeAttribute(
89  ILIAS_HTTP_PATH . "/" . $ctrl->getLinkTargetByClass(["ilPageEditorGUI", "ilPageEditorServerAdapterGUI"], "invokeServer")
90  );
91  $p2 = $this->sanitizeAttribute($ctrl->getFormActionByClass("ilPageEditorGUI"));
92  $p3 = $this->sanitizeAttribute($openPlaceHolderPcId);
93  $p4 = $this->sanitizeAttribute($openFormPcId);
94  $p5 = $this->sanitizeAttribute($openFormCName);
95 
96  $init_span = <<<EOT
97 <span id='il-copg-init'
98  data-endpoint='$p1'
99  data-formaction='$p2'
100  data-open-place-holder-pc-id='$p3'
101  data-open-form-pc-id='$p4'
102  data-open-form-cname='$p5'
103 ></span>
104 EOT;
105 
106  $debug = "";
107  //$debug = ".";
108  $module_tag = <<<EOT
109 <script type="module" src="$debug./components/ILIAS/COPage/Editor/js/src/editor.js"></script>
110 EOT;
111  return $init_span . $module_tag;
112  }
113 
114 }
initUI(\ilGlobalTemplateInterface $main_tpl)
Definition: Init.php:39
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Init.php:19
global $DIC
Definition: shib_login.php:22
getInitHtml(string $openPlaceHolderPcId="", string $openFormPcId="", string $openFormCName="")
Definition: Init.php:81
form( $class_path, string $cmd, string $submit_caption="")
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.
static initConnection(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Connection module.
ILIAS DI UIServices $ui
Definition: Init.php:26
sanitizeAttribute(string $attr)
Definition: Init.php:76