コード例 #1
0
ファイル: PhameBlogQuery.php プロジェクト: denghp/phabricator
 protected function loadPage()
 {
     $table = new PhameBlog();
     $conn_r = $table->establishConnection('r');
     $where_clause = $this->buildWhereClause($conn_r);
     $order_clause = $this->buildOrderClause($conn_r);
     $limit_clause = $this->buildLimitClause($conn_r);
     $data = queryfx_all($conn_r, 'SELECT * FROM %T b %Q %Q %Q', $table->getTableName(), $where_clause, $order_clause, $limit_clause);
     $blogs = $table->loadAllFromArray($data);
     return $blogs;
 }
コード例 #2
0
 private function renderDescription(PhameBlog $blog, PhabricatorUser $viewer)
 {
     require_celerity_resource('phame-css');
     if (strlen($blog->getDescription())) {
         $description = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($blog->getDescription()), 'default', $viewer);
     } else {
         $description = phutil_tag('em', array(), pht('No description.'));
     }
     $picture = $blog->getProfileImageURI();
     $description = phutil_tag_div('phame-blog-description-content', $description);
     $image = phutil_tag('div', array('class' => 'phame-blog-description-image', 'style' => 'background-image: url(' . $picture . ');'));
     $header = phutil_tag('div', array('class' => 'phame-blog-description-name'), pht('About %s', $blog->getName()));
     $view = phutil_tag('div', array('class' => 'phame-blog-description'), array($image, $header, $description));
     return $view;
 }
コード例 #3
0
ファイル: PhameBlogQuery.php プロジェクト: rudimk/phabricator
 public function execute()
 {
     $table = new PhameBlog();
     $conn_r = $table->establishConnection('r');
     $where_clause = $this->buildWhereClause($conn_r);
     $order_clause = $this->buildOrderClause($conn_r);
     $limit_clause = $this->buildLimitClause($conn_r);
     $data = queryfx_all($conn_r, 'SELECT * FROM %T b %Q %Q %Q', $table->getTableName(), $where_clause, $order_clause, $limit_clause);
     $blogs = $table->loadAllFromArray($data);
     if ($blogs) {
         if ($this->needBloggers) {
             $this->loadBloggers($blogs);
         }
     }
     return $blogs;
 }
