2007-09-17 12:14:28 +02:00
|
|
|
<?php
|
2007-11-14 02:15:40 +01:00
|
|
|
/**
|
2008-12-10 08:01:06 +01:00
|
|
|
* An individual blog entry page type.
|
|
|
|
*
|
2007-11-14 02:15:40 +01:00
|
|
|
* @package blog
|
|
|
|
*/
|
2007-09-07 00:33:58 +02:00
|
|
|
class BlogEntry extends Page {
|
|
|
|
static $db = array(
|
2009-10-26 23:03:52 +01:00
|
|
|
"Date" => "Datetime",
|
2007-09-07 00:33:58 +02:00
|
|
|
"Author" => "Text",
|
2008-04-09 01:21:13 +02:00
|
|
|
"Tags" => "Text"
|
2007-09-07 00:33:58 +02:00
|
|
|
);
|
|
|
|
|
2010-05-26 00:10:46 +02:00
|
|
|
static $casting = array(
|
|
|
|
'ParagraphSummary' => 'HTMLText'
|
|
|
|
);
|
|
|
|
|
2009-11-30 09:18:56 +01:00
|
|
|
static $default_parent = 'BlogHolder';
|
|
|
|
|
|
|
|
static $can_be_root = false;
|
|
|
|
|
|
|
|
static $icon = "blog/images/blogpage";
|
|
|
|
|
2009-01-20 05:01:45 +01:00
|
|
|
static $has_one = array();
|
2008-11-25 05:24:51 +01:00
|
|
|
|
2009-01-20 05:01:45 +01:00
|
|
|
static $has_many = array();
|
2008-11-25 05:24:51 +01:00
|
|
|
|
2009-01-20 05:01:45 +01:00
|
|
|
static $many_many = array();
|
|
|
|
|
|
|
|
static $belongs_many_many = array();
|
2008-11-25 05:24:51 +01:00
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
static $defaults = array(
|
2008-12-16 05:25:35 +01:00
|
|
|
"ProvideComments" => true,
|
|
|
|
'ShowInMenus' => false
|
2007-09-07 00:33:58 +02:00
|
|
|
);
|
2008-09-12 04:09:13 +02:00
|
|
|
|
|
|
|
static $extensions = array(
|
2008-09-15 05:59:39 +02:00
|
|
|
'Hierarchy',
|
|
|
|
'TrackBackDecorator',
|
|
|
|
"Versioned('Stage', 'Live')"
|
2008-09-12 04:09:13 +02:00
|
|
|
);
|
2007-09-07 00:33:58 +02:00
|
|
|
|
2007-12-11 23:13:19 +01:00
|
|
|
/**
|
|
|
|
* Is WYSIWYG editing allowed?
|
2008-11-27 02:43:55 +01:00
|
|
|
* @var boolean
|
2007-12-11 23:13:19 +01:00
|
|
|
*/
|
2009-11-30 09:20:46 +01:00
|
|
|
static $allow_wysiwyg_editing = true;
|
2007-12-11 23:13:19 +01:00
|
|
|
|
2008-11-27 02:43:55 +01:00
|
|
|
/**
|
|
|
|
* Is WYSIWYG editing enabled?
|
|
|
|
* Used in templates.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function IsWYSIWYGEnabled() {
|
|
|
|
return self::$allow_wysiwyg_editing;
|
|
|
|
}
|
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
/**
|
2008-12-10 08:05:18 +01:00
|
|
|
* Overload so that the default date is today.
|
2007-09-07 00:33:58 +02:00
|
|
|
*/
|
|
|
|
public function populateDefaults(){
|
|
|
|
parent::populateDefaults();
|
2008-12-10 08:05:18 +01:00
|
|
|
|
2008-12-16 05:25:35 +01:00
|
|
|
$this->setField('Date', date('Y-m-d H:i:s', strtotime('now')));
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getCMSFields() {
|
|
|
|
Requirements::javascript('blog/javascript/bbcodehelp.js');
|
2008-12-10 08:05:18 +01:00
|
|
|
Requirements::themedCSS('bbcodehelp');
|
2008-11-06 01:35:10 +01:00
|
|
|
|
|
|
|
$firstName = Member::currentUser() ? Member::currentUser()->FirstName : '';
|
|
|
|
$codeparser = new BBCodeParser();
|
2009-10-06 05:13:00 +02:00
|
|
|
|
|
|
|
SiteTree::disableCMSFieldsExtensions();
|
2007-09-07 00:33:58 +02:00
|
|
|
$fields = parent::getCMSFields();
|
2009-10-06 05:13:00 +02:00
|
|
|
SiteTree::enableCMSFieldsExtensions();
|
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
|
|
|
}
|
|
|
|
|
2010-02-17 06:04:17 +01:00
|
|
|
$fields->addFieldToTab("Root.Content.Main", $dateField = new DatetimeField("Date", _t("BlogEntry.DT", "Date")),"Content");
|
|
|
|
$dateField->getDateField()->setConfig('showcalendar', true);
|
|
|
|
$dateField->getTimeField()->setConfig('showdropdown', true);
|
2007-12-18 02:41:51 +01:00
|
|
|
$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");
|
2009-09-25 01:10:54 +02:00
|
|
|
|
|
|
|
$this->extend('updateCMSFields', $fields);
|
|
|
|
|
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
|
|
|
|
*/
|
2008-07-20 09:45:55 +02:00
|
|
|
function TagsCollection() {
|
2008-12-10 08:05:18 +01:00
|
|
|
$tags = split(" *, *", trim($this->Tags));
|
2007-09-07 00:33:58 +02:00
|
|
|
$output = new DataObjectSet();
|
2008-12-10 08:05:18 +01:00
|
|
|
|
2010-02-13 00:47:43 +01:00
|
|
|
$link = $this->getParent() ? $this->getParent()->Link('tag') : '';
|
|
|
|
|
2008-12-10 08:05:18 +01:00
|
|
|
foreach($tags as $tag) {
|
2007-09-07 00:33:58 +02:00
|
|
|
$output->push(new ArrayData(array(
|
2008-12-10 08:05:18 +01:00
|
|
|
'Tag' => $tag,
|
2010-02-13 00:47:43 +01:00
|
|
|
'Link' => $link . '/' . urlencode($tag),
|
2008-12-18 06:26:43 +01:00
|
|
|
'URLTag' => urlencode($tag)
|
2007-09-07 00:33:58 +02:00
|
|
|
)));
|
|
|
|
}
|
2008-12-10 08:05:18 +01:00
|
|
|
|
|
|
|
if($this->Tags) {
|
2007-09-07 00:33:58 +02:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-14 02:15:40 +01:00
|
|
|
/**
|
2008-12-10 08:05:18 +01:00
|
|
|
* Get the sidebar from the BlogHolder.
|
2007-11-14 02:15:40 +01:00
|
|
|
*/
|
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');
|
2008-10-24 02:05:01 +02:00
|
|
|
$content->value = $parser->parse();
|
2008-12-10 08:05:18 +01:00
|
|
|
|
2007-12-11 23:13:19 +01:00
|
|
|
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
|
|
|
*/
|
2008-11-06 01:35:10 +01:00
|
|
|
function EditURL() {
|
2008-12-10 08:05:18 +01:00
|
|
|
return $this->getParent()->Link('post') . '/' . $this->ID . '/';
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
2008-12-16 23:35:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if trackbacks are enabled.
|
|
|
|
*/
|
|
|
|
function TrackBacksEnabled() {
|
|
|
|
return $this->getParent()->TrackBacksEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
function trackbackping() {
|
2009-07-28 07:33:22 +02:00
|
|
|
if($this->TrackBacksEnabled() && $this->hasExtension('TrackBackDecorator')) {
|
|
|
|
return $this->decoratedTrackbackping();
|
2008-12-16 23:35:32 +01:00
|
|
|
} else {
|
|
|
|
Director::redirect($this->Link());
|
|
|
|
}
|
|
|
|
}
|
2007-09-07 00:33:58 +02:00
|
|
|
|
2009-02-07 03:19:27 +01:00
|
|
|
function IsOwner() {
|
2009-07-01 06:24:42 +02:00
|
|
|
if(method_exists($this->Parent(), 'IsOwner')) {
|
|
|
|
return $this->Parent()->IsOwner();
|
|
|
|
}
|
2009-02-07 03:19:27 +01:00
|
|
|
}
|
2009-07-01 06:24:42 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2010-05-16 03:10:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the previous blog entry from this section of blog pages.
|
|
|
|
*
|
|
|
|
* @return BlogEntry
|
|
|
|
*/
|
|
|
|
function PreviousBlogEntry() {
|
|
|
|
return DataObject::get_one(
|
|
|
|
'BlogEntry',
|
|
|
|
"\"SiteTree\".\"ParentID\" = '$this->ParentID' AND \"BlogEntry\".\"Date\" < '$this->Date'",
|
|
|
|
true,
|
|
|
|
'Date DESC'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the next blog entry from this section of blog pages.
|
|
|
|
*
|
|
|
|
* @return BlogEntry
|
|
|
|
*/
|
|
|
|
function NextBlogEntry() {
|
|
|
|
return DataObject::get_one(
|
|
|
|
'BlogEntry',
|
|
|
|
"\"SiteTree\".\"ParentID\" = '$this->ParentID' AND \"BlogEntry\".\"Date\" > '$this->Date'",
|
|
|
|
true,
|
|
|
|
'Date ASC'
|
|
|
|
);
|
|
|
|
}
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class BlogEntry_Controller extends Page_Controller {
|
2010-05-16 03:10:24 +02:00
|
|
|
|
2008-12-16 05:29:34 +01:00
|
|
|
static $allowed_actions = array(
|
2009-09-10 08:08:22 +02:00
|
|
|
'index',
|
2008-12-16 05:29:34 +01:00
|
|
|
'trackbackping',
|
2008-12-16 21:37:14 +01:00
|
|
|
'unpublishPost',
|
2009-01-12 23:27:05 +01:00
|
|
|
'PageComments',
|
|
|
|
'SearchForm'
|
2008-12-16 05:29:34 +01:00
|
|
|
);
|
2008-12-10 08:05:18 +01:00
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
function init() {
|
|
|
|
parent::init();
|
2008-12-10 08:05:18 +01:00
|
|
|
|
|
|
|
Requirements::themedCSS('blog');
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
|
|
|
|
2007-11-14 02:15:40 +01:00
|
|
|
/**
|
|
|
|
* Gets a link to unpublish the blog entry
|
|
|
|
*/
|
2008-12-10 08:01:06 +01:00
|
|
|
function unpublishPost() {
|
2009-02-07 03:19:27 +01:00
|
|
|
if(!$this->IsOwner()) {
|
2008-12-10 08:01:06 +01:00
|
|
|
Security::permissionFailure(
|
|
|
|
$this,
|
|
|
|
'Unpublishing blogs is an administrator task. Please log in.'
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$SQL_id = (int) $this->ID;
|
2007-09-07 00:33:58 +02:00
|
|
|
|
2008-12-10 08:01:06 +01:00
|
|
|
$page = DataObject::get_by_id('SiteTree', $SQL_id);
|
2007-09-07 00:33:58 +02:00
|
|
|
$page->deleteFromStage('Live');
|
|
|
|
$page->flushCache();
|
|
|
|
|
2008-12-10 08:01:06 +01:00
|
|
|
$page = DataObject::get_by_id('SiteTree', $SQL_id);
|
|
|
|
$page->Status = 'Unpublished';
|
2007-09-07 00:33:58 +02:00
|
|
|
|
|
|
|
Director::redirect($this->getParent()->Link());
|
|
|
|
}
|
|
|
|
}
|
2007-12-20 03:23:20 +01:00
|
|
|
|
2007-09-07 00:33:58 +02:00
|
|
|
}
|
2008-12-16 05:25:35 +01:00
|
|
|
?>
|