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",
|
2008-04-09 01:21:13 +02:00
|
|
|
"Tags" => "Text"
|
2007-09-07 00:33:58 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
static $casting = array(
|
|
|
|
"Date" => "Date"
|
|
|
|
);
|
|
|
|
|
|
|
|
static $defaults = array(
|
2008-04-09 01:21:13 +02:00
|
|
|
"ProvideComments" => true
|
2007-09-07 00:33:58 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
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();
|
2008-01-14 03:19:53 +01:00
|
|
|
$this->Date = date("Y-m-d H:i:s",time());
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2008-01-22 04:44:44 +01:00
|
|
|
return $this->obj('Content')->FirstParagraph('html');
|
2007-12-11 23:13:19 +01:00
|
|
|
} else {
|
2008-01-22 04:44:44 +01:00
|
|
|
$parser = new BBCodeParser($this->Content);
|
|
|
|
$html = new HTMLText('Content');
|
|
|
|
$html->setValue($parser->parse());
|
|
|
|
return $html->FirstParagraph('html');
|
2007-12-11 23:13:19 +01:00
|
|
|
}
|
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) {
|
2008-01-07 20:40:36 +01:00
|
|
|
return $this->obj('Content');
|
2007-12-11 23:13:19 +01:00
|
|
|
} 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
|
|
|
?>
|