mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 09:05:58 +00:00
Fixed author credits in blog
This commit is contained in:
parent
56f9d0c906
commit
947f65241f
@ -11,7 +11,7 @@
|
||||
* @method ManyManyList Authors()
|
||||
*
|
||||
* @author Michael Strong <github@michaelstrong.co.uk>
|
||||
**/
|
||||
**/
|
||||
class BlogPost extends Page {
|
||||
|
||||
private static $db = array(
|
||||
@ -70,6 +70,7 @@ class BlogPost extends Page {
|
||||
* Determine if the given member is an author of this post
|
||||
*
|
||||
* @param Member $member
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isAuthor($member) {
|
||||
@ -88,7 +89,7 @@ class BlogPost extends Page {
|
||||
Requirements::css(BLOGGER_DIR . '/css/cms.css');
|
||||
|
||||
$self =& $this;
|
||||
$this->beforeUpdateCMSFields(function($fields) use ($self) {
|
||||
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
|
||||
|
||||
// Add featured image
|
||||
$fields->insertAfter(
|
||||
@ -173,19 +174,18 @@ class BlogPost extends Page {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update the PublishDate to now, if being published for the first time, and the date hasn't been set to the future.
|
||||
* Update the PublishDate to now, if being published for the first time, and the date hasn't
|
||||
* been set to the future.
|
||||
**/
|
||||
public function onBeforePublish() {
|
||||
if ($this->dbObject('PublishDate')->InPast() && !$this->isPublished()) {
|
||||
if($this->dbObject('PublishDate')->InPast() && !$this->isPublished()) {
|
||||
$this->PublishDate = SS_Datetime::now()->getValue();
|
||||
$this->write();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks the publish date to see if the blog post has actually been published.
|
||||
*
|
||||
@ -230,6 +230,7 @@ class BlogPost extends Page {
|
||||
* Determine if this user can edit the authors list
|
||||
*
|
||||
* @param Member $member
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canEditAuthors($member = null) {
|
||||
@ -294,7 +295,6 @@ class BlogPost extends Page {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a monthly archive link for the current blog post.
|
||||
*
|
||||
@ -319,7 +319,6 @@ class BlogPost extends Page {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a yearly archive link for the current blog post.
|
||||
*
|
||||
@ -331,7 +330,6 @@ class BlogPost extends Page {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the label for BlogPost.Title to 'Post Title' (Rather than 'Page name')
|
||||
*
|
||||
@ -343,6 +341,101 @@ class BlogPost extends Page {
|
||||
return $labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves dynamic and static authors with appropriate join data.
|
||||
*
|
||||
* @return ArrayList
|
||||
*/
|
||||
public function getCredits() {
|
||||
$dynamic = $this->getDynamicAuthors();
|
||||
|
||||
$static = $this->getStaticAuthors();
|
||||
|
||||
return new ArrayList(
|
||||
$this->itemsWithJoins(
|
||||
array_merge($dynamic, $static)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves all dynamic authors linked to this post.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getDynamicAuthors() {
|
||||
$items = [];
|
||||
|
||||
$authors = $this->Authors()->toArray();
|
||||
|
||||
foreach($authors as $author) {
|
||||
$item = new ArrayData(array(
|
||||
'Name' => $author->Name,
|
||||
'Join' => '',
|
||||
'URL' => '',
|
||||
));
|
||||
|
||||
if($author->URLSegment) {
|
||||
$item->URL = $this->Parent->ProfileLink($author->URLSegment);
|
||||
}
|
||||
|
||||
$items[] = $item;
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves all static authors linked to this post.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getStaticAuthors() {
|
||||
$items = [];
|
||||
|
||||
$authors = array_filter(explode(',', $this->AuthorNames));
|
||||
|
||||
foreach($authors as $author) {
|
||||
$item = new ArrayData(array(
|
||||
'Name' => $author,
|
||||
'Join' => '',
|
||||
'URL' => ''
|
||||
));
|
||||
|
||||
$items[] = $item;
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new array with the appropriate join data.
|
||||
*
|
||||
* @param array $items
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function itemsWithJoins(array $items) {
|
||||
$count = count($items);
|
||||
|
||||
for($i = 0; $i < $count; $i++) {
|
||||
if($count === 2 && $i > 0) {
|
||||
$items[$i]->Join = ' and ';
|
||||
}
|
||||
|
||||
if($count > 2) {
|
||||
if($i > 0) {
|
||||
$items[$i]->Join = ', ';
|
||||
}
|
||||
|
||||
if($i + 1 === $count) {
|
||||
$items[$i]->Join = ' and ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -353,7 +446,7 @@ class BlogPost extends Page {
|
||||
* @subpackage blog
|
||||
*
|
||||
* @author Michael Strong <github@michaelstrong.co.uk>
|
||||
**/
|
||||
**/
|
||||
class BlogPost_Controller extends Page_Controller {
|
||||
|
||||
}
|
||||
|
@ -23,18 +23,8 @@
|
||||
<%t Blog.Posted "Posted" %>
|
||||
<a href="$MonthlyArchiveLink">$PublishDate.ago</a>
|
||||
|
||||
<% if $Authors || $AuthorNames %>
|
||||
<% if $Credits %>
|
||||
<%t Blog.By "by" %>
|
||||
<% if $Authors %><% loop $Authors %>
|
||||
<% 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 %>
|
||||
<% loop $Credits %><% if $URL %>$Join<a href="$URL">$Name.XML</a><% else %>$Join$Name.XML<% end_if %><% end_loop %>
|
||||
<% end_if %>
|
||||
</p>
|
||||
|
Loading…
x
Reference in New Issue
Block a user