@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 PholioUploadedImageView extends AphrontView {
4
5 private $image;
6 private $replacesPHID;
7
8 public function setReplacesPHID($replaces_phid) {
9 $this->replacesPHID = $replaces_phid;
10 return $this;
11 }
12
13 public function setImage(PholioImage $image) {
14 $this->image = $image;
15 return $this;
16 }
17
18 public function render() {
19 require_celerity_resource('pholio-edit-css');
20
21 $image = $this->image;
22 $file = $image->getFile();
23 $phid = $file->getPHID();
24 $replaces_phid = $this->replacesPHID;
25
26 $remove = $this->renderRemoveElement();
27
28 $title = id(new AphrontFormTextControl())
29 ->setName('title_'.$phid)
30 ->setValue($image->getName())
31 ->setSigil('image-title')
32 ->setLabel(pht('Title'));
33
34 $description = id(new PhabricatorRemarkupControl())
35 ->setViewer($this->getUser())
36 ->setName('description_'.$phid)
37 ->setValue($image->getDescription())
38 ->setSigil('image-description')
39 ->setLabel(pht('Description'));
40
41 $xform = PhabricatorFileTransform::getTransformByKey(
42 PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD);
43 $thumbnail_uri = $file->getURIForTransform($xform);
44
45 $thumb_img = javelin_tag(
46 'img',
47 array(
48 'class' => 'pholio-thumb-img',
49 'src' => $thumbnail_uri,
50 'sigil' => 'pholio-uploaded-thumb',
51 ));
52
53 $thumb_frame = phutil_tag(
54 'div',
55 array(
56 'class' => 'pholio-thumb-frame',
57 ),
58 $thumb_img);
59
60 $handle = javelin_tag(
61 'div',
62 array(
63 'class' => 'pholio-drag-handle',
64 'sigil' => 'pholio-drag-handle',
65 ));
66
67 $content = hsprintf(
68 '<div class="pholio-thumb-box">
69 <div class="pholio-thumb-title">
70 %s
71 <div class="pholio-thumb-name">%s</div>
72 </div>
73 %s
74 </div>
75 <div class="pholio-image-details">
76 %s
77 %s
78 </div>',
79 $remove,
80 $file->getName(),
81 $thumb_frame,
82 $title,
83 $description);
84
85 $input = phutil_tag(
86 'input',
87 array(
88 'type' => 'hidden',
89 'name' => 'file_phids[]',
90 'value' => $phid,
91 ));
92
93 $replaces_input = phutil_tag(
94 'input',
95 array(
96 'type' => 'hidden',
97 'name' => 'replaces['.$replaces_phid.']',
98 'value' => $phid,
99 ));
100
101 return javelin_tag(
102 'div',
103 array(
104 'class' => 'pholio-uploaded-image',
105 'sigil' => 'pholio-drop-image',
106 'meta' => array(
107 'filePHID' => $file->getPHID(),
108 'replacesPHID' => $replaces_phid,
109 ),
110 ),
111 array(
112 $handle,
113 $content,
114 $input,
115 $replaces_input,
116 ));
117 }
118
119 private function renderRemoveElement() {
120 return javelin_tag(
121 'a',
122 array(
123 'class' => 'button button-grey',
124 'sigil' => 'pholio-drop-remove',
125 ),
126 'X');
127 }
128
129}