mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
ENHANCEMENT: make blog module compatible with SS3
This commit is contained in:
parent
c574d12226
commit
c723c3398a
@ -61,22 +61,22 @@ class BlogEntry extends Page {
|
|||||||
SiteTree::enableCMSFieldsExtensions();
|
SiteTree::enableCMSFieldsExtensions();
|
||||||
|
|
||||||
if(!self::$allow_wysiwyg_editing) {
|
if(!self::$allow_wysiwyg_editing) {
|
||||||
$fields->removeFieldFromTab("Root.Content.Main","Content");
|
$fields->removeFieldFromTab("Root.Main","Content");
|
||||||
$fields->addFieldToTab("Root.Content.Main", new TextareaField("Content", _t("BlogEntry.CN", "Content"), 20));
|
$fields->addFieldToTab("Root.Main", new TextareaField("Content", _t("BlogEntry.CN", "Content"), 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields->addFieldToTab("Root.Content.Main", $dateField = new DatetimeField("Date", _t("BlogEntry.DT", "Date")),"Content");
|
$fields->addFieldToTab("Root.Main", $dateField = new DatetimeField("Date", _t("BlogEntry.DT", "Date")),"Content");
|
||||||
$dateField->getDateField()->setConfig('showcalendar', true);
|
$dateField->getDateField()->setConfig('showcalendar', true);
|
||||||
$dateField->getTimeField()->setConfig('showdropdown', true);
|
$dateField->getTimeField()->setConfig('showdropdown', true);
|
||||||
$fields->addFieldToTab("Root.Content.Main", new TextField("Author", _t("BlogEntry.AU", "Author"), $firstName),"Content");
|
$fields->addFieldToTab("Root.Main", new TextField("Author", _t("BlogEntry.AU", "Author"), $firstName),"Content");
|
||||||
|
|
||||||
if(!self::$allow_wysiwyg_editing) {
|
if(!self::$allow_wysiwyg_editing) {
|
||||||
$fields->addFieldToTab("Root.Content.Main", new LiteralField("BBCodeHelper", "<div id='BBCode' class='field'>" .
|
$fields->addFieldToTab("Root.Main", new LiteralField("BBCodeHelper", "<div id='BBCode' class='field'>" .
|
||||||
"<a id=\"BBCodeHint\" target='new'>" . _t("BlogEntry.BBH", "BBCode help") . "</a>" .
|
"<a id=\"BBCodeHint\" target='new'>" . _t("BlogEntry.BBH", "BBCode help") . "</a>" .
|
||||||
"<div id='BBTagsHolder' style='display:none;'>".$codeparser->useable_tagsHTML()."</div></div>"));
|
"<div id='BBTagsHolder' style='display:none;'>".$codeparser->useable_tagsHTML()."</div></div>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields->addFieldToTab("Root.Content.Main", new TextField("Tags", _t("BlogEntry.TS", "Tags (comma sep.)")),"Content");
|
$fields->addFieldToTab("Root.Main", new TextField("Tags", _t("BlogEntry.TS", "Tags (comma sep.)")),"Content");
|
||||||
|
|
||||||
$this->extend('updateCMSFields', $fields);
|
$this->extend('updateCMSFields', $fields);
|
||||||
|
|
||||||
@ -87,8 +87,8 @@ class BlogEntry extends Page {
|
|||||||
* Returns the tags added to this blog entry
|
* Returns the tags added to this blog entry
|
||||||
*/
|
*/
|
||||||
function TagsCollection() {
|
function TagsCollection() {
|
||||||
$tags = split(" *, *", trim($this->Tags));
|
$tags = preg_split(" *, *", trim($this->Tags));
|
||||||
$output = new DataObjectSet();
|
$output = new ArrayList();
|
||||||
|
|
||||||
$link = $this->getParent() ? $this->getParent()->Link('tag') : '';
|
$link = $this->getParent() ? $this->getParent()->Link('tag') : '';
|
||||||
|
|
||||||
|
@ -46,19 +46,14 @@ class BlogHolder extends BlogTree implements PermissionProvider {
|
|||||||
/**
|
/**
|
||||||
* Get members who have BLOGMANAGEMENT and ADMIN permission
|
* Get members who have BLOGMANAGEMENT and ADMIN permission
|
||||||
*/
|
*/
|
||||||
function blogOwners($sort = 'Name', $direction = "ASC") {
|
function blogOwners($sort = array('FirstName'=>'ASC','Surname'=>'ASC'), $direction = null) {
|
||||||
$adminMembers = Permission::get_members_by_permission('ADMIN');
|
|
||||||
$blogOwners = Permission::get_members_by_permission('BLOGMANAGEMENT');
|
|
||||||
|
|
||||||
if(!$adminMembers) $adminMembers = new DataObjectSet();
|
$members = Permission::get_members_by_permission(array('ADMIN','BLOGMANAGEMENT'));
|
||||||
if(!$blogOwners) $blogOwners = new DataObjectSet();
|
$members->sort($sort);
|
||||||
|
|
||||||
$blogOwners->merge($adminMembers);
|
$this->extend('extendBlogOwners', $members);
|
||||||
$blogOwners->sort($sort, $direction);
|
|
||||||
|
|
||||||
$this->extend('extendBlogOwners', $blogOwners);
|
return $members;
|
||||||
|
|
||||||
return $blogOwners;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function BlogHolderIDs() {
|
public function BlogHolderIDs() {
|
||||||
@ -204,7 +199,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$codeparser = new BBCodeParser();
|
$codeparser = new BBCodeParser();
|
||||||
$membername = Member::currentMember() ? Member::currentMember()->getName() : "";
|
$membername = Member::currentUser() ? Member::currentUser()->getName() : "";
|
||||||
|
|
||||||
if(BlogEntry::$allow_wysiwyg_editing) {
|
if(BlogEntry::$allow_wysiwyg_editing) {
|
||||||
$contentfield = new HtmlEditorField("BlogPost", _t("BlogEntry.CN"));
|
$contentfield = new HtmlEditorField("BlogPost", _t("BlogEntry.CN"));
|
||||||
@ -226,7 +221,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
|
|||||||
if(!$this->AllowCustomAuthors && !Permission::check('ADMIN')) {
|
if(!$this->AllowCustomAuthors && !Permission::check('ADMIN')) {
|
||||||
$field = 'ReadonlyField';
|
$field = 'ReadonlyField';
|
||||||
}
|
}
|
||||||
$fields = new FieldSet(
|
$fields = new FieldList(
|
||||||
new HiddenField("ID", "ID"),
|
new HiddenField("ID", "ID"),
|
||||||
new TextField("Title", _t('BlogHolder.SJ', "Subject")),
|
new TextField("Title", _t('BlogHolder.SJ', "Subject")),
|
||||||
new $field("Author", _t('BlogEntry.AU'), $membername),
|
new $field("Author", _t('BlogEntry.AU'), $membername),
|
||||||
@ -237,7 +232,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$submitAction = new FormAction('postblog', _t('BlogHolder.POST', 'Post blog entry'));
|
$submitAction = new FormAction('postblog', _t('BlogHolder.POST', 'Post blog entry'));
|
||||||
$actions = new FieldSet($submitAction);
|
$actions = new FieldList($submitAction);
|
||||||
$validator = new RequiredFields('Title','BlogPost');
|
$validator = new RequiredFields('Title','BlogPost');
|
||||||
|
|
||||||
$form = new Form($this, 'BlogEntryForm',$fields, $actions,$validator);
|
$form = new Form($this, 'BlogEntryForm',$fields, $actions,$validator);
|
||||||
@ -274,7 +269,8 @@ class BlogHolder_Controller extends BlogTree_Controller {
|
|||||||
|
|
||||||
$form->saveInto($blogentry);
|
$form->saveInto($blogentry);
|
||||||
$blogentry->ParentID = $this->ID;
|
$blogentry->ParentID = $this->ID;
|
||||||
$blogentry->Content = str_replace("\r\n", "\n", $form->datafieldByName('BlogPost')->dataValue());
|
|
||||||
|
$blogentry->Content = str_replace("\r\n", "\n", $form->Fields()->fieldByName('BlogPost')->dataValue());
|
||||||
|
|
||||||
if(Object::has_extension($this->ClassName, 'Translatable')) {
|
if(Object::has_extension($this->ClassName, 'Translatable')) {
|
||||||
$blogentry->Locale = $this->Locale;
|
$blogentry->Locale = $this->Locale;
|
||||||
|
@ -2,40 +2,45 @@
|
|||||||
/**
|
/**
|
||||||
* Add trackback (receive and send) feature blog entry
|
* Add trackback (receive and send) feature blog entry
|
||||||
*/
|
*/
|
||||||
class TrackBackDecorator extends DataObjectDecorator {
|
class TrackBackDecorator extends DataExtension {
|
||||||
|
|
||||||
static $trackback_server_class = 'TrackbackHTTPServer';
|
static $trackback_server_class = 'TrackbackHTTPServer';
|
||||||
|
|
||||||
function extraStatics() {
|
// function extraStatics() {
|
||||||
return array(
|
// return array(
|
||||||
'has_many' => array(
|
// 'has_many' => array(
|
||||||
|
// 'TrackBackURLs' => 'TrackBackURL',
|
||||||
|
// 'TrackBacks' => 'TrackBackPing'
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
static $has_many = array(
|
||||||
'TrackBackURLs' => 'TrackBackURL',
|
'TrackBackURLs' => 'TrackBackURL',
|
||||||
'TrackBacks' => 'TrackBackPing'
|
'TrackBacks' => 'TrackBackPing'
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
function updateCMSFields($fields) {
|
// function updateCMSFields($fields) {
|
||||||
// Trackback URL field
|
// // Trackback URL field
|
||||||
if($this->owner->TrackBacksEnabled()) {
|
// if($this->owner->TrackBacksEnabled()) {
|
||||||
$trackbackURLTable = new ComplexTableField(
|
// $trackbackURLTable = new ComplexTableField(
|
||||||
$this,
|
// $this,
|
||||||
'TrackBackURLs',
|
// 'TrackBackURLs',
|
||||||
'TrackBackURL',
|
// 'TrackBackURL',
|
||||||
array(
|
// array(
|
||||||
'URL' => 'URL',
|
// 'URL' => 'URL',
|
||||||
'IsPung' => 'Pung?'
|
// 'IsPung' => 'Pung?'
|
||||||
),
|
// ),
|
||||||
'getCMSFields_forPopup',
|
// 'getCMSFields_forPopup',
|
||||||
'',
|
// '',
|
||||||
'ID'
|
// 'ID'
|
||||||
);
|
// );
|
||||||
$fields->addFieldToTab("Root.Content.Main", $trackbackURLTable);
|
// $fields->addFieldToTab("Root.Content.Main", $trackbackURLTable);
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
$fields->addFieldToTab("Root.Content.Main", new ReadonlyField("TrackBackURLsReadOnly", _t("BlogEntry.TrackbackURLs", "Trackback URLs"), _t("BlogEntry.TrackbackURLs_DISABLED", "To use this feature, please check 'Enable TrackBacks' check box on the blog holder.")));
|
// $fields->addFieldToTab("Root.Content.Main", new ReadonlyField("TrackBackURLsReadOnly", _t("BlogEntry.TrackbackURLs", "Trackback URLs"), _t("BlogEntry.TrackbackURLs_DISABLED", "To use this feature, please check 'Enable TrackBacks' check box on the blog holder.")));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
function onBeforePublish() {
|
function onBeforePublish() {
|
||||||
if(!$this->owner->TrackBacksEnabled() && !$this->owner->TrackBackURLs()) return;
|
if(!$this->owner->TrackBacksEnabled() && !$this->owner->TrackBackURLs()) return;
|
||||||
|
@ -11,7 +11,7 @@ class TrackBackURL extends DataObject {
|
|||||||
);
|
);
|
||||||
|
|
||||||
function getCMSFields_forPopup() {
|
function getCMSFields_forPopup() {
|
||||||
return new FieldSet(
|
return new FieldList(
|
||||||
new TextField('URL'),
|
new TextField('URL'),
|
||||||
new ReadonlyField('Pung', 'Pung?')
|
new ReadonlyField('Pung', 'Pung?')
|
||||||
);
|
);
|
||||||
|
@ -32,7 +32,7 @@ class ArchiveWidget extends Widget {
|
|||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
|
|
||||||
$fields->merge(
|
$fields->merge(
|
||||||
new FieldSet(
|
new FieldList(
|
||||||
new OptionsetField(
|
new OptionsetField(
|
||||||
'DisplayMode',
|
'DisplayMode',
|
||||||
_t('ArchiveWidget.DispBY', 'Display by'),
|
_t('ArchiveWidget.DispBY', 'Display by'),
|
||||||
|
@ -21,6 +21,7 @@ class BlogManagementWidget extends Widget implements PermissionProvider {
|
|||||||
static $description = "Provide a number of links useful for administering a blog. Only shown if the user is an admin.";
|
static $description = "Provide a number of links useful for administering a blog. Only shown if the user is an admin.";
|
||||||
|
|
||||||
function CommentText() {
|
function CommentText() {
|
||||||
|
if(!class_exists('Comment')) return false;
|
||||||
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM \"PageComment\" WHERE \"NeedsModeration\"=1")->value();
|
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM \"PageComment\" WHERE \"NeedsModeration\"=1")->value();
|
||||||
if($unmoderatedcount == 1) {
|
if($unmoderatedcount == 1) {
|
||||||
return _t("BlogManagementWidget.UNM1", "You have 1 unmoderated comment");
|
return _t("BlogManagementWidget.UNM1", "You have 1 unmoderated comment");
|
||||||
@ -32,7 +33,7 @@ class BlogManagementWidget extends Widget implements PermissionProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function CommentLink() {
|
function CommentLink() {
|
||||||
if(!Permission::check('BLOGMANAGEMENT')) {
|
if(!Permission::check('BLOGMANAGEMENT') || !class_exists('Comment')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM \"PageComment\" WHERE \"NeedsModeration\"=1")->value();
|
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM \"PageComment\" WHERE \"NeedsModeration\"=1")->value();
|
||||||
|
@ -43,7 +43,7 @@ class RSSWidget extends Widget {
|
|||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
|
|
||||||
$fields->merge(
|
$fields->merge(
|
||||||
new FieldSet(
|
new FieldList(
|
||||||
new TextField("RSSTitle", _t('RSSWidget.CT', "Custom title for the feed")),
|
new TextField("RSSTitle", _t('RSSWidget.CT', "Custom title for the feed")),
|
||||||
new TextField("RssUrl", _t('RSSWidget.URL', "URL of the other page's RSS feed. Please make sure this URL points to an RSS feed.")),
|
new TextField("RssUrl", _t('RSSWidget.URL', "URL of the other page's RSS feed. Please make sure this URL points to an RSS feed.")),
|
||||||
new NumericField("NumberToShow", _t('RSSWidget.NTS', "Number of Items to show"))
|
new NumericField("NumberToShow", _t('RSSWidget.NTS', "Number of Items to show"))
|
||||||
|
@ -30,7 +30,7 @@ class TagCloudWidget extends Widget {
|
|||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
|
|
||||||
$fields->merge(
|
$fields->merge(
|
||||||
new FieldSet(
|
new FieldList(
|
||||||
new TextField("Title", _t("TagCloudWidget.TILE", "Title")),
|
new TextField("Title", _t("TagCloudWidget.TILE", "Title")),
|
||||||
new TextField("Limit", _t("TagCloudWidget.LIMIT", "Limit number of tags")),
|
new TextField("Limit", _t("TagCloudWidget.LIMIT", "Limit number of tags")),
|
||||||
new OptionsetField("Sortby",_t("TagCloudWidget.SORTBY","Sort by"),array("alphabet"=>_t("TagCloudWidget.SBAL", "alphabet"),"frequency"=>_t("TagCloudWidget.SBFREQ", "frequency")))
|
new OptionsetField("Sortby",_t("TagCloudWidget.SORTBY","Sort by"),array("alphabet"=>_t("TagCloudWidget.SBAL", "alphabet"),"frequency"=>_t("TagCloudWidget.SBFREQ", "frequency")))
|
||||||
@ -57,7 +57,7 @@ class TagCloudWidget extends Widget {
|
|||||||
|
|
||||||
if($entries) {
|
if($entries) {
|
||||||
foreach($entries as $entry) {
|
foreach($entries as $entry) {
|
||||||
$theseTags = split(" *, *", mb_strtolower(trim($entry->Tags)));
|
$theseTags = preg_split(" *, *", mb_strtolower(trim($entry->Tags)));
|
||||||
foreach($theseTags as $tag) {
|
foreach($theseTags as $tag) {
|
||||||
if($tag != "") {
|
if($tag != "") {
|
||||||
$allTags[$tag] = isset($allTags[$tag]) ? $allTags[$tag] + 1 : 1; //getting the count into key => value map
|
$allTags[$tag] = isset($allTags[$tag]) ? $allTags[$tag] + 1 : 1; //getting the count into key => value map
|
||||||
@ -105,7 +105,7 @@ class TagCloudWidget extends Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = new DataObjectSet();
|
$output = new ArrayList();
|
||||||
foreach($allTags as $tag => $fields) {
|
foreach($allTags as $tag => $fields) {
|
||||||
$output->push(new ArrayData($fields));
|
$output->push(new ArrayData($fields));
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,6 @@ class BlogHolderFunctionalTest extends FunctionalTest {
|
|||||||
);
|
);
|
||||||
$response = $this->post('blog/BlogEntryForm', $data);
|
$response = $this->post('blog/BlogEntryForm', $data);
|
||||||
|
|
||||||
$this->assertType('BlogEntry', DataObject::get_one('BlogEntry', sprintf("\"Title\" = 'Allowed'")));
|
$this->assertInstanceOf('BlogEntry', DataObject::get_one('BlogEntry', sprintf("\"Title\" = 'Allowed'")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,11 +56,12 @@ class BlogHolderTest extends SapphireTest {
|
|||||||
|
|
||||||
function testBlogOwners() {
|
function testBlogOwners() {
|
||||||
$mainblog = $this->objFromFixture('BlogHolder', 'mainblog');
|
$mainblog = $this->objFromFixture('BlogHolder', 'mainblog');
|
||||||
$actualMembers = array_values($mainblog->blogOwners()->toDropDownMap('ID', 'Name'));
|
|
||||||
|
$actualMembers = array_values($mainblog->blogOwners()->map('ID', 'Name')->toArray());
|
||||||
$expectedMembers = array(
|
$expectedMembers = array(
|
||||||
'ADMIN User', // test default admin
|
|
||||||
'Admin One',
|
'Admin One',
|
||||||
'Admin Two',
|
'Admin Two',
|
||||||
|
'ADMIN User', // test default admin
|
||||||
'Blog Owner One',
|
'Blog Owner One',
|
||||||
'Blog Owner Three',
|
'Blog Owner Three',
|
||||||
'Blog Owner Two',
|
'Blog Owner Two',
|
||||||
|
@ -60,12 +60,13 @@ class BlogTrackbackTest extends SapphireTest {
|
|||||||
$entry1 = $this->objFromFixture('BlogEntry', 'testpost');
|
$entry1 = $this->objFromFixture('BlogEntry', 'testpost');
|
||||||
$entry1->doPublish();
|
$entry1->doPublish();
|
||||||
$this->assertEquals(2, $entry1->TrackBackURLs()->Count());
|
$this->assertEquals(2, $entry1->TrackBackURLs()->Count());
|
||||||
$this->assertEquals(array('testGoodTrackbackURL' => 1), $entry1->TrackBackURLs()->map('URL', 'Pung'));
|
|
||||||
|
$this->assertEquals(array('testGoodTrackbackURL' => 1), $entry1->TrackBackURLs()->map('URL', 'Pung')->toArray());
|
||||||
|
|
||||||
$entry2 = $this->objFromFixture('BlogEntry', 'testpost2');
|
$entry2 = $this->objFromFixture('BlogEntry', 'testpost2');
|
||||||
$entry2->doPublish();
|
$entry2->doPublish();
|
||||||
$this->assertEquals(4, $entry2->TrackBackURLs()->Count());
|
$this->assertEquals(4, $entry2->TrackBackURLs()->Count());
|
||||||
$this->assertEquals(array('testBadTrackbackURL' => 0, 'testGoodTrackbackURL2' => 1, 'noneExistingURL' => 0, 'testGoodTrackbackURL3' => 1), $entry2->TrackBackURLs()->map('URL', 'Pung'));
|
$this->assertEquals(array('testBadTrackbackURL' => 0, 'testGoodTrackbackURL2' => 1, 'noneExistingURL' => 0, 'testGoodTrackbackURL3' => 1), $entry2->TrackBackURLs()->map('URL', 'Pung')->toArray());
|
||||||
|
|
||||||
TrackBackDecorator::$trackback_server_class = $tmpServerClass;
|
TrackBackDecorator::$trackback_server_class = $tmpServerClass;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class BlogTreeTest extends SapphireTest {
|
|||||||
$this->assertEquals($node->Entries()->Count(), 2);
|
$this->assertEquals($node->Entries()->Count(), 2);
|
||||||
|
|
||||||
$node = $this->objFromFixture('BlogTree', 'levelab');
|
$node = $this->objFromFixture('BlogTree', 'levelab');
|
||||||
$this->assertNull($node->Entries());
|
$this->assertEquals($node->Entries()->Count(), 0); // this is not null anymore, it returns a DataList with no elements
|
||||||
|
|
||||||
$node = $this->objFromFixture('BlogTree', 'levelb');
|
$node = $this->objFromFixture('BlogTree', 'levelb');
|
||||||
$this->assertEquals($node->Entries()->Count(), 1);
|
$this->assertEquals($node->Entries()->Count(), 1);
|
||||||
@ -22,7 +22,7 @@ class BlogTreeTest extends SapphireTest {
|
|||||||
$node = $this->objFromFixture('BlogTree', 'levelba');
|
$node = $this->objFromFixture('BlogTree', 'levelba');
|
||||||
$this->assertEquals($node->Entries()->Count(), 1);
|
$this->assertEquals($node->Entries()->Count(), 1);
|
||||||
|
|
||||||
$this->assertTrue($node->getCMSFields() instanceof FieldSet);
|
$this->assertTrue($node->getCMSFields() instanceof FieldList);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testEntriesByMonth() {
|
function testEntriesByMonth() {
|
||||||
|
Loading…
Reference in New Issue
Block a user