Differential D17543 Diff 42195 src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | public static function getImageMap() { | ||||
$list = id(new FileFinder($root)) | $list = id(new FileFinder($root)) | ||||
->withType('f') | ->withType('f') | ||||
->withFollowSymlinks(true) | ->withFollowSymlinks(true) | ||||
->find(); | ->find(); | ||||
foreach ($list as $file) { | foreach ($list as $file) { | ||||
$map['alphanumeric/'.$file] = $root.$file; | $map['alphanumeric/'.$file] = $root.$file; | ||||
} | } | ||||
return $map; | return $map; | ||||
} | } | ||||
public function getUniqueProfileImage($username) { | public function getUniqueProfileImage($username) { | ||||
$pack_map = $this->getImagePackMap(); | $pack_map = $this->getImagePackMap(); | ||||
$image_map = $this->getImageMap(); | $image_map = $this->getImageMap(); | ||||
$color_map = $this->getColorMap(); | $color_map = $this->getColorMap(); | ||||
$border_map = $this->getBorderMap(); | $border_map = $this->getBorderMap(); | ||||
$file = phutil_utf8_strtoupper(substr($username, 0, 1)); | $file = phutil_utf8_strtoupper(substr($username, 0, 1)); | ||||
$pack_count = count($pack_map); | $pack_count = count($pack_map); | ||||
$color_count = count($color_map); | $color_count = count($color_map); | ||||
$border_count = count($border_map); | $border_count = count($border_map); | ||||
$pack_seed = $username.'_pack'; | $pack_seed = $username.'_pack'; | ||||
$color_seed = $username.'_color'; | $color_seed = $username.'_color'; | ||||
$border_seed = $username.'_border'; | $border_seed = $username.'_border'; | ||||
$pack_key = | $pack_key = | ||||
PhabricatorHash::digestToRange($pack_seed, 1, $pack_count); | PhabricatorHash::digestToRange($pack_seed, 0, $pack_count - 1); | ||||
$color_key = | $color_key = | ||||
PhabricatorHash::digestToRange($color_seed, 1, $color_count); | PhabricatorHash::digestToRange($color_seed, 0, $color_count - 1); | ||||
$border_key = | $border_key = | ||||
PhabricatorHash::digestToRange($border_seed, 1, $border_count); | PhabricatorHash::digestToRange($border_seed, 0, $border_count - 1); | ||||
$pack = $pack_map[$pack_key]; | $pack = $pack_map[$pack_key]; | ||||
$icon = 'alphanumeric/'.$pack.'/'.$file.'.png'; | $icon = 'alphanumeric/'.$pack.'/'.$file.'.png'; | ||||
$color = $color_map[$color_key]; | $color = $color_map[$color_key]; | ||||
$border = $border_map[$border_key]; | $border = $border_map[$border_key]; | ||||
if (!isset($image_map[$icon])) { | if (!isset($image_map[$icon])) { | ||||
$icon = 'alphanumeric/'.$pack.'/_default.png'; | $icon = 'alphanumeric/'.$pack.'/_default.png'; | ||||
Show All 29 Lines | public static function getImagePackMap() { | ||||
$root = dirname(phutil_get_library_root('phabricator')); | $root = dirname(phutil_get_library_root('phabricator')); | ||||
$root = $root.'/resources/builtin/alphanumeric/'; | $root = $root.'/resources/builtin/alphanumeric/'; | ||||
$map = id(new FileFinder($root)) | $map = id(new FileFinder($root)) | ||||
->withType('d') | ->withType('d') | ||||
->withFollowSymlinks(false) | ->withFollowSymlinks(false) | ||||
->find(); | ->find(); | ||||
return $map; | return array_values($map); | ||||
} | } | ||||
public static function getBorderMap() { | public static function getBorderMap() { | ||||
$map = array( | $map = array( | ||||
array(0, 0, 0, 0), | array(0, 0, 0, 0), | ||||
array(0, 0, 0, 0.3), | array(0, 0, 0, 0.3), | ||||
array(255, 255, 255, 0.4), | array(255, 255, 255, 0.4), | ||||
▲ Show 20 Lines • Show All 245 Lines • Show Last 20 Lines |