ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 BOTH = "both";
20 const INT = "int";
21 const EXT = "ext";
23 protected $int_link_default_type = "RepositoryItem";
24 protected $int_link_default_obj = 0;
25 protected $int_link_filter_types = array("RepositoryItem");
26 protected $filter_white_list = true;
27
29
30 protected static $iltypemap = array(
31 "page" => "PageObject",
32 "chap" => "StructureObject",
33 "term" => "GlossaryItem",
34 "wpage" => "WikiPage"
35 );
36
40 protected $obj_definition;
41
48 public function __construct($a_title = "", $a_postvar = "")
49 {
50 global $DIC;
51
52 $this->ctrl = $DIC->ctrl();
53 $this->lng = $DIC->language();
54
55 parent::__construct($a_title, $a_postvar);
56 $this->setType("link");
57
58 $this->obj_definition = $DIC["objDefinition"];
59 }
60
66 public function setAllowedLinkTypes($a_val)
67 {
68 $this->allowed_link_types = $a_val;
69 }
70
76 public function getAllowedLinkTypes()
77 {
79 }
80
87 public function setInternalLinkDefault($a_type, $a_obj = 0)
88 {
89 $this->int_link_default_type = $a_type;
90 $this->int_link_default_obj = $a_obj;
91 }
92
98 public function setInternalLinkFilterTypes(array $a_val)
99 {
100 $this->int_link_filter_types = $a_val;
101 }
102
108 public static function getTypeToAttrType()
109 {
110 return self::$iltypemap;
111 }
112
118 public static function getAttrTypeToType()
119 {
120 return array_flip(self::$iltypemap);
121 }
122
128 public function setFilterWhiteList($a_val)
129 {
130 $this->filter_white_list = $a_val;
131 }
132
138 public function getFilterWhiteList()
139 {
141 }
142
146 public function setExternalLinkMaxLength($a_max)
147 {
148 $this->external_link_max_length = $a_max;
149 }
150
154 public function getExternalLinkMaxLength()
155 {
157 }
158
162 public function executeCommand()
163 {
166
167 $next_class = $ilCtrl->getNextClass($this);
168 $cmd = $ilCtrl->getCmd();
169
170 switch ($next_class) {
171 case "ilinternallinkgui":
172 $lng->loadLanguageModule("content");
173 require_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
174 $link_gui = new ilInternalLinkGUI(
175 $this->int_link_default_type,
176 $this->int_link_default_obj
177 );
178 foreach ($this->int_link_filter_types as $t) {
179 $link_gui->filterLinkType($t);
180 }
181 $link_gui->setFilterWhiteList($this->getFilterWhiteList());
182 $link_gui->setMode("asynch");
183
184 $ret = $ilCtrl->forwardCommand($link_gui);
185 break;
186
187 default:
188 var_dump($cmd);
189 //exit();
190 }
191
192 return $ret;
193 }
194
200 public function setValue($a_value)
201 {
202 $this->value = $a_value;
203 }
204
210 public function getValue()
211 {
212 return $this->value;
213 }
214
220 public function setValueByArray($a_values)
221 {
222 switch ($a_values[$this->getPostVar() . "_mode"]) {
223 case "int":
224 if ($a_values[$this->getPostVar() . "_ajax_type"] &&
225 $a_values[$this->getPostVar() . "_ajax_id"]) {
226 $val = $a_values[$this->getPostVar() . "_ajax_type"] . "|" .
227 $a_values[$this->getPostVar() . "_ajax_id"];
228 if ($a_values[$this->getPostVar() . "_ajax_target"] != "") {
229 $val .= "|" . $a_values[$this->getPostVar() . "_ajax_target"];
230 }
231 $this->setValue($val);
232 }
233 break;
234
235 case "no":
236 break;
237
238 default:
239 if ($a_values[$this->getPostVar()]) {
240 $this->setValue($a_values[$this->getPostVar()]);
241 }
242 break;
243 }
244 }
245
251 public function checkInput()
252 {
254
255 // debugging
256 // return false;
257
258 if ($this->getRequired()) {
259 switch ($_POST[$this->getPostVar() . "_mode"]) {
260 case "ext":
261 if (!$_POST[$this->getPostVar()]) {
262 $this->setAlert($lng->txt("msg_input_is_required"));
263 return false;
264 }
265 break;
266
267 case "int":
268 if (!$_POST[$this->getPostVar() . "_ajax_type"] ||
269 !$_POST[$this->getPostVar() . "_ajax_id"]) {
270 $this->setAlert($lng->txt("msg_input_is_required"));
271 return false;
272 }
273 break;
274
275 case "no":
276 default:
277 $this->setAlert($lng->txt("msg_input_is_required"));
278 return false;
279 }
280 }
281
282 if ($_POST[$this->getPostVar() . "_mode"] == "int") {
283 $_POST[$this->getPostVar() . "_ajax_type"] = ilUtil::stripSlashes($_POST[$this->getPostVar() . "_ajax_type"]);
284 $_POST[$this->getPostVar() . "_ajax_id"] = ilUtil::stripSlashes($_POST[$this->getPostVar() . "_ajax_id"]);
285 $_POST[$this->getPostVar() . "_ajax_target"] = ilUtil::stripSlashes($_POST[$this->getPostVar() . "_ajax_target"]);
286
287 // overwriting post-data so getInput() will work
288 $val = $_POST[$this->getPostVar() . "_ajax_type"] . "|" .
289 $_POST[$this->getPostVar() . "_ajax_id"];
290 if ($_POST[$this->getPostVar() . "_ajax_target"] != "") {
291 $val .= "|" . $_POST[$this->getPostVar() . "_ajax_target"];
292 }
293
294 $_POST[$this->getPostVar()] = $val;
295 } elseif ($_POST[$this->getPostVar() . "_mode"] == "no") {
296 $_POST[$this->getPostVar()] = "";
297 } else {
299 }
300
301 return true;
302 }
303
307 public function render()
308 {
311
312 // parse settings
313 $has_int = $has_ext = $has_radio = false;
314 switch ($this->getAllowedLinkTypes()) {
315 case self::EXT:
316 $has_ext = true;
317 break;
318
319 case self::INT:
320 $has_int = true;
321 break;
322
323 case self::BOTH:
324 $has_int = true;
325 $has_ext = true;
326 $has_radio = true;
327 break;
328 }
329 if (!$this->getRequired()) {
330 // see #0021274
331// $has_radio = true;
332 }
333
334 // external
335 if ($has_ext) {
336 $title = $has_radio ? $lng->txt("url") : "";
337
338 // external
339 $ti = new ilTextInputGUI($title, $this->getPostVar());
340 $ti->setMaxLength($this->getExternalLinkMaxLength());
341 }
342
343 // internal
344 if ($has_int) {
345 $ilCtrl->setParameterByClass("ilformpropertydispatchgui", "postvar", $this->getPostVar());
346 $link = array(get_class($this->getParent()), "ilformpropertydispatchgui", get_class($this), "ilinternallinkgui");
347 $link = $ilCtrl->getLinkTargetByClass($link, "", false, true, false);
348 $ilCtrl->setParameterByClass("ilformpropertydispatchgui", "postvar", $_REQUEST["postvar"]);
349
350 $no_disp_class = (strpos($this->getValue(), "|"))
351 ? ""
352 : " ilNoDisplay";
353
354 $itpl = new ilTemplate('tpl.prop_link.html', true, true, 'Services/Form');
355 $itpl->setVariable("VAL_ID", $this->getPostVar());
356 $itpl->setVariable("URL_EDIT", $link);
357 $itpl->setVariable("TXT_EDIT", $lng->txt("form_get_link"));
358 $itpl->setVariable("CSS_REMOVE", $no_disp_class);
359 $itpl->setVariable("TXT_REMOVE", $lng->txt("remove"));
360
361 $ne = new ilNonEditableValueGUI($lng->txt("object"), $this->getPostVar() . "_val", true);
362
363 // hidden field for selected value
364 $hidden_type = new ilHiddenInputGUI($this->getPostVar() . "_ajax_type");
365 $hidden_id = new ilHiddenInputGUI($this->getPostVar() . "_ajax_id");
366 $hidden_target = new ilHiddenInputGUI($this->getPostVar() . "_ajax_target");
367 }
368
369 // mode
370 if ($has_radio) {
371 $ext = new ilRadioOption($lng->txt("form_link_external"), "ext");
372 $ext->addSubItem($ti);
373
374 $int = new ilRadioOption($lng->txt("form_link_internal"), "int");
375 $int->addSubItem($ne);
376
377 $mode = new ilRadioGroupInputGUI("", $this->getPostVar() . "_mode");
378 if (!$this->getRequired()) {
379 $no = new ilRadioOption($lng->txt("form_no_link"), "no");
380 $mode->addOption($no);
381 }
382 $mode->addOption($ext);
383 $mode->addOption($int);
384 } else {
385 $mode = new ilHiddenInputGUI($this->getPostVar() . "_mode");
386 if ($has_int) {
387 $mode->setValue("int");
388 } else {
389 $mode->setValue("ext");
390 }
391 }
392
393 // value
394 $value = $this->getValue();
395 if ($value) {
396 // #15647
397 if ($has_int && self::isInternalLink($value)) {
398 $mode->setValue("int");
399
400 $value_trans = self::getTranslatedValue($value);
401
402 $value = explode("|", $value);
403 $hidden_type->setValue($value[0]);
404 $hidden_id->setValue($value[1]);
405 $hidden_target->setValue($value[2]);
406
407 $itpl->setVariable("VAL_OBJECT_TYPE", $value_trans["type"]);
408 $itpl->setVariable("VAL_OBJECT_NAME", $value_trans["name"]);
409 if ($value[2] != "") {
410 $itpl->setVariable("VAL_TARGET_FRAME", "(" . $value[2] . ")");
411 }
412 } elseif ($has_ext) {
413 $mode->setValue("ext");
414
415 $ti->setValue($value);
416 }
417 } elseif (!$this->getRequired()) {
418 $mode->setValue("no");
419 }
420
421 // #10185 - default for external urls
422 if ($has_ext && !$ti->getValue()) {
423 $ti->setValue("http://");
424 }
425
426 $ne->setValue($itpl->get());
427
428 // to html
429 if ($has_radio) {
430 $html = $mode->render();
431 } else {
432 $html = $mode->getToolbarHTML();
433
434 if ($has_ext) {
435 $html .= $ti->getToolbarHTML();
436 } else {
437 $html .= $ne->render() .
438 '<div class="help-block">' . $ne->getInfo() . '</div>';
439 }
440 }
441
442 // js for internal link
443 if ($has_int) {
444 include_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
445 $html .= $hidden_type->getToolbarHTML() .
446 $hidden_id->getToolbarHTML() .
447 $hidden_target->getToolbarHTML();
448 }
449
450 return $html;
451 }
452
453 public function getContentOutsideFormTag()
454 {
455 if ($this->getAllowedLinkTypes() == self::INT ||
456 $this->getAllowedLinkTypes() == self::BOTH) {
457 // as the ajax-panel uses a form it has to be outside of the parent form!
459 }
460 }
461
462 public static function isInternalLink($a_value)
463 {
464 if (strpos($a_value, "|")) {
465 $parts = explode("|", $a_value);
466 if (sizeof($parts) == 2 || sizeof($parts) == 3) {
467 // numeric id
468 if (is_numeric($parts[1])) {
469 // simple type
470 if (preg_match("/^[a-zA-Z_]+$/", $parts[0], $matches)) {
471 return true;
472 }
473 }
474 }
475 }
476 return false;
477 }
478
479 public static function getTranslatedValue($a_value)
480 {
481 global $DIC;
482
483 $lng = $DIC->language();
484
485 $value = explode("|", $a_value);
486
487 switch ($value[0]) {
488 case "media":
489 $type = $lng->txt("obj_mob");
490 $name = ilObject::_lookupTitle($value[1]);
491 break;
492
493 case "page":
494 include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
495 $type = $lng->txt("obj_pg");
497 break;
498
499 case "chap":
500 include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
501 $type = $lng->txt("obj_st");
503 break;
504
505 case "term":
506 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
507 $type = $lng->txt("term");
509 break;
510
511 default:
512 $type = $lng->txt("obj_" . $value[0]);
514 break;
515 }
516
517 return array("type" => $type, "name" => $name);
518 }
519
525 public function insert($a_tpl)
526 {
527 $html = $this->render();
528
529 $a_tpl->setCurrentBlock("prop_generic");
530 $a_tpl->setVariable("PROP_GENERIC", $html);
531 $a_tpl->parseCurrentBlock();
532 }
533
539 public function getIntLinkAttributes()
540 {
541 $val = explode("|", $_POST[$this->getPostVar()]);
542
543 $ret = false;
544 $type = "";
545 $target = "";
546 if (self::isInternalLink($_POST[$this->getPostVar()])) {
547 $target_frame = $val[2];
549 if (isset($map[$val[0]])) {
550 $type = $map[$val[0]];
551 $target_type = $val[0];
552 if ($val[0] == "chap") {
553 $target_type = "st";
554 }
555 if ($val[0] == "term") {
556 $target_type = "git";
557 }
558 if ($val[0] == "page") {
559 $target_type = "pg";
560 }
561 $target = "il__" . $target_type . "_" . $val[1];
562 } elseif ($this->obj_definition->isRBACObject($val[0])) {
563 $type = "RepositoryItem";
564 $target = "il__obj_" . $val[1];
565 }
566 if ($type != "") {
567 $ret = array(
568 "Target" => $target,
569 "Type" => $type,
570 "TargetFrame" => $target_frame
571 );
572 }
573 }
574 return $ret;
575 }
576
583 public function setValueByIntLinkAttributes($a_type, $a_target, $a_target_frame = "")
584 {
585 $t = explode("_", $a_target);
586 $target_id = $t[3];
587 $type = "";
589 if ($a_type == "RepositoryItem") {
591 } elseif (isset($map[$a_type])) {
592 $type = $map[$a_type];
593 }
594 if ($type != "" && $target_id != "") {
595 $val = $type . "|" . $target_id;
596 if ($a_target_frame != "") {
597 $val .= "|" . $a_target_frame;
598 }
599 $this->setValue($val);
600 }
601 }
602}
$_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 (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 (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
$html
Definition: example_001.php:87
$target_id
Definition: goto.php:49
$target_type
Definition: goto.php:48
global $ilCtrl
Definition: ilias.php:18
$target
Definition: test.php:19
$ret
Definition: parser.php:6
$int
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92