mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Converted to PSR-2
This commit is contained in:
parent
4785ad0123
commit
f82825d9a6
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor {
|
class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @param int $itemsPerPage
|
* @param int $itemsPerPage
|
||||||
* @param array|SS_List $mergeRecords
|
* @param array|SS_List $mergeRecords
|
||||||
@ -8,7 +9,8 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor {
|
|||||||
* @param string $parentMethod
|
* @param string $parentMethod
|
||||||
* @param string $childMethod
|
* @param string $childMethod
|
||||||
*/
|
*/
|
||||||
public function __construct($itemsPerPage = 15, $mergeRecords, $parentType, $parentMethod, $childMethod) {
|
public function __construct($itemsPerPage = 15, $mergeRecords, $parentType, $parentMethod, $childMethod)
|
||||||
|
{
|
||||||
parent::__construct($itemsPerPage);
|
parent::__construct($itemsPerPage);
|
||||||
|
|
||||||
$this->removeComponentsByType('GridFieldAddNewButton');
|
$this->removeComponentsByType('GridFieldAddNewButton');
|
||||||
@ -38,7 +40,8 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor {
|
|||||||
/**
|
/**
|
||||||
* Reorders GridField columns so that Actions is last.
|
* Reorders GridField columns so that Actions is last.
|
||||||
*/
|
*/
|
||||||
protected function changeColumnOrder() {
|
protected function changeColumnOrder()
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var GridFieldDataColumns $columns
|
* @var GridFieldDataColumns $columns
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class GridFieldFormAction extends GridField_FormAction {
|
class GridFieldFormAction extends GridField_FormAction
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -9,14 +10,16 @@ class GridFieldFormAction extends GridField_FormAction {
|
|||||||
/**
|
/**
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
*/
|
*/
|
||||||
public function setExtraAttributes(array $attributes) {
|
public function setExtraAttributes(array $attributes)
|
||||||
|
{
|
||||||
$this->extraAttributes = $attributes;
|
$this->extraAttributes = $attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getAttributes() {
|
public function getAttributes()
|
||||||
|
{
|
||||||
$attributes = parent::getAttributes();
|
$attributes = parent::getAttributes();
|
||||||
|
|
||||||
return array_merge(
|
return array_merge(
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class GridFieldMergeAction implements GridField_ColumnProvider, GridField_ActionProvider {
|
class GridFieldMergeAction implements GridField_ColumnProvider, GridField_ActionProvider
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* List of records to show in the MergeAction column.
|
* List of records to show in the MergeAction column.
|
||||||
*
|
*
|
||||||
@ -35,7 +36,8 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
|
|||||||
* @param string $parentMethod
|
* @param string $parentMethod
|
||||||
* @param string $childMethod
|
* @param string $childMethod
|
||||||
*/
|
*/
|
||||||
public function __construct($records = array(), $parentType, $parentMethod, $childMethod) {
|
public function __construct($records = array(), $parentType, $parentMethod, $childMethod)
|
||||||
|
{
|
||||||
$this->records = $records;
|
$this->records = $records;
|
||||||
$this->parentType = $parentType;
|
$this->parentType = $parentType;
|
||||||
$this->parentMethod = $parentMethod;
|
$this->parentMethod = $parentMethod;
|
||||||
@ -45,8 +47,9 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function augmentColumns($gridField, &$columns) {
|
public function augmentColumns($gridField, &$columns)
|
||||||
if(!in_array('MergeAction', $columns)) {
|
{
|
||||||
|
if (!in_array('MergeAction', $columns)) {
|
||||||
$columns[] = 'MergeAction';
|
$columns[] = 'MergeAction';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,15 +59,17 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getColumnsHandled($gridField) {
|
public function getColumnsHandled($gridField)
|
||||||
|
{
|
||||||
return array('MergeAction');
|
return array('MergeAction');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getColumnContent($gridField, $record, $columnName) {
|
public function getColumnContent($gridField, $record, $columnName)
|
||||||
if($columnName === 'MergeAction' && $record->{$this->childMethod}()->Count() > 0) {
|
{
|
||||||
|
if ($columnName === 'MergeAction' && $record->{$this->childMethod}()->Count() > 0) {
|
||||||
$dropdown = new DropdownField('Target', 'Target', $this->records->exclude('ID', $record->ID)->map());
|
$dropdown = new DropdownField('Target', 'Target', $this->records->exclude('ID', $record->ID)->map());
|
||||||
$dropdown->setAttribute('id', 'Target_'.$record->ID);
|
$dropdown->setAttribute('id', 'Target_'.$record->ID);
|
||||||
$prefix = strtolower($this->parentMethod . '-' . $this->childMethod);
|
$prefix = strtolower($this->parentMethod . '-' . $this->childMethod);
|
||||||
@ -93,29 +98,33 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getColumnAttributes($gridField, $record, $columnName) {
|
public function getColumnAttributes($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
return array('class' => 'MergeAction');
|
return array('class' => 'MergeAction');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getColumnMetadata($gridField, $columnName) {
|
public function getColumnMetadata($gridField, $columnName)
|
||||||
|
{
|
||||||
return array('title' => 'Move posts to');
|
return array('title' => 'Move posts to');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getActions($gridField) {
|
public function getActions($gridField)
|
||||||
|
{
|
||||||
return array('merge');
|
return array('merge');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
|
||||||
if($actionName === 'merge') {
|
{
|
||||||
|
if ($actionName === 'merge') {
|
||||||
$controller = Controller::curr();
|
$controller = Controller::curr();
|
||||||
|
|
||||||
$request = $controller->getRequest();
|
$request = $controller->getRequest();
|
||||||
@ -129,7 +138,7 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
|
|||||||
|
|
||||||
$posts = $fromParent->{$this->childMethod}();
|
$posts = $fromParent->{$this->childMethod}();
|
||||||
|
|
||||||
foreach($posts as $post) {
|
foreach ($posts as $post) {
|
||||||
$relationship = $post->{$this->parentMethod}();
|
$relationship = $post->{$this->parentMethod}();
|
||||||
|
|
||||||
$relationship->remove($fromParent);
|
$relationship->remove($fromParent);
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
* @property string $PublishDate
|
* @property string $PublishDate
|
||||||
* @property string $Tags
|
* @property string $Tags
|
||||||
*/
|
*/
|
||||||
class BlogEntry extends BlogPost implements MigratableObject {
|
class BlogEntry extends BlogPost implements MigratableObject
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -26,23 +27,23 @@ class BlogEntry extends BlogPost implements MigratableObject {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function canCreate($member = null) {
|
public function canCreate($member = null)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function up() {
|
public function up()
|
||||||
|
{
|
||||||
|
|
||||||
//Migrate comma separated tags into BlogTag objects.
|
//Migrate comma separated tags into BlogTag objects.
|
||||||
foreach($this->TagNames() as $tag) {
|
foreach ($this->TagNames() as $tag) {
|
||||||
|
|
||||||
$existingTag = BlogTag::get()->filter(array('Title' => $tag, 'BlogID' => $this->ParentID));
|
$existingTag = BlogTag::get()->filter(array('Title' => $tag, 'BlogID' => $this->ParentID));
|
||||||
if($existingTag->count()) {
|
if ($existingTag->count()) {
|
||||||
//if tag already exists we will simply add it to this post.
|
//if tag already exists we will simply add it to this post.
|
||||||
$tagObject = $existingTag->First();
|
$tagObject = $existingTag->First();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//if the tag is now we create it and add it to this post.
|
//if the tag is now we create it and add it to this post.
|
||||||
@ -50,11 +51,9 @@ class BlogEntry extends BlogPost implements MigratableObject {
|
|||||||
$tagObject->Title = $tag;
|
$tagObject->Title = $tag;
|
||||||
$tagObject->BlogID = $this->ParentID;
|
$tagObject->BlogID = $this->ParentID;
|
||||||
$tagObject->write();
|
$tagObject->write();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($tagObject){
|
if ($tagObject) {
|
||||||
$this->Tags()->add($tagObject);
|
$this->Tags()->add($tagObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,7 +61,7 @@ class BlogEntry extends BlogPost implements MigratableObject {
|
|||||||
//Store if the original entity was published or not (draft)
|
//Store if the original entity was published or not (draft)
|
||||||
$published = $this->IsPublished();
|
$published = $this->IsPublished();
|
||||||
// If a user has subclassed BlogEntry, it should not be turned into a BlogPost.
|
// If a user has subclassed BlogEntry, it should not be turned into a BlogPost.
|
||||||
if($this->ClassName === 'BlogEntry') {
|
if ($this->ClassName === 'BlogEntry') {
|
||||||
$this->ClassName = 'BlogPost';
|
$this->ClassName = 'BlogPost';
|
||||||
$this->RecordClassName = 'BlogPost';
|
$this->RecordClassName = 'BlogPost';
|
||||||
}
|
}
|
||||||
@ -73,8 +72,8 @@ class BlogEntry extends BlogPost implements MigratableObject {
|
|||||||
|
|
||||||
//Write and additionally publish the item if it was published before.
|
//Write and additionally publish the item if it was published before.
|
||||||
$this->write();
|
$this->write();
|
||||||
if($published){
|
if ($published) {
|
||||||
$this->publish('Stage','Live');
|
$this->publish('Stage', 'Live');
|
||||||
$message = "PUBLISHED: ";
|
$message = "PUBLISHED: ";
|
||||||
} else {
|
} else {
|
||||||
$message = "DRAFT: ";
|
$message = "DRAFT: ";
|
||||||
@ -90,23 +89,25 @@ class BlogEntry extends BlogPost implements MigratableObject {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function TagNames() {
|
public function TagNames()
|
||||||
|
{
|
||||||
$tags = preg_split('/\s*,\s*/', trim($this->Tags));
|
$tags = preg_split('/\s*,\s*/', trim($this->Tags));
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
||||||
foreach($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
if($tag) $results[mb_strtolower($tag)] = $tag;
|
if ($tag) {
|
||||||
|
$results[mb_strtolower($tag)] = $tag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated since version 2.0
|
* @deprecated since version 2.0
|
||||||
*/
|
*/
|
||||||
class BlogEntry_Controller extends BlogPost_Controller {
|
class BlogEntry_Controller extends BlogPost_Controller
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
/**
|
/**
|
||||||
* @deprecated since version 2.0
|
* @deprecated since version 2.0
|
||||||
*/
|
*/
|
||||||
class BlogHolder extends BlogTree implements MigratableObject {
|
class BlogHolder extends BlogTree implements MigratableObject
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -27,35 +28,38 @@ class BlogHolder extends BlogTree implements MigratableObject {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function canCreate($member = null) {
|
public function canCreate($member = null)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Overload these to stop the Uncaught Exception: Object->__call(): the method 'parent' does not exist on 'BlogHolder' error.
|
//Overload these to stop the Uncaught Exception: Object->__call(): the method 'parent' does not exist on 'BlogHolder' error.
|
||||||
public function validURLSegment() {
|
public function validURLSegment()
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public function syncLinkTracking() {
|
public function syncLinkTracking()
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function up() {
|
public function up()
|
||||||
|
{
|
||||||
$published = $this->IsPublished();
|
$published = $this->IsPublished();
|
||||||
|
|
||||||
if($this->ClassName === 'BlogHolder') {
|
if ($this->ClassName === 'BlogHolder') {
|
||||||
$this->ClassName = 'Blog';
|
$this->ClassName = 'Blog';
|
||||||
$this->RecordClassName = 'Blog';
|
$this->RecordClassName = 'Blog';
|
||||||
$this->PostsPerPage = 10;
|
$this->PostsPerPage = 10;
|
||||||
$this->write();
|
$this->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($published){
|
if ($published) {
|
||||||
$this->publish('Stage','Live');
|
$this->publish('Stage', 'Live');
|
||||||
$message = "PUBLISHED: ";
|
$message = "PUBLISHED: ";
|
||||||
} else {
|
} else {
|
||||||
$message = "DRAFT: ";
|
$message = "DRAFT: ";
|
||||||
@ -68,6 +72,6 @@ class BlogHolder extends BlogTree implements MigratableObject {
|
|||||||
/**
|
/**
|
||||||
* @deprecated since version 2.0
|
* @deprecated since version 2.0
|
||||||
*/
|
*/
|
||||||
class BlogHolder_Controller extends BlogTree_Controller {
|
class BlogHolder_Controller extends BlogTree_Controller
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
/**
|
/**
|
||||||
* @deprecated since version 2.0
|
* @deprecated since version 2.0
|
||||||
*/
|
*/
|
||||||
class BlogTree extends Page implements MigratableObject {
|
class BlogTree extends Page implements MigratableObject
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -20,22 +21,24 @@ class BlogTree extends Page implements MigratableObject {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function canCreate($member = null) {
|
public function canCreate($member = null)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function up() {
|
public function up()
|
||||||
|
{
|
||||||
$published = $this->IsPublished();
|
$published = $this->IsPublished();
|
||||||
if($this->ClassName === 'BlogTree') {
|
if ($this->ClassName === 'BlogTree') {
|
||||||
$this->ClassName = 'Page';
|
$this->ClassName = 'Page';
|
||||||
$this->RecordClassName = 'Page';
|
$this->RecordClassName = 'Page';
|
||||||
$this->write();
|
$this->write();
|
||||||
}
|
}
|
||||||
if($published){
|
if ($published) {
|
||||||
$this->publish('Stage','Live');
|
$this->publish('Stage', 'Live');
|
||||||
$message = "PUBLISHED: ";
|
$message = "PUBLISHED: ";
|
||||||
} else {
|
} else {
|
||||||
$message = "DRAFT: ";
|
$message = "DRAFT: ";
|
||||||
@ -48,6 +51,6 @@ class BlogTree extends Page implements MigratableObject {
|
|||||||
/**
|
/**
|
||||||
* @deprecated since version 2.0
|
* @deprecated since version 2.0
|
||||||
*/
|
*/
|
||||||
class BlogTree_Controller extends Page_Controller {
|
class BlogTree_Controller extends Page_Controller
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class BlogMigrationTask extends MigrationTask {
|
class BlogMigrationTask extends MigrationTask
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Should this task be invoked automatically via dev/build?
|
* Should this task be invoked automatically via dev/build?
|
||||||
*
|
*
|
||||||
@ -13,23 +14,23 @@ class BlogMigrationTask extends MigrationTask {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function up() {
|
public function up()
|
||||||
|
{
|
||||||
$classes = ClassInfo::implementorsOf('MigratableObject');
|
$classes = ClassInfo::implementorsOf('MigratableObject');
|
||||||
|
|
||||||
$this->message('Migrating legacy blog records');
|
$this->message('Migrating legacy blog records');
|
||||||
|
|
||||||
foreach($classes as $class) {
|
foreach ($classes as $class) {
|
||||||
|
|
||||||
$this->upClass($class);
|
$this->upClass($class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $text
|
* @param string $text
|
||||||
*/
|
*/
|
||||||
protected function message($text) {
|
protected function message($text)
|
||||||
if(Controller::curr() instanceof DatabaseAdmin) {
|
{
|
||||||
|
if (Controller::curr() instanceof DatabaseAdmin) {
|
||||||
DB::alteration_message($text, 'obsolete');
|
DB::alteration_message($text, 'obsolete');
|
||||||
} else {
|
} else {
|
||||||
echo $text . "<br/>";
|
echo $text . "<br/>";
|
||||||
@ -42,18 +43,19 @@ class BlogMigrationTask extends MigrationTask {
|
|||||||
* @param string $class
|
* @param string $class
|
||||||
* @param null|string $stage
|
* @param null|string $stage
|
||||||
*/
|
*/
|
||||||
protected function upClass($class) {
|
protected function upClass($class)
|
||||||
if(!class_exists($class)) {
|
{
|
||||||
|
if (!class_exists($class)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_subclass_of($class, 'SiteTree')) {
|
if (is_subclass_of($class, 'SiteTree')) {
|
||||||
$items = SiteTree::get()->filter('ClassName', $class);
|
$items = SiteTree::get()->filter('ClassName', $class);
|
||||||
} else {
|
} else {
|
||||||
$items = $class::get();
|
$items = $class::get();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($count = $items->count()) {
|
if ($count = $items->count()) {
|
||||||
$this->message(
|
$this->message(
|
||||||
sprintf(
|
sprintf(
|
||||||
'Migrating %s legacy %s records.',
|
'Migrating %s legacy %s records.',
|
||||||
@ -62,10 +64,10 @@ class BlogMigrationTask extends MigrationTask {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach($items as $item) {
|
foreach ($items as $item) {
|
||||||
$cancel = $item->extend('onBeforeUp');
|
$cancel = $item->extend('onBeforeUp');
|
||||||
|
|
||||||
if($cancel && min($cancel) === false) {
|
if ($cancel && min($cancel) === false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +85,8 @@ class BlogMigrationTask extends MigrationTask {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function down() {
|
public function down()
|
||||||
|
{
|
||||||
$this->message('BlogMigrationTask::down() not implemented');
|
$this->message('BlogMigrationTask::down() not implemented');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
interface MigratableObject {
|
interface MigratableObject
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Migrate the object up to the current version.
|
* Migrate the object up to the current version.
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if(!class_exists('Widget')) {
|
if (!class_exists('Widget')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10,7 +10,8 @@ if(!class_exists('Widget')) {
|
|||||||
* @property string $DisplayMode
|
* @property string $DisplayMode
|
||||||
* @property string $ArchiveType
|
* @property string $ArchiveType
|
||||||
*/
|
*/
|
||||||
class ArchiveWidget extends BlogArchiveWidget implements MigratableObject {
|
class ArchiveWidget extends BlogArchiveWidget implements MigratableObject
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -28,18 +29,20 @@ class ArchiveWidget extends BlogArchiveWidget implements MigratableObject {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function canCreate($member = null) {
|
public function canCreate($member = null)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function up() {
|
public function up()
|
||||||
if($this->DisplayMode) {
|
{
|
||||||
|
if ($this->DisplayMode) {
|
||||||
$this->ArchiveType = 'Monthly';
|
$this->ArchiveType = 'Monthly';
|
||||||
|
|
||||||
if($this->DisplayMode === 'year') {
|
if ($this->DisplayMode === 'year') {
|
||||||
$this->ArchiveType = 'Yearly';
|
$this->ArchiveType = 'Yearly';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,6 +50,5 @@ class ArchiveWidget extends BlogArchiveWidget implements MigratableObject {
|
|||||||
$this->ClassName = 'BlogArchiveWidget';
|
$this->ClassName = 'BlogArchiveWidget';
|
||||||
$this->write();
|
$this->write();
|
||||||
return "Migrated " . $this->ArchiveType . " archive widget";
|
return "Migrated " . $this->ArchiveType . " archive widget";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if(!class_exists('Widget')) {
|
if (!class_exists('Widget')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9,7 +9,8 @@ if(!class_exists('Widget')) {
|
|||||||
*
|
*
|
||||||
* @package blog
|
* @package blog
|
||||||
*/
|
*/
|
||||||
class TagCloudWidget extends BlogTagsWidget implements MigratableObject {
|
class TagCloudWidget extends BlogTagsWidget implements MigratableObject
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -29,14 +30,16 @@ class TagCloudWidget extends BlogTagsWidget implements MigratableObject {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function canCreate($member = null) {
|
public function canCreate($member = null)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function up() {
|
public function up()
|
||||||
|
{
|
||||||
$this->ClassName = 'BlogTagsWidget';
|
$this->ClassName = 'BlogTagsWidget';
|
||||||
$this->write();
|
$this->write();
|
||||||
return "Migrated " . $this->Title . " widget";
|
return "Migrated " . $this->Title . " widget";
|
||||||
|
@ -3,17 +3,19 @@
|
|||||||
/**
|
/**
|
||||||
* Adds Blog specific behaviour to Comment.
|
* Adds Blog specific behaviour to Comment.
|
||||||
*/
|
*/
|
||||||
class BlogCommentExtension extends DataExtension {
|
class BlogCommentExtension extends DataExtension
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Extra CSS classes for styling different comment types.
|
* Extra CSS classes for styling different comment types.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getExtraClass() {
|
public function getExtraClass()
|
||||||
|
{
|
||||||
$blogPost = $this->owner->getParent();
|
$blogPost = $this->owner->getParent();
|
||||||
|
|
||||||
if($blogPost instanceof BlogPost) {
|
if ($blogPost instanceof BlogPost) {
|
||||||
if($blogPost->isAuthor($this->owner->Author())) {
|
if ($blogPost->isAuthor($this->owner->Author())) {
|
||||||
return 'author-comment';
|
return 'author-comment';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,19 +7,21 @@
|
|||||||
* @package silverstripe
|
* @package silverstripe
|
||||||
* @subpackage blog
|
* @subpackage blog
|
||||||
*/
|
*/
|
||||||
class BlogFilter extends Lumberjack {
|
class BlogFilter extends Lumberjack
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function stageChildren($showAll = false) {
|
public function stageChildren($showAll = false)
|
||||||
|
{
|
||||||
$staged = parent::stageChildren($showAll);
|
$staged = parent::stageChildren($showAll);
|
||||||
|
|
||||||
if(!$this->shouldFilter() && $this->subclassForBlog() && !Permission::check('VIEW_DRAFT_CONTENT')) {
|
if (!$this->shouldFilter() && $this->subclassForBlog() && !Permission::check('VIEW_DRAFT_CONTENT')) {
|
||||||
$stage = Versioned::current_stage();
|
$stage = Versioned::current_stage();
|
||||||
|
|
||||||
if($stage == 'Stage') {
|
if ($stage == 'Stage') {
|
||||||
$stage = '';
|
$stage = '';
|
||||||
} elseif($stage) {
|
} elseif ($stage) {
|
||||||
$stage = '_' . $stage;
|
$stage = '_' . $stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,17 +38,19 @@ class BlogFilter extends Lumberjack {
|
|||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function subclassForBlog() {
|
protected function subclassForBlog()
|
||||||
|
{
|
||||||
return in_array(get_class($this->owner), ClassInfo::subClassesFor('Blog'));
|
return in_array(get_class($this->owner), ClassInfo::subClassesFor('Blog'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function liveChildren($showAll = false, $onlyDeletedFromStage = false) {
|
public function liveChildren($showAll = false, $onlyDeletedFromStage = false)
|
||||||
|
{
|
||||||
$staged = parent::liveChildren($showAll, $onlyDeletedFromStage);
|
$staged = parent::liveChildren($showAll, $onlyDeletedFromStage);
|
||||||
|
|
||||||
if(!$this->shouldFilter() && $this->isBlog() && !Permission::check('VIEW_DRAFT_CONTENT')) {
|
if (!$this->shouldFilter() && $this->isBlog() && !Permission::check('VIEW_DRAFT_CONTENT')) {
|
||||||
$dataQuery = $staged->dataQuery()
|
$dataQuery = $staged->dataQuery()
|
||||||
->innerJoin('BlogPost', '"BlogPost_Live"."ID" = "SiteTree_Live"."ID"')
|
->innerJoin('BlogPost', '"BlogPost_Live"."ID" = "SiteTree_Live"."ID"')
|
||||||
->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now())));
|
->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now())));
|
||||||
@ -60,17 +64,19 @@ class BlogFilter extends Lumberjack {
|
|||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isBlog() {
|
protected function isBlog()
|
||||||
|
{
|
||||||
return $this->owner instanceof Blog;
|
return $this->owner instanceof Blog;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function updateCMSFields(FieldList $fields) {
|
public function updateCMSFields(FieldList $fields)
|
||||||
|
{
|
||||||
$excluded = $this->owner->getExcludedSiteTreeClassNames();
|
$excluded = $this->owner->getExcludedSiteTreeClassNames();
|
||||||
|
|
||||||
if(!empty($excluded)) {
|
if (!empty($excluded)) {
|
||||||
$pages = BlogPost::get()->filter(array(
|
$pages = BlogPost::get()->filter(array(
|
||||||
'ParentID' => $this->owner->ID,
|
'ParentID' => $this->owner->ID,
|
||||||
'ClassName' => $excluded
|
'ClassName' => $excluded
|
||||||
@ -94,13 +100,15 @@ class BlogFilter extends Lumberjack {
|
|||||||
/**
|
/**
|
||||||
* Enables children of non-editable pages to be edited.
|
* Enables children of non-editable pages to be edited.
|
||||||
*/
|
*/
|
||||||
class BlogFilter_GridField extends GridField {
|
class BlogFilter_GridField extends GridField
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @param FormTransformation $transformation
|
* @param FormTransformation $transformation
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function transform(FormTransformation $transformation) {
|
public function transform(FormTransformation $transformation)
|
||||||
|
{
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
* @package silverstripe
|
* @package silverstripe
|
||||||
* @subpackage blog
|
* @subpackage blog
|
||||||
*/
|
*/
|
||||||
class BlogMemberExtension extends DataExtension {
|
class BlogMemberExtension extends DataExtension
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -32,12 +33,13 @@ class BlogMemberExtension extends DataExtension {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function onBeforeWrite() {
|
public function onBeforeWrite()
|
||||||
|
{
|
||||||
$count = 1;
|
$count = 1;
|
||||||
|
|
||||||
$this->owner->URLSegment = $this->generateURLSegment();
|
$this->owner->URLSegment = $this->generateURLSegment();
|
||||||
|
|
||||||
while(!$this->validURLSegment()) {
|
while (!$this->validURLSegment()) {
|
||||||
$this->owner->URLSegment = preg_replace('/-[0-9]+$/', null, $this->owner->URLSegment) . '-' . $count;
|
$this->owner->URLSegment = preg_replace('/-[0-9]+$/', null, $this->owner->URLSegment) . '-' . $count;
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
@ -48,12 +50,13 @@ class BlogMemberExtension extends DataExtension {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function generateURLSegment() {
|
public function generateURLSegment()
|
||||||
|
{
|
||||||
$filter = URLSegmentFilter::create();
|
$filter = URLSegmentFilter::create();
|
||||||
$name = $this->owner->FirstName . ' ' . $this->owner->Surname;
|
$name = $this->owner->FirstName . ' ' . $this->owner->Surname;
|
||||||
$urlSegment = $filter->filter($name);
|
$urlSegment = $filter->filter($name);
|
||||||
|
|
||||||
if(!$urlSegment || $urlSegment == '-' || $urlSegment == '-1') {
|
if (!$urlSegment || $urlSegment == '-' || $urlSegment == '-1') {
|
||||||
$urlSegment = 'profile-' . $this->owner->ID;
|
$urlSegment = 'profile-' . $this->owner->ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,10 +69,11 @@ class BlogMemberExtension extends DataExtension {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validURLSegment() {
|
public function validURLSegment()
|
||||||
|
{
|
||||||
$conflict = Member::get()->filter('URLSegment', $this->owner->URLSegment);
|
$conflict = Member::get()->filter('URLSegment', $this->owner->URLSegment);
|
||||||
|
|
||||||
if($this->owner->ID) {
|
if ($this->owner->ID) {
|
||||||
$conflict = $conflict->exclude('ID', $this->owner->ID);
|
$conflict = $conflict->exclude('ID', $this->owner->ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +84,8 @@ class BlogMemberExtension extends DataExtension {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function updateCMSFields(FieldList $fields) {
|
public function updateCMSFields(FieldList $fields)
|
||||||
|
{
|
||||||
$fields->removeByName('URLSegment');
|
$fields->removeByName('URLSegment');
|
||||||
|
|
||||||
// Remove the automatically-generated posts tab.
|
// Remove the automatically-generated posts tab.
|
||||||
|
@ -7,20 +7,22 @@
|
|||||||
* @package silverstripe
|
* @package silverstripe
|
||||||
* @subpackage blog
|
* @subpackage blog
|
||||||
*/
|
*/
|
||||||
class BlogPostFilter extends DataExtension {
|
class BlogPostFilter extends DataExtension
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Augment queries so that we don't fetch unpublished articles.
|
* Augment queries so that we don't fetch unpublished articles.
|
||||||
*
|
*
|
||||||
* @param SQLQuery $query
|
* @param SQLQuery $query
|
||||||
*/
|
*/
|
||||||
public function augmentSQL(SQLQuery &$query) {
|
public function augmentSQL(SQLQuery &$query)
|
||||||
|
{
|
||||||
$stage = Versioned::current_stage();
|
$stage = Versioned::current_stage();
|
||||||
|
|
||||||
if (Controller::curr() instanceof LeftAndMain) {
|
if (Controller::curr() instanceof LeftAndMain) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($stage == 'Live' || !Permission::check('VIEW_DRAFT_CONTENT')) {
|
if ($stage == 'Live' || !Permission::check('VIEW_DRAFT_CONTENT')) {
|
||||||
$query->addWhere(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now())));
|
$query->addWhere(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,7 +38,8 @@ class BlogPostFilter extends DataExtension {
|
|||||||
* @param mixed $dataQuery
|
* @param mixed $dataQuery
|
||||||
* @param mixed $parent
|
* @param mixed $parent
|
||||||
*/
|
*/
|
||||||
public function augmentLoadLazyFields(SQLQuery &$query, &$dataQuery, $parent) {
|
public function augmentLoadLazyFields(SQLQuery &$query, &$dataQuery, $parent)
|
||||||
|
{
|
||||||
$dataQuery->innerJoin('BlogPost', '"SiteTree"."ID" = "BlogPost"."ID"');
|
$dataQuery->innerJoin('BlogPost', '"SiteTree"."ID" = "BlogPost"."ID"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,16 @@
|
|||||||
*
|
*
|
||||||
* Extends {@see BlogPost} with extensions to {@see CommentNotifiable}.
|
* Extends {@see BlogPost} with extensions to {@see CommentNotifiable}.
|
||||||
*/
|
*/
|
||||||
class BlogPostNotifications extends DataExtension {
|
class BlogPostNotifications extends DataExtension
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Notify all authors of notifications.
|
* Notify all authors of notifications.
|
||||||
*
|
*
|
||||||
* @param SS_List $list
|
* @param SS_List $list
|
||||||
* @param mixed $comment
|
* @param mixed $comment
|
||||||
*/
|
*/
|
||||||
public function updateNotificationRecipients(&$list, &$comment) {
|
public function updateNotificationRecipients(&$list, &$comment)
|
||||||
|
{
|
||||||
$list = $this->owner->Authors();
|
$list = $this->owner->Authors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +25,8 @@ class BlogPostNotifications extends DataExtension {
|
|||||||
* @param Comment $comment
|
* @param Comment $comment
|
||||||
* @param Member|string $recipient
|
* @param Member|string $recipient
|
||||||
*/
|
*/
|
||||||
public function updateNotificationSubject(&$subject, &$comment, &$recipient) {
|
public function updateNotificationSubject(&$subject, &$comment, &$recipient)
|
||||||
|
{
|
||||||
$subject = sprintf('A new comment has been posted on ', $this->owner->Title);
|
$subject = sprintf('A new comment has been posted on ', $this->owner->Title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
* @package silverstripe
|
* @package silverstripe
|
||||||
* @subpackage blog
|
* @subpackage blog
|
||||||
*/
|
*/
|
||||||
class URLSegmentExtension extends DataExtension {
|
class URLSegmentExtension extends DataExtension
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -17,7 +18,8 @@ class URLSegmentExtension extends DataExtension {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function onBeforeWrite() {
|
public function onBeforeWrite()
|
||||||
|
{
|
||||||
$this->owner->generateURLSegment();
|
$this->owner->generateURLSegment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,12 +30,13 @@ class URLSegmentExtension extends DataExtension {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function generateURLSegment($increment = null) {
|
public function generateURLSegment($increment = null)
|
||||||
|
{
|
||||||
$filter = new URLSegmentFilter();
|
$filter = new URLSegmentFilter();
|
||||||
|
|
||||||
$this->owner->URLSegment = $filter->filter($this->owner->Title);
|
$this->owner->URLSegment = $filter->filter($this->owner->Title);
|
||||||
|
|
||||||
if(is_int($increment)) {
|
if (is_int($increment)) {
|
||||||
$this->owner->URLSegment .= '-' . $increment;
|
$this->owner->URLSegment .= '-' . $increment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,12 +45,12 @@ class URLSegmentExtension extends DataExtension {
|
|||||||
'BlogID' => $this->owner->BlogID,
|
'BlogID' => $this->owner->BlogID,
|
||||||
));
|
));
|
||||||
|
|
||||||
if($this->owner->ID) {
|
if ($this->owner->ID) {
|
||||||
$duplicate = $duplicate->exclude('ID', $this->owner->ID);
|
$duplicate = $duplicate->exclude('ID', $this->owner->ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($duplicate->count() > 0) {
|
if ($duplicate->count() > 0) {
|
||||||
if(is_int($increment)) {
|
if (is_int($increment)) {
|
||||||
$increment += 1;
|
$increment += 1;
|
||||||
} else {
|
} else {
|
||||||
$increment = 0;
|
$increment = 0;
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class BlogAdminSidebar extends FieldGroup {
|
class BlogAdminSidebar extends FieldGroup
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isOpen() {
|
public function isOpen()
|
||||||
|
{
|
||||||
$sidebar = Cookie::get('blog-admin-sidebar');
|
$sidebar = Cookie::get('blog-admin-sidebar');
|
||||||
|
|
||||||
if($sidebar == 1 || is_null($sidebar)) {
|
if ($sidebar == 1 || is_null($sidebar)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
* @package silverstripe
|
* @package silverstripe
|
||||||
* @subpackage blog
|
* @subpackage blog
|
||||||
*/
|
*/
|
||||||
class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLProvider {
|
class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLProvider
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* HTML Fragment to render the field.
|
* HTML Fragment to render the field.
|
||||||
*
|
*
|
||||||
@ -28,7 +29,8 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
* @param string $targetFragment
|
* @param string $targetFragment
|
||||||
* @param string $dataObjectField
|
* @param string $dataObjectField
|
||||||
*/
|
*/
|
||||||
public function __construct($targetFragment = 'before', $dataObjectField = 'Title') {
|
public function __construct($targetFragment = 'before', $dataObjectField = 'Title')
|
||||||
|
{
|
||||||
$this->targetFragment = $targetFragment;
|
$this->targetFragment = $targetFragment;
|
||||||
$this->dataObjectField = (string) $dataObjectField;
|
$this->dataObjectField = (string) $dataObjectField;
|
||||||
}
|
}
|
||||||
@ -40,7 +42,8 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getActions($gridField) {
|
public function getActions($gridField)
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
'add',
|
'add',
|
||||||
);
|
);
|
||||||
@ -58,8 +61,9 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
*
|
*
|
||||||
* @throws UnexpectedValueException
|
* @throws UnexpectedValueException
|
||||||
*/
|
*/
|
||||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
|
||||||
if($actionName == 'add') {
|
{
|
||||||
|
if ($actionName == 'add') {
|
||||||
$dbField = $this->getDataObjectField();
|
$dbField = $this->getDataObjectField();
|
||||||
|
|
||||||
$objClass = $gridField->getModelClass();
|
$objClass = $gridField->getModelClass();
|
||||||
@ -69,12 +73,12 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
*/
|
*/
|
||||||
$obj = new $objClass();
|
$obj = new $objClass();
|
||||||
|
|
||||||
if($obj->hasField($dbField)) {
|
if ($obj->hasField($dbField)) {
|
||||||
$obj->setCastedField($dbField, $data['gridfieldaddbydbfield'][$obj->ClassName][$dbField]);
|
$obj->setCastedField($dbField, $data['gridfieldaddbydbfield'][$obj->ClassName][$dbField]);
|
||||||
|
|
||||||
if($obj->canCreate()) {
|
if ($obj->canCreate()) {
|
||||||
$id = $gridField->getList()->add($obj);
|
$id = $gridField->getList()->add($obj);
|
||||||
if(!$id) {
|
if (!$id) {
|
||||||
$gridField->setError(
|
$gridField->setError(
|
||||||
_t(
|
_t(
|
||||||
'GridFieldAddByDBField.AddFail',
|
'GridFieldAddByDBField.AddFail',
|
||||||
@ -119,7 +123,8 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getDataObjectField() {
|
public function getDataObjectField()
|
||||||
|
{
|
||||||
return $this->dataObjectField;
|
return $this->dataObjectField;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +133,8 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
*
|
*
|
||||||
* @param $field string
|
* @param $field string
|
||||||
*/
|
*/
|
||||||
public function setDataObjectField($field) {
|
public function setDataObjectField($field)
|
||||||
|
{
|
||||||
$this->dataObjectField = (string) $field;
|
$this->dataObjectField = (string) $field;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +145,8 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getHTMLFragments($gridField) {
|
public function getHTMLFragments($gridField)
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var DataList $dataList
|
* @var DataList $dataList
|
||||||
*/
|
*/
|
||||||
@ -149,7 +156,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
|
|
||||||
$obj = singleton($dataClass);
|
$obj = singleton($dataClass);
|
||||||
|
|
||||||
if(!$obj->canCreate()) {
|
if (!$obj->canCreate()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,21 +7,23 @@
|
|||||||
* @package silverstripe
|
* @package silverstripe
|
||||||
* @subpackage blog
|
* @subpackage blog
|
||||||
*/
|
*/
|
||||||
class GridFieldBlogPostState extends GridFieldSiteTreeState {
|
class GridFieldBlogPostState extends GridFieldSiteTreeState
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getColumnContent($gridField, $record, $columnName) {
|
public function getColumnContent($gridField, $record, $columnName)
|
||||||
if($columnName == 'State') {
|
{
|
||||||
|
if ($columnName == 'State') {
|
||||||
Requirements::css(BLOGGER_DIR . '/css/cms.css');
|
Requirements::css(BLOGGER_DIR . '/css/cms.css');
|
||||||
if($record instanceof BlogPost) {
|
if ($record instanceof BlogPost) {
|
||||||
$modifiedLabel = '';
|
$modifiedLabel = '';
|
||||||
|
|
||||||
if($record->isModifiedOnStage) {
|
if ($record->isModifiedOnStage) {
|
||||||
$modifiedLabel = '<span class="modified">' . _t('GridFieldBlogPostState.Modified') . '</span>';
|
$modifiedLabel = '<span class="modified">' . _t('GridFieldBlogPostState.Modified') . '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$record->isPublished()) {
|
if (!$record->isPublished()) {
|
||||||
/**
|
/**
|
||||||
* @var SS_Datetime $lastEdited
|
* @var SS_Datetime $lastEdited
|
||||||
*/
|
*/
|
||||||
@ -42,7 +44,7 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState {
|
|||||||
*/
|
*/
|
||||||
$publishDate = $record->dbObject('PublishDate');
|
$publishDate = $record->dbObject('PublishDate');
|
||||||
|
|
||||||
if(strtotime($record->PublishDate) > time()) {
|
if (strtotime($record->PublishDate) > time()) {
|
||||||
return _t(
|
return _t(
|
||||||
'GridFieldBlogPostState.Timer',
|
'GridFieldBlogPostState.Timer',
|
||||||
'<i class="gridfield-icon blog-icon-timer"></i> Publish at {date}',
|
'<i class="gridfield-icon blog-icon-timer"></i> Publish at {date}',
|
||||||
@ -70,14 +72,15 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getColumnAttributes($gridField, $record, $columnName) {
|
public function getColumnAttributes($gridField, $record, $columnName)
|
||||||
if($columnName == 'State') {
|
{
|
||||||
if($record instanceof BlogPost) {
|
if ($columnName == 'State') {
|
||||||
|
if ($record instanceof BlogPost) {
|
||||||
$published = $record->isPublished();
|
$published = $record->isPublished();
|
||||||
|
|
||||||
if(!$published) {
|
if (!$published) {
|
||||||
$class = 'gridfield-icon draft';
|
$class = 'gridfield-icon draft';
|
||||||
} else if(strtotime($record->PublishDate) > time()) {
|
} elseif (strtotime($record->PublishDate) > time()) {
|
||||||
$class = 'gridfield-icon timer';
|
$class = 'gridfield-icon timer';
|
||||||
} else {
|
} else {
|
||||||
$class = 'gridfield-icon published';
|
$class = 'gridfield-icon published';
|
||||||
|
@ -6,11 +6,13 @@
|
|||||||
* @package silverstripe
|
* @package silverstripe
|
||||||
* @subpackage blog
|
* @subpackage blog
|
||||||
*/
|
*/
|
||||||
class GridFieldConfig_BlogPost extends GridFieldConfig_Lumberjack {
|
class GridFieldConfig_BlogPost extends GridFieldConfig_Lumberjack
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @param null|int $itemsPerPage
|
* @param null|int $itemsPerPage
|
||||||
*/
|
*/
|
||||||
public function __construct($itemsPerPage = null) {
|
public function __construct($itemsPerPage = null)
|
||||||
|
{
|
||||||
parent::__construct($itemsPerPage);
|
parent::__construct($itemsPerPage);
|
||||||
|
|
||||||
$this->removeComponentsByType('GridFieldSiteTreeState');
|
$this->removeComponentsByType('GridFieldSiteTreeState');
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
* @method ManyManyList Writers() List of writers
|
* @method ManyManyList Writers() List of writers
|
||||||
* @method ManyManyList Contributors() List of contributors
|
* @method ManyManyList Contributors() List of contributors
|
||||||
*/
|
*/
|
||||||
class Blog extends Page implements PermissionProvider {
|
class Blog extends Page implements PermissionProvider
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Permission for user management.
|
* Permission for user management.
|
||||||
*
|
*
|
||||||
@ -103,14 +104,15 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields()
|
||||||
|
{
|
||||||
Requirements::css(BLOGGER_DIR . '/css/cms.css');
|
Requirements::css(BLOGGER_DIR . '/css/cms.css');
|
||||||
Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
|
Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
|
||||||
|
|
||||||
$self =& $this;
|
$self =& $this;
|
||||||
|
|
||||||
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
|
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
|
||||||
if(!$self->canEdit()) {
|
if (!$self->canEdit()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,10 +147,11 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function canEdit($member = null) {
|
public function canEdit($member = null)
|
||||||
|
{
|
||||||
$member = $this->getMember($member);
|
$member = $this->getMember($member);
|
||||||
|
|
||||||
if($this->isEditor($member)) {
|
if ($this->isEditor($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,12 +163,13 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return null|Member
|
* @return null|Member
|
||||||
*/
|
*/
|
||||||
protected function getMember($member = null) {
|
protected function getMember($member = null)
|
||||||
if(!$member) {
|
{
|
||||||
|
if (!$member) {
|
||||||
$member = Member::currentUser();
|
$member = Member::currentUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_numeric($member)) {
|
if (is_numeric($member)) {
|
||||||
$member = Member::get()->byID($member);
|
$member = Member::get()->byID($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +183,8 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isEditor($member) {
|
public function isEditor($member)
|
||||||
|
{
|
||||||
$isEditor = $this->isMemberOf($member, $this->Editors());
|
$isEditor = $this->isMemberOf($member, $this->Editors());
|
||||||
$this->extend('updateIsEditor', $isEditor, $member);
|
$this->extend('updateIsEditor', $isEditor, $member);
|
||||||
|
|
||||||
@ -194,12 +199,13 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isMemberOf($member, $relation) {
|
protected function isMemberOf($member, $relation)
|
||||||
if(!$member || !$member->exists()) {
|
{
|
||||||
|
if (!$member || !$member->exists()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($relation instanceof UnsavedRelationList) {
|
if ($relation instanceof UnsavedRelationList) {
|
||||||
return in_array($member->ID, $relation->getIDList());
|
return in_array($member->ID, $relation->getIDList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,24 +223,25 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return null|string
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
public function RoleOf($member) {
|
public function RoleOf($member)
|
||||||
if(is_numeric($member)) {
|
{
|
||||||
|
if (is_numeric($member)) {
|
||||||
$member = DataObject::get_by_id('Member', $member);
|
$member = DataObject::get_by_id('Member', $member);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$member) {
|
if (!$member) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->isEditor($member)) {
|
if ($this->isEditor($member)) {
|
||||||
return _t('Blog.EDITOR', 'Editor');
|
return _t('Blog.EDITOR', 'Editor');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->isWriter($member)) {
|
if ($this->isWriter($member)) {
|
||||||
return _t('Blog.WRITER', 'Writer');
|
return _t('Blog.WRITER', 'Writer');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->isContributor($member)) {
|
if ($this->isContributor($member)) {
|
||||||
return _t('Blog.CONTRIBUTOR', 'Contributor');
|
return _t('Blog.CONTRIBUTOR', 'Contributor');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +255,8 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isWriter($member) {
|
public function isWriter($member)
|
||||||
|
{
|
||||||
$isWriter = $this->isMemberOf($member, $this->Writers());
|
$isWriter = $this->isMemberOf($member, $this->Writers());
|
||||||
$this->extend('updateIsWriter', $isWriter, $member);
|
$this->extend('updateIsWriter', $isWriter, $member);
|
||||||
|
|
||||||
@ -262,7 +270,8 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isContributor($member) {
|
public function isContributor($member)
|
||||||
|
{
|
||||||
$isContributor = $this->isMemberOf($member, $this->Contributors());
|
$isContributor = $this->isMemberOf($member, $this->Contributors());
|
||||||
$this->extend('updateIsContributor', $isContributor, $member);
|
$this->extend('updateIsContributor', $isContributor, $member);
|
||||||
|
|
||||||
@ -272,10 +281,11 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function canAddChildren($member = null) {
|
public function canAddChildren($member = null)
|
||||||
|
{
|
||||||
$member = $this->getMember($member);
|
$member = $this->getMember($member);
|
||||||
|
|
||||||
if($this->isEditor($member) || $this->isWriter($member) || $this->isContributor($member)) {
|
if ($this->isEditor($member) || $this->isWriter($member) || $this->isContributor($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,7 +295,8 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getSettingsFields() {
|
public function getSettingsFields()
|
||||||
|
{
|
||||||
$fields = parent::getSettingsFields();
|
$fields = parent::getSettingsFields();
|
||||||
|
|
||||||
$fields->addFieldToTab('Root.Settings',
|
$fields->addFieldToTab('Root.Settings',
|
||||||
@ -309,7 +320,7 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
Assign/unassign any member as an author of a particular BlogPost
|
Assign/unassign any member as an author of a particular BlogPost
|
||||||
');
|
');
|
||||||
|
|
||||||
if(!$this->canEditEditors()) {
|
if (!$this->canEditEditors()) {
|
||||||
$editorField = $editorField->performDisabledTransformation();
|
$editorField = $editorField->performDisabledTransformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,7 +336,7 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
Assign/unassign any member as an author of a particular BlogPost they have authored or have been assigned to
|
Assign/unassign any member as an author of a particular BlogPost they have authored or have been assigned to
|
||||||
');
|
');
|
||||||
|
|
||||||
if(!$this->canEditWriters()) {
|
if (!$this->canEditWriters()) {
|
||||||
$writerField = $writerField->performDisabledTransformation();
|
$writerField = $writerField->performDisabledTransformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,7 +351,7 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
Update any BlogPost they have authored or have been assigned to
|
Update any BlogPost they have authored or have been assigned to
|
||||||
');
|
');
|
||||||
|
|
||||||
if(!$this->canEditContributors()) {
|
if (!$this->canEditContributors()) {
|
||||||
$contributorField = $contributorField->performDisabledTransformation();
|
$contributorField = $contributorField->performDisabledTransformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,8 +369,9 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return SS_List
|
* @return SS_List
|
||||||
*/
|
*/
|
||||||
protected function getCandidateUsers() {
|
protected function getCandidateUsers()
|
||||||
if($this->config()->grant_user_access) {
|
{
|
||||||
|
if ($this->config()->grant_user_access) {
|
||||||
$list = Member::get();
|
$list = Member::get();
|
||||||
$this->extend('updateCandidateUsers', $list);
|
$this->extend('updateCandidateUsers', $list);
|
||||||
return $list;
|
return $list;
|
||||||
@ -377,12 +389,13 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canEditEditors($member = null) {
|
public function canEditEditors($member = null)
|
||||||
|
{
|
||||||
$member = $this->getMember($member);
|
$member = $this->getMember($member);
|
||||||
|
|
||||||
$extended = $this->extendedCan('canEditEditors', $member);
|
$extended = $this->extendedCan('canEditEditors', $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,16 +409,17 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function canEditWriters($member = null) {
|
public function canEditWriters($member = null)
|
||||||
|
{
|
||||||
$member = $this->getMember($member);
|
$member = $this->getMember($member);
|
||||||
|
|
||||||
$extended = $this->extendedCan('canEditWriters', $member);
|
$extended = $this->extendedCan('canEditWriters', $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->isEditor($member)) {
|
if ($this->isEditor($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,16 +433,17 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function canEditContributors($member = null) {
|
public function canEditContributors($member = null)
|
||||||
|
{
|
||||||
$member = $this->getMember($member);
|
$member = $this->getMember($member);
|
||||||
|
|
||||||
$extended = $this->extendedCan('canEditContributors', $member);
|
$extended = $this->extendedCan('canEditContributors', $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->isEditor($member)) {
|
if ($this->isEditor($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,12 +459,13 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return DataList
|
* @return DataList
|
||||||
*/
|
*/
|
||||||
public function getArchivedBlogPosts($year, $month = null, $day = null) {
|
public function getArchivedBlogPosts($year, $month = null, $day = null)
|
||||||
|
{
|
||||||
$query = $this->getBlogPosts()->dataQuery();
|
$query = $this->getBlogPosts()->dataQuery();
|
||||||
|
|
||||||
$stage = $query->getQueryParam('Versioned.stage');
|
$stage = $query->getQueryParam('Versioned.stage');
|
||||||
|
|
||||||
if($stage) {
|
if ($stage) {
|
||||||
$stage = '_' . $stage;
|
$stage = '_' . $stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,10 +473,10 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
|
|
||||||
$query->where(sprintf('YEAR("PublishDate") = \'%s\'', Convert::raw2sql($year)));
|
$query->where(sprintf('YEAR("PublishDate") = \'%s\'', Convert::raw2sql($year)));
|
||||||
|
|
||||||
if($month) {
|
if ($month) {
|
||||||
$query->where(sprintf('MONTH("PublishDate") = \'%s\'', Convert::raw2sql($month)));
|
$query->where(sprintf('MONTH("PublishDate") = \'%s\'', Convert::raw2sql($month)));
|
||||||
|
|
||||||
if($day) {
|
if ($day) {
|
||||||
$query->where(sprintf('DAY("PublishDate") = \'%s\'', Convert::raw2sql($day)));
|
$query->where(sprintf('DAY("PublishDate") = \'%s\'', Convert::raw2sql($day)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -473,7 +489,8 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return DataList of BlogPost objects
|
* @return DataList of BlogPost objects
|
||||||
*/
|
*/
|
||||||
public function getBlogPosts() {
|
public function getBlogPosts()
|
||||||
|
{
|
||||||
$blogPosts = BlogPost::get()->filter('ParentID', $this->ID);
|
$blogPosts = BlogPost::get()->filter('ParentID', $this->ID);
|
||||||
|
|
||||||
$this->extend('updateGetBlogPosts', $blogPosts);
|
$this->extend('updateGetBlogPosts', $blogPosts);
|
||||||
@ -488,7 +505,8 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function ProfileLink($urlSegment) {
|
public function ProfileLink($urlSegment)
|
||||||
|
{
|
||||||
return Controller::join_links($this->Link(), 'profile', $urlSegment);
|
return Controller::join_links($this->Link(), 'profile', $urlSegment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,7 +515,8 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getLumberjackTitle() {
|
public function getLumberjackTitle()
|
||||||
|
{
|
||||||
return _t('Blog.LumberjackTitle', 'Blog Posts');
|
return _t('Blog.LumberjackTitle', 'Blog Posts');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,14 +525,16 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return GridFieldConfig
|
* @return GridFieldConfig
|
||||||
*/
|
*/
|
||||||
public function getLumberjackGridFieldConfig() {
|
public function getLumberjackGridFieldConfig()
|
||||||
|
{
|
||||||
return GridFieldConfig_BlogPost::create();
|
return GridFieldConfig_BlogPost::create();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function providePermissions() {
|
public function providePermissions()
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
Blog::MANAGE_USERS => array(
|
Blog::MANAGE_USERS => array(
|
||||||
'name' => _t(
|
'name' => _t(
|
||||||
@ -533,7 +554,8 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function onBeforeWrite() {
|
protected function onBeforeWrite()
|
||||||
|
{
|
||||||
parent::onBeforeWrite();
|
parent::onBeforeWrite();
|
||||||
$this->assignGroup();
|
$this->assignGroup();
|
||||||
}
|
}
|
||||||
@ -541,8 +563,9 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
/**
|
/**
|
||||||
* Assign users as necessary to the blog group.
|
* Assign users as necessary to the blog group.
|
||||||
*/
|
*/
|
||||||
protected function assignGroup() {
|
protected function assignGroup()
|
||||||
if(!$this->config()->grant_user_access) {
|
{
|
||||||
|
if (!$this->config()->grant_user_access) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -550,9 +573,9 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
|
|
||||||
// Must check if the method exists or else an error occurs when changing page type
|
// Must check if the method exists or else an error occurs when changing page type
|
||||||
if ($this->hasMethod('Editors')) {
|
if ($this->hasMethod('Editors')) {
|
||||||
foreach(array($this->Editors(), $this->Writers(), $this->Contributors()) as $levels) {
|
foreach (array($this->Editors(), $this->Writers(), $this->Contributors()) as $levels) {
|
||||||
foreach($levels as $user) {
|
foreach ($levels as $user) {
|
||||||
if(!$user->inGroup($group)) {
|
if (!$user->inGroup($group)) {
|
||||||
$user->Groups()->add($group);
|
$user->Groups()->add($group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -565,12 +588,13 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
*
|
*
|
||||||
* @return Group
|
* @return Group
|
||||||
*/
|
*/
|
||||||
protected function getUserGroup() {
|
protected function getUserGroup()
|
||||||
|
{
|
||||||
$code = $this->config()->grant_user_group;
|
$code = $this->config()->grant_user_group;
|
||||||
|
|
||||||
$group = Group::get()->filter('Code', $code)->first();
|
$group = Group::get()->filter('Code', $code)->first();
|
||||||
|
|
||||||
if($group) {
|
if ($group) {
|
||||||
return $group;
|
return $group;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,7 +617,8 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
* @package silverstripe
|
* @package silverstripe
|
||||||
* @subpackage blog
|
* @subpackage blog
|
||||||
*/
|
*/
|
||||||
class Blog_Controller extends Page_Controller {
|
class Blog_Controller extends Page_Controller
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -633,7 +658,8 @@ class Blog_Controller extends Page_Controller {
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function index() {
|
public function index()
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var Blog $dataRecord
|
* @var Blog $dataRecord
|
||||||
*/
|
*/
|
||||||
@ -649,10 +675,11 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return SS_HTTPResponse
|
* @return SS_HTTPResponse
|
||||||
*/
|
*/
|
||||||
public function profile() {
|
public function profile()
|
||||||
|
{
|
||||||
$profile = $this->getCurrentProfile();
|
$profile = $this->getCurrentProfile();
|
||||||
|
|
||||||
if(!$profile) {
|
if (!$profile) {
|
||||||
return $this->httpError(404, 'Not Found');
|
return $this->httpError(404, 'Not Found');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,10 +693,11 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return null|Member
|
* @return null|Member
|
||||||
*/
|
*/
|
||||||
public function getCurrentProfile() {
|
public function getCurrentProfile()
|
||||||
|
{
|
||||||
$urlSegment = $this->request->param('URLSegment');
|
$urlSegment = $this->request->param('URLSegment');
|
||||||
|
|
||||||
if($urlSegment) {
|
if ($urlSegment) {
|
||||||
return Member::get()
|
return Member::get()
|
||||||
->filter('URLSegment', $urlSegment)
|
->filter('URLSegment', $urlSegment)
|
||||||
->first();
|
->first();
|
||||||
@ -683,10 +711,11 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return null|DataList
|
* @return null|DataList
|
||||||
*/
|
*/
|
||||||
public function getCurrentProfilePosts() {
|
public function getCurrentProfilePosts()
|
||||||
|
{
|
||||||
$profile = $this->getCurrentProfile();
|
$profile = $this->getCurrentProfile();
|
||||||
|
|
||||||
if($profile) {
|
if ($profile) {
|
||||||
return $profile->BlogPosts()->filter('ParentID', $this->ID);
|
return $profile->BlogPosts()->filter('ParentID', $this->ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -698,7 +727,8 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return null|SS_HTTPResponse
|
* @return null|SS_HTTPResponse
|
||||||
*/
|
*/
|
||||||
public function archive() {
|
public function archive()
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var Blog $dataRecord
|
* @var Blog $dataRecord
|
||||||
*/
|
*/
|
||||||
@ -708,15 +738,15 @@ class Blog_Controller extends Page_Controller {
|
|||||||
$month = $this->getArchiveMonth();
|
$month = $this->getArchiveMonth();
|
||||||
$day = $this->getArchiveDay();
|
$day = $this->getArchiveDay();
|
||||||
|
|
||||||
if($this->request->param('Month') && !$month) {
|
if ($this->request->param('Month') && !$month) {
|
||||||
$this->httpError(404, 'Not Found');
|
$this->httpError(404, 'Not Found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($month && $this->request->param('Day') && !$day) {
|
if ($month && $this->request->param('Day') && !$day) {
|
||||||
$this->httpError(404, 'Not Found');
|
$this->httpError(404, 'Not Found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($year) {
|
if ($year) {
|
||||||
$this->blogPosts = $dataRecord->getArchivedBlogPosts($year, $month, $day);
|
$this->blogPosts = $dataRecord->getArchivedBlogPosts($year, $month, $day);
|
||||||
|
|
||||||
return $this->render();
|
return $this->render();
|
||||||
@ -732,14 +762,13 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getArchiveYear() {
|
public function getArchiveYear()
|
||||||
|
{
|
||||||
if($this->request->param('Year')){
|
if ($this->request->param('Year')) {
|
||||||
|
if (preg_match('/^[0-9]{4}$/', $year = $this->request->param('Year'))) {
|
||||||
if(preg_match('/^[0-9]{4}$/', $year = $this->request->param('Year'))) {
|
|
||||||
return (int) $year;
|
return (int) $year;
|
||||||
}
|
}
|
||||||
} elseif($this->request->param('Action') == 'archive') {
|
} elseif ($this->request->param('Action') == 'archive') {
|
||||||
return SS_Datetime::now()->Year();
|
return SS_Datetime::now()->Year();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -751,12 +780,13 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return null|int
|
* @return null|int
|
||||||
*/
|
*/
|
||||||
public function getArchiveMonth() {
|
public function getArchiveMonth()
|
||||||
|
{
|
||||||
$month = $this->request->param('Month');
|
$month = $this->request->param('Month');
|
||||||
|
|
||||||
if(preg_match('/^[0-9]{1,2}$/', $month)) {
|
if (preg_match('/^[0-9]{1,2}$/', $month)) {
|
||||||
if($month > 0 && $month < 13) {
|
if ($month > 0 && $month < 13) {
|
||||||
if(checkdate($month, 01, $this->getArchiveYear())) {
|
if (checkdate($month, 01, $this->getArchiveYear())) {
|
||||||
return (int) $month;
|
return (int) $month;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -770,11 +800,12 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return null|int
|
* @return null|int
|
||||||
*/
|
*/
|
||||||
public function getArchiveDay() {
|
public function getArchiveDay()
|
||||||
|
{
|
||||||
$day = $this->request->param('Day');
|
$day = $this->request->param('Day');
|
||||||
|
|
||||||
if(preg_match('/^[0-9]{1,2}$/', $day)) {
|
if (preg_match('/^[0-9]{1,2}$/', $day)) {
|
||||||
if(checkdate($this->getArchiveMonth(), $day, $this->getArchiveYear())) {
|
if (checkdate($this->getArchiveMonth(), $day, $this->getArchiveYear())) {
|
||||||
return (int) $day;
|
return (int) $day;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -787,10 +818,11 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return null|SS_HTTPResponse
|
* @return null|SS_HTTPResponse
|
||||||
*/
|
*/
|
||||||
public function tag() {
|
public function tag()
|
||||||
|
{
|
||||||
$tag = $this->getCurrentTag();
|
$tag = $this->getCurrentTag();
|
||||||
|
|
||||||
if($tag) {
|
if ($tag) {
|
||||||
$this->blogPosts = $tag->BlogPosts();
|
$this->blogPosts = $tag->BlogPosts();
|
||||||
return $this->render();
|
return $this->render();
|
||||||
}
|
}
|
||||||
@ -805,13 +837,14 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return null|BlogTag
|
* @return null|BlogTag
|
||||||
*/
|
*/
|
||||||
public function getCurrentTag() {
|
public function getCurrentTag()
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var Blog $dataRecord
|
* @var Blog $dataRecord
|
||||||
*/
|
*/
|
||||||
$dataRecord = $this->dataRecord;
|
$dataRecord = $this->dataRecord;
|
||||||
$tag = $this->request->param('Tag');
|
$tag = $this->request->param('Tag');
|
||||||
if($tag) {
|
if ($tag) {
|
||||||
return $dataRecord->Tags()
|
return $dataRecord->Tags()
|
||||||
->filter('URLSegment', array($tag, rawurlencode($tag)))
|
->filter('URLSegment', array($tag, rawurlencode($tag)))
|
||||||
->first();
|
->first();
|
||||||
@ -824,10 +857,11 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return null|SS_HTTPResponse
|
* @return null|SS_HTTPResponse
|
||||||
*/
|
*/
|
||||||
public function category() {
|
public function category()
|
||||||
|
{
|
||||||
$category = $this->getCurrentCategory();
|
$category = $this->getCurrentCategory();
|
||||||
|
|
||||||
if($category) {
|
if ($category) {
|
||||||
$this->blogPosts = $category->BlogPosts();
|
$this->blogPosts = $category->BlogPosts();
|
||||||
|
|
||||||
return $this->render();
|
return $this->render();
|
||||||
@ -843,13 +877,14 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return null|BlogCategory
|
* @return null|BlogCategory
|
||||||
*/
|
*/
|
||||||
public function getCurrentCategory() {
|
public function getCurrentCategory()
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var Blog $dataRecord
|
* @var Blog $dataRecord
|
||||||
*/
|
*/
|
||||||
$dataRecord = $this->dataRecord;
|
$dataRecord = $this->dataRecord;
|
||||||
$category = $this->request->param('Category');
|
$category = $this->request->param('Category');
|
||||||
if($category) {
|
if ($category) {
|
||||||
return $dataRecord->Categories()
|
return $dataRecord->Categories()
|
||||||
->filter('URLSegment', array($category, rawurlencode($category)))
|
->filter('URLSegment', array($category, rawurlencode($category)))
|
||||||
->first();
|
->first();
|
||||||
@ -862,11 +897,12 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getMetaTitle() {
|
public function getMetaTitle()
|
||||||
|
{
|
||||||
$title = $this->data()->getTitle();
|
$title = $this->data()->getTitle();
|
||||||
$filter = $this->getFilterDescription();
|
$filter = $this->getFilterDescription();
|
||||||
|
|
||||||
if($filter) {
|
if ($filter) {
|
||||||
$title = sprintf('%s - %s', $title, $filter);
|
$title = sprintf('%s - %s', $title, $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -880,13 +916,14 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getFilterDescription() {
|
public function getFilterDescription()
|
||||||
|
{
|
||||||
$items = array();
|
$items = array();
|
||||||
|
|
||||||
$list = $this->PaginatedList();
|
$list = $this->PaginatedList();
|
||||||
$currentPage = $list->CurrentPage();
|
$currentPage = $list->CurrentPage();
|
||||||
|
|
||||||
if($currentPage > 1) {
|
if ($currentPage > 1) {
|
||||||
$items[] = _t(
|
$items[] = _t(
|
||||||
'Blog.FILTERDESCRIPTION_PAGE',
|
'Blog.FILTERDESCRIPTION_PAGE',
|
||||||
'Page {page}',
|
'Page {page}',
|
||||||
@ -897,7 +934,7 @@ class Blog_Controller extends Page_Controller {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($author = $this->getCurrentProfile()) {
|
if ($author = $this->getCurrentProfile()) {
|
||||||
$items[] = _t(
|
$items[] = _t(
|
||||||
'Blog.FILTERDESCRIPTION_AUTHOR',
|
'Blog.FILTERDESCRIPTION_AUTHOR',
|
||||||
'By {author}',
|
'By {author}',
|
||||||
@ -908,7 +945,7 @@ class Blog_Controller extends Page_Controller {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($tag = $this->getCurrentTag()) {
|
if ($tag = $this->getCurrentTag()) {
|
||||||
$items[] = _t(
|
$items[] = _t(
|
||||||
'Blog.FILTERDESCRIPTION_TAG',
|
'Blog.FILTERDESCRIPTION_TAG',
|
||||||
'Tagged with {tag}',
|
'Tagged with {tag}',
|
||||||
@ -919,7 +956,7 @@ class Blog_Controller extends Page_Controller {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($category = $this->getCurrentCategory()) {
|
if ($category = $this->getCurrentCategory()) {
|
||||||
$items[] = _t(
|
$items[] = _t(
|
||||||
'Blog.FILTERDESCRIPTION_CATEGORY',
|
'Blog.FILTERDESCRIPTION_CATEGORY',
|
||||||
'In category {category}',
|
'In category {category}',
|
||||||
@ -930,10 +967,10 @@ class Blog_Controller extends Page_Controller {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->owner->getArchiveYear()) {
|
if ($this->owner->getArchiveYear()) {
|
||||||
if($this->owner->getArchiveDay()) {
|
if ($this->owner->getArchiveDay()) {
|
||||||
$date = $this->owner->getArchiveDate()->Nice();
|
$date = $this->owner->getArchiveDate()->Nice();
|
||||||
} elseif($this->owner->getArchiveMonth()) {
|
} elseif ($this->owner->getArchiveMonth()) {
|
||||||
$date = $this->owner->getArchiveDate()->format('F, Y');
|
$date = $this->owner->getArchiveDate()->format('F, Y');
|
||||||
} else {
|
} else {
|
||||||
$date = $this->owner->getArchiveDate()->format('Y');
|
$date = $this->owner->getArchiveDate()->format('Y');
|
||||||
@ -951,7 +988,7 @@ class Blog_Controller extends Page_Controller {
|
|||||||
|
|
||||||
$result = '';
|
$result = '';
|
||||||
|
|
||||||
if($items) {
|
if ($items) {
|
||||||
$result = implode(', ', $items);
|
$result = implode(', ', $items);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -965,15 +1002,16 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return PaginatedList
|
* @return PaginatedList
|
||||||
*/
|
*/
|
||||||
public function PaginatedList() {
|
public function PaginatedList()
|
||||||
|
{
|
||||||
$allPosts = $this->blogPosts ?: new ArrayList();
|
$allPosts = $this->blogPosts ?: new ArrayList();
|
||||||
|
|
||||||
$posts = new PaginatedList($allPosts);
|
$posts = new PaginatedList($allPosts);
|
||||||
|
|
||||||
// Set appropriate page size
|
// Set appropriate page size
|
||||||
if($this->PostsPerPage > 0) {
|
if ($this->PostsPerPage > 0) {
|
||||||
$pageSize = $this->PostsPerPage;
|
$pageSize = $this->PostsPerPage;
|
||||||
} elseif($count = $allPosts->count()) {
|
} elseif ($count = $allPosts->count()) {
|
||||||
$pageSize = $count;
|
$pageSize = $count;
|
||||||
} else {
|
} else {
|
||||||
$pageSize = 99999;
|
$pageSize = 99999;
|
||||||
@ -992,7 +1030,8 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function rss() {
|
public function rss()
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var Blog $dataRecord
|
* @var Blog $dataRecord
|
||||||
*/
|
*/
|
||||||
@ -1012,16 +1051,17 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return null|Date
|
* @return null|Date
|
||||||
*/
|
*/
|
||||||
public function getArchiveDate() {
|
public function getArchiveDate()
|
||||||
|
{
|
||||||
$year = $this->getArchiveYear();
|
$year = $this->getArchiveYear();
|
||||||
$month = $this->getArchiveMonth();
|
$month = $this->getArchiveMonth();
|
||||||
$day = $this->getArchiveDay();
|
$day = $this->getArchiveDay();
|
||||||
|
|
||||||
if($year) {
|
if ($year) {
|
||||||
if($month) {
|
if ($month) {
|
||||||
$date = sprintf('%s-%s-01', $year, $month);
|
$date = sprintf('%s-%s-01', $year, $month);
|
||||||
|
|
||||||
if($day) {
|
if ($day) {
|
||||||
$date = sprintf('%s-%s-%s', $year, $month, $day);
|
$date = sprintf('%s-%s-%s', $year, $month, $day);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1039,7 +1079,8 @@ class Blog_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getRSSLink() {
|
public function getRSSLink()
|
||||||
|
{
|
||||||
return $this->Link('rss');
|
return $this->Link('rss');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
* @property string $URLSegment
|
* @property string $URLSegment
|
||||||
* @property int $BlogID
|
* @property int $BlogID
|
||||||
*/
|
*/
|
||||||
class BlogCategory extends DataObject implements CategorisationObject {
|
class BlogCategory extends DataObject implements CategorisationObject
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -43,7 +44,8 @@ class BlogCategory extends DataObject implements CategorisationObject {
|
|||||||
/**
|
/**
|
||||||
* @return DataList
|
* @return DataList
|
||||||
*/
|
*/
|
||||||
public function BlogPosts() {
|
public function BlogPosts()
|
||||||
|
{
|
||||||
$blogPosts = parent::BlogPosts();
|
$blogPosts = parent::BlogPosts();
|
||||||
|
|
||||||
$this->extend("updateGetBlogPosts", $blogPosts);
|
$this->extend("updateGetBlogPosts", $blogPosts);
|
||||||
@ -54,7 +56,8 @@ class BlogCategory extends DataObject implements CategorisationObject {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields()
|
||||||
|
{
|
||||||
$fields = new FieldList(
|
$fields = new FieldList(
|
||||||
TextField::create('Title', _t('BlogCategory.Title', 'Title'))
|
TextField::create('Title', _t('BlogCategory.Title', 'Title'))
|
||||||
);
|
);
|
||||||
@ -69,7 +72,8 @@ class BlogCategory extends DataObject implements CategorisationObject {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getLink() {
|
public function getLink()
|
||||||
|
{
|
||||||
return Controller::join_links($this->Blog()->Link(), 'category', $this->URLSegment);
|
return Controller::join_links($this->Blog()->Link(), 'category', $this->URLSegment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,10 +84,11 @@ class BlogCategory extends DataObject implements CategorisationObject {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canView($member = null) {
|
public function canView($member = null)
|
||||||
|
{
|
||||||
$extended = $this->extendedCan(__FUNCTION__, $member);
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,10 +102,11 @@ class BlogCategory extends DataObject implements CategorisationObject {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canCreate($member = null) {
|
public function canCreate($member = null)
|
||||||
|
{
|
||||||
$extended = $this->extendedCan(__FUNCTION__, $member);
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,10 +122,11 @@ class BlogCategory extends DataObject implements CategorisationObject {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canDelete($member = null) {
|
public function canDelete($member = null)
|
||||||
|
{
|
||||||
$extended = $this->extendedCan(__FUNCTION__, $member);
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,10 +140,11 @@ class BlogCategory extends DataObject implements CategorisationObject {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canEdit($member = null) {
|
public function canEdit($member = null)
|
||||||
|
{
|
||||||
$extended = $this->extendedCan(__FUNCTION__, $member);
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
* @property string $AuthorNames
|
* @property string $AuthorNames
|
||||||
* @property int $ParentID
|
* @property int $ParentID
|
||||||
*/
|
*/
|
||||||
class BlogPost extends Page {
|
class BlogPost extends Page
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Same as above, but for list of users that can be
|
* Same as above, but for list of users that can be
|
||||||
* given credit in the author field for blog posts
|
* given credit in the author field for blog posts
|
||||||
@ -122,20 +122,21 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return null|string
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
public function RoleOf($member = null) {
|
public function RoleOf($member = null)
|
||||||
|
{
|
||||||
$member = $this->getMember($member);
|
$member = $this->getMember($member);
|
||||||
|
|
||||||
if(!$member) {
|
if (!$member) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->isAuthor($member)) {
|
if ($this->isAuthor($member)) {
|
||||||
return _t('BlogPost.AUTHOR', 'Author');
|
return _t('BlogPost.AUTHOR', 'Author');
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent = $this->Parent();
|
$parent = $this->Parent();
|
||||||
|
|
||||||
if($parent instanceof Blog) {
|
if ($parent instanceof Blog) {
|
||||||
return $parent->RoleOf($member);
|
return $parent->RoleOf($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,14 +150,15 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isAuthor($member = null) {
|
public function isAuthor($member = null)
|
||||||
if(!$member || !$member->exists()) {
|
{
|
||||||
|
if (!$member || !$member->exists()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = $this->Authors();
|
$list = $this->Authors();
|
||||||
|
|
||||||
if($list instanceof UnsavedRelationList) {
|
if ($list instanceof UnsavedRelationList) {
|
||||||
return in_array($member->ID, $list->getIDList());
|
return in_array($member->ID, $list->getIDList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +168,8 @@ class BlogPost extends Page {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields()
|
||||||
|
{
|
||||||
Requirements::css(BLOGGER_DIR . '/css/cms.css');
|
Requirements::css(BLOGGER_DIR . '/css/cms.css');
|
||||||
Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
|
Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
|
||||||
|
|
||||||
@ -226,14 +229,14 @@ class BlogPost extends Page {
|
|||||||
'If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.')
|
'If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.')
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!$self->canEditAuthors()) {
|
if (!$self->canEditAuthors()) {
|
||||||
$authorField = $authorField->performDisabledTransformation();
|
$authorField = $authorField->performDisabledTransformation();
|
||||||
$authorNames = $authorNames->performDisabledTransformation();
|
$authorNames = $authorNames->performDisabledTransformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
$publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date'));
|
$publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date'));
|
||||||
$publishDate->getDateField()->setConfig('showcalendar', true);
|
$publishDate->getDateField()->setConfig('showcalendar', true);
|
||||||
if(!$self->PublishDate) {
|
if (!$self->PublishDate) {
|
||||||
$publishDate->setDescription(_t(
|
$publishDate->setDescription(_t(
|
||||||
'BlogPost.PublishDate_Description',
|
'BlogPost.PublishDate_Description',
|
||||||
'Will be set to "now" if published without a value.')
|
'Will be set to "now" if published without a value.')
|
||||||
@ -289,8 +292,9 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return SS_List
|
* @return SS_List
|
||||||
*/
|
*/
|
||||||
public function getCandidateAuthors() {
|
public function getCandidateAuthors()
|
||||||
if($this->config()->restrict_authors_to_group) {
|
{
|
||||||
|
if ($this->config()->restrict_authors_to_group) {
|
||||||
return Group::get()->filter('Code', $this->config()->restrict_authors_to_group)->first()->Members();
|
return Group::get()->filter('Code', $this->config()->restrict_authors_to_group)->first()->Members();
|
||||||
} else {
|
} else {
|
||||||
$list = Member::get();
|
$list = Member::get();
|
||||||
@ -306,23 +310,24 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canEditAuthors($member = null) {
|
public function canEditAuthors($member = null)
|
||||||
|
{
|
||||||
$member = $this->getMember($member);
|
$member = $this->getMember($member);
|
||||||
|
|
||||||
$extended = $this->extendedCan('canEditAuthors', $member);
|
$extended = $this->extendedCan('canEditAuthors', $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent = $this->Parent();
|
$parent = $this->Parent();
|
||||||
|
|
||||||
if($parent instanceof Blog && $parent->exists()) {
|
if ($parent instanceof Blog && $parent->exists()) {
|
||||||
if($parent->isEditor($member)) {
|
if ($parent->isEditor($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($parent->isWriter($member) && $this->isAuthor($member)) {
|
if ($parent->isWriter($member) && $this->isAuthor($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,12 +340,13 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return null|Member
|
* @return null|Member
|
||||||
*/
|
*/
|
||||||
protected function getMember($member = null) {
|
protected function getMember($member = null)
|
||||||
if(!$member) {
|
{
|
||||||
|
if (!$member) {
|
||||||
$member = Member::currentUser();
|
$member = Member::currentUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_numeric($member)) {
|
if (is_numeric($member)) {
|
||||||
$member = Member::get()->byID($member);
|
$member = Member::get()->byID($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,16 +360,17 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canCreateCategories($member = null) {
|
public function canCreateCategories($member = null)
|
||||||
|
{
|
||||||
$member = $this->getMember($member);
|
$member = $this->getMember($member);
|
||||||
|
|
||||||
$parent = $this->Parent();
|
$parent = $this->Parent();
|
||||||
|
|
||||||
if(!$parent || !$parent->exists() || !($parent instanceof Blog)) {
|
if (!$parent || !$parent->exists() || !($parent instanceof Blog)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($parent->isEditor($member)) {
|
if ($parent->isEditor($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,20 +384,21 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canCreateTags($member = null) {
|
public function canCreateTags($member = null)
|
||||||
|
{
|
||||||
$member = $this->getMember($member);
|
$member = $this->getMember($member);
|
||||||
|
|
||||||
$parent = $this->Parent();
|
$parent = $this->Parent();
|
||||||
|
|
||||||
if(!$parent || !$parent->exists() || !($parent instanceof Blog)) {
|
if (!$parent || !$parent->exists() || !($parent instanceof Blog)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($parent->isEditor($member)) {
|
if ($parent->isEditor($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($parent->isWriter($member)) {
|
if ($parent->isWriter($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -402,13 +410,14 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* Update the PublishDate to now if the BlogPost would otherwise be published without a date.
|
* Update the PublishDate to now if the BlogPost would otherwise be published without a date.
|
||||||
*/
|
*/
|
||||||
public function onBeforePublish() {
|
public function onBeforePublish()
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var SS_Datetime $publishDate
|
* @var SS_Datetime $publishDate
|
||||||
*/
|
*/
|
||||||
$publishDate = $this->dbObject('PublishDate');
|
$publishDate = $this->dbObject('PublishDate');
|
||||||
|
|
||||||
if(!$publishDate->getValue()) {
|
if (!$publishDate->getValue()) {
|
||||||
$this->PublishDate = SS_Datetime::now()->getValue();
|
$this->PublishDate = SS_Datetime::now()->getValue();
|
||||||
$this->write();
|
$this->write();
|
||||||
}
|
}
|
||||||
@ -419,10 +428,11 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* Sets blog relationship on all categories and tags assigned to this post.
|
* Sets blog relationship on all categories and tags assigned to this post.
|
||||||
*/
|
*/
|
||||||
public function onAfterWrite() {
|
public function onAfterWrite()
|
||||||
|
{
|
||||||
parent::onAfterWrite();
|
parent::onAfterWrite();
|
||||||
|
|
||||||
foreach($this->Categories() as $category) {
|
foreach ($this->Categories() as $category) {
|
||||||
/**
|
/**
|
||||||
* @var BlogCategory $category
|
* @var BlogCategory $category
|
||||||
*/
|
*/
|
||||||
@ -430,7 +440,7 @@ class BlogPost extends Page {
|
|||||||
$category->write();
|
$category->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->Tags() as $tag) {
|
foreach ($this->Tags() as $tag) {
|
||||||
/**
|
/**
|
||||||
* @var BlogTag $tag
|
* @var BlogTag $tag
|
||||||
*/
|
*/
|
||||||
@ -442,10 +452,11 @@ class BlogPost extends Page {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function canView($member = null) {
|
public function canView($member = null)
|
||||||
|
{
|
||||||
$member = $this->getMember($member);
|
$member = $this->getMember($member);
|
||||||
|
|
||||||
if(!parent::canView($member)) {
|
if (!parent::canView($member)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,7 +466,7 @@ class BlogPost extends Page {
|
|||||||
$publishDate = $this->dbObject('PublishDate');
|
$publishDate = $this->dbObject('PublishDate');
|
||||||
|
|
||||||
// Show past posts
|
// Show past posts
|
||||||
if(!$publishDate->exists() || !$publishDate->InFuture()) {
|
if (!$publishDate->exists() || !$publishDate->InFuture()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,31 +477,32 @@ class BlogPost extends Page {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function canPublish($member = null) {
|
public function canPublish($member = null)
|
||||||
|
{
|
||||||
$member = $this->getMember($member);
|
$member = $this->getMember($member);
|
||||||
|
|
||||||
if(Permission::checkMember($member, 'ADMIN')) {
|
if (Permission::checkMember($member, 'ADMIN')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$extended = $this->extendedCan('canPublish', $member);
|
$extended = $this->extendedCan('canPublish', $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent = $this->Parent();
|
$parent = $this->Parent();
|
||||||
|
|
||||||
if($parent instanceof Blog && $parent->exists()) {
|
if ($parent instanceof Blog && $parent->exists()) {
|
||||||
if($parent->isEditor($member)) {
|
if ($parent->isEditor($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($parent->isWriter($member) && $this->isAuthor($member)) {
|
if ($parent->isWriter($member) && $this->isAuthor($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($parent->isContributor($member)) {
|
if ($parent->isContributor($member)) {
|
||||||
return parent::canEdit($member);
|
return parent::canEdit($member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -501,24 +513,25 @@ class BlogPost extends Page {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function canEdit($member = null) {
|
public function canEdit($member = null)
|
||||||
|
{
|
||||||
$member = $this->getMember($member);
|
$member = $this->getMember($member);
|
||||||
|
|
||||||
if(parent::canEdit($member)) {
|
if (parent::canEdit($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent = $this->Parent();
|
$parent = $this->Parent();
|
||||||
|
|
||||||
if(!$parent || !$parent->exists() || !($parent instanceof Blog)) {
|
if (!$parent || !$parent->exists() || !($parent instanceof Blog)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($parent->isEditor($member)) {
|
if ($parent->isEditor($member)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$parent->isWriter($member) && !$parent->isContributor($member)) {
|
if (!$parent->isWriter($member) && !$parent->isContributor($member)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -532,7 +545,8 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function Excerpt($wordsToDisplay = 30) {
|
public function Excerpt($wordsToDisplay = 30)
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var Text $content
|
* @var Text $content
|
||||||
*/
|
*/
|
||||||
@ -548,14 +562,15 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getMonthlyArchiveLink($type = 'day') {
|
public function getMonthlyArchiveLink($type = 'day')
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var SS_Datetime $date
|
* @var SS_Datetime $date
|
||||||
*/
|
*/
|
||||||
$date = $this->dbObject('PublishDate');
|
$date = $this->dbObject('PublishDate');
|
||||||
|
|
||||||
if($type != 'year') {
|
if ($type != 'year') {
|
||||||
if($type == 'day') {
|
if ($type == 'day') {
|
||||||
return Controller::join_links(
|
return Controller::join_links(
|
||||||
$this->Parent()->Link('archive'),
|
$this->Parent()->Link('archive'),
|
||||||
$date->format('Y'),
|
$date->format('Y'),
|
||||||
@ -575,7 +590,8 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getYearlyArchiveLink() {
|
public function getYearlyArchiveLink()
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var SS_Datetime $date
|
* @var SS_Datetime $date
|
||||||
*/
|
*/
|
||||||
@ -589,7 +605,8 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return ArrayList
|
* @return ArrayList
|
||||||
*/
|
*/
|
||||||
public function getCredits() {
|
public function getCredits()
|
||||||
|
{
|
||||||
$list = new ArrayList();
|
$list = new ArrayList();
|
||||||
|
|
||||||
$list->merge($this->getDynamicCredits());
|
$list->merge($this->getDynamicCredits());
|
||||||
@ -603,22 +620,23 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return ArrayList
|
* @return ArrayList
|
||||||
*/
|
*/
|
||||||
protected function getDynamicCredits() {
|
protected function getDynamicCredits()
|
||||||
|
{
|
||||||
// Find best page to host user profiles
|
// Find best page to host user profiles
|
||||||
$parent = $this->Parent();
|
$parent = $this->Parent();
|
||||||
if(! ($parent instanceof Blog) ) {
|
if (! ($parent instanceof Blog)) {
|
||||||
$parent = Blog::get()->first();
|
$parent = Blog::get()->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no parent blog, return list undecorated
|
// If there is no parent blog, return list undecorated
|
||||||
if(!$parent) {
|
if (!$parent) {
|
||||||
$items = $this->Authors()->toArray();
|
$items = $this->Authors()->toArray();
|
||||||
return new ArrayList($items);
|
return new ArrayList($items);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update all authors
|
// Update all authors
|
||||||
$items = new ArrayList();
|
$items = new ArrayList();
|
||||||
foreach($this->Authors() as $author) {
|
foreach ($this->Authors() as $author) {
|
||||||
// Add link for each author
|
// Add link for each author
|
||||||
$author = $author->customise(array(
|
$author = $author->customise(array(
|
||||||
'URL' => $parent->ProfileLink($author->URLSegment),
|
'URL' => $parent->ProfileLink($author->URLSegment),
|
||||||
@ -634,12 +652,13 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return ArrayList
|
* @return ArrayList
|
||||||
*/
|
*/
|
||||||
protected function getStaticCredits() {
|
protected function getStaticCredits()
|
||||||
|
{
|
||||||
$items = new ArrayList();
|
$items = new ArrayList();
|
||||||
|
|
||||||
$authors = array_filter(preg_split('/\s*,\s*/', $this->AuthorNames));
|
$authors = array_filter(preg_split('/\s*,\s*/', $this->AuthorNames));
|
||||||
|
|
||||||
foreach($authors as $author) {
|
foreach ($authors as $author) {
|
||||||
$item = new ArrayData(array(
|
$item = new ArrayData(array(
|
||||||
'Name' => $author,
|
'Name' => $author,
|
||||||
));
|
));
|
||||||
@ -657,7 +676,8 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function fieldLabels($includeRelations = true) {
|
public function fieldLabels($includeRelations = true)
|
||||||
|
{
|
||||||
$labels = parent::fieldLabels($includeRelations);
|
$labels = parent::fieldLabels($includeRelations);
|
||||||
|
|
||||||
$labels['Title'] = _t('BlogPost.PageTitleLabel', 'Post Title');
|
$labels['Title'] = _t('BlogPost.PageTitleLabel', 'Post Title');
|
||||||
@ -668,10 +688,11 @@ class BlogPost extends Page {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function onBeforeWrite() {
|
protected function onBeforeWrite()
|
||||||
|
{
|
||||||
parent::onBeforeWrite();
|
parent::onBeforeWrite();
|
||||||
|
|
||||||
if(!$this->exists() && ($member = Member::currentUser())) {
|
if (!$this->exists() && ($member = Member::currentUser())) {
|
||||||
$this->Authors()->add($member);
|
$this->Authors()->add($member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -681,6 +702,6 @@ class BlogPost extends Page {
|
|||||||
* @package silverstripe
|
* @package silverstripe
|
||||||
* @subpackage blog
|
* @subpackage blog
|
||||||
*/
|
*/
|
||||||
class BlogPost_Controller extends Page_Controller {
|
class BlogPost_Controller extends Page_Controller
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
* @property string $URLSegment
|
* @property string $URLSegment
|
||||||
* @property int $BlogID
|
* @property int $BlogID
|
||||||
*/
|
*/
|
||||||
class BlogTag extends DataObject implements CategorisationObject {
|
class BlogTag extends DataObject implements CategorisationObject
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -44,7 +45,8 @@ class BlogTag extends DataObject implements CategorisationObject {
|
|||||||
/**
|
/**
|
||||||
* @return DataList
|
* @return DataList
|
||||||
*/
|
*/
|
||||||
public function BlogPosts() {
|
public function BlogPosts()
|
||||||
|
{
|
||||||
$blogPosts = parent::BlogPosts();
|
$blogPosts = parent::BlogPosts();
|
||||||
|
|
||||||
$this->extend("updateGetBlogPosts", $blogPosts);
|
$this->extend("updateGetBlogPosts", $blogPosts);
|
||||||
@ -55,7 +57,8 @@ class BlogTag extends DataObject implements CategorisationObject {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields()
|
||||||
|
{
|
||||||
$fields = new FieldList(
|
$fields = new FieldList(
|
||||||
TextField::create('Title', _t('BlogTag.Title', 'Title'))
|
TextField::create('Title', _t('BlogTag.Title', 'Title'))
|
||||||
);
|
);
|
||||||
@ -70,7 +73,8 @@ class BlogTag extends DataObject implements CategorisationObject {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getLink() {
|
public function getLink()
|
||||||
|
{
|
||||||
return Controller::join_links($this->Blog()->Link(), 'tag', $this->URLSegment);
|
return Controller::join_links($this->Blog()->Link(), 'tag', $this->URLSegment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,10 +85,11 @@ class BlogTag extends DataObject implements CategorisationObject {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canView($member = null) {
|
public function canView($member = null)
|
||||||
|
{
|
||||||
$extended = $this->extendedCan(__FUNCTION__, $member);
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,10 +103,11 @@ class BlogTag extends DataObject implements CategorisationObject {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canCreate($member = null) {
|
public function canCreate($member = null)
|
||||||
|
{
|
||||||
$extended = $this->extendedCan(__FUNCTION__, $member);
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,10 +123,11 @@ class BlogTag extends DataObject implements CategorisationObject {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canDelete($member = null) {
|
public function canDelete($member = null)
|
||||||
|
{
|
||||||
$extended = $this->extendedCan(__FUNCTION__, $member);
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,10 +141,11 @@ class BlogTag extends DataObject implements CategorisationObject {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canEdit($member = null) {
|
public function canEdit($member = null)
|
||||||
|
{
|
||||||
$extended = $this->extendedCan(__FUNCTION__, $member);
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
||||||
|
|
||||||
if($extended !== null) {
|
if ($extended !== null) {
|
||||||
return $extended;
|
return $extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
/**
|
/**
|
||||||
* @method ManyManyList BlogPosts
|
* @method ManyManyList BlogPosts
|
||||||
*/
|
*/
|
||||||
interface CategorisationObject {
|
interface CategorisationObject
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if(!class_exists('Widget')) {
|
if (!class_exists('Widget')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10,7 +10,8 @@ if(!class_exists('Widget')) {
|
|||||||
* @property string $ArchiveType
|
* @property string $ArchiveType
|
||||||
* @property int $NumberToDisplay
|
* @property int $NumberToDisplay
|
||||||
*/
|
*/
|
||||||
class BlogArchiveWidget extends Widget {
|
class BlogArchiveWidget extends Widget
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -51,7 +52,8 @@ class BlogArchiveWidget extends Widget {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields()
|
||||||
|
{
|
||||||
$self =& $this;
|
$self =& $this;
|
||||||
|
|
||||||
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
|
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
|
||||||
@ -62,7 +64,7 @@ class BlogArchiveWidget extends Widget {
|
|||||||
|
|
||||||
$type = $archiveType->enumValues();
|
$type = $archiveType->enumValues();
|
||||||
|
|
||||||
foreach($type as $k => $v) {
|
foreach ($type as $k => $v) {
|
||||||
$type[$k] = _t('BlogArchiveWidget.' . ucfirst(strtolower($v)), $v);
|
$type[$k] = _t('BlogArchiveWidget.' . ucfirst(strtolower($v)), $v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,10 +86,11 @@ class BlogArchiveWidget extends Widget {
|
|||||||
*
|
*
|
||||||
* @return DataList
|
* @return DataList
|
||||||
*/
|
*/
|
||||||
public function getArchive() {
|
public function getArchive()
|
||||||
|
{
|
||||||
$query = $this->Blog()->getBlogPosts()->dataQuery();
|
$query = $this->Blog()->getBlogPosts()->dataQuery();
|
||||||
|
|
||||||
if($this->ArchiveType == 'Yearly') {
|
if ($this->ArchiveType == 'Yearly') {
|
||||||
$query->groupBy('DATE_FORMAT("PublishDate", \'%Y\')');
|
$query->groupBy('DATE_FORMAT("PublishDate", \'%Y\')');
|
||||||
} else {
|
} else {
|
||||||
$query->groupBy('DATE_FORMAT("PublishDate", \'%Y-%M\')');
|
$query->groupBy('DATE_FORMAT("PublishDate", \'%Y-%M\')');
|
||||||
@ -95,21 +98,21 @@ class BlogArchiveWidget extends Widget {
|
|||||||
|
|
||||||
$posts = $this->Blog()->getBlogPosts()->setDataQuery($query);
|
$posts = $this->Blog()->getBlogPosts()->setDataQuery($query);
|
||||||
|
|
||||||
if($this->NumberToDisplay > 0) {
|
if ($this->NumberToDisplay > 0) {
|
||||||
$posts = $posts->limit($this->NumberToDisplay);
|
$posts = $posts->limit($this->NumberToDisplay);
|
||||||
}
|
}
|
||||||
|
|
||||||
$archive = new ArrayList();
|
$archive = new ArrayList();
|
||||||
|
|
||||||
if($posts->count() > 0) {
|
if ($posts->count() > 0) {
|
||||||
foreach($posts as $post) {
|
foreach ($posts as $post) {
|
||||||
/**
|
/**
|
||||||
* @var BlogPost $post
|
* @var BlogPost $post
|
||||||
*/
|
*/
|
||||||
$date = Date::create();
|
$date = Date::create();
|
||||||
$date->setValue($post->PublishDate);
|
$date->setValue($post->PublishDate);
|
||||||
|
|
||||||
if($this->ArchiveType == 'Yearly') {
|
if ($this->ArchiveType == 'Yearly') {
|
||||||
$year = $date->FormatI18N("%Y");
|
$year = $date->FormatI18N("%Y");
|
||||||
$month = null;
|
$month = null;
|
||||||
$title = $year;
|
$title = $year;
|
||||||
@ -130,6 +133,6 @@ class BlogArchiveWidget extends Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BlogArchiveWidget_Controller extends Widget_Controller {
|
class BlogArchiveWidget_Controller extends Widget_Controller
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if(!class_exists("Widget")) {
|
if (!class_exists("Widget")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method Blog Blog()
|
* @method Blog Blog()
|
||||||
*/
|
*/
|
||||||
class BlogCategoriesWidget extends Widget {
|
class BlogCategoriesWidget extends Widget
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -42,7 +43,8 @@ class BlogCategoriesWidget extends Widget {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields()
|
||||||
|
{
|
||||||
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
||||||
$fields[] = DropdownField::create(
|
$fields[] = DropdownField::create(
|
||||||
'BlogID', _t('BlogCategoriesWidget.Blog', 'Blog'), Blog::get()->map()
|
'BlogID', _t('BlogCategoriesWidget.Blog', 'Blog'), Blog::get()->map()
|
||||||
@ -71,7 +73,8 @@ class BlogCategoriesWidget extends Widget {
|
|||||||
/**
|
/**
|
||||||
* @return DataList
|
* @return DataList
|
||||||
*/
|
*/
|
||||||
public function getCategories() {
|
public function getCategories()
|
||||||
|
{
|
||||||
$blog = $this->Blog();
|
$blog = $this->Blog();
|
||||||
|
|
||||||
if (!$blog) {
|
if (!$blog) {
|
||||||
@ -92,6 +95,6 @@ class BlogCategoriesWidget extends Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BlogCategoriesWidget_Controller extends Widget_Controller {
|
class BlogCategoriesWidget_Controller extends Widget_Controller
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if(!class_exists("Widget")) {
|
if (!class_exists("Widget")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9,7 +9,8 @@ if(!class_exists("Widget")) {
|
|||||||
*
|
*
|
||||||
* @property int $NumberOfPosts
|
* @property int $NumberOfPosts
|
||||||
*/
|
*/
|
||||||
class BlogRecentPostsWidget extends Widget {
|
class BlogRecentPostsWidget extends Widget
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -42,7 +43,8 @@ class BlogRecentPostsWidget extends Widget {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields()
|
||||||
|
{
|
||||||
$this->beforeUpdateCMSFields(function ($fields) {
|
$this->beforeUpdateCMSFields(function ($fields) {
|
||||||
/**
|
/**
|
||||||
* @var FieldList $fields
|
* @var FieldList $fields
|
||||||
@ -59,10 +61,11 @@ class BlogRecentPostsWidget extends Widget {
|
|||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getPosts() {
|
public function getPosts()
|
||||||
|
{
|
||||||
$blog = $this->Blog();
|
$blog = $this->Blog();
|
||||||
|
|
||||||
if($blog) {
|
if ($blog) {
|
||||||
return $blog->getBlogPosts()
|
return $blog->getBlogPosts()
|
||||||
->sort('"PublishDate" DESC')
|
->sort('"PublishDate" DESC')
|
||||||
->limit($this->NumberOfPosts);
|
->limit($this->NumberOfPosts);
|
||||||
@ -72,6 +75,6 @@ class BlogRecentPostsWidget extends Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BlogRecentPostsWidget_Controller extends Widget_Controller {
|
class BlogRecentPostsWidget_Controller extends Widget_Controller
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if(!class_exists("Widget")) {
|
if (!class_exists("Widget")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method Blog Blog()
|
* @method Blog Blog()
|
||||||
*/
|
*/
|
||||||
class BlogTagsWidget extends Widget {
|
class BlogTagsWidget extends Widget
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -42,7 +43,8 @@ class BlogTagsWidget extends Widget {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields()
|
||||||
|
{
|
||||||
$this->beforeUpdateCMSFields(function (Fieldlist $fields) {
|
$this->beforeUpdateCMSFields(function (Fieldlist $fields) {
|
||||||
$fields[] = DropdownField::create(
|
$fields[] = DropdownField::create(
|
||||||
'BlogID', _t('BlogTagsWidget.Blog', 'Blog'), Blog::get()->map()
|
'BlogID', _t('BlogTagsWidget.Blog', 'Blog'), Blog::get()->map()
|
||||||
@ -71,7 +73,8 @@ class BlogTagsWidget extends Widget {
|
|||||||
/**
|
/**
|
||||||
* @return DataList
|
* @return DataList
|
||||||
*/
|
*/
|
||||||
public function getTags() {
|
public function getTags()
|
||||||
|
{
|
||||||
$blog = $this->Blog();
|
$blog = $this->Blog();
|
||||||
|
|
||||||
if (!$blog) {
|
if (!$blog) {
|
||||||
@ -92,6 +95,6 @@ class BlogTagsWidget extends Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BlogTagsWidget_Controller extends Widget_Controller {
|
class BlogTagsWidget_Controller extends Widget_Controller
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,18 @@
|
|||||||
/**
|
/**
|
||||||
* @mixin PHPUnit_Framework_TestCase
|
* @mixin PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
class BlogCategoryTest extends FunctionalTest {
|
class BlogCategoryTest extends FunctionalTest
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
static $fixture_file = 'blog.yml';
|
public static $fixture_file = 'blog.yml';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function setUp() {
|
public function setUp()
|
||||||
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
SS_Datetime::set_mock_now('2013-10-10 20:00:00');
|
SS_Datetime::set_mock_now('2013-10-10 20:00:00');
|
||||||
@ -21,7 +23,8 @@ class BlogCategoryTest extends FunctionalTest {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function tearDown() {
|
public function tearDown()
|
||||||
|
{
|
||||||
SS_Datetime::clear_mock_now();
|
SS_Datetime::clear_mock_now();
|
||||||
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
@ -31,10 +34,11 @@ class BlogCategoryTest extends FunctionalTest {
|
|||||||
* Tests that any blog posts returned from $category->BlogPosts() many_many are published,
|
* Tests that any blog posts returned from $category->BlogPosts() many_many are published,
|
||||||
* both by normal 'save & publish' functionality and by publish date.
|
* both by normal 'save & publish' functionality and by publish date.
|
||||||
*/
|
*/
|
||||||
public function testBlogPosts() {
|
public function testBlogPosts()
|
||||||
|
{
|
||||||
$member = Member::currentUser();
|
$member = Member::currentUser();
|
||||||
|
|
||||||
if($member) {
|
if ($member) {
|
||||||
$member->logout();
|
$member->logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +52,8 @@ class BlogCategoryTest extends FunctionalTest {
|
|||||||
$this->assertEquals(1, $category->BlogPosts()->count(), 'Category blog post count');
|
$this->assertEquals(1, $category->BlogPosts()->count(), 'Category blog post count');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanView() {
|
public function testCanView()
|
||||||
|
{
|
||||||
$this->useDraftSite();
|
$this->useDraftSite();
|
||||||
|
|
||||||
$this->objFromFixture('Member', 'Admin');
|
$this->objFromFixture('Member', 'Admin');
|
||||||
@ -62,7 +67,8 @@ class BlogCategoryTest extends FunctionalTest {
|
|||||||
/**
|
/**
|
||||||
* The first blog can be viewed by anybody.
|
* The first blog can be viewed by anybody.
|
||||||
*/
|
*/
|
||||||
public function testCanEdit() {
|
public function testCanEdit()
|
||||||
|
{
|
||||||
$this->useDraftSite();
|
$this->useDraftSite();
|
||||||
|
|
||||||
$admin = $this->objFromFixture('Member', 'Admin');
|
$admin = $this->objFromFixture('Member', 'Admin');
|
||||||
@ -84,7 +90,8 @@ class BlogCategoryTest extends FunctionalTest {
|
|||||||
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
|
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanCreate() {
|
public function testCanCreate()
|
||||||
|
{
|
||||||
$this->useDraftSite();
|
$this->useDraftSite();
|
||||||
|
|
||||||
$admin = $this->objFromFixture('Member', 'Admin');
|
$admin = $this->objFromFixture('Member', 'Admin');
|
||||||
@ -96,7 +103,8 @@ class BlogCategoryTest extends FunctionalTest {
|
|||||||
$this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.');
|
$this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanDelete() {
|
public function testCanDelete()
|
||||||
|
{
|
||||||
$this->useDraftSite();
|
$this->useDraftSite();
|
||||||
|
|
||||||
$admin = $this->objFromFixture('Member', 'Admin');
|
$admin = $this->objFromFixture('Member', 'Admin');
|
||||||
|
@ -3,28 +3,32 @@
|
|||||||
/**
|
/**
|
||||||
* @mixin PHPUnit_Framework_TestCase
|
* @mixin PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
class BlogPostFilterTest extends SapphireTest {
|
class BlogPostFilterTest extends SapphireTest
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
static $fixture_file = 'blog.yml';
|
public static $fixture_file = 'blog.yml';
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp()
|
||||||
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
SS_Datetime::set_mock_now('2013-10-10 20:00:00');
|
SS_Datetime::set_mock_now('2013-10-10 20:00:00');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown() {
|
public function tearDown()
|
||||||
|
{
|
||||||
SS_Datetime::clear_mock_now();
|
SS_Datetime::clear_mock_now();
|
||||||
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFilter() {
|
public function testFilter()
|
||||||
|
{
|
||||||
$member = Member::currentUser();
|
$member = Member::currentUser();
|
||||||
|
|
||||||
if($member) {
|
if ($member) {
|
||||||
$member->logout();
|
$member->logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,23 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class BlogPostTest extends SapphireTest {
|
class BlogPostTest extends SapphireTest
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
static $fixture_file = 'blog.yml';
|
public static $fixture_file = 'blog.yml';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function setUp() {
|
public function setUp()
|
||||||
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function tearDown() {
|
public function tearDown()
|
||||||
|
{
|
||||||
SS_Datetime::clear_mock_now();
|
SS_Datetime::clear_mock_now();
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
@ -25,14 +27,16 @@ class BlogPostTest extends SapphireTest {
|
|||||||
/**
|
/**
|
||||||
* @dataProvider canViewProvider
|
* @dataProvider canViewProvider
|
||||||
*/
|
*/
|
||||||
public function testCanView($date, $user, $page, $canView) {
|
public function testCanView($date, $user, $page, $canView)
|
||||||
|
{
|
||||||
$userRecord = $this->objFromFixture('Member', $user);
|
$userRecord = $this->objFromFixture('Member', $user);
|
||||||
$pageRecord = $this->objFromFixture('BlogPost', $page);
|
$pageRecord = $this->objFromFixture('BlogPost', $page);
|
||||||
SS_Datetime::set_mock_now($date);
|
SS_Datetime::set_mock_now($date);
|
||||||
$this->assertEquals($canView, $pageRecord->canView($userRecord));
|
$this->assertEquals($canView, $pageRecord->canView($userRecord));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canViewProvider() {
|
public function canViewProvider()
|
||||||
|
{
|
||||||
$someFutureDate = '2013-10-10 20:00:00';
|
$someFutureDate = '2013-10-10 20:00:00';
|
||||||
$somePastDate = '2009-10-10 20:00:00';
|
$somePastDate = '2009-10-10 20:00:00';
|
||||||
return array(
|
return array(
|
||||||
@ -64,16 +68,15 @@ class BlogPostTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCandidateAuthors() {
|
public function testCandidateAuthors()
|
||||||
|
{
|
||||||
$blogpost = $this->objFromFixture('BlogPost', 'PostC');
|
$blogpost = $this->objFromFixture('BlogPost', 'PostC');
|
||||||
|
|
||||||
$this->assertEquals(7, $blogpost->getCandidateAuthors()->count());
|
$this->assertEquals(7, $blogpost->getCandidateAuthors()->count());
|
||||||
|
|
||||||
//Set the group to draw Members from
|
//Set the group to draw Members from
|
||||||
Config::inst()->update('BlogPost', 'restrict_authors_to_group','BlogUsers');
|
Config::inst()->update('BlogPost', 'restrict_authors_to_group', 'BlogUsers');
|
||||||
|
|
||||||
$this->assertEquals(3, $blogpost->getCandidateAuthors()->count());
|
$this->assertEquals(3, $blogpost->getCandidateAuthors()->count());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,18 @@
|
|||||||
/**
|
/**
|
||||||
* @mixin PHPUnit_Framework_TestCase
|
* @mixin PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
class BlogTagTest extends FunctionalTest {
|
class BlogTagTest extends FunctionalTest
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
static $fixture_file = 'blog.yml';
|
public static $fixture_file = 'blog.yml';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function setUp() {
|
public function setUp()
|
||||||
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
SS_Datetime::set_mock_now('2013-10-10 20:00:00');
|
SS_Datetime::set_mock_now('2013-10-10 20:00:00');
|
||||||
@ -21,7 +23,8 @@ class BlogTagTest extends FunctionalTest {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function tearDown() {
|
public function tearDown()
|
||||||
|
{
|
||||||
SS_Datetime::clear_mock_now();
|
SS_Datetime::clear_mock_now();
|
||||||
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
@ -31,10 +34,11 @@ class BlogTagTest extends FunctionalTest {
|
|||||||
* Tests that any blog posts returned from $tag->BlogPosts() many_many are published, both by
|
* Tests that any blog posts returned from $tag->BlogPosts() many_many are published, both by
|
||||||
* normal 'save & publish' functionality and by publish date.
|
* normal 'save & publish' functionality and by publish date.
|
||||||
*/
|
*/
|
||||||
public function testBlogPosts() {
|
public function testBlogPosts()
|
||||||
|
{
|
||||||
$member = Member::currentUser();
|
$member = Member::currentUser();
|
||||||
|
|
||||||
if($member) {
|
if ($member) {
|
||||||
$member->logout();
|
$member->logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +55,8 @@ class BlogTagTest extends FunctionalTest {
|
|||||||
/**
|
/**
|
||||||
* The first blog can be viewed by anybody.
|
* The first blog can be viewed by anybody.
|
||||||
*/
|
*/
|
||||||
public function testCanView() {
|
public function testCanView()
|
||||||
|
{
|
||||||
$this->useDraftSite();
|
$this->useDraftSite();
|
||||||
|
|
||||||
$admin = $this->objFromFixture('Member', 'Admin');
|
$admin = $this->objFromFixture('Member', 'Admin');
|
||||||
@ -68,7 +73,8 @@ class BlogTagTest extends FunctionalTest {
|
|||||||
$this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.');
|
$this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanEdit() {
|
public function testCanEdit()
|
||||||
|
{
|
||||||
$this->useDraftSite();
|
$this->useDraftSite();
|
||||||
|
|
||||||
$admin = $this->objFromFixture('Member', 'Admin');
|
$admin = $this->objFromFixture('Member', 'Admin');
|
||||||
@ -90,7 +96,8 @@ class BlogTagTest extends FunctionalTest {
|
|||||||
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
|
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanCreate() {
|
public function testCanCreate()
|
||||||
|
{
|
||||||
$this->useDraftSite();
|
$this->useDraftSite();
|
||||||
|
|
||||||
$admin = $this->objFromFixture('Member', 'Admin');
|
$admin = $this->objFromFixture('Member', 'Admin');
|
||||||
@ -102,7 +109,8 @@ class BlogTagTest extends FunctionalTest {
|
|||||||
$this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.');
|
$this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanDelete() {
|
public function testCanDelete()
|
||||||
|
{
|
||||||
$this->useDraftSite();
|
$this->useDraftSite();
|
||||||
|
|
||||||
$admin = $this->objFromFixture('Member', 'Admin');
|
$admin = $this->objFromFixture('Member', 'Admin');
|
||||||
|
@ -3,16 +3,18 @@
|
|||||||
/**
|
/**
|
||||||
* @mixin PHPUnit_Framework_TestCase
|
* @mixin PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
class BlogTest extends SapphireTest {
|
class BlogTest extends SapphireTest
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
static $fixture_file = 'blog.yml';
|
public static $fixture_file = 'blog.yml';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function setUp() {
|
public function setUp()
|
||||||
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
Config::nest();
|
Config::nest();
|
||||||
@ -29,17 +31,19 @@ class BlogTest extends SapphireTest {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function tearDown() {
|
public function tearDown()
|
||||||
|
{
|
||||||
SS_Datetime::clear_mock_now();
|
SS_Datetime::clear_mock_now();
|
||||||
Config::unnest();
|
Config::unnest();
|
||||||
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetExcludedSiteTreeClassNames() {
|
public function testGetExcludedSiteTreeClassNames()
|
||||||
|
{
|
||||||
$member = Member::currentUser();
|
$member = Member::currentUser();
|
||||||
|
|
||||||
if($member) {
|
if ($member) {
|
||||||
$member->logout();
|
$member->logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,10 +63,11 @@ class BlogTest extends SapphireTest {
|
|||||||
$this->assertContains('BlogPost', $classes, 'BlogPost class should be hidden.');
|
$this->assertContains('BlogPost', $classes, 'BlogPost class should be hidden.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetArchivedBlogPosts() {
|
public function testGetArchivedBlogPosts()
|
||||||
|
{
|
||||||
$member = Member::currentUser();
|
$member = Member::currentUser();
|
||||||
|
|
||||||
if($member) {
|
if ($member) {
|
||||||
$member->logout();
|
$member->logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +91,8 @@ class BlogTest extends SapphireTest {
|
|||||||
$this->assertEquals(1, $archive->count(), 'Incorrect daily archive count.');
|
$this->assertEquals(1, $archive->count(), 'Incorrect daily archive count.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testArchiveLinks() {
|
public function testArchiveLinks()
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var Blog $blog
|
* @var Blog $blog
|
||||||
*/
|
*/
|
||||||
@ -122,13 +128,13 @@ class BlogTest extends SapphireTest {
|
|||||||
$link = Controller::join_links($blog->Link('archive'), '2013', '10', '99');
|
$link = Controller::join_links($blog->Link('archive'), '2013', '10', '99');
|
||||||
|
|
||||||
$this->assertEquals(404, $this->getStatusOf($link), 'HTTP Status should be 404');
|
$this->assertEquals(404, $this->getStatusOf($link), 'HTTP Status should be 404');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test archive year
|
* Test archive year
|
||||||
*/
|
*/
|
||||||
public function testArchiveYear(){
|
public function testArchiveYear()
|
||||||
|
{
|
||||||
$blog = $this->objFromFixture('Blog', 'FirstBlog');
|
$blog = $this->objFromFixture('Blog', 'FirstBlog');
|
||||||
$controller = new Blog_Controller($blog);
|
$controller = new Blog_Controller($blog);
|
||||||
$this->requestURL($controller, 'first-post/archive/');
|
$this->requestURL($controller, 'first-post/archive/');
|
||||||
@ -140,11 +146,13 @@ class BlogTest extends SapphireTest {
|
|||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function getStatusOf($link) {
|
protected function getStatusOf($link)
|
||||||
|
{
|
||||||
return Director::test($link)->getStatusCode();
|
return Director::test($link)->getStatusCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRoles() {
|
public function testRoles()
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var Blog $firstBlog
|
* @var Blog $firstBlog
|
||||||
*/
|
*/
|
||||||
@ -264,7 +272,8 @@ class BlogTest extends SapphireTest {
|
|||||||
$this->assertFalse($postC->canPublish($visitor));
|
$this->assertFalse($postC->canPublish($visitor));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFilteredCategories() {
|
public function testFilteredCategories()
|
||||||
|
{
|
||||||
$blog = $this->objFromFixture('Blog', 'FirstBlog');
|
$blog = $this->objFromFixture('Blog', 'FirstBlog');
|
||||||
$controller = new Blog_Controller($blog);
|
$controller = new Blog_Controller($blog);
|
||||||
|
|
||||||
@ -310,7 +319,8 @@ class BlogTest extends SapphireTest {
|
|||||||
* @param ContentController $controller
|
* @param ContentController $controller
|
||||||
* @param string $url
|
* @param string $url
|
||||||
*/
|
*/
|
||||||
protected function requestURL(ContentController $controller, $url) {
|
protected function requestURL(ContentController $controller, $url)
|
||||||
|
{
|
||||||
$request = new SS_HTTPRequest('get', $url);
|
$request = new SS_HTTPRequest('get', $url);
|
||||||
$request->match('$URLSegment//$Action/$ID/$OtherID');
|
$request->match('$URLSegment//$Action/$ID/$OtherID');
|
||||||
$request->shift();
|
$request->shift();
|
||||||
@ -324,9 +334,14 @@ class BlogTest extends SapphireTest {
|
|||||||
* @param array|SS_List $left
|
* @param array|SS_List $left
|
||||||
* @param array|SS_List $right
|
* @param array|SS_List $right
|
||||||
*/
|
*/
|
||||||
protected function assertIDsEquals($left, $right) {
|
protected function assertIDsEquals($left, $right)
|
||||||
if($left instanceof SS_List) $left = $left->column('ID');
|
{
|
||||||
if($right instanceof SS_List) $right = $right->column('ID');
|
if ($left instanceof SS_List) {
|
||||||
|
$left = $left->column('ID');
|
||||||
|
}
|
||||||
|
if ($right instanceof SS_List) {
|
||||||
|
$right = $right->column('ID');
|
||||||
|
}
|
||||||
asort($left);
|
asort($left);
|
||||||
asort($right);
|
asort($right);
|
||||||
$this->assertEquals(array_values($left), array_values($right));
|
$this->assertEquals(array_values($left), array_values($right));
|
||||||
|
Loading…
Reference in New Issue
Block a user