From e3a21012fbcddd3df97d97d4e5f3f0b32ab48d75 Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Tue, 16 Dec 2008 04:25:35 +0000 Subject: [PATCH] BUGFIX: Fix not being able to post from frontend, change posting code to be more SilverStripey --- code/ArchiveWidget.php | 2 +- code/BlogEntry.php | 24 +---- code/BlogHolder.php | 147 ++++++++++++++-------------- templates/Layout/BlogHolder_post.ss | 9 -- 4 files changed, 81 insertions(+), 101 deletions(-) delete mode 100644 templates/Layout/BlogHolder_post.ss diff --git a/code/ArchiveWidget.php b/code/ArchiveWidget.php index be17cac..f5cb756 100644 --- a/code/ArchiveWidget.php +++ b/code/ArchiveWidget.php @@ -85,4 +85,4 @@ class ArchiveWidget extends Widget { return $results; } } -?> \ No newline at end of file +?> diff --git a/code/BlogEntry.php b/code/BlogEntry.php index bdc9b53..d7254d4 100644 --- a/code/BlogEntry.php +++ b/code/BlogEntry.php @@ -27,12 +27,9 @@ class BlogEntry extends Page { static $many_many = array( ); - static $casting = array( - "Date" => "Date" - ); - static $defaults = array( - "ProvideComments" => true + "ProvideComments" => true, + 'ShowInMenus' => false ); static $extensions = array( @@ -63,20 +60,9 @@ class BlogEntry extends Page { public function populateDefaults(){ parent::populateDefaults(); - $this->Date = date('Y-m-d H:i:s', time()); + $this->setField('Date', date('Y-m-d H:i:s', strtotime('now'))); } - /** - * Ensures the most recent article edited on the same day is shown first. - */ - public function setDate($val) { - $datepart = date('Y-m-d', strtotime($val)); - $minutepart = date('H:i:s', time()); - $date = $datepart . " " . $minutepart; - - return $this->setField('Date', $date); - } - function getCMSFields() { Requirements::javascript('blog/javascript/bbcodehelp.js'); Requirements::themedCSS('bbcodehelp'); @@ -91,7 +77,7 @@ class BlogEntry extends Page { $fields->addFieldToTab("Root.Content.Main", new TextareaField("Content", _t("BlogEntry.CN", "Content"), 20)); } - $fields->addFieldToTab("Root.Content.Main", new CalendarDateField("Date", _t("BlogEntry.DT", "Date")),"Content"); + $fields->addFieldToTab("Root.Content.Main", new PopupDateTimeField("Date", _t("BlogEntry.DT", "Date")),"Content"); $fields->addFieldToTab("Root.Content.Main", new TextField("Author", _t("BlogEntry.AU", "Author"), $firstName),"Content"); if(!self::$allow_wysiwyg_editing) { @@ -207,4 +193,4 @@ class BlogEntry_Controller extends Page_Controller { } } -?> \ No newline at end of file +?> diff --git a/code/BlogHolder.php b/code/BlogHolder.php index 837a46a..beb6b43 100644 --- a/code/BlogHolder.php +++ b/code/BlogHolder.php @@ -92,7 +92,7 @@ class BlogHolder extends Page { } } - return DataObject::get("Page","`ParentID` = $this->ID AND ShowInMenus = 1 $tagCheck $dateCheck","`BlogEntry`.Date DESC",'',"$limit"); + return DataObject::get("Page","`ParentID` = $this->ID $tagCheck $dateCheck","`BlogEntry`.Date DESC",'',"$limit"); } /** @@ -104,55 +104,6 @@ class BlogHolder extends Page { } } - /** - * A simple form for creating blog entries - */ - function BlogEntryForm() { - Requirements::javascript('jsparty/behaviour.js'); - Requirements::javascript('jsparty/prototype.js'); - Requirements::javascript('jsparty/scriptaculous/effects.js'); - Requirements::javascript('cms/javascript/PageCommentInterface.js'); - Requirements::javascript('blog/javascript/bbcodehelp.js'); - - $id = 0; - if(Director::urlParam('ID')) { - $id = (int) Director::urlParam('ID'); - } - - $codeparser = new BBCodeParser(); - $membername = Member::currentMember() ? Member::currentMember()->getName() : ""; - - $fields = new FieldSet( - new HiddenField("ParentID", "ParentID", $this->ID), - new HiddenField("ID","ID"), - new HiddenField("Date","Date"), - new TextField("Title",_t('BlogHolder.SJ', "Subject")), - new TextField("Author",_t('BlogEntry.AU'),$membername), - new CompositeField( - new LiteralField("BBCodeHelper",""._t("BlogEntry.BBH")."
" ), - new TextareaField("Content", _t("BlogEntry.CN"),20), - new LiteralField("BBCodeTags","
".$codeparser->useable_tagsHTML()."
") - ), - new TextField("Tags","Tags"), - new LiteralField("Tagsnote"," ") - ); - - $submitAction = new FormAction('postblog', _t('BlogHolder.POST', 'Post blog entry')); - $actions = new FieldSet($submitAction); - $validator = new RequiredFields('Title','Content'); - - $form = new BlogEntry_Form($this, 'BlogEntryForm',$fields, $actions,$validator); - - if($id != 0) { - $form->loadNonBlankDataFrom(DataObject::get_by_id('BlogEntry', $id)); - } else { - $form->loadNonBlankDataFrom(array("Author" => Cookie::get("BlogHolder_Name"))); - } - - return $form; - } - /** * Check if url has "/post" */ @@ -308,10 +259,15 @@ class BlogHolder_Controller extends Page_Controller { */ function post(){ if(!Permission::check('ADMIN')){ - Security::permissionFailure($this, - _t('BlogHolder.HAVENTPERM',"Posting blogs is an administrator task. Please log in.")); + Security::permissionFailure($this, _t('BlogHolder.HAVENTPERM', 'Posting blogs is an administrator task. Please log in.')); } - return array(); + + $page = $this->customise(array( + 'Content' => false, + 'Form' => $this->BlogEntryForm() + )); + + return $page->renderWith('Page'); } function defaultAction($action) { @@ -322,32 +278,79 @@ class BlogHolder_Controller extends Page_Controller { return parent::defaultAction($action); } -} - -/** - * Blog entry form - */ -class BlogEntry_Form extends Form { - function postblog($data) { - Cookie::set("BlogHolder_Name", $data['Author']); - $blogentry = new BlogEntry(); - $this->saveInto($blogentry); - - if($data['ID'] != 0){ //new post - $blogentry = DataObject::get_by_id("BlogEntry",$data['ID']); - $this->saveInto($blogentry); - $blogentry->setDate($data['Date']); - }else{ - $blogentry->setDate(date("Y-m-d H:i:s",time())); + + /** + * A simple form for creating blog entries + */ + function BlogEntryForm() { + Requirements::javascript('jsparty/behaviour.js'); + Requirements::javascript('jsparty/prototype.js'); + Requirements::javascript('jsparty/scriptaculous/effects.js'); + Requirements::javascript('cms/javascript/PageCommentInterface.js'); + Requirements::javascript('blog/javascript/bbcodehelp.js'); + + $id = 0; + if(Director::urlParam('ID')) { + $id = (int) Director::urlParam('ID'); } + $codeparser = new BBCodeParser(); + $membername = Member::currentMember() ? Member::currentMember()->getName() : ""; + + $fields = new FieldSet( + new HiddenField("ID", "ID"), + new TextField("Title",_t('BlogHolder.SJ', "Subject")), + new TextField("Author",_t('BlogEntry.AU'),$membername), + 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()."
") + ), + new TextField("Tags","Tags"), + 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); + $form->loadNonBlankDataFrom($entry); + $form->datafieldByName('BlogPost')->setValue($entry->Content); + } else { + $form->loadNonBlankDataFrom(array("Author" => Cookie::get("BlogHolder_Name"))); + } + + return $form; + } + + function postblog($data, $form) { + Cookie::set("BlogHolder_Name", $data['Author']); + $blogentry = false; + + if($data['ID']) { + $blogentry = DataObject::get_by_id("BlogEntry", $data['ID']); + } + + 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->controller->Link()); + Director::redirect($this->Link()); } } + ?> diff --git a/templates/Layout/BlogHolder_post.ss b/templates/Layout/BlogHolder_post.ss deleted file mode 100644 index 09961da..0000000 --- a/templates/Layout/BlogHolder_post.ss +++ /dev/null @@ -1,9 +0,0 @@ -<% include BlogSideBar %> - -
- <% include BreadCrumbs %> - - <% if isPost %> - $BlogEntryForm - <% end_if %> -
\ No newline at end of file