[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phame/controller/blog/ -> PhameBlogViewController.php (source)

   1  <?php
   2  
   3  final class PhameBlogViewController 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      $blog = id(new PhameBlogQuery())
  16        ->setViewer($user)
  17        ->withIDs(array($this->id))
  18        ->executeOne();
  19      if (!$blog) {
  20        return new Aphront404Response();
  21      }
  22  
  23      $pager = id(new AphrontCursorPagerView())
  24        ->readFromRequest($request);
  25  
  26      $posts = id(new PhamePostQuery())
  27        ->setViewer($user)
  28        ->withBlogPHIDs(array($blog->getPHID()))
  29        ->executeWithCursorPager($pager);
  30  
  31      $nav = $this->renderSideNavFilterView(null);
  32  
  33      $header = id(new PHUIHeaderView())
  34        ->setHeader($blog->getName())
  35        ->setUser($user)
  36        ->setPolicyObject($blog);
  37  
  38      $handle_phids = array_merge(
  39        mpull($posts, 'getBloggerPHID'),
  40        mpull($posts, 'getBlogPHID'));
  41      $this->loadHandles($handle_phids);
  42  
  43      $actions = $this->renderActions($blog, $user);
  44      $properties = $this->renderProperties($blog, $user, $actions);
  45      $post_list = $this->renderPostList(
  46        $posts,
  47        $user,
  48        pht('This blog has no visible posts.'));
  49  
  50      require_celerity_resource('phame-css');
  51      $post_list = id(new PHUIBoxView())
  52        ->addPadding(PHUI::PADDING_LARGE)
  53        ->addClass('phame-post-list')
  54        ->appendChild($post_list);
  55  
  56  
  57      $crumbs = $this->buildApplicationCrumbs();
  58      $crumbs->addTextCrumb($blog->getName(), $this->getApplicationURI());
  59  
  60      $object_box = id(new PHUIObjectBoxView())
  61        ->setHeader($header)
  62        ->addPropertyList($properties);
  63  
  64      $nav->appendChild(
  65        array(
  66          $crumbs,
  67          $object_box,
  68          $post_list,
  69        ));
  70  
  71      return $this->buildApplicationPage(
  72        $nav,
  73        array(
  74          'title' => $blog->getName(),
  75        ));
  76    }
  77  
  78    private function renderProperties(
  79      PhameBlog $blog,
  80      PhabricatorUser $user,
  81      PhabricatorActionListView $actions) {
  82  
  83      require_celerity_resource('aphront-tooltip-css');
  84      Javelin::initBehavior('phabricator-tooltips');
  85  
  86      $properties = new PHUIPropertyListView();
  87      $properties->setActionList($actions);
  88  
  89      $properties->addProperty(
  90        pht('Skin'),
  91        $blog->getSkin());
  92  
  93      $properties->addProperty(
  94        pht('Domain'),
  95        $blog->getDomain());
  96  
  97      $feed_uri = PhabricatorEnv::getProductionURI(
  98        $this->getApplicationURI('blog/feed/'.$blog->getID().'/'));
  99      $properties->addProperty(
 100        pht('Atom URI'),
 101        javelin_tag('a',
 102          array(
 103            'href' => $feed_uri,
 104            'sigil' => 'has-tooltip',
 105            'meta' => array(
 106              'tip' => pht('Atom URI does not support custom domains.'),
 107              'size' => 320,
 108            ),
 109          ),
 110          $feed_uri));
 111  
 112      $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
 113        $user,
 114        $blog);
 115  
 116      $properties->addProperty(
 117        pht('Editable By'),
 118        $descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
 119  
 120      $properties->addProperty(
 121        pht('Joinable By'),
 122        $descriptions[PhabricatorPolicyCapability::CAN_JOIN]);
 123  
 124      $engine = id(new PhabricatorMarkupEngine())
 125        ->setViewer($user)
 126        ->addObject($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION)
 127        ->process();
 128  
 129      $properties->addTextContent(
 130        phutil_tag(
 131          'div',
 132          array(
 133            'class' => 'phabricator-remarkup',
 134          ),
 135          $engine->getOutput($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION)));
 136  
 137      return $properties;
 138    }
 139  
 140    private function renderActions(PhameBlog $blog, PhabricatorUser $user) {
 141      $actions = id(new PhabricatorActionListView())
 142        ->setObject($blog)
 143        ->setObjectURI($this->getRequest()->getRequestURI())
 144        ->setUser($user);
 145  
 146      $can_edit = PhabricatorPolicyFilter::hasCapability(
 147        $user,
 148        $blog,
 149        PhabricatorPolicyCapability::CAN_EDIT);
 150  
 151      $can_join = PhabricatorPolicyFilter::hasCapability(
 152        $user,
 153        $blog,
 154        PhabricatorPolicyCapability::CAN_JOIN);
 155  
 156      $actions->addAction(
 157        id(new PhabricatorActionView())
 158          ->setIcon('fa-plus')
 159          ->setHref($this->getApplicationURI('post/edit/?blog='.$blog->getID()))
 160          ->setName(pht('Write Post'))
 161          ->setDisabled(!$can_join)
 162          ->setWorkflow(!$can_join));
 163  
 164      $actions->addAction(
 165        id(new PhabricatorActionView())
 166          ->setUser($user)
 167          ->setIcon('fa-globe')
 168          ->setHref($blog->getLiveURI())
 169          ->setName(pht('View Live')));
 170  
 171      $actions->addAction(
 172        id(new PhabricatorActionView())
 173          ->setIcon('fa-pencil')
 174          ->setHref($this->getApplicationURI('blog/edit/'.$blog->getID().'/'))
 175          ->setName('Edit Blog')
 176          ->setDisabled(!$can_edit)
 177          ->setWorkflow(!$can_edit));
 178  
 179      $actions->addAction(
 180        id(new PhabricatorActionView())
 181          ->setIcon('fa-times')
 182          ->setHref($this->getApplicationURI('blog/delete/'.$blog->getID().'/'))
 183          ->setName('Delete Blog')
 184          ->setDisabled(!$can_edit)
 185          ->setWorkflow(true));
 186  
 187      return $actions;
 188    }
 189  
 190  }


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