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
@ -3,15 +3,15 @@
|
||||
/**
|
||||
* An indivisual blog post.
|
||||
*
|
||||
* @package silverstripe
|
||||
* @package silverstripe
|
||||
* @subpackage blog
|
||||
*
|
||||
* @method ManyManyList Categories()
|
||||
* @method ManyManyList Tags()
|
||||
* @method ManyManyList Authors()
|
||||
*
|
||||
* @author Michael Strong <github@michaelstrong.co.uk>
|
||||
**/
|
||||
* @author Michael Strong <github@michaelstrong.co.uk>
|
||||
**/
|
||||
class BlogPost extends Page {
|
||||
|
||||
private static $db = array(
|
||||
@ -62,7 +62,7 @@ class BlogPost extends Page {
|
||||
* variable can be configured using YAML.
|
||||
*
|
||||
* @var boolean
|
||||
**/
|
||||
**/
|
||||
private static $show_in_sitetree = false;
|
||||
|
||||
|
||||
@ -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,26 +174,25 @@ 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.
|
||||
*
|
||||
* @param $member Member|null
|
||||
*
|
||||
* @return boolean
|
||||
**/
|
||||
**/
|
||||
public function canView($member = null) {
|
||||
if(!parent::canView($member)) return false;
|
||||
|
||||
@ -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) {
|
||||
@ -287,29 +288,28 @@ class BlogPost extends Page {
|
||||
*
|
||||
* @param $wordCount int - number of words to display
|
||||
*
|
||||
* @return string
|
||||
**/
|
||||
* @return string
|
||||
**/
|
||||
public function Excerpt($wordCount = 30) {
|
||||
return $this->dbObject("Content")->LimitWordCount($wordCount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a monthly archive link for the current blog post.
|
||||
*
|
||||
* @param $type string day|month|year
|
||||
*
|
||||
* @return string URL
|
||||
**/
|
||||
**/
|
||||
public function getMonthlyArchiveLink($type = "day") {
|
||||
$date = $this->dbObject("PublishDate");
|
||||
if($type != "year") {
|
||||
if($type == "day") {
|
||||
return Controller::join_links(
|
||||
$this->Parent()->Link("archive"),
|
||||
$date->format("Y"),
|
||||
$date->format("m"),
|
||||
$this->Parent()->Link("archive"),
|
||||
$date->format("Y"),
|
||||
$date->format("m"),
|
||||
$date->format("d")
|
||||
);
|
||||
}
|
||||
@ -319,41 +319,134 @@ class BlogPost extends Page {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a yearly archive link for the current blog post.
|
||||
*
|
||||
* @return string URL
|
||||
**/
|
||||
**/
|
||||
public function getYearlyArchiveLink() {
|
||||
$date = $this->dbObject("PublishDate");
|
||||
return Controller::join_links($this->Parent()->Link("archive"), $date->format("Y"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the label for BlogPost.Title to 'Post Title' (Rather than 'Page name')
|
||||
*
|
||||
* @return array
|
||||
**/
|
||||
public function fieldLabels($includerelations = true) {
|
||||
**/
|
||||
public function fieldLabels($includerelations = true) {
|
||||
$labels = parent::fieldLabels($includerelations);
|
||||
$labels['Title'] = _t('BlogPost.PageTitleLabel', "Post Title");
|
||||
$labels['Title'] = _t('BlogPost.PageTitleLabel', "Post Title");
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Blog Post controller
|
||||
*
|
||||
* @package silverstripe
|
||||
* @package silverstripe
|
||||
* @subpackage blog
|
||||
*
|
||||
* @author Michael Strong <github@michaelstrong.co.uk>
|
||||
**/
|
||||
* @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