gravatar() public method

Returns a URL to this user's gravatar image
public gravatar ( string $rating = 'g', string $imageset = 'mm', integer $size = 80 ) : string
$rating string Gravatar rating, one of [ g | pg | r | x ], default is g.
$imageset string Gravatar default imageset, one of [ 404 | mm | identicon | monsterid | wavatar | retro | blank ], default is mm.
$size integer Gravatar image size, default is 80.
return string
 /**
  * Render the comment
  *
  * This is the default rendering for development/testing/demonstration purposes
  *
  * It may be used for production, but only if it meets your needs already. Typically you'll want to render the comments
  * using your own code in your templates. 
  *
  * @see CommentArray::render()
  * @return string 
  *
  */
 public function renderItem(Comment $comment, $depth = 0)
 {
     $text = $comment->getFormatted('text');
     $cite = $comment->getFormatted('cite');
     $gravatar = '';
     if ($this->options['useGravatar']) {
         $imgUrl = $comment->gravatar($this->options['useGravatar'], $this->options['useGravatarImageset']);
         if ($imgUrl) {
             $gravatar = "\n\t\t<img class='CommentGravatar' src='{$imgUrl}' alt='{$cite}' />";
         }
     }
     $website = '';
     if ($comment->website) {
         $website = $comment->getFormatted('website');
     }
     if ($website) {
         $cite = "<a href='{$website}' rel='nofollow' target='_blank'>{$cite}</a>";
     }
     $created = wireDate($this->options['dateFormat'], $comment->created);
     if (empty($this->options['commentHeader'])) {
         $header = "<span class='CommentCite'>{$cite}</span> <small class='CommentCreated'>{$created}</small> ";
         if ($this->options['useVotes']) {
             $header .= $this->renderVotes($comment);
         }
     } else {
         $header = str_replace(array('{cite}', '{created}'), array($cite, $created), $this->options['commentHeader']);
         if (strpos($header, '{votes}') !== false) {
             $header = str_replace('{votes}', $this->renderVotes($comment), $header);
         }
     }
     $liClass = '';
     $replies = $this->options['depth'] > 0 ? $this->renderList($comment->id, $depth + 1) : '';
     if ($replies) {
         $liClass .= ' CommentHasReplies';
     }
     if ($comment->status == Comment::statusPending) {
         $liClass .= ' CommentStatusPending';
     } else {
         if ($comment->status == Comment::statusSpam) {
             $liClass .= ' CommentStatusSpam';
         }
     }
     $out = "\n\t<li id='Comment{$comment->id}' class='CommentListItem{$liClass}' data-comment='{$comment->id}'>" . $gravatar . "\n\t\t<p class='CommentHeader'>{$header}</p>" . "\n\t\t<div class='CommentText'>" . "\n\t\t\t<p>{$text}</p>" . "\n\t\t</div>";
     if ($this->options['usePermalink']) {
         $permalink = $comment->getPage()->httpUrl;
         $urlSegmentStr = $this->wire('input')->urlSegmentStr;
         if ($urlSegmentStr) {
             $permalink .= rtrim($permalink, '/') . $urlSegmentStr . '/';
         }
         $permalink .= '#Comment' . $comment->id;
         $permalink = "<a class='CommentActionPermalink' href='{$permalink}'>" . $this->_('Permalink') . "</a>";
     } else {
         $permalink = '';
     }
     if ($this->options['depth'] > 0 && $depth < $this->options['depth']) {
         $out .= "\n\t\t<div class='CommentFooter'>" . "\n\t\t\t<p class='CommentAction'>" . "\n\t\t\t\t<a class='CommentActionReply' data-comment-id='{$comment->id}' href='#Comment{$comment->id}'>" . $this->_('Reply') . "</a> " . ($permalink ? "\n\t\t\t\t{$permalink}" : "") . "\n\t\t\t</p>" . "\n\t\t</div>";
         if ($replies) {
             $out .= $replies;
         }
     } else {
         $out .= "\n\t\t<div class='CommentFooter'></div>";
     }
     $out .= "\n\t</li>";
     return $out;
 }
Esempio n. 2
0
 /**
  * Render the comment
  *
  * This is the default rendering for development/testing/demonstration purposes
  *
  * It may be used for production, but only if it meets your needs already. Typically you'll want to render the comments
  * using your own code in your templates. 
  *
  * @see CommentArray::render()
  * @return string 
  *
  */
 public function renderItem(Comment $comment)
 {
     $text = htmlentities(trim($comment->text), ENT_QUOTES, $this->options['encoding']);
     $text = str_replace("\n\n", "</p><p>", $text);
     $text = str_replace("\n", "<br />", $text);
     $cite = htmlentities(trim($comment->cite), ENT_QUOTES, $this->options['encoding']);
     $gravatar = '';
     if ($this->options['useGravatar']) {
         $imgUrl = $comment->gravatar($this->options['useGravatar'], $this->options['useGravatarImageset']);
         if ($imgUrl) {
             $gravatar = "\n\t\t<img class='CommentGravatar' src='{$imgUrl}' alt='{$cite}' />";
         }
     }
     $website = '';
     if ($comment->website) {
         $website = htmlentities(trim($comment->website), ENT_QUOTES, $this->options['encoding']);
     }
     if ($website) {
         $cite = "<a href='{$website}' rel='nofollow' target='_blank'>{$cite}</a>";
     }
     if (strpos($this->options['dateFormat'], '%') !== false) {
         $created = strftime($this->options['dateFormat'], $comment->created);
     } else {
         $created = date($this->options['dateFormat'], $comment->created);
     }
     $header = str_replace(array('{cite}', '{created}'), array($cite, $created), $this->options['commentHeader']);
     if ($comment->status == Comment::statusPending) {
         $liClass = ' CommentStatusPending';
     } else {
         if ($comment->status == Comment::statusSpam) {
             $liClass = ' CommentStatusSpam';
         } else {
             $liClass = '';
         }
     }
     $out = "\n\t<li id='Comment{$comment->id}' class='CommentListItem{$liClass}'>" . $gravatar . "\n\t\t<p class='CommentHeader'>{$header}</p>" . "\n\t\t<div class='CommentText'>" . "\n\t\t\t<p>{$text}</p>" . "\n\t\t</div>" . "\n\t</li>";
     return $out;
 }