Added BlogEntry::allow_wysiwyg_editing() for people who don't want to use BBCode

This commit is contained in:
Sam Minnee 2007-12-11 22:13:19 +00:00
parent 641d35c942
commit 104301e42d
2 changed files with 42 additions and 15 deletions

View File

@ -30,7 +30,12 @@ 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();
$fields->removeFieldFromTab("Root.Content.Main","Content");
$fields->addFieldToTab("Root.Content.Main", new TextareaField("Content", "Content", 20)); 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 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");
$fields->addFieldToTab("Root.Content.Main", new LiteralField("BBCodeHelper", "<div id='BBCode' class='field'>" . if(!self::$allow_wysiwyg_editing) {
"<a id=\"BBCodeHint\" target='new'>BBCode help</a>" . $fields->addFieldToTab("Root.Content.Main", new LiteralField("BBCodeHelper", "<div id='BBCode' class='field'>" .
"<div id='BBTagsHolder' style='display:none;'>".$codeparser->useable_tagsHTML()."</div></div>")); "<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"); $fields->addFieldToTab("Root.Content.Main", new TextField("Tags", "Tags (comma sep.)"),"Content");
return $fields; return $fields;
@ -98,20 +109,28 @@ 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(){
$content = new Text('Content'); if(self::$allow_wysiwyg_editing) {
$content->value = Convert::raw2xml($this->Content); return $this->obj('Content')->FirstParagraph();
$parser = new BBCodeParser($content->FirstParagraph()); } else {
return $parser->parse(); $content = new Text('Content');
$content->value = Convert::raw2xml($this->Content);
$parser = new BBCodeParser($content->FirstParagraph());
return $parser->parse();
}
} }
/** /**
* Get the bbcode parsed content * Get the bbcode parsed content
*/ */
function ParsedContent() { function ParsedContent() {
$parser = new BBCodeParser($this->Content); if(self::$allow_wysiwyg_editing) {
$content = new Text('Content'); return $this->Content;
$content->value =$parser->parse(); } else {
return $content; $parser = new BBCodeParser($this->Content);
$content = new Text('Content');
$content->value =$parser->parse();
return $content;
}
} }
/** /**
@ -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 {

View File

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