mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Move "code" to PSR-4 friendly "src" folders. Add namespacing.
This commit is contained in:
parent
4313643a0b
commit
13a5badff5
@ -5,4 +5,4 @@
|
||||
*
|
||||
* @return string
|
||||
**/
|
||||
define('BLOGGER_DIR', ltrim(Director::makeRelative(realpath(__DIR__)), DIRECTORY_SEPARATOR));
|
||||
define('BLOGGER_DIR', dirname(__FILE__));
|
||||
|
@ -5,13 +5,13 @@ Only:
|
||||
---
|
||||
Comment:
|
||||
extensions:
|
||||
- BlogCommentExtension
|
||||
- SilverStripe\Blog\Model\BlogCommentExtension
|
||||
|
||||
---
|
||||
Name: blogcommentnotifications
|
||||
Only:
|
||||
moduleexists: 'comment-notifications'
|
||||
---
|
||||
BlogPost:
|
||||
SilverStripe\Blog\Model\BlogPost:
|
||||
extensions:
|
||||
- BlogPostNotifications
|
||||
- SilverStripe\Blog\Model\BlogPostNotifications
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
Name: blogconfig
|
||||
---
|
||||
Member:
|
||||
SilverStripe\Security\Member:
|
||||
extensions:
|
||||
- BlogMemberExtension
|
||||
- SilverStripe\Blog\Model\BlogMemberExtension
|
||||
|
@ -1,112 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @deprecated since version 2.0
|
||||
*
|
||||
* @property int $ParentID
|
||||
* @property string $Date
|
||||
* @property string $PublishDate
|
||||
* @property string $Tags
|
||||
*/
|
||||
class BlogEntry extends BlogPost implements MigratableObject
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $hide_ancestor = 'BlogEntry';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
'Date' => 'SS_Datetime',
|
||||
'Author' => 'Text',
|
||||
'Tags' => 'Text',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function canCreate($member = null, $context = array())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
|
||||
//Migrate comma separated tags into BlogTag objects.
|
||||
foreach ($this->TagNames() as $tag) {
|
||||
$existingTag = BlogTag::get()->filter(array('Title' => $tag, 'BlogID' => $this->ParentID));
|
||||
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.
|
||||
$tagObject = new BlogTag();
|
||||
$tagObject->Title = $tag;
|
||||
$tagObject->BlogID = $this->ParentID;
|
||||
$tagObject->write();
|
||||
}
|
||||
|
||||
if ($tagObject) {
|
||||
$this->Tags()->add($tagObject);
|
||||
}
|
||||
}
|
||||
|
||||
//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') {
|
||||
$this->ClassName = 'BlogPost';
|
||||
$this->RecordClassName = 'BlogPost';
|
||||
}
|
||||
//Migrate these key data attributes
|
||||
$this->PublishDate = $this->Date;
|
||||
$this->AuthorNames = $this->Author;
|
||||
$this->InheritSideBar = true;
|
||||
|
||||
//Write and additionally publish the item if it was published before.
|
||||
$this->write();
|
||||
if ($published) {
|
||||
$this->publish('Stage', 'Live');
|
||||
$message = "PUBLISHED: ";
|
||||
} else {
|
||||
$message = "DRAFT: ";
|
||||
}
|
||||
|
||||
return $message . $this->Title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely split and parse all distinct tags assigned to this BlogEntry.
|
||||
*
|
||||
* @deprecated since version 2.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function TagNames()
|
||||
{
|
||||
$tags = preg_split('/\s*,\s*/', trim($this->Tags));
|
||||
|
||||
$results = array();
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
if ($tag) {
|
||||
$results[mb_strtolower($tag)] = $tag;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 2.0
|
||||
*/
|
||||
class BlogEntry_Controller extends BlogPost_Controller
|
||||
{
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @deprecated since version 2.0
|
||||
*/
|
||||
class BlogHolder extends BlogTree implements MigratableObject
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $hide_ancestor = 'BlogHolder';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
'AllowCustomAuthors' => 'Boolean',
|
||||
'ShowFullEntry' => 'Boolean',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $has_one = array(
|
||||
'Owner' => 'Member',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function canCreate($member = null, $context = array())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Overload these to stop the Uncaught Exception: Object->__call(): the method 'parent' does not exist on 'BlogHolder' error.
|
||||
public function validURLSegment()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function syncLinkTracking()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$published = $this->IsPublished();
|
||||
|
||||
if ($this->ClassName === 'BlogHolder') {
|
||||
$this->ClassName = 'Blog';
|
||||
$this->RecordClassName = 'Blog';
|
||||
$this->PostsPerPage = 10;
|
||||
$this->write();
|
||||
}
|
||||
|
||||
if ($published) {
|
||||
$this->publish('Stage', 'Live');
|
||||
$message = "PUBLISHED: ";
|
||||
} else {
|
||||
$message = "DRAFT: ";
|
||||
}
|
||||
|
||||
return $message . $this->Title;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 2.0
|
||||
*/
|
||||
class BlogHolder_Controller extends BlogTree_Controller
|
||||
{
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @deprecated since version 2.0
|
||||
*/
|
||||
class BlogTree extends Page implements MigratableObject
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $hide_ancestor = 'BlogTree';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
'Name' => 'Varchar(255)',
|
||||
'LandingPageFreshness' => 'Varchar',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function canCreate($member = null, $context = array())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$published = $this->IsPublished();
|
||||
if ($this->ClassName === 'BlogTree') {
|
||||
$this->ClassName = 'Page';
|
||||
$this->RecordClassName = 'Page';
|
||||
$this->write();
|
||||
}
|
||||
if ($published) {
|
||||
$this->publish('Stage', 'Live');
|
||||
$message = "PUBLISHED: ";
|
||||
} else {
|
||||
$message = "DRAFT: ";
|
||||
}
|
||||
|
||||
return $message . $this->Title;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 2.0
|
||||
*/
|
||||
class BlogTree_Controller extends Page_Controller
|
||||
{
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
<?php
|
||||
|
||||
class BlogMigrationTask extends MigrationTask
|
||||
{
|
||||
/**
|
||||
* Should this task be invoked automatically via dev/build?
|
||||
*
|
||||
* @config
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private static $run_during_dev_build = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$classes = ClassInfo::implementorsOf('MigratableObject');
|
||||
|
||||
$this->message('Migrating legacy blog records');
|
||||
|
||||
foreach ($classes as $class) {
|
||||
$this->upClass($class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
*/
|
||||
protected function message($text)
|
||||
{
|
||||
if (Controller::curr() instanceof DatabaseAdmin) {
|
||||
DB::alteration_message($text, 'obsolete');
|
||||
} else {
|
||||
echo $text . "<br/>";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate records of a single class
|
||||
*
|
||||
* @param string $class
|
||||
* @param null|string $stage
|
||||
*/
|
||||
protected function upClass($class)
|
||||
{
|
||||
if (!class_exists($class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_subclass_of($class, 'SiteTree')) {
|
||||
$items = SiteTree::get()->filter('ClassName', $class);
|
||||
} else {
|
||||
$items = $class::get();
|
||||
}
|
||||
|
||||
if ($count = $items->count()) {
|
||||
$this->message(
|
||||
sprintf(
|
||||
'Migrating %s legacy %s records.',
|
||||
$count,
|
||||
$class
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$cancel = $item->extend('onBeforeUp');
|
||||
|
||||
if ($cancel && min($cancel) === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var MigratableObject $item
|
||||
*/
|
||||
$result = $item->up();
|
||||
$this->message($result);
|
||||
|
||||
$item->extend('onAfterUp');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$this->message('BlogMigrationTask::down() not implemented');
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
interface MigratableObject
|
||||
{
|
||||
/**
|
||||
* Migrate the object up to the current version.
|
||||
*/
|
||||
public function up();
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (!class_exists('Widget')) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 2.0
|
||||
*
|
||||
* @property string $DisplayMode
|
||||
* @property string $ArchiveType
|
||||
*/
|
||||
class ArchiveWidget extends BlogArchiveWidget implements MigratableObject
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
'DisplayMode' => 'Varchar',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $only_available_in = array(
|
||||
'none',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function canCreate($member = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if ($this->DisplayMode) {
|
||||
$this->ArchiveType = 'Monthly';
|
||||
|
||||
if ($this->DisplayMode === 'year') {
|
||||
$this->ArchiveType = 'Yearly';
|
||||
}
|
||||
}
|
||||
|
||||
$this->ClassName = 'BlogArchiveWidget';
|
||||
$this->write();
|
||||
return "Migrated " . $this->ArchiveType . " archive widget";
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (!class_exists('Widget')) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of tags associated with blog posts.
|
||||
*
|
||||
* @package blog
|
||||
*/
|
||||
class TagCloudWidget extends BlogTagsWidget implements MigratableObject
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
'Title' => 'Varchar',
|
||||
'Limit' => 'Int',
|
||||
'Sortby' => 'Varchar',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $only_available_in = array(
|
||||
'none',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function canCreate($member = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$this->ClassName = 'BlogTagsWidget';
|
||||
$this->write();
|
||||
return "Migrated " . $this->Title . " widget";
|
||||
}
|
||||
}
|
@ -17,7 +17,12 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.x-dev"
|
||||
"dev-master": "3.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"SilverStripe\\Blog\\": "src/"
|
||||
}
|
||||
},
|
||||
"license": "BSD-2-Clause",
|
||||
|
28
src/.upgrade.yml
Normal file
28
src/.upgrade.yml
Normal file
@ -0,0 +1,28 @@
|
||||
mappings:
|
||||
GridFieldCategorisationConfig: SilverStripe\Blog\Admin\GridFieldCategorisationConfig
|
||||
GridFieldFormAction: SilverStripe\Blog\Admin\GridFieldFormAction
|
||||
GridFieldMergeAction: SilverStripe\Blog\Admin\GridFieldMergeAction
|
||||
BlogCommentExtension: SilverStripe\Blog\Model\BlogCommentExtension
|
||||
BlogFilter: SilverStripe\Blog\Model\BlogFilter
|
||||
BlogFilter_GridField: SilverStripe\Blog\Model\BlogFilter_GridField
|
||||
BlogMemberExtension: SilverStripe\Blog\Model\BlogMemberExtension
|
||||
BlogPostFilter: SilverStripe\Blog\Model\BlogPostFilter
|
||||
BlogPostNotifications: SilverStripe\Blog\Model\BlogPostNotifications
|
||||
Blog: SilverStripe\Blog\Model\Blog
|
||||
Blog_Controller: SilverStripe\Blog\Controllers\BlogController
|
||||
BlogController: SilverStripe\Blog\Controllers\BlogController
|
||||
BlogCategory: SilverStripe\Blog\Model\BlogCategory
|
||||
BlogPost: SilverStripe\Blog\Model\BlogPost
|
||||
BlogPost_Controller: SilverStripe\Blog\Controllers\BlogPostController
|
||||
BlogPostController: SilverStripe\Blog\Controllers\BlogPostController
|
||||
BlogTag: SilverStripe\Blog\Model\BlogTag
|
||||
CategorisationObject: SilverStripe\Blog\Model\CategorisationObject
|
||||
BlogAdminSidebar: SilverStripe\Blog\Forms\BlogAdminSidebar
|
||||
GridFieldAddByDBField: SilverStripe\Blog\Forms\GridField\GridFieldAddByDBField
|
||||
GridFieldBlogPostState: SilverStripe\Blog\Forms\GridField\GridFieldBlogPostState
|
||||
GridFieldConfig_BlogPost: SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost
|
||||
BlogArchiveWidget: SilverStripe\Blog\Widgets\BlogArchiveWidget
|
||||
BlogCategoriesWidget: SilverStripe\Blog\Widgets\BlogCategoriesWidget
|
||||
BlogRecentPostsWidget: SilverStripe\Blog\Widgets\BlogRecentPostsWidget
|
||||
BlogTagsCloudWidget: SilverStripe\Blog\Widgets\BlogTagsCloudWidget
|
||||
BlogTagsWidget: SilverStripe\Blog\Widgets\BlogTagsWidget
|
@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Admin;
|
||||
|
||||
use SilverStripe\Blog\Form\GridField\GridFieldAddByDBField;
|
||||
use SilverStripe\Blog\Admin\GridFieldMergeAction;
|
||||
use SilverStripe\Blog\Model\CategorisationObject;
|
||||
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
||||
|
||||
class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
|
||||
{
|
||||
/**
|
||||
@ -47,11 +54,13 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
|
||||
*/
|
||||
$columns = $this->getComponentByType('GridFieldDataColumns');
|
||||
|
||||
$columns->setDisplayFields(array(
|
||||
$columns->setDisplayFields(
|
||||
array(
|
||||
'Title' => 'Title',
|
||||
'BlogPostsCount' => 'Posts',
|
||||
'MergeAction' => 'MergeAction',
|
||||
'Actions' => 'Actions',
|
||||
));
|
||||
'Actions' => 'Actions'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Admin;
|
||||
|
||||
use GridField_FormAction;
|
||||
|
||||
class GridFieldFormAction extends GridField_FormAction
|
||||
{
|
||||
/**
|
@ -1,5 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Admin;
|
||||
|
||||
use GridField_ColumnProvider;
|
||||
use GridField_ActionProvider;
|
||||
use DropdownField;
|
||||
|
||||
use GridField;
|
||||
use Controller;
|
||||
use SilverStripe\Blog\Admin\GridFieldFormAction;
|
||||
|
||||
|
||||
class GridFieldMergeAction implements GridField_ColumnProvider, GridField_ActionProvider
|
||||
{
|
||||
/**
|
517
src/Controllers/BlogController.php
Normal file
517
src/Controllers/BlogController.php
Normal file
@ -0,0 +1,517 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Controllers;
|
||||
|
||||
use Page_Controller;
|
||||
use SilverStripe\Control\RSS\RSSFeed;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\ORM\PaginatedList;
|
||||
use SilverStripe\Security\Member;
|
||||
|
||||
/**
|
||||
* @package silverstripe
|
||||
* @subpackage blog
|
||||
*/
|
||||
class BlogController extends Page_Controller
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $allowed_actions = array(
|
||||
'archive',
|
||||
'tag',
|
||||
'category',
|
||||
'rss',
|
||||
'profile'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $url_handlers = array(
|
||||
'tag/$Tag!/$Rss' => 'tag',
|
||||
'category/$Category!/$Rss' => 'category',
|
||||
'archive/$Year!/$Month/$Day' => 'archive',
|
||||
'profile/$URLSegment!' => 'profile'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $casting = array(
|
||||
'MetaTitle' => 'Text',
|
||||
'FilterDescription' => 'Text'
|
||||
);
|
||||
|
||||
/**
|
||||
* The current Blog Post DataList query.
|
||||
*
|
||||
* @var DataList
|
||||
*/
|
||||
protected $blogPosts;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$this->blogPosts = $dataRecord->getBlogPosts();
|
||||
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a Blog Member's profile.
|
||||
*
|
||||
* @return SS_HTTPResponse
|
||||
*/
|
||||
public function profile()
|
||||
{
|
||||
$profile = $this->getCurrentProfile();
|
||||
|
||||
if (!$profile) {
|
||||
return $this->httpError(404, 'Not Found');
|
||||
}
|
||||
|
||||
$this->blogPosts = $this->getCurrentProfilePosts();
|
||||
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Member associated with the current URL segment.
|
||||
*
|
||||
* @return null|Member
|
||||
*/
|
||||
public function getCurrentProfile()
|
||||
{
|
||||
$urlSegment = $this->request->param('URLSegment');
|
||||
|
||||
if ($urlSegment) {
|
||||
return Member::get()
|
||||
->filter('URLSegment', $urlSegment)
|
||||
->first();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts related to the current Member profile.
|
||||
*
|
||||
* @return null|DataList
|
||||
*/
|
||||
public function getCurrentProfilePosts()
|
||||
{
|
||||
$profile = $this->getCurrentProfile();
|
||||
|
||||
if ($profile) {
|
||||
return $profile->BlogPosts()->filter('ParentID', $this->ID);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an archive for a specified date. This can be by year or year/month.
|
||||
*
|
||||
* @return null|SS_HTTPResponse
|
||||
*/
|
||||
public function archive()
|
||||
{
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$year = $this->getArchiveYear();
|
||||
$month = $this->getArchiveMonth();
|
||||
$day = $this->getArchiveDay();
|
||||
|
||||
if ($this->request->param('Month') && !$month) {
|
||||
$this->httpError(404, 'Not Found');
|
||||
}
|
||||
|
||||
if ($month && $this->request->param('Day') && !$day) {
|
||||
$this->httpError(404, 'Not Found');
|
||||
}
|
||||
|
||||
if ($year) {
|
||||
$this->blogPosts = $dataRecord->getArchivedBlogPosts($year, $month, $day);
|
||||
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
$this->httpError(404, 'Not Found');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the archive year from the url.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
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') {
|
||||
return DBDatetime::now()->Year();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the archive money from the url.
|
||||
*
|
||||
* @return null|int
|
||||
*/
|
||||
public function getArchiveMonth()
|
||||
{
|
||||
$month = $this->request->param('Month');
|
||||
|
||||
if (preg_match('/^[0-9]{1,2}$/', $month)) {
|
||||
if ($month > 0 && $month < 13) {
|
||||
if (checkdate($month, 01, $this->getArchiveYear())) {
|
||||
return (int) $month;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the archive day from the url.
|
||||
*
|
||||
* @return null|int
|
||||
*/
|
||||
public function getArchiveDay()
|
||||
{
|
||||
$day = $this->request->param('Day');
|
||||
|
||||
if (preg_match('/^[0-9]{1,2}$/', $day)) {
|
||||
if (checkdate($this->getArchiveMonth(), $day, $this->getArchiveYear())) {
|
||||
return (int) $day;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the blog posts for a given tag.
|
||||
*
|
||||
* @return null|HTTPResponse
|
||||
*/
|
||||
public function tag()
|
||||
{
|
||||
$tag = $this->getCurrentTag();
|
||||
|
||||
if ($tag) {
|
||||
$this->blogPosts = $tag->BlogPosts();
|
||||
|
||||
if($this->isRSS()) {
|
||||
return $this->rssFeed($this->blogPosts, $tag->getLink());
|
||||
} else {
|
||||
return $this->render();
|
||||
}
|
||||
}
|
||||
|
||||
$this->httpError(404, 'Not Found');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag Getter for use in templates.
|
||||
*
|
||||
* @return null|BlogTag
|
||||
*/
|
||||
public function getCurrentTag()
|
||||
{
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
$tag = $this->request->param('Tag');
|
||||
if ($tag) {
|
||||
return $dataRecord->Tags()
|
||||
->filter('URLSegment', array($tag, rawurlencode($tag)))
|
||||
->first();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the blog posts for a given category.
|
||||
*
|
||||
* @return null|SS_HTTPResponse
|
||||
*/
|
||||
public function category()
|
||||
{
|
||||
$category = $this->getCurrentCategory();
|
||||
|
||||
if ($category) {
|
||||
$this->blogPosts = $category->BlogPosts();
|
||||
|
||||
if($this->isRSS()) {
|
||||
return $this->rssFeed($this->blogPosts, $category->getLink());
|
||||
} else {
|
||||
return $this->render();
|
||||
}
|
||||
}
|
||||
|
||||
$this->httpError(404, 'Not Found');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Category Getter for use in templates.
|
||||
*
|
||||
* @return null|BlogCategory
|
||||
*/
|
||||
public function getCurrentCategory()
|
||||
{
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
$category = $this->request->param('Category');
|
||||
if ($category) {
|
||||
return $dataRecord->Categories()
|
||||
->filter('URLSegment', array($category, rawurlencode($category)))
|
||||
->first();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta title for the current action.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMetaTitle()
|
||||
{
|
||||
$title = $this->data()->getTitle();
|
||||
$filter = $this->getFilterDescription();
|
||||
|
||||
if ($filter) {
|
||||
$title = sprintf('%s - %s', $title, $filter);
|
||||
}
|
||||
|
||||
$this->extend('updateMetaTitle', $title);
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a description of the current filter.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFilterDescription()
|
||||
{
|
||||
$items = array();
|
||||
|
||||
$list = $this->PaginatedList();
|
||||
$currentPage = $list->CurrentPage();
|
||||
|
||||
if ($currentPage > 1) {
|
||||
$items[] = _t(
|
||||
'Blog.FILTERDESCRIPTION_PAGE',
|
||||
'Page {page}',
|
||||
null,
|
||||
array(
|
||||
'page' => $currentPage
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($author = $this->getCurrentProfile()) {
|
||||
$items[] = _t(
|
||||
'Blog.FILTERDESCRIPTION_AUTHOR',
|
||||
'By {author}',
|
||||
null,
|
||||
array(
|
||||
'author' => $author->Title
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($tag = $this->getCurrentTag()) {
|
||||
$items[] = _t(
|
||||
'Blog.FILTERDESCRIPTION_TAG',
|
||||
'Tagged with {tag}',
|
||||
null,
|
||||
array(
|
||||
'tag' => $tag->Title
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($category = $this->getCurrentCategory()) {
|
||||
$items[] = _t(
|
||||
'Blog.FILTERDESCRIPTION_CATEGORY',
|
||||
'In category {category}',
|
||||
null,
|
||||
array(
|
||||
'category' => $category->Title
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->owner->getArchiveYear()) {
|
||||
if ($this->owner->getArchiveDay()) {
|
||||
$date = $this->owner->getArchiveDate()->Nice();
|
||||
} elseif ($this->owner->getArchiveMonth()) {
|
||||
$date = $this->owner->getArchiveDate()->format('F, Y');
|
||||
} else {
|
||||
$date = $this->owner->getArchiveDate()->format('Y');
|
||||
}
|
||||
|
||||
$items[] = _t(
|
||||
'Blog.FILTERDESCRIPTION_DATE',
|
||||
'In {date}',
|
||||
null,
|
||||
array(
|
||||
'date' => $date,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$result = '';
|
||||
|
||||
if ($items) {
|
||||
$result = implode(', ', $items);
|
||||
}
|
||||
|
||||
$this->extend('updateFilterDescription', $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of paginated blog posts based on the BlogPost dataList.
|
||||
*
|
||||
* @return PaginatedList
|
||||
*/
|
||||
public function PaginatedList()
|
||||
{
|
||||
$allPosts = $this->blogPosts ?: ArrayList::create();
|
||||
|
||||
$posts = PaginatedList::create($allPosts);
|
||||
|
||||
// Set appropriate page size
|
||||
if ($this->PostsPerPage > 0) {
|
||||
$pageSize = $this->PostsPerPage;
|
||||
} elseif ($count = $allPosts->count()) {
|
||||
$pageSize = $count;
|
||||
} else {
|
||||
$pageSize = 99999;
|
||||
}
|
||||
$posts->setPageLength($pageSize);
|
||||
|
||||
// Set current page
|
||||
$start = $this->request->getVar($posts->getPaginationGetVar());
|
||||
$posts->setPageStart($start);
|
||||
|
||||
return $posts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an RSS feed of blog posts.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function rss()
|
||||
{
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$this->blogPosts = $dataRecord->getBlogPosts();
|
||||
|
||||
return $this->rssFeed($this->blogPosts, $this->Link());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current archive date.
|
||||
*
|
||||
* @return null|Date
|
||||
*/
|
||||
public function getArchiveDate()
|
||||
{
|
||||
$year = $this->getArchiveYear();
|
||||
$month = $this->getArchiveMonth();
|
||||
$day = $this->getArchiveDay();
|
||||
|
||||
if ($year) {
|
||||
if ($month) {
|
||||
$date = sprintf('%s-%s-01', $year, $month);
|
||||
|
||||
if ($day) {
|
||||
$date = sprintf('%s-%s-%s', $year, $month, $day);
|
||||
}
|
||||
} else {
|
||||
$date = sprintf('%s-01-01', $year);
|
||||
}
|
||||
|
||||
$obj = DBDatetime::create('date');
|
||||
$obj->setValue($date);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a link to the RSS feed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRSSLink()
|
||||
{
|
||||
return $this->Link('rss');
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an RSS feed of the given blog posts.
|
||||
*
|
||||
* @param DataList $blogPosts
|
||||
* @param string $link
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function rssFeed($blogPosts, $link)
|
||||
{
|
||||
$rss = new RSSFeed($blogPosts, $link, $this->MetaTitle, $this->MetaDescription);
|
||||
|
||||
$this->extend('updateRss', $rss);
|
||||
|
||||
return $rss->outputToBrowser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the $Rss sub-action for categories/tags has been set to "rss"
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isRSS()
|
||||
{
|
||||
$rss = $this->request->param('Rss');
|
||||
return (is_string($rss) && strcasecmp($rss, 'rss') == 0);
|
||||
}
|
||||
}
|
14
src/Controllers/BlogPostController.php
Normal file
14
src/Controllers/BlogPostController.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Controllers;
|
||||
|
||||
use Page_Controller;
|
||||
|
||||
/**
|
||||
* @package silverstripe
|
||||
* @subpackage blog
|
||||
*/
|
||||
class BlogPostController extends Page_Controller
|
||||
{
|
||||
|
||||
}
|
@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Forms;
|
||||
|
||||
use SilverStripe\Forms\FieldGroup;
|
||||
use SilverStripe\Control\Cookie;
|
||||
|
||||
class BlogAdminSidebar extends FieldGroup
|
||||
{
|
||||
/**
|
@ -1,5 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Forms\GridField;
|
||||
|
||||
use UnexpectedValueException;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridField_ActionProvider;
|
||||
use SilverStripe\Forms\GridField\GridField_FormAction;
|
||||
use SilverStripe\Forms\GridField\GridField_HTMLProvider;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\Security\Security;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\Requirements;
|
||||
|
||||
/**
|
||||
* Adds a component which allows a user to add a new DataObject by database field.
|
||||
*
|
||||
@ -195,7 +210,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
||||
$forTemplate->Fields->push($addAction);
|
||||
|
||||
return array(
|
||||
$this->targetFragment => $forTemplate->renderWith('GridFieldAddByDBField')
|
||||
$this->targetFragment => $forTemplate->renderWith('SilverStripe\\Blog\\Form\\GridField\\GridFieldAddByDBField')
|
||||
);
|
||||
}
|
||||
}
|
@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Forms\GridField;
|
||||
|
||||
use SilverStripe\Blog\Model\BlogPost;
|
||||
use SilverStripe\Lumberjack\Forms\GridFieldSiteTreeState;
|
||||
use SilverStripe\View\Requirements;
|
||||
|
||||
|
||||
/**
|
||||
* Provides a component to the {@link GridField} which tells the user whether or not a blog post
|
||||
* has been published and when.
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Forms\GridField;
|
||||
|
||||
use SilverStripe\Lumberjack\Forms\GridFieldConfig_Lumberjack;
|
||||
|
||||
/**
|
||||
* GridField config necessary for managing a SiteTree object.
|
||||
*
|
@ -1,6 +1,28 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Model\FieldType\DBDatetime;
|
||||
namespace SilverStripe\Blog\Model;
|
||||
|
||||
use Page;
|
||||
use Page_Controller;
|
||||
use SilverStripe\Blog\Admin\GridFieldCategorisationConfig;
|
||||
use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\RSS\RSSFeed;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\ListboxField;
|
||||
use SilverStripe\Forms\NumericField;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\ORM\PaginatedList;
|
||||
use SilverStripe\ORM\UnsavedRelationList;
|
||||
use SilverStripe\Security\Group;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Security\Permission;
|
||||
use SilverStripe\Security\PermissionProvider;
|
||||
use SilverStripe\View\Requirements;
|
||||
|
||||
/**
|
||||
* Blog Holder
|
||||
@ -52,6 +74,12 @@ class Blog extends Page implements PermissionProvider
|
||||
*/
|
||||
private static $grant_user_group = 'blog-users';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @var string
|
||||
*/
|
||||
private static $table_name = 'Blog';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@ -63,31 +91,31 @@ class Blog extends Page implements PermissionProvider
|
||||
* @var array
|
||||
*/
|
||||
private static $has_many = array(
|
||||
'Tags' => 'BlogTag',
|
||||
'Categories' => 'BlogCategory',
|
||||
'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag',
|
||||
'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $many_many = array(
|
||||
'Editors' => 'Member',
|
||||
'Writers' => 'Member',
|
||||
'Contributors' => 'Member',
|
||||
'Editors' => 'SilverStripe\\Security\\Member',
|
||||
'Writers' => 'SilverStripe\\Security\\Member',
|
||||
'Contributors' => 'SilverStripe\\Security\\Member',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $allowed_children = array(
|
||||
'BlogPost',
|
||||
'SilverStripe\\Blog\\Model\\BlogPost',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $extensions = array(
|
||||
'BlogFilter',
|
||||
'SilverStripe\\Blog\\Model\\BlogFilter',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -95,7 +123,7 @@ class Blog extends Page implements PermissionProvider
|
||||
*/
|
||||
private static $defaults = array(
|
||||
'ProvideComments' => false,
|
||||
'PostsPerPage' => 10,
|
||||
'PostsPerPage' => 10
|
||||
);
|
||||
|
||||
/**
|
||||
@ -124,14 +152,14 @@ class Blog extends Page implements PermissionProvider
|
||||
'Categories',
|
||||
_t('Blog.Categories', 'Categories'),
|
||||
$self->Categories(),
|
||||
GridFieldCategorisationConfig::create(15, $self->Categories()->sort('Title'), 'BlogCategory', 'Categories', 'BlogPosts')
|
||||
GridFieldCategorisationConfig::create(15, $self->Categories()->sort('Title'), 'SilverStripe\\Blog\\Model\\BlogCategory', 'Categories', 'BlogPosts')
|
||||
);
|
||||
|
||||
$tags = GridField::create(
|
||||
'Tags',
|
||||
_t('Blog.Tags', 'Tags'),
|
||||
$self->Tags(),
|
||||
GridFieldCategorisationConfig::create(15, $self->Tags()->sort('Title'), 'BlogTag', 'Tags', 'BlogPosts')
|
||||
GridFieldCategorisationConfig::create(15, $self->Tags()->sort('Title'), 'SilverStripe\\Blog\\Model\\BlogTag', 'Tags', 'BlogPosts')
|
||||
);
|
||||
|
||||
/**
|
||||
@ -473,7 +501,7 @@ class Blog extends Page implements PermissionProvider
|
||||
$stage = '_' . $stage;
|
||||
}
|
||||
|
||||
$query->innerJoin('BlogPost', sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage));
|
||||
$query->innerJoin('SilverStripe\\Blog\\Model\\BlogPost', sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage));
|
||||
|
||||
$conn = DB::getConn();
|
||||
|
||||
@ -624,512 +652,3 @@ class Blog extends Page implements PermissionProvider
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package silverstripe
|
||||
* @subpackage blog
|
||||
*/
|
||||
class Blog_Controller extends Page_Controller
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $allowed_actions = array(
|
||||
'archive',
|
||||
'tag',
|
||||
'category',
|
||||
'rss',
|
||||
'profile',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $url_handlers = array(
|
||||
'tag/$Tag!/$Rss' => 'tag',
|
||||
'category/$Category!/$Rss' => 'category',
|
||||
'archive/$Year!/$Month/$Day' => 'archive',
|
||||
'profile/$URLSegment!' => 'profile',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $casting = array(
|
||||
'MetaTitle' => 'Text',
|
||||
'FilterDescription' => 'Text',
|
||||
);
|
||||
|
||||
/**
|
||||
* The current Blog Post DataList query.
|
||||
*
|
||||
* @var DataList
|
||||
*/
|
||||
protected $blogPosts;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$this->blogPosts = $dataRecord->getBlogPosts();
|
||||
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a Blog Member's profile.
|
||||
*
|
||||
* @return SS_HTTPResponse
|
||||
*/
|
||||
public function profile()
|
||||
{
|
||||
$profile = $this->getCurrentProfile();
|
||||
|
||||
if (!$profile) {
|
||||
return $this->httpError(404, 'Not Found');
|
||||
}
|
||||
|
||||
$this->blogPosts = $this->getCurrentProfilePosts();
|
||||
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Member associated with the current URL segment.
|
||||
*
|
||||
* @return null|Member
|
||||
*/
|
||||
public function getCurrentProfile()
|
||||
{
|
||||
$urlSegment = $this->request->param('URLSegment');
|
||||
|
||||
if ($urlSegment) {
|
||||
return Member::get()
|
||||
->filter('URLSegment', $urlSegment)
|
||||
->first();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts related to the current Member profile.
|
||||
*
|
||||
* @return null|DataList
|
||||
*/
|
||||
public function getCurrentProfilePosts()
|
||||
{
|
||||
$profile = $this->getCurrentProfile();
|
||||
|
||||
if ($profile) {
|
||||
return $profile->BlogPosts()->filter('ParentID', $this->ID);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an archive for a specified date. This can be by year or year/month.
|
||||
*
|
||||
* @return null|SS_HTTPResponse
|
||||
*/
|
||||
public function archive()
|
||||
{
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$year = $this->getArchiveYear();
|
||||
$month = $this->getArchiveMonth();
|
||||
$day = $this->getArchiveDay();
|
||||
|
||||
if ($this->request->param('Month') && !$month) {
|
||||
$this->httpError(404, 'Not Found');
|
||||
}
|
||||
|
||||
if ($month && $this->request->param('Day') && !$day) {
|
||||
$this->httpError(404, 'Not Found');
|
||||
}
|
||||
|
||||
if ($year) {
|
||||
$this->blogPosts = $dataRecord->getArchivedBlogPosts($year, $month, $day);
|
||||
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
$this->httpError(404, 'Not Found');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the archive year from the url.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
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') {
|
||||
return SS_Datetime::now()->Year();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the archive money from the url.
|
||||
*
|
||||
* @return null|int
|
||||
*/
|
||||
public function getArchiveMonth()
|
||||
{
|
||||
$month = $this->request->param('Month');
|
||||
|
||||
if (preg_match('/^[0-9]{1,2}$/', $month)) {
|
||||
if ($month > 0 && $month < 13) {
|
||||
if (checkdate($month, 01, $this->getArchiveYear())) {
|
||||
return (int) $month;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the archive day from the url.
|
||||
*
|
||||
* @return null|int
|
||||
*/
|
||||
public function getArchiveDay()
|
||||
{
|
||||
$day = $this->request->param('Day');
|
||||
|
||||
if (preg_match('/^[0-9]{1,2}$/', $day)) {
|
||||
if (checkdate($this->getArchiveMonth(), $day, $this->getArchiveYear())) {
|
||||
return (int) $day;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the blog posts for a given tag.
|
||||
*
|
||||
* @return null|SS_HTTPResponse
|
||||
*/
|
||||
public function tag()
|
||||
{
|
||||
$tag = $this->getCurrentTag();
|
||||
|
||||
if ($tag) {
|
||||
$this->blogPosts = $tag->BlogPosts();
|
||||
|
||||
if($this->isRSS()) {
|
||||
return $this->rssFeed($this->blogPosts, $tag->getLink());
|
||||
} else {
|
||||
return $this->render();
|
||||
}
|
||||
}
|
||||
|
||||
$this->httpError(404, 'Not Found');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag Getter for use in templates.
|
||||
*
|
||||
* @return null|BlogTag
|
||||
*/
|
||||
public function getCurrentTag()
|
||||
{
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
$tag = $this->request->param('Tag');
|
||||
if ($tag) {
|
||||
return $dataRecord->Tags()
|
||||
->filter('URLSegment', array($tag, rawurlencode($tag)))
|
||||
->first();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the blog posts for a given category.
|
||||
*
|
||||
* @return null|SS_HTTPResponse
|
||||
*/
|
||||
public function category()
|
||||
{
|
||||
$category = $this->getCurrentCategory();
|
||||
|
||||
if ($category) {
|
||||
$this->blogPosts = $category->BlogPosts();
|
||||
|
||||
if($this->isRSS()) {
|
||||
return $this->rssFeed($this->blogPosts, $category->getLink());
|
||||
} else {
|
||||
return $this->render();
|
||||
}
|
||||
}
|
||||
|
||||
$this->httpError(404, 'Not Found');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Category Getter for use in templates.
|
||||
*
|
||||
* @return null|BlogCategory
|
||||
*/
|
||||
public function getCurrentCategory()
|
||||
{
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
$category = $this->request->param('Category');
|
||||
if ($category) {
|
||||
return $dataRecord->Categories()
|
||||
->filter('URLSegment', array($category, rawurlencode($category)))
|
||||
->first();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta title for the current action.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMetaTitle()
|
||||
{
|
||||
$title = $this->data()->getTitle();
|
||||
$filter = $this->getFilterDescription();
|
||||
|
||||
if ($filter) {
|
||||
$title = sprintf('%s - %s', $title, $filter);
|
||||
}
|
||||
|
||||
$this->extend('updateMetaTitle', $title);
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a description of the current filter.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFilterDescription()
|
||||
{
|
||||
$items = array();
|
||||
|
||||
$list = $this->PaginatedList();
|
||||
$currentPage = $list->CurrentPage();
|
||||
|
||||
if ($currentPage > 1) {
|
||||
$items[] = _t(
|
||||
'Blog.FILTERDESCRIPTION_PAGE',
|
||||
'Page {page}',
|
||||
null,
|
||||
array(
|
||||
'page' => $currentPage,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($author = $this->getCurrentProfile()) {
|
||||
$items[] = _t(
|
||||
'Blog.FILTERDESCRIPTION_AUTHOR',
|
||||
'By {author}',
|
||||
null,
|
||||
array(
|
||||
'author' => $author->Title,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($tag = $this->getCurrentTag()) {
|
||||
$items[] = _t(
|
||||
'Blog.FILTERDESCRIPTION_TAG',
|
||||
'Tagged with {tag}',
|
||||
null,
|
||||
array(
|
||||
'tag' => $tag->Title,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($category = $this->getCurrentCategory()) {
|
||||
$items[] = _t(
|
||||
'Blog.FILTERDESCRIPTION_CATEGORY',
|
||||
'In category {category}',
|
||||
null,
|
||||
array(
|
||||
'category' => $category->Title,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->owner->getArchiveYear()) {
|
||||
if ($this->owner->getArchiveDay()) {
|
||||
$date = $this->owner->getArchiveDate()->Nice();
|
||||
} elseif ($this->owner->getArchiveMonth()) {
|
||||
$date = $this->owner->getArchiveDate()->format('F, Y');
|
||||
} else {
|
||||
$date = $this->owner->getArchiveDate()->format('Y');
|
||||
}
|
||||
|
||||
$items[] = _t(
|
||||
'Blog.FILTERDESCRIPTION_DATE',
|
||||
'In {date}',
|
||||
null,
|
||||
array(
|
||||
'date' => $date,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$result = '';
|
||||
|
||||
if ($items) {
|
||||
$result = implode(', ', $items);
|
||||
}
|
||||
|
||||
$this->extend('updateFilterDescription', $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of paginated blog posts based on the BlogPost dataList.
|
||||
*
|
||||
* @return PaginatedList
|
||||
*/
|
||||
public function PaginatedList()
|
||||
{
|
||||
$allPosts = $this->blogPosts ?: new ArrayList();
|
||||
|
||||
$posts = new PaginatedList($allPosts);
|
||||
|
||||
// Set appropriate page size
|
||||
if ($this->PostsPerPage > 0) {
|
||||
$pageSize = $this->PostsPerPage;
|
||||
} elseif ($count = $allPosts->count()) {
|
||||
$pageSize = $count;
|
||||
} else {
|
||||
$pageSize = 99999;
|
||||
}
|
||||
$posts->setPageLength($pageSize);
|
||||
|
||||
// Set current page
|
||||
$start = $this->request->getVar($posts->getPaginationGetVar());
|
||||
$posts->setPageStart($start);
|
||||
|
||||
return $posts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an RSS feed of blog posts.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function rss()
|
||||
{
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$this->blogPosts = $dataRecord->getBlogPosts();
|
||||
|
||||
return $this->rssFeed($this->blogPosts, $this->Link());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current archive date.
|
||||
*
|
||||
* @return null|Date
|
||||
*/
|
||||
public function getArchiveDate()
|
||||
{
|
||||
$year = $this->getArchiveYear();
|
||||
$month = $this->getArchiveMonth();
|
||||
$day = $this->getArchiveDay();
|
||||
|
||||
if ($year) {
|
||||
if ($month) {
|
||||
$date = sprintf('%s-%s-01', $year, $month);
|
||||
|
||||
if ($day) {
|
||||
$date = sprintf('%s-%s-%s', $year, $month, $day);
|
||||
}
|
||||
} else {
|
||||
$date = sprintf('%s-01-01', $year);
|
||||
}
|
||||
|
||||
$obj = new DBDatetime('date');
|
||||
$obj->setValue($date);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a link to the RSS feed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRSSLink()
|
||||
{
|
||||
return $this->Link('rss');
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an RSS feed of the given blog posts.
|
||||
*
|
||||
* @param DataList $blogPosts
|
||||
* @param string $link
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function rssFeed($blogPosts, $link)
|
||||
{
|
||||
$rss = new RSSFeed($blogPosts, $link, $this->MetaTitle, $this->MetaDescription);
|
||||
|
||||
$this->extend('updateRss', $rss);
|
||||
|
||||
return $rss->outputToBrowser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the $Rss sub-action for categories/tags has been set to "rss"
|
||||
*/
|
||||
private function isRSS()
|
||||
{
|
||||
$rss = $this->request->param('Rss');
|
||||
if(is_string($rss) && strcasecmp($rss, "rss") == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Model;
|
||||
|
||||
use SilverStripe\Blog\Model\BlogObject;
|
||||
use SilverStripe\Blog\Model\CategorisationObject;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
|
||||
/**
|
||||
* A blog category for generalising blog posts.
|
||||
*
|
||||
@ -25,26 +31,32 @@ class BlogCategory extends DataObject implements CategorisationObject
|
||||
*/
|
||||
const DUPLICATE_EXCEPTION = 'DUPLICATE';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @var string
|
||||
*/
|
||||
private static $table_name = 'BlogCategory';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
'Title' => 'Varchar(255)',
|
||||
'URLSegment' => 'Varchar(255)',
|
||||
'URLSegment' => 'Varchar(255)'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $has_one = array(
|
||||
'Blog' => 'Blog',
|
||||
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $belongs_many_many = array(
|
||||
'BlogPosts' => 'BlogPost',
|
||||
'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost',
|
||||
);
|
||||
|
||||
/**
|
@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Model;
|
||||
|
||||
use SilverStripe\Blog\Model\BlogPost;
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
|
||||
/**
|
||||
* Adds Blog specific behaviour to Comment.
|
||||
*/
|
@ -1,5 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Model;
|
||||
|
||||
use SilverStripe\Blog\Model\Blog;
|
||||
use SilverStripe\Blog\Model\BlogPost;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\FormTransformation;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\Tab;
|
||||
use SilverStripe\Lumberjack\Model\Lumberjack;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\ORM\Versioning\Versioned;
|
||||
use SilverStripe\Security\Permission;
|
||||
|
||||
/**
|
||||
* This class is responsible for filtering the SiteTree when necessary and also overlaps into
|
||||
* filtering only published posts.
|
||||
@ -27,7 +42,7 @@ class BlogFilter extends Lumberjack
|
||||
|
||||
$dataQuery = $staged->dataQuery()
|
||||
->innerJoin('BlogPost', sprintf('"BlogPost%s"."ID" = "SiteTree%s"."ID"', $stage, $stage))
|
||||
->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now())));
|
||||
->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(DBDatetime::now())));
|
||||
|
||||
$staged = $staged->setDataQuery($dataQuery);
|
||||
}
|
||||
@ -40,7 +55,7 @@ class BlogFilter extends Lumberjack
|
||||
*/
|
||||
protected function subclassForBlog()
|
||||
{
|
||||
return in_array(get_class($this->owner), ClassInfo::subClassesFor('Blog'));
|
||||
return in_array(get_class($this->owner), ClassInfo::subclassesFor('Blog'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,7 +68,7 @@ class BlogFilter extends Lumberjack
|
||||
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())));
|
||||
->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(DBDatetime::now())));
|
||||
|
||||
$staged = $staged->setDataQuery($dataQuery);
|
||||
}
|
||||
@ -82,14 +97,14 @@ class BlogFilter extends Lumberjack
|
||||
'ClassName' => $excluded
|
||||
));
|
||||
|
||||
$gridField = new BlogFilter_GridField(
|
||||
$gridField = BlogFilter_GridField::create(
|
||||
'ChildPages',
|
||||
$this->getLumberjackTitle(),
|
||||
$pages,
|
||||
$this->getLumberjackGridFieldConfig()
|
||||
);
|
||||
|
||||
$tab = new Tab('ChildPages', $this->getLumberjackTitle(), $gridField);
|
||||
$tab = Tab::create('ChildPages', $this->getLumberjackTitle(), $gridField);
|
||||
|
||||
$fields->insertBefore($tab, 'Main');
|
||||
}
|
@ -1,5 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Model;
|
||||
|
||||
use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\Tab;
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\View\Parsers\URLSegmentFilter;
|
||||
use SilverStripe\View\Requirements;
|
||||
|
||||
/**
|
||||
* This class is responsible for add Blog specific behaviour to Members.
|
||||
*
|
||||
@ -27,7 +38,7 @@ class BlogMemberExtension extends DataExtension
|
||||
* @var array
|
||||
*/
|
||||
private static $belongs_many_many = array(
|
||||
'BlogPosts' => 'BlogPost',
|
||||
'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -80,7 +91,6 @@ class BlogMemberExtension extends DataExtension
|
||||
return $conflict->count() == 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -97,13 +107,13 @@ class BlogMemberExtension extends DataExtension
|
||||
Requirements::css(BLOGGER_DIR . '/css/cms.css');
|
||||
Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
|
||||
|
||||
$tab = new Tab('BlogPosts', 'Blog Posts');
|
||||
$tab = Tab::create('BlogPosts', 'Blog Posts');
|
||||
|
||||
$gridField = new GridField(
|
||||
$gridField = GridField::create(
|
||||
'BlogPosts',
|
||||
'Blog Posts',
|
||||
$this->owner->BlogPosts(),
|
||||
new GridFieldConfig_BlogPost()
|
||||
GridFieldConfig_BlogPost::create()
|
||||
);
|
||||
|
||||
$tab->Fields()->add($gridField);
|
@ -1,13 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Model;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Tab;
|
||||
use SilverStripe\Forms\TabSet;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\Security\Permission;
|
||||
use SilverStripe\View\Parsers\URLSegmentFilter;
|
||||
|
||||
/**
|
||||
* An object shared by BlogTag and BlogCategory.
|
||||
*
|
||||
* @package silverstripe
|
||||
* @subpackage blog
|
||||
*/
|
||||
trait BlogObject {
|
||||
|
||||
trait BlogObject
|
||||
{
|
||||
/**
|
||||
* @return DataList
|
||||
*/
|
||||
@ -25,8 +36,8 @@ trait BlogObject {
|
||||
*/
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = new TabSet('Root',
|
||||
new Tab('Main',
|
||||
$fields = TabSet::create('Root',
|
||||
Tab::create('Main',
|
||||
TextField::create('Title', _t(self::class . '.Title', 'Title'))
|
||||
)
|
||||
);
|
||||
@ -39,21 +50,23 @@ trait BlogObject {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @return ValidationResult
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
/** @var ValidationResult $validation */
|
||||
$validation = parent::validate();
|
||||
if(!$validation->valid()) {
|
||||
if (!$validation->isValid()) {
|
||||
return $validation;
|
||||
}
|
||||
|
||||
$blog = $this->Blog();
|
||||
if(!$blog || !$blog->exists()) {
|
||||
if (!$blog || !$blog->exists()) {
|
||||
return $validation;
|
||||
}
|
||||
|
||||
if($this->getDuplicatesByUrlSegment()->count() > 0) {
|
||||
$validation->error($this->getDuplicateError(), self::DUPLICATE_EXCEPTION);
|
||||
if ($this->getDuplicatesByUrlSegment()->count() > 0) {
|
||||
$validation->addError($this->getDuplicateError(), self::DUPLICATE_EXCEPTION);
|
||||
}
|
||||
return $validation;
|
||||
}
|
||||
@ -163,7 +176,7 @@ trait BlogObject {
|
||||
public function generateURLSegment($increment = 0)
|
||||
{
|
||||
$increment = (int) $increment;
|
||||
$filter = new URLSegmentFilter();
|
||||
$filter = URLSegmentFilter::create();
|
||||
|
||||
$this->URLSegment = $filter->filter($this->owner->Title);
|
||||
|
||||
@ -185,10 +198,13 @@ trait BlogObject {
|
||||
*/
|
||||
protected function getDuplicatesByUrlSegment()
|
||||
{
|
||||
$duplicates = DataList::create(self::class)->filter(array(
|
||||
$duplicates = DataList::create(self::class)
|
||||
->filter(
|
||||
array(
|
||||
'URLSegment' => $this->URLSegment,
|
||||
'BlogID' => (int) $this->BlogID,
|
||||
));
|
||||
)
|
||||
);
|
||||
|
||||
if ($this->ID) {
|
||||
$duplicates = $duplicates->exclude('ID', $this->ID);
|
||||
@ -217,5 +233,4 @@ trait BlogObject {
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getDuplicateError();
|
||||
|
||||
}
|
@ -1,5 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Model;
|
||||
|
||||
use Page;
|
||||
use SilverStripe\Blog\Forms\BlogAdminSidebar;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Forms\DatetimeField;
|
||||
use SilverStripe\Forms\HiddenField;
|
||||
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
|
||||
use SilverStripe\Forms\ListboxField;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\Forms\ToggleCompositeField;
|
||||
use SilverStripe\Forms\UploadField;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\ORM\UnsavedRelationList;
|
||||
use SilverStripe\Security\Group;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Security\Permission;
|
||||
use SilverStripe\TagField\TagField;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\Requirements;
|
||||
|
||||
/**
|
||||
* An individual blog post.
|
||||
*
|
||||
@ -24,11 +46,17 @@ class BlogPost extends Page
|
||||
*/
|
||||
private static $restrict_authors_to_group = false;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @var string
|
||||
*/
|
||||
private static $table_name = 'BlogPost';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
'PublishDate' => 'SS_Datetime',
|
||||
'PublishDate' => 'Datetime',
|
||||
'AuthorNames' => 'Varchar(1024)',
|
||||
'Summary' => 'HTMLText',
|
||||
);
|
||||
@ -37,16 +65,16 @@ class BlogPost extends Page
|
||||
* @var array
|
||||
*/
|
||||
private static $has_one = array(
|
||||
'FeaturedImage' => 'Image',
|
||||
'FeaturedImage' => 'SilverStripe\\Assets\\Image',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $many_many = array(
|
||||
'Categories' => 'BlogCategory',
|
||||
'Tags' => 'BlogTag',
|
||||
'Authors' => 'Member',
|
||||
'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory',
|
||||
'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag',
|
||||
'Authors' => 'SilverStripe\\Security\\Member',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -62,21 +90,21 @@ class BlogPost extends Page
|
||||
* @var array
|
||||
*/
|
||||
private static $extensions = array(
|
||||
'BlogPostFilter',
|
||||
'SilverStripe\\Blog\\Model\\BlogPostFilter'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $searchable_fields = array(
|
||||
'Title',
|
||||
'Title'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $summary_fields = array(
|
||||
'Title',
|
||||
'Title'
|
||||
);
|
||||
|
||||
/**
|
||||
@ -84,7 +112,7 @@ class BlogPost extends Page
|
||||
*/
|
||||
private static $casting = array(
|
||||
'Excerpt' => 'HTMLText',
|
||||
'Date' => 'SS_Datetime',
|
||||
'Date' => 'SS_Datetime'
|
||||
);
|
||||
|
||||
/**
|
||||
@ -412,12 +440,12 @@ class BlogPost extends Page
|
||||
public function onBeforePublish()
|
||||
{
|
||||
/**
|
||||
* @var SS_Datetime $publishDate
|
||||
* @var DBDatetime $publishDate
|
||||
*/
|
||||
$publishDate = $this->dbObject('PublishDate');
|
||||
|
||||
if (!$publishDate->getValue()) {
|
||||
$this->PublishDate = SS_Datetime::now()->getValue();
|
||||
$this->PublishDate = DBDatetime::now()->getValue();
|
||||
$this->write();
|
||||
}
|
||||
}
|
||||
@ -464,7 +492,7 @@ class BlogPost extends Page
|
||||
}
|
||||
|
||||
/**
|
||||
* @var SS_Datetime $publishDate
|
||||
* @var DBDatetime $publishDate
|
||||
*/
|
||||
$publishDate = $this->dbObject('PublishDate');
|
||||
if(!$publishDate->exists()) {
|
||||
@ -563,7 +591,7 @@ class BlogPost extends Page
|
||||
public function getMonthlyArchiveLink($type = 'day')
|
||||
{
|
||||
/**
|
||||
* @var SS_Datetime $date
|
||||
* @var DBDatetime $date
|
||||
*/
|
||||
$date = $this->dbObject('PublishDate');
|
||||
|
||||
@ -591,7 +619,7 @@ class BlogPost extends Page
|
||||
public function getYearlyArchiveLink()
|
||||
{
|
||||
/**
|
||||
* @var SS_Datetime $date
|
||||
* @var DBDatetime $date
|
||||
*/
|
||||
$date = $this->dbObject('PublishDate');
|
||||
|
||||
@ -706,11 +734,3 @@ class BlogPost extends Page
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package silverstripe
|
||||
* @subpackage blog
|
||||
*/
|
||||
class BlogPost_Controller extends Page_Controller
|
||||
{
|
||||
}
|
@ -1,5 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Model;
|
||||
|
||||
use SilverStripe\Admin\LeftAndMain;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
use SilverStripe\ORM\DataQuery;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\ORM\Queries\SQLSelect;
|
||||
use SilverStripe\ORM\Versioning\Versioned;
|
||||
use SilverStripe\Security\Permission;
|
||||
|
||||
/**
|
||||
* This is responsible for filtering only published posts to users who do not have permission to
|
||||
* view non-published posts.
|
||||
@ -25,27 +37,26 @@ class BlogPostFilter extends DataExtension
|
||||
if ($stage == 'Live' || !Permission::check('VIEW_DRAFT_CONTENT')) {
|
||||
$query->addWhere(sprintf(
|
||||
'"PublishDate" < \'%s\'',
|
||||
Convert::raw2sql(SS_Datetime::now())
|
||||
Convert::raw2sql(DBDatetime::now())
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* This is a fix so that when we try to fetch subclasses of BlogPost, lazy loading includes the
|
||||
* BlogPost table in its query. Leaving this table out means the default sort order column
|
||||
* PublishDate causes an error.
|
||||
*
|
||||
* @see https://github.com/silverstripe/silverstripe-framework/issues/1682
|
||||
*
|
||||
* @param SQLQuery $query
|
||||
* @param mixed $dataQuery
|
||||
* @param mixed $parent
|
||||
* @param SQLSelect $query
|
||||
* @param DataQuery $dataQuery
|
||||
* @param DataObject $dataObject
|
||||
*/
|
||||
public function augmentLoadLazyFields(
|
||||
SQLSelect &$query,
|
||||
DataQuery &$dataQuery = null,
|
||||
$dataObject
|
||||
) {
|
||||
public function augmentLoadLazyFields(SQLSelect &$query, DataQuery &$dataQuery = null, $dataObject)
|
||||
{
|
||||
$dataQuery->innerJoin('BlogPost', '"SiteTree"."ID" = "BlogPost"."ID"');
|
||||
}
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Model;
|
||||
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
|
||||
/**
|
||||
* Customise blog post to support comment notifications.
|
||||
*
|
@ -1,5 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Model;
|
||||
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Blog\Model\BlogObject;
|
||||
use SilverStripe\Blog\Model\CategorisationObject;
|
||||
|
||||
/**
|
||||
* A blog tag for keyword descriptions of a blog post.
|
||||
*
|
||||
@ -23,28 +29,34 @@ class BlogTag extends DataObject implements CategorisationObject
|
||||
* @const string
|
||||
* This must be a string because ValidationException has decided we can't use int
|
||||
*/
|
||||
const DUPLICATE_EXCEPTION = "DUPLICATE";
|
||||
const DUPLICATE_EXCEPTION = 'DUPLICATE';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @var string
|
||||
*/
|
||||
private static $table_name = 'BlogTag';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
'Title' => 'Varchar(255)',
|
||||
'URLSegment' => 'Varchar(255)',
|
||||
'URLSegment' => 'Varchar(255)'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $has_one = array(
|
||||
'Blog' => 'Blog',
|
||||
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $belongs_many_many = array(
|
||||
'BlogPosts' => 'BlogPost',
|
||||
'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost',
|
||||
);
|
||||
|
||||
/**
|
@ -1,8 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Model;
|
||||
|
||||
/**
|
||||
* @method ManyManyList BlogPosts
|
||||
*/
|
||||
interface CategorisationObject
|
||||
{
|
||||
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Widgets;
|
||||
|
||||
use SilverStripe\Blog\Model\Blog;
|
||||
|
||||
if (!class_exists('Widget')) {
|
||||
return;
|
||||
}
|
||||
@ -46,7 +50,7 @@ class BlogArchiveWidget extends Widget
|
||||
* @var array
|
||||
*/
|
||||
private static $has_one = array(
|
||||
'Blog' => 'Blog',
|
||||
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -72,7 +76,7 @@ class BlogArchiveWidget extends Widget
|
||||
* @var FieldList $fields
|
||||
*/
|
||||
$fields->merge(array(
|
||||
DropdownField::create('BlogID', _t('BlogArchiveWidget.Blog', 'Blog'), Blog::get()->map()),
|
||||
DropdownField::create('BlogID', _t('BlogArchiveWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()),
|
||||
DropdownField::create('ArchiveType', _t('BlogArchiveWidget.ArchiveType', 'ArchiveType'), $type),
|
||||
NumericField::create('NumberToDisplay', _t('BlogArchiveWidget.NumberToDisplay', 'No. to Display'))
|
||||
));
|
@ -1,6 +1,10 @@
|
||||
<?php
|
||||
|
||||
if (!class_exists("Widget")) {
|
||||
namespace SilverStripe\Blog\Widgets;
|
||||
|
||||
use SilverStripe\Blog\Model\Blog;
|
||||
|
||||
if (!class_exists('Widget')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -37,7 +41,7 @@ class BlogCategoriesWidget extends Widget
|
||||
* @var array
|
||||
*/
|
||||
private static $has_one = array(
|
||||
'Blog' => 'Blog',
|
||||
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -47,7 +51,7 @@ class BlogCategoriesWidget extends Widget
|
||||
{
|
||||
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
||||
$fields[] = DropdownField::create(
|
||||
'BlogID', _t('BlogCategoriesWidget.Blog', 'Blog'), Blog::get()->map()
|
||||
'BlogID', _t('BlogCategoriesWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()
|
||||
);
|
||||
|
||||
$fields[] = NumericField::create(
|
@ -1,6 +1,10 @@
|
||||
<?php
|
||||
|
||||
if (!class_exists("Widget")) {
|
||||
namespace SilverStripe\Blog\Widgets;
|
||||
|
||||
use SilverStripe\Blog\Model\Blog;
|
||||
|
||||
if (!class_exists('Widget')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -37,7 +41,7 @@ class BlogRecentPostsWidget extends Widget
|
||||
* @var array
|
||||
*/
|
||||
private static $has_one = array(
|
||||
'Blog' => 'Blog',
|
||||
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -50,7 +54,7 @@ class BlogRecentPostsWidget extends Widget
|
||||
* @var FieldList $fields
|
||||
*/
|
||||
$fields->merge(array(
|
||||
DropdownField::create('BlogID', _t('BlogRecentPostsWidget.Blog', 'Blog'), Blog::get()->map()),
|
||||
DropdownField::create('BlogID', _t('BlogRecentPostsWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()),
|
||||
NumericField::create('NumberOfPosts', _t('BlogRecentPostsWidget.NumberOfPosts', 'Number of Posts'))
|
||||
));
|
||||
});
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Widgets;
|
||||
|
||||
use SilverStripe\Blog\Model\Blog;
|
||||
|
||||
if (!class_exists('Widget')) {
|
||||
return;
|
||||
}
|
||||
@ -33,7 +37,7 @@ class BlogTagsCloudWidget extends Widget
|
||||
* @var array
|
||||
*/
|
||||
private static $has_one = array(
|
||||
'Blog' => 'Blog',
|
||||
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -47,7 +51,7 @@ class BlogTagsCloudWidget extends Widget
|
||||
*/
|
||||
$fields->push(
|
||||
DropdownField::create('BlogID', _t('BlogTagsCloudWidget.Blog',
|
||||
'Blog'), Blog::get()->map())
|
||||
'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map())
|
||||
);
|
||||
});
|
||||
|
@ -1,6 +1,10 @@
|
||||
<?php
|
||||
|
||||
if (!class_exists("Widget")) {
|
||||
namespace SilverStripe\Blog\Widgets;
|
||||
|
||||
use SilverStripe\Blog\Model\Blog;
|
||||
|
||||
if (!class_exists('Widget')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -37,7 +41,7 @@ class BlogTagsWidget extends Widget
|
||||
* @var array
|
||||
*/
|
||||
private static $has_one = array(
|
||||
'Blog' => 'Blog',
|
||||
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -47,7 +51,7 @@ class BlogTagsWidget extends Widget
|
||||
{
|
||||
$this->beforeUpdateCMSFields(function (Fieldlist $fields) {
|
||||
$fields[] = DropdownField::create(
|
||||
'BlogID', _t('BlogTagsWidget.Blog', 'Blog'), Blog::get()->map()
|
||||
'BlogID', _t('BlogTagsWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()
|
||||
);
|
||||
|
||||
$fields[] = NumericField::create(
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Blog\Model\Blog;
|
||||
use SilverStripe\Blog\Model\BlogCategory;
|
||||
use SilverStripe\Blog\Model\BlogTag;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\ORM\ValidationException;
|
||||
use SilverStripe\Security\Member;
|
||||
|
||||
/**
|
||||
* @mixin PHPUnit_Framework_TestCase
|
||||
*/
|
||||
@ -17,7 +25,7 @@ class BlogCategoryTest extends FunctionalTest
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
SS_Datetime::set_mock_now('2013-10-10 20:00:00');
|
||||
DBDatetime::set_mock_now('2013-10-10 20:00:00');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -25,7 +33,7 @@ class BlogCategoryTest extends FunctionalTest
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
SS_Datetime::clear_mock_now();
|
||||
DBDatetime::clear_mock_now();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
@ -42,12 +50,12 @@ class BlogCategoryTest extends FunctionalTest
|
||||
$member->logout();
|
||||
}
|
||||
|
||||
$this->objFromFixture('BlogPost', 'FirstBlogPost');
|
||||
$this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstBlogPost');
|
||||
|
||||
/**
|
||||
* @var BlogCategory $category
|
||||
*/
|
||||
$category = $this->objFromFixture('BlogCategory', 'FirstCategory');
|
||||
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'FirstCategory');
|
||||
|
||||
$this->assertEquals(5, $category->BlogPosts()->count(), 'Category blog post count');
|
||||
}
|
||||
@ -72,10 +80,10 @@ class BlogCategoryTest extends FunctionalTest
|
||||
{
|
||||
$this->useDraftSite();
|
||||
|
||||
$this->objFromFixture('Member', 'Admin');
|
||||
$this->objFromFixture('SilverStripe\\Security\\Member', 'Admin');
|
||||
|
||||
$editor = $this->objFromFixture('Member', 'Editor');
|
||||
$category = $this->objFromFixture('BlogCategory', 'SecondCategory');
|
||||
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor');
|
||||
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'SecondCategory');
|
||||
|
||||
$this->assertFalse($category->canView($editor), 'Editor should not be able to view category.');
|
||||
}
|
||||
@ -87,20 +95,20 @@ class BlogCategoryTest extends FunctionalTest
|
||||
{
|
||||
$this->useDraftSite();
|
||||
|
||||
$admin = $this->objFromFixture('Member', 'Admin');
|
||||
$editor = $this->objFromFixture('Member', 'Editor');
|
||||
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin');
|
||||
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor');
|
||||
|
||||
$category = $this->objFromFixture('BlogCategory', 'FirstCategory');
|
||||
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'FirstCategory');
|
||||
|
||||
$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.');
|
||||
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
|
||||
|
||||
$category = $this->objFromFixture('BlogCategory', 'SecondCategory');
|
||||
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'SecondCategory');
|
||||
|
||||
$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.');
|
||||
$this->assertFalse($category->canEdit($editor), 'Editor should not be able to edit category.');
|
||||
|
||||
$category = $this->objFromFixture('BlogCategory', 'ThirdCategory');
|
||||
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'ThirdCategory');
|
||||
|
||||
$this->assertTrue($category->canEdit($admin), 'Admin should always be able to edit category.');
|
||||
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
|
||||
@ -110,10 +118,10 @@ class BlogCategoryTest extends FunctionalTest
|
||||
{
|
||||
$this->useDraftSite();
|
||||
|
||||
$admin = $this->objFromFixture('Member', 'Admin');
|
||||
$editor = $this->objFromFixture('Member', 'Editor');
|
||||
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin');
|
||||
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor');
|
||||
|
||||
$category = singleton('BlogCategory');
|
||||
$category = singleton('SilverStripe\\Blog\\Model\\BlogCategory');
|
||||
|
||||
$this->assertTrue($category->canCreate($admin), 'Admin should be able to create category.');
|
||||
$this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.');
|
||||
@ -123,24 +131,25 @@ class BlogCategoryTest extends FunctionalTest
|
||||
{
|
||||
$this->useDraftSite();
|
||||
|
||||
$admin = $this->objFromFixture('Member', 'Admin');
|
||||
$editor = $this->objFromFixture('Member', 'Editor');
|
||||
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin');
|
||||
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor');
|
||||
|
||||
$category = $this->objFromFixture('BlogCategory', 'FirstCategory');
|
||||
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'FirstCategory');
|
||||
|
||||
$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.');
|
||||
$this->assertTrue($category->canDelete($editor), 'Editor should be able to category category.');
|
||||
|
||||
$category = $this->objFromFixture('BlogCategory', 'SecondCategory');
|
||||
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'SecondCategory');
|
||||
$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.');
|
||||
$this->assertFalse($category->canDelete($editor), 'Editor should not be able to delete category.');
|
||||
|
||||
$category = $this->objFromFixture('BlogCategory', 'ThirdCategory');
|
||||
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'ThirdCategory');
|
||||
$this->assertTrue($category->canDelete($admin), 'Admin should always be able to delete category.');
|
||||
$this->assertTrue($category->canDelete($editor), 'Editor should be able to delete category.');
|
||||
}
|
||||
|
||||
public function testDuplicateCategories() {
|
||||
public function testDuplicateCategories()
|
||||
{
|
||||
$blog = new Blog();
|
||||
$blog->Title = 'Testing for duplicate categories';
|
||||
$blog->write();
|
||||
@ -159,9 +168,9 @@ class BlogCategoryTest extends FunctionalTest
|
||||
$category->write();
|
||||
$this->fail('Duplicate BlogCategory written');
|
||||
} catch (ValidationException $e) {
|
||||
$codeList = $e->getResult()->codeList();
|
||||
$this->assertCount(1, $codeList);
|
||||
$this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $codeList[0]);
|
||||
$messages = $e->getResult()->getMessages();
|
||||
$this->assertCount(1, $messages);
|
||||
$this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $messages[0]['messageType']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\Security\Member;
|
||||
|
||||
/**
|
||||
* @mixin PHPUnit_Framework_TestCase
|
||||
*/
|
||||
@ -14,12 +18,12 @@ class BlogPostFilterTest extends SapphireTest
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
SS_Datetime::set_mock_now('2013-10-10 20:00:00');
|
||||
DBDatetime::set_mock_now('2013-10-10 20:00:00');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
SS_Datetime::clear_mock_now();
|
||||
DBDatetime::clear_mock_now();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
@ -35,11 +39,11 @@ class BlogPostFilterTest extends SapphireTest
|
||||
/**
|
||||
* @var Blog $blog
|
||||
*/
|
||||
$blog = $this->objFromFixture('Blog', 'FirstBlog');
|
||||
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog');
|
||||
|
||||
$this->assertEquals(3, $blog->AllChildren()->Count(), 'Filtered blog posts');
|
||||
|
||||
SS_Datetime::set_mock_now('2020-01-01 00:00:00');
|
||||
DBDatetime::set_mock_now('2020-01-01 00:00:00');
|
||||
|
||||
$this->assertEquals(5, $blog->AllChildren()->Count(), 'Unfiltered blog posts');
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
||||
class BlogPostNotificationsTest extends SapphireTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @var string
|
||||
*/
|
||||
public static $fixture_file = 'blog.yml';
|
||||
@ -13,7 +16,7 @@ class BlogPostNotificationsTest extends SapphireTest
|
||||
$this->markTestSkipped('Comments Notification module is not installed');
|
||||
}
|
||||
|
||||
$blogPost = $this->objFromFixture('BlogPost', 'PostC');
|
||||
$blogPost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC');
|
||||
$comment = new Comment();
|
||||
$comment->Comment = 'This is a comment';
|
||||
$comment->write();
|
||||
@ -27,8 +30,10 @@ class BlogPostNotificationsTest extends SapphireTest
|
||||
}
|
||||
|
||||
sort($segments);
|
||||
$this->assertEquals(array('blog-contributor', 'blog-editor',
|
||||
'blog-writer', ), $segments);
|
||||
$this->assertEquals(
|
||||
array('blog-contributor', 'blog-editor', 'blog-writer'),
|
||||
$segments
|
||||
);
|
||||
}
|
||||
|
||||
public function testUpdateNotificationSubject()
|
||||
@ -36,7 +41,7 @@ class BlogPostNotificationsTest extends SapphireTest
|
||||
if (!class_exists('CommentNotifier')) {
|
||||
$this->markTestSkipped('Comments Notification module is not installed');
|
||||
}
|
||||
$blogPost = $this->objFromFixture('BlogPost', 'PostC');
|
||||
$blogPost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC');
|
||||
$comment = new Comment();
|
||||
$comment->Comment = 'This is a comment';
|
||||
$comment->write();
|
||||
|
@ -1,8 +1,13 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
|
||||
class BlogPostTest extends SapphireTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @var string
|
||||
*/
|
||||
public static $fixture_file = 'blog.yml';
|
||||
@ -20,7 +25,7 @@ class BlogPostTest extends SapphireTest
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
SS_Datetime::clear_mock_now();
|
||||
DBDatetime::clear_mock_now();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
@ -29,12 +34,15 @@ class BlogPostTest extends SapphireTest
|
||||
*/
|
||||
public function testCanView($date, $user, $page, $canView)
|
||||
{
|
||||
$userRecord = $this->objFromFixture('Member', $user);
|
||||
$pageRecord = $this->objFromFixture('BlogPost', $page);
|
||||
SS_Datetime::set_mock_now($date);
|
||||
$userRecord = $this->objFromFixture('SilverStripe\\Security\\Member', $user);
|
||||
$pageRecord = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', $page);
|
||||
DBDatetime::set_mock_now($date);
|
||||
$this->assertEquals($canView, $pageRecord->canView($userRecord));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function canViewProvider()
|
||||
{
|
||||
$someFutureDate = '2013-10-10 20:00:00';
|
||||
@ -70,12 +78,12 @@ class BlogPostTest extends SapphireTest
|
||||
|
||||
public function testCandidateAuthors()
|
||||
{
|
||||
$blogpost = $this->objFromFixture('BlogPost', 'PostC');
|
||||
$blogpost = $this->objFromFixture('SilverStripe\\Blog\\Model\\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('SilverStripe\\Blog\\Model\\BlogPost', 'restrict_authors_to_group', 'blogusers');
|
||||
|
||||
$this->assertEquals(3, $blogpost->getCandidateAuthors()->count());
|
||||
|
||||
@ -86,12 +94,12 @@ class BlogPostTest extends SapphireTest
|
||||
|
||||
public function testCanViewFuturePost()
|
||||
{
|
||||
$blogPost = $this->objFromFixture('BlogPost', 'NullPublishDate');
|
||||
$blogPost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'NullPublishDate');
|
||||
|
||||
$editor = $this->objFromFixture('Member', 'BlogEditor');
|
||||
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'BlogEditor');
|
||||
$this->assertTrue($blogPost->canView($editor));
|
||||
|
||||
$visitor = $this->objFromFixture('Member', 'Visitor');
|
||||
$visitor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Visitor');
|
||||
$this->assertFalse($blogPost->canView($visitor));
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,19 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Blog\Model\Blog;
|
||||
use SilverStripe\Blog\Model\BlogTag;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\ORM\ValidationException;
|
||||
use SilverStripe\Security\Member;
|
||||
|
||||
/**
|
||||
* @mixin PHPUnit_Framework_TestCase
|
||||
*/
|
||||
class BlogTagTest extends FunctionalTest
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @var string
|
||||
*/
|
||||
public static $fixture_file = 'blog.yml';
|
||||
@ -17,7 +25,7 @@ class BlogTagTest extends FunctionalTest
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
SS_Datetime::set_mock_now('2013-10-10 20:00:00');
|
||||
DBDatetime::set_mock_now('2013-10-10 20:00:00');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -25,7 +33,7 @@ class BlogTagTest extends FunctionalTest
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
SS_Datetime::clear_mock_now();
|
||||
DBDatetime::clear_mock_now();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
@ -42,12 +50,12 @@ class BlogTagTest extends FunctionalTest
|
||||
$member->logout();
|
||||
}
|
||||
|
||||
$this->objFromFixture('BlogPost', 'FirstBlogPost');
|
||||
$this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstBlogPost');
|
||||
|
||||
/**
|
||||
* @var BlogTag $tag
|
||||
*/
|
||||
$tag = $this->objFromFixture('BlogTag', 'FirstTag');
|
||||
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag');
|
||||
|
||||
$this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count');
|
||||
}
|
||||
@ -75,15 +83,15 @@ class BlogTagTest extends FunctionalTest
|
||||
{
|
||||
$this->useDraftSite();
|
||||
|
||||
$admin = $this->objFromFixture('Member', 'Admin');
|
||||
$editor = $this->objFromFixture('Member', 'Editor');
|
||||
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin');
|
||||
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor');
|
||||
|
||||
$tag = $this->objFromFixture('BlogTag', 'FirstTag');
|
||||
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag');
|
||||
|
||||
$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.');
|
||||
$this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.');
|
||||
|
||||
$tag = $this->objFromFixture('BlogTag', 'SecondTag');
|
||||
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'SecondTag');
|
||||
|
||||
$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.');
|
||||
$this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.');
|
||||
@ -93,20 +101,20 @@ class BlogTagTest extends FunctionalTest
|
||||
{
|
||||
$this->useDraftSite();
|
||||
|
||||
$admin = $this->objFromFixture('Member', 'Admin');
|
||||
$editor = $this->objFromFixture('Member', 'Editor');
|
||||
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin');
|
||||
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor');
|
||||
|
||||
$tag = $this->objFromFixture('BlogTag', 'FirstTag');
|
||||
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag');
|
||||
|
||||
$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.');
|
||||
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
|
||||
|
||||
$tag = $this->objFromFixture('BlogTag', 'SecondTag');
|
||||
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'SecondTag');
|
||||
|
||||
$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.');
|
||||
$this->assertFalse($tag->canEdit($editor), 'Editor should not be able to edit tag.');
|
||||
|
||||
$tag = $this->objFromFixture('BlogTag', 'ThirdTag');
|
||||
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'ThirdTag');
|
||||
|
||||
$this->assertTrue($tag->canEdit($admin), 'Admin should always be able to edit tags.');
|
||||
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
|
||||
@ -116,10 +124,10 @@ class BlogTagTest extends FunctionalTest
|
||||
{
|
||||
$this->useDraftSite();
|
||||
|
||||
$admin = $this->objFromFixture('Member', 'Admin');
|
||||
$editor = $this->objFromFixture('Member', 'Editor');
|
||||
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin');
|
||||
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor');
|
||||
|
||||
$tag = singleton('BlogTag');
|
||||
$tag = singleton('SilverStripe\\Blog\\Model\\BlogTag');
|
||||
|
||||
$this->assertTrue($tag->canCreate($admin), 'Admin should be able to create tag.');
|
||||
$this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.');
|
||||
@ -129,26 +137,27 @@ class BlogTagTest extends FunctionalTest
|
||||
{
|
||||
$this->useDraftSite();
|
||||
|
||||
$admin = $this->objFromFixture('Member', 'Admin');
|
||||
$editor = $this->objFromFixture('Member', 'Editor');
|
||||
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin');
|
||||
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor');
|
||||
|
||||
$tag = $this->objFromFixture('BlogTag', 'FirstTag');
|
||||
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag');
|
||||
|
||||
$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.');
|
||||
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');
|
||||
|
||||
$tag = $this->objFromFixture('BlogTag', 'SecondTag');
|
||||
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'SecondTag');
|
||||
|
||||
$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.');
|
||||
$this->assertFalse($tag->canDelete($editor), 'Editor should not be able to delete tag.');
|
||||
|
||||
$tag = $this->objFromFixture('BlogTag', 'ThirdTag');
|
||||
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'ThirdTag');
|
||||
|
||||
$this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.');
|
||||
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');
|
||||
}
|
||||
|
||||
public function testDuplicateTagsForURLSegment() {
|
||||
public function testDuplicateTagsForURLSegment()
|
||||
{
|
||||
$blog = new Blog();
|
||||
$blog->Title = 'Testing for duplicates blog';
|
||||
$blog->write();
|
||||
@ -163,10 +172,10 @@ class BlogTagTest extends FunctionalTest
|
||||
$tag2->BlogID = $blog->ID;
|
||||
$tag2->write();
|
||||
$this->assertEquals('cat-test-1', $tag2->URLSegment);
|
||||
|
||||
}
|
||||
|
||||
public function testDuplicateTags() {
|
||||
public function testDuplicateTags()
|
||||
{
|
||||
$blog = new Blog();
|
||||
$blog->Title = 'Testing for duplicate tags';
|
||||
$blog->write();
|
||||
@ -185,10 +194,9 @@ class BlogTagTest extends FunctionalTest
|
||||
$tag->write();
|
||||
$this->fail('Duplicate BlogTag written');
|
||||
} catch (ValidationException $e) {
|
||||
$codeList = $e->getResult()->codeList();
|
||||
$this->assertCount(1, $codeList);
|
||||
$this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $codeList[0]);
|
||||
$messages = $e->getResult()->getMessages();
|
||||
$this->assertCount(1, $messages);
|
||||
$this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $messages[0]['messageType']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,19 @@
|
||||
<?php
|
||||
|
||||
class BlogTagsCloudWidgetTest extends SapphireTest {
|
||||
use SilverStripe\Blog\Model\Blog\BlogTagsCloudWidget;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Director;
|
||||
|
||||
class BlogTagsCloudWidgetTest extends SapphireTest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public static $fixture_file = 'blog.yml';
|
||||
|
||||
public function testGetCMSFields() {
|
||||
public function testGetCMSFields()
|
||||
{
|
||||
if (!class_exists('Widget')) {
|
||||
$this->markTestSkipped('Widgets module not installed');
|
||||
}
|
||||
@ -23,12 +29,13 @@ class BlogTagsCloudWidgetTest extends SapphireTest {
|
||||
$this->assertEquals($expected, $names);
|
||||
}
|
||||
|
||||
public function testGetTags() {
|
||||
public function testGetTags()
|
||||
{
|
||||
if (!class_exists('Widget')) {
|
||||
$this->markTestSkipped('Widgets module not installed');
|
||||
}
|
||||
$widget = new BlogTagsCloudWidget();
|
||||
$blog = $this->objFromFixture('Blog', 'FourthBlog');
|
||||
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FourthBlog');
|
||||
$widget->BlogID = $blog->ID;
|
||||
$widget->write();
|
||||
$tags = $widget->getTags()->toArray();
|
||||
|
@ -1,5 +1,17 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Blog\Controllers\BlogController;
|
||||
use SilverStripe\CMS\Controllers\ContentController;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\ORM\DataModel;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\ORM\SS_List;
|
||||
use SilverStripe\Security\Member;
|
||||
|
||||
/**
|
||||
* @mixin PHPUnit_Framework_TestCase
|
||||
*/
|
||||
@ -18,12 +30,12 @@ class BlogTest extends SapphireTest
|
||||
parent::setUp();
|
||||
|
||||
Config::nest();
|
||||
SS_Datetime::set_mock_now('2013-10-10 20:00:00');
|
||||
DBDatetime::set_mock_now('2013-10-10 20:00:00');
|
||||
|
||||
/**
|
||||
* @var Blog $blog
|
||||
*/
|
||||
$blog = $this->objFromFixture('Blog', 'FirstBlog');
|
||||
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog');
|
||||
|
||||
$blog->publish('Stage', 'Live');
|
||||
}
|
||||
@ -33,7 +45,7 @@ class BlogTest extends SapphireTest
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
SS_Datetime::clear_mock_now();
|
||||
DBDatetime::clear_mock_now();
|
||||
Config::unnest();
|
||||
|
||||
parent::tearDown();
|
||||
@ -50,17 +62,17 @@ class BlogTest extends SapphireTest
|
||||
/**
|
||||
* @var Blog $blog
|
||||
*/
|
||||
$blog = $this->objFromFixture('Blog', 'FirstBlog');
|
||||
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog');
|
||||
|
||||
Config::inst()->update('BlogPost', 'show_in_sitetree', true);
|
||||
Config::inst()->update('SilverStripe\\Blog\\Model\\BlogPost', 'show_in_sitetree', true);
|
||||
$classes = $blog->getExcludedSiteTreeClassNames();
|
||||
|
||||
$this->assertNotContains('BlogPost', $classes, 'BlogPost class should be hidden.');
|
||||
$this->assertNotContains('SilverStripe\\Blog\\Model\\BlogPost', $classes, 'BlogPost class should be hidden.');
|
||||
|
||||
Config::inst()->update('BlogPost', 'show_in_sitetree', false);
|
||||
Config::inst()->update('SilverStripe\\Blog\\Model\\BlogPost', 'show_in_sitetree', false);
|
||||
$classes = $blog->getExcludedSiteTreeClassNames();
|
||||
|
||||
$this->assertContains('BlogPost', $classes, 'BlogPost class should be hidden.');
|
||||
$this->assertContains('SilverStripe\\Blog\\Model\\BlogPost', $classes, 'BlogPost class should be hidden.');
|
||||
}
|
||||
|
||||
public function testGetArchivedBlogPosts()
|
||||
@ -74,7 +86,7 @@ class BlogTest extends SapphireTest
|
||||
/**
|
||||
* @var Blog $blog
|
||||
*/
|
||||
$blog = $this->objFromFixture('Blog', 'FirstBlog');
|
||||
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog');
|
||||
|
||||
$archive = $blog->getArchivedBlogPosts(2013);
|
||||
|
||||
@ -96,7 +108,7 @@ class BlogTest extends SapphireTest
|
||||
/**
|
||||
* @var Blog $blog
|
||||
*/
|
||||
$blog = $this->objFromFixture('Blog', 'FirstBlog');
|
||||
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog');
|
||||
|
||||
$link = Controller::join_links($blog->Link('archive'), '2013', '10', '01');
|
||||
|
||||
@ -135,8 +147,8 @@ class BlogTest extends SapphireTest
|
||||
*/
|
||||
public function testArchiveYear()
|
||||
{
|
||||
$blog = $this->objFromFixture('Blog', 'FirstBlog');
|
||||
$controller = new Blog_Controller($blog);
|
||||
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog');
|
||||
$controller = new BlogController($blog);
|
||||
$this->requestURL($controller, 'first-post/archive/');
|
||||
$this->assertEquals(2013, $controller->getArchiveYear(), 'getArchiveYear should return 2013');
|
||||
}
|
||||
@ -156,47 +168,47 @@ class BlogTest extends SapphireTest
|
||||
/**
|
||||
* @var Blog $firstBlog
|
||||
*/
|
||||
$firstBlog = $this->objFromFixture('Blog', 'FirstBlog');
|
||||
$firstBlog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog');
|
||||
|
||||
/**
|
||||
* @var Blog $fourthBlog
|
||||
*/
|
||||
$fourthBlog = $this->objFromFixture('Blog', 'FourthBlog');
|
||||
$fourthBlog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FourthBlog');
|
||||
|
||||
/**
|
||||
* @var BlogPost $postA
|
||||
*/
|
||||
$postA = $this->objFromFixture('BlogPost', 'PostA');
|
||||
$postA = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostA');
|
||||
|
||||
/**
|
||||
* @var BlogPost $postB
|
||||
*/
|
||||
$postB = $this->objFromFixture('BlogPost', 'PostB');
|
||||
$postB = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostB');
|
||||
|
||||
/**
|
||||
* @var BlogPost $postC
|
||||
*/
|
||||
$postC = $this->objFromFixture('BlogPost', 'PostC');
|
||||
$postC = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC');
|
||||
|
||||
/**
|
||||
* @var Member $editor
|
||||
*/
|
||||
$editor = $this->objFromFixture('Member', 'BlogEditor');
|
||||
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'BlogEditor');
|
||||
|
||||
/**
|
||||
* @var Member $writer
|
||||
*/
|
||||
$writer = $this->objFromFixture('Member', 'Writer');
|
||||
$writer = $this->objFromFixture('SilverStripe\\Security\\Member', 'Writer');
|
||||
|
||||
/**
|
||||
* @var Member $contributor
|
||||
*/
|
||||
$contributor = $this->objFromFixture('Member', 'Contributor');
|
||||
$contributor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Contributor');
|
||||
|
||||
/**
|
||||
* @var Member $visitor
|
||||
*/
|
||||
$visitor = $this->objFromFixture('Member', 'Visitor');
|
||||
$visitor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Visitor');
|
||||
|
||||
$this->assertEquals('Editor', $fourthBlog->RoleOf($editor));
|
||||
$this->assertEquals('Contributor', $fourthBlog->RoleOf($contributor));
|
||||
@ -274,8 +286,8 @@ class BlogTest extends SapphireTest
|
||||
|
||||
public function testFilteredCategories()
|
||||
{
|
||||
$blog = $this->objFromFixture('Blog', 'FirstBlog');
|
||||
$controller = new Blog_Controller($blog);
|
||||
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog');
|
||||
$controller = new BlogController($blog);
|
||||
|
||||
// Root url
|
||||
$this->requestURL($controller, 'first-post');
|
||||
@ -293,10 +305,10 @@ class BlogTest extends SapphireTest
|
||||
);
|
||||
|
||||
// Posts
|
||||
$firstPostID = $this->idFromFixture('BlogPost', 'FirstBlogPost');
|
||||
$secondPostID = $this->idFromFixture('BlogPost', 'SecondBlogPost');
|
||||
$firstFuturePostID = $this->idFromFixture('BlogPost', 'FirstFutureBlogPost');
|
||||
$secondFuturePostID = $this->idFromFixture('BlogPost', 'SecondFutureBlogPost');
|
||||
$firstPostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstBlogPost');
|
||||
$secondPostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'SecondBlogPost');
|
||||
$firstFuturePostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstFutureBlogPost');
|
||||
$secondFuturePostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'SecondFutureBlogPost');
|
||||
|
||||
// Request first tag
|
||||
$this->requestURL($controller, 'first-post/tag/first-tag');
|
||||
@ -321,7 +333,7 @@ class BlogTest extends SapphireTest
|
||||
*/
|
||||
protected function requestURL(ContentController $controller, $url)
|
||||
{
|
||||
$request = new SS_HTTPRequest('get', $url);
|
||||
$request = new HTTPRequest('get', $url);
|
||||
$request->match('$URLSegment//$Action/$ID/$OtherID');
|
||||
$request->shift();
|
||||
$controller->init();
|
||||
|
130
tests/blog.yml
130
tests/blog.yml
@ -1,6 +1,6 @@
|
||||
# Mock date is set to 2013-10-01 20:00:00
|
||||
|
||||
Group:
|
||||
SilverStripe\Security\Group:
|
||||
Administrators:
|
||||
Title: Administrators
|
||||
Editors:
|
||||
@ -9,193 +9,193 @@ Group:
|
||||
Title: Blog Users
|
||||
Code: blogusers
|
||||
|
||||
Permission:
|
||||
SilverStripe\Security\Permission:
|
||||
Administrators:
|
||||
Code: ADMIN
|
||||
Group: =>Group.Administrators
|
||||
Group: =>SilverStripe\Security\Group.Administrators
|
||||
Editors:
|
||||
Code: CMS_ACCESS_CMSMain
|
||||
Group: =>Group.Editors
|
||||
Group: =>SilverStripe\Security\Group.Editors
|
||||
BlogUsers:
|
||||
Code: CMS_ACCESS_CMSMain
|
||||
Group: =>Group.BlogUsers
|
||||
Group: =>SilverStripe\Security\Group.BlogUsers
|
||||
|
||||
SiteConfig:
|
||||
SilverStripe\SiteConfig\SiteConfig:
|
||||
Default:
|
||||
CanEditType: 'OnlyTheseUsers'
|
||||
CanCreateTopLevelType: 'OnlyTheseUsers'
|
||||
EditorGroups: =>Group.Administrators,=>Group.Editors
|
||||
CreateTopLevelGroups: =>Group.Administrators,=>Group.Editors
|
||||
EditorGroups: =>SilverStripe\Security\Group.Administrators,=>SilverStripe\Security\Group.Editors
|
||||
CreateTopLevelGroups: =>SilverStripe\Security\Group.Administrators,=>SilverStripe\Security\Group.Editors
|
||||
|
||||
Member:
|
||||
SilverStripe\Security\Member:
|
||||
Admin:
|
||||
FirstName: Test
|
||||
Surname: Administrator
|
||||
Groups: =>Group.Administrators
|
||||
Groups: =>SilverStripe\Security\Group.Administrators
|
||||
Editor:
|
||||
FirstName: Test
|
||||
Surname: Editor
|
||||
Groups: =>Group.Editors
|
||||
Groups: =>SilverStripe\Security\Group.Editors
|
||||
BlogEditor:
|
||||
FirstName: Blog
|
||||
Surname: Editor
|
||||
Groups: =>Group.BlogUsers
|
||||
Groups: =>SilverStripe\Security\Group.BlogUsers
|
||||
Writer:
|
||||
FirstName: Blog
|
||||
Surname: Writer
|
||||
Groups: =>Group.BlogUsers
|
||||
Groups: =>SilverStripe\Security\Group.BlogUsers
|
||||
Contributor:
|
||||
FirstName: Blog
|
||||
Surname: Contributor
|
||||
Groups: =>Group.BlogUsers
|
||||
Groups: =>SilverStripe\Security\Group.BlogUsers
|
||||
Visitor:
|
||||
FirstName: Blog
|
||||
Surname: Visitor
|
||||
|
||||
Blog:
|
||||
SilverStripe\Blog\Model\Blog:
|
||||
FirstBlog:
|
||||
Title: 'First Blog'
|
||||
SecondBlog:
|
||||
Title: 'Second Blog'
|
||||
CanViewType: 'OnlyTheseUsers'
|
||||
CanEditType: 'OnlyTheseUsers'
|
||||
ViewerGroups: =>Group.Administrators
|
||||
EditorGroups: =>Group.Administrators
|
||||
ViewerGroups: =>SilverStripe\Security\Group.Administrators
|
||||
EditorGroups: =>SilverStripe\Security\Group.Administrators
|
||||
ThirdBlog:
|
||||
Title: 'Third Blog'
|
||||
CanEditType: 'OnlyTheseUsers'
|
||||
EditorGroups: =>Group.Editors
|
||||
EditorGroups: =>SilverStripe\Security\Group.Editors
|
||||
FourthBlog:
|
||||
Title: 'Fourth Blog'
|
||||
Editors: =>Member.BlogEditor
|
||||
Writers: =>Member.Writer
|
||||
Contributors: =>Member.Contributor
|
||||
Editors: =>SilverStripe\Security\Member.BlogEditor
|
||||
Writers: =>SilverStripe\Security\Member.Writer
|
||||
Contributors: =>SilverStripe\Security\Member.Contributor
|
||||
|
||||
BlogTag:
|
||||
SilverStripe\Blog\Model\BlogTag:
|
||||
FirstTag:
|
||||
Title: 'First Tag'
|
||||
URLSegment: 'first-tag'
|
||||
Blog: =>Blog.FirstBlog
|
||||
Blog: =>SilverStripe\Blog\Model\Blog.FirstBlog
|
||||
SecondTag:
|
||||
Title: 'Second Tag'
|
||||
URLSegment: 'second-tag'
|
||||
Blog: =>Blog.SecondBlog
|
||||
Blog: =>SilverStripe\Blog\Model\Blog.SecondBlog
|
||||
ThirdTag:
|
||||
Title: 'Third Tag'
|
||||
URLSegment: 'third-tag'
|
||||
Blog: =>Blog.ThirdBlog
|
||||
Blog: =>SilverStripe\Blog\Model\Blog.ThirdBlog
|
||||
|
||||
#Tags for Tag Cloud widget
|
||||
PopularTag:
|
||||
Title: 'Popular'
|
||||
URLSegment: 'popular-tag'
|
||||
Blog: =>Blog.FourthBlog
|
||||
Blog: =>SilverStripe\Blog\Model\Blog.FourthBlog
|
||||
CoolTag:
|
||||
Title: 'Cool'
|
||||
URLSegment: 'cool-tag'
|
||||
Blog: =>Blog.FourthBlog
|
||||
Blog: =>SilverStripe\Blog\Model\Blog.FourthBlog
|
||||
CatTag:
|
||||
Title: 'Cat'
|
||||
URLSegment: 'cat-tag'
|
||||
Blog: =>Blog.FourthBlog
|
||||
Blog: =>SilverStripe\Blog\Model\Blog.FourthBlog
|
||||
KiwiTag:
|
||||
Title: 'Kiwi'
|
||||
URLSegment: 'kiwi-tag'
|
||||
Blog: =>Blog.FourthBlog
|
||||
Blog: =>SilverStripe\Blog\Model\Blog.FourthBlog
|
||||
|
||||
BlogCategory:
|
||||
SilverStripe\Blog\Model\BlogCategory:
|
||||
FirstCategory:
|
||||
Title: 'First Category'
|
||||
URLSegment: 'first-category'
|
||||
Blog: =>Blog.FirstBlog
|
||||
Blog: =>SilverStripe\Blog\Model\Blog.FirstBlog
|
||||
SecondCategory:
|
||||
Title: 'Second Category'
|
||||
URLSegment: 'second-category'
|
||||
Blog: =>Blog.SecondBlog
|
||||
Blog: =>SilverStripe\Blog\Model\Blog.SecondBlog
|
||||
ThirdCategory:
|
||||
Title: 'Third Category'
|
||||
URLSegment: 'third-category'
|
||||
Blog: =>Blog.ThirdBlog
|
||||
Blog: =>SilverStripe\Blog\Model\Blog.ThirdBlog
|
||||
|
||||
BlogPost:
|
||||
SilverStripe\Blog\Model\BlogPost:
|
||||
FirstBlogPost:
|
||||
Title: 'First Post'
|
||||
URLSegment: first-post
|
||||
PublishDate: '2013-10-01 15:00:00'
|
||||
Parent: =>Blog.FirstBlog
|
||||
Tags: =>BlogTag.FirstTag
|
||||
Categories: =>BlogCategory.FirstCategory
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog
|
||||
Tags: =>SilverStripe\Blog\Model\BlogTag.FirstTag
|
||||
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
|
||||
SecondBlogPost:
|
||||
Title: 'Second Post'
|
||||
URLSegment: second-post
|
||||
PublishDate: '2013-09-01 15:00:00'
|
||||
Parent: =>Blog.FirstBlog
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog
|
||||
ThirdBlogPost:
|
||||
Title: 'Old Post'
|
||||
URLSegment: old-post
|
||||
PublishDate: '2012-01-09 15:00:00'
|
||||
Parent: =>Blog.FirstBlog
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog
|
||||
FirstFutureBlogPost:
|
||||
Title: 'Future Post'
|
||||
URLSegment: future-post
|
||||
PublishDate: '2015-01-01 00:00:00'
|
||||
Tags: =>BlogTag.FirstTag
|
||||
Categories: =>BlogCategory.FirstCategory
|
||||
Parent: =>Blog.FirstBlog
|
||||
Tags: =>SilverStripe\Blog\Model\BlogTag.FirstTag
|
||||
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog
|
||||
SecondFutureBlogPost:
|
||||
Title: 'Future Post 2'
|
||||
URLSegment: future-post-2
|
||||
PublishDate: '2013-11-01 00:00:00'
|
||||
Tags: =>BlogTag.FirstTag
|
||||
Categories: =>BlogCategory.FirstCategory
|
||||
Parent: =>Blog.FirstBlog
|
||||
Tags: =>SilverStripe\Blog\Model\BlogTag.FirstTag
|
||||
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog
|
||||
PostA:
|
||||
Title: 'One Post'
|
||||
PublishDate: '2012-01-09 15:00:00'
|
||||
Parent: =>Blog.FourthBlog
|
||||
Authors: =>Member.Writer,=>Member.Contributor
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog
|
||||
Authors: =>SilverStripe\Security\Member.Writer,=>SilverStripe\Security\Member.Contributor
|
||||
PostB:
|
||||
Title: 'Second Post'
|
||||
PublishDate: '2012-01-09 15:00:00'
|
||||
Parent: =>Blog.FourthBlog
|
||||
Authors: =>Member.BlogEditor
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog
|
||||
Authors: =>SilverStripe\Security\Member.BlogEditor
|
||||
PostC:
|
||||
Title: 'Third Post'
|
||||
PublishDate: '2012-01-09 15:00:00'
|
||||
Parent: =>Blog.FourthBlog
|
||||
Authors: =>Member.BlogEditor,=>Member.Writer,=>Member.Contributor
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog
|
||||
Authors: =>SilverStripe\Security\Member.BlogEditor,=>SilverStripe\Security\Member.Writer,=>SilverStripe\Security\Member.Contributor
|
||||
NullPublishDate:
|
||||
Title: 'No publish date'
|
||||
PublishDate: ''
|
||||
Parent: =>Blog.FourthBlog
|
||||
Authors: =>Member.BlogEditor,=>Member.Writer,=>Member.Contributor
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog
|
||||
Authors: =>SilverStripe\Security\Member.BlogEditor,=>SilverStripe\Security\Member.Writer,=>SilverStripe\Security\Member.Contributor
|
||||
|
||||
#Posts for the tag cloud widget test
|
||||
TaggedPost1:
|
||||
Title: 'Tagged Post 1'
|
||||
URLSegment: tagged-post-1
|
||||
PublishDate: '2012-01-09 15:00:00'
|
||||
Tags: =>BlogTag.PopularTag,=>BlogTag.CoolTag
|
||||
Categories: =>BlogCategory.FirstCategory
|
||||
Parent: =>Blog.FourthBlog
|
||||
Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag,=>SilverStripe\Blog\Model\BlogTag.CoolTag
|
||||
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog
|
||||
TaggedPost2:
|
||||
Title: 'Tagged Post 2'
|
||||
URLSegment: tagged-post-2
|
||||
PublishDate: '2012-01-09 15:00:00'
|
||||
Tags: =>BlogTag.PopularTag,=>BlogTag.CoolTag,=>BlogTag.CatTag
|
||||
Categories: =>BlogCategory.FirstCategory
|
||||
Parent: =>Blog.FourthBlog
|
||||
Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag,=>SilverStripe\Blog\Model\BlogTag.CoolTag,=>SilverStripe\Blog\Model\BlogTag.CatTag
|
||||
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog
|
||||
TaggedPost3:
|
||||
Title: 'Tagged Post 3'
|
||||
URLSegment: tagged-post-3
|
||||
PublishDate: '2012-01-09 17:20:00'
|
||||
Tags: =>BlogTag.PopularTag,=>BlogTag.CoolTag,=>BlogTag.CatTag,=>BlogTag.KiwiTag
|
||||
Categories: =>BlogCategory.FirstCategory
|
||||
Parent: =>Blog.FourthBlog
|
||||
Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag,=>SilverStripe\Blog\Model\BlogTag.CoolTag,=>SilverStripe\Blog\Model\BlogTag.CatTag,=>SilverStripe\Blog\Model\BlogTag.KiwiTag
|
||||
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog
|
||||
TaggedPost4:
|
||||
Title: 'Tagged Post 4'
|
||||
URLSegment: tagged-post-4
|
||||
PublishDate: '2012-04-09 15:00:00'
|
||||
Tags: =>BlogTag.PopularTag
|
||||
Categories: =>BlogCategory.FirstCategory
|
||||
Parent: =>Blog.FourthBlog
|
||||
Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag
|
||||
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
|
||||
Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog
|
||||
|
Loading…
Reference in New Issue
Block a user