コード例 #4
0
 private function renderProperties(PhameBlog $blog, PhabricatorUser $user, PhabricatorActionListView $actions)
 {
     require_celerity_resource('aphront-tooltip-css');
     Javelin::initBehavior('phabricator-tooltips');
     $properties = new PHUIPropertyListView();
     $properties->setActionList($actions);
     $properties->addProperty(pht('Skin'), $blog->getSkin());
     $properties->addProperty(pht('Domain'), $blog->getDomain());
     $feed_uri = PhabricatorEnv::getProductionURI($this->getApplicationURI('blog/feed/' . $blog->getID() . '/'));
     $properties->addProperty(pht('Atom URI'), javelin_tag('a', array('href' => $feed_uri, 'sigil' => 'has-tooltip', 'meta' => array('tip' => pht('Atom URI does not support custom domains.'), 'size' => 320)), $feed_uri));
     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions($user, $blog);
     $properties->addProperty(pht('Editable By'), $descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
     $properties->addProperty(pht('Joinable By'), $descriptions[PhabricatorPolicyCapability::CAN_JOIN]);
     $engine = id(new PhabricatorMarkupEngine())->setViewer($user)->addObject($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION)->process();
     $properties->addTextContent(phutil_tag('div', array('class' => 'phabricator-remarkup'), $engine->getOutput($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION)));
     return $properties;
 }
コード例 #5
0
 protected function newEditableObject()
 {
     $viewer = $this->getViewer();
     if ($this->blog) {
         $blog = $this->blog;
     } else {
         $blog = PhameBlog::initializeNewBlog($viewer);
     }
     return PhamePost::initializePost($viewer, $blog);
 }
コード例 #6
0
 private function buildPhameHeader(PhameBlog $blog)
 {
     $image = null;
     if ($blog->getHeaderImagePHID()) {
         $image = phutil_tag('div', array('class' => 'phame-header-hero'), phutil_tag('img', array('src' => $blog->getHeaderImageURI(), 'class' => 'phame-header-image')));
     }
     $title = phutil_tag_div('phame-header-title', $blog->getName());
     $subtitle = null;
     if ($blog->getSubtitle()) {
         $subtitle = phutil_tag_div('phame-header-subtitle', $blog->getSubtitle());
     }
     return phutil_tag_div('phame-mega-header', array($image, $title, $subtitle));
 }
コード例 #7
0
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     if ($id) {
         $blog = id(new PhameBlogQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
         if (!$blog) {
             return new Aphront404Response();
         }
         $submit_button = pht('Save Changes');
         $page_title = pht('Edit Blog');
         $cancel_uri = $this->getApplicationURI('blog/view/' . $blog->getID() . '/');
         $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs($blog->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
         $v_projects = array_reverse($v_projects);
         $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID($blog->getPHID());
     } else {
         $this->requireApplicationCapability(PhameBlogCreateCapability::CAPABILITY);
         $blog = PhameBlog::initializeNewBlog($viewer);
         $submit_button = pht('Create Blog');
         $page_title = pht('Create Blog');
         $cancel_uri = $this->getApplicationURI();
         $v_projects = array();
         $v_cc = array();
     }
     $name = $blog->getName();
     $description = $blog->getDescription();
     $custom_domain = $blog->getDomain();
     $skin = $blog->getSkin();
     $can_view = $blog->getViewPolicy();
     $can_edit = $blog->getEditPolicy();
     $e_name = true;
     $e_custom_domain = null;
     $e_view_policy = null;
     $validation_exception = null;
     if ($request->isFormPost()) {
         $name = $request->getStr('name');
         $description = $request->getStr('description');
         $custom_domain = nonempty($request->getStr('custom_domain'), null);
         $skin = $request->getStr('skin');
         $can_view = $request->getStr('can_view');
         $can_edit = $request->getStr('can_edit');
         $v_projects = $request->getArr('projects');
         $v_cc = $request->getArr('cc');
         $xactions = array(id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_NAME)->setNewValue($name), id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_DESCRIPTION)->setNewValue($description), id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_DOMAIN)->setNewValue($custom_domain), id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_SKIN)->setNewValue($skin), id(new PhameBlogTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($can_view), id(new PhameBlogTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)->setNewValue($can_edit), id(new PhameBlogTransaction())->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)->setNewValue(array('=' => $v_cc)));
         $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
         $xactions[] = id(new PhameBlogTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $proj_edge_type)->setNewValue(array('=' => array_fuse($v_projects)));
         $editor = id(new PhameBlogEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true);
         try {
             $editor->applyTransactions($blog, $xactions);
             return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI('blog/view/' . $blog->getID() . '/'));
         } catch (PhabricatorApplicationTransactionValidationException $ex) {
             $validation_exception = $ex;
             $e_name = $validation_exception->getShortMessage(PhameBlogTransaction::TYPE_NAME);
             $e_custom_domain = $validation_exception->getShortMessage(PhameBlogTransaction::TYPE_DOMAIN);
             $e_view_policy = $validation_exception->getShortMessage(PhabricatorTransactions::TYPE_VIEW_POLICY);
         }
     }
     $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($blog)->execute();
     $skins = PhameSkinSpecification::loadAllSkinSpecifications();
     $skins = mpull($skins, 'getName');
     $form = id(new AphrontFormView())->setUser($viewer)->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($name)->setID('blog-name')->setError($e_name))->appendChild(id(new PhabricatorRemarkupControl())->setUser($viewer)->setLabel(pht('Description'))->setName('description')->setValue($description)->setID('blog-description')->setUser($viewer)->setDisableMacros(true))->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Subscribers'))->setName('cc')->setValue($v_cc)->setUser($viewer)->setDatasource(new PhabricatorMetaMTAMailableDatasource()))->appendChild(id(new AphrontFormPolicyControl())->setUser($viewer)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicyObject($blog)->setPolicies($policies)->setError($e_view_policy)->setValue($can_view)->setName('can_view'))->appendChild(id(new AphrontFormPolicyControl())->setUser($viewer)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicyObject($blog)->setPolicies($policies)->setValue($can_edit)->setName('can_edit'))->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Projects'))->setName('projects')->setValue($v_projects)->setDatasource(new PhabricatorProjectDatasource()))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Custom Domain'))->setName('custom_domain')->setValue($custom_domain)->setCaption(pht('Must include at least one dot (.), e.g. %s', 'blog.example.com'))->setError($e_custom_domain))->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Skin'))->setName('skin')->setValue($skin)->setOptions($skins))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($submit_button));
     $form_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setValidationException($validation_exception)->setForm($form);
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Blogs'), $this->getApplicationURI('blog/'));
     $crumbs->addTextCrumb($page_title, $this->getApplicationURI('blog/new'));
     return $this->newPage()->setTitle($page_title)->setCrumbs($crumbs)->appendChild(array($form_box));
 }
