[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorFileComposeController 4 extends PhabricatorFileController { 5 6 public function processRequest() { 7 $request = $this->getRequest(); 8 $viewer = $request->getUser(); 9 10 $colors = array( 11 'red' => pht('Verbillion'), 12 'orange' => pht('Navel Orange'), 13 'yellow' => pht('Prim Goldenrod'), 14 'green' => pht('Lustrous Verdant'), 15 'blue' => pht('Tropical Deep'), 16 'sky' => pht('Wide Open Sky'), 17 'indigo' => pht('Pleated Khaki'), 18 'violet' => pht('Aged Merlot'), 19 'charcoal' => pht('Gemstone'), 20 'backdrop' => pht('Driven Snow'), 21 ); 22 23 $manifest = PHUIIconView::getSheetManifest(PHUIIconView::SPRITE_PROJECTS); 24 25 if ($request->isFormPost()) { 26 $icon = $request->getStr('icon'); 27 $color = $request->getStr('color'); 28 29 if (isset($colors[$color]) && isset($manifest['projects-'.$icon])) { 30 $root = dirname(phutil_get_library_root('phabricator')); 31 $icon_file = $root.'/resources/sprite/projects_1x/'.$icon.'.png'; 32 $icon_data = Filesystem::readFile($icon_file); 33 34 35 $data = $this->composeImage($color, $icon_data); 36 37 $file = PhabricatorFile::buildFromFileDataOrHash( 38 $data, 39 array( 40 'name' => 'project.png', 41 'canCDN' => true, 42 )); 43 44 $content = array( 45 'phid' => $file->getPHID(), 46 ); 47 48 return id(new AphrontAjaxResponse())->setContent($content); 49 } 50 } 51 52 $value_color = head_key($colors); 53 $value_icon = head_key($manifest); 54 $value_icon = substr($value_icon, strlen('projects-')); 55 56 require_celerity_resource('people-profile-css'); 57 58 $buttons = array(); 59 foreach ($colors as $color => $name) { 60 $buttons[] = javelin_tag( 61 'button', 62 array( 63 'class' => 'grey profile-image-button', 64 'sigil' => 'has-tooltip compose-select-color', 65 'style' => 'margin: 0 8px 8px 0', 66 'meta' => array( 67 'color' => $color, 68 'tip' => $name, 69 ), 70 ), 71 id(new PHUIIconView()) 72 ->addClass('compose-background-'.$color)); 73 } 74 75 $icons = array(); 76 77 $icon_quips = array( 78 '8ball' => pht('Take a Risk'), 79 'alien' => pht('Foreign Interface'), 80 'announce' => pht('Louder is Better'), 81 'art' => pht('Unique Snowflake'), 82 'award' => pht('Shooting Star'), 83 'bacon' => pht('Healthy Vegetables'), 84 'bandaid' => pht('Durable Infrastructure'), 85 'beer' => pht('Healthy Vegetable Juice'), 86 'bomb' => pht('Imminent Success'), 87 'briefcase' => pht('Adventure Pack'), 88 'bug' => pht('Costumed Egg'), 89 'calendar' => pht('Everyone Loves Meetings'), 90 'cloud' => pht('Water Cycle'), 91 'coffee' => pht('Half-Whip Nonfat Soy Latte'), 92 'creditcard' => pht('Expense It'), 93 'death' => pht('Calcium Promotes Bone Health'), 94 'desktop' => pht('Magical Portal'), 95 'dropbox' => pht('Cardboard Box'), 96 'education' => pht('Debt'), 97 'experimental' => pht('CAUTION: Dangerous Chemicals'), 98 'facebook' => pht('Popular Social Network'), 99 'facility' => pht('Pollution Solves Problems'), 100 'film' => pht('Actual Physical Film'), 101 'forked' => pht('You Can\'t Eat Soup'), 102 'games' => pht('Serious Business'), 103 'ghost' => pht('Haunted'), 104 'gift' => pht('Surprise!'), 105 'globe' => pht('Scanner Sweep'), 106 'golf' => pht('Business Meeting'), 107 'heart' => pht('Undergoing a Major Surgery'), 108 'intergalactic' => pht('Jupiter'), 109 'lock' => pht('Extremely Secret'), 110 'mail' => pht('Oragami'), 111 'martini' => pht('Healthy Olive Drink'), 112 'medical' => pht('Medic!'), 113 'mobile' => pht('Cellular Telephone'), 114 'music' => pht("\xE2\x99\xAB"), 115 'news' => pht('Actual Physical Newspaper'), 116 'orgchart' => pht('It\'s Good to be King'), 117 'peoples' => pht('Angel and Devil'), 118 'piechart' => pht('Actual Physical Pie'), 119 'poison' => pht('Healthy Bone Juice'), 120 'putabirdonit' => pht('Put a Bird On It'), 121 'radiate' => pht('Radiant Beauty'), 122 'savings' => pht('Oink Oink'), 123 'search' => pht('Sleuthing'), 124 'shield' => pht('Royal Crest'), 125 'speed' => pht('Slow and Steady'), 126 'sprint' => pht('Fire Exit'), 127 'star' => pht('The More You Know'), 128 'storage' => pht('Stack of Pancakes'), 129 'tablet' => pht('Cellular Telephone For Giants'), 130 'travel' => pht('Pretty Clearly an Airplane'), 131 'twitter' => pht('Bird Stencil'), 132 'warning' => pht('No Caution Required, Everything Looks Safe'), 133 'whale' => pht('Friendly Walrus'), 134 ); 135 136 foreach ($manifest as $icon => $spec) { 137 $icon = substr($icon, strlen('projects-')); 138 139 $icons[] = javelin_tag( 140 'button', 141 array( 142 'class' => 'grey profile-image-button', 143 'sigil' => 'has-tooltip compose-select-icon', 144 'style' => 'margin: 0 8px 8px 0', 145 'meta' => array( 146 'icon' => $icon, 147 'tip' => idx($icon_quips, $icon, $icon), 148 ), 149 ), 150 id(new PHUIIconView()) 151 ->setSpriteIcon($icon) 152 ->setSpriteSheet(PHUIIconView::SPRITE_PROJECTS)); 153 } 154 155 $dialog_id = celerity_generate_unique_node_id(); 156 $color_input_id = celerity_generate_unique_node_id();; 157 $icon_input_id = celerity_generate_unique_node_id(); 158 $preview_id = celerity_generate_unique_node_id(); 159 160 $preview = id(new PHUIIconView()) 161 ->setID($preview_id) 162 ->addClass('compose-background-'.$value_color) 163 ->setSpriteIcon($value_icon) 164 ->setSpriteSheet(PHUIIconView::SPRITE_PROJECTS); 165 166 $color_input = javelin_tag( 167 'input', 168 array( 169 'type' => 'hidden', 170 'name' => 'color', 171 'value' => $value_color, 172 'id' => $color_input_id, 173 )); 174 175 $icon_input = javelin_tag( 176 'input', 177 array( 178 'type' => 'hidden', 179 'name' => 'icon', 180 'value' => $value_icon, 181 'id' => $icon_input_id, 182 )); 183 184 Javelin::initBehavior('phabricator-tooltips'); 185 Javelin::initBehavior( 186 'icon-composer', 187 array( 188 'dialogID' => $dialog_id, 189 'colorInputID' => $color_input_id, 190 'iconInputID' => $icon_input_id, 191 'previewID' => $preview_id, 192 'defaultColor' => $value_color, 193 'defaultIcon' => $value_icon, 194 )); 195 196 $dialog = id(new AphrontDialogView()) 197 ->setUser($viewer) 198 ->setFormID($dialog_id) 199 ->setClass('compose-dialog') 200 ->setTitle(pht('Compose Image')) 201 ->appendChild( 202 phutil_tag( 203 'div', 204 array( 205 'class' => 'compose-header', 206 ), 207 pht('Choose Background Color'))) 208 ->appendChild($buttons) 209 ->appendChild( 210 phutil_tag( 211 'div', 212 array( 213 'class' => 'compose-header', 214 ), 215 pht('Choose Icon'))) 216 ->appendChild($icons) 217 ->appendChild( 218 phutil_tag( 219 'div', 220 array( 221 'class' => 'compose-header', 222 ), 223 pht('Preview'))) 224 ->appendChild($preview) 225 ->appendChild($color_input) 226 ->appendChild($icon_input) 227 ->addCancelButton('/') 228 ->addSubmitButton(pht('Save Image')); 229 230 return id(new AphrontDialogResponse())->setDialog($dialog); 231 } 232 233 private function composeImage($color, $icon_data) { 234 $icon_img = imagecreatefromstring($icon_data); 235 236 $map = CelerityResourceTransformer::getCSSVariableMap(); 237 $color_string = idx($map, $color, '#ff00ff'); 238 $color_const = hexdec(trim($color_string, '#')); 239 240 $canvas = imagecreatetruecolor(50, 50); 241 imagefill($canvas, 0, 0, $color_const); 242 243 imagecopy($canvas, $icon_img, 0, 0, 0, 0, 50, 50); 244 245 return PhabricatorImageTransformer::saveImageDataInAnyFormat( 246 $canvas, 247 'image/png'); 248 } 249 250 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |