mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
BUGFIX: Fix not being able to post from frontend, change posting code to be more SilverStripey
This commit is contained in:
parent
968b9ff467
commit
e3a21012fb
@ -85,4 +85,4 @@ class ArchiveWidget extends Widget {
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
@ -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 {
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
@ -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","<a id=\"BBCodeHint\" target='new'>"._t("BlogEntry.BBH")."</a><div class='clear'><!-- --></div>" ),
|
||||
new TextareaField("Content", _t("BlogEntry.CN"),20),
|
||||
new LiteralField("BBCodeTags","<div id=\"BBTagsHolder\">".$codeparser->useable_tagsHTML()."</div>")
|
||||
),
|
||||
new TextField("Tags","Tags"),
|
||||
new LiteralField("Tagsnote"," <label id='tagsnote'>"._t('BlogHolder.TE', "For example: sport, personal, science fiction")."<br/>" .
|
||||
_t('BlogHolder.SPUC', "Please separate tags using commas.")."</label>")
|
||||
);
|
||||
|
||||
$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","<a id=\"BBCodeHint\" target='new'>"._t("BlogEntry.BBH")."</a><div class='clear'><!-- --></div>" ),
|
||||
new TextareaField("BlogPost", _t("BlogEntry.CN"),20), // This is called BlogPost as the id #Content is generally used already
|
||||
new LiteralField("BBCodeTags","<div id=\"BBTagsHolder\">".$codeparser->useable_tagsHTML()."</div>")
|
||||
),
|
||||
new TextField("Tags","Tags"),
|
||||
new LiteralField("Tagsnote"," <label id='tagsnote'>"._t('BlogHolder.TE', "For example: sport, personal, science fiction")."<br/>" .
|
||||
_t('BlogHolder.SPUC', "Please separate tags using commas.")."</label>")
|
||||
);
|
||||
|
||||
$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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
@ -1,9 +0,0 @@
|
||||
<% include BlogSideBar %>
|
||||
|
||||
<div id="BlogContent" class="blogcontent typography">
|
||||
<% include BreadCrumbs %>
|
||||
|
||||
<% if isPost %>
|
||||
$BlogEntryForm
|
||||
<% end_if %>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user