ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 if ($has_int) {
375 $int = new ilRadioOption($lng->txt("form_link_internal"), "int");
376 $int->addSubItem($ne);
377 }
378
379 $mode = new ilRadioGroupInputGUI("", $this->getPostVar() . "_mode");
380 if (!$this->getRequired()) {
381 $no = new ilRadioOption($lng->txt("form_no_link"), "no");
382 $mode->addOption($no);
383 }
384 $mode->addOption($ext);
385 if ($has_int) {
386 $mode->addOption($int);
387 }
388 } else {
389 $mode = new ilHiddenInputGUI($this->getPostVar() . "_mode");
390 if ($has_int) {
391 $mode->setValue("int");
392 } else {
393 $mode->setValue("ext");
394 }
395 }
396
397 // value
398 $value = $this->getValue();
399 if ($value) {
400 // #15647
401 if ($has_int && self::isInternalLink($value)) {
402 $mode->setValue("int");
403
404 $value_trans = self::getTranslatedValue($value);
405
406 $value = explode("|", $value);
407 $hidden_type->setValue($value[0]);
408 $hidden_id->setValue($value[1]);
409 $hidden_target->setValue($value[2]);
410
411 $itpl->setVariable("VAL_OBJECT_TYPE", $value_trans["type"]);
412 $itpl->setVariable("VAL_OBJECT_NAME", $value_trans["name"]);
413 if ($value[2] != "") {
414 $itpl->setVariable("VAL_TARGET_FRAME", "(" . $value[2] . ")");
415 }
416 } elseif ($has_ext) {
417 $mode->setValue("ext");
418
419 $ti->setValue($value);
420 }
421 } elseif (!$this->getRequired()) {
422 $mode->setValue("no");
423 }
424
425 // #10185 - default for external urls
426 if ($has_ext && !$ti->getValue()) {
427 $ti->setValue("https://");
428 }
429
430 if ($has_int) {
431 $ne->setValue($itpl->get());
432 }
433
434 // to html
435 if ($has_radio) {
436 $html = $mode->render();
437 } else {
438 $html = $mode->getToolbarHTML();
439
440 if ($has_ext) {
441 $html .= $ti->getToolbarHTML();
442 } elseif ($has_int) {
443 $html .= $ne->render() .
444 '<div class="help-block">' . $ne->getInfo() . '</div>';
445 }
446 }
447
448 // js for internal link
449 if ($has_int) {
450 include_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
451 $html .= $hidden_type->getToolbarHTML() .
452 $hidden_id->getToolbarHTML() .
453 $hidden_target->getToolbarHTML();
454 }
455
456 return $html;
457 }
458
459 public function getContentOutsideFormTag()
460 {
461 if ($this->getAllowedLinkTypes() == self::INT ||
462 $this->getAllowedLinkTypes() == self::BOTH) {
463 // as the ajax-panel uses a form it has to be outside of the parent form!
465 }
466 }
467
468 public static function isInternalLink($a_value)
469 {
470 if (strpos($a_value, "|")) {
471 $parts = explode("|", $a_value);
472 if (sizeof($parts) == 2 || sizeof($parts) == 3) {
473 // numeric id
474 if (is_numeric($parts[1])) {
475 // simple type
476 if (preg_match("/^[a-zA-Z_]+$/", $parts[0], $matches)) {
477 return true;
478 }
479 }
480 }
481 }
482 return false;
483 }
484
485 public static function getTranslatedValue($a_value)
486 {
487 global $DIC;
488
489 $lng = $DIC->language();
490
491 $value = explode("|", $a_value);
492
493 switch ($value[0]) {
494 case "media":
495 $type = $lng->txt("obj_mob");
496 $name = ilObject::_lookupTitle($value[1]);
497 break;
498
499 case "page":
500 include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
501 $type = $lng->txt("obj_pg");
503 break;
504
505 case "chap":
506 include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
507 $type = $lng->txt("obj_st");
509 break;
510
511 case "term":
512 $type = $lng->txt("term");
514 break;
515
516 default:
517 $type = $lng->txt("obj_" . $value[0]);
519 break;
520 }
521
522 return array("type" => $type, "name" => $name);
523 }
524
530 public function insert($a_tpl)
531 {
532 $html = $this->render();
533
534 $a_tpl->setCurrentBlock("prop_generic");
535 $a_tpl->setVariable("PROP_GENERIC", $html);
536 $a_tpl->parseCurrentBlock();
537 }
538
544 public function getIntLinkAttributes()
545 {
546 $val = explode("|", $_POST[$this->getPostVar()]);
547
548 $ret = false;
549 $type = "";
550 $target = "";
551 if (self::isInternalLink($_POST[$this->getPostVar()])) {
552 $target_frame = $val[2];
554 if (isset($map[$val[0]])) {
555 $type = $map[$val[0]];
556 $target_type = $val[0];
557 if ($val[0] == "chap") {
558 $target_type = "st";
559 }
560 if ($val[0] == "term") {
561 $target_type = "git";
562 }
563 if ($val[0] == "page") {
564 $target_type = "pg";
565 }
566 $target = "il__" . $target_type . "_" . $val[1];
567 } elseif ($this->obj_definition->isRBACObject($val[0])) {
568 $type = "RepositoryItem";
569 $target = "il__obj_" . $val[1];
570 }
571 if ($type != "") {
572 $ret = array(
573 "Target" => $target,
574 "Type" => $type,
575 "TargetFrame" => $target_frame
576 );
577 }
578 }
579 return $ret;
580 }
581
588 public function setValueByIntLinkAttributes($a_type, $a_target, $a_target_frame = "")
589 {
590 $t = explode("_", $a_target);
591 $target_id = $t[3];
592 $type = "";
594 if ($a_type == "RepositoryItem") {
596 } elseif (isset($map[$a_type])) {
597 $type = $map[$a_type];
598 }
599 if ($type != "" && $target_id != "") {
600 $val = $type . "|" . $target_id;
601 if ($a_target_frame != "") {
602 $val .= "|" . $a_target_frame;
603 }
604 $this->setValue($val);
605 }
606 }
607}
$_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
$target_id
Definition: goto.php:49
$target_type
Definition: goto.php:48
global $ilCtrl
Definition: ilias.php:18
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46