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_import_fs.php
executable file
·94 lines (83 loc) · 2.12 KB
/
xml_import_fs.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
#!/usr/bin/php
<?php
/*
* FreeSwitch
* TTS Voice Prompt Generator
* - Import from FreeSwitch phrase XML files -
*
* Copyright (c) 2013, Julian Pawlowski <[email protected]>
* See LICENSE file for details.
*
*/
error_reporting(E_ALL ^ E_NOTICE);
$locale = $argv[1];
$import_file = "./import/phrase_".$locale.".xml";
if(empty($locale)) {
print ("ERROR: Please enter locale name as parameter.\n");
exit;
} elseif(is_file($import_file)) {
$url = $import_file;
} else {
$url = "http://git.freeswitch.org/git/freeswitch/plain/docs/phrase/phrase_" . $locale . ".xml";
}
$xml = simplexml_load_file($url);
foreach($xml as $locale => $xml_locale)
{
foreach($xml_locale as $category => $xml_category)
{
foreach($xml_category as $prompt)
{
if ($prompt[filename] != "")
{
$filename_base = trim(str_replace(".wav", ".txt", $prompt[filename]));
} else {
continue;
}
if ($prompt[type])
{
$inputdir = "./" . $prompt[type] . ".new/";
$dirname = $inputdir . $category;
$filename = $inputdir . $category . "/" . $filename_base;
$filename_check = "./" . $prompt[type] . "/" . $category . "/" . $filename_base;
} else {
$inputdir = "./input.new/";
$dirname = $inputdir . $locale . "/" . $category;
$filename = $inputdir . $locale . "/" . $category . "/" . $filename_base;
$filename_check = "./input/" . $locale . "/" . $category . "/" . $filename_base;
}
if (!is_file($filename_check))
{
if (!is_dir($dirname))
{
mkdir($dirname, 0777, true);
}
if ($prompt[phrase] == "" OR $prompt[phrase] == "NULL")
{
$phrase = "This text is missing #TODO";
} else {
$phrase = $prompt[phrase];
}
$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);
}
}
}
}
}
?>