Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F451290
PhameBlogProfilePictureController.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
PhameBlogProfilePictureController.php
View Options
<?php
final
class
PhameBlogProfilePictureController
extends
PhameBlogController
{
public
function
shouldRequireAdmin
()
{
return
false
;
}
public
function
handleRequest
(
AphrontRequest
$request
)
{
$viewer
=
$request
->
getViewer
();
$id
=
$request
->
getURIData
(
'id'
);
$blog
=
id
(
new
PhameBlogQuery
())
->
setViewer
(
$viewer
)
->
withIDs
(
array
(
$id
))
->
needProfileImage
(
true
)
->
requireCapabilities
(
array
(
PhabricatorPolicyCapability
::
CAN_VIEW
,
PhabricatorPolicyCapability
::
CAN_EDIT
,
))
->
executeOne
();
if
(!
$blog
)
{
return
new
Aphront404Response
();
}
$blog_uri
=
'/phame/blog/manage/'
.
$id
;
$supported_formats
=
PhabricatorFile
::
getTransformableImageFormats
();
$e_file
=
true
;
$errors
=
array
();
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 blog picture.'
);
}
}
if
(!
$errors
&&
!
$is_default
)
{
if
(!
$file
->
isTransformableImage
())
{
$e_file
=
pht
(
'Not Supported'
);
$errors
[]
=
pht
(
'This server only supports these image formats: %s.'
,
implode
(
', '
,
$supported_formats
));
}
else
{
$xform
=
PhabricatorFileTransform
::
getTransformByKey
(
PhabricatorFileThumbnailTransform
::
TRANSFORM_PROFILE
);
$xformed
=
$xform
->
executeTransform
(
$file
);
}
}
if
(!
$errors
)
{
if
(
$is_default
)
{
$blog
->
setProfileImagePHID
(
null
);
}
else
{
$blog
->
setProfileImagePHID
(
$xformed
->
getPHID
());
$xformed
->
attachToObject
(
$blog
->
getPHID
());
}
$blog
->
save
();
return
id
(
new
AphrontRedirectResponse
())->
setURI
(
$blog_uri
);
}
}
$title
=
pht
(
'Edit Blog Picture'
);
$form
=
id
(
new
PHUIFormLayoutView
())
->
setUser
(
$viewer
);
$default_image
=
PhabricatorFile
::
loadBuiltin
(
$viewer
,
'blog.png'
);
$images
=
array
();
$current
=
$blog
->
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'
),
);
}
}
}
$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
)
{
$button
=
javelin_tag
(
'button'
,
array
(
'class'
=>
'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
)
->
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
(
pht
(
'Supported formats: %s'
,
implode
(
', '
,
$supported_formats
))))
->
appendChild
(
id
(
new
AphrontFormSubmitControl
())
->
addCancelButton
(
$blog_uri
)
->
setValue
(
pht
(
'Upload Picture'
)));
$upload_box
=
id
(
new
PHUIObjectBoxView
())
->
setHeaderText
(
pht
(
'Upload New Picture'
))
->
setForm
(
$upload_form
);
$crumbs
=
$this
->
buildApplicationCrumbs
();
$crumbs
->
addTextCrumb
(
pht
(
'Blogs'
),
$this
->
getApplicationURI
(
'blog/'
));
$crumbs
->
addTextCrumb
(
$blog
->
getName
(),
$this
->
getApplicationURI
(
'blog/view/'
.
$id
));
$crumbs
->
addTextCrumb
(
pht
(
'Blog Picture'
));
return
$this
->
newPage
()
->
setTitle
(
$title
)
->
setCrumbs
(
$crumbs
)
->
appendChild
(
array
(
$form_box
,
$upload_box
,
));
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, May 4, 10:09 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68227
Default Alt Text
PhameBlogProfilePictureController.php (5 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment