Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120150480
PhabricatorSourceCodeView.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
Wed, Jul 2, 07:21
Size
3 KB
Mime Type
text/x-php
Expires
Fri, Jul 4, 07:21 (2 d)
Engine
blob
Format
Raw Data
Handle
27147951
Attached To
rPH Phabricator
PhabricatorSourceCodeView.php
View Options
<?php
final
class
PhabricatorSourceCodeView
extends
AphrontView
{
private
$lines
;
private
$limit
;
private
$uri
;
private
$highlights
=
array
();
private
$canClickHighlight
=
true
;
public
function
setLimit
(
$limit
)
{
$this
->
limit
=
$limit
;
return
$this
;
}
public
function
setLines
(
array
$lines
)
{
$this
->
lines
=
$lines
;
return
$this
;
}
public
function
setURI
(
PhutilURI
$uri
)
{
$this
->
uri
=
$uri
;
return
$this
;
}
public
function
setHighlights
(
array
$array
)
{
$this
->
highlights
=
array_fuse
(
$array
);
return
$this
;
}
public
function
disableHighlightOnClick
()
{
$this
->
canClickHighlight
=
false
;
return
$this
;
}
public
function
render
()
{
require_celerity_resource
(
'phabricator-source-code-view-css'
);
require_celerity_resource
(
'syntax-highlighting-css'
);
Javelin
::
initBehavior
(
'phabricator-oncopy'
,
array
());
if
(
$this
->
canClickHighlight
)
{
Javelin
::
initBehavior
(
'phabricator-line-linker'
);
}
$line_number
=
1
;
$rows
=
array
();
foreach
(
$this
->
lines
as
$line
)
{
$hit_limit
=
$this
->
limit
&&
(
$line_number
==
$this
->
limit
)
&&
(
count
(
$this
->
lines
)
!=
$this
->
limit
);
if
(
$hit_limit
)
{
$content_number
=
''
;
$content_line
=
phutil_tag
(
'span'
,
array
(
'class'
=>
'c'
,
),
pht
(
'...'
));
}
else
{
$content_number
=
$line_number
;
$content_line
=
hsprintf
(
"
\x
E2
\x
80
\x
8B%s"
,
$line
);
}
$row_attributes
=
array
();
if
(
isset
(
$this
->
highlights
[
$line_number
]))
{
$row_attributes
[
'class'
]
=
'phabricator-source-highlight'
;
}
if
(
$this
->
canClickHighlight
)
{
$line_uri
=
$this
->
uri
.
"$"
.
$line_number
;
$line_href
=
(
string
)
new
PhutilURI
(
$line_uri
);
$tag_number
=
javelin_tag
(
'a'
,
array
(
'href'
=>
$line_href
),
$line_number
);
}
else
{
$tag_number
=
javelin_tag
(
'span'
,
array
(),
$line_number
);
}
$rows
[]
=
phutil_tag
(
'tr'
,
$row_attributes
,
array
(
javelin_tag
(
'th'
,
array
(
'class'
=>
'phabricator-source-line'
,
'sigil'
=>
'phabricator-source-line'
),
$tag_number
),
phutil_tag
(
'td'
,
array
(
'class'
=>
'phabricator-source-code'
),
$content_line
)));
if
(
$hit_limit
)
{
break
;
}
$line_number
++;
}
$classes
=
array
();
$classes
[]
=
'phabricator-source-code-view'
;
$classes
[]
=
'remarkup-code'
;
$classes
[]
=
'PhabricatorMonospaced'
;
return
phutil_tag
(
'div'
,
array
(
'class'
=>
'phabricator-source-code-container'
,
),
javelin_tag
(
'table'
,
array
(
'class'
=>
implode
(
' '
,
$classes
),
'sigil'
=>
'phabricator-source'
),
phutil_implode_html
(
''
,
$rows
)));
}
}
Event Timeline
Log In to Comment