1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package Com_Localise |
4
|
|
|
* @subpackage models |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. |
7
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
defined('_JEXEC') or die; |
11
|
|
|
|
12
|
|
|
jimport('joomla.form.formfield'); |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Form Field Key class. |
16
|
|
|
* |
17
|
|
|
* @package Extensions.Components |
18
|
|
|
* @subpackage Localise |
19
|
|
|
* |
20
|
|
|
* @since 1.0 |
21
|
|
|
*/ |
22
|
|
|
class JFormFieldKey extends JFormField |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* The field type. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $type = 'Key'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Method to get the field label. |
33
|
|
|
* |
34
|
|
|
* @return string The field label. |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Method to get the field label markup. |
39
|
|
|
* |
40
|
|
|
* @return string The field label markup. |
41
|
|
|
* |
42
|
|
|
* @since 1.6 |
43
|
|
|
*/ |
44
|
|
|
protected function getLabel() |
45
|
|
|
{ |
46
|
|
|
$istranslation = (int) $this->element['istranslation']; |
47
|
|
|
$status = (string) $this->element['status']; |
|
|
|
|
48
|
|
|
$istextchange = (int) $this->element['istextchange']; |
49
|
|
|
|
50
|
|
|
if ($istextchange == '1') |
51
|
|
|
{ |
52
|
|
|
$textchange_status = (int) $this->element['changestatus']; |
53
|
|
|
$textchange_source = (string) $this->element['sourcetext']; |
54
|
|
|
$textchange_target = (string) $this->element['targettext']; |
55
|
|
|
$textchange_visible_id = "textchange_visible_id_" . $this->element['name']; |
56
|
|
|
$textchange_hidded_id = "textchange_hidded_id_" . $this->element['name']; |
57
|
|
|
$textchange_source_id = "textchange_source_id_" . $this->element['name']; |
58
|
|
|
$textchange_target_id = "textchange_target_id_" . $this->element['name']; |
59
|
|
|
|
60
|
|
|
if ($textchange_status == '1') |
61
|
|
|
{ |
62
|
|
|
$textchange_checked = ' checked="checked" '; |
63
|
|
|
} |
64
|
|
|
else |
65
|
|
|
{ |
66
|
|
|
$textchange_checked = ''; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$textchanges_onclick = "javascript:document.id( |
70
|
|
|
'" . $textchange_hidded_id . "' |
71
|
|
|
) |
72
|
|
|
.set( |
73
|
|
|
'value', document.getElementById('" . $textchange_visible_id . "' ).checked |
74
|
|
|
);"; |
75
|
|
|
|
76
|
|
|
if ($istranslation == '1') |
77
|
|
|
{ |
78
|
|
|
$title = JText::_('COM_LOCALISE_REVISED'); |
79
|
|
|
} |
80
|
|
|
else |
81
|
|
|
{ |
82
|
|
|
$title = 'Grammar case'; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$textchanges_checkbox = ''; |
86
|
|
|
$textchanges_checkbox .= '<div><b>' . $title . '</b><input style="max-width:5%; min-width:5%;" id="'; |
87
|
|
|
$textchanges_checkbox .= $textchange_visible_id; |
88
|
|
|
$textchanges_checkbox .= '" type="checkbox" '; |
89
|
|
|
$textchanges_checkbox .= ' name="jform[vtext_changes][]" value="'; |
90
|
|
|
$textchanges_checkbox .= $this->element['name']; |
91
|
|
|
$textchanges_checkbox .= '" title="' . $title . '" onclick="'; |
92
|
|
|
$textchanges_checkbox .= $textchanges_onclick; |
93
|
|
|
$textchanges_checkbox .= '" '; |
94
|
|
|
$textchanges_checkbox .= $textchange_checked; |
95
|
|
|
$textchanges_checkbox .= '></input></div>'; |
96
|
|
|
$textchanges_checkbox .= '<input id="'; |
97
|
|
|
$textchanges_checkbox .= $textchange_hidded_id; |
98
|
|
|
$textchanges_checkbox .= '" type="hidden" name="jform[text_changes]['; |
99
|
|
|
$textchanges_checkbox .= $this->element['name']; |
100
|
|
|
$textchanges_checkbox .= ']" value="'; |
101
|
|
|
$textchanges_checkbox .= $textchange_status; |
102
|
|
|
$textchanges_checkbox .= '" ></input>'; |
103
|
|
|
$textchanges_checkbox .= '<input id="'; |
104
|
|
|
$textchanges_checkbox .= $textchange_source_id; |
105
|
|
|
$textchanges_checkbox .= '" type="hidden" name="jform[source_text_changes]['; |
106
|
|
|
$textchanges_checkbox .= $this->element['name']; |
107
|
|
|
$textchanges_checkbox .= ']" value="'; |
108
|
|
|
$textchanges_checkbox .= htmlspecialchars($textchange_source, ENT_COMPAT, 'UTF-8'); |
109
|
|
|
$textchanges_checkbox .= '" ></input>'; |
110
|
|
|
$textchanges_checkbox .= '<input id="'; |
111
|
|
|
$textchanges_checkbox .= $textchange_target_id; |
112
|
|
|
$textchanges_checkbox .= '" type="hidden" name="jform[target_text_changes]['; |
113
|
|
|
$textchanges_checkbox .= $this->element['name']; |
114
|
|
|
$textchanges_checkbox .= ']" value="'; |
115
|
|
|
$textchanges_checkbox .= htmlspecialchars($textchange_target, ENT_COMPAT, 'UTF-8'); |
116
|
|
|
$textchanges_checkbox .= '" ></input>'; |
117
|
|
|
|
118
|
|
|
$return = ''; |
119
|
|
|
|
120
|
|
|
$return .= '<div><label id="'; |
121
|
|
|
$return .= $this->id; |
122
|
|
|
$return .= '-lbl" for="'; |
123
|
|
|
$return .= $this->id; |
124
|
|
|
$return .= '">'; |
125
|
|
|
$return .= $this->element['label']; |
126
|
|
|
$return .= $textchanges_checkbox; |
127
|
|
|
$return .= '</label></div>'; |
128
|
|
|
|
129
|
|
|
return $return; |
130
|
|
|
} |
131
|
|
|
else |
132
|
|
|
{ |
133
|
|
|
return '<label id="' . $this->id . '-lbl" for="' . $this->id . '">' |
134
|
|
|
. $this->element['label'] |
135
|
|
|
. '</label>'; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Method to get the field input. |
141
|
|
|
* |
142
|
|
|
* @return string The field input. |
143
|
|
|
*/ |
144
|
|
|
protected function getInput() |
145
|
|
|
{ |
146
|
|
|
// Set the class for the label. |
147
|
|
|
$class = !empty($this->descText) ? 'key-label hasTooltip fltrt' : 'key-label fltrt'; |
148
|
|
|
$istranslation = (int) $this->element['istranslation']; |
149
|
|
|
$istextchange = (int) $this->element['istextchange']; |
150
|
|
|
$isextraindev = (int) $this->element['isextraindev']; |
151
|
|
|
$status = (string) $this->element['status']; |
152
|
|
|
|
153
|
|
|
$label_id = $this->id . '-lbl'; |
154
|
|
|
$label_for = $this->id; |
155
|
|
|
$textarea_name = $this->name; |
156
|
|
|
$textarea_id = $this->id; |
157
|
|
|
$id = $this->id; |
158
|
|
|
|
159
|
|
|
if ($istranslation == '1') |
160
|
|
|
{ |
161
|
|
|
// If a description is specified, use it to build a tooltip. |
162
|
|
|
if (!empty($this->descText)) |
163
|
|
|
{ |
164
|
|
|
$label = '<label id="' . $label_id . '-lbl" for="' . $label_for . '" class="' . $class . '" title="' |
165
|
|
|
. htmlspecialchars(htmlspecialchars('::' . str_replace("\n", "\\n", $this->descText), ENT_QUOTES, 'UTF-8')) . '">'; |
166
|
|
|
} |
167
|
|
|
else |
168
|
|
|
{ |
169
|
|
|
$label = '<label id="' . $label_id . '-lbl" for="' . $label_for . '" class="' . $class . '">'; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
JText::script('COM_LOCALISE_LABEL_TRANSLATION_GOOGLE_ERROR'); |
173
|
|
|
|
174
|
|
|
$label .= $this->element['label'] . '<br />' . (string) $this->element['description']; |
175
|
|
|
$label .= '</label>'; |
176
|
|
|
|
177
|
|
|
$onclick = ''; |
|
|
|
|
178
|
|
|
$button = ''; |
|
|
|
|
179
|
|
|
|
180
|
|
|
$onclick2 = ''; |
|
|
|
|
181
|
|
|
$button2 = ''; |
|
|
|
|
182
|
|
|
|
183
|
|
|
if ($status == 'extra') |
184
|
|
|
{ |
185
|
|
|
$onclick = ''; |
|
|
|
|
186
|
|
|
$button = '<span style="width:5%;">' |
187
|
|
|
. JHtml::_('image', 'com_localise/icon-16-arrow-gray.png', '', array('class' => 'pointer'), true) . '</span>'; |
188
|
|
|
|
189
|
|
|
$onclick2 = ''; |
|
|
|
|
190
|
|
|
$button2 = '<span style="width:5%;">' |
191
|
|
|
. JHtml::_('image', 'com_localise/icon-16-bing-gray.png', '', array('class' => 'pointer'), true) . '</span>'; |
192
|
|
|
$input = ''; |
193
|
|
|
$input .= '<textarea name="' . $textarea_name; |
194
|
|
|
$input .= '" id="' . $textarea_id . '" class="width-45 ' . $status . ' ">'; |
195
|
|
|
$input .= htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '</textarea>'; |
196
|
|
|
} |
197
|
|
|
else |
198
|
|
|
{ |
199
|
|
|
$token = JSession::getFormToken(); |
200
|
|
|
|
201
|
|
|
$onclick = ""; |
202
|
|
|
$onclick .= "javascript:document.id('" . $id . "').set('value','"; |
203
|
|
|
$onclick .= addslashes(htmlspecialchars($this->element['description'], ENT_COMPAT, 'UTF-8')); |
204
|
|
|
$onclick .= "');"; |
205
|
|
|
$onclick .= "document.id('" . $id . "').set('class','width-45 untranslated');"; |
206
|
|
|
|
207
|
|
|
$onclick2 = "javascript:AzureTranslator(this, [], 0, '$token');"; |
208
|
|
|
|
209
|
|
|
$button = ''; |
210
|
|
|
$button .= '<i class="icon-reset hasTooltip return pointer" title="'; |
211
|
|
|
$button .= JText::_('COM_LOCALISE_TOOLTIP_TRANSLATION_INSERT'); |
212
|
|
|
$button .= '" onclick="' . $onclick . '"></i>'; |
213
|
|
|
|
214
|
|
|
$button2 = ''; |
215
|
|
|
$button2 .= '<input type="hidden" id="' . $id . 'text" value=\''; |
216
|
|
|
$button2 .= addslashes(htmlspecialchars($this->element['description'], ENT_COMPAT, 'UTF-8')) . '\' />'; |
217
|
|
|
$button2 .= '<i class="icon-translate-bing hasTooltip translate pointer" title="'; |
218
|
|
|
$button2 .= JText::_('COM_LOCALISE_TOOLTIP_TRANSLATION_AZURE'); |
219
|
|
|
$button2 .= '" onclick="' . $onclick2 . '" rel="' . $id . '"></i>'; |
220
|
|
|
|
221
|
|
|
$onkeyup = "javascript:"; |
222
|
|
|
|
223
|
|
|
if ($istextchange == 1) |
224
|
|
|
{ |
225
|
|
|
$onkeyup .= "if (this.get('value')=='') |
226
|
|
|
{ |
227
|
|
|
this.set('class','width-45 untranslated'); |
228
|
|
|
} |
229
|
|
|
else if (this.get('value')=='" |
230
|
|
|
. addslashes(htmlspecialchars($this->element['description'], ENT_COMPAT, 'UTF-8')) |
231
|
|
|
. "') |
232
|
|
|
{ |
233
|
|
|
this.set('class','width-45 untranslated'); |
234
|
|
|
} |
235
|
|
|
else if (this.get('value')=='" |
236
|
|
|
. addslashes(htmlspecialchars($this->element['frozen_task'], ENT_COMPAT, 'UTF-8')) |
237
|
|
|
. "') |
238
|
|
|
{ |
239
|
|
|
this.set('class','width-45 untranslated'); |
240
|
|
|
} |
241
|
|
|
else |
242
|
|
|
{ |
243
|
|
|
this.set('class','width-45 translated'); |
244
|
|
|
}"; |
245
|
|
|
} |
246
|
|
|
else |
247
|
|
|
{ |
248
|
|
|
$onkeyup .= "if (this.get('value')=='') |
249
|
|
|
{ |
250
|
|
|
this.set('class','width-45 untranslated'); |
251
|
|
|
} |
252
|
|
|
else if (this.get('value')=='" |
253
|
|
|
. addslashes(htmlspecialchars($this->element['description'], ENT_COMPAT, 'UTF-8')) |
254
|
|
|
. "') |
255
|
|
|
{ |
256
|
|
|
this.set('class','width-45 untranslated'); |
257
|
|
|
} |
258
|
|
|
else |
259
|
|
|
{ |
260
|
|
|
this.set('class','width-45 translated'); |
261
|
|
|
}"; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
$onfocus = "javascript:this.select();"; |
265
|
|
|
|
266
|
|
|
$input = ''; |
267
|
|
|
$input .= '<textarea name="' . $textarea_name . '" id="' . $textarea_id . '" onfocus="' . $onfocus; |
268
|
|
|
$input .= '" class="width-45 ' . $status . '" onkeyup="'; |
269
|
|
|
$input .= $onkeyup . '">' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '</textarea>'; |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
else |
273
|
|
|
{ |
274
|
|
|
// Set the class for the label. |
275
|
|
|
$class = !empty($this->descText) ? 'key-label hasTooltip fltrt' : 'key-label fltrt'; |
276
|
|
|
|
277
|
|
|
// If a description is specified, use it to build a tooltip. |
278
|
|
|
if (!empty($this->descText)) |
279
|
|
|
{ |
280
|
|
|
$label = '<label id="' . $this->id . '-lbl" for="' . $this->id . '" class="' . $class . '" title="' |
281
|
|
|
. htmlspecialchars(htmlspecialchars('::' . str_replace("\n", "\\n", $this->descText), ENT_QUOTES, 'UTF-8')) . '">'; |
282
|
|
|
} |
283
|
|
|
else |
284
|
|
|
{ |
285
|
|
|
$label = '<label id="' . $this->id . '-lbl" for="' . $this->id . '" class="' . $class . '">'; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
JText::script('COM_LOCALISE_LABEL_TRANSLATION_GOOGLE_ERROR'); |
289
|
|
|
$label .= $this->element['label'] . '<br />' . $this->element['description']; |
290
|
|
|
$label .= '</label>'; |
291
|
|
|
|
292
|
|
|
// Adjusting the stuff when all them are reference keys. |
293
|
|
|
$readonly = ''; |
294
|
|
|
$textvalue = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'); |
295
|
|
|
|
296
|
|
|
if ($istextchange == 1 || $isextraindev == 1) |
297
|
|
|
{ |
298
|
|
|
// There is no translation task in develop for the reference files in develop. |
299
|
|
|
$readonly = ' readonly="readonly" '; |
300
|
|
|
$textvalue = htmlspecialchars($this->element['description'], ENT_COMPAT, 'UTF-8'); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
$status = (string) $this->element['status']; |
304
|
|
|
|
305
|
|
|
$onclick = "javascript:document.id( |
306
|
|
|
'" . $this->id . "' |
307
|
|
|
) |
308
|
|
|
.set( |
309
|
|
|
'value','" . addslashes(htmlspecialchars($this->element['description'], ENT_COMPAT, 'UTF-8')) . "' |
310
|
|
|
); |
311
|
|
|
if (document.id('" . $this->id . "').get('value')=='') {document.id('" . $this->id . "').set('class','width-45 untranslated');} |
312
|
|
|
else {document.id('" . $this->id . "').set('class','width-45 " . $status . "');}"; |
313
|
|
|
$button = '<i class="icon-reset hasTooltip return pointer" |
314
|
|
|
title="' . JText::_('COM_LOCALISE_TOOLTIP_TRANSLATION_INSERT') . '" |
315
|
|
|
onclick="' . $onclick . '"></i>'; |
316
|
|
|
|
317
|
|
|
// No sense translate the reference keys by the same language. |
318
|
|
|
$onclick2 = ''; |
|
|
|
|
319
|
|
|
$button2 = '<span style="width:5%;">' |
320
|
|
|
. JHtml::_('image', 'com_localise/icon-16-bing-gray.png', '', array('class' => 'pointer'), true) . '</span>'; |
321
|
|
|
|
322
|
|
|
if ($istextchange == 1 || $isextraindev == 1) |
323
|
|
|
{ |
324
|
|
|
// Is read only, so no changes. |
325
|
|
|
$onkeyup = ""; |
326
|
|
|
} |
327
|
|
|
else |
328
|
|
|
{ |
329
|
|
|
$onkeyup = "javascript:"; |
330
|
|
|
$onkeyup .= "if (this.get('value')=='') {this.set('class','width-45 untranslated');} |
331
|
|
|
else {if (this.get('value')=='" . addslashes(htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8')) |
332
|
|
|
. "') this.set('class','width-45 " . $status . "'); |
333
|
|
|
" . "else this.set('class','width-45 translated');}"; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
$input = ''; |
337
|
|
|
$input .= '<textarea name="' . $this->name . '" id="'; |
338
|
|
|
$input .= $this->id . '"' . $readonly . ' onfocus="this.select()" class="width-45 '; |
339
|
|
|
$input .= $status; |
340
|
|
|
$input .= '" onkeyup="' . $onkeyup . '">' . $textvalue; |
341
|
|
|
$input .= '</textarea>'; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
return $button . $button2 . $input; |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.