'Boolean', 'AllowCustomAuthors' => 'Boolean', ); static $has_one = array( 'Owner' => 'Member', ); static $allowed_children = array( 'BlogEntry' ); function getCMSFields() { SiteTree::disableCMSFieldsExtensions(); $fields = parent::getCMSFields(); SiteTree::enableCMSFieldsExtensions(); $fields->addFieldToTab('Root.Content.Main', new CheckboxField('TrackBacksEnabled', 'Enable TrackBacks')); $fields->addFieldToTab('Root.Content.Main', new DropdownField('OwnerID', 'Blog owner', DataObject::get('Member')->toDropDownMap('ID', 'Name', 'None'))); $fields->addFieldToTab('Root.Content.Main', new CheckboxField('AllowCustomAuthors', 'Allow non-admins to have a custom author field')); $this->extend('updateCMSFields', $fields); return $fields; } public function BlogHolderIDs() { return array( $this->ID ); } /* * @todo: These next few functions don't really belong in the model. Can we remove them? */ /** * Only display the blog entries that have the specified tag */ function ShowTag() { if(Director::urlParam('Action') == 'tag') { return Convert::raw2xml(Director::urlParam('ID')); } } /** * Check if url has "/post" */ function isPost() { return Director::urlParam('Action') == 'post'; } /** * Link for creating a new blog entry */ function postURL(){ return $this->Link('post'); } /** * Returns true if the current user is an admin, or is the owner of this blog * * @return Boolean */ function IsOwner() { return (Permission::check('BLOGMANAGEMENT') || Permission::check('ADMIN')); } /** * Create default blog setup */ function requireDefaultRecords() { parent::requireDefaultRecords(); $blogHolder = DataObject::get_one('BlogHolder'); //TODO: This does not check for whether this blogholder is an orphan or not if(!$blogHolder) { $blogholder = new BlogHolder(); $blogholder->Title = "Blog"; $blogholder->URLSegment = "blog"; $blogholder->Status = "Published"; $widgetarea = new WidgetArea(); $widgetarea->write(); $blogholder->SideBarID = $widgetarea->ID; $blogholder->write(); $blogholder->publish("Stage", "Live"); $managementwidget = new BlogManagementWidget(); $managementwidget->ParentID = $widgetarea->ID; $managementwidget->write(); $tagcloudwidget = new TagCloudWidget(); $tagcloudwidget->ParentID = $widgetarea->ID; $tagcloudwidget->write(); $archivewidget = new ArchiveWidget(); $archivewidget->ParentID = $widgetarea->ID; $archivewidget->write(); $widgetarea->write(); $blog = new BlogEntry(); $blog->Title = _t('BlogHolder.SUCTITLE', "SilverStripe blog module successfully installed"); $blog->URLSegment = 'sample-blog-entry'; $blog->Tags = _t('BlogHolder.SUCTAGS',"silverstripe, blog"); $blog->Content = _t('BlogHolder.SUCCONTENT',"
Congratulations, the SilverStripe blog module has been successfully installed. This blog entry can be safely deleted. You can configure aspects of your blog (such as the widgets displayed in the sidebar) in the CMS.
"); $blog->Status = "Published"; $blog->ParentID = $blogholder->ID; $blog->write(); $blog->publish("Stage", "Live"); DB::alteration_message("Blog page created","created"); } } } class BlogHolder_Controller extends BlogTree_Controller { static $allowed_actions = array( 'index', 'tag', 'date', 'metaweblog', 'postblog' => 'BLOGMANAGEMENT', 'post' => 'BLOGMANAGEMENT', 'BlogEntryForm' => 'BLOGMANAGEMENT', ); function init() { parent::init(); Requirements::themedCSS("bbcodehelp"); } /** * Return list of usable tags for help */ function BBTags() { return BBCodeParser::usable_tags(); } function providePermissions() { return array("BLOGMANAGEMENT" => "Blog management"); } /** * Post a new blog entry */ function post(){ if(!Permission::check('BLOGMANAGEMENT')) return Security::permissionFailure(); $page = $this->customise(array( 'Content' => false, 'Form' => $this->BlogEntryForm() )); return $page->renderWith('Page'); } /** * A simple form for creating blog entries */ function BlogEntryForm() { if(!Permission::check('BLOGMANAGEMENT')) return Security::permissionFailure(); 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() : ""; if(BlogEntry::$allow_wysiwyg_editing) { $contentfield = new HtmlEditorField("BlogPost", _t("BlogEntry.CN")); } else { $contentfield = 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","