Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2992418
DiffusionRepositoryProfilePictureController.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
6 KB
Referenced Files
None
Subscribers
None
DiffusionRepositoryProfilePictureController.php
View Options
<?php
final
class
DiffusionRepositoryProfilePictureController
extends
DiffusionController
{
public
function
handleRequest
(
AphrontRequest
$request
)
{
$viewer
=
$this
->
getViewer
(
)
;
$id
=
$request
->
getURIData
(
'id'
)
;
$repository
=
id
(
new
PhabricatorRepositoryQuery
(
)
)
->
setViewer
(
$viewer
)
->
withIDs
(
array
(
$id
)
)
->
needProfileImage
(
true
)
->
needURIs
(
true
)
->
requireCapabilities
(
array
(
PhabricatorPolicyCapability
::
CAN_VIEW
,
PhabricatorPolicyCapability
::
CAN_EDIT
,
)
)
->
executeOne
(
)
;
if
(
!
$repository
)
{
return
new
Aphront404Response
(
)
;
}
$supported_formats
=
PhabricatorFile
::
getTransformableImageFormats
(
)
;
if
(
$supported_formats
)
{
$supported_formats_message
=
pht
(
'Supported image formats: %s.'
,
implode
(
', '
,
$supported_formats
)
)
;
}
else
{
$supported_formats_message
=
pht
(
'Server supports no image formats.'
)
;
}
$e_file
=
true
;
$errors
=
array
(
)
;
$done_uri
=
$repository
->
getURI
(
)
;
if
(
$request
->
isFormPost
(
)
)
{
$phid
=
$request
->
getStr
(
'phid'
)
;
$is_default
=
false
;
if
(
$phid
==
PhabricatorPHIDConstants
::
PHID_VOID
)
{
$phid
=
null
;
$is_default
=
true
;
}
else
if
(
$phid
)
{
$file
=
id
(
new
PhabricatorFileQuery
(
)
)
->
setViewer
(
$viewer
)
->
withPHIDs
(
array
(
$phid
)
)
->
executeOne
(
)
;
}
else
{
if
(
$request
->
getFileExists
(
'picture'
)
)
{
$file
=
PhabricatorFile
::
newFromPHPUpload
(
$_FILES
[
'picture'
]
,
array
(
'authorPHID'
=>
$viewer
->
getPHID
(
)
,
'canCDN'
=>
true
,
)
)
;
}
else
{
$e_file
=
pht
(
'Required'
)
;
$errors
[
]
=
pht
(
'You must choose a file when uploading a new profile picture.'
)
;
}
}
if
(
!
$errors
&&
!
$is_default
)
{
if
(
!
$file
->
isTransformableImage
(
)
)
{
$e_file
=
pht
(
'Not Supported'
)
;
$errors
[
]
=
$supported_formats_message
;
}
else
{
$xform
=
PhabricatorFileTransform
::
getTransformByKey
(
PhabricatorFileThumbnailTransform
::
TRANSFORM_PROFILE
)
;
$xformed
=
$xform
->
executeTransform
(
$file
)
;
}
}
if
(
!
$errors
)
{
if
(
$is_default
)
{
$repository
->
setProfileImagePHID
(
null
)
;
}
else
{
$repository
->
setProfileImagePHID
(
$xformed
->
getPHID
(
)
)
;
$xformed
->
attachToObject
(
$repository
->
getPHID
(
)
)
;
}
$repository
->
save
(
)
;
return
id
(
new
AphrontRedirectResponse
(
)
)
->
setURI
(
$done_uri
)
;
}
}
$title
=
pht
(
'Edit Picture'
)
;
$form
=
id
(
new
PHUIFormLayoutView
(
)
)
->
setUser
(
$viewer
)
;
$default_image
=
PhabricatorFile
::
loadBuiltin
(
$viewer
,
'repo/code.png'
)
;
$images
=
array
(
)
;
$current
=
$repository
->
getProfileImagePHID
(
)
;
$has_current
=
false
;
if
(
$current
)
{
$files
=
id
(
new
PhabricatorFileQuery
(
)
)
->
setViewer
(
$viewer
)
->
withPHIDs
(
array
(
$current
)
)
->
execute
(
)
;
if
(
$files
)
{
$file
=
head
(
$files
)
;
if
(
$file
->
isTransformableImage
(
)
)
{
$has_current
=
true
;
$images
[
$current
]
=
array
(
'uri'
=>
$file
->
getBestURI
(
)
,
'tip'
=>
pht
(
'Current Picture'
)
,
)
;
}
}
}
$builtins
=
array
(
'repo/repo-git.png'
,
'repo/repo-svn.png'
,
'repo/repo-hg.png'
,
'repo/building.png'
,
'repo/cloud.png'
,
'repo/commit.png'
,
'repo/database.png'
,
'repo/desktop.png'
,
'repo/gears.png'
,
'repo/globe.png'
,
'repo/locked.png'
,
'repo/microchip.png'
,
'repo/mobile.png'
,
'repo/repo.png'
,
'repo/servers.png'
,
)
;
foreach
(
$builtins
as
$builtin
)
{
$file
=
PhabricatorFile
::
loadBuiltin
(
$viewer
,
$builtin
)
;
$images
[
$file
->
getPHID
(
)
]
=
array
(
'uri'
=>
$file
->
getBestURI
(
)
,
'tip'
=>
pht
(
'Builtin Image'
)
,
)
;
}
$images
[
PhabricatorPHIDConstants
::
PHID_VOID
]
=
array
(
'uri'
=>
$default_image
->
getBestURI
(
)
,
'tip'
=>
pht
(
'Default Picture'
)
,
)
;
require_celerity_resource
(
'people-profile-css'
)
;
Javelin
::
initBehavior
(
'phabricator-tooltips'
,
array
(
)
)
;
$buttons
=
array
(
)
;
foreach
(
$images
as
$phid
=>
$spec
)
{
$style
=
null
;
if
(
isset
(
$spec
[
'style'
]
)
)
{
$style
=
$spec
[
'style'
]
;
}
$button
=
javelin_tag
(
'button'
,
array
(
'class'
=>
'button-grey profile-image-button'
,
'sigil'
=>
'has-tooltip'
,
'meta'
=>
array
(
'tip'
=>
$spec
[
'tip'
]
,
'size'
=>
300
,
)
,
)
,
phutil_tag
(
'img'
,
array
(
'height'
=>
50
,
'width'
=>
50
,
'src'
=>
$spec
[
'uri'
]
,
)
)
)
;
$button
=
array
(
phutil_tag
(
'input'
,
array
(
'type'
=>
'hidden'
,
'name'
=>
'phid'
,
'value'
=>
$phid
,
)
)
,
$button
,
)
;
$button
=
phabricator_form
(
$viewer
,
array
(
'class'
=>
'profile-image-form'
,
'method'
=>
'POST'
,
)
,
$button
)
;
$buttons
[
]
=
$button
;
}
if
(
$has_current
)
{
$form
->
appendChild
(
id
(
new
AphrontFormMarkupControl
(
)
)
->
setLabel
(
pht
(
'Current Picture'
)
)
->
setValue
(
array_shift
(
$buttons
)
)
)
;
}
$form
->
appendChild
(
id
(
new
AphrontFormMarkupControl
(
)
)
->
setLabel
(
pht
(
'Use Picture'
)
)
->
setValue
(
$buttons
)
)
;
$form_box
=
id
(
new
PHUIObjectBoxView
(
)
)
->
setHeaderText
(
$title
)
->
setFormErrors
(
$errors
)
->
setBackground
(
PHUIObjectBoxView
::
BLUE_PROPERTY
)
->
setForm
(
$form
)
;
$upload_form
=
id
(
new
AphrontFormView
(
)
)
->
setUser
(
$viewer
)
->
setEncType
(
'multipart/form-data'
)
->
appendChild
(
id
(
new
AphrontFormFileControl
(
)
)
->
setName
(
'picture'
)
->
setLabel
(
pht
(
'Upload Picture'
)
)
->
setError
(
$e_file
)
->
setCaption
(
$supported_formats_message
)
)
->
appendChild
(
id
(
new
AphrontFormSubmitControl
(
)
)
->
addCancelButton
(
$done_uri
)
->
setValue
(
pht
(
'Upload Picture'
)
)
)
;
$header
=
id
(
new
PHUIHeaderView
(
)
)
->
setHeader
(
pht
(
'Edit Repository Picture'
)
)
->
setHeaderIcon
(
'fa-camera-retro'
)
;
$crumbs
=
$this
->
buildApplicationCrumbs
(
)
;
$crumbs
->
addTextCrumb
(
$repository
->
getName
(
)
,
$repository
->
getURI
(
)
)
;
$crumbs
->
addTextCrumb
(
pht
(
'Edit Picture'
)
)
;
$crumbs
->
setBorder
(
true
)
;
$upload_box
=
id
(
new
PHUIObjectBoxView
(
)
)
->
setHeaderText
(
pht
(
'Upload New Picture'
)
)
->
setBackground
(
PHUIObjectBoxView
::
BLUE_PROPERTY
)
->
setForm
(
$upload_form
)
;
$view
=
id
(
new
PHUITwoColumnView
(
)
)
->
setHeader
(
$header
)
->
setFooter
(
array
(
$form_box
,
$upload_box
,
)
)
;
return
$this
->
newPage
(
)
->
setTitle
(
$title
)
->
setCrumbs
(
$crumbs
)
->
appendChild
(
$view
)
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Feb 23, 09:30 (1 d, 14 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1181244
Default Alt Text
DiffusionRepositoryProfilePictureController.php (6 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment