1
|
|
|
<?php |
2
|
|
|
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
3
|
|
|
/********************************************************************************* |
4
|
|
|
* SugarCRM Community Edition is a customer relationship management program developed by |
5
|
|
|
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
6
|
|
|
|
7
|
|
|
* SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd. |
8
|
|
|
* Copyright (C) 2011 - 2014 Salesagility Ltd. |
9
|
|
|
* |
10
|
|
|
* This program is free software; you can redistribute it and/or modify it under |
11
|
|
|
* the terms of the GNU Affero General Public License version 3 as published by the |
12
|
|
|
* Free Software Foundation with the addition of the following permission added |
13
|
|
|
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK |
14
|
|
|
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY |
15
|
|
|
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
18
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
19
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
20
|
|
|
* details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License along with |
23
|
|
|
* this program; if not, see http://www.gnu.org/licenses or write to the Free |
24
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
25
|
|
|
* 02110-1301 USA. |
26
|
|
|
* |
27
|
|
|
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, |
28
|
|
|
* SW2-130, Cupertino, CA 95014, USA. or at email address [email protected]. |
29
|
|
|
* |
30
|
|
|
* The interactive user interfaces in modified source and object code versions |
31
|
|
|
* of this program must display Appropriate Legal Notices, as required under |
32
|
|
|
* Section 5 of the GNU Affero General Public License version 3. |
33
|
|
|
* |
34
|
|
|
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, |
35
|
|
|
* these Appropriate Legal Notices must retain the display of the "Powered by |
36
|
|
|
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not |
37
|
|
|
* reasonably feasible for technical reasons, the Appropriate Legal Notices must |
38
|
|
|
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". |
39
|
|
|
********************************************************************************/ |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
|
43
|
|
|
|
44
|
|
|
|
45
|
|
|
require_once('include/utils/array_utils.php'); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return bool |
49
|
|
|
* @desc Creates the include language directory under the custom directory. |
50
|
|
|
*/ |
51
|
|
|
function create_include_lang_dir() |
52
|
|
|
{ |
53
|
|
|
|
54
|
|
|
if(!is_dir("custom/include/language")) |
55
|
|
|
return sugar_mkdir("custom/include/language", null, true); |
56
|
|
|
|
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return bool |
62
|
|
|
* @param module string |
63
|
|
|
* @desc Creates the module's language directory under the custom directory. |
64
|
|
|
*/ |
65
|
|
|
function create_module_lang_dir($module) |
66
|
|
|
{ |
67
|
|
|
|
68
|
|
|
if(!is_dir("custom/modules/$module/language")) |
69
|
|
|
return sugar_mkdir("custom/modules/$module/language", null, true); |
70
|
|
|
|
71
|
|
|
return true; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string& |
|
|
|
|
76
|
|
|
* @param the_array array, language string, module string |
77
|
|
|
* @desc Returns the contents of the customized language pack. |
78
|
|
|
*/ |
79
|
|
|
function &create_field_lang_pak_contents($old_contents, $key, $value, $language, $module) |
80
|
|
|
{ |
81
|
|
|
if(!empty($old_contents)) |
82
|
|
|
{ |
83
|
|
|
|
84
|
|
|
$old_contents = preg_replace("'[^\[\n\r]+\[\'{$key}\'\][^\;]+;[\ \r\n]*'i", '', $old_contents); |
85
|
|
|
$contents = str_replace("\n?>","\n\$mod_strings['{$key}'] = '$value';\n?>", $old_contents); |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
else |
90
|
|
|
{ |
91
|
|
|
$contents = "<?php\n" |
92
|
|
|
. '// Creation date: ' . date('Y-m-d H:i:s') . "\n" |
93
|
|
|
. "// Module: $module\n" |
94
|
|
|
. "// Language: $language\n\n" |
95
|
|
|
. "\$mod_strings['$key'] = '$value';" |
96
|
|
|
. "\n?>"; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return $contents; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return string& |
|
|
|
|
104
|
|
|
* @param the_array array, language string |
105
|
|
|
* @desc Returns the contents of the customized language pack. |
106
|
|
|
*/ |
107
|
|
|
function &create_dropdown_lang_pak_contents(&$the_array, $language) |
108
|
|
|
{ |
109
|
|
|
$contents = "<?php\n" . |
110
|
|
|
'// ' . date('Y-m-d H:i:s') . "\n" . |
111
|
|
|
"// Language: $language\n\n" . |
112
|
|
|
'$app_list_strings = ' . |
113
|
|
|
var_export($the_array, true) . |
114
|
|
|
";\n?>"; |
115
|
|
|
|
116
|
|
|
return $contents; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return bool |
121
|
|
|
* @param module string, key string, value string |
122
|
|
|
* @desc Wrapper function that will create a field label for every language. |
123
|
|
|
*/ |
124
|
|
|
function create_field_label_all_lang($module, $key, $value, $overwrite = false) |
125
|
|
|
{ |
126
|
|
|
$languages = get_languages(); |
127
|
|
|
$return_value = false; |
128
|
|
|
|
129
|
|
|
foreach($languages as $lang_key => $lang_value) |
130
|
|
|
{ |
131
|
|
|
$return_value = create_field_label($module, $lang_key, $key, $value, $overwrite); |
132
|
|
|
if(!$return_value) |
133
|
|
|
{ |
134
|
|
|
break; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
return $return_value; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return bool |
143
|
|
|
* @param module string, language string, key string, value string |
144
|
|
|
* @desc Returns true if new field label can be created, false otherwise. |
145
|
|
|
* Probable reason for returning false: new_field_key already exists. |
146
|
|
|
*/ |
147
|
|
|
function create_field_label($module, $language, $key, $value, $overwrite=false) |
148
|
|
|
{ |
149
|
|
|
$return_value = false; |
150
|
|
|
$mod_strings = return_module_language($language, $module); |
151
|
|
|
|
152
|
|
|
if(isset($mod_strings[$key]) && !$overwrite) |
153
|
|
|
{ |
154
|
|
|
$GLOBALS['log']->info("Tried to create a key that already exists: $key"); |
155
|
|
|
} |
156
|
|
|
else |
157
|
|
|
{ |
158
|
|
|
$mod_strings = array_merge($mod_strings, array($key => $value)); |
159
|
|
|
$dirname = "custom/modules/$module/language"; |
160
|
|
|
$dir_exists = is_dir($dirname); |
161
|
|
|
|
162
|
|
|
if(!$dir_exists) |
163
|
|
|
{ |
164
|
|
|
|
165
|
|
|
$dir_exists = create_module_lang_dir($module); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
if($dir_exists) |
169
|
|
|
{ |
170
|
|
|
$filename = "$dirname/$language.lang.php"; |
171
|
|
|
if(is_file($filename) && filesize($filename) > 0){ |
172
|
|
|
$old_contents = file_get_contents($filename); |
173
|
|
|
}else{ |
174
|
|
|
$old_contents = ''; |
175
|
|
|
} |
176
|
|
|
$handle = sugar_fopen($filename, 'wb'); |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
if($handle) |
180
|
|
|
{ |
181
|
|
|
$contents =create_field_lang_pak_contents($old_contents, $key, |
182
|
|
|
$value, $language, $module); |
183
|
|
|
|
184
|
|
|
if(fwrite($handle, $contents)) |
185
|
|
|
{ |
186
|
|
|
$return_value = true; |
187
|
|
|
$GLOBALS['log']->info("Successful write to: $filename"); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
fclose($handle); |
191
|
|
|
} |
192
|
|
|
else |
193
|
|
|
{ |
194
|
|
|
$GLOBALS['log']->info("Unable to write edited language pak to file: $filename"); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
else |
198
|
|
|
{ |
199
|
|
|
$GLOBALS['log']->info("Unable to create dir: $dirname"); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
return $return_value; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return bool |
208
|
|
|
* @param dropdown_name string |
209
|
|
|
* @desc Wrapper function that creates a dropdown type for all languages. |
210
|
|
|
*/ |
211
|
|
|
function create_dropdown_type_all_lang($dropdown_name) |
212
|
|
|
{ |
213
|
|
|
$languages = get_languages(); |
214
|
|
|
$return_value = false; |
215
|
|
|
|
216
|
|
|
foreach($languages as $lang_key => $lang_value) |
217
|
|
|
{ |
218
|
|
|
$return_value = create_dropdown_type($dropdown_name, $lang_key); |
219
|
|
|
if(!$return_value) |
220
|
|
|
{ |
221
|
|
|
break; |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
return $return_value; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @return bool |
230
|
|
|
* @param app_list_strings array |
231
|
|
|
* @desc Saves the app_list_strings to file in the 'custom' dir. |
232
|
|
|
*/ |
233
|
|
|
function save_custom_app_list_strings_contents(&$contents, $language, $custom_dir_name = '') |
234
|
|
|
{ |
235
|
|
|
$return_value = false; |
236
|
|
|
$dirname = 'custom/include/language'; |
237
|
|
|
if(!empty($custom_dir_name)) |
238
|
|
|
$dirname = $custom_dir_name; |
239
|
|
|
|
240
|
|
|
$dir_exists = is_dir($dirname); |
241
|
|
|
|
242
|
|
|
if(!$dir_exists) |
243
|
|
|
{ |
244
|
|
|
$dir_exists = create_include_lang_dir($dirname); |
|
|
|
|
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
if($dir_exists) |
248
|
|
|
{ |
249
|
|
|
$filename = "$dirname/$language.lang.php"; |
250
|
|
|
$handle = @sugar_fopen($filename, 'wt'); |
251
|
|
|
|
252
|
|
|
if($handle) |
253
|
|
|
{ |
254
|
|
|
if(fwrite($handle, $contents)) |
255
|
|
|
{ |
256
|
|
|
$return_value = true; |
257
|
|
|
$GLOBALS['log']->info("Successful write to: $filename"); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
fclose($handle); |
261
|
|
|
} |
262
|
|
|
else |
263
|
|
|
{ |
264
|
|
|
$GLOBALS['log']->info("Unable to write edited language pak to file: $filename"); |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
else |
268
|
|
|
{ |
269
|
|
|
$GLOBALS['log']->info("Unable to create dir: $dirname"); |
270
|
|
|
} |
271
|
|
|
if($return_value){ |
272
|
|
|
$cache_key = 'app_list_strings.'.$language; |
273
|
|
|
sugar_cache_clear($cache_key); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
return $return_value; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @return bool |
281
|
|
|
* @param app_list_strings array |
282
|
|
|
* @desc Saves the app_list_strings to file in the 'custom' dir. |
283
|
|
|
*/ |
284
|
|
|
function save_custom_app_list_strings(&$app_list_strings, $language) |
285
|
|
|
{ |
286
|
|
|
$return_value = false; |
287
|
|
|
$dirname = 'custom/include/language'; |
288
|
|
|
|
289
|
|
|
$dir_exists = is_dir($dirname); |
290
|
|
|
|
291
|
|
|
if(!$dir_exists) |
292
|
|
|
{ |
293
|
|
|
$dir_exists = create_include_lang_dir($dirname); |
|
|
|
|
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
if($dir_exists) |
297
|
|
|
{ |
298
|
|
|
$filename = "$dirname/$language.lang.php"; |
299
|
|
|
$handle = @sugar_fopen($filename, 'wt'); |
300
|
|
|
|
301
|
|
|
if($handle) |
302
|
|
|
{ |
303
|
|
|
$contents =create_dropdown_lang_pak_contents($app_list_strings, |
304
|
|
|
$language); |
305
|
|
|
|
306
|
|
|
if(fwrite($handle, $contents)) |
307
|
|
|
{ |
308
|
|
|
$return_value = true; |
309
|
|
|
$GLOBALS['log']->info("Successful write to: $filename"); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
fclose($handle); |
313
|
|
|
} |
314
|
|
|
else |
315
|
|
|
{ |
316
|
|
|
$GLOBALS['log']->info("Unable to write edited language pak to file: $filename"); |
317
|
|
|
} |
318
|
|
|
} |
319
|
|
|
else |
320
|
|
|
{ |
321
|
|
|
$GLOBALS['log']->info("Unable to create dir: $dirname"); |
322
|
|
|
} |
323
|
|
|
if($return_value){ |
324
|
|
|
$cache_key = 'app_list_strings.'.$language; |
325
|
|
|
sugar_cache_clear($cache_key); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
return $return_value; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
function return_custom_app_list_strings_file_contents($language, $custom_filename = '') |
332
|
|
|
{ |
333
|
|
|
$contents = ''; |
334
|
|
|
|
335
|
|
|
$filename = "custom/include/language/$language.lang.php"; |
336
|
|
|
if(!empty($custom_filename)) |
337
|
|
|
$filename = $custom_filename; |
338
|
|
|
|
339
|
|
|
if (is_file($filename)) |
340
|
|
|
{ |
341
|
|
|
$contents = file_get_contents($filename); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
return $contents; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @return bool |
349
|
|
|
* @param dropdown_name string, language string |
350
|
|
|
* @desc Creates a new dropdown type. |
351
|
|
|
*/ |
352
|
|
|
function create_dropdown_type($dropdown_name, $language) |
353
|
|
|
{ |
354
|
|
|
$return_value = false; |
355
|
|
|
$app_list_strings = return_app_list_strings_language($language); |
356
|
|
|
|
357
|
|
|
if(isset($app_list_strings[$dropdown_name])) |
358
|
|
|
{ |
359
|
|
|
$GLOBALS['log']->info("Tried to create a dropdown list key that already exists: $dropdown_name"); |
360
|
|
|
} |
361
|
|
|
else |
362
|
|
|
{ |
363
|
|
|
// get the contents of the custom app list strings file |
364
|
|
|
$contents = return_custom_app_list_strings_file_contents($language); |
365
|
|
|
|
366
|
|
|
// add the new dropdown_name to it |
367
|
|
|
if($contents == '') |
368
|
|
|
{ |
369
|
|
|
$new_contents = "<?php\n\$app_list_strings['$dropdown_name'] = array(''=>'');\n?>"; |
370
|
|
|
} |
371
|
|
|
else |
372
|
|
|
{ |
373
|
|
|
$new_contents = str_replace('?>', "\$app_list_strings['$dropdown_name'] = array(''=>'');\n?>", $contents); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
// save the new contents to file |
377
|
|
|
$return_value = save_custom_app_list_strings_contents($new_contents, $language); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
return $return_value; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* @return string& |
|
|
|
|
385
|
|
|
* @param identifier string, pairs array, first_entry string, selected_key string |
386
|
|
|
* @desc Generates the HTML for a dropdown list. |
387
|
|
|
*/ |
388
|
|
|
function &create_dropdown_html($identifier, &$pairs, $first_entry='', $selected_key='') |
389
|
|
|
{ |
390
|
|
|
$html = "<select name=\"$identifier\">\n"; |
391
|
|
|
|
392
|
|
|
if('' != $first_entry) |
393
|
|
|
{ |
394
|
|
|
$html .= "<option name=\"\">$first_entry</option>\n"; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
foreach($pairs as $key => $value) |
398
|
|
|
{ |
399
|
|
|
$html .= $selected_key == $key ? |
400
|
|
|
"<option name=\"$key\" selected=\"selected\">$value</option>\n" : |
401
|
|
|
"<option name=\"$key\">$value</option>\n"; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
$html .= "</select>\n"; |
405
|
|
|
|
406
|
|
|
return $html; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
|
410
|
|
|
function dropdown_item_delete($dropdown_type, $language, $index) |
411
|
|
|
{ |
412
|
|
|
$app_list_strings_to_edit = return_app_list_strings_language($language); |
413
|
|
|
$dropdown_array =$app_list_strings_to_edit[$dropdown_type]; |
414
|
|
|
helper_dropdown_item_delete($dropdown_array, $index); |
415
|
|
|
|
416
|
|
|
$contents = return_custom_app_list_strings_file_contents($language); |
417
|
|
|
$new_contents = replace_or_add_dropdown_type($dropdown_type, $dropdown_array, |
418
|
|
|
$contents); |
419
|
|
|
|
420
|
|
|
save_custom_app_list_strings_contents($new_contents, $language); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
function helper_dropdown_item_delete(&$dropdown_array, $index) |
424
|
|
|
{ |
425
|
|
|
// perform the delete from the array |
426
|
|
|
$sliced_off_array = array_splice($dropdown_array, $index); |
427
|
|
|
array_shift($sliced_off_array); |
428
|
|
|
$dropdown_array = array_merge($dropdown_array, $sliced_off_array); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
function dropdown_item_move_up($dropdown_type, $language, $index) |
432
|
|
|
{ |
433
|
|
|
$app_list_strings_to_edit = return_app_list_strings_language($language); |
434
|
|
|
$dropdown_array =$app_list_strings_to_edit[$dropdown_type]; |
435
|
|
|
|
436
|
|
|
if($index > 0 && $index < count($dropdown_array)) |
437
|
|
|
{ |
438
|
|
|
$key = ''; |
439
|
|
|
$value = ''; |
440
|
|
|
$i = 0; |
441
|
|
|
|
442
|
|
|
reset($dropdown_array); |
443
|
|
|
while(list($k, $v) = each($dropdown_array)) |
444
|
|
|
{ |
445
|
|
|
if($i == $index) |
446
|
|
|
{ |
447
|
|
|
$key = $k; |
448
|
|
|
$value = $v; |
449
|
|
|
break; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
$i++; |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
helper_dropdown_item_delete($dropdown_array, $index); |
456
|
|
|
helper_dropdown_item_insert($dropdown_array, $index - 1, $key, $value); |
457
|
|
|
|
458
|
|
|
// get the contents of the custom app list strings file |
459
|
|
|
$contents = return_custom_app_list_strings_file_contents($language); |
460
|
|
|
$new_contents = replace_or_add_dropdown_type($dropdown_type, |
461
|
|
|
$dropdown_array, $contents); |
462
|
|
|
|
463
|
|
|
save_custom_app_list_strings_contents($new_contents, $language); |
464
|
|
|
} |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
function dropdown_item_move_down($dropdown_type, $language, $index) |
468
|
|
|
{ |
469
|
|
|
$app_list_strings_to_edit = return_app_list_strings_language($language); |
470
|
|
|
$dropdown_array =$app_list_strings_to_edit[$dropdown_type]; |
471
|
|
|
|
472
|
|
|
if($index >= 0 && $index < count($dropdown_array) - 1) |
473
|
|
|
{ |
474
|
|
|
$key = ''; |
475
|
|
|
$value = ''; |
476
|
|
|
$i = 0; |
477
|
|
|
|
478
|
|
|
reset($dropdown_array); |
479
|
|
|
while(list($k, $v) = each($dropdown_array)) |
480
|
|
|
{ |
481
|
|
|
if($i == $index) |
482
|
|
|
{ |
483
|
|
|
$key = $k; |
484
|
|
|
$value = $v; |
485
|
|
|
break; |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
$i++; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
helper_dropdown_item_delete($dropdown_array, $index); |
492
|
|
|
helper_dropdown_item_insert($dropdown_array, $index + 1, $key, $value); |
493
|
|
|
|
494
|
|
|
// get the contents of the custom app list strings file |
495
|
|
|
$contents = return_custom_app_list_strings_file_contents($language); |
496
|
|
|
$new_contents = replace_or_add_dropdown_type($dropdown_type, |
497
|
|
|
$dropdown_array, $contents); |
498
|
|
|
|
499
|
|
|
save_custom_app_list_strings_contents($new_contents, $language); |
500
|
|
|
} |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
function dropdown_item_insert($dropdown_type, $language, $index, $key, $value) |
504
|
|
|
{ |
505
|
|
|
$app_list_strings_to_edit = return_app_list_strings_language($language); |
506
|
|
|
$dropdown_array =$app_list_strings_to_edit[$dropdown_type]; |
507
|
|
|
helper_dropdown_item_insert($dropdown_array, $index, $key, $value); |
508
|
|
|
|
509
|
|
|
// get the contents of the custom app list strings file |
510
|
|
|
$contents = return_custom_app_list_strings_file_contents($language); |
511
|
|
|
$new_contents = replace_or_add_dropdown_type($dropdown_type, |
512
|
|
|
$dropdown_array, $contents); |
513
|
|
|
|
514
|
|
|
save_custom_app_list_strings_contents($new_contents, $language); |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
function helper_dropdown_item_insert(&$dropdown_array, $index, $key, $value) |
518
|
|
|
{ |
519
|
|
|
$pair = array($key => $value); |
520
|
|
|
if($index <= 0) |
521
|
|
|
{ |
522
|
|
|
$dropdown_array = array_merge($pair, $dropdown_array); |
523
|
|
|
} |
524
|
|
|
if($index >= count($dropdown_array)) |
525
|
|
|
{ |
526
|
|
|
$dropdown_array = array_merge($dropdown_array, $pair); |
527
|
|
|
} |
528
|
|
|
else |
529
|
|
|
{ |
530
|
|
|
$sliced_off_array = array_splice($dropdown_array, $index); |
531
|
|
|
$dropdown_array = array_merge($dropdown_array, $pair); |
532
|
|
|
$dropdown_array = array_merge($dropdown_array, $sliced_off_array); |
533
|
|
|
} |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
function dropdown_item_edit($dropdown_type, $language, $key, $value) |
537
|
|
|
{ |
538
|
|
|
$app_list_strings_to_edit = return_app_list_strings_language($language); |
539
|
|
|
$dropdown_array =$app_list_strings_to_edit[$dropdown_type]; |
540
|
|
|
|
541
|
|
|
$dropdown_array[$key] = $value; |
542
|
|
|
|
543
|
|
|
$contents = return_custom_app_list_strings_file_contents($language); |
544
|
|
|
|
545
|
|
|
// get the contents of the custom app list strings file |
546
|
|
|
$new_contents = replace_or_add_dropdown_type($dropdown_type, |
547
|
|
|
$dropdown_array, $contents); |
548
|
|
|
|
549
|
|
|
save_custom_app_list_strings_contents($new_contents, $language); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
function replace_or_add_dropdown_type($dropdown_type, &$dropdown_array, |
553
|
|
|
&$file_contents) |
554
|
|
|
{ |
555
|
|
|
$new_contents = "<?php\n?>"; |
556
|
|
|
$new_entry = override_value_to_string('app_list_strings', |
557
|
|
|
$dropdown_type, $dropdown_array); |
558
|
|
|
|
559
|
|
|
if(empty($file_contents)) |
560
|
|
|
{ |
561
|
|
|
// empty file, must create the php tags |
562
|
|
|
$new_contents = "<?php\n$new_entry\n?>"; |
563
|
|
|
} |
564
|
|
|
else |
565
|
|
|
{ |
566
|
|
|
// existing file, try to replace |
567
|
|
|
$new_contents = replace_dropdown_type($dropdown_type, |
568
|
|
|
$dropdown_array, $file_contents); |
569
|
|
|
|
570
|
|
|
$new_contents = dropdown_duplicate_check($dropdown_type, $new_contents); |
571
|
|
|
|
572
|
|
|
if($new_contents == $file_contents) |
573
|
|
|
{ |
574
|
|
|
// replace failed, append to end of file |
575
|
|
|
$new_contents = str_replace("?>", '', $file_contents); |
576
|
|
|
$new_contents .= "\n$new_entry\n?>"; |
577
|
|
|
} |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
return $new_contents; |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
function replace_or_add_app_string($name, $value, |
584
|
|
|
&$file_contents) |
585
|
|
|
{ |
586
|
|
|
$new_contents = "<?php\n?>"; |
587
|
|
|
$new_entry = override_value_to_string('app_strings', |
588
|
|
|
$name, $value); |
589
|
|
|
|
590
|
|
|
if(empty($file_contents)) |
591
|
|
|
{ |
592
|
|
|
// empty file, must create the php tags |
593
|
|
|
$new_contents = "<?php\n$new_entry\n?>"; |
594
|
|
|
} |
595
|
|
|
else |
596
|
|
|
{ |
597
|
|
|
// existing file, try to replace |
598
|
|
|
$new_contents = replace_app_string($name, |
599
|
|
|
$value, $file_contents); |
600
|
|
|
|
601
|
|
|
$new_contents = app_string_duplicate_check($name, $new_contents); |
602
|
|
|
|
603
|
|
|
if($new_contents == $file_contents) |
604
|
|
|
{ |
605
|
|
|
// replace failed, append to end of file |
606
|
|
|
$new_contents = str_replace("?>", '', $file_contents); |
607
|
|
|
$new_contents .= "\n$new_entry\n?>"; |
608
|
|
|
} |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
return $new_contents; |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
|
615
|
|
|
function dropdown_duplicate_check($dropdown_type, &$file_contents) |
616
|
|
|
{ |
617
|
|
|
|
618
|
|
|
if(!empty($dropdown_type) && |
619
|
|
|
!empty($file_contents)) |
620
|
|
|
{ |
621
|
|
|
$pattern = '/\$app_list_strings\[\''. $dropdown_type . |
622
|
|
|
'\'\][\ ]*=[\ ]*array[\ ]*\([^\)]*\)[\ ]*;/'; |
623
|
|
|
|
624
|
|
|
$result = array(); |
625
|
|
|
preg_match_all($pattern, $file_contents, $result); |
626
|
|
|
|
627
|
|
|
if(count($result[0]) > 1) |
628
|
|
|
{ |
629
|
|
|
$new_entry = $result[0][0]; |
630
|
|
|
$new_contents = preg_replace($pattern, '', $file_contents); |
631
|
|
|
|
632
|
|
|
// Append the new entry. |
633
|
|
|
$new_contents = str_replace("?>", '', $new_contents); |
634
|
|
|
$new_contents .= "\n$new_entry\n?>"; |
635
|
|
|
return $new_contents; |
636
|
|
|
} |
637
|
|
|
|
638
|
|
|
return $file_contents; |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
return $file_contents; |
642
|
|
|
|
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
function replace_dropdown_type($dropdown_type, &$dropdown_array, |
646
|
|
|
&$file_contents) |
647
|
|
|
{ |
648
|
|
|
$new_contents = $file_contents; |
649
|
|
|
|
650
|
|
|
if(!empty($dropdown_type) && |
651
|
|
|
is_array($dropdown_array) && |
652
|
|
|
!empty($file_contents)) |
653
|
|
|
{ |
654
|
|
|
$pattern = '/\$app_list_strings\[\''. $dropdown_type . |
655
|
|
|
'\'\][\ ]*=[\ ]*array[\ ]*\([^\)]*\)[\ ]*;/'; |
656
|
|
|
$replacement = override_value_to_string('app_list_strings', |
657
|
|
|
$dropdown_type, $dropdown_array); |
658
|
|
|
$new_contents = preg_replace($pattern, $replacement, $file_contents, 1); |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
return $new_contents; |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
function replace_app_string($name, $value, |
665
|
|
|
&$file_contents) |
666
|
|
|
{ |
667
|
|
|
$new_contents = $file_contents; |
668
|
|
|
|
669
|
|
|
if(!empty($name) && |
670
|
|
|
is_string($value) && |
671
|
|
|
!empty($file_contents)) |
672
|
|
|
{ |
673
|
|
|
$pattern = '/\$app_strings\[\''. $name .'\'\][\ ]*=[\ ]*\'[^\']*\'[\ ]*;/'; |
674
|
|
|
$replacement = override_value_to_string('app_strings', |
675
|
|
|
$name, $value); |
676
|
|
|
$new_contents = preg_replace($pattern, $replacement, $file_contents, 1); |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
return $new_contents; |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
function app_string_duplicate_check($name, &$file_contents) |
683
|
|
|
{ |
684
|
|
|
|
685
|
|
|
if(!empty($name) && |
686
|
|
|
!empty($file_contents)) |
687
|
|
|
{ |
688
|
|
|
$pattern = '/\$app_strings\[\''. $name .'\'\][\ ]*=[\ ]*\'[^\']*\'[\ ]*;/'; |
689
|
|
|
|
690
|
|
|
$result = array(); |
691
|
|
|
preg_match_all($pattern, $file_contents, $result); |
692
|
|
|
|
693
|
|
|
if(count($result[0]) > 1) |
694
|
|
|
{ |
695
|
|
|
$new_entry = $result[0][0]; |
696
|
|
|
$new_contents = preg_replace($pattern, '', $file_contents); |
697
|
|
|
|
698
|
|
|
// Append the new entry. |
699
|
|
|
$new_contents = str_replace("?>", '', $new_contents); |
700
|
|
|
$new_contents .= "\n$new_entry\n?>"; |
701
|
|
|
return $new_contents; |
702
|
|
|
} |
703
|
|
|
return $file_contents; |
704
|
|
|
} |
705
|
|
|
|
706
|
|
|
return $file_contents; |
707
|
|
|
|
708
|
|
|
} |
709
|
|
|
|
710
|
|
|
?> |
711
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.