@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add image support for diffusion file view

Summary:
render image as an image tag in diffusion view.

Test Plan:
1. Image shows up correctly. 2. Non-image file still works
fine.

Reviewed By: epriestley
Reviewers: epriestley
CC: epriestley
Differential Revision: 94

+39 -3
+39 -3
src/applications/diffusion/controller/file/DiffusionBrowseFileController.php
··· 18 18 19 19 class DiffusionBrowseFileController extends DiffusionController { 20 20 21 + protected $imageTypes = array( 22 + 'png' => 'image/png', 23 + 'gif' => 'image/gif', 24 + 'ico' => 'image/png', 25 + 'jpg' => 'image/jpeg', 26 + 'jpeg'=> 'image/jpeg' 27 + ); 28 + 21 29 public function processRequest() { 22 30 23 31 // Build the view selection form. ··· 90 98 $file_query->setNeedsBlame($needs_blame); 91 99 $file_query->loadFileContent(); 92 100 93 - // TODO: image 101 + $drequest = $this->getDiffusionRequest(); 102 + $path = $drequest->getPath(); 103 + 104 + $image_type = $this->getImageType($path); 105 + if ($image_type && !$selected) { 106 + $data = $file_query->getRawData(); 107 + 108 + $corpus = phutil_render_tag( 109 + 'img', 110 + array( 111 + 'style' => 'padding-bottom: 10px', 112 + 'src' => 'data:'.$image_type.';base64,'.base64_encode($data), 113 + ) 114 + ); 115 + return $corpus; 116 + } 117 + 94 118 // TODO: blame of blame. 95 119 switch ($selected) { 96 120 case 'plain': ··· 136 160 137 161 list($text_list, $rev_list, $blame_dict) = $file_query->getBlameData(); 138 162 139 - $drequest = $this->getDiffusionRequest(); 140 - $path = $drequest->getPath(); 141 163 $highlightEngine = new PhutilDefaultSyntaxHighlighterEngine(); 142 164 143 165 $text_list = explode("\n", $highlightEngine->highlightSource($path, ··· 253 275 ), 254 276 $name 255 277 ); 278 + } 279 + 280 + 281 + /** 282 + * Returns a content-type corrsponding to an image file extension 283 + * 284 + * @param string $path File path 285 + * @return mixed A content-type string or NULL if path doesn't end with a 286 + * recognized image extension 287 + */ 288 + public function getImageType($path) { 289 + $ext = pathinfo($path); 290 + $ext = $ext['extension']; 291 + return idx($this->imageTypes, $ext); 256 292 } 257 293 258 294 }