Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93877223
PhabricatorRemarkupRuleImageMacro.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Dec 2, 05:07
Size
1 KB
Mime Type
text/x-php
Expires
Wed, Dec 4, 05:07 (2 d)
Engine
blob
Format
Raw Data
Handle
22718140
Attached To
rPH Phabricator
PhabricatorRemarkupRuleImageMacro.php
View Options
<?php
/**
* @group markup
*/
final
class
PhabricatorRemarkupRuleImageMacro
extends
PhutilRemarkupRule
{
private
$images
;
public
function
apply
(
$text
)
{
return
$this
->
replaceHTML
(
'@^([a-zA-Z0-9:_
\-
]+)$@m'
,
array
(
$this
,
'markupImageMacro'
),
$text
);
}
public
function
markupImageMacro
(
$matches
)
{
if
(
$this
->
images
===
null
)
{
$this
->
images
=
array
();
$rows
=
id
(
new
PhabricatorFileImageMacro
())->
loadAllWhere
(
'isDisabled = 0'
);
foreach
(
$rows
as
$row
)
{
$this
->
images
[
$row
->
getName
()]
=
$row
->
getFilePHID
();
}
}
$name
=
(
string
)
$matches
[
1
];
if
(
array_key_exists
(
$name
,
$this
->
images
))
{
$phid
=
$this
->
images
[
$name
];
$file
=
id
(
new
PhabricatorFile
())->
loadOneWhere
(
'phid = %s'
,
$phid
);
$style
=
null
;
$src_uri
=
null
;
if
(
$file
)
{
$src_uri
=
$file
->
getBestURI
();
$file_data
=
$file
->
getMetadata
();
$height
=
idx
(
$file_data
,
PhabricatorFile
::
METADATA_IMAGE_HEIGHT
);
$width
=
idx
(
$file_data
,
PhabricatorFile
::
METADATA_IMAGE_WIDTH
);
if
(
$height
&&
$width
)
{
$style
=
sprintf
(
'height: %dpx; width: %dpx;'
,
$height
,
$width
);
}
}
$img
=
phutil_tag
(
'img'
,
array
(
'src'
=>
$src_uri
,
'alt'
=>
$matches
[
1
],
'title'
=>
$matches
[
1
],
'style'
=>
$style
,
));
return
$this
->
getEngine
()->
storeText
(
$img
);
}
else
{
return
$matches
[
1
];
}
}
}
Event Timeline
Log In to Comment