2007-09-17 12:14:28 +02:00
|
|
|
<?php
|
2007-09-07 00:33:58 +02:00
|
|
|
|
2007-11-14 02:15:40 +01:00
|
|
|
/**
|
|
|
|
* @package blog
|
|
|
|
*/
|
2007-12-18 02:41:51 +01:00
|
|
|
|
2007-11-14 02:15:40 +01:00
|
|
|
/**
|
|
|
|
* An individual blog entry page to show a blog entry in full
|
|
|
|
*/
|
2007-09-07 00:33:58 +02:00
|
|
|
class BlogEntry extends Page {
|
|
|
|
|
|
|
|
static $default_parent = array('BlogHolder');
|
|
|
|
|
|
|
|
static $can_be_root = false;
|
|
|
|
|
|
|
|
static $icon = "blog/images/blogpage";
|
|
|
|
|
|
|
|
static $db = array(
|
|
|
|
"Date" => "Datetime",
|
|
|
|
"Author" => "Text",
|
|
|
|
"Tags" => "Text"
|
|
|
|
);
|
|
|
|
|
|
|
|
static $casting = array(
|
|
|
|
"Date" => "Date"
|
|
|
|
);
|
|
|
|
|
|
|
|
static $defaults = array(
|
|
|
|
"ProvideComments" => true
|
|
|
|
);
|
|
|
|
|
|
|
|
static $allowed_children = "none";
|
2007-12-11 23:13:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is WYSIWYG editing allowed?
|
|
|
|
*/
|
|
|
|
static $allow_wysiwyg_editing = false;
|
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
/**
|
|
|
|
* overload so that the default date is today.
|
|
|
|
*/
|
|
|
|
public function populateDefaults(){
|
|
|
|
parent::populateDefaults();
|
|
|
|
$this->Date = date("d/m/Y H:i:s",time());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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::css('blog/css/bbcodehelp.css');
|
|
|
|
$firstName = Member::CurrentMember() ? Member::currentMember()->FirstName : '';
|
|
|
|
$codeparser = new BBCodeParser();
|
|
|
|
|
|
|
|
$fields = parent::getCMSFields();
|
2007-12-11 23:13:19 +01:00
|
|
|
|
|
|
|
if(!self::$allow_wysiwyg_editing) {
|
|
|
|
$fields->removeFieldFromTab("Root.Content.Main","Content");
|
2007-12-18 02:41:51 +01:00
|
|
|
$fields->addFieldToTab("Root.Content.Main", new TextareaField("Content", _t("BlogEntry.CN", "Content"), 20));
|
2007-12-11 23:13:19 +01:00
|
|
|
}
|
|
|
|
|
2007-12-18 02:41:51 +01:00
|
|
|
$fields->addFieldToTab("Root.Content.Main", new CalendarDateField("Date", _t("BlogEntry.DT", "Date")),"Content");
|
|
|
|
$fields->addFieldToTab("Root.Content.Main", new TextField("Author", _t("BlogEntry.AU", "Author"), $firstName),"Content");
|
2007-09-07 00:33:58 +02:00
|
|
|
|
2007-12-11 23:13:19 +01:00
|
|
|
if(!self::$allow_wysiwyg_editing) {
|
|
|
|
$fields->addFieldToTab("Root.Content.Main", new LiteralField("BBCodeHelper", "<div id='BBCode' class='field'>" .
|
2008-01-06 23:48:49 +01:00
|
|
|
"<a id=\"BBCodeHint\" target='new'>" . _t("BlogEntry.BBH", "BBCode help") . "</a>" .
|
2007-12-11 23:13:19 +01:00
|
|
|
"<div id='BBTagsHolder' style='display:none;'>".$codeparser->useable_tagsHTML()."</div></div>"));
|
|
|
|
}
|
2007-09-07 00:33:58 +02:00
|
|
|
|
2007-12-18 02:41:51 +01:00
|
|
|
$fields->addFieldToTab("Root.Content.Main", new TextField("Tags", _t("BlogEntry.TS", "Tags (comma sep.)")),"Content");
|
2007-09-07 00:33:58 +02:00
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
2007-11-14 02:15:40 +01:00
|
|
|
/**
|
|
|
|
* Returns the tags added to this blog entry
|
|
|
|
*/
|
2007-09-07 00:33:58 +02:00
|
|
|
function Tags() {
|
|
|
|
$theseTags = split(" *, *", trim($this->Tags));
|
|
|
|
|
|
|
|
$output = new DataObjectSet();
|
|
|
|
foreach($theseTags as $tag) {
|
|
|
|
$output->push(new ArrayData(array(
|
|
|
|
"Tag" => $tag,
|
2007-11-23 09:35:49 +01:00
|
|
|
"Link" => $this->getParent()->Link() . 'tag/' . urlencode($tag)
|
2007-09-07 00:33:58 +02:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
if($this->Tags){
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-14 02:15:40 +01:00
|
|
|
/**
|
|
|
|
* Get the sidebar
|
|
|
|
*/
|
2007-09-07 00:33:58 +02:00
|
|
|
function SideBar() {
|
|
|
|
return $this->getParent()->SideBar();
|
|
|
|
}
|
|
|
|
|
2007-11-14 02:15:40 +01:00
|
|
|
/**
|
|
|
|
* Get a bbcode parsed summary of the blog entry
|
|
|
|
*/
|
2007-09-07 00:33:58 +02:00
|
|
|
function ParagraphSummary(){
|
2007-12-11 23:13:19 +01:00
|
|
|
if(self::$allow_wysiwyg_editing) {
|
|
|
|
return $this->obj('Content')->FirstParagraph();
|
|
|
|
} else {
|
|
|
|
$content = new Text('Content');
|
2007-12-18 04:21:47 +01:00
|
|
|
$content->value = $this->Content;
|
2007-12-11 23:13:19 +01:00
|
|
|
$parser = new BBCodeParser($content->FirstParagraph());
|
|
|
|
return $parser->parse();
|
|
|
|
}
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
|
|
|
|
2007-11-14 02:15:40 +01:00
|
|
|
/**
|
|
|
|
* Get the bbcode parsed content
|
|
|
|
*/
|
2007-09-07 00:33:58 +02:00
|
|
|
function ParsedContent() {
|
2007-12-11 23:13:19 +01:00
|
|
|
if(self::$allow_wysiwyg_editing) {
|
|
|
|
return $this->Content;
|
|
|
|
} else {
|
|
|
|
$parser = new BBCodeParser($this->Content);
|
|
|
|
$content = new Text('Content');
|
|
|
|
$content->value =$parser->parse();
|
|
|
|
return $content;
|
|
|
|
}
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
|
|
|
|
2007-11-14 02:15:40 +01:00
|
|
|
/**
|
2007-12-18 02:41:51 +01:00
|
|
|
* Link for editing this blog entry
|
2007-11-14 02:15:40 +01:00
|
|
|
*/
|
2007-09-07 00:33:58 +02:00
|
|
|
function EditURL(){
|
|
|
|
return $this->getParent()->Link('post')."/".$this->ID."/";
|
|
|
|
}
|
|
|
|
|
2007-12-20 03:23:20 +01:00
|
|
|
/**
|
|
|
|
* Return the NewsletterSignupForm from the parent (BlogHolder).
|
|
|
|
*/
|
|
|
|
function NewsletterSignupForm() {
|
|
|
|
if(isset($this->Parent->ID) && $this->Parent->NewsletterSignupForm()) {
|
|
|
|
return $this->Parent->NewsletterSignupForm();
|
|
|
|
}
|
|
|
|
}
|
2007-12-11 23:13:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class BlogEntry_Controller extends Page_Controller {
|
|
|
|
function init() {
|
|
|
|
parent::init();
|
|
|
|
Requirements::themedCSS("blog");
|
|
|
|
}
|
|
|
|
|
2007-11-14 02:15:40 +01:00
|
|
|
/**
|
|
|
|
* Gets a link to unpublish the blog entry
|
|
|
|
*/
|
2007-09-07 00:33:58 +02:00
|
|
|
function unpublishPost(){
|
|
|
|
if(!Permission::check('ADMIN')){
|
|
|
|
Security::permissionFailure($this,
|
|
|
|
"Unpublishing blogs is an administrator task. Please log in.");
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$SQL_id = Convert::raw2sql($this->ID);
|
|
|
|
|
|
|
|
$page = DataObject::get_by_id("SiteTree", $SQL_id);
|
|
|
|
$page->deleteFromStage('Live');
|
|
|
|
$page->flushCache();
|
|
|
|
|
|
|
|
$page = DataObject::get_by_id("SiteTree", $SQL_id);
|
|
|
|
$page->Status = "Unpublished";
|
|
|
|
|
|
|
|
Director::redirect($this->getParent()->Link());
|
|
|
|
}
|
|
|
|
}
|
2007-12-20 03:23:20 +01:00
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
|
|
|
|
2007-11-23 09:35:49 +01:00
|
|
|
?>
|