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