1 <?php
2 3 4 5 6 7
8
9 defined('FOF_INCLUDED') or die;
10
11 JFormHelper::loadFieldClass('text');
12
13 14 15 16 17 18 19
20 class FOFFormFieldText extends JFormFieldText implements FOFFormField
21 {
22 protected $static;
23
24 protected $repeatable;
25
26
27 public $item;
28
29
30 public $rowid;
31
32 33 34 35 36 37 38 39 40
41 public function __get($name)
42 {
43 switch ($name)
44 {
45 case 'static':
46 if (empty($this->static))
47 {
48 $this->static = $this->getStatic();
49 }
50
51 return $this->static;
52 break;
53
54 case 'repeatable':
55 if (empty($this->repeatable))
56 {
57 $this->repeatable = $this->getRepeatable();
58 }
59
60 return $this->repeatable;
61 break;
62
63 default:
64 return parent::__get($name);
65 }
66 }
67
68 69 70 71 72 73 74 75
76 public function getStatic()
77 {
78 $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
79 $empty_replacement = '';
80
81 if ($this->element['empty_replacement'])
82 {
83 $empty_replacement = (string) $this->element['empty_replacement'];
84 }
85
86 if (!empty($empty_replacement) && empty($this->value))
87 {
88 $this->value = JText::_($empty_replacement);
89 }
90
91 return '<span id="' . $this->id . '" ' . $class . '>' .
92 htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') .
93 '</span>';
94 }
95
96 97 98 99 100 101 102 103
104 public function getRepeatable()
105 {
106
107 $class = $this->id;
108 $format_string = '';
109 $format_if_not_empty = false;
110 $parse_value = false;
111 $show_link = false;
112 $link_url = '';
113 $empty_replacement = '';
114
115
116 if ($this->element['class'])
117 {
118 $class = (string) $this->element['class'];
119 }
120
121 if ($this->element['format'])
122 {
123 $format_string = (string) $this->element['format'];
124 }
125
126 if ($this->element['show_link'] == 'true')
127 {
128 $show_link = true;
129 }
130
131 if ($this->element['format_if_not_empty'] == 'true')
132 {
133 $format_if_not_empty = true;
134 }
135
136 if ($this->element['parse_value'] == 'true')
137 {
138 $parse_value = true;
139 }
140
141 if ($this->element['url'])
142 {
143 $link_url = $this->element['url'];
144 }
145 else
146 {
147 $show_link = false;
148 }
149
150 if ($show_link && ($this->item instanceof FOFTable))
151 {
152 $link_url = $this->parseFieldTags($link_url);
153 }
154 else
155 {
156 $show_link = false;
157 }
158
159 if ($this->element['empty_replacement'])
160 {
161 $empty_replacement = (string) $this->element['empty_replacement'];
162 }
163
164
165 $value = $this->value;
166
167 if (!empty($empty_replacement) && empty($this->value))
168 {
169 $value = JText::_($empty_replacement);
170 }
171
172 if ($parse_value)
173 {
174 $value = $this->parseFieldTags($value);
175 }
176
177 if (!empty($format_string) && (!$format_if_not_empty || ($format_if_not_empty && !empty($this->value))))
178 {
179 $format_string = $this->parseFieldTags($format_string);
180 $value = sprintf($format_string, $value);
181 }
182 else
183 {
184 $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
185 }
186
187
188 $html = '<span class="' . $class . '">';
189
190 if ($show_link)
191 {
192 $html .= '<a href="' . $link_url . '">';
193 }
194
195 $html .= $value;
196
197 if ($show_link)
198 {
199 $html .= '</a>';
200 }
201
202 $html .= '</span>';
203
204 return $html;
205 }
206
207 208 209 210 211 212 213
214 protected function parseFieldTags($text)
215 {
216 $ret = $text;
217
218
219
220 $keyfield = $this->item->getKeyName();
221 $replace = $this->item->$keyfield;
222 $ret = str_replace('[ITEM:ID]', $replace, $ret);
223
224
225 $ret = str_replace('[ITEMID]', JFactory::getApplication()->input->getInt('Itemid', 0), $ret);
226
227
228 $fields = $this->item->getTableFields();
229
230 foreach ($fields as $fielddata)
231 {
232 $fieldname = $fielddata->Field;
233
234 if (empty($fieldname))
235 {
236 $fieldname = $fielddata->column_name;
237 }
238
239 $search = '[ITEM:' . strtoupper($fieldname) . ']';
240 $replace = $this->item->$fieldname;
241 $ret = str_replace($search, $replace, $ret);
242 }
243
244 return $ret;
245 }
246 }
247