ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCParagraphGUI.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\Style;
20
27{
28 protected ilObjUser $user;
29
30 public function __construct(
31 ilPageObject $a_pg_obj,
32 ?ilPageContent $a_content_obj,
33 string $a_hier_id,
34 string $a_pc_id = ""
35 ) {
36 global $DIC;
37
38 $this->user = $DIC->user();
39 $this->ctrl = $DIC->ctrl();
40 $this->lng = $DIC->language();
41 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
42
43 // characteristics (should be flexible in the future)
45 }
46
50 public static function _getStandardCharacteristics(): array
51 {
52 global $DIC;
53
54 $lng = $DIC->language();
55
56 return array("Standard" => $lng->txt("cont_standard"),
57 "Headline1" => $lng->txt("cont_Headline1"),
58 "Headline2" => $lng->txt("cont_Headline2"),
59 "Headline3" => $lng->txt("cont_Headline3"),
60 "Book" => $lng->txt("cont_Book"),
61 "Numbers" => $lng->txt("cont_Numbers"),
62 "Verse" => $lng->txt("cont_Verse"),
63 "List" => $lng->txt("cont_List"),
64 "TableContent" => $lng->txt("cont_TableContent")
65 );
66 }
67
71 public static function _getStandardTextCharacteristics(): array
72 {
73 return ["Mnemonic", "Attention"];
74 }
75
79 public static function _getCharacteristics(int $a_style_id): array
80 {
81 global $DIC;
82 $request = $DIC->copage()->internal()
83 ->gui()
84 ->pc()
85 ->editRequest();
86 $requested_ref_id = $request->getRefId();
87
88 $service = $DIC->contentStyle()->internal();
89
92 if ($a_style_id > 0 &&
93 ilObject::_lookupType($a_style_id) == "sty") {
94 $access_manager = $service->domain()->access(
96 $DIC->user()->getId()
97 );
98 $char_manager = $service->domain()->characteristic(
99 $a_style_id,
100 $access_manager
101 );
102
103 $chars = $char_manager->getByTypes(
104 ["text_block", "heading1", "heading2", "heading3"],
105 false,
106 false
107 );
108 $new_chars = array();
109 foreach ($chars as $char) {
110 if (($st_chars[$char->getCharacteristic()] ?? "") != "") { // keep lang vars for standard chars
111 $title = $char_manager->getPresentationTitle(
112 $char->getType(),
113 $char->getCharacteristic()
114 );
115 if ($title == "") {
116 $title = $st_chars[$char->getCharacteristic()];
117 }
118 $new_chars[$char->getCharacteristic()] = $title;
119 } else {
120 $new_chars[$char->getCharacteristic()] = $char_manager->getPresentationTitle(
121 $char->getType(),
122 $char->getCharacteristic()
123 );
124 }
125 }
126 $chars = $new_chars;
127 }
128
129 return $chars;
130 }
131
135 public static function _getTextCharacteristics(
136 int $a_style_id,
137 bool $a_include_core = false
138 ): array {
139 global $DIC;
140
141 $chars = array();
142
143 $service = $DIC->contentStyle()->internal();
144 $request = $DIC->copage()->internal()
145 ->gui()
146 ->pc()
147 ->editRequest();
148 $requested_ref_id = $request->getRefId();
149
150 if ($a_style_id > 0 &&
151 ilObject::_lookupType($a_style_id) == "sty") {
152
153 $access_manager = $service->domain()->access(
155 $DIC->user()->getId()
156 );
157 $char_manager = $service->domain()->characteristic(
158 $a_style_id,
159 $access_manager
160 );
161
162 $style = new ilObjStyleSheet($a_style_id);
163 /*$ti_chars = $style->getCharacteristics("text_inline", false, $a_include_core);*/
164 $ti_chars = $char_manager->getByTypes(
165 ["text_inline", "code_inline"],
166 false,
167 false
168 );
170 foreach ($ti_chars as $k => $v) {
171 if (!$char_manager->isOutdated("text_inline", $v->getCharacteristic())) {
172 $chars[] = $v->getCharacteristic();
173 }
174 }
175 } else {
177 }
178
179 return $chars;
180 }
181
182
187 public function executeCommand()
188 {
189 // get next class that processes or forwards current command
190 $next_class = $this->ctrl->getNextClass($this);
191
192 $this->getCharacteristicsOfCurrentStyle(
193 array("text_block", "heading1", "heading2", "heading3")
194 ); // scorm-2004
195
196 // get current command
197 $cmd = $this->ctrl->getCmd();
198
199 $this->log->debug("ilPCParagraphGUI: executeCommand " . $cmd);
200
201 switch ($next_class) {
202 default:
203 $ret = $this->$cmd();
204 break;
205 }
206
207 return $ret;
208 }
209
210
214 public function determineCharacteristic(bool $a_insert = false): string
215 {
216 $cmd = $this->ctrl->getCmd();
217 // language and characteristic selection
218 if (!$a_insert) {
219 if ($cmd == "update") {
220 $s_char = $this->request->getString("par_characteristic");
221 } else {
222 $s_char = $this->content_obj->getCharacteristic();
223 if ($s_char == "") {
224 $s_char = "Standard";
225 }
226 }
227 } else {
228 if ($cmd == "create") {
229 $s_char = $this->request->getString("par_characteristic");
230 } else {
231 $s_char = "Standard";
232
233 // set characteristic of new paragraphs in list items to "List"
234 $cont_obj = $this->pg_obj->getContentObject($this->getHierId());
235 if (is_object($cont_obj)) {
236 if ($cont_obj->getType() == "li" ||
237 ($cont_obj->getType() == "par" && $cont_obj->getCharacteristic() == "List")) {
238 $s_char = "List";
239 }
240
241 if ($cont_obj->getType() == "td" ||
242 ($cont_obj->getType() == "par" && $cont_obj->getCharacteristic() == "TableContent")) {
243 $s_char = "TableContent";
244 }
245 }
246 }
247 }
248 return $s_char;
249 }
250
254 public function editJS(): void
255 {
256 $s_text = $this->content_obj->getText();
257 $this->log->debug("step 1: " . substr($s_text, 0, 1000));
258
259 //echo "\n<br><br>".htmlentities($s_text);
260 $s_text = $this->content_obj->xml2output($s_text, true, false);
261 $this->log->debug("step 2: " . substr($s_text, 0, 1000));
262
263 //echo "\n<br><br>".htmlentities($s_text);
264 $char = $this->determineCharacteristic(false);
265 $s_text = ilPCParagraphGUI::xml2outputJS($s_text);
266 $this->log->debug("step 3: " . substr($s_text, 0, 1000));
267
268 //echo "\n<br><br>".htmlentities($s_text);
269 $ids = "###" . $this->content_obj->readHierId() . ":" . $this->content_obj->readPCId() . "###" .
270 $char . "###";
271 echo $ids . $s_text;
272 $this->log->debug("step 4: " . substr($ids . $s_text, 0, 1000));
273 exit;
274 }
275
279 public static function xml2outputJS(string $s_text): string
280 {
281 // lists
282 $s_text = str_replace(
283 array("<SimpleBulletList>", "</SimpleBulletList>"),
284 array('<ul class="ilc_list_u_BulletedList">', "</ul>"),
285 $s_text
286 );
287 while (preg_match('~<SimpleBulletList Class=\"([^\"]*)\">~i', $s_text, $found)) {
288 $class = $found[1];
289 $s_text = str_replace('<SimpleBulletList Class="' . $class . '">', '<ul class="ilc_list_u_' . $class . '">', $s_text);
290 }
291 $s_text = str_replace(
292 array("<SimpleNumberedList>", "</SimpleNumberedList>"),
293 array('<ol class="ilc_list_o_NumberedList">', "</ol>"),
294 $s_text
295 );
296 while (preg_match('~<SimpleNumberedList Class=\"([^\"]*)\">~i', $s_text, $found)) {
297 $class = $found[1];
298 $s_text = str_replace('<SimpleNumberedList Class="' . $class . '">', '<ol class="ilc_list_o_' . $class . '">', $s_text);
299 }
300 $s_text = str_replace(
301 array("<SimpleListItem>", "</SimpleListItem>"),
302 array('<li class="ilc_list_item_StandardListItem">', "</li>"),
303 $s_text
304 );
305 $s_text = str_replace(
306 array("<SimpleListItem/>"),
307 array('<li class="ilc_list_item_StandardListItem"></li>'),
308 $s_text
309 );
310 while (preg_match('~<SimpleListItem Class=\"([^\"]*)\">~i', $s_text, $found)) {
311 $class = $found[1];
312 $s_text = str_replace('<SimpleListItem Class="' . $class . '">', '<li class="ilc_list_item_' . $class . '">', $s_text);
313 }
314
315 // spans
316 foreach (ilPageContentGUI::_getCommonBBButtons() as $bb => $cl) {
317 if (!in_array($bb, array("code", "tex", "fn", "xln", "sub", "sup"))) {
318 $s_text = str_replace(
319 "[" . $bb . "]",
320 '<span class="ilc_text_inline_' . $cl . '">',
321 $s_text
322 );
323 $s_text = str_replace(
324 "[/" . $bb . "]",
325 '</span>',
326 $s_text
327 );
328 }
329 }
330
331 // marked text spans
332 $ws = "[ \t\r\f\v\n]*";
333 while (preg_match("~\[(marked$ws(class$ws=$ws\"([^\"])*\")$ws)\]~i", $s_text, $found)) {
334 $attribs = ilPCParagraph::attribsToArray($found[2]);
335 if (isset($attribs["class"])) {
336 $s_text = str_replace("[" . $found[1] . "]", "<span class=\"ilc_text_inline_" . $attribs["class"] . "\">", $s_text);
337 } else {
338 $s_text = str_replace("[" . $found[1] . "]", "[error:marked" . $found[1] . "]", $s_text);
339 }
340 }
341 $s_text = preg_replace('~\[\/marked\]~i', "</span>", $s_text);
342
343
344 // code
345 $s_text = str_replace(
346 array("[code]", "[/code]"),
347 array("<code>", "</code>"),
348 $s_text
349 );
350
351 // sup
352 $s_text = str_replace(
353 array("[sup]", "[/sup]"),
354 array('<sup class="ilc_sup_Sup">', "</sup>"),
355 $s_text
356 );
357
358 // sub
359 $s_text = str_replace(
360 array("[sub]", "[/sub]"),
361 array('<sub class="ilc_sub_Sub">', "</sub>"),
362 $s_text
363 );
364
365 return $s_text;
366 }
367
371 public function outputError(array $a_err): void
372 {
373 $err_str = "";
374 foreach ($a_err as $err) {
375 $err_str .= $err[1] . "<br />";
376 }
377 echo $err_str;
378 $this->log->debug("ilPCParagraphGUI, outputError() and exit: " . substr($err_str, 0, 100));
379 exit;
380 }
381
382 public function cancel(): void
383 {
384 $this->log->debug("ilPCParagraphGUI, cancel(): return to parent: jump" . $this->hier_id);
385 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
386 }
387
392 ilTemplate $a_tpl,
393 string $a_seleted_value
394 ): void {
395 $i = 0;
396
397 $chars = $this->getCharacteristics();
398
399 if ($chars[$a_seleted_value] == "" && ($a_seleted_value != "")) {
400 $chars = array_merge(
401 array($a_seleted_value => $a_seleted_value),
402 $chars
403 );
404 }
405
406 foreach ($chars as $char => $char_lang) {
407 $a_tpl->setCurrentBlock("characteristic_cell");
408 $a_tpl->setVariable(
409 "CHAR_HTML",
410 '<div class="ilc_text_block_' . $char . '" style="margin-top:2px; margin-bottom:2px; position:static;">' . $char_lang . "</div>"
411 );
412 $a_tpl->setVariable("CHAR_VALUE", $char);
413 if ($char == $a_seleted_value) {
414 $a_tpl->setVariable(
415 "SELECTED",
416 ' checked="checked" '
417 );
418 }
419 $a_tpl->parseCurrentBlock();
420 if ((($i + 1) % 3) == 0) { //
421 $a_tpl->touchBlock("characteristic_row");
422 }
423 $i++;
424 }
425 $a_tpl->touchBlock("characteristic_table");
426 }
427
428 private function setStyle(): void
429 {
430 if ($this->pg_obj->getParentType() == "term" ||
431 $this->pg_obj->getParentType() == "lm") {
432 if ($this->pg_obj->getParentType() != "term") {
433 $this->tpl->addCss(ilObjStyleSheet::getContentStylePath(
434 ilObjContentObject::_lookupStyleSheetId($this->pg_obj->getParentId())
435 ));
436 } else {
437 $this->tpl->addCss(ilObjStyleSheet::getContentStylePath(0));
438 }
439 }
440 }
441
445 public function insertHelp(ilTemplate $a_tpl): void
446 {
448
449 $a_tpl->setCurrentBlock("help_item");
450 $a_tpl->setVariable("TXT_HELP", "<strong>" . $lng->txt("cont_syntax_help") . "</strong>");
451 $a_tpl->parseCurrentBlock();
452 $a_tpl->setCurrentBlock("help_item");
453 $a_tpl->setVariable("TXT_HELP", "* " . $lng->txt("cont_bullet_list"));
454 $a_tpl->parseCurrentBlock();
455 $a_tpl->setCurrentBlock("help_item");
456 $a_tpl->setVariable("TXT_HELP", "# " . $lng->txt("cont_numbered_list"));
457 $a_tpl->parseCurrentBlock();
458 $a_tpl->setCurrentBlock("help_item");
459 $a_tpl->setVariable("TXT_HELP", "=" . $lng->txt("cont_Headline1") . "=<br />" .
460 "==" . $lng->txt("cont_Headline2") . "==<br />" .
461 "===" . $lng->txt("cont_Headline3") . "===");
462 $a_tpl->parseCurrentBlock();
463
464 if ($this->getPageConfig()->getEnableWikiLinks()) {
465 $a_tpl->setCurrentBlock("help_item");
466 $a_tpl->setVariable("TXT_HELP", "[[" . $lng->txt("cont_wiki_page_link") . "]]");
467 $a_tpl->parseCurrentBlock();
468 }
469
470 $a_tpl->setCurrentBlock("help");
471 $a_tpl->parseCurrentBlock();
472 }
473}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
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 _lookupStyleSheetId(int $a_cont_obj_id)
Class ilObjStyleSheet.
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
User class.
static _lookupType(int $id, bool $reference=false)
Class ilPCParagraphGUI User Interface for Paragraph Editing.
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
outputError(array $a_err)
Output error.
insertCharacteristicTable(ilTemplate $a_tpl, string $a_seleted_value)
Insert characteristic table.
static _getCharacteristics(int $a_style_id)
Get characteristics.
editJS()
Edit paragraph (Ajax mode, sends the content of the paragraph)
executeCommand()
execute command
static _getStandardTextCharacteristics()
Get standard characteristics.
determineCharacteristic(bool $a_insert=false)
Determine current characteristic.
static _getStandardCharacteristics()
Get standard characteristics.
insertHelp(ilTemplate $a_tpl)
Insert Help.
static xml2outputJS(string $s_text)
Prepare content for js output.
static attribsToArray(string $a_str)
converts a string of format var1 = "val1" var2 = "val2" ... into an array
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
Style Content CharacteristicManager $char_manager
setCharacteristics(array $a_chars)
Content object of ilPageObject (see ILIAS DTD).
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
touchBlock(string $block)
exit
$service
Definition: ltiresult.php:36
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26