ENHANCEMENT: make blog module compatible with SS3

This commit is contained in:
carlos barberis 2012-05-19 14:26:55 +12:00
parent c574d12226
commit c723c3398a
12 changed files with 70 additions and 66 deletions

View File

@ -61,22 +61,22 @@ class BlogEntry extends Page {
SiteTree::enableCMSFieldsExtensions();
if(!self::$allow_wysiwyg_editing) {
$fields->removeFieldFromTab("Root.Content.Main","Content");
$fields->addFieldToTab("Root.Content.Main", new TextareaField("Content", _t("BlogEntry.CN", "Content"), 20));
$fields->removeFieldFromTab("Root.Main","Content");
$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->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) {
$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>" .
"<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);
@ -87,8 +87,8 @@ class BlogEntry extends Page {
* Returns the tags added to this blog entry
*/
function TagsCollection() {
$tags = split(" *, *", trim($this->Tags));
$output = new DataObjectSet();
$tags = preg_split(" *, *", trim($this->Tags));
$output = new ArrayList();
$link = $this->getParent() ? $this->getParent()->Link('tag') : '';

View File

@ -46,19 +46,14 @@ class BlogHolder extends BlogTree implements PermissionProvider {
/**
* Get members who have BLOGMANAGEMENT and ADMIN permission
*/
function blogOwners($sort = 'Name', $direction = "ASC") {
$adminMembers = Permission::get_members_by_permission('ADMIN');
$blogOwners = Permission::get_members_by_permission('BLOGMANAGEMENT');
function blogOwners($sort = array('FirstName'=>'ASC','Surname'=>'ASC'), $direction = null) {
if(!$adminMembers) $adminMembers = new DataObjectSet();
if(!$blogOwners) $blogOwners = new DataObjectSet();
$members = Permission::get_members_by_permission(array('ADMIN','BLOGMANAGEMENT'));
$members->sort($sort);
$blogOwners->merge($adminMembers);
$blogOwners->sort($sort, $direction);
$this->extend('extendBlogOwners', $members);
$this->extend('extendBlogOwners', $blogOwners);
return $blogOwners;
return $members;
}
public function BlogHolderIDs() {
@ -204,7 +199,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
}
$codeparser = new BBCodeParser();
$membername = Member::currentMember() ? Member::currentMember()->getName() : "";
$membername = Member::currentUser() ? Member::currentUser()->getName() : "";
if(BlogEntry::$allow_wysiwyg_editing) {
$contentfield = new HtmlEditorField("BlogPost", _t("BlogEntry.CN"));
@ -226,7 +221,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
if(!$this->AllowCustomAuthors && !Permission::check('ADMIN')) {
$field = 'ReadonlyField';
}
$fields = new FieldSet(
$fields = new FieldList(
new HiddenField("ID", "ID"),
new TextField("Title", _t('BlogHolder.SJ', "Subject")),
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'));
$actions = new FieldSet($submitAction);
$actions = new FieldList($submitAction);
$validator = new RequiredFields('Title','BlogPost');
$form = new Form($this, 'BlogEntryForm',$fields, $actions,$validator);
@ -274,7 +269,8 @@ class BlogHolder_Controller extends BlogTree_Controller {
$form->saveInto($blogentry);
$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')) {
$blogentry->Locale = $this->Locale;

View File

@ -2,40 +2,45 @@
/**
* Add trackback (receive and send) feature blog entry
*/
class TrackBackDecorator extends DataObjectDecorator {
class TrackBackDecorator extends DataExtension {
static $trackback_server_class = 'TrackbackHTTPServer';
function extraStatics() {
return array(
'has_many' => array(
// function extraStatics() {
// return array(
// 'has_many' => array(
// 'TrackBackURLs' => 'TrackBackURL',
// 'TrackBacks' => 'TrackBackPing'
// )
// );
// }
static $has_many = array(
'TrackBackURLs' => 'TrackBackURL',
'TrackBacks' => 'TrackBackPing'
)
);
}
function updateCMSFields($fields) {
// Trackback URL field
if($this->owner->TrackBacksEnabled()) {
$trackbackURLTable = new ComplexTableField(
$this,
'TrackBackURLs',
'TrackBackURL',
array(
'URL' => 'URL',
'IsPung' => 'Pung?'
),
'getCMSFields_forPopup',
'',
'ID'
);
$fields->addFieldToTab("Root.Content.Main", $trackbackURLTable);
}
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.")));
}
}
// function updateCMSFields($fields) {
// // Trackback URL field
// if($this->owner->TrackBacksEnabled()) {
// $trackbackURLTable = new ComplexTableField(
// $this,
// 'TrackBackURLs',
// 'TrackBackURL',
// array(
// 'URL' => 'URL',
// 'IsPung' => 'Pung?'
// ),
// 'getCMSFields_forPopup',
// '',
// 'ID'
// );
// $fields->addFieldToTab("Root.Content.Main", $trackbackURLTable);
// }
// 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.")));
// }
// }
function onBeforePublish() {
if(!$this->owner->TrackBacksEnabled() && !$this->owner->TrackBackURLs()) return;

View File

@ -11,7 +11,7 @@ class TrackBackURL extends DataObject {
);
function getCMSFields_forPopup() {
return new FieldSet(
return new FieldList(
new TextField('URL'),
new ReadonlyField('Pung', 'Pung?')
);

View File

@ -32,7 +32,7 @@ class ArchiveWidget extends Widget {
$fields = parent::getCMSFields();
$fields->merge(
new FieldSet(
new FieldList(
new OptionsetField(
'DisplayMode',
_t('ArchiveWidget.DispBY', 'Display by'),

View File

@ -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.";
function CommentText() {
if(!class_exists('Comment')) return false;
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM \"PageComment\" WHERE \"NeedsModeration\"=1")->value();
if($unmoderatedcount == 1) {
return _t("BlogManagementWidget.UNM1", "You have 1 unmoderated comment");
@ -32,7 +33,7 @@ class BlogManagementWidget extends Widget implements PermissionProvider {
}
function CommentLink() {
if(!Permission::check('BLOGMANAGEMENT')) {
if(!Permission::check('BLOGMANAGEMENT') || !class_exists('Comment')) {
return false;
}
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM \"PageComment\" WHERE \"NeedsModeration\"=1")->value();

View File

@ -43,7 +43,7 @@ class RSSWidget extends Widget {
$fields = parent::getCMSFields();
$fields->merge(
new FieldSet(
new FieldList(
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 NumericField("NumberToShow", _t('RSSWidget.NTS', "Number of Items to show"))

View File

@ -30,7 +30,7 @@ class TagCloudWidget extends Widget {
$fields = parent::getCMSFields();
$fields->merge(
new FieldSet(
new FieldList(
new TextField("Title", _t("TagCloudWidget.TILE", "Title")),
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")))
@ -57,7 +57,7 @@ class TagCloudWidget extends Widget {
if($entries) {
foreach($entries as $entry) {
$theseTags = split(" *, *", mb_strtolower(trim($entry->Tags)));
$theseTags = preg_split(" *, *", mb_strtolower(trim($entry->Tags)));
foreach($theseTags as $tag) {
if($tag != "") {
$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) {
$output->push(new ArrayData($fields));
}

View File

@ -46,6 +46,6 @@ class BlogHolderFunctionalTest extends FunctionalTest {
);
$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'")));
}
}

View File

@ -56,11 +56,12 @@ class BlogHolderTest extends SapphireTest {
function testBlogOwners() {
$mainblog = $this->objFromFixture('BlogHolder', 'mainblog');
$actualMembers = array_values($mainblog->blogOwners()->toDropDownMap('ID', 'Name'));
$actualMembers = array_values($mainblog->blogOwners()->map('ID', 'Name')->toArray());
$expectedMembers = array(
'ADMIN User', // test default admin
'Admin One',
'Admin Two',
'ADMIN User', // test default admin
'Blog Owner One',
'Blog Owner Three',
'Blog Owner Two',

View File

@ -60,12 +60,13 @@ class BlogTrackbackTest extends SapphireTest {
$entry1 = $this->objFromFixture('BlogEntry', 'testpost');
$entry1->doPublish();
$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->doPublish();
$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;
}

View File

@ -14,7 +14,7 @@ class BlogTreeTest extends SapphireTest {
$this->assertEquals($node->Entries()->Count(), 2);
$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');
$this->assertEquals($node->Entries()->Count(), 1);
@ -22,7 +22,7 @@ class BlogTreeTest extends SapphireTest {
$node = $this->objFromFixture('BlogTree', 'levelba');
$this->assertEquals($node->Entries()->Count(), 1);
$this->assertTrue($node->getCMSFields() instanceof FieldSet);
$this->assertTrue($node->getCMSFields() instanceof FieldList);
}
function testEntriesByMonth() {