-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathville_fui_svg.php
156 lines (124 loc) · 5.32 KB
/
ville_fui_svg.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
$directory = 'node_modules/@fluentui/svg-icons/icons';
$outputbasedir = 'source/class/ville/embed/fluent/';
$endswithbasestr = "_regular.svg";
$templatedirectory = 'templates/';
$templatefile = file_get_contents('templates/fui.bundle.icon.tmpl.js');
$templatefilecode = file_get_contents('templates/fui.appcode.tmpl');
$templateprepcode = file_get_contents('templates/fui.appcode.gb.tmpl');
$apptxtfile = 'fui.appcode.txt';
if (!is_dir($directory)) {
exit('Invalid diretory path');
}
$limitcount = 0;
foreach (scandir($directory) as $file) {
if ($file !== '.' && $file !== '..') {
if (is_dir($directory.'/'.$file)) {
// directory prep code
//mkdir($outputbasedir.$file);
//$file = str_replace('-', '', $file);
//writePrepCodetoFile($file);
$endswithstr = $endswithbasestr;
if ($file == "ar" or $file == "he")
$endswithstr = "_24".$endswithstr;
else
$endswithstr = "_20".$endswithstr;
$subdirectory = $directory.'/'.$file;
foreach (scandir($subdirectory) as $subfile) {
if (str_ends_with($subfile, $endswithstr)) {
createIconObjFile($subfile, $file);
}
}
++$limitcount;
} else {
if (str_ends_with($file, "_20".$endswithbasestr)) {
createIconObjFile($file, null);
}
}
++$limitcount;
}
//if ($limitcount >= 6)
// break;
}
// START Update the Application.js with demos of each icon
//read the entire string
// $apptxtstr = file_get_contents($apptxtfile);
//replace something in the file string - this is a VERY simple example
// $appcodefileloc = 'source/class/wax/demo/Application.js';
// $appcodefile = file_get_contents($appcodefileloc);
// $appcodefile = str_replace('//${{phpgenerated}}', $apptxtstr, $appcodefile);
//write the entire string
// file_put_contents($appcodefileloc, $appcodefile);
// END of Application.js file update
//var_dump($files);
//var_dump(count($files));
//var_dump($svgData);
echo "Extraction and writing complete!\n";
// FUNCTIONS
function createIconObjFile(string $file, ?string $fromdirname): void {
global $directory, $outputbasedir, $templatefile;
$subfolderns = "";
$dotnotation = "";
$curdirectory = $directory;
if ($fromdirname) {
$curdirectory = $curdirectory.'/'.$fromdirname;
$subfolderns = str_replace('-', '', $fromdirname);
$dotnotation = ".";
}
// get classname and remove underscore if any
$allnames = explode("_",ucwords($file,"_"));
$lastele = array_pop($allnames);
$lastele = array_pop($allnames);
$classname = implode($allnames);
// get path d value
$svgData = file_get_contents($curdirectory.'/'.$file);
$svgregcontents = new SimpleXMLElement($svgData);
$pathdregular = $svgregcontents->path->attributes()[0];
$classtemplate = $templatefile;
$classtemplate = str_replace('${{subfolderns}}', $subfolderns, $classtemplate);
$classtemplate = str_replace('${{dotnotation}}', $dotnotation, $classtemplate);
$classtemplate = str_replace('${{classname}}', $classname, $classtemplate);
$classtemplate = str_replace('${{pathdregular}}', $pathdregular, $classtemplate);
// check to see if there's a filled version
$replacedfilename = str_replace("_regular.svg", "_filled.svg", $file);
if (file_exists($curdirectory.'/'.$replacedfilename)){
$filledfile = file_get_contents($curdirectory.'/'.$replacedfilename);
$svgfilledcontents = new SimpleXMLElement($filledfile);
$pathdfilled = $svgfilledcontents->path->attributes()[0];
$classtemplate = str_replace('${{pathdfilled}}', $pathdfilled, $classtemplate);
} else {
$classtemplate = str_replace('${{pathdfilled}}', '', $classtemplate);
}
//echo "Hello: ".$classtemplate."\n";
// write file
if ($fromdirname) {
$fromdirname = str_replace('-', '', $fromdirname);
$outputFile = $outputbasedir.$fromdirname.'/'.$classname.'.js';
} else
$outputFile = $outputbasedir.$classname.'.js';
if (!file_exists($outputFile)) {
file_put_contents($outputFile, $classtemplate);
addToAppCodeFile($classname, $subfolderns);
}
}
function addToAppCodeFile(string $classname, string $subfolderns): void {
global $templatefilecode, $apptxtfile;
$strdot = "";
if ($subfolderns !== "")
$strdot = ".";
$appcodetemplate = $templatefilecode;
$appcodetemplate = str_replace('${{subfolderns}}', $subfolderns, $appcodetemplate);
$appcodetemplate = str_replace('${{dotnotation}}', $strdot, $appcodetemplate);
$appcodetemplate = str_replace('${{iconobjname}}', $classname, $appcodetemplate);
file_put_contents($apptxtfile, $appcodetemplate . "\n", FILE_APPEND);
//echo "addToAppCodeFile: ".$classname."\n";
}
function writePrepCodetoFile(string $subfolderns): void {
global $templateprepcode, $apptxtfile;
$appcodetemplate = $templateprepcode;
$appcodetemplate = str_replace('${{subfolderns}}', $subfolderns, $appcodetemplate);
//$appcodetemplate = str_replace('${{iconobjname}}', $classname, $appcodetemplate);
file_put_contents($apptxtfile, $appcodetemplate . "\n", FILE_APPEND);
//echo "addToAppCodeFile: ".$classname."\n";
}
?>