コード例 #1
0
 public function getTransformedDimensions(PhabricatorFile $file)
 {
     $dst_x = $this->dstX;
     $dst_y = $this->dstY;
     // If this is transform has fixed dimensions, we can trivially predict
     // the dimensions of the transformed file.
     if ($dst_y !== null) {
         return array($dst_x, $dst_y);
     }
     $src_x = $file->getImageWidth();
     $src_y = $file->getImageHeight();
     if (!$src_x || !$src_y) {
         return null;
     }
     $dimensions = $this->computeDimensions($src_x, $src_y, $dst_x, $dst_y);
     return array($dimensions['dst_x'], $dimensions['dst_y']);
 }
コード例 #2
0
 private function renderImageFile(PhabricatorFile $file, PhabricatorObjectHandle $handle, array $options)
 {
     require_celerity_resource('lightbox-attachment-css');
     $attrs = array();
     $image_class = null;
     $use_size = true;
     if (!$options['size']) {
         $width = $this->parseDimension($options['width']);
         $height = $this->parseDimension($options['height']);
         if ($width || $height) {
             $use_size = false;
             $attrs += array('src' => $file->getBestURI(), 'width' => $width, 'height' => $height);
         }
     }
     if ($use_size) {
         switch ((string) $options['size']) {
             case 'full':
                 $attrs += array('src' => $file->getBestURI(), 'height' => $file->getImageHeight(), 'width' => $file->getImageWidth());
                 $image_class = 'phabricator-remarkup-embed-image-full';
                 break;
             case 'thumb':
             default:
                 $preview_key = PhabricatorFileThumbnailTransform::TRANSFORM_PREVIEW;
                 $xform = PhabricatorFileTransform::getTransformByKey($preview_key);
                 $attrs['src'] = $file->getURIForTransform($xform);
                 $dimensions = $xform->getTransformedDimensions($file);
                 if ($dimensions) {
                     list($x, $y) = $dimensions;
                     $attrs['width'] = $x;
                     $attrs['height'] = $y;
                 }
                 $image_class = 'phabricator-remarkup-embed-image';
                 break;
         }
     }
     if (isset($options['alt'])) {
         $attrs['alt'] = $options['alt'];
     }
     $img = phutil_tag('img', $attrs);
     $embed = javelin_tag('a', array('href' => $file->getBestURI(), 'class' => $image_class, 'sigil' => 'lightboxable', 'meta' => array('phid' => $file->getPHID(), 'uri' => $file->getBestURI(), 'dUri' => $file->getDownloadURI(), 'viewable' => true)), $img);
     switch ($options['layout']) {
         case 'right':
         case 'center':
         case 'inline':
         case 'left':
             $layout_class = 'phabricator-remarkup-embed-layout-' . $options['layout'];
             break;
         default:
             $layout_class = 'phabricator-remarkup-embed-layout-left';
             break;
     }
     if ($options['float']) {
         switch ($options['layout']) {
             case 'center':
             case 'inline':
                 break;
             case 'right':
                 $layout_class .= ' phabricator-remarkup-embed-float-right';
                 break;
             case 'left':
             default:
                 $layout_class .= ' phabricator-remarkup-embed-float-left';
                 break;
         }
     }
     return phutil_tag($options['layout'] == 'inline' ? 'span' : 'div', array('class' => $layout_class), $embed);
 }
