diff --git a/code/model/BlogPost.php b/code/model/BlogPost.php index dd699d7..5c32998 100644 --- a/code/model/BlogPost.php +++ b/code/model/BlogPost.php @@ -330,7 +330,62 @@ class BlogPost extends Page { return Controller::join_links($this->Parent()->Link("archive"), $date->format("Y")); } + /** + * Resolves static and dynamic authors linked to this post. + * + * @return ArrayList + */ + public function getCredits() + { + $list = new ArrayList(); + $list->merge($this->getDynamicCredits()); + $list->merge($this->getStaticCredits()); + + return $list->sort('Name'); + } + + /** + * Resolves dynamic authors linked to this post. + * + * @return ArrayList + */ + protected function getDynamicCredits() + { + $items = new ArrayList(); + + foreach($this->Authors() as $author) { + $items->push( + $author->customise(array( + 'URL' => $this->Parent->ProfileLink($author->URLSegment), + )) + ); + } + + return $items; + } + + /** + * Resolves static authors linked to this post. + * + * @return ArrayList + */ + protected function getStaticCredits() + { + $items = new ArrayList(); + + $authors = array_filter(preg_split('/\s*,\s*/', $this->AuthorNames)); + + foreach ($authors as $author) { + $item = new ArrayData(array( + 'Name' => $author, + )); + + $items->push($item); + } + + return $items; + } /** * Sets the label for BlogPost.Title to 'Post Title' (Rather than 'Page name') diff --git a/templates/Includes/EntryMeta.ss b/templates/Includes/EntryMeta.ss index 0569388..e9cc973 100644 --- a/templates/Includes/EntryMeta.ss +++ b/templates/Includes/EntryMeta.ss @@ -23,18 +23,9 @@ <%t Blog.Posted "Posted" %> $PublishDate.ago - <% if $Authors || $AuthorNames %> + <% if $Credits %> <%t Blog.By "by" %> - <% if $Authors %><% loop $Authors %> - <% if $URLSegment %> - $Name.XML - <% else %> - $Name.XML - <% end_if %> - <% if not $Last || $Up.AuthorNames %>,<% end_if %> - <% end_loop %><% end_if %> - <% if $AuthorNames %> - $AuthorNames - <% end_if %> + <% loop $Credits %><% if not $First && not $Last %>, <% end_if %><% if not $First && $Last %> and <% end_if %><% if $URLSegment %>$Name.XML<% else %>$Name.XML<% end_if %><% end_loop %> <% end_if %> +