Move "code" to PSR-4 friendly "src" folders. Add namespacing.

This commit is contained in:
Robbie Averill 2016-12-15 16:41:49 +13:00
parent 4313643a0b
commit 13a5badff5
45 changed files with 1143 additions and 1272 deletions

View File

@ -1,8 +1,8 @@
<?php
/**
* Fetches the name of the current module folder name.
*
* @return string
**/
define('BLOGGER_DIR', ltrim(Director::makeRelative(realpath(__DIR__)), DIRECTORY_SEPARATOR));
<?php
/**
* Fetches the name of the current module folder name.
*
* @return string
**/
define('BLOGGER_DIR', dirname(__FILE__));

View 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

View File

@ -1,6 +1,6 @@
---
Name: blogconfig
---
Member:
SilverStripe\Security\Member:
extensions:
- BlogMemberExtension
- SilverStripe\Blog\Model\BlogMemberExtension

View File

@ -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
{
}

View File

@ -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
{
}

View File

@ -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
{
}

View File

@ -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');
}
}

View File

@ -1,9 +0,0 @@
<?php
interface MigratableObject
{
/**
* Migrate the object up to the current version.
*/
public function up();
}

View File

@ -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";
}
}

View File

@ -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";
}
}

View File

@ -1,39 +1,44 @@
{
"name": "silverstripe/blog",
"description": "A fresh take on blogging in Silverstripe set out to tackle the issue of a cluttered Site Tree.",
"keywords": [
"silverstripe",
"blog",
"news"
],
"type": "silverstripe-module",
"require": {
"silverstripe/cms": "^4.0",
"silverstripe/lumberjack": "^2.0",
"silverstripe/tagfield": "^2.0"
},
"require-dev": {
"phpunit/PHPUnit": "~4.8"
},
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
},
"license": "BSD-2-Clause",
"authors": [
{
"name": "Michael Strong",
"email": "github@michaelstrong.co.uk"
}
],
"suggest": {
"silverstripe/widgets": "Some widgets come with the blog which are compatible with the widgets module.",
"silverstripe/comments": "This module adds comments to your blog."
},
"replace": {
"micmania1/silverstripe-blog": "*"
},
"minimum-stability": "dev",
"prefer-stable": true
"name": "silverstripe/blog",
"description": "A fresh take on blogging in Silverstripe set out to tackle the issue of a cluttered Site Tree.",
"keywords": [
"silverstripe",
"blog",
"news"
],
"type": "silverstripe-module",
"require": {
"silverstripe/cms": "^4.0",
"silverstripe/lumberjack": "^2.0",
"silverstripe/tagfield": "^2.0"
},
"require-dev": {
"phpunit/PHPUnit": "~4.8"
},
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
}
},
"autoload": {
"psr-4": {
"SilverStripe\\Blog\\": "src/"
}
},
"license": "BSD-2-Clause",
"authors": [
{
"name": "Michael Strong",
"email": "github@michaelstrong.co.uk"
}
],
"suggest": {
"silverstripe/widgets": "Some widgets come with the blog which are compatible with the widgets module.",
"silverstripe/comments": "This module adds comments to your blog."
},
"replace": {
"micmania1/silverstripe-blog": "*"
},
"minimum-stability": "dev",
"prefer-stable": true
}

28
src/.upgrade.yml Normal file
View 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

View File

@ -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(
'Title' => 'Title',
'BlogPostsCount' => 'Posts',
'MergeAction' => 'MergeAction',
'Actions' => 'Actions',
));
$columns->setDisplayFields(
array(
'Title' => 'Title',
'BlogPostsCount' => 'Posts',
'MergeAction' => 'MergeAction',
'Actions' => 'Actions'
)
);
}
}

View File

@ -1,5 +1,9 @@
<?php
namespace SilverStripe\Blog\Admin;
use GridField_FormAction;
class GridFieldFormAction extends GridField_FormAction
{
/**

View File

@ -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
{
/**

View 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);
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace SilverStripe\Blog\Controllers;
use Page_Controller;
/**
* @package silverstripe
* @subpackage blog
*/
class BlogPostController extends Page_Controller
{
}

View File

@ -1,5 +1,10 @@
<?php
namespace SilverStripe\Blog\Forms;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Control\Cookie;
class BlogAdminSidebar extends FieldGroup
{
/**

View File

@ -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')
);
}
}

View File

@ -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.

View File

@ -1,5 +1,9 @@
<?php
namespace SilverStripe\Blog\Forms\GridField;
use SilverStripe\Lumberjack\Forms\GridFieldConfig_Lumberjack;
/**
* GridField config necessary for managing a SiteTree object.
*

View File

@ -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
*/