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:
Saophalkun Ponlu 2010-06-17 23:19:56 +00:00
parent 1f706f6e73
commit 8b4b0f9ac6
5 changed files with 66 additions and 39 deletions

View File

@ -11,10 +11,6 @@ class BlogEntry extends Page {
"Tags" => "Text"
);
static $casting = array(
'ParagraphSummary' => 'HTMLText'
);
static $default_parent = 'BlogHolder';
static $can_be_root = false;
@ -46,16 +42,6 @@ class BlogEntry extends Page {
*/
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.
*/
@ -128,33 +114,49 @@ class BlogEntry extends Page {
return $this->getParent()->SideBar();
}
/**
* Get a bbcode parsed summary of the blog entry
*/
function ParagraphSummary(){
function Content() {
if(self::$allow_wysiwyg_editing) {
return $this->obj('Content')->FirstParagraph('html');
return $this->getField('Content');
} else {
$parser = new BBCodeParser($this->Content);
$html = new HTMLText('Content');
$html->setValue($parser->parse());
return $html->FirstParagraph('html');
$content = new HTMLText('Content');
$content->value = $parser->parse();
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
* @deprecated
*/
function ParsedContent() {
if(self::$allow_wysiwyg_editing) {
return $this->obj('Content');
} else {
$parser = new BBCodeParser($this->Content);
$content = new Text('Content');
$content->value = $parser->parse();
return $content;
}
user_error("BlogEntry::ParsedContent() is deprecated; use BlogEntry::Content()", E_USER_NOTICE);
return $this->Content();
}
/**

View File

@ -277,7 +277,7 @@ class BlogTree_Controller extends Page_Controller {
$entries = $this->Entries(20);
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();
}
}

View File

@ -9,6 +9,8 @@
<% end_control %>
</p>
<% 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>
</div>

View File

@ -13,12 +13,9 @@
<% end_control %>
</p>
<% end_if %>
<% if IsWYSIWYGEnabled %>
$Content
<% else %>
$ParsedContent
<% end_if %>
<br />
$Content
</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 %>

26
tests/BlogEntryTest.php Normal file
View 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;
}
}