diff --git a/code/BlogHolder.php b/code/BlogHolder.php
index 3997cfb..c458b0a 100644
--- a/code/BlogHolder.php
+++ b/code/BlogHolder.php
@@ -174,7 +174,114 @@ class BlogHolder_Controller extends BlogTree_Controller {
return BBCodeParser::usable_tags();
}
-
+ function providePermissions() {
+ return array("BLOGMANAGEMENT" => "Blog management");
+ }
+
+ /**
+ * Post a new blog entry
+ */
+ function post(){
+ if(!Permission::check('BLOGMANAGEMENT')) return Security::permissionFailure();
+ $page = $this->customise(array(
+ 'Content' => false,
+ 'Form' => $this->BlogEntryForm()
+ ));
+
+ return $page->renderWith('Page');
+ }
+
+ /**
+ * A simple form for creating blog entries
+ */
+ function BlogEntryForm() {
+ if(!Permission::check('BLOGMANAGEMENT')) return Security::permissionFailure();
+
+
+ $id = 0;
+ if($this->request->latestParam('ID')) {
+ $id = (int) $this->request->latestParam('ID');
+ }
+
+ $codeparser = new BBCodeParser();
+ $membername = Member::currentMember() ? Member::currentMember()->getName() : "";
+
+ if(BlogEntry::$allow_wysiwyg_editing) {
+ $contentfield = new HtmlEditorField("BlogPost", _t("BlogEntry.CN"));
+ } else {
+ $contentfield = new CompositeField(
+ new LiteralField("BBCodeHelper",""._t("BlogEntry.BBH")."
" ),
+ new TextareaField("BlogPost", _t("BlogEntry.CN"),20), // This is called BlogPost as the id #Content is generally used already
+ new LiteralField("BBCodeTags","
".$codeparser->useable_tagsHTML()."
")
+ );
+ }
+ if(class_exists('TagField')) {
+ $tagfield = new TagField('Tags', null, null, 'BlogEntry');
+ $tagfield->setSeparator(', ');
+ } else {
+ $tagfield = new TextField('Tags');
+ }
+
+ $field = 'TextField';
+ if(!$this->AllowCustomAuthors && !Permission::check('ADMIN')) {
+ $field = 'ReadonlyField';
+ }
+ $fields = new FieldSet(
+ new HiddenField("ID", "ID"),
+ new TextField("Title", _t('BlogHolder.SJ', "Subject")),
+ new $field("Author", _t('BlogEntry.AU'), $membername),
+ $contentfield,
+ $tagfield,
+ new LiteralField("Tagsnote"," ")
+ );
+
+ $submitAction = new FormAction('postblog', _t('BlogHolder.POST', 'Post blog entry'));
+ $actions = new FieldSet($submitAction);
+ $validator = new RequiredFields('Title','Content');
+
+ $form = new Form($this, 'BlogEntryForm',$fields, $actions,$validator);
+
+ if($id != 0) {
+ $entry = DataObject::get_by_id('BlogEntry', $id);
+ if($entry->IsOwner()) {
+ $form->loadDataFrom($entry);
+ $form->datafieldByName('BlogPost')->setValue($entry->Content);
+ }
+ } else {
+ $form->loadDataFrom(array("Author" => Cookie::get("BlogHolder_Name")));
+ }
+
+ return $form;
+ }
+
+ function postblog($data, $form) {
+ if(!Permission::check('BLOGMANAGEMENT')) return Security::permissionFailure();
+
+ Cookie::set("BlogHolder_Name", $data['Author']);
+ $blogentry = false;
+
+ if(isset($data['ID']) && $data['ID']) {
+ $blogentry = DataObject::get_by_id("BlogEntry", $data['ID']);
+ if(!$blogentry->IsOwner()) {
+ unset($blogentry);
+ }
+ }
+
+ if(!$blogentry) {
+ $blogentry = new BlogEntry();
+ }
+
+ $form->saveInto($blogentry);
+ $blogentry->ParentID = $this->ID;
+ $blogentry->Content = $form->datafieldByName('BlogPost')->dataValue();
+
+ $blogentry->Status = "Published";
+ $blogentry->writeToStage("Stage");
+ $blogentry->publish("Stage", "Live");
+
+ Director::redirect($this->Link());
+ }
}
diff --git a/code/BlogTree.php b/code/BlogTree.php
index 18ca075..caa5e36 100644
--- a/code/BlogTree.php
+++ b/code/BlogTree.php
@@ -210,8 +210,7 @@ class BlogTree_Controller extends Page_Controller {
static $allowed_actions = array(
'index',
'rss',
- 'post',
- 'BlogEntryForm'
+ 'tag'
);
function init() {
@@ -250,7 +249,7 @@ class BlogTree_Controller extends Page_Controller {
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
$date = $this->SelectedDate();
-
+
return $this->Entries("$start,$limit", $this->SelectedTag(), ($date) ? $date->Format('Y-m') : '', null, $filter);
}
@@ -316,121 +315,4 @@ class BlogTree_Controller extends Page_Controller {
return false;
}
-
- function providePermissions() {
- return array("BLOGMANAGEMENT" => "Blog management");
- }
-
- /**
- * Post a new blog entry
- */
- function post(){
- if(!Permission::check('BLOGMANAGEMENT')) return Security::permissionFailure();
- $page = $this->customise(array(
- 'Content' => false,
- 'Form' => $this->BlogEntryForm()
- ));
-
- return $page->renderWith('Page');
- }
-
- /**
- * A simple form for creating blog entries
- */
- function BlogEntryForm() {
- if(!Permission::check('BLOGMANAGEMENT')) return Security::permissionFailure();
-
-
- $id = 0;
- if($this->request->latestParam('ID')) {
- $id = (int) $this->request->latestParam('ID');
- }
-
- $codeparser = new BBCodeParser();
- $membername = Member::currentMember() ? Member::currentMember()->getName() : "";
-
- if(BlogEntry::$allow_wysiwyg_editing) {
- $contentfield = new HtmlEditorField("BlogPost", _t("BlogEntry.CN"));
- } else {
- $contentfield = new CompositeField(
- new LiteralField("BBCodeHelper",""._t("BlogEntry.BBH")."" ),
- new TextareaField("BlogPost", _t("BlogEntry.CN"),20), // This is called BlogPost as the id #Content is generally used already
- new LiteralField("BBCodeTags","