Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98949254
PhutilRemarkupRuleDocumentLink.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
Fri, Jan 17, 23:41
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Jan 19, 23:41 (2 d)
Engine
blob
Format
Raw Data
Handle
23675307
Attached To
rPHU libphutil
PhutilRemarkupRuleDocumentLink.php
View Options
<?php
/**
* @group markup
*/
final
class
PhutilRemarkupRuleDocumentLink
extends
PhutilRemarkupRule
{
public
function
apply
(
$text
)
{
$text
=
preg_replace_callback
(
'@
\B\\
[
\\
[([^|
\\
]]+)(?:
\\
|([^
\\
]]+))?
\\
]
\\
]
\B
@U'
,
array
(
$this
,
'markupDocumentLink'
),
$text
);
return
$text
;
}
protected
function
renderHyperlink
(
$link
,
$name
)
{
return
phutil_render_tag
(
'a'
,
array
(
'href'
=>
$link
,
'target'
=>
'_blank'
,
),
phutil_escape_html
(
$name
));
}
public
function
markupDocumentLink
(
$matches
)
{
$uri
=
trim
(
$matches
[
1
]);
$name
=
trim
(
idx
(
$matches
,
2
,
$uri
));
// If whatever is being linked to begins with "/" or has "://", treat it
// as a URI instead of a wiki page.
$is_uri
=
preg_match
(
'@(^/)|(://)@'
,
$uri
);
if
(
$is_uri
&&
strncmp
(
'/'
,
$uri
,
1
))
{
$protocols
=
$this
->
getEngine
()->
getConfig
(
'uri.allowed-protocols'
,
array
());
$protocol
=
id
(
new
PhutilURI
(
$uri
))->
getProtocol
();
if
(!
idx
(
$protocols
,
$protocol
))
{
// Don't treat this as a URI if it's not an allowed protocol.
$is_uri
=
false
;
}
}
if
(!
$is_uri
)
{
return
$matches
[
0
];
}
return
$this
->
getEngine
()->
storeText
(
$this
->
renderHyperlink
(
$uri
,
$name
));
}
}
Event Timeline
Log In to Comment