mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Added BlogEntry::allow_wysiwyg_editing() for people who don't want to use BBCode
This commit is contained in:
parent
641d35c942
commit
104301e42d
@ -31,6 +31,11 @@ class BlogEntry extends Page {
|
||||
|
||||
static $allowed_children = "none";
|
||||
|
||||
/**
|
||||
* Is WYSIWYG editing allowed?
|
||||
*/
|
||||
static $allow_wysiwyg_editing = false;
|
||||
|
||||
/**
|
||||
* overload so that the default date is today.
|
||||
*/
|
||||
@ -56,14 +61,20 @@ class BlogEntry extends Page {
|
||||
$codeparser = new BBCodeParser();
|
||||
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
if(!self::$allow_wysiwyg_editing) {
|
||||
$fields->removeFieldFromTab("Root.Content.Main","Content");
|
||||
$fields->addFieldToTab("Root.Content.Main", new TextareaField("Content", "Content", 20));
|
||||
}
|
||||
|
||||
$fields->addFieldToTab("Root.Content.Main", new CalendarDateField("Date", "Date"),"Content");
|
||||
$fields->addFieldToTab("Root.Content.Main", new TextField("Author", "Author", $firstName),"Content");
|
||||
|
||||
if(!self::$allow_wysiwyg_editing) {
|
||||
$fields->addFieldToTab("Root.Content.Main", new LiteralField("BBCodeHelper", "<div id='BBCode' class='field'>" .
|
||||
"<a id=\"BBCodeHint\" target='new'>BBCode help</a>" .
|
||||
"<div id='BBTagsHolder' style='display:none;'>".$codeparser->useable_tagsHTML()."</div></div>"));
|
||||
}
|
||||
|
||||
$fields->addFieldToTab("Root.Content.Main", new TextField("Tags", "Tags (comma sep.)"),"Content");
|
||||
return $fields;
|
||||
@ -98,21 +109,29 @@ class BlogEntry extends Page {
|
||||
* Get a bbcode parsed summary of the blog entry
|
||||
*/
|
||||
function ParagraphSummary(){
|
||||
if(self::$allow_wysiwyg_editing) {
|
||||
return $this->obj('Content')->FirstParagraph();
|
||||
} else {
|
||||
$content = new Text('Content');
|
||||
$content->value = Convert::raw2xml($this->Content);
|
||||
$parser = new BBCodeParser($content->FirstParagraph());
|
||||
return $parser->parse();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bbcode parsed content
|
||||
*/
|
||||
function ParsedContent() {
|
||||
if(self::$allow_wysiwyg_editing) {
|
||||
return $this->Content;
|
||||
} else {
|
||||
$parser = new BBCodeParser($this->Content);
|
||||
$content = new Text('Content');
|
||||
$content->value =$parser->parse();
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Link for editing this blog entry
|
||||
@ -121,6 +140,14 @@ class BlogEntry extends Page {
|
||||
return $this->getParent()->Link('post')."/".$this->ID."/";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call this to enable WYSIWYG editing on your blog entries.
|
||||
* By default the blog uses BBCode
|
||||
*/
|
||||
static function allow_wysiwyg_editing() {
|
||||
self::$allow_wysiwyg_editing = true;
|
||||
}
|
||||
}
|
||||
|
||||
class BlogEntry_Controller extends Page_Controller {
|
||||
|
@ -13,7 +13,7 @@
|
||||
<% end_control %>
|
||||
</p>
|
||||
<% end_if %>
|
||||
<p>$Content.Parse(BBCodeParser)</p>
|
||||
<p>$ParsedContent</p>
|
||||
<br />
|
||||
</div>
|
||||
<% if CurrentMember %><p><a href="$EditURL" id="editpost" title="Edit this post">Edit this post</a> | <a href="$Link(unpublishPost)" id="unpublishpost">Unpublish this post</a></p><% end_if %>
|
||||
|
Loading…
Reference in New Issue
Block a user