Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/storage/PhabricatorFile.php
Show All 35 Lines | final class PhabricatorFile extends PhabricatorFileDAO | ||||
const METADATA_IMAGE_HEIGHT = 'height'; | const METADATA_IMAGE_HEIGHT = 'height'; | ||||
const METADATA_CAN_CDN = 'canCDN'; | const METADATA_CAN_CDN = 'canCDN'; | ||||
const METADATA_BUILTIN = 'builtin'; | const METADATA_BUILTIN = 'builtin'; | ||||
const METADATA_PARTIAL = 'partial'; | const METADATA_PARTIAL = 'partial'; | ||||
const METADATA_PROFILE = 'profile'; | const METADATA_PROFILE = 'profile'; | ||||
const METADATA_STORAGE = 'storage'; | const METADATA_STORAGE = 'storage'; | ||||
const METADATA_INTEGRITY = 'integrity'; | const METADATA_INTEGRITY = 'integrity'; | ||||
const METADATA_CHUNK = 'chunk'; | const METADATA_CHUNK = 'chunk'; | ||||
const METADATA_ALT_TEXT = 'alt'; | |||||
const STATUS_ACTIVE = 'active'; | const STATUS_ACTIVE = 'active'; | ||||
const STATUS_DELETED = 'deleted'; | const STATUS_DELETED = 'deleted'; | ||||
protected $name; | protected $name; | ||||
protected $mimeType; | protected $mimeType; | ||||
protected $byteSize; | protected $byteSize; | ||||
protected $authorPHID; | protected $authorPHID; | ||||
▲ Show 20 Lines • Show All 1,217 Lines • ▼ Show 20 Lines | |||||
public function getImageWidth() { | public function getImageWidth() { | ||||
if (!$this->isViewableImage()) { | if (!$this->isViewableImage()) { | ||||
return null; | return null; | ||||
} | } | ||||
return idx($this->metadata, self::METADATA_IMAGE_WIDTH); | return idx($this->metadata, self::METADATA_IMAGE_WIDTH); | ||||
} | } | ||||
public function getAltText() { | |||||
$alt = $this->getCustomAltText(); | |||||
if (strlen($alt)) { | |||||
return $alt; | |||||
} | |||||
return $this->getDefaultAltText(); | |||||
} | |||||
public function getCustomAltText() { | |||||
return idx($this->metadata, self::METADATA_ALT_TEXT); | |||||
} | |||||
public function setCustomAltText($value) { | |||||
$value = phutil_string_cast($value); | |||||
if (!strlen($value)) { | |||||
$value = null; | |||||
} | |||||
if ($value === null) { | |||||
unset($this->metadata[self::METADATA_ALT_TEXT]); | |||||
} else { | |||||
$this->metadata[self::METADATA_ALT_TEXT] = $value; | |||||
} | |||||
return $this; | |||||
} | |||||
public function getDefaultAltText() { | |||||
$parts = array(); | |||||
$name = $this->getName(); | |||||
if (strlen($name)) { | |||||
$parts[] = $name; | |||||
} | |||||
$stats = array(); | |||||
$image_x = $this->getImageHeight(); | |||||
$image_y = $this->getImageWidth(); | |||||
if ($image_x && $image_y) { | |||||
$stats[] = pht( | |||||
"%d\xC3\x97%d px", | |||||
new PhutilNumber($image_x), | |||||
new PhutilNumber($image_y)); | |||||
} | |||||
$bytes = $this->getByteSize(); | |||||
if ($bytes) { | |||||
$stats[] = phutil_format_bytes($bytes); | |||||
} | |||||
if ($stats) { | |||||
$parts[] = pht('(%s)', implode(', ', $stats)); | |||||
} | |||||
if (!$parts) { | |||||
return null; | |||||
} | |||||
return implode(' ', $parts); | |||||
} | |||||
public function getCanCDN() { | public function getCanCDN() { | ||||
if (!$this->isViewableImage()) { | if (!$this->isViewableImage()) { | ||||
return false; | return false; | ||||
} | } | ||||
return idx($this->metadata, self::METADATA_CAN_CDN); | return idx($this->metadata, self::METADATA_CAN_CDN); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 386 Lines • ▼ Show 20 Lines | /* -( PhabricatorConduitResultInterface )---------------------------------- */ | ||||
} | } | ||||
public function getFieldValuesForConduit() { | public function getFieldValuesForConduit() { | ||||
return array( | return array( | ||||
'name' => $this->getName(), | 'name' => $this->getName(), | ||||
'uri' => PhabricatorEnv::getURI($this->getURI()), | 'uri' => PhabricatorEnv::getURI($this->getURI()), | ||||
'dataURI' => $this->getCDNURI('data'), | 'dataURI' => $this->getCDNURI('data'), | ||||
'size' => (int)$this->getByteSize(), | 'size' => (int)$this->getByteSize(), | ||||
'alt' => array( | |||||
'custom' => $this->getCustomAltText(), | |||||
'default' => $this->getDefaultAltText(), | |||||
), | |||||
); | ); | ||||
} | } | ||||
public function getConduitSearchAttachments() { | public function getConduitSearchAttachments() { | ||||
return array(); | return array(); | ||||
} | } | ||||
/* -( PhabricatorNgramInterface )------------------------------------------ */ | /* -( PhabricatorNgramInterface )------------------------------------------ */ | ||||
Show All 10 Lines |