コード例 #8
0
 protected function buildCustomEditFields($object)
 {
     return array(id(new PhabricatorTextEditField())->setKey('name')->setLabel(pht('Name'))->setDescription(pht('Blog name.'))->setConduitDescription(pht('Retitle the blog.'))->setConduitTypeDescription(pht('New blog title.'))->setTransactionType(PhameBlogTransaction::TYPE_NAME)->setValue($object->getName()), id(new PhabricatorTextEditField())->setKey('subtitle')->setLabel(pht('Subtitle'))->setDescription(pht('Blog subtitle.'))->setConduitDescription(pht('Change the blog subtitle.'))->setConduitTypeDescription(pht('New blog subtitle.'))->setTransactionType(PhameBlogTransaction::TYPE_SUBTITLE)->setValue($object->getSubtitle()), id(new PhabricatorRemarkupEditField())->setKey('description')->setLabel(pht('Description'))->setDescription(pht('Blog description.'))->setConduitDescription(pht('Change the blog description.'))->setConduitTypeDescription(pht('New blog description.'))->setTransactionType(PhameBlogTransaction::TYPE_DESCRIPTION)->setValue($object->getDescription()), id(new PhabricatorTextEditField())->setKey('domainFullURI')->setLabel(pht('Full Domain URI'))->setControlInstructions(pht('Set Full Domain URI if you plan to ' . 'serve this blog on another hosted domain. Parent Site Name and ' . 'Parent Site URI are optional but helpful since they provide ' . 'a link from the blog back to your parent site.'))->setDescription(pht('Blog full domain URI.'))->setConduitDescription(pht('Change the blog full domain URI.'))->setConduitTypeDescription(pht('New blog full domain URI.'))->setValue($object->getDomainFullURI())->setTransactionType(PhameBlogTransaction::TYPE_FULLDOMAIN), id(new PhabricatorTextEditField())->setKey('parentSite')->setLabel(pht('Parent Site Name'))->setDescription(pht('Blog parent site name.'))->setConduitDescription(pht('Change the blog parent site name.'))->setConduitTypeDescription(pht('New blog parent site name.'))->setValue($object->getParentSite())->setTransactionType(PhameBlogTransaction::TYPE_PARENTSITE), id(new PhabricatorTextEditField())->setKey('parentDomain')->setLabel(pht('Parent Site URI'))->setDescription(pht('Blog parent domain name.'))->setConduitDescription(pht('Change the blog parent domain.'))->setConduitTypeDescription(pht('New blog parent domain.'))->setValue($object->getParentDomain())->setTransactionType(PhameBlogTransaction::TYPE_PARENTDOMAIN), id(new PhabricatorSelectEditField())->setKey('status')->setLabel(pht('Status'))->setTransactionType(PhameBlogTransaction::TYPE_STATUS)->setIsConduitOnly(true)->setOptions(PhameBlog::getStatusNameMap())->setDescription(pht('Active or archived status.'))->setConduitDescription(pht('Active or archive the blog.'))->setConduitTypeDescription(pht('New blog status constant.'))->setValue($object->getStatus()));
 }
コード例 #9
0
 protected function buildCustomEditFields($object)
 {
     return array(id(new PhabricatorTextEditField())->setKey('name')->setLabel(pht('Name'))->setDescription(pht('Blog name.'))->setConduitDescription(pht('Retitle the blog.'))->setConduitTypeDescription(pht('New blog title.'))->setTransactionType(PhameBlogTransaction::TYPE_NAME)->setValue($object->getName()), id(new PhabricatorRemarkupEditField())->setKey('description')->setLabel(pht('Description'))->setDescription(pht('Blog description.'))->setConduitDescription(pht('Change the blog description.'))->setConduitTypeDescription(pht('New blog description.'))->setTransactionType(PhameBlogTransaction::TYPE_DESCRIPTION)->setValue($object->getDescription()), id(new PhabricatorTextEditField())->setKey('domain')->setLabel(pht('Custom Domain'))->setDescription(pht('Blog domain name.'))->setConduitDescription(pht('Change the blog domain.'))->setConduitTypeDescription(pht('New blog domain.'))->setValue($object->getDomain())->setTransactionType(PhameBlogTransaction::TYPE_DOMAIN), id(new PhabricatorSelectEditField())->setKey('status')->setLabel(pht('Status'))->setTransactionType(PhameBlogTransaction::TYPE_STATUS)->setIsConduitOnly(true)->setOptions(PhameBlog::getStatusNameMap())->setDescription(pht('Active or archived status.'))->setConduitDescription(pht('Active or archive the blog.'))->setConduitTypeDescription(pht('New blog status constant.'))->setValue($object->getStatus()));
 }
コード例 #10
0
 public static function setRequestBlog(PhameBlog $blog)
 {
     self::$requestBlog = $blog;
 }
