Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F537891
DiffusionPatternSearchView.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
DiffusionPatternSearchView.php
View Options
<?php
final
class
DiffusionPatternSearchView
extends
DiffusionView
{
private
$path
;
private
$matches
;
private
$pattern
;
public
function
setPath
(
$path
)
{
$this
->
path
=
$path
;
return
$this
;
}
public
function
setMatches
(
array
$matches
)
{
$this
->
matches
=
$matches
;
return
$this
;
}
public
function
setPattern
(
$pattern
)
{
$this
->
pattern
=
$pattern
;
return
$this
;
}
public
function
render
()
{
$drequest
=
$this
->
getDiffusionRequest
();
$path
=
$this
->
path
;
$pattern
=
$this
->
pattern
;
$rows
=
array
();
foreach
(
$this
->
matches
as
$result
)
{
list
(
$line
,
$string
)
=
$result
;
$matches
=
null
;
$count
=
@
preg_match_all
(
'('
.
$pattern
.
')u'
,
$string
,
$matches
,
PREG_OFFSET_CAPTURE
);
if
(!
$count
)
{
$output
=
ltrim
(
$string
);
}
else
{
$output
=
array
();
$cursor
=
0
;
$length
=
strlen
(
$string
);
foreach
(
$matches
[
0
]
as
$match
)
{
$offset
=
$match
[
1
];
if
(
$cursor
!=
$offset
)
{
$output
[]
=
array
(
'text'
=>
substr
(
$string
,
$cursor
,
$offset
),
'highlight'
=>
false
,
);
}
$output
[]
=
array
(
'text'
=>
$match
[
0
],
'highlight'
=>
true
,
);
$cursor
=
$offset
+
strlen
(
$match
[
0
]);
}
if
(
$cursor
!=
$length
)
{
$output
[]
=
array
(
'text'
=>
substr
(
$string
,
$cursor
),
'highlight'
=>
false
,
);
}
if
(
$output
)
{
$output
[
0
][
'text'
]
=
ltrim
(
$output
[
0
][
'text'
]);
}
foreach
(
$output
as
$key
=>
$segment
)
{
if
(
$segment
[
'highlight'
])
{
$output
[
$key
]
=
phutil_tag
(
'strong'
,
array
(),
$segment
[
'text'
]);
}
else
{
$output
[
$key
]
=
$segment
[
'text'
];
}
}
}
$string
=
phutil_tag
(
'pre'
,
array
(
'class'
=>
'PhabricatorMonospaced phui-source-fragment'
),
$output
);
$href
=
$drequest
->
generateURI
(
array
(
'action'
=>
'browse'
,
'path'
=>
$path
,
'line'
=>
$line
,
));
$rows
[]
=
array
(
phutil_tag
(
'a'
,
array
(
'href'
=>
$href
),
$line
),
$string
,
);
}
$path_title
=
Filesystem
::
readablePath
(
$this
->
path
,
$drequest
->
getPath
());
$href
=
$drequest
->
generateURI
(
array
(
'action'
=>
'browse'
,
'path'
=>
$path_title
,
));
$title
=
phutil_tag
(
'a'
,
array
(
'href'
=>
$href
),
$path_title
);
$table
=
id
(
new
AphrontTableView
(
$rows
))
->
setClassName
(
'remarkup-code'
)
->
setHeaders
(
array
(
pht
(
'Line'
),
pht
(
'String'
)))
->
setColumnClasses
(
array
(
'n'
,
'wide'
));
$header
=
id
(
new
PHUIHeaderView
())
->
setHeader
(
$title
);
$box
=
id
(
new
PHUIObjectBoxView
())
->
setHeader
(
$header
)
->
setBackground
(
PHUIObjectBoxView
::
BLUE_PROPERTY
)
->
setTable
(
$table
);
return
$box
->
render
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, May 12, 8:24 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
100078
Default Alt Text
DiffusionPatternSearchView.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment