Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80680074
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, Sep 2, 01:33
Size
1 KB
Mime Type
text/x-php
Expires
Wed, Sep 4, 01:33 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20421970
Attached To
rPH Phabricator
PhabricatorRemarkupRuleImageMacro.php
View Options
<?php
/**
* @group markup
*/
final
class
PhabricatorRemarkupRuleImageMacro
extends
PhutilRemarkupRule
{
private
$images
;
public
function
apply
(
$text
)
{
return
preg_replace_callback
(
'@^([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
();
}
}
if
(
array_key_exists
(
$matches
[
1
],
$this
->
images
))
{
$phid
=
$this
->
images
[
$matches
[
1
]];
$file
=
id
(
new
PhabricatorFile
())->
loadOneWhere
(
'phid = %s'
,
$phid
);
if
(
$file
)
{
$src_uri
=
$file
->
getBestURI
();
}
else
{
$src_uri
=
null
;
}
$img
=
phutil_render_tag
(
'img'
,
array
(
'src'
=>
$src_uri
,
'alt'
=>
$matches
[
1
],
'title'
=>
$matches
[
1
]),
null
);
return
$this
->
getEngine
()->
storeText
(
$img
);
}
else
{
return
$matches
[
1
];
}
}
}
Event Timeline
Log In to Comment