@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PasteEmbedView extends AphrontView {
4
5 private $paste;
6 private $handle;
7 private $highlights = array();
8 private $lines = 24;
9
10 public function setPaste(PhabricatorPaste $paste) {
11 $this->paste = $paste;
12 return $this;
13 }
14
15 public function setHandle(PhabricatorObjectHandle $handle) {
16 $this->handle = $handle;
17 return $this;
18 }
19
20 public function setHighlights(array $highlights) {
21 $this->highlights = $highlights;
22 return $this;
23 }
24
25 public function setLines($lines) {
26 $this->lines = $lines;
27 return $this;
28 }
29
30 public function render() {
31 if (!$this->paste) {
32 throw new PhutilInvalidStateException('setPaste');
33 }
34
35 $lines = phutil_split_lines($this->paste->getContent());
36 require_celerity_resource('paste-css');
37
38 $link = phutil_tag(
39 'a',
40 array(
41 'href' => '/P'.$this->paste->getID(),
42 ),
43 $this->handle->getFullName());
44
45 $head = phutil_tag(
46 'div',
47 array(
48 'class' => 'paste-embed-head',
49 ),
50 $link);
51
52 $body_attributes = array('class' => 'paste-embed-body');
53 if ($this->lines != null) {
54 $body_attributes['style'] = 'max-height: '.$this->lines * (1.15).'em;';
55 }
56
57 $body = phutil_tag(
58 'div',
59 $body_attributes,
60 id(new PhabricatorSourceCodeView())
61 ->setLines($lines)
62 ->setHighlights($this->highlights)
63 ->disableHighlightOnClick());
64
65 return phutil_tag(
66 'div',
67 array('class' => 'paste-embed'),
68 array($head, $body));
69
70 }
71}