ILIAS  release_7 Revision v7.30-3-g800a261c036
class.PageQueryActionHandler.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
12
17{
21 protected $ui;
22
26 protected $lng;
27
31 protected $page_gui;
32
36 protected $user;
37
41 protected $ui_wrapper;
42
46 protected $ctrl;
47
51 protected $plugin_admin;
52
53
55 {
56 global $DIC;
57
58 $this->ui = $DIC->ui();
59 $this->lng = $DIC->language();
60 $this->page_gui = $page_gui;
61 $this->user = $DIC->user();
62 $this->ctrl = $DIC->ctrl();
63 $this->plugin_admin = $DIC["ilPluginAdmin"];
64
65 $this->ui_wrapper = new Server\UIWrapper($this->ui, $this->lng);
66 }
67
73 public function handle($query) : Server\Response
74 {
75 switch ($query["action"]) {
76 case "ui.all":
77 return $this->allCommand();
78 break;
79 case "component.edit.form":
80 return $this->componentEditFormResponse($query);
81 break;
82 }
83 throw new Exception("Unknown action " . $query["action"]);
84 }
85
91 protected function allCommand() : Server\Response
92 {
94 $f = $this->ui->factory();
95 $dd = $f->dropdown()->standard([
96 $f->link()->standard("label", "#")
97 ]);
98 $r = $this->ui->renderer();
99 $o = new \stdClass();
100 $o->dropdown = $r->render($dd);
101 $o->addCommands = $this->getAddCommands();
102 $o->pageEditHelp = $this->getPageEditHelp();
103 $o->multiEditHelp = $this->getMultiEditHelp();
104 $o->pageTopActions = $this->getTopActions();
105 $o->multiActions = $this->getMultiActions();
106 $o->pasteMessage = $this->getPasteMessage();
107 $o->errorMessage = $this->getErrorMessage();
108 $o->errorModalMessage = $this->getErrorModalMessage();
109 $o->config = $this->getConfig();
110 $o->components = $this->getComponentsEditorUI();
111 $o->pcModel = $this->getPCModel();
112 $o->pcDefinition = $this->getComponentsDefinitions();
113 $o->formatSelection = $this->getFormatSelection();
114 $o->modal = $this->getModalTemplate();
115 $o->confirmation = $this->getConfirmationTemplate();
116 $o->autoSaveInterval = $this->getAutoSaveInterval();
117 $o->backUrl = $ctrl->getLinkTarget($this->page_gui, "edit");
118 $o->pasting = (bool) (in_array(\ilEditClipboard::getAction(), ["copy", "cut"])) &&
119 count($this->user->getPCClipboardContent()) > 0;
120 $o->loaderUrl = \ilUtil::getImagePath("loader.svg");
121 return new Server\Response($o);
122 }
123
128 protected function getConfig()
129 {
130 $config = new \stdClass();
131 $config->user = $this->user->getLogin();
132 $config->content_css =
133 \ilObjStyleSheet::getContentStylePath((int) $this->page_gui->getStyleId()) . ", " .
135 "./Services/COPage/css/tiny_extra.css";
136 $config->text_formats = \ilPCParagraphGUI::_getTextCharacteristics($this->page_gui->getStyleId());
137 $config->text_block_formats = [];
138 foreach (["text_block", "heading1", "heading2", "heading3"] as $type) {
139 $dummy_pc = new \ilPCParagraphGUI($this->page_gui->getPageObject(), null, "");
140 $dummy_pc->setStyleId($this->page_gui->getStyleId());
141 $dummy_pc->getCharacteristicsOfCurrentStyle($type);
142 foreach ($dummy_pc->getCharacteristics() as $char => $txt) {
143 $config->text_block_formats[$char] = $txt;
144 }
145 }
146 $config->editPlaceholders = $this->page_gui->getPageConfig()->getEnablePCType("PlaceHolder");
147
148 return $config;
149 }
150
156 protected function getAddCommands()
157 {
159
160 $commands = [];
161
162 // content types
163 $config = $this->page_gui->getPageConfig();
164 foreach ($config->getEnabledTopPCTypes() as $def) {
165 $commands[$def["pc_type"]] = $lng->txt("cont_ed_insert_" . $def["pc_type"]);
166 }
167
168 // content templates
169 if (count($this->page_gui->getPageObject()->getContentTemplates()) > 0) {
170 $commands["templ"] = $lng->txt("cont_ed_insert_templ");
171 }
172
173 // plugins
174 $pl_names = $this->plugin_admin->getActivePluginsForSlot(
176 "COPage",
177 "pgcp"
178 );
179 foreach ($pl_names as $pl_name) {
180 $plugin = $this->plugin_admin->getPluginObject(
182 "COPage",
183 "pgcp",
184 $pl_name
185 );
186 $commands["plug_" . $plugin->getPluginName()] =
188 }
189
190 return $commands;
191 }
192
197 protected function getPageEditHelp()
198 {
200 $lng->loadLanguageModule("content");
201 $tpl = new \ilTemplate("tpl.page_edit_help.html", true, true, "Services/COPage/Editor");
202 $tpl->setCurrentBlock("help");
203 $tpl->setVariable("TXT_ADD_EL", $lng->txt("cont_add_elements"));
204 $tpl->setVariable("PLUS", \ilGlyphGUI::get(\ilGlyphGUI::ADD));
205 $tpl->setVariable("DRAG_ARROW", \ilGlyphGUI::get(\ilGlyphGUI::DRAG));
206 $tpl->setVariable("TXT_DRAG", $lng->txt("cont_drag_and_drop_elements"));
207 $tpl->setVariable("TXT_EDIT", $lng->txt("cont_click_edit"));
208 $tpl->setVariable("TXT_SEL", $lng->txt("cont_shift_click_to_select"));
209 $tpl->parseCurrentBlock();
210
211 return $tpl->get();
212 }
213
218 protected function getMultiEditHelp()
219 {
221 $lng->loadLanguageModule("content");
222 $tpl = new \ilTemplate("tpl.page_edit_help.html", true, true, "Services/COPage/Editor");
223 $tpl->setCurrentBlock("multi-help");
224 $tpl->setVariable("TXT_SEL", $lng->txt("cont_click_multi_select"));
225 $tpl->parseCurrentBlock();
226
227 return $tpl->get();
228 }
229
234 protected function getTopActions()
235 {
236 $ui = $this->ui;
238
240 $lng->loadLanguageModule("content");
241 $tpl = new \ilTemplate("tpl.top_actions.html", true, true, "Services/COPage/Editor");
242
243 $dd = $this->getActionsDropDown();
244 $tpl->setVariable("DROPDOWN", $ui->renderer()->renderAsync($dd));
245
246 if ($this->page_gui->getPageObject()->getEffectiveEditLockTime() > 0) {
247 $mess = $this->page_gui->getBlockingInfoMessage();
248 $tpl->setVariable("MESSAGE", $mess);
249 $b = $ui->factory()->button()->standard(
250 $lng->txt("cont_finish_editing"),
251 $ctrl->getLinkTarget($this->page_gui, "releasePageLock")
252 );
253 } else {
254 $b = $ui->factory()->button()->standard(
255 $lng->txt("cont_finish_editing"),
256 $ctrl->getLinkTarget($this->page_gui, "finishEditing")
257 );
258 }
259 $tpl->setVariable("MESSAGE2", $this->getMultiLangInfo());
260 $tpl->setVariable("QUIT_BUTTON", $ui->renderer()->renderAsync($b));
261
262 $html = $this->ui_wrapper->getRenderedViewControl(
263 [
264 ["Page", "switch.single", $lng->txt("cont_edit_comp")],
265 ["Page", "switch.multi", $lng->txt("cont_edit_multi")]
266 ]
267 );
268 $tpl->setVariable("SWITCH", $html);
269 $tpl->setVariable("SRC_LOADER", \ilUtil::getImagePath("loader.svg"));
270
271 return $tpl->get();
272 }
273
277 public function getActionsDropDown()
278 {
279 $ui = $this->ui;
281 $config = $this->page_gui->getPageConfig();
282 $page = $this->page_gui->getPageObject();
285
286 // determine media, html and javascript mode
287 $sel_media_mode = ($user->getPref("ilPageEditor_MediaMode") != "disable");
288 $sel_html_mode = ($user->getPref("ilPageEditor_HTMLMode") != "disable");
289 $sel_js_mode = \ilPageEditorGUI::_doJSEditing();
290
291 $items = [];
292
293 // activate/deactivate
294 if ($config->getEnableActivation()) {
295 $captions = $this->page_gui->getActivationCaptions();
296
297 if ($page->getActive()) {
298 $items[] = $ui->factory()->link()->standard(
299 $captions["deactivatePage"],
300 $ctrl->getLinkTarget($this->page_gui, "deactivatePage")
301 );
302 } else {
303 $items[] = $ui->factory()->link()->standard(
304 $captions["activatePage"],
305 $ctrl->getLinkTarget($this->page_gui, "activatePage")
306 );
307 }
308 }
309
310 // initially opened content
311 if ($config->getUseAttachedContent()) {
312 $items[] = $ui->factory()->link()->standard(
313 $lng->txt("cont_initial_attached_content"),
314 $ctrl->getLinkTarget($this->page_gui, "initialOpenedContent")
315 );
316 }
317
318 // multi-lang actions
319 foreach ($this->getMultiLangActions() as $item) {
320 $items[] = $item;
321 }
322
323 $lng->loadLanguageModule("content");
324
325 // media mode
326 if ($sel_media_mode) {
327 $ctrl->setParameter($this->page_gui, "media_mode", "disable");
328 $items[] = $ui->factory()->link()->standard(
329 $lng->txt("cont_deactivate_media"),
330 $ctrl->getLinkTarget($this->page_gui, "setEditMode")
331 );
332 } else {
333 $ctrl->setParameter($this->page_gui, "media_mode", "enable");
334 $items[] = $ui->factory()->link()->standard(
335 $lng->txt("cont_activate_media"),
336 $ctrl->getLinkTarget($this->page_gui, "setEditMode")
337 );
338 }
339 $ctrl->setParameter($this, "media_mode", "");
340
341 // html mode
342 if (!$config->getPreventHTMLUnmasking()) {
343 if ($sel_html_mode) {
344 $ctrl->setParameter($this->page_gui, "html_mode", "disable");
345 $items[] = $ui->factory()->link()->standard(
346 $lng->txt("cont_deactivate_html"),
347 $ctrl->getLinkTarget($this->page_gui, "setEditMode")
348 );
349 } else {
350 $ctrl->setParameter($this->page_gui, "html_mode", "enable");
351 $items[] = $ui->factory()->link()->standard(
352 $lng->txt("cont_activate_html"),
353 $ctrl->getLinkTarget($this->page_gui, "setEditMode")
354 );
355 }
356 }
357 $ctrl->setParameter($this->page_gui, "html_mode", "");
358
359 $lm_set = new \ilSetting("lm");
360 if ($this->page_gui->getEnableEditing() && $this->user->getId() != ANONYMOUS_USER_ID) {
361
362 // history
363 if ($lm_set->get("page_history", 1)) {
364 $items[] = $ui->factory()->link()->standard(
365 $lng->txt("history"),
366 $ctrl->getLinkTarget($this->page_gui, "history")
367 );
368 }
369
370 if ($config->getEnableScheduledActivation()) {
371 $items[] = $ui->factory()->link()->standard(
372 $lng->txt("cont_activation"),
373 $ctrl->getLinkTarget($this->page_gui, "editActivation")
374 );
375 }
376
377 // clipboard
378 $items[] = $ui->factory()->link()->standard(
379 $lng->txt("clipboard"),
380 $ctrl->getLinkTargetByClass([get_class($this->page_gui), "ilEditClipboardGUI"], "view")
381 );
382 }
383
384
385 // additional page actions
386 foreach ($this->page_gui->getAdditionalPageActions() as $item) {
387 $items[] = $item;
388 }
389
390 return $ui->factory()->dropdown()->standard($items);
391 }
392
399 public function getMultiLangActions()
400 {
401 $config = $this->page_gui->getPageConfig();
402 $page = $this->page_gui->getPageObject();
404 $ui = $this->ui;
406
407 $items = [];
408
409
410 // general multi lang support and single page mode?
411 if ($config->getMultiLangSupport()) {
412 $ot = \ilObjectTranslation::getInstance($page->getParentId());
413
414 if ($ot->getContentActivated()) {
415 $lng->loadLanguageModule("meta");
416
417 if ($page->getLanguage() != "-") {
418 $l = $ot->getMasterLanguage();
419 $items[] = $ui->factory()->link()->standard(
420 $lng->txt("cont_edit_language_version") . ": " .
421 $lng->txt("meta_l_" . $l),
422 $ctrl->getLinkTarget($this->page_gui, "editMasterLanguage")
423 );
424 }
425
426 foreach ($ot->getLanguages() as $al => $lang) {
427 if ($page->getLanguage() != $al &&
428 $al != $ot->getMasterLanguage()) {
429 $ctrl->setParameter($this->page_gui, "totransl", $al);
430 $items[] = $ui->factory()->link()->standard(
431 $lng->txt("cont_edit_language_version") . ": " .
432 $lng->txt("meta_l_" . $al),
433 $ctrl->getLinkTarget($this->page_gui, "switchToLanguage")
434 );
435 $ctrl->setParameter($this->page_gui, "totransl", $_GET["totransl"]);
436 }
437 }
438 }
439 }
440
441 return $items;
442 }
443
444 public function getMultiLangInfo()
445 {
446 $info = "";
447
448 $config = $this->page_gui->getPageConfig();
449 $page = $this->page_gui->getPageObject();
451 $ui = $this->ui;
452
453 // general multi lang support and single page mode?
454 if ($config->getMultiLangSupport()) {
455 $ot = \ilObjectTranslation::getInstance($page->getParentId());
456
457 if ($ot->getContentActivated()) {
458 $lng->loadLanguageModule("meta");
459
460 $ml_gui = new \ilPageMultiLangGUI(
461 $page->getParentType(),
462 $page->getParentId()
463 );
464 $info = $ml_gui->getMultiLangInfo($page->getLanguage());
465 $info = $ui->renderer()->renderAsync($ui->factory()->messageBox()->info($info));
466 }
467 }
468
469 return $info;
470 }
471
472
477 protected function getMultiActions()
478 {
479 $groups = [
480 [
481 "cut" => "cut",
482 "copy" => "copy",
483 "delete" => "delete"
484 ],
485 [
486 "all" => "select_all",
487 "none" => "cont_select_none",
488 ],
489 [
490 "activate" => "cont_ed_enable",
491 "characteristic" => "cont_assign_characteristic"
492 ]
493 ];
494
495 return $this->ui_wrapper->getRenderedButtonGroups($groups);
496 }
497
502 protected function getPasteMessage()
503 {
505
506 $html = $this->ui_wrapper->getRenderedInfoBox($lng->txt("cont_sel_el_use_paste"));
507
508 return $html;
509 }
510
515 protected function getErrorMessage()
516 {
517 $html = $this->ui_wrapper->getRenderedFailureBox();
518
519 return $html;
520 }
521
525 protected function getErrorModalMessage() : string
526 {
527 $html = $this->ui_wrapper->getRenderedModalFailureBox();
528
529 return $html;
530 }
531
535 protected function getFormatSelection()
536 {
538 $ui = $this->ui;
539 $tpl = new \ilTemplate("tpl.format_selection.html", true, true, "Services/COPage/Editor");
540 $tpl->setVariable("TXT_PAR", $lng->txt("cont_choose_characteristic_text"));
541 $tpl->setVariable("TXT_SECTION", $lng->txt("cont_choose_characteristic_section"));
542 $tpl->setVariable("TXT_MEDIA", $lng->txt("cont_media"));
543
544 $par_sel = new ParagraphStyleSelector($this->ui_wrapper, $this->page_gui->getStyleId());
545 $tpl->setVariable("PAR_SELECTOR", $ui->renderer()->renderAsync($par_sel->getStyleSelector("", "format", "format.paragraph", "format")));
546
547 $sec_sel = new SectionStyleSelector($this->ui_wrapper, $this->page_gui->getStyleId());
548 $tpl->setVariable("SEC_SELECTOR", $ui->renderer()->renderAsync($sec_sel->getStyleSelector("", "format", "format.section", "format")));
549
550 $med_sel = new MediaObjectStyleSelector($this->ui_wrapper, $this->page_gui->getStyleId());
551 $tpl->setVariable("MEDIA_SELECTOR", $ui->renderer()->renderAsync($med_sel->getStyleSelector("", "format", "format.media", "format")));
552
553 $tpl->setVariable(
554 "SAVE_BUTTON",
555 $this->ui_wrapper->getRenderedButton(
556 $lng->txt("save"),
557 "format",
558 "format.save"
559 )
560 );
561 $tpl->setVariable(
562 "CANCEL_BUTTON",
563 $this->ui_wrapper->getRenderedButton(
564 $lng->txt("cancel"),
565 "format",
566 "format.cancel"
567 )
568 );
569 return $tpl->get();
570 }
571
572
578 protected function getPCModel()
579 {
580 return $this->page_gui->getPageObject()->getPCModel();
581 }
582
588 {
590 $form = "";
591 if (!is_null($pc_edit)) {
592 $form = $pc_edit->getEditComponentForm(
593 $this->ui_wrapper,
594 $this->page_gui->getPageObject()->getParentType(),
595 $this->page_gui,
596 (int) $this->page_gui->getStyleId(),
597 $query["pcid"]
598 );
599 }
600 $o = new \stdClass();
601 $o->editForm = $form;
602 return new Server\Response($o);
603 }
604
610 protected function getComponentsEditorUI()
611 {
612 $ui = [];
613 foreach (\ilCOPagePCDef::getPCDefinitions() as $def) {
614 $pc_edit = \ilCOPagePCDef::getPCEditorInstanceByName($def["name"]);
615 if (!is_null($pc_edit)) {
616 $ui[$def["name"]] = $pc_edit->getEditorElements(
617 $this->ui_wrapper,
618 $this->page_gui->getPageObject()->getParentType(),
619 $this->page_gui,
620 (int) $this->page_gui->getStyleId()
621 );
622 }
623 }
624 return $ui;
625 }
626
631 protected function getComponentsDefinitions()
632 {
633 $pcdef = [];
634 foreach (\ilCOPagePCDef::getPCDefinitions() as $def) {
635 $pcdef["types"][$def["name"]] = $def["pc_type"];
636 $pcdef["names"][$def["pc_type"]] = $def["name"];
637 $pcdef["txt"][$def["pc_type"]] = $this->lng->txt("cont_" . "pc_" . $def["pc_type"]);
638 }
639 return $pcdef;
640 }
641
645 public function getModalTemplate()
646 {
647 $ui = $this->ui;
648 $modal = $ui->factory()->modal()->roundtrip('#title#', $ui->factory()->legacy('#content#'))
649 ->withActionButtons([
650 $ui->factory()->button()->standard('#button_title#', '#'),
651 ]);
652 $modalt["signal"] = $modal->getShowSignal()->getId();
653 $modalt["template"] = $ui->renderer()->renderAsync($modal);
654
655 return $modalt;
656 }
657
661 public function getConfirmationTemplate()
662 {
663 $ui = $this->ui;
664
665 $confirmation = $ui->factory()->messageBox()->confirmation("#text#");
666
667 return $ui->renderer()->renderAsync($confirmation);
668 }
669
674 protected function getAutoSaveInterval()
675 {
676 $aset = new \ilSetting("adve");
677 return (int) $aset->get("autosave");
678 }
679}
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Page editor json server.
const IL_COMP_SERVICE
static getPCDefinitions()
Get PC definitions.
static getPCEditorInstanceByName($a_name)
Get instance.
static get($a_glyph, $a_text="")
Get glyph html.
static getContentStylePath($a_style_id, $add_random=true, $add_token=true)
get content style path
static getInstance($a_obj_id)
Get instance.
static _getTextCharacteristics($a_style_id, $a_include_core=false)
Get text characteristics.
static _doJSEditing()
checks if current user has activated js editing and if browser is js capable
Class ilPageObjectGUI.
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
const ANONYMOUS_USER_ID
Definition: constants.php:25
$txt
Definition: error.php:13
global $DIC
Definition: goto.php:24
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:68
$query
$type
$lm_set
ui()
Definition: ui.php:5
$lang
Definition: xapiexit.php:8