ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLinkInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
16{
18
19 const LIST = "list";
20 const BOTH = "both";
21 const INT = "int";
22 const EXT = "ext";
24 protected $int_link_default_type = "RepositoryItem";
25 protected $int_link_default_obj = 0;
26 protected $int_link_filter_types = array("RepositoryItem");
27 protected $filter_white_list = true;
28
30
31 protected static $iltypemap = array(
32 "page" => "PageObject",
33 "chap" => "StructureObject",
34 "term" => "GlossaryItem",
35 "wpage" => "WikiPage"
36 );
37
41 protected $obj_definition;
42
49 public function __construct($a_title = "", $a_postvar = "")
50 {
51 global $DIC;
52
53 $this->ctrl = $DIC->ctrl();
54 $this->lng = $DIC->language();
55
56 parent::__construct($a_title, $a_postvar);
57 $this->setType("link");
58
59 $this->obj_definition = $DIC["objDefinition"];
60 }
61
67 public function setAllowedLinkTypes($a_val)
68 {
69 $this->allowed_link_types = $a_val;
70 }
71
77 public function getAllowedLinkTypes()
78 {
80 }
81
88 public function setInternalLinkDefault($a_type, $a_obj = 0)
89 {
90 $this->int_link_default_type = $a_type;
91 $this->int_link_default_obj = $a_obj;
92 }
93
99 public function setInternalLinkFilterTypes(array $a_val)
100 {
101 $this->int_link_filter_types = $a_val;
102 }
103
109 public static function getTypeToAttrType()
110 {
111 return self::$iltypemap;
112 }
113
119 public static function getAttrTypeToType()
120 {
121 return array_flip(self::$iltypemap);
122 }
123
129 public function setFilterWhiteList($a_val)
130 {
131 $this->filter_white_list = $a_val;
132 }
133
139 public function getFilterWhiteList()
140 {
142 }
143
147 public function setExternalLinkMaxLength($a_max)
148 {
149 $this->external_link_max_length = $a_max;
150 }
151
155 public function getExternalLinkMaxLength()
156 {
158 }
159
163 public function executeCommand()
164 {
165 $ilCtrl = $this->ctrl;
167
168 $next_class = $ilCtrl->getNextClass($this);
169 $cmd = $ilCtrl->getCmd();
170
171 switch ($next_class) {
172 case "ilinternallinkgui":
173 $lng->loadLanguageModule("content");
174 require_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
175 $link_gui = new ilInternalLinkGUI(
176 $this->int_link_default_type,
177 $this->int_link_default_obj
178 );
179 foreach ($this->int_link_filter_types as $t) {
180 $link_gui->filterLinkType($t);
181 }
182 $link_gui->setFilterWhiteList($this->getFilterWhiteList());
183 $link_gui->setMode("asynch");
184
185 $ret = $ilCtrl->forwardCommand($link_gui);
186 break;
187
188 default:
189 var_dump($cmd);
190 //exit();
191 }
192
193 return $ret;
194 }
195
201 public function setValue($a_value)
202 {
203 $this->value = $a_value;
204 }
205
211 public function getValue()
212 {
213 return $this->value;
214 }
215
221 public function setValueByArray($a_values)
222 {
223 switch ($a_values[$this->getPostVar() . "_mode"]) {
224 case "int":
225 if ($a_values[$this->getPostVar() . "_ajax_type"] &&
226 $a_values[$this->getPostVar() . "_ajax_id"]) {
227 $val = $a_values[$this->getPostVar() . "_ajax_type"] . "|" .
228 $a_values[$this->getPostVar() . "_ajax_id"];
229 if ($a_values[$this->getPostVar() . "_ajax_target"] != "") {
230 $val .= "|" . $a_values[$this->getPostVar() . "_ajax_target"];
231 }
232 $this->setValue($val);
233 }
234 break;
235
236 case "no":
237 break;
238
239 default:
240 if ($a_values[$this->getPostVar()]) {
241 $this->setValue($a_values[$this->getPostVar()]);
242 }
243 break;
244 }
245 }
246
252 public function checkInput()
253 {
255
256 // debugging
257 // return false;
258
259 if ($this->getRequired()) {
260 if ($_POST[$this->getPostVar() . "_mode_type"] == "list") {
261 return true;
262 }
263
264 switch ($_POST[$this->getPostVar() . "_mode"]) {
265 case "ext":
266 if (!$_POST[$this->getPostVar()]) {
267 $this->setAlert($lng->txt("msg_input_is_required"));
268 return false;
269 }
270 break;
271
272 case "int":
273 if (!$_POST[$this->getPostVar() . "_ajax_type"] ||
274 !$_POST[$this->getPostVar() . "_ajax_id"]) {
275 $this->setAlert($lng->txt("msg_input_is_required"));
276 return false;
277 }
278 break;
279
280 case "no":
281 default:
282 $this->setAlert($lng->txt("msg_input_is_required"));
283 return false;
284 }
285 }
286
287 if ($_POST[$this->getPostVar() . "_mode"] == "int") {
288 $_POST[$this->getPostVar() . "_ajax_type"] = ilUtil::stripSlashes($_POST[$this->getPostVar() . "_ajax_type"]);
289 $_POST[$this->getPostVar() . "_ajax_id"] = ilUtil::stripSlashes($_POST[$this->getPostVar() . "_ajax_id"]);
290 $_POST[$this->getPostVar() . "_ajax_target"] = ilUtil::stripSlashes($_POST[$this->getPostVar() . "_ajax_target"]);
291
292 // overwriting post-data so getInput() will work
293 $val = $_POST[$this->getPostVar() . "_ajax_type"] . "|" .
294 $_POST[$this->getPostVar() . "_ajax_id"];
295 if ($_POST[$this->getPostVar() . "_ajax_target"] != "") {
296 $val .= "|" . $_POST[$this->getPostVar() . "_ajax_target"];
297 }
298
299 $_POST[$this->getPostVar()] = $val;
300 } elseif ($_POST[$this->getPostVar() . "_mode"] == "no") {
301 $_POST[$this->getPostVar()] = "";
302 } else {
304 }
305
306 return true;
307 }
308
312 public function render()
313 {
315 $ilCtrl = $this->ctrl;
316
317 // parse settings
318 $has_int = $has_ext = $has_radio = $has_list = false;
319 switch ($this->getAllowedLinkTypes()) {
320 case self::EXT:
321 $has_ext = true;
322 break;
323
324 case self::INT:
325 $has_int = true;
326 break;
327
328 case self::BOTH:
329 $has_int = true;
330 $has_ext = true;
331 $has_radio = true;
332 break;
333
334 case self::LIST:
335 $has_int = true;
336 $has_ext = true;
337 $has_radio = true;
338 $has_list = true;
339 break;
340 }
341 if (!$this->getRequired()) {
342 // see #0021274
343 $has_radio = true;
344 }
345
346 // external
347 if ($has_ext) {
348 $title = $has_radio ? $lng->txt("url") : "";
349
350 // external
351 $ti = new ilTextInputGUI($title, $this->getPostVar());
352 $ti->setMaxLength($this->getExternalLinkMaxLength());
353 }
354
355 // internal
356 if ($has_int) {
357 $ilCtrl->setParameterByClass("ilformpropertydispatchgui", "postvar", $this->getPostVar());
358 $link = array(get_class($this->getParent()), "ilformpropertydispatchgui", get_class($this), "ilinternallinkgui");
359 $link = $ilCtrl->getLinkTargetByClass($link, "", false, true, false);
360 $ilCtrl->setParameterByClass("ilformpropertydispatchgui", "postvar", $_REQUEST["postvar"]);
361
362 $no_disp_class = (strpos($this->getValue(), "|"))
363 ? ""
364 : " ilNoDisplay";
365
366 $itpl = new ilTemplate('tpl.prop_link.html', true, true, 'Services/Form');
367 $itpl->setVariable("VAL_ID", $this->getPostVar());
368 $itpl->setVariable("URL_EDIT", $link);
369 $itpl->setVariable("TXT_EDIT", $lng->txt("form_get_link"));
370 $itpl->setVariable("CSS_REMOVE", $no_disp_class);
371 $itpl->setVariable("TXT_REMOVE", $lng->txt("remove"));
372
373 $ne = new ilNonEditableValueGUI($lng->txt("object"), $this->getPostVar() . "_val", true);
374
375 // hidden field for selected value
376 $hidden_type = new ilHiddenInputGUI($this->getPostVar() . "_ajax_type");
377 $hidden_id = new ilHiddenInputGUI($this->getPostVar() . "_ajax_id");
378 $hidden_target = new ilHiddenInputGUI($this->getPostVar() . "_ajax_target");
379 }
380
381 // mode
382 if ($has_radio) {
383 $ext = new ilRadioOption($lng->txt("form_link_external"), "ext");
384 $ext->addSubItem($ti);
385
386 if ($has_int) {
387 $int = new ilRadioOption($lng->txt("form_link_internal"), "int");
388 $int->addSubItem($ne);
389 }
390
391 $mode = new ilRadioGroupInputGUI("", $this->getPostVar() . "_mode");
392 if (!$this->getRequired()) {
393 $no = new ilRadioOption($lng->txt("form_no_link"), "no");
394 $mode->addOption($no);
395 }
396 $mode->addOption($ext);
397 if ($has_int) {
398 $mode->addOption($int);
399 }
400 } else {
401 $mode = new ilHiddenInputGUI($this->getPostVar() . "_mode");
402 if ($has_int) {
403 $mode->setValue("int");
404 } else {
405 $mode->setValue("ext");
406 }
407 }
408
409 // list mode
410 if ($has_list) {
411 $mode_type = new ilRadioGroupInputGUI("", $this->getPostVar() . "_mode_type");
412 $mode_single = new ilRadioOption($lng->txt("webr_link_type_single"), "single");
413 $mode_type->addOption($mode_single);
414 $mode_list = new ilRadioOption($lng->txt("webr_link_type_list"), "list");
415 $mode_type->addOption($mode_list);
416 $mode = new ilRadioGroupInputGUI($lng->txt("webr_link_target"), $this->getPostVar() . "_mode");
417 if (!$this->getRequired()) {
418 $no = new ilRadioOption($lng->txt("form_no_link"), "no");
419 $mode->addOption($no);
420 }
421 $ext = new ilRadioOption($lng->txt("form_link_external"), "ext");
422 $ext->addSubItem($ti);
423 $int = new ilRadioOption($lng->txt("form_link_internal"), "int");
424 $int->addSubItem($ne);
425 $mode->addOption($ext);
426 $mode->addOption($int);
427 $mode_single->addSubItem($mode);
428 }
429
430 // value
431 $value = $this->getValue();
432 if ($value) {
433 // #15647
434 if ($has_int && self::isInternalLink($value)) {
435 $mode->setValue("int");
436
437 $value_trans = self::getTranslatedValue($value);
438
439 $value = explode("|", $value);
440 $hidden_type->setValue($value[0]);
441 $hidden_id->setValue($value[1]);
442 $hidden_target->setValue($value[2]);
443
444 $itpl->setVariable("VAL_OBJECT_TYPE", $value_trans["type"]);
445 $itpl->setVariable("VAL_OBJECT_NAME", $value_trans["name"]);
446 if ($value[2] != "") {
447 $itpl->setVariable("VAL_TARGET_FRAME", "(" . $value[2] . ")");
448 }
449 } elseif ($has_ext) {
450 $mode->setValue("ext");
451
452 $ti->setValue($value);
453 }
454 } elseif (!$this->getRequired()) {
455 $mode->setValue("no");
456 }
457
458 // #10185 - default for external urls
459 if ($has_ext && !$ti->getValue()) {
460 $ti->setValue("https://");
461 }
462
463 if ($has_int) {
464 $ne->setValue($itpl->get());
465 }
466
467 // to html
468 if ($has_radio) {
469 $html = $mode->render();
470 } else {
471 $html = $mode->getToolbarHTML();
472
473 if ($has_ext) {
474 $html .= $ti->getToolbarHTML();
475 } elseif ($has_int) {
476 $html .= $ne->render() .
477 '<div class="help-block">' . $ne->getInfo() . '</div>';
478 }
479 }
480 if ($has_list) {
481 $html = $mode_type->render();
482 }
483
484 // js for internal link
485 if ($has_int) {
486 include_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
487 $html .= $hidden_type->getToolbarHTML() .
488 $hidden_id->getToolbarHTML() .
489 $hidden_target->getToolbarHTML();
490 }
491
492 return $html;
493 }
494
495 public function getContentOutsideFormTag()
496 {
497 if ($this->getAllowedLinkTypes() == self::INT ||
498 $this->getAllowedLinkTypes() == self::BOTH ||
499 $this->getAllowedLinkTypes() == self::LIST) {
500 // as the ajax-panel uses a form it has to be outside of the parent form!
502 }
503 }
504
505 public static function isInternalLink($a_value)
506 {
507 if (strpos($a_value, "|")) {
508 $parts = explode("|", $a_value);
509 if (sizeof($parts) == 2 || sizeof($parts) == 3) {
510 // numeric id
511 if (is_numeric($parts[1])) {
512 // simple type
513 if (preg_match("/^[a-zA-Z_]+$/", $parts[0], $matches)) {
514 return true;
515 }
516 }
517 }
518 }
519 return false;
520 }
521
522 public static function getTranslatedValue($a_value)
523 {
524 global $DIC;
525
526 $lng = $DIC->language();
527
528 $value = explode("|", $a_value);
529
530 switch ($value[0]) {
531 case "media":
532 $type = $lng->txt("obj_mob");
533 $name = ilObject::_lookupTitle($value[1]);
534 break;
535
536 case "page":
537 include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
538 $type = $lng->txt("obj_pg");
540 break;
541
542 case "chap":
543 include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
544 $type = $lng->txt("obj_st");
546 break;
547
548 case "term":
549 $type = $lng->txt("term");
551 break;
552
553 default:
554 $type = $lng->txt("obj_" . $value[0]);
556 break;
557 }
558
559 return array("type" => $type, "name" => $name);
560 }
561
567 public function insert($a_tpl)
568 {
569 $html = $this->render();
570
571 $a_tpl->setCurrentBlock("prop_generic");
572 $a_tpl->setVariable("PROP_GENERIC", $html);
573 $a_tpl->parseCurrentBlock();
574 }
575
581 public function getIntLinkAttributes()
582 {
583 $val = explode("|", $_POST[$this->getPostVar()]);
584
585 $ret = false;
586 $type = "";
587 $target = "";
588 if (self::isInternalLink($_POST[$this->getPostVar()])) {
589 $target_frame = $val[2];
591 if (isset($map[$val[0]])) {
592 $type = $map[$val[0]];
593 $target_type = $val[0];
594 if ($val[0] == "chap") {
595 $target_type = "st";
596 }
597 if ($val[0] == "term") {
598 $target_type = "git";
599 }
600 if ($val[0] == "page") {
601 $target_type = "pg";
602 }
603 $target = "il__" . $target_type . "_" . $val[1];
604 } elseif ($this->obj_definition->isRBACObject($val[0])) {
605 $type = "RepositoryItem";
606 $target = "il__obj_" . $val[1];
607 }
608 if ($type != "") {
609 $ret = array(
610 "Target" => $target,
611 "Type" => $type,
612 "TargetFrame" => $target_frame
613 );
614 }
615 }
616 return $ret;
617 }
618
625 public function setValueByIntLinkAttributes($a_type, $a_target, $a_target_frame = "")
626 {
627 $t = explode("_", $a_target);
628 $target_id = $t[3];
629 $type = "";
631 if ($a_type == "RepositoryItem") {
633 } elseif (isset($map[$a_type])) {
634 $type = $map[$a_type];
635 }
636 if ($type != "" && $target_id != "") {
637 $val = $type . "|" . $target_id;
638 if ($a_target_frame != "") {
639 $val .= "|" . $a_target_frame;
640 }
641 $this->setValue($val);
642 }
643 }
644}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a property in a property form.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getParent()
Get Parent GUI object.
static _lookGlossaryTerm($term_id)
get glossary term
This class represents a hidden form property in a property form.
Class ilInternalLinkGUI.
static getInitHTML($a_url)
Get initialisation HTML to use interna link editing.
static _lookupTitle($a_obj_id)
Lookup title.
This class represents a external and/or internal link in a property form.
checkInput()
Check input, strip slashes etc.
getFilterWhiteList()
Get filter white list.
getAllowedLinkTypes()
Get allowed link types (LIST, BOTH, INT, EXT)
setInternalLinkFilterTypes(array $a_val)
Set internal link filter types.
setValueByIntLinkAttributes($a_type, $a_target, $a_target_frame="")
Set value by internal links attributes.
setValue($a_value)
Set Value.
static getTranslatedValue($a_value)
executeCommand()
Execute current command.
setFilterWhiteList($a_val)
Set filter white list.
__construct($a_title="", $a_postvar="")
Constructor.
insert($a_tpl)
Insert property html.
getContentOutsideFormTag()
Get content that has to reside outside of the parent form tag, e.g.
setInternalLinkDefault($a_type, $a_obj=0)
Set internal link default.
static getAttrTypeToType()
Get internal types to xml attribute types map (reverse)
static getTypeToAttrType()
Get internal types to xml attribute types map.
setValueByArray($a_values)
Set value by array.
static isInternalLink($a_value)
getIntLinkAttributes()
Get value as internal link attributes.
setAllowedLinkTypes($a_val)
Set allowed link types (LIST, BOTH, INT, EXT)
This class represents a non editable value in a property form.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a property in a property form.
This class represents an option in a radio group.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $DIC
Definition: goto.php:24
$target_id
Definition: goto.php:51
$target_type
Definition: goto.php:50
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6