Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/builtin/PhabricatorFilesComposeIconBuiltinFile.php
12242 views
1
<?php
2
3
final class PhabricatorFilesComposeIconBuiltinFile
4
extends PhabricatorFilesBuiltinFile {
5
6
private $icon;
7
private $color;
8
9
public function setIcon($icon) {
10
$this->icon = $icon;
11
return $this;
12
}
13
14
public function getIcon() {
15
return $this->icon;
16
}
17
18
public function setColor($color) {
19
$this->color = $color;
20
return $this;
21
}
22
23
public function getColor() {
24
return $this->color;
25
}
26
27
public function getBuiltinFileKey() {
28
$icon = $this->getIcon();
29
$color = $this->getColor();
30
$desc = "compose(icon={$icon}, color={$color})";
31
$hash = PhabricatorHash::digestToLength($desc, 40);
32
return "builtin:{$hash}";
33
}
34
35
public function getBuiltinDisplayName() {
36
$icon = $this->getIcon();
37
$color = $this->getColor();
38
return "{$icon}-{$color}.png";
39
}
40
41
public function loadBuiltinFileData() {
42
return $this->composeImage($this->getColor(), $this->getIcon());
43
}
44
45
public static function getAllIcons() {
46
$root = dirname(phutil_get_library_root('phabricator'));
47
$root = $root.'/resources/builtin/projects/';
48
49
$quips = self::getIconQuips();
50
51
$map = array();
52
$list = Filesystem::listDirectory($root, $include_hidden = false);
53
foreach ($list as $file) {
54
$short = preg_replace('/\.png$/', '', $file);
55
56
$map[$short] = array(
57
'path' => $root.$file,
58
'quip' => idx($quips, $short, $short),
59
);
60
}
61
62
return $map;
63
}
64
65
public static function getAllColors() {
66
$colors = id(new CelerityResourceTransformer())
67
->getCSSVariableMap();
68
69
$colors = array_select_keys(
70
$colors,
71
array(
72
'red',
73
'orange',
74
'yellow',
75
'green',
76
'blue',
77
'sky',
78
'indigo',
79
'violet',
80
'pink',
81
'charcoal',
82
'backdrop',
83
));
84
85
$quips = self::getColorQuips();
86
87
$map = array();
88
foreach ($colors as $name => $color) {
89
$map[$name] = array(
90
'color' => $color,
91
'quip' => idx($quips, $name, $name),
92
);
93
}
94
95
return $map;
96
}
97
98
private function composeImage($color, $icon) {
99
$color_map = self::getAllColors();
100
$color = idx($color_map, $color);
101
if (!$color) {
102
$fallback = 'backdrop';
103
$color = idx($color_map, $fallback);
104
if (!$color) {
105
throw new Exception(
106
pht(
107
'Fallback compose color ("%s") does not exist!',
108
$fallback));
109
}
110
}
111
112
$color_hex = idx($color, 'color');
113
$color_const = hexdec(trim($color_hex, '#'));
114
115
$icon_map = self::getAllIcons();
116
$icon = idx($icon_map, $icon);
117
if (!$icon) {
118
$fallback = 'fa-umbrella';
119
$icon = idx($icon_map, $fallback);
120
if (!$icon) {
121
throw new Exception(
122
pht(
123
'Fallback compose icon ("%s") does not exist!',
124
$fallback));
125
}
126
}
127
128
$path = idx($icon, 'path');
129
$data = Filesystem::readFile($path);
130
131
$icon_img = imagecreatefromstring($data);
132
133
$canvas = imagecreatetruecolor(200, 200);
134
imagefill($canvas, 0, 0, $color_const);
135
imagecopy($canvas, $icon_img, 0, 0, 0, 0, 200, 200);
136
137
return PhabricatorImageTransformer::saveImageDataInAnyFormat(
138
$canvas,
139
'image/png');
140
}
141
142
private static function getIconQuips() {
143
return array(
144
'fa-android' => pht('Friendly Robot'),
145
'fa-apple' => pht('Friendly Fruit'),
146
'fa-beer' => pht('Liquid Carbs'),
147
'fa-bomb' => pht('Boom!'),
148
'fa-book' => pht('Read Me'),
149
'fa-briefcase' => pht('Briefcase'),
150
'fa-bug' => pht('Bug'),
151
'fa-building' => pht('Company'),
152
'fa-calendar' => pht('Deadline'),
153
'fa-camera-retro' => pht('Leica Enthusiast'),
154
'fa-chrome' => pht('Shiny'),
155
'fa-cloud' => pht('The Cloud'),
156
'fa-coffee' => pht('Go Juice'),
157
'fa-comments' => pht('Cartoon Captions'),
158
'fa-credit-card' => pht('Accounting'),
159
'fa-database' => pht('Stack of Pancakes'),
160
'fa-desktop' => pht('Cardboard Box'),
161
'fa-diamond' => pht('Isometric-Hexoctahedral'),
162
'fa-empire' => pht('Bad Guys'),
163
'fa-envelope' => pht('Communication'),
164
'fa-facebook' => pht('College Site'),
165
'fa-fax' => pht('Communication Device'),
166
'fa-film' => pht('Physical Film'),
167
'fa-firefox' => pht('Blake Ross'),
168
'fa-flag-checkered' => pht('Goal'),
169
'fa-flask' => pht('Experimental'),
170
'fa-folder' => pht('Folder'),
171
'fa-gamepad' => pht('Half-Life 3 Confirmed'),
172
'fa-gears' => pht('Mechanical'),
173
'fa-google' => pht('Car Company'),
174
'fa-hand-peace-o' => pht('Peace'),
175
'fa-hashtag' => pht('Not Slack'),
176
'fa-heart' => pht('Myocardial Infarction'),
177
'fa-internet-explorer' => pht('Now Just Edge'),
178
'fa-key' => pht('Primitive Security'),
179
'fa-legal' => pht('Hired Protection'),
180
'fa-linux' => pht('M\'Lady'),
181
'fa-lock' => pht('Policy'),
182
'fa-map-marker' => pht('Destination Beacon'),
183
'fa-microphone' => pht('Podcasting'),
184
'fa-mobile' => pht('Tiny Pocket Cat Meme Machine'),
185
'fa-money' => pht('1 of 99 Problems'),
186
'fa-phone' => pht('Grandma Uses This'),
187
'fa-pie-chart' => pht('Not Actually Edible'),
188
'fa-rebel' => pht('Good Guys'),
189
'fa-reddit-alien' => pht('Updoot In 5 Seconds'),
190
'fa-safari' => pht('Fruit Exploration'),
191
'fa-search' => pht('Dust Detector'),
192
'fa-server' => pht('Heating Units'),
193
'fa-shopping-cart' => pht('Buy Stuff'),
194
'fa-sitemap' => pht('Sitemap'),
195
'fa-star' => pht('The More You Know'),
196
'fa-tablet' => pht('Cellular Telephone For Giants'),
197
'fa-tag' => pht('You\'re It'),
198
'fa-tags' => pht('Tags'),
199
'fa-trash-o' => pht('Garbage'),
200
'fa-truck' => pht('Release'),
201
'fa-twitter' => pht('Bird Stencil'),
202
'fa-umbrella' => pht('An Umbrella'),
203
'fa-university' => pht('School'),
204
'fa-user-secret' => pht('Shhh'),
205
'fa-user' => pht('Individual'),
206
'fa-users' => pht('Team'),
207
'fa-warning' => pht('No Caution Required, Everything Looks Safe'),
208
'fa-wheelchair' => pht('Accessibility'),
209
'fa-windows' => pht('Windows'),
210
);
211
}
212
213
private static function getColorQuips() {
214
return array(
215
'red' => pht('Verbillion'),
216
'orange' => pht('Navel Orange'),
217
'yellow' => pht('Prim Goldenrod'),
218
'green' => pht('Lustrous Verdant'),
219
'blue' => pht('Tropical Deep'),
220
'sky' => pht('Wide Open Sky'),
221
'indigo' => pht('Pleated Khaki'),
222
'violet' => pht('Aged Merlot'),
223
'pink' => pht('Easter Bunny'),
224
'charcoal' => pht('Gemstone'),
225
'backdrop' => pht('Driven Snow'),
226
);
227
}
228
229
}
230
231