コード例 #3
0
 private function buildPropertyViews(PHUIObjectBoxView $box, PhabricatorFile $file)
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $tab_group = id(new PHUITabGroupView());
     $box->addTabGroup($tab_group);
     $properties = id(new PHUIPropertyListView());
     $tab_group->addTab(id(new PHUITabView())->setName(pht('Details'))->setKey('details')->appendChild($properties));
     if ($file->getAuthorPHID()) {
         $properties->addProperty(pht('Author'), $viewer->renderHandle($file->getAuthorPHID()));
     }
     $properties->addProperty(pht('Created'), phabricator_datetime($file->getDateCreated(), $viewer));
     $finfo = id(new PHUIPropertyListView());
     $tab_group->addTab(id(new PHUITabView())->setName(pht('File Info'))->setKey('info')->appendChild($finfo));
     $finfo->addProperty(pht('Size'), phutil_format_bytes($file->getByteSize()));
     $finfo->addProperty(pht('Mime Type'), $file->getMimeType());
     $width = $file->getImageWidth();
     if ($width) {
         $finfo->addProperty(pht('Width'), pht('%s px', new PhutilNumber($width)));
     }
     $height = $file->getImageHeight();
     if ($height) {
         $finfo->addProperty(pht('Height'), pht('%s px', new PhutilNumber($height)));
     }
     $is_image = $file->isViewableImage();
     if ($is_image) {
         $image_string = pht('Yes');
         $cache_string = $file->getCanCDN() ? pht('Yes') : pht('No');
     } else {
         $image_string = pht('No');
         $cache_string = pht('Not Applicable');
     }
     $types = array();
     if ($file->isViewableImage()) {
         $types[] = pht('Image');
     }
     if ($file->isVideo()) {
         $types[] = pht('Video');
     }
     if ($file->isAudio()) {
         $types[] = pht('Audio');
     }
     if ($file->getCanCDN()) {
         $types[] = pht('Can CDN');
     }
     $builtin = $file->getBuiltinName();
     if ($builtin !== null) {
         $types[] = pht('Builtin ("%s")', $builtin);
     }
     if ($file->getIsProfileImage()) {
         $types[] = pht('Profile');
     }
     if ($types) {
         $types = implode(', ', $types);
         $finfo->addProperty(pht('Attributes'), $types);
     }
     $storage_properties = new PHUIPropertyListView();
     $tab_group->addTab(id(new PHUITabView())->setName(pht('Storage'))->setKey('storage')->appendChild($storage_properties));
     $storage_properties->addProperty(pht('Engine'), $file->getStorageEngine());
     $engine = $this->loadStorageEngine($file);
     if ($engine && $engine->isChunkEngine()) {
         $format_name = pht('Chunks');
     } else {
         $format_key = $file->getStorageFormat();
         $format = PhabricatorFileStorageFormat::getFormat($format_key);
         if ($format) {
             $format_name = $format->getStorageFormatName();
         } else {
             $format_name = pht('Unknown ("%s")', $format_key);
         }
     }
     $storage_properties->addProperty(pht('Format'), $format_name);
     $storage_properties->addProperty(pht('Handle'), $file->getStorageHandle());
     $phids = $file->getObjectPHIDs();
     if ($phids) {
         $attached = new PHUIPropertyListView();
         $tab_group->addTab(id(new PHUITabView())->setName(pht('Attached'))->setKey('attached')->appendChild($attached));
         $attached->addProperty(pht('Attached To'), $viewer->renderHandleList($phids));
     }
     if ($file->isViewableImage()) {
         $image = phutil_tag('img', array('src' => $file->getViewURI(), 'class' => 'phui-property-list-image'));
         $linked_image = phutil_tag('a', array('href' => $file->getViewURI()), $image);
         $media = id(new PHUIPropertyListView())->addImageContent($linked_image);
         $box->addPropertyList($media);
     } else {
         if ($file->isVideo()) {
             $video = phutil_tag('video', array('controls' => 'controls', 'class' => 'phui-property-list-video'), phutil_tag('source', array('src' => $file->getViewURI(), 'type' => $file->getMimeType())));
             $media = id(new PHUIPropertyListView())->addImageContent($video);
             $box->addPropertyList($media);
         } else {
             if ($file->isAudio()) {
                 $audio = phutil_tag('audio', array('controls' => 'controls', 'class' => 'phui-property-list-audio'), phutil_tag('source', array('src' => $file->getViewURI(), 'type' => $file->getMimeType())));
                 $media = id(new PHUIPropertyListView())->addImageContent($audio);
                 $box->addPropertyList($media);
             }
         }
     }
     $engine = $this->loadStorageEngine($file);
     if ($engine) {
         if ($engine->isChunkEngine()) {
             $chunkinfo = new PHUIPropertyListView();
             $tab_group->addTab(id(new PHUITabView())->setName(pht('Chunks'))->setKey('chunks')->appendChild($chunkinfo));
             $chunks = id(new PhabricatorFileChunkQuery())->setViewer($viewer)->withChunkHandles(array($file->getStorageHandle()))->execute();
             $chunks = msort($chunks, 'getByteStart');
             $rows = array();
             $completed = array();
             foreach ($chunks as $chunk) {
                 $is_complete = $chunk->getDataFilePHID();
                 $rows[] = array($chunk->getByteStart(), $chunk->getByteEnd(), $is_complete ? pht('Yes') : pht('No'));
                 if ($is_complete) {
                     $completed[] = $chunk;
                 }
             }
             $table = id(new AphrontTableView($rows))->setHeaders(array(pht('Offset'), pht('End'), pht('Complete')))->setColumnClasses(array('', '', 'wide'));
             $chunkinfo->addProperty(pht('Total Chunks'), count($chunks));
             $chunkinfo->addProperty(pht('Completed Chunks'), count($completed));
             $chunkinfo->addRawContent($table);
         }
     }
 }
