From 4ee278abb3bbd11cc7f52452c6acc8fb736d3dd5 Mon Sep 17 00:00:00 2001 From: Christopher Pitt Date: Wed, 1 Apr 2015 14:52:46 +1300 Subject: [PATCH] Fixed credits --- code/model/BlogPost.php | 55 +++++++++++++++++++++++++++++++++ templates/Includes/EntryMeta.ss | 15 ++------- 2 files changed, 58 insertions(+), 12 deletions(-) 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 %> +