[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhameBlog extends PhameDAO 4 implements PhabricatorPolicyInterface, PhabricatorMarkupInterface { 5 6 const MARKUP_FIELD_DESCRIPTION = 'markup:description'; 7 8 const SKIN_DEFAULT = 'oblivious'; 9 10 protected $name; 11 protected $description; 12 protected $domain; 13 protected $configData; 14 protected $creatorPHID; 15 protected $viewPolicy; 16 protected $editPolicy; 17 protected $joinPolicy; 18 19 private $bloggerPHIDs = self::ATTACHABLE; 20 private $bloggers = self::ATTACHABLE; 21 22 static private $requestBlog; 23 24 public function getConfiguration() { 25 return array( 26 self::CONFIG_AUX_PHID => true, 27 self::CONFIG_SERIALIZATION => array( 28 'configData' => self::SERIALIZATION_JSON, 29 ), 30 self::CONFIG_COLUMN_SCHEMA => array( 31 'name' => 'text64', 32 'description' => 'text', 33 'domain' => 'text128?', 34 35 // T6203/NULLABILITY 36 // These policies should always be non-null. 37 'joinPolicy' => 'policy?', 38 'editPolicy' => 'policy?', 39 'viewPolicy' => 'policy?', 40 ), 41 self::CONFIG_KEY_SCHEMA => array( 42 'key_phid' => null, 43 'phid' => array( 44 'columns' => array('phid'), 45 'unique' => true, 46 ), 47 'domain' => array( 48 'columns' => array('domain'), 49 'unique' => true, 50 ), 51 ), 52 ) + parent::getConfiguration(); 53 } 54 55 public function generatePHID() { 56 return PhabricatorPHID::generateNewPHID( 57 PhabricatorPhameBlogPHIDType::TYPECONST); 58 } 59 60 public function getSkinRenderer(AphrontRequest $request) { 61 $spec = PhameSkinSpecification::loadOneSkinSpecification( 62 $this->getSkin()); 63 64 if (!$spec) { 65 $spec = PhameSkinSpecification::loadOneSkinSpecification( 66 self::SKIN_DEFAULT); 67 } 68 69 if (!$spec) { 70 throw new Exception( 71 'This blog has an invalid skin, and the default skin failed to '. 72 'load.'); 73 } 74 75 $skin = newv($spec->getSkinClass(), array()); 76 $skin->setRequest($request); 77 $skin->setSpecification($spec); 78 79 return $skin; 80 } 81 82 /** 83 * Makes sure a given custom blog uri is properly configured in DNS 84 * to point at this Phabricator instance. If there is an error in 85 * the configuration, return a string describing the error and how 86 * to fix it. If there is no error, return an empty string. 87 * 88 * @return string 89 */ 90 public function validateCustomDomain($custom_domain) { 91 $example_domain = 'blog.example.com'; 92 $label = pht('Invalid'); 93 94 // note this "uri" should be pretty busted given the desired input 95 // so just use it to test if there's a protocol specified 96 $uri = new PhutilURI($custom_domain); 97 if ($uri->getProtocol()) { 98 return array( 99 $label, 100 pht( 101 'The custom domain should not include a protocol. Just provide '. 102 'the bare domain name (for example, "%s").', 103 $example_domain), 104 ); 105 } 106 107 if ($uri->getPort()) { 108 return array( 109 $label, 110 pht( 111 'The custom domain should not include a port number. Just provide '. 112 'the bare domain name (for example, "%s").', 113 $example_domain), 114 ); 115 } 116 117 if (strpos($custom_domain, '/') !== false) { 118 return array( 119 $label, 120 pht( 121 'The custom domain should not specify a path (hosting a Phame '. 122 'blog at a path is currently not supported). Instead, just provide '. 123 'the bare domain name (for example, "%s").', 124 $example_domain), 125 ); 126 } 127 128 if (strpos($custom_domain, '.') === false) { 129 return array( 130 $label, 131 pht( 132 'The custom domain should contain at least one dot (.) because '. 133 'some browsers fail to set cookies on domains without a dot. '. 134 'Instead, use a normal looking domain name like "%s".', 135 $example_domain), 136 ); 137 } 138 139 if (!PhabricatorEnv::getEnvConfig('policy.allow-public')) { 140 $href = PhabricatorEnv::getProductionURI( 141 '/config/edit/policy.allow-public/'); 142 return array( 143 pht('Fix Configuration'), 144 pht( 145 'For custom domains to work, this Phabricator instance must be '. 146 'configured to allow the public access policy. Configure this '. 147 'setting %s, or ask an administrator to configure this setting. '. 148 'The domain can be specified later once this setting has been '. 149 'changed.', 150 phutil_tag( 151 'a', 152 array('href' => $href), 153 pht('here'))), 154 ); 155 } 156 157 return null; 158 } 159 160 public function getBloggerPHIDs() { 161 return $this->assertAttached($this->bloggerPHIDs); 162 } 163 164 public function attachBloggers(array $bloggers) { 165 assert_instances_of($bloggers, 'PhabricatorObjectHandle'); 166 167 $this->bloggers = $bloggers; 168 169 return $this; 170 } 171 172 public function getBloggers() { 173 return $this->assertAttached($this->bloggers); 174 } 175 176 public function getSkin() { 177 $config = coalesce($this->getConfigData(), array()); 178 return idx($config, 'skin', self::SKIN_DEFAULT); 179 } 180 181 public function setSkin($skin) { 182 $config = coalesce($this->getConfigData(), array()); 183 $config['skin'] = $skin; 184 return $this->setConfigData($config); 185 } 186 187 static public function getSkinOptionsForSelect() { 188 $classes = id(new PhutilSymbolLoader()) 189 ->setAncestorClass('PhameBlogSkin') 190 ->setType('class') 191 ->setConcreteOnly(true) 192 ->selectSymbolsWithoutLoading(); 193 194 return ipull($classes, 'name', 'name'); 195 } 196 197 public static function setRequestBlog(PhameBlog $blog) { 198 self::$requestBlog = $blog; 199 } 200 201 public static function getRequestBlog() { 202 return self::$requestBlog; 203 } 204 205 public function getLiveURI(PhamePost $post = null) { 206 if ($this->getDomain()) { 207 $base = new PhutilURI('http://'.$this->getDomain().'/'); 208 } else { 209 $base = '/phame/live/'.$this->getID().'/'; 210 $base = PhabricatorEnv::getURI($base); 211 } 212 213 if ($post) { 214 $base .= '/post/'.$post->getPhameTitle(); 215 } 216 217 return $base; 218 } 219 220 221 /* -( PhabricatorPolicyInterface Implementation )-------------------------- */ 222 223 224 public function getCapabilities() { 225 return array( 226 PhabricatorPolicyCapability::CAN_VIEW, 227 PhabricatorPolicyCapability::CAN_EDIT, 228 PhabricatorPolicyCapability::CAN_JOIN, 229 ); 230 } 231 232 233 public function getPolicy($capability) { 234 switch ($capability) { 235 case PhabricatorPolicyCapability::CAN_VIEW: 236 return $this->getViewPolicy(); 237 case PhabricatorPolicyCapability::CAN_EDIT: 238 return $this->getEditPolicy(); 239 case PhabricatorPolicyCapability::CAN_JOIN: 240 return $this->getJoinPolicy(); 241 } 242 } 243 244 public function hasAutomaticCapability($capability, PhabricatorUser $user) { 245 $can_edit = PhabricatorPolicyCapability::CAN_EDIT; 246 $can_join = PhabricatorPolicyCapability::CAN_JOIN; 247 248 switch ($capability) { 249 case PhabricatorPolicyCapability::CAN_VIEW: 250 // Users who can edit or post to a blog can always view it. 251 if (PhabricatorPolicyFilter::hasCapability($user, $this, $can_edit)) { 252 return true; 253 } 254 if (PhabricatorPolicyFilter::hasCapability($user, $this, $can_join)) { 255 return true; 256 } 257 break; 258 case PhabricatorPolicyCapability::CAN_JOIN: 259 // Users who can edit a blog can always post to it. 260 if (PhabricatorPolicyFilter::hasCapability($user, $this, $can_edit)) { 261 return true; 262 } 263 break; 264 } 265 266 return false; 267 } 268 269 270 public function describeAutomaticCapability($capability) { 271 switch ($capability) { 272 case PhabricatorPolicyCapability::CAN_VIEW: 273 return pht( 274 'Users who can edit or post on a blog can always view it.'); 275 case PhabricatorPolicyCapability::CAN_JOIN: 276 return pht( 277 'Users who can edit a blog can always post on it.'); 278 } 279 280 return null; 281 } 282 283 284 /* -( PhabricatorMarkupInterface Implementation )-------------------------- */ 285 286 287 public function getMarkupFieldKey($field) { 288 $hash = PhabricatorHash::digest($this->getMarkupText($field)); 289 return $this->getPHID().':'.$field.':'.$hash; 290 } 291 292 293 public function newMarkupEngine($field) { 294 return PhabricatorMarkupEngine::newPhameMarkupEngine(); 295 } 296 297 298 public function getMarkupText($field) { 299 return $this->getDescription(); 300 } 301 302 303 public function didMarkupText( 304 $field, 305 $output, 306 PhutilMarkupEngine $engine) { 307 return $output; 308 } 309 310 public function shouldUseMarkupCache($field) { 311 return (bool)$this->getPHID(); 312 } 313 314 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |