Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phame/storage/PhameBlog.php
| <?php | <?php | ||||
| final class PhameBlog extends PhameDAO | final class PhameBlog extends PhameDAO | ||||
| implements | implements | ||||
| PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
| PhabricatorMarkupInterface, | PhabricatorMarkupInterface, | ||||
| PhabricatorSubscribableInterface, | PhabricatorSubscribableInterface, | ||||
| PhabricatorFlaggableInterface, | PhabricatorFlaggableInterface, | ||||
| PhabricatorProjectInterface, | PhabricatorProjectInterface, | ||||
| PhabricatorDestructibleInterface, | PhabricatorDestructibleInterface, | ||||
| PhabricatorApplicationTransactionInterface { | PhabricatorApplicationTransactionInterface { | ||||
| const MARKUP_FIELD_DESCRIPTION = 'markup:description'; | const MARKUP_FIELD_DESCRIPTION = 'markup:description'; | ||||
| const SKIN_DEFAULT = 'oblivious'; | |||||
| protected $name; | protected $name; | ||||
| protected $description; | protected $description; | ||||
| protected $domain; | protected $domain; | ||||
| protected $configData; | protected $configData; | ||||
| protected $creatorPHID; | protected $creatorPHID; | ||||
| protected $viewPolicy; | protected $viewPolicy; | ||||
| protected $editPolicy; | protected $editPolicy; | ||||
| protected $status; | protected $status; | ||||
| protected $mailKey; | protected $mailKey; | ||||
| protected $profileImagePHID; | protected $profileImagePHID; | ||||
| private $profileImageFile = self::ATTACHABLE; | private $profileImageFile = self::ATTACHABLE; | ||||
| private static $requestBlog; | |||||
| const STATUS_ACTIVE = 'active'; | const STATUS_ACTIVE = 'active'; | ||||
| const STATUS_ARCHIVED = 'archived'; | const STATUS_ARCHIVED = 'archived'; | ||||
| protected function getConfiguration() { | protected function getConfiguration() { | ||||
| return array( | return array( | ||||
| self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
| self::CONFIG_SERIALIZATION => array( | self::CONFIG_SERIALIZATION => array( | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public static function initializeNewBlog(PhabricatorUser $actor) { | ||||
| $blog = id(new PhameBlog()) | $blog = id(new PhameBlog()) | ||||
| ->setCreatorPHID($actor->getPHID()) | ->setCreatorPHID($actor->getPHID()) | ||||
| ->setStatus(self::STATUS_ACTIVE) | ->setStatus(self::STATUS_ACTIVE) | ||||
| ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) | ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) | ||||
| ->setEditPolicy(PhabricatorPolicies::POLICY_USER); | ->setEditPolicy(PhabricatorPolicies::POLICY_USER); | ||||
| return $blog; | return $blog; | ||||
| } | } | ||||
| public function getSkinRenderer(AphrontRequest $request) { | |||||
| $spec = PhameSkinSpecification::loadOneSkinSpecification( | |||||
| $this->getSkin()); | |||||
| if (!$spec) { | |||||
| $spec = PhameSkinSpecification::loadOneSkinSpecification( | |||||
| self::SKIN_DEFAULT); | |||||
| } | |||||
| if (!$spec) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'This blog has an invalid skin, and the default skin failed to '. | |||||
| 'load.')); | |||||
| } | |||||
| $skin = newv($spec->getSkinClass(), array()); | |||||
| $skin->setRequest($request); | |||||
| $skin->setSpecification($spec); | |||||
| return $skin; | |||||
| } | |||||
| public function isArchived() { | public function isArchived() { | ||||
| return ($this->getStatus() == self::STATUS_ARCHIVED); | return ($this->getStatus() == self::STATUS_ARCHIVED); | ||||
| } | } | ||||
| public static function getStatusNameMap() { | public static function getStatusNameMap() { | ||||
| return array( | return array( | ||||
| self::STATUS_ACTIVE => pht('Active'), | self::STATUS_ACTIVE => pht('Active'), | ||||
| self::STATUS_ARCHIVED => pht('Archived'), | self::STATUS_ARCHIVED => pht('Archived'), | ||||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | if (!PhabricatorEnv::getEnvConfig('policy.allow-public')) { | ||||
| array('href' => $href), | array('href' => $href), | ||||
| pht('here'))), | pht('here'))), | ||||
| ); | ); | ||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| public function getSkin() { | public function getLiveURI() { | ||||
| $config = coalesce($this->getConfigData(), array()); | if (strlen($this->getDomain())) { | ||||
| return idx($config, 'skin', self::SKIN_DEFAULT); | return $this->getExternalLiveURI(); | ||||
| } | |||||
| public function setSkin($skin) { | |||||
| $config = coalesce($this->getConfigData(), array()); | |||||
| $config['skin'] = $skin; | |||||
| return $this->setConfigData($config); | |||||
| } | |||||
| public static function getSkinOptionsForSelect() { | |||||
| $classes = id(new PhutilSymbolLoader()) | |||||
| ->setAncestorClass('PhameBlogSkin') | |||||
| ->setType('class') | |||||
| ->setConcreteOnly(true) | |||||
| ->selectSymbolsWithoutLoading(); | |||||
| return ipull($classes, 'name', 'name'); | |||||
| } | |||||
| public static function setRequestBlog(PhameBlog $blog) { | |||||
| self::$requestBlog = $blog; | |||||
| } | |||||
| public static function getRequestBlog() { | |||||
| return self::$requestBlog; | |||||
| } | |||||
| public function getLiveURI(PhamePost $post = null) { | |||||
| if ($this->getDomain()) { | |||||
| $base = new PhutilURI('http://'.$this->getDomain().'/'); | |||||
| } else { | } else { | ||||
| $base = '/phame/live/'.$this->getID().'/'; | return $this->getInternalLiveURI(); | ||||
| $base = PhabricatorEnv::getURI($base); | } | ||||
| } | } | ||||
| if ($post) { | public function getExternalLiveURI() { | ||||
| $base .= '/post/'.$post->getPhameTitle(); | $domain = $this->getDomain(); | ||||
| $uri = new PhutilURI('http://'.$this->getDomain().'/'); | |||||
| return (string)$uri; | |||||
| } | } | ||||
| return $base; | public function getInternalLiveURI() { | ||||
| return '/phame/live/'.$this->getID().'/'; | |||||
| } | } | ||||
| public function getViewURI() { | public function getViewURI() { | ||||
| $uri = '/phame/blog/view/'.$this->getID().'/'; | return '/phame/blog/view/'.$this->getID().'/'; | ||||
| return PhabricatorEnv::getProductionURI($uri); | |||||
| } | } | ||||
| public function getProfileImageURI() { | public function getProfileImageURI() { | ||||
| return $this->getProfileImageFile()->getBestURI(); | return $this->getProfileImageFile()->getBestURI(); | ||||
| } | } | ||||
| public function attachProfileImageFile(PhabricatorFile $file) { | public function attachProfileImageFile(PhabricatorFile $file) { | ||||
| $this->profileImageFile = $file; | $this->profileImageFile = $file; | ||||
| ▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines | |||||