2013-07-21 12:23:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blog Holder
|
|
|
|
*
|
|
|
|
* @package silverstripe
|
|
|
|
* @subpackage blog
|
2015-04-21 06:47:46 +02:00
|
|
|
*
|
2015-03-06 03:52:07 +01:00
|
|
|
* @method HasManyList Tags() List of tags in this blog
|
|
|
|
* @method HasManyList Categories() List of categories in this blog
|
|
|
|
* @method ManyManyList Editors() List of editors
|
|
|
|
* @method ManyManyList Writers() List of writers
|
|
|
|
* @method ManyManyList Contributors() List of contributors
|
2015-05-09 16:33:12 +02:00
|
|
|
*/
|
2015-03-06 03:52:07 +01:00
|
|
|
class Blog extends Page implements PermissionProvider {
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Permission for user management.
|
2015-03-06 03:52:07 +01:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const MANAGE_USERS = 'BLOG_MANAGE_USERS';
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* If true, users assigned as editor, writer, or contributor will be automatically granted
|
|
|
|
* CMS_ACCESS_CMSMain permission. If false, only users with this permission already may be
|
|
|
|
* assigned.
|
2015-03-06 03:52:07 +01:00
|
|
|
*
|
|
|
|
* @config
|
2015-05-09 16:33:12 +02:00
|
|
|
*
|
|
|
|
* @var boolean
|
2015-03-06 03:52:07 +01:00
|
|
|
*/
|
|
|
|
private static $grant_user_access = true;
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Permission to either require, or grant to users assigned to work on this blog.
|
2015-03-06 03:52:07 +01:00
|
|
|
*
|
|
|
|
* @config
|
2015-05-09 16:33:12 +02:00
|
|
|
*
|
|
|
|
* @var string
|
2015-03-06 03:52:07 +01:00
|
|
|
*/
|
|
|
|
private static $grant_user_permission = 'CMS_ACCESS_CMSMain';
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Group code to assign newly granted users to.
|
2015-03-06 03:52:07 +01:00
|
|
|
*
|
|
|
|
* @config
|
2015-05-09 16:33:12 +02:00
|
|
|
*
|
|
|
|
* @var string
|
2015-03-06 03:52:07 +01:00
|
|
|
*/
|
|
|
|
private static $grant_user_group = 'blog-users';
|
2013-07-21 12:23:35 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-08-04 18:38:26 +02:00
|
|
|
private static $db = array(
|
2015-05-09 16:33:12 +02:00
|
|
|
'PostsPerPage' => 'Int',
|
2013-08-04 18:38:26 +02:00
|
|
|
);
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-07-21 12:23:35 +02:00
|
|
|
private static $has_many = array(
|
2015-05-09 16:33:12 +02:00
|
|
|
'Tags' => 'BlogTag',
|
|
|
|
'Categories' => 'BlogCategory',
|
2013-07-21 12:23:35 +02:00
|
|
|
);
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2015-03-06 03:52:07 +01:00
|
|
|
private static $many_many = array(
|
|
|
|
'Editors' => 'Member',
|
|
|
|
'Writers' => 'Member',
|
|
|
|
'Contributors' => 'Member',
|
|
|
|
);
|
2015-04-21 06:47:46 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-07-21 12:23:35 +02:00
|
|
|
private static $allowed_children = array(
|
2015-05-09 16:33:12 +02:00
|
|
|
'BlogPost',
|
2013-07-21 12:23:35 +02:00
|
|
|
);
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-08-04 18:38:26 +02:00
|
|
|
private static $extensions = array(
|
2015-05-09 16:33:12 +02:00
|
|
|
'BlogFilter',
|
2013-08-04 18:38:26 +02:00
|
|
|
);
|
2013-07-21 12:23:35 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-08-11 00:34:46 +02:00
|
|
|
private static $defaults = array(
|
2015-05-09 16:33:12 +02:00
|
|
|
'ProvideComments' => false,
|
2015-05-13 05:12:48 +02:00
|
|
|
'PostsPerPage' => 10,
|
2013-08-11 00:34:46 +02:00
|
|
|
);
|
2013-07-21 12:23:35 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2014-12-11 11:42:36 +01:00
|
|
|
private static $description = 'Adds a blog to your website.';
|
2013-07-21 12:23:35 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2013-07-21 12:23:35 +02:00
|
|
|
public function getCMSFields() {
|
2015-04-09 03:03:16 +02:00
|
|
|
Requirements::css(BLOGGER_DIR . '/css/cms.css');
|
2015-04-23 04:27:30 +02:00
|
|
|
Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
|
2015-04-09 03:03:16 +02:00
|
|
|
|
2014-07-27 07:34:43 +02:00
|
|
|
$self =& $this;
|
2015-03-25 02:59:58 +01:00
|
|
|
|
2015-04-21 06:47:46 +02:00
|
|
|
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
|
|
|
|
if(!$self->canEdit()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-04 18:38:26 +02:00
|
|
|
|
2014-06-13 17:19:15 +02:00
|
|
|
$categories = GridField::create(
|
2015-05-09 16:33:12 +02:00
|
|
|
'Categories',
|
|
|
|
_t('Blog.Categories', 'Categories'),
|
2014-07-27 07:34:43 +02:00
|
|
|
$self->Categories(),
|
2015-04-21 06:47:46 +02:00
|
|
|
GridFieldCategorisationConfig::create(15, $self->Categories(), 'BlogCategory', 'Categories', 'BlogPosts')
|
2014-06-13 17:19:15 +02:00
|
|
|
);
|
2013-08-04 18:38:26 +02:00
|
|
|
|
2014-06-13 17:19:15 +02:00
|
|
|
$tags = GridField::create(
|
2015-05-09 16:33:12 +02:00
|
|
|
'Tags',
|
|
|
|
_t('Blog.Tags', 'Tags'),
|
2014-07-27 07:34:43 +02:00
|
|
|
$self->Tags(),
|
2015-04-21 09:17:27 +02:00
|
|
|
GridFieldCategorisationConfig::create(15, $self->Tags(), 'BlogTag', 'Tags', 'BlogPosts')
|
2014-06-13 17:19:15 +02:00
|
|
|
);
|
2013-08-04 18:38:26 +02:00
|
|
|
|
2015-05-13 23:12:48 +02:00
|
|
|
/**
|
|
|
|
* @var FieldList $fields
|
|
|
|
*/
|
2015-05-09 16:33:12 +02:00
|
|
|
$fields->addFieldsToTab('Root.Categorisation', array(
|
2014-06-13 17:19:15 +02:00
|
|
|
$categories,
|
|
|
|
$tags
|
|
|
|
));
|
2015-04-21 06:47:46 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$fields->findOrMakeTab('Root.Categorisation')->addExtraClass('blog-cms-categorisation');
|
|
|
|
});
|
2015-04-21 06:47:46 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
return parent::getCMSFields();
|
2013-08-04 18:38:26 +02:00
|
|
|
}
|
|
|
|
|
2015-03-06 03:52:07 +01:00
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* {@inheritdoc}
|
2015-03-06 03:52:07 +01:00
|
|
|
*/
|
2015-05-09 16:33:12 +02:00
|
|
|
public function canEdit($member = null) {
|
|
|
|
$member = $this->getMember($member);
|
|
|
|
|
|
|
|
if($this->isEditor($member)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::canEdit($member);
|
2015-03-06 03:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* @param null|int|Member $member
|
2015-04-21 06:47:46 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return null|Member
|
2015-03-06 03:52:07 +01:00
|
|
|
*/
|
2015-05-09 16:33:12 +02:00
|
|
|
protected function getMember($member = null) {
|
|
|
|
if(!$member) {
|
|
|
|
$member = Member::currentUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_int($member)) {
|
|
|
|
$member = Member::get()->byID($member);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $member;
|
2015-03-06 03:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Check if this member is an editor of the blog.
|
2015-03-06 03:52:07 +01:00
|
|
|
*
|
|
|
|
* @param Member $member
|
2015-04-21 06:47:46 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return bool
|
2015-03-06 03:52:07 +01:00
|
|
|
*/
|
2015-05-09 16:33:12 +02:00
|
|
|
public function isEditor($member) {
|
|
|
|
$isEditor = $this->isMemberOf($member, $this->Editors());
|
|
|
|
$this->extend('updateIsEditor', $isEditor, $member);
|
|
|
|
|
|
|
|
return $isEditor;
|
2015-03-06 03:52:07 +01:00
|
|
|
}
|
|
|
|
|
2015-04-09 05:45:12 +02:00
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Determine if the given member belongs to the given relation.
|
2015-04-09 05:45:12 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @param Member $member
|
|
|
|
* @param DataList $relation
|
2015-04-21 06:47:46 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return bool
|
2015-04-09 05:45:12 +02:00
|
|
|
*/
|
2015-05-09 16:33:12 +02:00
|
|
|
protected function isMemberOf($member, $relation) {
|
|
|
|
if(!$member || !$member->exists()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-09 05:45:12 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
if($relation instanceof UnsavedRelationList) {
|
|
|
|
return in_array($member->ID, $relation->getIDList());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $relation->byID($member->ID) !== null;
|
2015-04-09 05:45:12 +02:00
|
|
|
}
|
|
|
|
|
2015-03-06 03:52:07 +01:00
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Determine the role of the given member.
|
2015-03-06 03:52:07 +01:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* Call be called via template to determine the current user.
|
2015-04-21 06:47:46 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @example "Hello $RoleOf($CurrentMember.ID)"
|
|
|
|
*
|
|
|
|
* @param int|Member $member
|
|
|
|
*
|
|
|
|
* @return null|string
|
2015-03-06 03:52:07 +01:00
|
|
|
*/
|
2015-05-09 16:33:12 +02:00
|
|
|
public function RoleOf($member) {
|
|
|
|
if(is_numeric($member)) {
|
|
|
|
$member = DataObject::get_by_id('Member', $member);
|
2015-03-06 03:52:07 +01:00
|
|
|
}
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
if(!$member) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-03-06 03:52:07 +01:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
if($this->isEditor($member)) {
|
|
|
|
return _t('Blog.EDITOR', 'Editor');
|
|
|
|
}
|
2015-03-06 03:52:07 +01:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
if($this->isWriter($member)) {
|
|
|
|
return _t('Blog.WRITER', 'Writer');
|
|
|
|
}
|
2015-04-21 06:47:46 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
if($this->isContributor($member)) {
|
|
|
|
return _t('Blog.CONTRIBUTOR', 'Contributor');
|
|
|
|
}
|
2015-03-06 03:52:07 +01:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
return null;
|
2015-03-06 03:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Check if this member is a writer of the blog.
|
2015-03-06 03:52:07 +01:00
|
|
|
*
|
|
|
|
* @param Member $member
|
2015-04-21 06:47:46 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return bool
|
2015-03-06 03:52:07 +01:00
|
|
|
*/
|
2015-05-09 16:33:12 +02:00
|
|
|
public function isWriter($member) {
|
|
|
|
$isWriter = $this->isMemberOf($member, $this->Writers());
|
|
|
|
$this->extend('updateIsWriter', $isWriter, $member);
|
2015-03-06 03:52:07 +01:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
return $isWriter;
|
2015-03-06 03:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Check if this member is a contributor of the blog.
|
2015-03-06 03:52:07 +01:00
|
|
|
*
|
|
|
|
* @param Member $member
|
2015-04-21 06:47:46 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return bool
|
2015-03-06 03:52:07 +01:00
|
|
|
*/
|
2015-05-09 16:33:12 +02:00
|
|
|
public function isContributor($member) {
|
|
|
|
$isContributor = $this->isMemberOf($member, $this->Contributors());
|
|
|
|
$this->extend('updateIsContributor', $isContributor, $member);
|
2015-03-06 03:52:07 +01:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
return $isContributor;
|
2015-03-06 03:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* {@inheritdoc}
|
2015-03-06 03:52:07 +01:00
|
|
|
*/
|
|
|
|
public function canAddChildren($member = null) {
|
2015-05-09 16:33:12 +02:00
|
|
|
$member = $this->getMember($member);
|
2015-03-06 03:52:07 +01:00
|
|
|
|
|
|
|
if($this->isEditor($member) || $this->isWriter($member) || $this->isContributor($member)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::canAddChildren($member);
|
|
|
|
}
|
2013-08-04 18:38:26 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2013-08-04 18:38:26 +02:00
|
|
|
public function getSettingsFields() {
|
|
|
|
$fields = parent::getSettingsFields();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
|
|
|
$fields->addFieldToTab('Root.Settings',
|
|
|
|
NumericField::create('PostsPerPage', _t('Blog.PostsPerPage', 'Posts Per Page'))
|
2014-02-16 06:19:26 +01:00
|
|
|
);
|
2015-03-06 03:52:07 +01:00
|
|
|
|
|
|
|
$members = $this->getCandidateUsers()->map()->toArray();
|
|
|
|
|
|
|
|
$editorField = ListboxField::create('Editors', 'Editors', $members)
|
|
|
|
->setMultiple(true)
|
2015-04-09 03:03:16 +02:00
|
|
|
->setRightTitle('<a class="toggle-description">help</a>')
|
|
|
|
->setDescription('
|
2015-04-13 01:45:57 +02:00
|
|
|
An editor has control over specific Blogs, and all posts included within it. Short of being able to assign other editors to a blog, they are able to handle most changes to their assigned blog.<br />
|
2015-04-09 03:03:16 +02:00
|
|
|
<br />
|
|
|
|
Editors have these permissions:<br />
|
|
|
|
<br />
|
|
|
|
Update or publish any BlogPost in their Blog<br />
|
|
|
|
Update or publish their Blog<br />
|
|
|
|
Assign/unassign writers to their Blog<br />
|
|
|
|
Assign/unassign contributors to their Blog<br />
|
|
|
|
Assign/unassign any member as an author of a particular BlogPost
|
|
|
|
');
|
|
|
|
|
2015-03-06 03:52:07 +01:00
|
|
|
if(!$this->canEditEditors()) {
|
|
|
|
$editorField = $editorField->performDisabledTransformation();
|
|
|
|
}
|
|
|
|
|
|
|
|
$writerField = ListboxField::create('Writers', 'Writers', $members)
|
|
|
|
->setMultiple(true)
|
2015-04-09 03:03:16 +02:00
|
|
|
->setRightTitle('<a class="toggle-description">help</a>')
|
|
|
|
->setDescription('
|
2015-04-13 01:45:57 +02:00
|
|
|
A writer has full control over creating, editing and publishing BlogPosts they have authored or have been assigned to. Writers are unable to edit BlogPosts to which they are not assigned.<br />
|
2015-04-09 03:03:16 +02:00
|
|
|
<br />
|
|
|
|
Writers have these permissions:<br />
|
|
|
|
<br />
|
2015-04-13 01:45:57 +02:00
|
|
|
Update or publish any BlogPost they have authored or have been assigned to<br />
|
|
|
|
Assign/unassign any member as an author of a particular BlogPost they have authored or have been assigned to
|
2015-04-09 03:03:16 +02:00
|
|
|
');
|
|
|
|
|
2015-03-06 03:52:07 +01:00
|
|
|
if(!$this->canEditWriters()) {
|
|
|
|
$writerField = $writerField->performDisabledTransformation();
|
|
|
|
}
|
|
|
|
|
|
|
|
$contributorField = ListboxField::create('Contributors', 'Contributors', $members)
|
|
|
|
->setMultiple(true)
|
2015-04-09 03:03:16 +02:00
|
|
|
->setRightTitle('<a class="toggle-description">help</a>')
|
|
|
|
->setDescription('
|
2015-04-13 01:45:57 +02:00
|
|
|
Contributors have the ability to create or edit BlogPosts, but are unable to publish without authorisation of an editor. They are also unable to assign other contributing authors to any of their BlogPosts.<br />
|
2015-04-09 03:03:16 +02:00
|
|
|
<br />
|
|
|
|
Contributors have these permissions:<br />
|
|
|
|
<br />
|
2015-04-13 01:45:57 +02:00
|
|
|
Update any BlogPost they have authored or have been assigned to
|
2015-04-09 03:03:16 +02:00
|
|
|
');
|
2015-04-21 06:47:46 +02:00
|
|
|
|
2015-03-06 03:52:07 +01:00
|
|
|
if(!$this->canEditContributors()) {
|
|
|
|
$contributorField = $contributorField->performDisabledTransformation();
|
|
|
|
}
|
2015-04-21 06:47:46 +02:00
|
|
|
|
2015-03-06 03:52:07 +01:00
|
|
|
$fields->addFieldsToTab('Root.Users', array(
|
|
|
|
$editorField,
|
|
|
|
$writerField,
|
|
|
|
$contributorField
|
|
|
|
));
|
|
|
|
|
2013-07-21 12:23:35 +02:00
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* Gets the list of user candidates to be assigned to assist with this blog.
|
|
|
|
*
|
|
|
|
* @return SS_List
|
|
|
|
*/
|
|
|
|
protected function getCandidateUsers() {
|
|
|
|
if($this->config()->grant_user_access) {
|
|
|
|
return Member::get();
|
|
|
|
} else {
|
|
|
|
return Permission::get_members_by_permission(
|
|
|
|
$this->config()->grant_user_permission
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2013-07-21 12:23:35 +02:00
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Determine if this user can edit the editors list.
|
2013-07-21 12:23:35 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @param int|Member $member
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canEditEditors($member = null) {
|
|
|
|
$member = $this->getMember($member);
|
|
|
|
|
|
|
|
$extended = $this->extendedCan('canEditEditors', $member);
|
|
|
|
|
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Permission::checkMember($member, self::MANAGE_USERS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if this user can edit writers list.
|
|
|
|
*
|
|
|
|
* @param int|Member $member
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canEditWriters($member = null) {
|
|
|
|
$member = $this->getMember($member);
|
|
|
|
|
|
|
|
$extended = $this->extendedCan('canEditWriters', $member);
|
|
|
|
|
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($this->isEditor($member)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Permission::checkMember($member, self::MANAGE_USERS);
|
2013-07-21 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* Determines if this user can edit the contributors list.
|
|
|
|
*
|
|
|
|
* @param int|Member $member
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canEditContributors($member = null) {
|
|
|
|
$member = $this->getMember($member);
|
|
|
|
|
|
|
|
$extended = $this->extendedCan('canEditContributors', $member);
|
|
|
|
|
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($this->isEditor($member)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Permission::checkMember($member, self::MANAGE_USERS);
|
|
|
|
}
|
2013-10-10 00:09:28 +02:00
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Returns BlogPosts for a given date period.
|
2013-10-10 00:09:28 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @param int $year
|
|
|
|
* @param null|int $month
|
|
|
|
* @param null|int $day
|
2013-10-10 00:09:28 +02:00
|
|
|
*
|
|
|
|
* @return DataList
|
2015-05-09 16:33:12 +02:00
|
|
|
*/
|
2013-10-10 00:09:28 +02:00
|
|
|
public function getArchivedBlogPosts($year, $month = null, $day = null) {
|
|
|
|
$query = $this->getBlogPosts()->dataQuery();
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$stage = $query->getQueryParam('Versioned.stage');
|
|
|
|
|
2015-05-13 23:12:48 +02:00
|
|
|
if($stage) {
|
2015-05-09 16:33:12 +02:00
|
|
|
$stage = '_' . $stage;
|
|
|
|
}
|
|
|
|
|
2015-05-14 01:11:50 +02:00
|
|
|
$query->innerJoin('BlogPost', sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage));
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-05-14 01:11:50 +02:00
|
|
|
$query->where(sprintf('YEAR("PublishDate") = \'%s\'', Convert::raw2sql($year)));
|
2013-10-10 00:09:28 +02:00
|
|
|
|
|
|
|
if($month) {
|
2015-05-14 01:11:50 +02:00
|
|
|
$query->where(sprintf('MONTH("PublishDate") = \'%s\'', Convert::raw2sql($month)));
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2013-10-10 00:09:28 +02:00
|
|
|
if($day) {
|
2015-05-14 01:11:50 +02:00
|
|
|
$query->where(sprintf('DAY("PublishDate") = \'%s\'', Convert::raw2sql($day)));
|
2013-10-10 00:09:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getBlogPosts()->setDataQuery($query);
|
|
|
|
}
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* Return blog posts.
|
|
|
|
*
|
|
|
|
* @return DataList of BlogPost objects
|
|
|
|
*/
|
|
|
|
public function getBlogPosts() {
|
|
|
|
$blogPosts = BlogPost::get()->filter('ParentID', $this->ID);
|
|
|
|
|
|
|
|
$this->extend('updateGetBlogPosts', $blogPosts);
|
|
|
|
|
|
|
|
return $blogPosts;
|
|
|
|
}
|
2014-12-11 11:42:36 +01:00
|
|
|
|
2015-03-22 23:18:02 +01:00
|
|
|
/**
|
|
|
|
* Get a link to a Member profile.
|
2015-04-21 06:47:46 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @param string $urlSegment
|
2015-04-21 06:47:46 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return string
|
2015-03-22 23:18:02 +01:00
|
|
|
*/
|
|
|
|
public function ProfileLink($urlSegment) {
|
|
|
|
return Controller::join_links($this->Link(), 'profile', $urlSegment);
|
|
|
|
}
|
|
|
|
|
2014-12-11 11:42:36 +01:00
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* This sets the title for our gridfield.
|
2014-12-11 11:42:36 +01:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLumberjackTitle() {
|
|
|
|
return _t('Blog.LumberjackTitle', 'Blog Posts');
|
|
|
|
}
|
|
|
|
|
2015-02-05 05:30:27 +01:00
|
|
|
/**
|
|
|
|
* This overwrites lumberjacks default gridfield config.
|
|
|
|
*
|
|
|
|
* @return GridFieldConfig
|
|
|
|
*/
|
|
|
|
public function getLumberjackGridFieldConfig() {
|
2015-02-07 00:52:45 +01:00
|
|
|
return GridFieldConfig_BlogPost::create();
|
2015-02-05 05:30:27 +01:00
|
|
|
}
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2015-03-06 03:52:07 +01:00
|
|
|
public function providePermissions() {
|
|
|
|
return array(
|
|
|
|
Blog::MANAGE_USERS => array(
|
|
|
|
'name' => _t(
|
|
|
|
'Blog.PERMISSION_MANAGE_USERS_DESCRIPTION',
|
|
|
|
'Manage users for individual blogs'
|
|
|
|
),
|
|
|
|
'help' => _t(
|
|
|
|
'Blog.PERMISSION_MANAGE_USERS_HELP',
|
|
|
|
'Allow assignment of Editors, Writers, or Contributors to blogs'
|
|
|
|
),
|
|
|
|
'category' => _t('Blog.PERMISSIONS_CATEGORY', 'Blog permissions'),
|
|
|
|
'sort' => 100
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* {@inheritdoc}
|
2015-03-06 03:52:07 +01:00
|
|
|
*/
|
2015-05-09 16:33:12 +02:00
|
|
|
protected function onBeforeWrite() {
|
|
|
|
parent::onBeforeWrite();
|
|
|
|
$this->assignGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assign users as necessary to the blog group.
|
|
|
|
*/
|
|
|
|
protected function assignGroup() {
|
|
|
|
if(!$this->config()->grant_user_access) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$group = $this->getUserGroup();
|
|
|
|
|
|
|
|
foreach(array($this->Editors(), $this->Writers(), $this->Contributors()) as $levels) {
|
|
|
|
foreach($levels as $user) {
|
|
|
|
if(!$user->inGroup($group)) {
|
|
|
|
$user->Groups()->add($group);
|
|
|
|
}
|
|
|
|
}
|
2015-03-06 03:52:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Gets or creates the group used to assign CMS access.
|
2015-03-06 03:52:07 +01:00
|
|
|
*
|
|
|
|
* @return Group
|
|
|
|
*/
|
|
|
|
protected function getUserGroup() {
|
|
|
|
$code = $this->config()->grant_user_group;
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-03-06 03:52:07 +01:00
|
|
|
$group = Group::get()->filter('Code', $code)->first();
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
if($group) {
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
2015-03-06 03:52:07 +01:00
|
|
|
$group = new Group();
|
|
|
|
$group->Title = 'Blog users';
|
|
|
|
$group->Code = $code;
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-03-06 03:52:07 +01:00
|
|
|
$group->write();
|
|
|
|
|
|
|
|
$permission = new Permission();
|
|
|
|
$permission->Code = $this->config()->grant_user_permission;
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-03-06 03:52:07 +01:00
|
|
|
$group->Permissions()->add($permission);
|
|
|
|
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
2013-07-21 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package silverstripe
|
|
|
|
* @subpackage blog
|
2015-05-09 16:33:12 +02:00
|
|
|
*/
|
2013-07-21 12:23:35 +02:00
|
|
|
class Blog_Controller extends Page_Controller {
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-07-21 12:23:35 +02:00
|
|
|
private static $allowed_actions = array(
|
|
|
|
'archive',
|
|
|
|
'tag',
|
|
|
|
'category',
|
2013-08-11 00:34:46 +02:00
|
|
|
'rss',
|
2015-05-09 16:33:12 +02:00
|
|
|
'profile',
|
2013-07-21 12:23:35 +02:00
|
|
|
);
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-07-21 12:23:35 +02:00
|
|
|
private static $url_handlers = array(
|
2013-08-04 18:38:26 +02:00
|
|
|
'tag/$Tag!' => 'tag',
|
|
|
|
'category/$Category!' => 'category',
|
2013-08-11 00:34:46 +02:00
|
|
|
'archive/$Year!/$Month/$Day' => 'archive',
|
2015-05-09 16:33:12 +02:00
|
|
|
'profile/$URLSegment!' => 'profile',
|
2013-07-21 12:23:35 +02:00
|
|
|
);
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2015-04-09 07:25:52 +02:00
|
|
|
private static $casting = array(
|
|
|
|
'MetaTitle' => 'Text',
|
2015-05-09 16:33:12 +02:00
|
|
|
'FilterDescription' => 'Text',
|
2015-04-09 07:25:52 +02:00
|
|
|
);
|
|
|
|
|
2015-04-21 06:47:46 +02:00
|
|
|
/**
|
2013-08-04 18:38:26 +02:00
|
|
|
* The current Blog Post DataList query.
|
|
|
|
*
|
|
|
|
* @var DataList
|
2015-05-09 16:33:12 +02:00
|
|
|
*/
|
2013-07-21 12:23:35 +02:00
|
|
|
protected $blogPosts;
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-07-21 12:23:35 +02:00
|
|
|
public function index() {
|
2015-05-13 23:12:48 +02:00
|
|
|
/**
|
|
|
|
* @var Blog $dataRecord
|
|
|
|
*/
|
|
|
|
$dataRecord = $this->dataRecord;
|
|
|
|
|
|
|
|
$this->blogPosts = $dataRecord->getBlogPosts();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2013-07-21 12:23:35 +02:00
|
|
|
return $this->render();
|
|
|
|
}
|
|
|
|
|
2015-03-22 23:18:02 +01:00
|
|
|
/**
|
|
|
|
* Renders a Blog Member's profile.
|
|
|
|
*
|
|
|
|
* @return SS_HTTPResponse
|
2015-05-09 16:33:12 +02:00
|
|
|
*/
|
2015-03-22 23:18:02 +01:00
|
|
|
public function profile() {
|
|
|
|
$profile = $this->getCurrentProfile();
|
|
|
|
|
|
|
|
if(!$profile) {
|
|
|
|
return $this->httpError(404, 'Not Found');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->blogPosts = $this->getCurrentProfilePosts();
|
|
|
|
|
|
|
|
return $this->render();
|
|
|
|
}
|
2013-07-21 12:23:35 +02:00
|
|
|
|
2015-03-22 23:18:02 +01:00
|
|
|
/**
|
|
|
|
* Get the Member associated with the current URL segment.
|
2015-04-21 06:47:46 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return null|Member
|
|
|
|
*/
|
2015-03-22 23:18:02 +01:00
|
|
|
public function getCurrentProfile() {
|
|
|
|
$urlSegment = $this->request->param('URLSegment');
|
|
|
|
|
|
|
|
if($urlSegment) {
|
|
|
|
return Member::get()
|
|
|
|
->filter('URLSegment', $urlSegment)
|
|
|
|
->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Get posts related to the current Member profile.
|
2015-04-21 06:47:46 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return null|DataList
|
|
|
|
*/
|
2015-03-22 23:18:02 +01:00
|
|
|
public function getCurrentProfilePosts() {
|
|
|
|
$profile = $this->getCurrentProfile();
|
|
|
|
|
|
|
|
if($profile) {
|
|
|
|
return $profile->AuthoredPosts()->filter('ParentID', $this->ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2013-08-04 18:38:26 +02:00
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Renders an archive for a specified date. This can be by year or year/month.
|
2013-08-04 18:38:26 +02:00
|
|
|
*
|
2015-05-13 23:12:48 +02:00
|
|
|
* @return null|SS_HTTPResponse
|
2015-05-09 16:33:12 +02:00
|
|
|
*/
|
2013-07-21 12:23:35 +02:00
|
|
|
public function archive() {
|
2015-05-13 23:12:48 +02:00
|
|
|
/**
|
|
|
|
* @var Blog $dataRecord
|
|
|
|
*/
|
|
|
|
$dataRecord = $this->dataRecord;
|
|
|
|
|
2013-08-04 18:38:26 +02:00
|
|
|
$year = $this->getArchiveYear();
|
|
|
|
$month = $this->getArchiveMonth();
|
2013-08-11 00:34:46 +02:00
|
|
|
$day = $this->getArchiveDay();
|
2013-08-04 18:38:26 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
if($this->request->param('Month') && !$month) {
|
2015-05-13 23:12:48 +02:00
|
|
|
$this->httpError(404, 'Not Found');
|
2014-04-10 14:44:17 +02:00
|
|
|
}
|
2013-08-04 18:38:26 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
if($month && $this->request->param('Day') && !$day) {
|
2015-05-13 23:12:48 +02:00
|
|
|
$this->httpError(404, 'Not Found');
|
2013-08-11 00:34:46 +02:00
|
|
|
}
|
2013-08-04 18:38:26 +02:00
|
|
|
|
2013-08-11 00:34:46 +02:00
|
|
|
if($year) {
|
2015-05-13 23:12:48 +02:00
|
|
|
$this->blogPosts = $dataRecord->getArchivedBlogPosts($year, $month, $day);
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2013-08-04 18:38:26 +02:00
|
|
|
return $this->render();
|
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-05-13 23:12:48 +02:00
|
|
|
$this->httpError(404, 'Not Found');
|
|
|
|
|
|
|
|
return null;
|
2015-05-09 16:33:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches the archive year from the url.
|
|
|
|
*
|
|
|
|
* @return null|int
|
|
|
|
*/
|
|
|
|
public function getArchiveYear() {
|
|
|
|
$year = $this->request->param('Year');
|
|
|
|
|
|
|
|
if(preg_match('/^[0-9]{4}$/', $year)) {
|
|
|
|
return (int) $year;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2013-07-21 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* Fetches the archive money from the url.
|
|
|
|
*
|
|
|
|
* @return null|int
|
|
|
|
*/
|
|
|
|
public function getArchiveMonth() {
|
|
|
|
$month = $this->request->param('Month');
|
|
|
|
|
|
|
|
if(preg_match('/^[0-9]{1,2}$/', $month)) {
|
|
|
|
if($month > 0 && $month < 13) {
|
|
|
|
if(checkdate($month, 01, $this->getArchiveYear())) {
|
|
|
|
return (int) $month;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches the archive day from the url.
|
|
|
|
*
|
|
|
|
* @return null|int
|
|
|
|
*/
|
|
|
|
public function getArchiveDay() {
|
|
|
|
$day = $this->request->param('Day');
|
|
|
|
|
|
|
|
if(preg_match('/^[0-9]{1,2}$/', $day)) {
|
|
|
|
if(checkdate($this->getArchiveMonth(), $day, $this->getArchiveYear())) {
|
|
|
|
return (int) $day;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2013-07-21 12:23:35 +02:00
|
|
|
|
2013-08-04 18:38:26 +02:00
|
|
|
/**
|
|
|
|
* Renders the blog posts for a given tag.
|
|
|
|
*
|
2015-05-13 23:12:48 +02:00
|
|
|
* @return null|SS_HTTPResponse
|
2015-05-09 16:33:12 +02:00
|
|
|
*/
|
2013-07-21 12:23:35 +02:00
|
|
|
public function tag() {
|
2013-08-04 18:38:26 +02:00
|
|
|
$tag = $this->getCurrentTag();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2013-07-21 12:23:35 +02:00
|
|
|
if($tag) {
|
2013-08-04 18:38:26 +02:00
|
|
|
$this->blogPosts = $tag->BlogPosts();
|
|
|
|
return $this->render();
|
2013-07-21 12:23:35 +02:00
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-05-13 23:12:48 +02:00
|
|
|
$this->httpError(404, 'Not Found');
|
|
|
|
|
|
|
|
return null;
|
2013-07-21 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* Tag Getter for use in templates.
|
|
|
|
*
|
|
|
|
* @return null|BlogTag
|
|
|
|
*/
|
|
|
|
public function getCurrentTag() {
|
2015-05-13 23:12:48 +02:00
|
|
|
/**
|
|
|
|
* @var Blog $dataRecord
|
|
|
|
*/
|
|
|
|
$dataRecord = $this->dataRecord;
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$tag = $this->request->param('Tag');
|
|
|
|
|
|
|
|
if($tag) {
|
2015-05-13 23:12:48 +02:00
|
|
|
return $dataRecord->Tags()
|
2015-05-09 16:33:12 +02:00
|
|
|
->filter('URLSegment', $tag)
|
|
|
|
->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2013-08-04 18:38:26 +02:00
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Renders the blog posts for a given category.
|
2013-08-04 18:38:26 +02:00
|
|
|
*
|
2015-05-13 23:12:48 +02:00
|
|
|
* @return null|SS_HTTPResponse
|
2015-05-09 16:33:12 +02:00
|
|
|
*/
|
2013-07-21 12:23:35 +02:00
|
|
|
public function category() {
|
2013-08-04 18:38:26 +02:00
|
|
|
$category = $this->getCurrentCategory();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2013-07-21 12:23:35 +02:00
|
|
|
if($category) {
|
2013-08-04 18:38:26 +02:00
|
|
|
$this->blogPosts = $category->BlogPosts();
|
2015-05-13 23:12:48 +02:00
|
|
|
|
2013-08-04 18:38:26 +02:00
|
|
|
return $this->render();
|
2013-07-21 12:23:35 +02:00
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-05-13 23:12:48 +02:00
|
|
|
$this->httpError(404, 'Not Found');
|
|
|
|
|
|
|
|
return null;
|
2013-07-21 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
2015-04-09 07:25:52 +02:00
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Category Getter for use in templates.
|
|
|
|
*
|
|
|
|
* @return null|BlogCategory
|
|
|
|
*/
|
|
|
|
public function getCurrentCategory() {
|
2015-05-13 23:12:48 +02:00
|
|
|
/**
|
|
|
|
* @var Blog $dataRecord
|
|
|
|
*/
|
|
|
|
$dataRecord = $this->dataRecord;
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$category = $this->request->param('Category');
|
|
|
|
|
|
|
|
if($category) {
|
2015-05-13 23:12:48 +02:00
|
|
|
return $dataRecord->Categories()
|
2015-05-09 16:33:12 +02:00
|
|
|
->filter('URLSegment', $category)
|
|
|
|
->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the meta title for the current action.
|
2015-04-09 07:25:52 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getMetaTitle() {
|
|
|
|
$title = $this->data()->getTitle();
|
|
|
|
$filter = $this->getFilterDescription();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-04-09 07:25:52 +02:00
|
|
|
if($filter) {
|
2015-05-13 23:12:48 +02:00
|
|
|
$title = sprintf('%s - %s', $title, $filter);
|
2015-04-09 07:25:52 +02:00
|
|
|
}
|
2015-04-21 06:47:46 +02:00
|
|
|
|
2015-04-09 07:25:52 +02:00
|
|
|
$this->extend('updateMetaTitle', $title);
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-04-09 07:25:52 +02:00
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Returns a description of the current filter.
|
2015-04-09 07:25:52 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFilterDescription() {
|
|
|
|
$items = array();
|
|
|
|
|
|
|
|
$list = $this->PaginatedList();
|
|
|
|
$currentPage = $list->CurrentPage();
|
|
|
|
|
|
|
|
if($currentPage > 1) {
|
|
|
|
$items[] = _t(
|
|
|
|
'Blog.FILTERDESCRIPTION_PAGE',
|
2015-05-09 16:33:12 +02:00
|
|
|
'Page {page}',
|
2015-04-09 07:25:52 +02:00
|
|
|
null,
|
2015-05-09 16:33:12 +02:00
|
|
|
array(
|
|
|
|
'page' => $currentPage,
|
|
|
|
)
|
2015-04-09 07:25:52 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($author = $this->getCurrentProfile()) {
|
|
|
|
$items[] = _t(
|
|
|
|
'Blog.FILTERDESCRIPTION_AUTHOR',
|
2015-05-09 16:33:12 +02:00
|
|
|
'By {author}',
|
2015-04-09 07:25:52 +02:00
|
|
|
null,
|
2015-05-09 16:33:12 +02:00
|
|
|
array(
|
|
|
|
'author' => $author->Title,
|
|
|
|
)
|
2015-04-09 07:25:52 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($tag = $this->getCurrentTag()) {
|
|
|
|
$items[] = _t(
|
|
|
|
'Blog.FILTERDESCRIPTION_TAG',
|
2015-05-09 16:33:12 +02:00
|
|
|
'Tagged with {tag}',
|
2015-04-09 07:25:52 +02:00
|
|
|
null,
|
2015-05-09 16:33:12 +02:00
|
|
|
array(
|
|
|
|
'tag' => $tag->Title,
|
|
|
|
)
|
2015-04-09 07:25:52 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($category = $this->getCurrentCategory()) {
|
|
|
|
$items[] = _t(
|
|
|
|
'Blog.FILTERDESCRIPTION_CATEGORY',
|
2015-05-09 16:33:12 +02:00
|
|
|
'In category {category}',
|
2015-04-09 07:25:52 +02:00
|
|
|
null,
|
2015-05-09 16:33:12 +02:00
|
|
|
array(
|
|
|
|
'category' => $category->Title,
|
|
|
|
)
|
2015-04-09 07:25:52 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($this->owner->getArchiveYear()) {
|
|
|
|
if($this->owner->getArchiveDay()) {
|
|
|
|
$date = $this->owner->getArchiveDate()->Nice();
|
2015-04-21 06:47:46 +02:00
|
|
|
} elseif($this->owner->getArchiveMonth()) {
|
2015-05-09 16:33:12 +02:00
|
|
|
$date = $this->owner->getArchiveDate()->format('F, Y');
|
2015-04-09 07:25:52 +02:00
|
|
|
} else {
|
2015-05-09 16:33:12 +02:00
|
|
|
$date = $this->owner->getArchiveDate()->format('Y');
|
2015-04-09 07:25:52 +02:00
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-04-09 07:25:52 +02:00
|
|
|
$items[] = _t(
|
|
|
|
'Blog.FILTERDESCRIPTION_DATE',
|
2015-05-09 16:33:12 +02:00
|
|
|
'In {date}',
|
2015-04-09 07:25:52 +02:00
|
|
|
null,
|
2015-05-09 16:33:12 +02:00
|
|
|
array(
|
|
|
|
'date' => $date,
|
|
|
|
)
|
2015-04-09 07:25:52 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = '';
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
if($items) {
|
|
|
|
$result = implode(', ', $items);
|
|
|
|
}
|
2013-08-04 18:38:26 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$this->extend('updateFilterDescription', $result);
|
2013-08-04 18:38:26 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
return $result;
|
2013-08-11 00:34:46 +02:00
|
|
|
}
|
|
|
|
|
2013-08-04 18:38:26 +02:00
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Returns a list of paginated blog posts based on the BlogPost dataList.
|
2013-08-04 18:38:26 +02:00
|
|
|
*
|
|
|
|
* @return PaginatedList
|
2015-05-09 16:33:12 +02:00
|
|
|
*/
|
2013-08-04 18:38:26 +02:00
|
|
|
public function PaginatedList() {
|
2015-05-13 23:12:48 +02:00
|
|
|
/**
|
|
|
|
* @var Blog $dataRecord
|
|
|
|
*/
|
|
|
|
$dataRecord = $this->dataRecord;
|
|
|
|
|
2013-08-04 18:38:26 +02:00
|
|
|
$posts = new PaginatedList($this->blogPosts);
|
|
|
|
|
2015-03-04 23:20:47 +01:00
|
|
|
if($this->PostsPerPage > 0) {
|
|
|
|
$posts->setPageLength($this->PostsPerPage);
|
|
|
|
} else {
|
2015-05-09 16:33:12 +02:00
|
|
|
$pageSize = 99999;
|
|
|
|
|
2015-05-13 23:12:48 +02:00
|
|
|
if($count = $dataRecord->getBlogPosts()->count()) {
|
2015-05-09 16:33:12 +02:00
|
|
|
$pageSize = $count;
|
|
|
|
}
|
|
|
|
|
2015-03-04 23:20:47 +01:00
|
|
|
$posts->setPageLength($pageSize);
|
|
|
|
}
|
2013-08-04 18:38:26 +02:00
|
|
|
|
|
|
|
$start = $this->request->getVar($posts->getPaginationGetVar());
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2013-08-04 18:38:26 +02:00
|
|
|
$posts->setPageStart($start);
|
|
|
|
|
|
|
|
return $posts;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Displays an RSS feed of blog posts.
|
2013-08-04 18:38:26 +02:00
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function rss() {
|
2015-05-13 23:12:48 +02:00
|
|
|
/**
|
|
|
|
* @var Blog $dataRecord
|
|
|
|
*/
|
|
|
|
$dataRecord = $this->dataRecord;
|
|
|
|
|
|
|
|
$rss = new RSSFeed($dataRecord->getBlogPosts(), $this->Link(), $this->MetaTitle, $this->MetaDescription);
|
2013-08-11 00:34:46 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$this->extend('updateRss', $rss);
|
2013-08-11 00:34:46 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
return $rss->outputToBrowser();
|
2013-08-04 18:38:26 +02:00
|
|
|
}
|
|
|
|
|
2013-08-11 00:34:46 +02:00
|
|
|
/**
|
|
|
|
* Returns the current archive date.
|
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return null|Date
|
|
|
|
*/
|
2013-08-04 18:38:26 +02:00
|
|
|
public function getArchiveDate() {
|
|
|
|
$year = $this->getArchiveYear();
|
|
|
|
$month = $this->getArchiveMonth();
|
2013-08-11 00:34:46 +02:00
|
|
|
$day = $this->getArchiveDay();
|
2013-08-04 18:38:26 +02:00
|
|
|
|
|
|
|
if($year) {
|
|
|
|
if($month) {
|
2015-05-09 16:33:12 +02:00
|
|
|
$date = sprintf('%s-%s-01', $year, $month);
|
|
|
|
|
2013-08-11 00:34:46 +02:00
|
|
|
if($day) {
|
2015-05-09 16:33:12 +02:00
|
|
|
$date = sprintf('%s-%s-%s', $year, $month, $day);
|
2013-08-11 00:34:46 +02:00
|
|
|
}
|
2013-08-04 18:38:26 +02:00
|
|
|
} else {
|
2015-05-09 16:33:12 +02:00
|
|
|
$date = sprintf('%s-01-01', $year);
|
2013-08-04 18:38:26 +02:00
|
|
|
}
|
2015-05-09 16:33:12 +02:00
|
|
|
|
|
|
|
return DBField::create_field('Date', $date);
|
2013-08-04 18:38:26 +02:00
|
|
|
}
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
return null;
|
|
|
|
}
|
2013-08-11 00:34:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a link to the RSS feed.
|
|
|
|
*
|
2015-05-09 16:33:12 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
2013-08-11 00:34:46 +02:00
|
|
|
public function getRSSLink() {
|
2015-05-09 16:33:12 +02:00
|
|
|
return $this->Link('rss');
|
2013-08-11 00:34:46 +02:00
|
|
|
}
|
2014-09-29 10:47:23 +02:00
|
|
|
}
|