ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDclTextRecordRepresentation.php
Go to the documentation of this file.
1<?php
2require_once('./Modules/DataCollection/classes/Fields/Base/class.ilDclBaseRecordRepresentation.php');
10 const LINK_MAX_LENGTH = 40;
11
19 public function getHTML($link = true) {
20 $value = $this->getRecordField()->getValue();
21
22 //Property URL
23 $field = $this->getField();
24 if ($field->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
25 if (is_array($value)) {
26 $link = $value['link'];
27 $link_value = $value['title'] ? $value['title'] : $this->shortenLink($link);
28 } else {
29 $link = $value;
30 $link_value = $this->shortenLink($value);
31 }
32
33 if (substr($link, 0, 3) === 'www') {
34 $link = 'http://' . $link;
35 }
36
37 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)) {
38 $link = "mailto:" . $link;
39 } elseif (!(preg_match('~(^(news|(ht|f)tp(s?)\://){1}\S+)~i', $link))) {
40 return $link;
41 }
42
43 $html = "<a rel='noopener' target='_blank' href='" . htmlspecialchars($link, ENT_QUOTES) . "'>" . htmlspecialchars($link_value, ENT_QUOTES) . "</a>";
44
45 } elseif ($field->hasProperty(ilDclBaseFieldModel::PROP_LINK_DETAIL_PAGE_TEXT) && $link && ilDclDetailedViewDefinition::isActive($_GET['tableview_id'])) {
46 $this->ctrl->clearParametersByClass("ilDclDetailedViewGUI");
47 $this->ctrl->setParameterByClass('ilDclDetailedViewGUI', 'record_id', $this->getRecordField()->getRecord()->getId());
48 $this->ctrl->setParameterByClass('ilDclDetailedViewGUI', 'tableview_id', $_GET['tableview_id']);
49 $html = '<a href="' . $this->ctrl->getLinkTargetByClass("ilDclDetailedViewGUI", 'renderRecord') . '">' . $value . '</a>';
50 } else {
51 $html = (is_array($value) && isset($value['link']))? $value['link'] : $value;
52 }
53 return $html;
54 }
55
64 protected function shortenLink($value) {
65 if (strlen($value) > self::LINK_MAX_LENGTH) {
66 if (substr($value, 0, 7) == "http://") {
67 $value = substr($value, 7);
68 }
69 if (substr($value, 0, 8) == "https://") {
70 $value = substr($value, 8);
71 }
72 if (substr($value, 0, 4) == "www.") {
73 $value = substr($value, 4);
74 }
75 }
76 $link = $value;
77
78 if (strlen($value) > self::LINK_MAX_LENGTH) {
79 $link = substr($value, 0, (self::LINK_MAX_LENGTH - 3) / 2);
80 $link .= "...";
81 $link .= substr($value, -(self::LINK_MAX_LENGTH - 3) / 2);
82 }
83
84 return $link;
85 }
86
90 public function fillFormInput($form) {
91 $input_field = $form->getItemByPostVar('field_'.$this->getField()->getId());
92 $raw_input = $this->getFormInput();
93
94 $value = is_array($raw_input) ? $raw_input['link'] : $raw_input;
95 $field_values = array();
96 if($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) {
97 $field_values["field_".$this->getRecordField()->getField()->getId()."_title"] = (isset($raw_input['title']))? $raw_input['title'] : '';
98 }
99
100 if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_TEXTAREA)) {
101 $breaks = array( "<br />" );
102 $value = str_ireplace($breaks, "", $value);
103 }
104
105 $field_values["field_".$this->getRecordField()->getField()->getId()] = $value;
106 $input_field->setValueByArray($field_values);
107 }
108}
$_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.
Class ilDclTextFieldRepresentation.
getHTML($link=true)
Outputs html of a certain field.
shortenLink($value)
This method shortens a link.
$html
Definition: example_001.php:87