mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-15 11:22:40 +01:00
a22ef4e9b4
Summary: This resolves lots of double escaping. We changed most of `phutil_render_tag(, , $s)` to `phutil_tag(, , $s)` which means that `$s` is now auto-escaped. Also `pht()` auto escapes if it gets `PhutilSafeHTML`. Test Plan: None. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2432 Differential Revision: https://secure.phabricator.com/D4889
82 lines
1.8 KiB
PHP
82 lines
1.8 KiB
PHP
<?php
|
|
|
|
final class PhabricatorSourceCodeView extends AphrontView {
|
|
|
|
private $lines;
|
|
private $limit;
|
|
|
|
public function setLimit($limit) {
|
|
$this->limit = $limit;
|
|
return $this;
|
|
}
|
|
|
|
public function setLines(array $lines) {
|
|
$this->lines = $lines;
|
|
return $this;
|
|
}
|
|
|
|
public function render() {
|
|
require_celerity_resource('phabricator-source-code-view-css');
|
|
require_celerity_resource('syntax-highlighting-css');
|
|
|
|
Javelin::initBehavior('phabricator-oncopy', array());
|
|
|
|
$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 = "\xE2\x80\x8B".$line;
|
|
}
|
|
|
|
// TODO: Provide nice links.
|
|
|
|
$rows[] =
|
|
'<tr>'.
|
|
'<th class="phabricator-source-line">'.
|
|
$content_number.
|
|
'</th>'.
|
|
'<td class="phabricator-source-code">'.
|
|
$content_line.
|
|
'</td>'.
|
|
'</tr>';
|
|
|
|
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',
|
|
),
|
|
phutil_tag(
|
|
'table',
|
|
array(
|
|
'class' => implode(' ', $classes),
|
|
),
|
|
new PhutilSafeHTML(implode('', $rows))));
|
|
}
|
|
|
|
}
|