ILIAS  release_8 Revision v8.24
class.PageQueryActionHandler.php
Go to the documentation of this file.
1<?php
2
20
26
31{
32 protected \ILIAS\DI\UIServices $ui;
33 protected \ilLanguage $lng;
34 protected \ilPageObjectGUI $page_gui;
35 protected \ilObjUser $user;
37 protected \ilCtrl $ctrl;
38 protected \ilComponentFactory $component_factory;
39
41 {
42 global $DIC;
43
44 $this->ui = $DIC->ui();
45 $this->lng = $DIC->language();
46 $this->page_gui = $page_gui;
47 $this->user = $DIC->user();
48 $this->ctrl = $DIC->ctrl();
49 $this->component_factory = $DIC["component.factory"];
50
51 $this->ui_wrapper = new Server\UIWrapper($this->ui, $this->lng);
52 }
53
57 public function handle(array $query): Server\Response
58 {
59 switch ($query["action"]) {
60 case "ui.all":
61 return $this->allCommand();
62
63 case "component.edit.form":
64 return $this->componentEditFormResponse($query);
65
66 }
67 throw new Exception("Unknown action " . $query["action"]);
68 }
69
70 protected function allCommand(): Server\Response
71 {
73 $f = $this->ui->factory();
74 $dd = $f->dropdown()->standard([
75 $f->link()->standard("label", "#")
76 ]);
77 $r = $this->ui->renderer();
78 $o = new \stdClass();
79 $o->dropdown = $r->render($dd);
80 $o->addCommands = $this->getAddCommands();
81 $o->pageEditHelp = $this->getPageEditHelp();
82 $o->multiEditHelp = $this->getMultiEditHelp();
83 $o->pageTopActions = $this->getTopActions();
84 $o->multiActions = $this->getMultiActions();
85 $o->pasteMessage = $this->getPasteMessage();
86 $o->errorMessage = $this->getErrorMessage();
87 $o->errorModalMessage = $this->getErrorModalMessage();
88 $o->config = $this->getConfig();
89 $o->components = $this->getComponentsEditorUI();
90 $o->pcModel = $this->getPCModel();
91 $o->pcDefinition = $this->getComponentsDefinitions();
92 $o->formatSelection = $this->getFormatSelection();
93 $o->modal = $this->getModalTemplate();
94 $o->confirmation = $this->getConfirmationTemplate();
95 $o->autoSaveInterval = $this->getAutoSaveInterval();
96 $o->backUrl = $ctrl->getLinkTarget($this->page_gui, "edit");
97 $o->pasting = in_array(\ilEditClipboard::getAction(), ["copy", "cut"]) &&
98 count($this->user->getPCClipboardContent()) > 0;
99 $o->loaderUrl = \ilUtil::getImagePath("loader.svg");
100 return new Server\Response($o);
101 }
102
103 protected function getConfig(): \stdClass
104 {
105 $config = new \stdClass();
106 $config->user = $this->user->getLogin();
107 $config->content_css =
108 \ilObjStyleSheet::getContentStylePath($this->page_gui->getStyleId()) . ", " .
110 "./Services/COPage/css/tiny_extra.css";
111 $config->text_formats = \ilPCParagraphGUI::_getTextCharacteristics($this->page_gui->getStyleId());
112 $config->text_block_formats = [];
113 foreach (["text_block", "heading1", "heading2", "heading3"] as $type) {
114 $dummy_pc = new \ilPCParagraphGUI($this->page_gui->getPageObject(), null, "");
115 $dummy_pc->setStyleId($this->page_gui->getStyleId());
116 $dummy_pc->getCharacteristicsOfCurrentStyle([$type]);
117 foreach ($dummy_pc->getCharacteristics() as $char => $txt) {
118 $config->text_block_formats[$char] = $txt;
119 }
120 }
121 $config->editPlaceholders = $this->page_gui->getPageConfig()->getEnablePCType("PlaceHolder");
122 $config->activatedProtection =
123 ($this->page_gui->getPageConfig()->getSectionProtection() == \ilPageConfig::SEC_PROTECT_PROTECTED);
124
125 return $config;
126 }
127
128 protected function getAddCommands(): array
129 {
131
132 $commands = [];
133
134 // content types
135 $config = $this->page_gui->getPageConfig();
136 foreach ($config->getEnabledTopPCTypes() as $def) {
137 $commands[$def["pc_type"]] = $lng->txt("cont_ed_insert_" . $def["pc_type"]);
138 }
139
140 // content templates
141 if (count($this->page_gui->getPageObject()->getContentTemplates()) > 0) {
142 $commands["templ"] = $lng->txt("cont_ed_insert_templ");
143 }
144
145 // plugins
146 foreach ($this->component_factory->getActivePluginsInSlot("pgcp") as $plugin) {
147 if ($plugin->isValidParentType($this->page_gui->getPageObject()->getParentType())) {
148 $commands["plug_" . $plugin->getPluginName()] =
150 }
151 }
152 return $commands;
153 }
154
158 protected function getPageEditHelp(): string
159 {
161 $lng->loadLanguageModule("content");
162 $tpl = new \ilTemplate("tpl.page_edit_help.html", true, true, "Services/COPage/Editor");
163 $tpl->setCurrentBlock("help");
164 $tpl->setVariable("TXT_ADD_EL", $lng->txt("cont_add_elements"));
165 $tpl->setVariable("PLUS", \ilGlyphGUI::get(\ilGlyphGUI::ADD));
166 $tpl->setVariable("DRAG_ARROW", \ilGlyphGUI::get(\ilGlyphGUI::DRAG));
167 $tpl->setVariable("TXT_DRAG", $lng->txt("cont_drag_and_drop_elements"));
168 $tpl->setVariable("TXT_EDIT", $lng->txt("cont_click_edit"));
169 $tpl->setVariable("TXT_SEL", $lng->txt("cont_shift_click_to_select"));
170 $tpl->parseCurrentBlock();
171
172 return $tpl->get();
173 }
174
178 protected function getMultiEditHelp(): string
179 {
181 $lng->loadLanguageModule("content");
182 $tpl = new \ilTemplate("tpl.page_edit_help.html", true, true, "Services/COPage/Editor");
183 $tpl->setCurrentBlock("multi-help");
184 $tpl->setVariable("TXT_SEL", $lng->txt("cont_click_multi_select"));
185 $tpl->parseCurrentBlock();
186
187 return $tpl->get();
188 }
189
190 protected function getTopActions(): string
191 {
192 $ui = $this->ui;
195 $lng->loadLanguageModule("content");
196 $tpl = new \ilTemplate("tpl.top_actions.html", true, true, "Services/COPage/Editor");
197
198 $dd = $this->getActionsDropDown();
199 $tpl->setVariable("DROPDOWN", $ui->renderer()->renderAsync($dd));
200
201 if ($this->page_gui->getPageObject()->getEffectiveEditLockTime() > 0) {
202 $mess = $this->page_gui->getBlockingInfoMessage();
203 $tpl->setVariable("MESSAGE", $mess);
204 $b = $ui->factory()->button()->standard(
205 $lng->txt("cont_finish_editing"),
206 $ctrl->getLinkTarget($this->page_gui, "releasePageLock")
207 );
208 } else {
209 $b = $ui->factory()->button()->standard(
210 $lng->txt("cont_finish_editing"),
211 $ctrl->getLinkTarget($this->page_gui, "finishEditing")
212 );
213 }
214 $tpl->setVariable("MESSAGE2", $this->getMultiLangInfo());
215 $tpl->setVariable("QUIT_BUTTON", $ui->renderer()->renderAsync($b));
216
217 $html = $this->ui_wrapper->getRenderedViewControl(
218 [
219 ["Page", "switch.single", $lng->txt("cont_edit_comp")],
220 ["Page", "switch.multi", $lng->txt("cont_edit_multi")]
221 ]
222 );
223 $tpl->setVariable("SWITCH", $html);
224 $tpl->setVariable("SRC_LOADER", \ilUtil::getImagePath("loader.svg"));
225
226 return $tpl->get();
227 }
228
229 public function getActionsDropDown(): \ILIAS\UI\Component\Dropdown\Standard
230 {
231 $ui = $this->ui;
233 $config = $this->page_gui->getPageConfig();
234 $page = $this->page_gui->getPageObject();
237
238 // determine media, html and javascript mode
239 $sel_media_mode = ($user->getPref("ilPageEditor_MediaMode") != "disable");
240 $sel_html_mode = ($user->getPref("ilPageEditor_HTMLMode") != "disable");
241 $items = [];
242
243 // activate/deactivate
244 if ($config->getEnableActivation()) {
245 $captions = $this->page_gui->getActivationCaptions();
246
247 if ($page->getActive()) {
248 $items[] = $ui->factory()->link()->standard(
249 $captions["deactivatePage"],
250 $ctrl->getLinkTarget($this->page_gui, "deactivatePage")
251 );
252 } else {
253 $items[] = $ui->factory()->link()->standard(
254 $captions["activatePage"],
255 $ctrl->getLinkTarget($this->page_gui, "activatePage")
256 );
257 }
258 }
259
260 // initially opened content
261 if ($config->getUseAttachedContent()) {
262 $items[] = $ui->factory()->link()->standard(
263 $lng->txt("cont_initial_attached_content"),
264 $ctrl->getLinkTarget($this->page_gui, "initialOpenedContent")
265 );
266 }
267
268 // multi-lang actions
269 foreach ($this->getMultiLangActions() as $item) {
270 $items[] = $item;
271 }
272
273 $lng->loadLanguageModule("content");
274
275 // media mode
276 if ($sel_media_mode) {
277 $ctrl->setParameter($this->page_gui, "media_mode", "disable");
278 $items[] = $ui->factory()->link()->standard(
279 $lng->txt("cont_deactivate_media"),
280 $ctrl->getLinkTarget($this->page_gui, "setEditMode")
281 );
282 } else {
283 $ctrl->setParameter($this->page_gui, "media_mode", "enable");
284 $items[] = $ui->factory()->link()->standard(
285 $lng->txt("cont_activate_media"),
286 $ctrl->getLinkTarget($this->page_gui, "setEditMode")
287 );
288 }
289 $ctrl->setParameter($this, "media_mode", "");
290
291 // html mode
292 if (!$config->getPreventHTMLUnmasking()) {
293 if ($sel_html_mode) {
294 $ctrl->setParameter($this->page_gui, "html_mode", "disable");
295 $items[] = $ui->factory()->link()->standard(
296 $lng->txt("cont_deactivate_html"),
297 $ctrl->getLinkTarget($this->page_gui, "setEditMode")
298 );
299 } else {
300 $ctrl->setParameter($this->page_gui, "html_mode", "enable");
301 $items[] = $ui->factory()->link()->standard(
302 $lng->txt("cont_activate_html"),
303 $ctrl->getLinkTarget($this->page_gui, "setEditMode")
304 );
305 }
306 }
307 $ctrl->setParameter($this->page_gui, "html_mode", "");
308
309 $lm_set = new \ilSetting("lm");
310 if ($this->page_gui->getEnableEditing() && $this->user->getId() != ANONYMOUS_USER_ID) {
311
312 // history
313 if ($lm_set->get("page_history", 1)) {
314 $items[] = $ui->factory()->link()->standard(
315 $lng->txt("history"),
316 $ctrl->getLinkTarget($this->page_gui, "history")
317 );
318 }
319
320 if ($config->getEnableScheduledActivation()) {
321 $items[] = $ui->factory()->link()->standard(
322 $lng->txt("cont_activation"),
323 $ctrl->getLinkTarget($this->page_gui, "editActivation")
324 );
325 }
326
327 // clipboard
328 $items[] = $ui->factory()->link()->standard(
329 $lng->txt("clipboard"),
330 $ctrl->getLinkTargetByClass([get_class($this->page_gui), "ilEditClipboardGUI"], "view")
331 );
332 }
333
334 if ($this->page_gui->use_meta_data) {
335 $mdgui = new \ilObjectMetaDataGUI(
336 $this->page_gui->meta_data_rep_obj,
337 $this->page_gui->meta_data_type,
338 $this->page_gui->meta_data_sub_obj_id
339 );
340 $mdtab = $mdgui->getTab();
341 if ($mdtab) {
342 $items[] = $ui->factory()->link()->standard(
343 $lng->txt("meta_data"),
344 $mdtab
345 );
346 }
347 }
348
349
350 if ($this->page_gui->getEnabledNews()) {
351 $items[] = $ui->factory()->link()->standard(
352 $lng->txt("news"),
353 $ctrl->getLinkTargetByClass([get_class($this->page_gui), \ilNewsItemGUI::class], "editNews")
354 );
355 }
356
357
358 // additional page actions
359 foreach ($this->page_gui->getAdditionalPageActions() as $item) {
360 $items[] = $item;
361 }
362
363 return $ui->factory()->dropdown()->standard($items);
364 }
365
369 public function getMultiLangActions(): array
370 {
371 $config = $this->page_gui->getPageConfig();
372 $page = $this->page_gui->getPageObject();
374 $ui = $this->ui;
376
377 $items = [];
378
379
380 // general multi lang support and single page mode?
381 if ($config->getMultiLangSupport()) {
382 $ot = \ilObjectTranslation::getInstance($page->getParentId());
383
384 if ($ot->getContentActivated()) {
385 $lng->loadLanguageModule("meta");
386
387 if ($page->getLanguage() != "-") {
388 $l = $ot->getMasterLanguage();
389 $items[] = $ui->factory()->link()->standard(
390 $lng->txt("cont_edit_language_version") . ": " .
391 $lng->txt("meta_l_" . $l),
392 $ctrl->getLinkTarget($this->page_gui, "editMasterLanguage")
393 );
394 }
395
396 foreach ($ot->getLanguages() as $al => $lang) {
397 if ($page->getLanguage() != $al &&
398 $al != $ot->getMasterLanguage()) {
399 $ctrl->setParameter($this->page_gui, "totransl", $al);
400 $items[] = $ui->factory()->link()->standard(
401 $lng->txt("cont_edit_language_version") . ": " .
402 $lng->txt("meta_l_" . $al),
403 $ctrl->getLinkTarget($this->page_gui, "switchToLanguage")
404 );
405 $ctrl->setParameter($this->page_gui, "totransl", "");
406 }
407 }
408 }
409 }
410
411 return $items;
412 }
413
414 public function getMultiLangInfo(): string
415 {
416 $info = "";
417
418 $config = $this->page_gui->getPageConfig();
419 $page = $this->page_gui->getPageObject();
421 $ui = $this->ui;
422
423 // general multi lang support and single page mode?
424 if ($config->getMultiLangSupport()) {
425 $ot = \ilObjectTranslation::getInstance($page->getParentId());
426
427 if ($ot->getContentActivated()) {
428 $lng->loadLanguageModule("meta");
429
430 $ml_gui = new \ilPageMultiLangGUI(
431 $page->getParentType(),
432 $page->getParentId()
433 );
434 $info = $ml_gui->getMultiLangInfo($page->getLanguage());
435 $info = $ui->renderer()->renderAsync($ui->factory()->messageBox()->info($info));
436 }
437 }
438
439 return $info;
440 }
441
442 protected function getMultiActions(): string
443 {
444 $groups = [
445 [
446 "cut" => "cut",
447 "copy" => "copy",
448 "delete" => "delete"
449 ],
450 [
451 "all" => "select_all",
452 "none" => "cont_select_none",
453 ],
454 [
455 "activate" => "cont_ed_enable",
456 "characteristic" => "cont_assign_characteristic"
457 ]
458 ];
459
460 return $this->ui_wrapper->getRenderedButtonGroups($groups);
461 }
462
466 protected function getPasteMessage(): string
467 {
469
470 $html = $this->ui_wrapper->getRenderedInfoBox($lng->txt("cont_sel_el_use_paste"));
471
472 return $html;
473 }
474
478 protected function getErrorMessage(): string
479 {
480 $html = $this->ui_wrapper->getRenderedFailureBox();
481
482 return $html;
483 }
484
485 protected function getErrorModalMessage(): string
486 {
487 $html = $this->ui_wrapper->getRenderedModalFailureBox();
488
489 return $html;
490 }
491
492 protected function getFormatSelection(): string
493 {
495 $ui = $this->ui;
496 $tpl = new \ilTemplate("tpl.format_selection.html", true, true, "Services/COPage/Editor");
497 $tpl->setVariable("TXT_PAR", $lng->txt("cont_choose_characteristic_text"));
498 $tpl->setVariable("TXT_SECTION", $lng->txt("cont_choose_characteristic_section"));
499 $tpl->setVariable("TXT_MEDIA", $lng->txt("cont_media"));
500
501 $par_sel = new ParagraphStyleSelector($this->ui_wrapper, $this->page_gui->getStyleId());
502 $tpl->setVariable("PAR_SELECTOR", $ui->renderer()->renderAsync($par_sel->getStyleSelector("", "format", "format.paragraph", "format")));
503
504 $sec_sel = new SectionStyleSelector($this->ui_wrapper, $this->page_gui->getStyleId());
505 $tpl->setVariable("SEC_SELECTOR", $ui->renderer()->renderAsync($sec_sel->getStyleSelector("", "format", "format.section", "format")));
506
507 $med_sel = new MediaObjectStyleSelector($this->ui_wrapper, $this->page_gui->getStyleId());
508 $tpl->setVariable("MEDIA_SELECTOR", $ui->renderer()->renderAsync($med_sel->getStyleSelector("", "format", "format.media", "format")));
509
510 $tpl->setVariable(
511 "SAVE_BUTTON",
512 $this->ui_wrapper->getRenderedButton(
513 $lng->txt("save"),
514 "format",
515 "format.save"
516 )
517 );
518 $tpl->setVariable(
519 "CANCEL_BUTTON",
520 $this->ui_wrapper->getRenderedButton(
521 $lng->txt("cancel"),
522 "format",
523 "format.cancel"
524 )
525 );
526 return $tpl->get();
527 }
528
529
533 protected function getPCModel(): array
534 {
535 return $this->page_gui->getPageObject()->getPCModel();
536 }
537
539 {
541 $form = "";
542 if (!is_null($pc_edit)) {
543 $form = $pc_edit->getEditComponentForm(
544 $this->ui_wrapper,
545 $this->page_gui->getPageObject()->getParentType(),
546 $this->page_gui,
547 $this->page_gui->getStyleId(),
548 $query["pcid"]
549 );
550 }
551 $o = new \stdClass();
552 $o->editForm = $form;
553 return new Server\Response($o);
554 }
555
559 protected function getComponentsEditorUI(): array
560 {
561 $ui = [];
562 foreach (\ilCOPagePCDef::getPCDefinitions() as $def) {
563 $pc_edit = \ilCOPagePCDef::getPCEditorInstanceByName($def["name"]);
564 if (!is_null($pc_edit)) {
565 $ui[$def["name"]] = $pc_edit->getEditorElements(
566 $this->ui_wrapper,
567 $this->page_gui->getPageObject()->getParentType(),
568 $this->page_gui,
569 $this->page_gui->getStyleId()
570 );
571 }
572 }
573 return $ui;
574 }
575
576 protected function getComponentsDefinitions(): array
577 {
578 $pcdef = [];
579 foreach (\ilCOPagePCDef::getPCDefinitions() as $def) {
580 $pcdef["types"][$def["name"]] = $def["pc_type"];
581 $pcdef["names"][$def["pc_type"]] = $def["name"];
582 $pcdef["txt"][$def["pc_type"]] = $this->lng->txt("cont_" . "pc_" . $def["pc_type"]);
583 }
584 return $pcdef;
585 }
586
587 public function getModalTemplate(): array
588 {
589 $ui = $this->ui;
590 $modal = $ui->factory()->modal()->roundtrip('#title#', $ui->factory()->legacy('#content#'))
591 ->withActionButtons([
592 $ui->factory()->button()->standard('#button_title#', '#'),
593 ]);
594 $modalt["signal"] = $modal->getShowSignal()->getId();
595 $modalt["template"] = $ui->renderer()->renderAsync($modal);
596
597 return $modalt;
598 }
599
603 public function getConfirmationTemplate(): string
604 {
605 $ui = $this->ui;
606
607 $confirmation = $ui->factory()->messageBox()->confirmation("#text#");
608
609 return $ui->renderer()->renderAsync($confirmation);
610 }
611
615 protected function getAutoSaveInterval(): int
616 {
617 $aset = new \ilSetting("adve");
618 return (int) $aset->get("autosave");
619 }
620}
Page editor json server.
static getPCEditorInstanceByName(string $a_name)
Get instance.
getLinkTargetByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
static get(string $a_glyph, string $a_text="")
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
getPref(string $a_keyword)
static getInstance(int $obj_id)
Class ilPageObjectGUI.
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
const ANONYMOUS_USER_ID
Definition: constants.php:27
$txt
Definition: error.php:13
global $DIC
Definition: feed.php:28
This describes commonalities between all types of Dropdowns.
Definition: Dropdown.php:35
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$query
$type
$lm_set
$lang
Definition: xapiexit.php:26