[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PholioInlineController extends PholioController { 4 5 private $id; 6 7 public function willProcessRequest(array $data) { 8 $this->id = idx($data, 'id'); 9 } 10 11 public function processRequest() { 12 $request = $this->getRequest(); 13 $viewer = $request->getUser(); 14 15 if ($this->id) { 16 $inline = id(new PholioTransactionComment())->load($this->id); 17 18 if (!$inline) { 19 return new Aphront404Response(); 20 } 21 22 if ($inline->getTransactionPHID()) { 23 $mode = 'view'; 24 } else { 25 if ($inline->getAuthorPHID() == $viewer->getPHID()) { 26 $mode = 'edit'; 27 } else { 28 return new Aphront404Response(); 29 } 30 } 31 } else { 32 $mock = id(new PholioMockQuery()) 33 ->setViewer($viewer) 34 ->withIDs(array($request->getInt('mockID'))) 35 ->executeOne(); 36 37 if (!$mock) { 38 return new Aphront404Response(); 39 } 40 41 $inline = id(new PholioTransactionComment()) 42 ->setImageID($request->getInt('imageID')) 43 ->setX($request->getInt('startX')) 44 ->setY($request->getInt('startY')) 45 ->setCommentVersion(1) 46 ->setAuthorPHID($viewer->getPHID()) 47 ->setEditPolicy($viewer->getPHID()) 48 ->setViewPolicy(PhabricatorPolicies::POLICY_PUBLIC) 49 ->setContentSourceFromRequest($request) 50 ->setWidth($request->getInt('endX') - $request->getInt('startX')) 51 ->setHeight($request->getInt('endY') - $request->getInt('startY')); 52 53 $mode = 'new'; 54 } 55 56 $v_content = $inline->getContent(); 57 58 // TODO: Not correct, but we don't always have a mock right now. 59 $mock_uri = '/'; 60 61 if ($mode == 'view') { 62 require_celerity_resource('pholio-inline-comments-css'); 63 $image = id(new PholioImageQuery()) 64 ->setViewer($viewer) 65 ->withIDs(array($inline->getImageID())) 66 ->executeOne(); 67 68 $handles = $this->loadViewerHandles(array($inline->getAuthorPHID())); 69 $author_handle = $handles[$inline->getAuthorPHID()]; 70 71 $file = $image->getFile(); 72 if (!$file->isViewableImage()) { 73 throw new Exception('File is not viewable.'); 74 } 75 76 $image_uri = $file->getBestURI(); 77 78 $thumb = id(new PHUIImageMaskView()) 79 ->addClass('mrl') 80 ->setImage($image_uri) 81 ->setDisplayHeight(200) 82 ->setDisplayWidth(498) 83 ->withMask(true) 84 ->centerViewOnPoint( 85 $inline->getX(), $inline->getY(), 86 $inline->getHeight(), $inline->getWidth()); 87 88 $comment_head = phutil_tag( 89 'div', 90 array( 91 'class' => 'pholio-inline-comment-head', 92 ), 93 $author_handle->renderLink()); 94 95 $comment_body = phutil_tag( 96 'div', 97 array( 98 'class' => 'pholio-inline-comment-body', 99 ), 100 PhabricatorMarkupEngine::renderOneObject( 101 id(new PhabricatorMarkupOneOff()) 102 ->setContent($inline->getContent()), 103 'default', 104 $viewer)); 105 106 return $this->newDialog() 107 ->setTitle(pht('Inline Comment')) 108 ->appendChild($thumb) 109 ->appendChild($comment_head) 110 ->appendChild($comment_body) 111 ->addCancelButton($mock_uri, pht('Close')); 112 } 113 114 if ($request->isFormPost()) { 115 $v_content = $request->getStr('content'); 116 117 if (strlen($v_content)) { 118 $inline->setContent($v_content); 119 $inline->save(); 120 $dictionary = $inline->toDictionary(); 121 } else if ($inline->getID()) { 122 $inline->delete(); 123 $dictionary = array(); 124 } 125 126 return id(new AphrontAjaxResponse())->setContent($dictionary); 127 } 128 129 switch ($mode) { 130 case 'edit': 131 $title = pht('Edit Inline Comment'); 132 $submit_text = pht('Save Draft'); 133 break; 134 case 'new': 135 $title = pht('New Inline Comment'); 136 $submit_text = pht('Save Draft'); 137 break; 138 } 139 140 $form = id(new AphrontFormView()) 141 ->setUser($viewer); 142 143 if ($mode == 'new') { 144 $params = array( 145 'mockID' => $request->getInt('mockID'), 146 'imageID' => $request->getInt('imageID'), 147 'startX' => $request->getInt('startX'), 148 'startY' => $request->getInt('startY'), 149 'endX' => $request->getInt('endX'), 150 'endY' => $request->getInt('endY'), 151 ); 152 foreach ($params as $key => $value) { 153 $form->addHiddenInput($key, $value); 154 } 155 } 156 157 $form 158 ->appendChild( 159 id(new PhabricatorRemarkupControl()) 160 ->setUser($viewer) 161 ->setName('content') 162 ->setLabel(pht('Comment')) 163 ->setValue($v_content)); 164 165 return $this->newDialog() 166 ->setTitle($title) 167 ->setWidth(AphrontDialogView::WIDTH_FORM) 168 ->appendChild($form->buildLayoutView()) 169 ->addCancelButton($mock_uri) 170 ->addSubmitButton($submit_text); 171 } 172 173 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |