mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
ENHANCEMENT: create a template function, BlogEntry::Content(), for consistency of template writing and enable using text summary functionalities in template
This commit is contained in:
parent
1f706f6e73
commit
8b4b0f9ac6
@ -11,10 +11,6 @@ class BlogEntry extends Page {
|
|||||||
"Tags" => "Text"
|
"Tags" => "Text"
|
||||||
);
|
);
|
||||||
|
|
||||||
static $casting = array(
|
|
||||||
'ParagraphSummary' => 'HTMLText'
|
|
||||||
);
|
|
||||||
|
|
||||||
static $default_parent = 'BlogHolder';
|
static $default_parent = 'BlogHolder';
|
||||||
|
|
||||||
static $can_be_root = false;
|
static $can_be_root = false;
|
||||||
@ -46,16 +42,6 @@ class BlogEntry extends Page {
|
|||||||
*/
|
*/
|
||||||
static $allow_wysiwyg_editing = true;
|
static $allow_wysiwyg_editing = true;
|
||||||
|
|
||||||
/**
|
|
||||||
* Is WYSIWYG editing enabled?
|
|
||||||
* Used in templates.
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function IsWYSIWYGEnabled() {
|
|
||||||
return self::$allow_wysiwyg_editing;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overload so that the default date is today.
|
* Overload so that the default date is today.
|
||||||
*/
|
*/
|
||||||
@ -128,33 +114,49 @@ class BlogEntry extends Page {
|
|||||||
return $this->getParent()->SideBar();
|
return $this->getParent()->SideBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function Content() {
|
||||||
* Get a bbcode parsed summary of the blog entry
|
|
||||||
*/
|
|
||||||
function ParagraphSummary(){
|
|
||||||
if(self::$allow_wysiwyg_editing) {
|
if(self::$allow_wysiwyg_editing) {
|
||||||
return $this->obj('Content')->FirstParagraph('html');
|
return $this->getField('Content');
|
||||||
} else {
|
} else {
|
||||||
$parser = new BBCodeParser($this->Content);
|
$parser = new BBCodeParser($this->Content);
|
||||||
$html = new HTMLText('Content');
|
$content = new HTMLText('Content');
|
||||||
$html->setValue($parser->parse());
|
$content->value = $parser->parse();
|
||||||
return $html->FirstParagraph('html');
|
return $content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To be used by RSSFeed. If RSSFeed uses Content field, it doesn't pull in correctly parsed content.
|
||||||
|
*/
|
||||||
|
function RSSContent() {
|
||||||
|
return $this->Content();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a bbcode parsed summary of the blog entry
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
function ParagraphSummary(){
|
||||||
|
user_error("BlogEntry::ParagraphSummary() is deprecated; use BlogEntry::Content()", E_USER_NOTICE);
|
||||||
|
|
||||||
|
$val = $this->Content();
|
||||||
|
$content = $val;
|
||||||
|
|
||||||
|
if(!($content instanceof HTMLText)) {
|
||||||
|
$content = new HTMLText('Content');
|
||||||
|
$content->value = $val;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content->FirstParagraph('html');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the bbcode parsed content
|
* Get the bbcode parsed content
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
function ParsedContent() {
|
function ParsedContent() {
|
||||||
if(self::$allow_wysiwyg_editing) {
|
user_error("BlogEntry::ParsedContent() is deprecated; use BlogEntry::Content()", E_USER_NOTICE);
|
||||||
return $this->obj('Content');
|
return $this->Content();
|
||||||
} else {
|
|
||||||
$parser = new BBCodeParser($this->Content);
|
|
||||||
$content = new Text('Content');
|
|
||||||
$content->value = $parser->parse();
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -277,7 +277,7 @@ class BlogTree_Controller extends Page_Controller {
|
|||||||
$entries = $this->Entries(20);
|
$entries = $this->Entries(20);
|
||||||
|
|
||||||
if($entries) {
|
if($entries) {
|
||||||
$rss = new RSSFeed($entries, $this->Link(), ($blogName ? $blogName : $altBlogName), "", "Title", "ParsedContent");
|
$rss = new RSSFeed($entries, $this->Link(), ($blogName ? $blogName : $altBlogName), "", "Title", "RSSContent");
|
||||||
$rss->outputToBrowser();
|
$rss->outputToBrowser();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
<% end_control %>
|
<% end_control %>
|
||||||
</p>
|
</p>
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
$ParagraphSummary
|
|
||||||
|
<p>$Content.FirstParagraph(html)</p>
|
||||||
|
|
||||||
<p class="blogVitals"><a href="$Link#PageComments_holder" class="comments" title="View Comments for this post">$Comments.Count comments</a> | <a href="$Link" class="readmore" title="Read Full Post">Read the full post</a></p>
|
<p class="blogVitals"><a href="$Link#PageComments_holder" class="comments" title="View Comments for this post">$Comments.Count comments</a> | <a href="$Link" class="readmore" title="Read Full Post">Read the full post</a></p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -13,12 +13,9 @@
|
|||||||
<% end_control %>
|
<% end_control %>
|
||||||
</p>
|
</p>
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
<% if IsWYSIWYGEnabled %>
|
|
||||||
$Content
|
$Content
|
||||||
<% else %>
|
|
||||||
$ParsedContent
|
|
||||||
<% end_if %>
|
|
||||||
<br />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if IsOwner %><p><a href="$EditURL" id="editpost" title="<% _t('EDITTHIS', 'Edit this post') %>"><% _t('EDITTHIS', 'Edit this post') %></a> | <a href="$Link(unpublishPost)" id="unpublishpost"><% _t('UNPUBLISHTHIS', 'Unpublish this post') %></a></p><% end_if %>
|
<% if IsOwner %><p><a href="$EditURL" id="editpost" title="<% _t('EDITTHIS', 'Edit this post') %>"><% _t('EDITTHIS', 'Edit this post') %></a> | <a href="$Link(unpublishPost)" id="unpublishpost"><% _t('UNPUBLISHTHIS', 'Unpublish this post') %></a></p><% end_if %>
|
||||||
|
26
tests/BlogEntryTest.php
Normal file
26
tests/BlogEntryTest.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
class BlogEntryTest extends SapphireTest {
|
||||||
|
static $fixture_file = 'blog/tests/BlogTest.yml';
|
||||||
|
|
||||||
|
function testBBCodeContent() {
|
||||||
|
$tmpFlag = BlogEntry::$allow_wysiwyg_editing;
|
||||||
|
BlogEntry::$allow_wysiwyg_editing = false;
|
||||||
|
|
||||||
|
$entry = $this->objFromFixture('BlogEntry', 'testpost');
|
||||||
|
$entry->Content = "[url=admin]the CMS[/url]";
|
||||||
|
|
||||||
|
$this->assertEquals('<p><a href="admin">the CMS</a></p>', $entry->Content()->value);
|
||||||
|
BlogEntry::$allow_wysiwyg_editing = $tmpFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
function testContent() {
|
||||||
|
$tmpFlag = BlogEntry::$allow_wysiwyg_editing;
|
||||||
|
BlogEntry::$allow_wysiwyg_editing = true;
|
||||||
|
|
||||||
|
$entry = $this->objFromFixture('BlogEntry', 'testpost');
|
||||||
|
$entry->Content = '<a href="admin">the CMS</a>';
|
||||||
|
|
||||||
|
$this->assertEquals('<a href="admin">the CMS</a>', $entry->Content());
|
||||||
|
BlogEntry::$allow_wysiwyg_editing = $tmpFlag;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user