コード例 #4
0
 private function buildPropertyViews(PHUIObjectBoxView $box, PhabricatorFile $file, PhabricatorActionListView $actions)
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $properties = id(new PHUIPropertyListView());
     $properties->setActionList($actions);
     $box->addPropertyList($properties, pht('Details'));
     if ($file->getAuthorPHID()) {
         $properties->addProperty(pht('Author'), $viewer->renderHandle($file->getAuthorPHID()));
     }
     $properties->addProperty(pht('Created'), phabricator_datetime($file->getDateCreated(), $viewer));
     $finfo = id(new PHUIPropertyListView());
     $box->addPropertyList($finfo, pht('File Info'));
     $finfo->addProperty(pht('Size'), phutil_format_bytes($file->getByteSize()));
     $finfo->addProperty(pht('Mime Type'), $file->getMimeType());
     $width = $file->getImageWidth();
     if ($width) {
         $finfo->addProperty(pht('Width'), pht('%s px', new PhutilNumber($width)));
     }
     $height = $file->getImageHeight();
     if ($height) {
         $finfo->addProperty(pht('Height'), pht('%s px', new PhutilNumber($height)));
     }
     $is_image = $file->isViewableImage();
     if ($is_image) {
         $image_string = pht('Yes');
         $cache_string = $file->getCanCDN() ? pht('Yes') : pht('No');
     } else {
         $image_string = pht('No');
         $cache_string = pht('Not Applicable');
     }
     $finfo->addProperty(pht('Viewable Image'), $image_string);
     $finfo->addProperty(pht('Cacheable'), $cache_string);
     $builtin = $file->getBuiltinName();
     if ($builtin === null) {
         $builtin_string = pht('No');
     } else {
         $builtin_string = $builtin;
     }
     $finfo->addProperty(pht('Builtin'), $builtin_string);
     $is_profile = $file->getIsProfileImage() ? pht('Yes') : pht('No');
     $finfo->addProperty(pht('Profile'), $is_profile);
     $storage_properties = new PHUIPropertyListView();
     $box->addPropertyList($storage_properties, pht('Storage'));
     $storage_properties->addProperty(pht('Engine'), $file->getStorageEngine());
     $storage_properties->addProperty(pht('Format'), $file->getStorageFormat());
     $storage_properties->addProperty(pht('Handle'), $file->getStorageHandle());
     $phids = $file->getObjectPHIDs();
     if ($phids) {
         $attached = new PHUIPropertyListView();
         $box->addPropertyList($attached, pht('Attached'));
         $attached->addProperty(pht('Attached To'), $viewer->renderHandleList($phids));
     }
     if ($file->isViewableImage()) {
         $image = phutil_tag('img', array('src' => $file->getViewURI(), 'class' => 'phui-property-list-image'));
         $linked_image = phutil_tag('a', array('href' => $file->getViewURI()), $image);
         $media = id(new PHUIPropertyListView())->addImageContent($linked_image);
         $box->addPropertyList($media);
     } else {
         if ($file->isAudio()) {
             $audio = phutil_tag('audio', array('controls' => 'controls', 'class' => 'phui-property-list-audio'), phutil_tag('source', array('src' => $file->getViewURI(), 'type' => $file->getMimeType())));
             $media = id(new PHUIPropertyListView())->addImageContent($audio);
             $box->addPropertyList($media);
         }
     }
     $engine = null;
     try {
         $engine = $file->instantiateStorageEngine();
     } catch (Exception $ex) {
         // Don't bother raising this anywhere for now.
     }
     if ($engine) {
         if ($engine->isChunkEngine()) {
             $chunkinfo = new PHUIPropertyListView();
             $box->addPropertyList($chunkinfo, pht('Chunks'));
             $chunks = id(new PhabricatorFileChunkQuery())->setViewer($viewer)->withChunkHandles(array($file->getStorageHandle()))->execute();
             $chunks = msort($chunks, 'getByteStart');
             $rows = array();
             $completed = array();
             foreach ($chunks as $chunk) {
                 $is_complete = $chunk->getDataFilePHID();
                 $rows[] = array($chunk->getByteStart(), $chunk->getByteEnd(), $is_complete ? pht('Yes') : pht('No'));
                 if ($is_complete) {
                     $completed[] = $chunk;
                 }
             }
             $table = id(new AphrontTableView($rows))->setHeaders(array(pht('Offset'), pht('End'), pht('Complete')))->setColumnClasses(array('', '', 'wide'));
             $chunkinfo->addProperty(pht('Total Chunks'), count($chunks));
             $chunkinfo->addProperty(pht('Completed Chunks'), count($completed));
             $chunkinfo->addRawContent($table);
         }
     }
 }
