|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @param string $fileName |
|
5
|
|
|
* @param string $unicodeOptionsRegular |
|
6
|
|
|
* @param string $unicodeOptionsSolid |
|
7
|
|
|
* @param string $unicodeOptionsBrands |
|
8
|
|
|
*/ |
|
9
|
|
|
function writePartial(string $fileName, string $unicodeOptionsRegular, string $unicodeOptionsSolid, string $unicodeOptionsBrands) |
|
10
|
|
|
{ |
|
11
|
|
|
$unicodeOptions = <<<OPTIONS |
|
12
|
|
|
<optgroup label="Regular">$unicodeOptionsRegular</optgroup> |
|
13
|
|
|
<optgroup label="Solid">$unicodeOptionsSolid</optgroup> |
|
14
|
|
|
<optgroup label="Brands">$unicodeOptionsBrands</optgroup> |
|
15
|
|
|
OPTIONS; |
|
16
|
|
|
|
|
17
|
|
|
if (file_put_contents("../partials/$fileName", $unicodeOptions) === false) { |
|
18
|
|
|
echo "Failed to write options to the $fileName\n"; |
|
19
|
|
|
exit(1); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
echo "Options were written successfully to the $fileName\n"; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
$icons = file_get_contents("https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/metadata/icons.yml"); |
|
26
|
|
|
|
|
27
|
|
|
if (empty($icons)) { |
|
28
|
|
|
echo "Failed to load metadata file\n"; |
|
29
|
|
|
exit(1); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if (!function_exists('yaml_parse')) { |
|
33
|
|
|
echo "Please install and enable yaml extension\n"; |
|
34
|
|
|
exit(1); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if (($parsed = yaml_parse($icons)) === false) { |
|
38
|
|
|
echo "Failed to parse metadata file\n"; |
|
39
|
|
|
exit(1); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$optionTemplate = "<option data-icon='%s awesome-icon-item' value='%s'>%s</option>"; |
|
43
|
|
|
|
|
44
|
|
|
$unicodeOptionsRegular = ""; |
|
45
|
|
|
$unicodeOptionsSolid = ""; |
|
46
|
|
|
$unicodeOptionsBrands = ""; |
|
47
|
|
|
|
|
48
|
|
|
$classOptionsRegular = ""; |
|
49
|
|
|
$classOptionsSolid = ""; |
|
50
|
|
|
$classOptionsBrands = ""; |
|
51
|
|
|
|
|
52
|
|
|
$count = 0; |
|
53
|
|
|
|
|
54
|
|
|
foreach ($parsed as $iconName => $iconData) { |
|
55
|
|
|
if (empty($iconData['styles'])) { |
|
56
|
|
|
continue; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if (empty($iconData['label'])) { |
|
60
|
|
|
continue; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if (empty($iconData['unicode'])) { |
|
64
|
|
|
continue; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$label = ucwords($iconData['label']); |
|
68
|
|
|
|
|
69
|
|
|
foreach ($iconData['styles'] as $style) { |
|
70
|
|
View Code Duplication |
if ($style === 'regular') { |
|
|
|
|
|
|
71
|
|
|
$count++; |
|
72
|
|
|
$unicodeOptionsRegular .= sprintf($optionTemplate, "far fa-$iconName", "&#x" . $iconData['unicode'], $label); |
|
73
|
|
|
$classOptionsRegular .= sprintf($optionTemplate, "far fa-$iconName", "far fa-$iconName", $label); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
View Code Duplication |
if ($style === 'solid') { |
|
|
|
|
|
|
77
|
|
|
$count++; |
|
78
|
|
|
$unicodeOptionsSolid .= sprintf($optionTemplate, "fas fa-$iconName", "&#x" . $iconData['unicode'], $label); |
|
79
|
|
|
$classOptionsSolid .= sprintf($optionTemplate, "fas fa-$iconName", "fas fa-$iconName", $label); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
View Code Duplication |
if ($style === 'brands') { |
|
|
|
|
|
|
83
|
|
|
$count++; |
|
84
|
|
|
$unicodeOptionsBrands .= sprintf($optionTemplate, "fab fa-$iconName","&#x" . $iconData['unicode'], $label); |
|
85
|
|
|
$classOptionsBrands .= sprintf($optionTemplate, "fab fa-$iconName", "fab fa-$iconName", $label); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
echo "Icons discovered: $count\n"; |
|
91
|
|
|
|
|
92
|
|
|
writePartial("_unicodeoptions.htm", $unicodeOptionsRegular, $unicodeOptionsSolid, $unicodeOptionsBrands); |
|
93
|
|
|
writePartial("_classoptions.htm", $classOptionsRegular, $classOptionsSolid, $classOptionsBrands); |
|
94
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.