This repository has been archived by the owner on Aug 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathxml_read.php
executable file
·96 lines (84 loc) · 1.89 KB
/
xml_read.php
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
#!/usr/bin/php
<?php
/*
* FreeSwitch
* TTS Voice Prompt Generator
* - Import from XML to flat files -
*
* Copyright (c) 2013, Julian Pawlowski <[email protected]>
* See LICENSE file for details.
*
*/
error_reporting(E_ALL ^ E_NOTICE);
$locale = $argv[1];
$import_file = "./xml/phrase-tts_".$locale.".xml";
if(empty($locale)) {
print ("ERROR: Please enter locale name as parameter.\n");
exit;
} elseif(!is_file($import_file)) {
print ("ERROR: No locale file $import_file found.\n");
exit;
}
$xml = simplexml_load_file($import_file);
foreach($xml as $category => $xml_category)
{
foreach($xml_category as $prompt)
{
if ($prompt[filename] != "")
{
$filename_base = trim(str_replace(".wav", ".txt", $prompt[filename]));
} else {
continue;
}
$inputdir = "./input/";
$dirname = "./input/" . $locale . "/" . $category;
$filename = "./input/" . $locale . "/" . $category . "/" . $filename_base;
if (!is_dir($dirname))
{
mkdir($dirname, 0777, true);
}
if ($prompt[phrase] == "" OR $prompt[phrase] == "NULL")
{
$phrase = "This text is missing #TODO";
} else {
$phrase = utf8_decode($prompt[phrase]);
}
if ($prompt[link])
{
if (is_link($filename))
{
unlink($filename);
} elseif (is_file($filename)) {
delete($filename);
}
if (symlink($prompt[link], $filename))
{
print "Created link $filename to $prompt[link]\n";
} else {
print ("ERROR on file $filename\n");
print_r ($prompt);
}
} else {
$fhandle = fopen($filename, "w");
if (fwrite($fhandle, $prompt[phrase]))
{
if ($prompt[phrase] == "")
{
print "Created file $filename with EMPTY phrase";
} else {
print "Created file $filename";
}
if ($prompt[type])
{
print " (type: ".$prompt[type].")\n";
} else {
print "\n";
}
} else {
print ("ERROR on file $filename\n");
print_r ($prompt);
}
}
}
}
?>