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";
|
static $allowed_children = "none";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is WYSIWYG editing allowed?
|
||||||
|
*/
|
||||||
|
static $allow_wysiwyg_editing = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* overload so that the default date is today.
|
* overload so that the default date is today.
|
||||||
*/
|
*/
|
||||||
@ -56,14 +61,20 @@ class BlogEntry extends Page {
|
|||||||
$codeparser = new BBCodeParser();
|
$codeparser = new BBCodeParser();
|
||||||
|
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
|
|
||||||
|
if(!self::$allow_wysiwyg_editing) {
|
||||||
$fields->removeFieldFromTab("Root.Content.Main","Content");
|
$fields->removeFieldFromTab("Root.Content.Main","Content");
|
||||||
$fields->addFieldToTab("Root.Content.Main", new TextareaField("Content", "Content", 20));
|
$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 CalendarDateField("Date", "Date"),"Content");
|
||||||
$fields->addFieldToTab("Root.Content.Main", new TextField("Author", "Author", $firstName),"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'>" .
|
$fields->addFieldToTab("Root.Content.Main", new LiteralField("BBCodeHelper", "<div id='BBCode' class='field'>" .
|
||||||
"<a id=\"BBCodeHint\" target='new'>BBCode help</a>" .
|
"<a id=\"BBCodeHint\" target='new'>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", "Tags (comma sep.)"),"Content");
|
$fields->addFieldToTab("Root.Content.Main", new TextField("Tags", "Tags (comma sep.)"),"Content");
|
||||||
return $fields;
|
return $fields;
|
||||||
@ -98,21 +109,29 @@ class BlogEntry extends Page {
|
|||||||
* Get a bbcode parsed summary of the blog entry
|
* Get a bbcode parsed summary of the blog entry
|
||||||
*/
|
*/
|
||||||
function ParagraphSummary(){
|
function ParagraphSummary(){
|
||||||
|
if(self::$allow_wysiwyg_editing) {
|
||||||
|
return $this->obj('Content')->FirstParagraph();
|
||||||
|
} else {
|
||||||
$content = new Text('Content');
|
$content = new Text('Content');
|
||||||
$content->value = Convert::raw2xml($this->Content);
|
$content->value = Convert::raw2xml($this->Content);
|
||||||
$parser = new BBCodeParser($content->FirstParagraph());
|
$parser = new BBCodeParser($content->FirstParagraph());
|
||||||
return $parser->parse();
|
return $parser->parse();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the bbcode parsed content
|
* Get the bbcode parsed content
|
||||||
*/
|
*/
|
||||||
function ParsedContent() {
|
function ParsedContent() {
|
||||||
|
if(self::$allow_wysiwyg_editing) {
|
||||||
|
return $this->Content;
|
||||||
|
} else {
|
||||||
$parser = new BBCodeParser($this->Content);
|
$parser = new BBCodeParser($this->Content);
|
||||||
$content = new Text('Content');
|
$content = new Text('Content');
|
||||||
$content->value =$parser->parse();
|
$content->value =$parser->parse();
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link for editing this blog entry
|
* Link for editing this blog entry
|
||||||
@ -121,6 +140,14 @@ class BlogEntry extends Page {
|
|||||||
return $this->getParent()->Link('post')."/".$this->ID."/";
|
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 {
|
class BlogEntry_Controller extends Page_Controller {
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<% end_control %>
|
<% end_control %>
|
||||||
</p>
|
</p>
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
<p>$Content.Parse(BBCodeParser)</p>
|
<p>$ParsedContent</p>
|
||||||
<br />
|
<br />
|
||||||
</div>
|
</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 %>
|
<% 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