text.php
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* @package Regular Labs Library
* @version 18.2.10140
*
* @author Peter van Westen <info@regularlabs.com>
* @link http://www.regularlabs.com
* @copyright Copyright © 2018 Regular Labs All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
defined('_JEXEC') or die;
require_once JPATH_LIBRARIES . '/joomla/form/fields/text.php';
if ( ! is_file(JPATH_LIBRARIES . '/regularlabs/autoload.php'))
{
return;
}
require_once JPATH_LIBRARIES . '/regularlabs/autoload.php';
use RegularLabs\Library\StringHelper as RL_String;
class JFormFieldRL_Text extends JFormFieldText
{
public $type = 'Text';
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$this->element = $element;
$element['label'] = $this->prepareText($element['label']);
$element['description'] = $this->prepareText($element['description']);
$element['hint'] = $this->prepareText($element['hint']);
$element['translateDescription'] = false;
return parent::setup($element, $value, $group);
}
private function prepareText($string = '')
{
$string = trim($string);
if ($string == '')
{
return '';
}
// variables
$var1 = JText::_($this->get('var1'));
$var2 = JText::_($this->get('var2'));
$var3 = JText::_($this->get('var3'));
$var4 = JText::_($this->get('var4'));
$var5 = JText::_($this->get('var5'));
$string = JText::sprintf(JText::_($string), $var1, $var2, $var3, $var4, $var5);
$string = trim(RL_String::html_entity_decoder($string));
$string = str_replace('"', '"', $string);
$string = str_replace('span style="font-family:monospace;"', 'span class="rl_code"', $string);
return $string;
}
private function get($val, $default = '')
{
if ( ! isset($this->params[$val]) || (string) $this->params[$val] == '')
{
return $default;
}
return (string) $this->params[$val];
}
}