dolibarr 24.0.0-beta
urlfield.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2025 Open-Dsi <support@open-dsi.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24require_once DOL_DOCUMENT_ROOT . '/core/class/fields/commonfield.class.php';
25
26
30class UrlField extends CommonField
31{
35 public $emptyValues = array('');
36
37
50 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
51 {
52 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
53 $htmlName = $keyPrefix . $key . $keySuffix;
54
55 return self::$form->inputType('text', $htmlName, (string) $value, $htmlName, $moreCss, $moreAttrib);
56 }
57
70 public function printInputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
71 {
72 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
73 $moreAttrib = trim((string) $moreAttrib);
74 if (empty($moreAttrib)) $moreAttrib = ' ' . $moreAttrib;
75 $autoFocus = $fieldInfos->inputAutofocus ? ' autofocus' : '';
76 $htmlName = $keyPrefix . $key . $keySuffix;
77
78 return self::$form->inputType('text', $htmlName, (string) $value, $htmlName, $moreCss, $moreAttrib . $autoFocus);
79 }
80
93 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
94 {
95 return !$this->isEmptyValue($fieldInfos, $value) ? dol_print_url((string) $value, '_blank', 32, 1) : '';
96 }
97
107 public function getInputCss($fieldInfos, $moreCss = '', $defaultCss = '')
108 {
109 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss);
110 }
111
121 public function verifyFieldValue($fieldInfos, $key, $value)
122 {
123 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
124 if ($result && !$this->isEmptyValue($fieldInfos, $value)) {
125 if (!self::$validator->isUrl($value)) {
126 return false;
127 }
128
129 $result = true;
130 }
131
132 return $result;
133 }
134
145 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
146 {
147 return parent::verifyPostFieldValue($fieldInfos, $key, $keyPrefix, $keySuffix);
148 }
149
161 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
162 {
163 $htmlName = $keyPrefix . $key . $keySuffix;
164
165 if (GETPOSTISSET($htmlName)) {
166 $value = GETPOST($htmlName, 'alphanohtml');
167 } else {
168 $value = $defaultValue;
169 }
170
171 return $value;
172 }
173
185 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
186 {
187 $htmlName = $keyPrefix . $key . $keySuffix;
188
189 if (GETPOSTISSET($htmlName)) {
190 $value = GETPOST($htmlName, 'alpha');
191 } else {
192 $value = $defaultValue;
193 }
194
195 return $value;
196 }
197
207 public function sqlFilterSearchField($fieldInfos, $key, $value)
208 {
209 if (!$this->isEmptyValue($fieldInfos, $value)) {
210 $alias = $fieldInfos->sqlAlias ?? 't.';
211
212 return natural_search($alias . ($fieldInfos->nameInTable ?? $key), $value, 0);
213 }
214
215 return '';
216 }
217}
Class to common field.
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to url field.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.