[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhamePostPublishController 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        ->requireCapabilities(
  19          array(
  20            PhabricatorPolicyCapability::CAN_EDIT,
  21          ))
  22        ->executeOne();
  23      if (!$post) {
  24        return new Aphront404Response();
  25      }
  26  
  27      $view_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
  28  
  29      if ($request->isFormPost()) {
  30        $post->setVisibility(PhamePost::VISIBILITY_PUBLISHED);
  31        $post->setDatePublished(time());
  32        $post->save();
  33  
  34        return id(new AphrontRedirectResponse())->setURI($view_uri);
  35      }
  36  
  37      $form = id(new AphrontFormView())
  38        ->setUser($user)
  39        ->appendChild(
  40          id(new AphrontFormSubmitControl())
  41            ->setValue(pht('Publish Post'))
  42            ->addCancelButton($view_uri));
  43  
  44      $frame = $this->renderPreviewFrame($post);
  45  
  46      $form_box = id(new PHUIObjectBoxView())
  47        ->setHeaderText(pht('Preview Post'))
  48        ->setForm($form);
  49  
  50      $crumbs = $this->buildApplicationCrumbs();
  51      $crumbs->addTextCrumb(pht('Preview'), $view_uri);
  52  
  53      $nav = $this->renderSideNavFilterView(null);
  54      $nav->appendChild(
  55        array(
  56          $crumbs,
  57          $form_box,
  58          $frame,
  59        ));
  60  
  61      return $this->buildApplicationPage(
  62        $nav,
  63        array(
  64          'title'   => pht('Preview Post'),
  65        ));
  66    }
  67  
  68    private function renderPreviewFrame(PhamePost $post) {
  69  
  70      // TODO: Clean up this CSS.
  71  
  72      return phutil_tag(
  73        'div',
  74        array(
  75          'style' => 'text-align: center; padding: 1em;',
  76        ),
  77        phutil_tag(
  78          'iframe',
  79          array(
  80            'style' => 'width: 100%; height: 600px; '.
  81                       'border: 1px solid #303030;',
  82            'src' => $this->getApplicationURI('/post/framed/'.$post->getID().'/'),
  83          ),
  84          ''));
  85    }
  86  
  87  }


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