コード例 #11
0
 public function handleRequest(AphrontRequest $request)
 {
     $user = $request->getUser();
     $id = $request->getURIData('id');
     if ($id) {
         $blog = id(new PhameBlogQuery())->setViewer($user)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
         if (!$blog) {
             return new Aphront404Response();
         }
         $submit_button = pht('Save Changes');
         $page_title = pht('Edit Blog');
         $cancel_uri = $this->getApplicationURI('blog/view/' . $blog->getID() . '/');
     } else {
         $blog = PhameBlog::initializeNewBlog($user);
         $submit_button = pht('Create Blog');
         $page_title = pht('Create Blog');
         $cancel_uri = $this->getApplicationURI();
     }
     $name = $blog->getName();
     $description = $blog->getDescription();
     $custom_domain = $blog->getDomain();
     $skin = $blog->getSkin();
     $can_view = $blog->getViewPolicy();
     $can_edit = $blog->getEditPolicy();
     $can_join = $blog->getJoinPolicy();
     $e_name = true;
     $e_custom_domain = null;
     $e_view_policy = null;
     $validation_exception = null;
     if ($request->isFormPost()) {
         $name = $request->getStr('name');
         $description = $request->getStr('description');
         $custom_domain = nonempty($request->getStr('custom_domain'), null);
         $skin = $request->getStr('skin');
         $can_view = $request->getStr('can_view');
         $can_edit = $request->getStr('can_edit');
         $can_join = $request->getStr('can_join');
         $xactions = array(id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_NAME)->setNewValue($name), id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_DESCRIPTION)->setNewValue($description), id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_DOMAIN)->setNewValue($custom_domain), id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_SKIN)->setNewValue($skin), id(new PhameBlogTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($can_view), id(new PhameBlogTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)->setNewValue($can_edit), id(new PhameBlogTransaction())->setTransactionType(PhabricatorTransactions::TYPE_JOIN_POLICY)->setNewValue($can_join));
         $editor = id(new PhameBlogEditor())->setActor($user)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true);
         try {
             $editor->applyTransactions($blog, $xactions);
             return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI('blog/view/' . $blog->getID() . '/'));
         } catch (PhabricatorApplicationTransactionValidationException $ex) {
             $validation_exception = $ex;
             $e_name = $validation_exception->getShortMessage(PhameBlogTransaction::TYPE_NAME);
             $e_custom_domain = $validation_exception->getShortMessage(PhameBlogTransaction::TYPE_DOMAIN);
             $e_view_policy = $validation_exception->getShortMessage(PhabricatorTransactions::TYPE_VIEW_POLICY);
         }
     }
     $policies = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($blog)->execute();
     $skins = PhameSkinSpecification::loadAllSkinSpecifications();
     $skins = mpull($skins, 'getName');
     $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($name)->setID('blog-name')->setError($e_name))->appendChild(id(new PhabricatorRemarkupControl())->setUser($user)->setLabel(pht('Description'))->setName('description')->setValue($description)->setID('blog-description')->setUser($user)->setDisableMacros(true))->appendChild(id(new AphrontFormPolicyControl())->setUser($user)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicyObject($blog)->setPolicies($policies)->setError($e_view_policy)->setValue($can_view)->setName('can_view'))->appendChild(id(new AphrontFormPolicyControl())->setUser($user)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicyObject($blog)->setPolicies($policies)->setValue($can_edit)->setName('can_edit'))->appendChild(id(new AphrontFormPolicyControl())->setUser($user)->setCapability(PhabricatorPolicyCapability::CAN_JOIN)->setPolicyObject($blog)->setPolicies($policies)->setValue($can_join)->setName('can_join'))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Custom Domain'))->setName('custom_domain')->setValue($custom_domain)->setCaption(pht('Must include at least one dot (.), e.g. %s', 'blog.example.com'))->setError($e_custom_domain))->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Skin'))->setName('skin')->setValue($skin)->setOptions($skins))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($submit_button));
     $form_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setValidationException($validation_exception)->setForm($form);
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($page_title, $this->getApplicationURI('blog/new'));
     $nav = $this->renderSideNavFilterView();
     $nav->selectFilter($id ? null : 'blog/new');
     $nav->appendChild(array($crumbs, $form_box));
     return $this->buildApplicationPage($nav, array('title' => $page_title));
 }
コード例 #12
0
<?php

$table = new PhameBlog();
$conn_w = $table->establishConnection('w');
$iterator = new LiskMigrationIterator($table);
foreach ($iterator as $blog) {
    $id = $blog->getID();
    echo pht('Adding mail key for Blog %d...', $id);
    echo "\n";
    queryfx($conn_w, 'UPDATE %T SET mailKey = %s WHERE id = %d', $table->getTableName(), Filesystem::readRandomCharacters(20), $id);
}
コード例 #13
0
 private function buildFileView(PhameBlog $blog)
 {
     $viewer = $this->getViewer();
     $view = id(new PHUIPropertyListView())->setUser($viewer);
     if ($blog->getHeaderImagePHID()) {
         $view->addImageContent(phutil_tag('img', array('src' => $blog->getHeaderImageURI(), 'class' => 'phabricator-image-macro-hero')));
         return $view;
     }
     return null;
 }