Changeset View
Changeset View
Standalone View
Standalone View
src/applications/config/custom/PhabricatorCustomLogoConfigType.php
<?php | <?php | ||||
final class PhabricatorCustomLogoConfigType | final class PhabricatorCustomLogoConfigType | ||||
extends PhabricatorConfigOptionType { | extends PhabricatorConfigOptionType { | ||||
public static function getLogoImagePHID() { | public static function getLogoImagePHID() { | ||||
$logo = PhabricatorEnv::getEnvConfig('ui.logo'); | $logo = PhabricatorEnv::getEnvConfig('ui.logo'); | ||||
return idx($logo, 'logoImagePHID'); | return idx($logo, 'logoImagePHID'); | ||||
} | } | ||||
public static function getLogoWordmark() { | public static function getLogoWordmark() { | ||||
$logo = PhabricatorEnv::getEnvConfig('ui.logo'); | $logo = PhabricatorEnv::getEnvConfig('ui.logo'); | ||||
return idx($logo, 'wordmarkText'); | return idx($logo, 'wordmarkText'); | ||||
} | } | ||||
public static function getLogoURI(PhabricatorUser $viewer) { | |||||
$logo_uri = null; | |||||
$custom_header = self::getLogoImagePHID(); | |||||
if ($custom_header) { | |||||
$cache = PhabricatorCaches::getImmutableCache(); | |||||
$cache_key_logo = 'ui.custom-header.logo-phid.v3.'.$custom_header; | |||||
$logo_uri = $cache->getKey($cache_key_logo); | |||||
if (!$logo_uri) { | |||||
// NOTE: If the file policy has been changed to be restrictive, we'll | |||||
// miss here and just show the default logo. The cache will fill later | |||||
// when someone who can see the file loads the page. This might be a | |||||
// little spooky, see T11982. | |||||
$files = id(new PhabricatorFileQuery()) | |||||
->setViewer($viewer) | |||||
->withPHIDs(array($custom_header)) | |||||
->execute(); | |||||
$file = head($files); | |||||
if ($file) { | |||||
$logo_uri = $file->getViewURI(); | |||||
$cache->setKey($cache_key_logo, $logo_uri); | |||||
} | |||||
} | |||||
} | |||||
if (!$logo_uri) { | |||||
$logo_uri = celerity_get_resource_uri('/rsrc/image/logo/light-eye.png'); | |||||
} | |||||
return $logo_uri; | |||||
} | |||||
public function validateOption(PhabricatorConfigOption $option, $value) { | public function validateOption(PhabricatorConfigOption $option, $value) { | ||||
if (!is_array($value)) { | if (!is_array($value)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Logo configuration is not valid: value must be a dictionary.')); | 'Logo configuration is not valid: value must be a dictionary.')); | ||||
} | } | ||||
PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines |