radiocache.php
3.81 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('_JEXEC') or die;
/**
* Form Field class for the Joomla Platform.
* Provides radio button inputs
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/command.radio.html#command.radio
* @since 11.1
*/
class JFormFieldRadioCache extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'RadioCache';
/**
* Method to get the radio button field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
// Initialize variables.
$html = array();
// Initialize some field attributes.
$class = $this->element['class'] ? ' class="radio btn-group ' . (string) $this->element['class'] . '"' : ' class="radio btn-group pull-left"';
$translationCacheType = $this->element['cachetype'] ? (string)$this->element['cachetype'] : '';
// Start the radio field output.
$html[] = '<fieldset id="' . $this->id . '"' . $class . '>';
// Get the field options.
$options = $this->getOptions();
// Build the radio field output.
foreach ($options as $i => $option)
{
// Initialize some option attributes.
$checked = ((string) $option->value == (string) $this->value) ? ' checked="checked"' : '';
$class = !empty($option->class) ? ' class="' . $option->class . '"' : '';
$disabled = !empty($option->disable) ? ' disabled="disabled"' : '';
// Initialize some JavaScript option attributes.
$onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : '';
$html[] = '<input type="radio" id="' . $this->id . $i . '" name="' . $this->name . '"' . ' value="'
. htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . '/>';
$html[] = '<label for="' . $this->id . $i . '"' . $class . '>'
. JText::alt($option->text, preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)) . '</label>';
}
// End the radio field output.
$html[] = '</fieldset>';
if($this->value) {
$html[] = '<span data-content="' . JText::sprintf('COM_JMAP_JOOMLA_' . $translationCacheType . 'CACHE_ENABLED_DESC') . '" class="label label-success hasPopover">' .
'<span class="glyphicon glyphicon-ok-sign"></span>' . JText::sprintf('COM_JMAP_JOOMLA_' . $translationCacheType . 'CACHE_ENABLED') . '</span>';
} else {
$html[] = '<span data-content="' . JText::sprintf('COM_JMAP_JOOMLA_' . $translationCacheType . 'CACHE_DISABLED_DESC') . '" class="label label-danger hasPopover">' .
'<span class="glyphicon glyphicon-warning-sign"></span>' . JText::sprintf('COM_JMAP_JOOMLA_' . $translationCacheType . 'CACHE_DISABLED') . '</span>';
}
return implode($html);
}
/**
* Method to get the field options for radio buttons.
*
* @return array The field option objects.
*
* @since 11.1
*/
protected function getOptions()
{
// Initialize variables.
$options = array();
foreach ($this->element->children() as $option)
{
// Only add <option /> elements.
if ($option->getName() != 'option')
{
continue;
}
// Create a new option object based on the <option /> element.
$tmp = JHtml::_(
'select.option', (string) $option['value'], trim((string) $option), 'value', 'text',
((string) $option['disabled'] == 'true')
);
// Set some option attributes.
$tmp->class = (string) $option['class'];
// Set some JavaScript option attributes.
$tmp->onclick = (string) $option['onclick'];
// Add the option object to the result set.
$options[] = $tmp;
}
reset($options);
return $options;
}
}