-
Notifications
You must be signed in to change notification settings - Fork 0
/
unbuildApplication.php
83 lines (70 loc) · 2.81 KB
/
unbuildApplication.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
<?php
/**
* @brief use this script to unbuild XML files to their original .php/phtml/js files. Supply the application key as solo argument.
* @copyright jannes-io <https://github.com/jannes-io/>
* @example php unbuildApplication.php perscom
*/
$application = $argv[1];
if (empty($application)) {
throw new InvalidArgumentException('Argument 1 "application key" is missing. I.E. core, forums,...');
}
$dir = __DIR__ . '/applications/' . $application;
class ApplicationUnbuilder
{
public function unbuild(string $dir): void
{
$this->unbuildLang($dir);
$this->unbuildTheme($dir);
$this->unbuildJS($dir);
}
private function unbuildLang(string $dir): void
{
$langXML = $this->readXML($dir . '/data/lang.xml');
$langFile = "<?php\n\$lang = [\n";
foreach ($langXML->app->word as $word) {
$key = (string)$word->attributes()->key;
$val = addslashes((string)$word);
$langFile .= "'{$key}' => '$val',\n";
}
$langFile .= "];";
file_put_contents($dir . '/dev/lang.php', $langFile);
}
private function unbuildTheme(string $dir)
{
$themeXML = $this->readXML($dir . '/data/theme.xml');
foreach ($themeXML->template as $template) {
$location = (string)$template->attributes()->template_location;
$group = (string)$template->attributes()->template_group;
$name = (string)$template->attributes()->template_name;
$data = (string)$template->attributes()->template_data;
$content = (string)$template;
$phtmlContent = "<ips:template parameters=\"{$data}\" />\n" . $content;
$templateDir = "$dir/dev/html/$location/$group";
if (!is_dir($templateDir)) {
mkdir($templateDir, 0777, true);
}
file_put_contents("$templateDir/$name.phtml", $phtmlContent);
}
}
private function unbuildJS(string $dir)
{
$jsXML = $this->readXML($dir . '/data/javascript.xml');
foreach ($jsXML->file as $template) {
$location = (string)$template->attributes()->javascript_location;
$path = (string)$template->attributes()->javascript_path;
$name = (string)$template->attributes()->javascript_name;
$content = (string)$template;
$templateDir = "$dir/dev/js/$location/$path";
if (!is_dir($templateDir)) {
mkdir($templateDir, 0777, true);
}
file_put_contents("$templateDir/$name", $content);
}
}
private function readXML(string $filename): SimpleXMLElement
{
$langXML = file_get_contents($filename);
return simplexml_load_string($langXML, 'SimpleXMLElement', LIBXML_NOCDATA);
}
}
(new ApplicationUnbuilder())->unbuild($dir);