Fixed credits

This commit is contained in:
Christopher Pitt 2015-04-01 14:52:46 +13:00
parent 56f9d0c906
commit 4ee278abb3
2 changed files with 58 additions and 12 deletions

View File

@ -330,7 +330,62 @@ class BlogPost extends Page {
return Controller::join_links($this->Parent()->Link("archive"), $date->format("Y")); 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') * Sets the label for BlogPost.Title to 'Post Title' (Rather than 'Page name')

View File

@ -23,18 +23,9 @@
<%t Blog.Posted "Posted" %> <%t Blog.Posted "Posted" %>
<a href="$MonthlyArchiveLink">$PublishDate.ago</a> <a href="$MonthlyArchiveLink">$PublishDate.ago</a>
<% if $Authors || $AuthorNames %> <% if $Credits %>
<%t Blog.By "by" %> <%t Blog.By "by" %>
<% if $Authors %><% loop $Authors %> <% loop $Credits %><% if not $First && not $Last %>, <% end_if %><% if not $First && $Last %> and <% end_if %><% if $URLSegment %><a href="$URL">$Name.XML</a><% else %>$Name.XML<% end_if %><% end_loop %>
<% if $URLSegment %>
<a href="{$Up.Parent.ProfileLink($URLSegment)}">$Name.XML</a>
<% else %>
$Name.XML
<% end_if %>
<% if not $Last || $Up.AuthorNames %>,<% end_if %>
<% end_loop %><% end_if %>
<% if $AuthorNames %>
$AuthorNames
<% end_if %>
<% end_if %> <% end_if %>
</p> </p>