Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F103317443
PhabricatorPhurlLinkRemarkupRule.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
Sat, Mar 1, 03:19
Size
1 KB
Mime Type
text/x-php
Expires
Mon, Mar 3, 03:19 (2 d)
Engine
blob
Format
Raw Data
Handle
24540468
Attached To
rPH Phabricator
PhabricatorPhurlLinkRemarkupRule.php
View Options
<?php
final
class
PhabricatorPhurlLinkRemarkupRule
extends
PhutilRemarkupRule
{
public
function
getPriority
()
{
return
200.0
;
}
public
function
apply
(
$text
)
{
// `((U123))` remarkup link to `/u/123`
// `((alias))` remarkup link to `/u/alias`
return
preg_replace_callback
(
'/
\(\(
([^ )]+)
\)\)
/'
,
array
(
$this
,
'markupLink'
),
$text
);
}
public
function
markupLink
(
array
$matches
)
{
$engine
=
$this
->
getEngine
();
$viewer
=
$engine
->
getConfig
(
'viewer'
);
$text_mode
=
$engine
->
isTextMode
();
if
(!
$this
->
isFlatText
(
$matches
[
0
]))
{
return
$matches
[
0
];
}
$ref
=
$matches
[
1
];
if
(
ctype_digit
(
$ref
))
{
$phurls
=
id
(
new
PhabricatorPhurlURLQuery
())
->
setViewer
(
$viewer
)
->
withIDs
(
array
(
$ref
))
->
execute
();
}
else
{
$phurls
=
id
(
new
PhabricatorPhurlURLQuery
())
->
setViewer
(
$viewer
)
->
withAliases
(
array
(
$ref
))
->
execute
();
}
$phurl
=
head
(
$phurls
);
if
(
$phurl
)
{
if
(
$text_mode
)
{
return
$phurl
->
getName
().
' <'
.
$phurl
->
getLongURL
().
'>'
;
}
$link
=
phutil_tag
(
'a'
,
array
(
'href'
=>
$phurl
->
getLongURL
(),
'target'
=>
'_blank'
,
),
$phurl
->
getName
());
return
$this
->
getEngine
()->
storeText
(
$link
);
}
else
{
return
$matches
[
0
];
}
}
}
Event Timeline
Log In to Comment