[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhamePostView extends AphrontView { 4 5 private $post; 6 private $author; 7 private $body; 8 private $skin; 9 private $summary; 10 11 12 public function setSkin(PhameBlogSkin $skin) { 13 $this->skin = $skin; 14 return $this; 15 } 16 17 public function getSkin() { 18 return $this->skin; 19 } 20 21 public function setAuthor(PhabricatorObjectHandle $author) { 22 $this->author = $author; 23 return $this; 24 } 25 26 public function getAuthor() { 27 return $this->author; 28 } 29 30 public function setPost(PhamePost $post) { 31 $this->post = $post; 32 return $this; 33 } 34 35 public function getPost() { 36 return $this->post; 37 } 38 39 public function setBody($body) { 40 $this->body = $body; 41 return $this; 42 } 43 44 public function getBody() { 45 return $this->body; 46 } 47 48 public function setSummary($summary) { 49 $this->summary = $summary; 50 return $this; 51 } 52 53 public function getSummary() { 54 return $this->summary; 55 } 56 57 public function renderTitle() { 58 $href = $this->getSkin()->getURI('post/'.$this->getPost()->getPhameTitle()); 59 return phutil_tag( 60 'h2', 61 array( 62 'class' => 'phame-post-title', 63 ), 64 phutil_tag( 65 'a', 66 array( 67 'href' => $href, 68 ), 69 $this->getPost()->getTitle())); 70 } 71 72 public function renderDatePublished() { 73 return phutil_tag( 74 'div', 75 array( 76 'class' => 'phame-post-date', 77 ), 78 pht( 79 'Published on %s by %s', 80 phabricator_datetime( 81 $this->getPost()->getDatePublished(), 82 $this->getUser()), 83 $this->getAuthor()->getName())); 84 } 85 86 public function renderBody() { 87 return phutil_tag( 88 'div', 89 array( 90 'class' => 'phame-post-body', 91 ), 92 $this->getBody()); 93 } 94 95 public function renderSummary() { 96 return phutil_tag( 97 'div', 98 array( 99 'class' => 'phame-post-body', 100 ), 101 $this->getSummary()); 102 } 103 104 public function renderComments() { 105 $post = $this->getPost(); 106 107 switch ($post->getCommentsWidget()) { 108 case 'facebook': 109 $comments = $this->renderFacebookComments(); 110 break; 111 case 'disqus': 112 $comments = $this->renderDisqusComments(); 113 break; 114 case 'none': 115 default: 116 $comments = null; 117 break; 118 } 119 return $comments; 120 } 121 122 public function render() { 123 return phutil_tag( 124 'div', 125 array( 126 'class' => 'phame-post', 127 ), 128 array( 129 $this->renderTitle(), 130 $this->renderDatePublished(), 131 $this->renderBody(), 132 $this->renderComments(), 133 )); 134 } 135 136 public function renderWithSummary() { 137 return phutil_tag( 138 'div', 139 array( 140 'class' => 'phame-post', 141 ), 142 array( 143 $this->renderTitle(), 144 $this->renderDatePublished(), 145 $this->renderSummary(), 146 )); 147 } 148 149 private function renderFacebookComments() { 150 $fb_id = PhabricatorFacebookAuthProvider::getFacebookApplicationID(); 151 if (!$fb_id) { 152 return null; 153 } 154 155 $fb_root = phutil_tag('div', 156 array( 157 'id' => 'fb-root', 158 ), 159 ''); 160 161 $c_uri = '//connect.facebook.net/en_US/all.js#xfbml=1&appId='.$fb_id; 162 $fb_js = CelerityStaticResourceResponse::renderInlineScript( 163 jsprintf( 164 '(function(d, s, id) {'. 165 ' var js, fjs = d.getElementsByTagName(s)[0];'. 166 ' if (d.getElementById(id)) return;'. 167 ' js = d.createElement(s); js.id = id;'. 168 ' js.src = %s;'. 169 ' fjs.parentNode.insertBefore(js, fjs);'. 170 '}(document, \'script\', \'facebook-jssdk\'));', 171 $c_uri)); 172 173 174 $uri = $this->getSkin()->getURI('post/'.$this->getPost()->getPhameTitle()); 175 176 $fb_comments = phutil_tag('div', 177 array( 178 'class' => 'fb-comments', 179 'data-href' => $uri, 180 'data-num-posts' => 5, 181 ), 182 ''); 183 184 return phutil_tag( 185 'div', 186 array( 187 'class' => 'phame-comments-facebook', 188 ), 189 array( 190 $fb_root, 191 $fb_js, 192 $fb_comments, 193 )); 194 } 195 196 private function renderDisqusComments() { 197 $disqus_shortname = PhabricatorEnv::getEnvConfig('disqus.shortname'); 198 if (!$disqus_shortname) { 199 return null; 200 } 201 202 $post = $this->getPost(); 203 204 $disqus_thread = phutil_tag('div', 205 array( 206 'id' => 'disqus_thread', 207 )); 208 209 // protip - try some var disqus_developer = 1; action to test locally 210 $disqus_js = CelerityStaticResourceResponse::renderInlineScript( 211 jsprintf( 212 ' var disqus_shortname = %s;'. 213 ' var disqus_identifier = %s;'. 214 ' var disqus_url = %s;'. 215 ' var disqus_title = %s;'. 216 '(function() {'. 217 ' var dsq = document.createElement("script");'. 218 ' dsq.type = "text/javascript";'. 219 ' dsq.async = true;'. 220 ' dsq.src = "//" + disqus_shortname + ".disqus.com/embed.js";'. 221 '(document.getElementsByTagName("head")[0] ||'. 222 ' document.getElementsByTagName("body")[0]).appendChild(dsq);'. 223 '})();', 224 $disqus_shortname, 225 $post->getPHID(), 226 $this->getSkin()->getURI('post/'.$this->getPost()->getPhameTitle()), 227 $post->getTitle())); 228 229 return phutil_tag( 230 'div', 231 array( 232 'class' => 'phame-comments-disqus', 233 ), 234 array( 235 $disqus_thread, 236 $disqus_js, 237 )); 238 } 239 240 }
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 |