ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDclTextRecordRepresentation.php
Go to the documentation of this file.
1<?php
2
10{
11 const LINK_MAX_LENGTH = 40;
12
13
22 public function getHTML($link = true)
23 {
24 $value = $this->getRecordField()->getValue();
25
26 //Property URL
27 $field = $this->getField();
28 if ($field->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
29 if (is_array($value)) {
30 $link = $value['link'];
31 $link_value = $value['title'] ? $value['title'] : $this->shortenLink($link);
32 } else {
33 $link = $value;
34 $link_value = $this->shortenLink($value);
35 }
36
37 if (substr($link, 0, 3) === 'www') {
38 $link = 'http://' . $link;
39 }
40
41 if (preg_match("/^[a-z0-9!#$%&'*+=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i", $link)) {
42 $link = "mailto:" . $link;
43 } elseif (!(preg_match('~(^(news|(ht|f)tp(s?)\://){1}\S+)~i', $link))) {
44 return $link;
45 }
46
47 $html = "<a rel='noopener' target='_blank' href='" . htmlspecialchars($link, ENT_QUOTES) . "'>" . htmlspecialchars($link_value, ENT_QUOTES) . "</a>";
48 } elseif ($field->hasProperty(ilDclBaseFieldModel::PROP_LINK_DETAIL_PAGE_TEXT) && $link && ilDclDetailedViewDefinition::isActive($_GET['tableview_id'])) {
49 $this->ctrl->clearParametersByClass("ilDclDetailedViewGUI");
50 $this->ctrl->setParameterByClass('ilDclDetailedViewGUI', 'record_id', $this->getRecordField()->getRecord()->getId());
51 $this->ctrl->setParameterByClass('ilDclDetailedViewGUI', 'tableview_id', $_GET['tableview_id']);
52 $html = '<a href="' . $this->ctrl->getLinkTargetByClass("ilDclDetailedViewGUI", 'renderRecord') . '">' . $value . '</a>';
53 } else {
54 $html = (is_array($value) && isset($value['link'])) ? $value['link'] : $value;
55 }
56
57 return $html;
58 }
59
60
69 protected function shortenLink($value)
70 {
71 if (strlen($value) > self::LINK_MAX_LENGTH) {
72 if (substr($value, 0, 7) == "http://") {
73 $value = substr($value, 7);
74 }
75 if (substr($value, 0, 8) == "https://") {
76 $value = substr($value, 8);
77 }
78 if (substr($value, 0, 4) == "www.") {
79 $value = substr($value, 4);
80 }
81 }
82 $link = $value;
83
84 if (strlen($value) > self::LINK_MAX_LENGTH) {
85 $link = substr($value, 0, (self::LINK_MAX_LENGTH - 3) / 2);
86 $link .= "...";
87 $link .= substr($value, -(self::LINK_MAX_LENGTH - 3) / 2);
88 }
89
90 return $link;
91 }
92
93
97 public function fillFormInput($form)
98 {
99 $input_field = $form->getItemByPostVar('field_' . $this->getField()->getId());
100 $raw_input = $this->getFormInput();
101
102 $value = is_array($raw_input) ? $raw_input['link'] : $raw_input;
103 $field_values = [];
104 if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) {
105 $field_values["field_" . $this->getRecordField()->getField()->getId() . "_title"] = (isset($raw_input['title'])) ? $raw_input['title'] : '';
106 }
107
108 if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_TEXTAREA)) {
109 $breaks = ["<br />"];
110 $value = str_ireplace($breaks, "", $value);
111 }
112
113 $field_values["field_" . $this->getRecordField()->getField()->getId()] = $value;
114 $input_field->setValueByArray($field_values);
115 }
116}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Class ilDclBaseRecordRepresentation.
getFormInput()
Gets the value from from the record field.
getHTML($link=true)
Outputs html of a certain field.
shortenLink($value)
This method shortens a link.