[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phame/controller/post/ -> PhamePostViewController.php (source)

   1  <?php
   2  
   3  final class PhamePostViewController extends PhameController {
   4  
   5    private $id;
   6  
   7    public function willProcessRequest(array $data) {
   8      $this->id = $data['id'];
   9    }
  10  
  11    public function processRequest() {
  12      $request = $this->getRequest();
  13      $user = $request->getUser();
  14  
  15      $post = id(new PhamePostQuery())
  16        ->setViewer($user)
  17        ->withIDs(array($this->id))
  18        ->executeOne();
  19  
  20      if (!$post) {
  21        return new Aphront404Response();
  22      }
  23  
  24      $nav = $this->renderSideNavFilterView();
  25  
  26      $this->loadHandles(
  27        array(
  28          $post->getBlogPHID(),
  29          $post->getBloggerPHID(),
  30        ));
  31      $actions = $this->renderActions($post, $user);
  32      $properties = $this->renderProperties($post, $user, $actions);
  33  
  34      $crumbs = $this->buildApplicationCrumbs();
  35      $crumbs->setActionList($actions);
  36      $crumbs->addTextCrumb(
  37        $post->getTitle(),
  38        $this->getApplicationURI('post/view/'.$post->getID().'/'));
  39  
  40      $nav->appendChild($crumbs);
  41  
  42      $header = id(new PHUIHeaderView())
  43          ->setHeader($post->getTitle())
  44          ->setUser($user)
  45          ->setPolicyObject($post);
  46  
  47      $object_box = id(new PHUIObjectBoxView())
  48        ->setHeader($header)
  49        ->addPropertyList($properties);
  50  
  51      if ($post->isDraft()) {
  52        $object_box->appendChild(
  53          id(new AphrontErrorView())
  54            ->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
  55            ->setTitle(pht('Draft Post'))
  56            ->appendChild(
  57              pht('Only you can see this draft until you publish it. '.
  58                  'Use "Preview / Publish" to publish this post.')));
  59      }
  60  
  61      if (!$post->getBlog()) {
  62        $object_box->appendChild(
  63          id(new AphrontErrorView())
  64            ->setSeverity(AphrontErrorView::SEVERITY_WARNING)
  65            ->setTitle(pht('Not On A Blog'))
  66            ->appendChild(
  67              pht('This post is not associated with a blog (the blog may have '.
  68                  'been deleted). Use "Move Post" to move it to a new blog.')));
  69      }
  70  
  71      $nav->appendChild(
  72        array(
  73          $object_box,
  74        ));
  75  
  76      return $this->buildApplicationPage(
  77        $nav,
  78        array(
  79          'title' => $post->getTitle(),
  80        ));
  81    }
  82  
  83    private function renderActions(
  84      PhamePost $post,
  85      PhabricatorUser $user) {
  86  
  87      $actions = id(new PhabricatorActionListView())
  88        ->setObject($post)
  89        ->setObjectURI($this->getRequest()->getRequestURI())
  90        ->setUser($user);
  91  
  92      $can_edit = PhabricatorPolicyFilter::hasCapability(
  93        $user,
  94        $post,
  95        PhabricatorPolicyCapability::CAN_EDIT);
  96  
  97      $id = $post->getID();
  98  
  99      $actions->addAction(
 100        id(new PhabricatorActionView())
 101          ->setIcon('fa-pencil')
 102          ->setHref($this->getApplicationURI('post/edit/'.$id.'/'))
 103          ->setName(pht('Edit Post'))
 104          ->setDisabled(!$can_edit)
 105          ->setWorkflow(!$can_edit));
 106  
 107      $actions->addAction(
 108        id(new PhabricatorActionView())
 109          ->setIcon('fa-arrows')
 110          ->setHref($this->getApplicationURI('post/move/'.$id.'/'))
 111          ->setName(pht('Move Post'))
 112          ->setDisabled(!$can_edit)
 113          ->setWorkflow(!$can_edit));
 114  
 115      if ($post->isDraft()) {
 116        $actions->addAction(
 117          id(new PhabricatorActionView())
 118            ->setIcon('fa-eye')
 119            ->setHref($this->getApplicationURI('post/publish/'.$id.'/'))
 120            ->setName(pht('Preview / Publish')));
 121      } else {
 122        $actions->addAction(
 123          id(new PhabricatorActionView())
 124            ->setIcon('fa-eye-slash')
 125            ->setHref($this->getApplicationURI('post/unpublish/'.$id.'/'))
 126            ->setName(pht('Unpublish'))
 127            ->setWorkflow(true));
 128      }
 129  
 130      $actions->addAction(
 131        id(new PhabricatorActionView())
 132          ->setIcon('fa-times')
 133          ->setHref($this->getApplicationURI('post/delete/'.$id.'/'))
 134          ->setName(pht('Delete Post'))
 135          ->setDisabled(!$can_edit)
 136          ->setWorkflow(true));
 137  
 138      $blog = $post->getBlog();
 139      $can_view_live = $blog && !$post->isDraft();
 140  
 141      if ($can_view_live) {
 142        $live_uri = $blog->getLiveURI($post);
 143      } else {
 144        $live_uri = 'post/notlive/'.$post->getID().'/';
 145        $live_uri = $this->getApplicationURI($live_uri);
 146      }
 147  
 148      $actions->addAction(
 149        id(new PhabricatorActionView())
 150          ->setUser($user)
 151          ->setIcon('fa-globe')
 152          ->setHref($live_uri)
 153          ->setName(pht('View Live'))
 154          ->setDisabled(!$can_view_live)
 155          ->setWorkflow(!$can_view_live));
 156  
 157      return $actions;
 158    }
 159  
 160    private function renderProperties(
 161      PhamePost $post,
 162      PhabricatorUser $user,
 163      PhabricatorActionListView $actions) {
 164  
 165      $properties = id(new PHUIPropertyListView())
 166        ->setUser($user)
 167        ->setObject($post)
 168        ->setActionList($actions);
 169  
 170      $properties->addProperty(
 171        pht('Blog'),
 172        $post->getBlogPHID()
 173          ? $this->getHandle($post->getBlogPHID())->renderLink()
 174          : null);
 175  
 176      $properties->addProperty(
 177        pht('Blogger'),
 178        $this->getHandle($post->getBloggerPHID())->renderLink());
 179  
 180      $properties->addProperty(
 181        pht('Published'),
 182        $post->isDraft()
 183          ? pht('Draft')
 184          : phabricator_datetime($post->getDatePublished(), $user));
 185  
 186      $engine = id(new PhabricatorMarkupEngine())
 187        ->setViewer($user)
 188        ->addObject($post, PhamePost::MARKUP_FIELD_BODY)
 189        ->process();
 190  
 191      $properties->invokeWillRenderEvent();
 192  
 193      $properties->addTextContent(
 194        phutil_tag(
 195           'div',
 196          array(
 197            'class' => 'phabricator-remarkup',
 198          ),
 199          $engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY)));
 200  
 201      return $properties;
 202    }
 203  
 204  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1