コード例 #5
0
 private function buildPropertyViews(PHUIObjectBoxView $box, PhabricatorFile $file, PhabricatorActionListView $actions)
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $properties = id(new PHUIPropertyListView());
     $properties->setActionList($actions);
     $box->addPropertyList($properties, pht('Details'));
     if ($file->getAuthorPHID()) {
         $properties->addProperty(pht('Author'), $this->getHandle($file->getAuthorPHID())->renderLink());
     }
     $properties->addProperty(pht('Created'), phabricator_datetime($file->getDateCreated(), $user));
     $finfo = id(new PHUIPropertyListView());
     $box->addPropertyList($finfo, pht('File Info'));
     $finfo->addProperty(pht('Size'), phutil_format_bytes($file->getByteSize()));
     $finfo->addProperty(pht('Mime Type'), $file->getMimeType());
     $width = $file->getImageWidth();
     if ($width) {
         $finfo->addProperty(pht('Width'), pht('%s px', new PhutilNumber($width)));
     }
     $height = $file->getImageHeight();
     if ($height) {
         $finfo->addProperty(pht('Height'), pht('%s px', new PhutilNumber($height)));
     }
     $is_image = $file->isViewableImage();
     if ($is_image) {
         $image_string = pht('Yes');
         $cache_string = $file->getCanCDN() ? pht('Yes') : pht('No');
     } else {
         $image_string = pht('No');
         $cache_string = pht('Not Applicable');
     }
     $finfo->addProperty(pht('Viewable Image'), $image_string);
     $finfo->addProperty(pht('Cacheable'), $cache_string);
     $storage_properties = new PHUIPropertyListView();
     $box->addPropertyList($storage_properties, pht('Storage'));
     $storage_properties->addProperty(pht('Engine'), $file->getStorageEngine());
     $storage_properties->addProperty(pht('Format'), $file->getStorageFormat());
     $storage_properties->addProperty(pht('Handle'), $file->getStorageHandle());
     $phids = $file->getObjectPHIDs();
     if ($phids) {
         $attached = new PHUIPropertyListView();
         $box->addPropertyList($attached, pht('Attached'));
         $attached->addProperty(pht('Attached To'), $this->renderHandlesForPHIDs($phids));
     }
     if ($file->isViewableImage()) {
         $image = phutil_tag('img', array('src' => $file->getViewURI(), 'class' => 'phui-property-list-image'));
         $linked_image = phutil_tag('a', array('href' => $file->getViewURI()), $image);
         $media = id(new PHUIPropertyListView())->addImageContent($linked_image);
         $box->addPropertyList($media);
     } else {
         if ($file->isAudio()) {
             $audio = phutil_tag('audio', array('controls' => 'controls', 'class' => 'phui-property-list-audio'), phutil_tag('source', array('src' => $file->getViewURI(), 'type' => $file->getMimeType())));
             $media = id(new PHUIPropertyListView())->addImageContent($audio);
             $box->addPropertyList($media);
         }
     }
 }