BUGFIX: Fixed template naming and variables for front end template.

This commit is contained in:
Will Rossiter 2010-11-30 22:49:21 +13:00
parent 15a0dbc087
commit b9970c1f94
9 changed files with 114 additions and 192 deletions

14
TODO.md Normal file
View File

@ -0,0 +1,14 @@
# TODO
* Permissions and configuration needs to be set on a per type of owner class rather than global
so we can support a blog with public comments and an ecommerce store with comments that you
have to login to post for instance
Commenting::enable_comments('SiteTree', array(
'requires_permission' => FOO,
'requires_login' => false
));
* Merge simon_w's jQuery work for page comments back in.
* Tests

View File

@ -18,51 +18,6 @@ class CommentInterface extends RequestHandler {
protected $controller, $methodName, $page;
/**
* If this is true, you must be logged in to post a comment
* (and therefore, you don't need to specify a 'Your name' field unless
* your name is blank)
*
* @var bool
*/
private static $comments_require_login = false;
/**
* If this is a valid permission code, you must be logged in
* and have the appropriate permission code on your account before you can
* post a comment.
*
* @var string
*/
private static $comments_require_permission = "";
/**
* If this is true it will include the javascript for AJAX
* commenting. If it is set to false then it will not load
* the files required and it will fall back
*
* @var bool
*/
private static $use_ajax_commenting = true;
/**
* If this is true then we should show the existing comments on
* the page even when we have disabled the comment form.
*
* If this is false the form + existing comments will be hidden
*
* @var bool
*/
private static $show_comments_when_disabled = true;
/**
* Define how you want to order page comments by. By default order by newest
* to oldest.
*
* @var String - used as $orderby in DB query
* @since 2.4
*/
static $order_comments_by = "\"Created\" DESC";
/**
* Create a new page comment interface
@ -81,77 +36,7 @@ class CommentInterface extends RequestHandler {
return Controller::join_links($this->controller->Link(), $this->methodName);
}
/**
* See {@link CommentInterface::$comments_require_login}
*
* @param boolean state The new state of this static field
*/
static function set_comments_require_login($state) {
self::$comments_require_login = (boolean) $state;
}
/**
* See {@link CommentInterface::$comments_require_permission}
*
* @param string permission The permission to check against.
*/
static function set_comments_require_permission($permission) {
self::$comments_require_permission = $permission;
}
/**
* See {@link CommentInterface::$show_comments_when_disabled}
*
* @param bool - show / hide the existing comments when disabled
*/
static function set_show_comments_when_disabled($state) {
self::$show_comments_when_disabled = $state;
}
/**
* See {@link CommentInterface::$order_comments_by}
*
* @param String
*/
static function set_order_comments_by($order) {
self::$order_comments_by = $order;
}
/**
* See {@link CommentInterface::$use_ajax_commenting}
*
* @param bool
*/
static function set_use_ajax_commenting($state) {
self::$use_ajax_commenting = $state;
}
/**
* @return boolean true if the currently logged in user can post a comment,
* false if they can't. Users can post comments by default, enforce
* security by using
*
* @link CommentInterface::set_comments_require_login() and
* @link {CommentInterface::set_comments_require_permission()}.
*/
public static function canPost() {
$member = Member::currentUser();
if(self::$comments_require_permission && $member && Permission::check(self::$comments_require_permission)) {
// Comments require a certain permission, and the user has the correct permission
return true;
} elseif(self::$comments_require_login && $member && !self::$comments_require_permission) {
// Comments only require that a member is logged in
return true;
} elseif(!self::$comments_require_permission && !self::$comments_require_login) {
// Comments don't require anything - anyone can add a comment
return true;
}
return false;
}
/**
* if this page comment form requires users to have a

View File

@ -39,6 +39,7 @@ class Comment extends DataObject {
/**
* Return a link to this comment
*
* @return string link to this comment.
*/
function Link() {
@ -165,7 +166,22 @@ class Comment extends DataObject {
* @return Boolean
*/
function canCreate($member = null) {
$member = Member::currentUser();
if(self::$comments_require_permission && $member && Permission::check(self::$comments_require_permission)) {
// Comments require a certain permission, and the user has the correct permission
return true;
} elseif(self::$comments_require_login && $member && !self::$comments_require_permission) {
// Comments only require that a member is logged in
return true;
} elseif(!self::$comments_require_permission && !self::$comments_require_login) {
// Comments don't require anything - anyone can add a comment
return true;
}
return false;
}
/**

View File

@ -87,7 +87,15 @@ class CommentsExtension extends DataObjectDecorator {
public function CommentsForm() {
$interface = new SSViewer('CommentsInterface');
// detect whether we comments are enabled. By default if $CommentsForm is included
// on a {@link DataObject} then it is enabled, however {@link SiteTree} objects can
// trigger comments on / off via ProvideComments
$enabled = (!$this->attachedToSiteTree() || $this->owner->ProvideComments) ? true : false;
// if comments are turned off then
return $interface->process(new ArrayData(array(
'CommentsEnabled' => $enabled,
'AddCommentForm' => $this->AddCommentForm(),
'Comments' => $this->Comments()
)));
@ -101,11 +109,6 @@ class CommentsExtension extends DataObjectDecorator {
*/
public function AddCommentForm() {
// detect whether we comments are enabled. By default if $CommentsForm is included
// on a {@link DataObject} then it is enabled, however {@link SiteTree} objects can
// trigger comments on / off via ProvideComments
if($this->attachedToSiteTree() && !$this->owner->ProvideComments) return false;
$form = new CommentForm(Controller::curr(), 'CommentsForm');
// hook to allow further extensions to alter the comments form

View File

@ -28,7 +28,7 @@ class CommentForm extends Form {
}
$fields->push(new TextField("URL", _t('CommentForm.COMMENTERURL', "Your website URL")));
$fields->push(new EmailField("Email", _t('CommentForm', "Your email address (will not be published)")))
$fields->push(new EmailField("Email", _t('CommentForm', "Your email address (will not be published)")));
$fields->push(new TextareaField("Comment", _t('CommentInterface.YOURCOMMENT', "Comments")));
$actions = new FieldSet(
@ -126,12 +126,11 @@ class CommentForm extends Form {
// we need to link to the comment holder rather than the individual comment
$url = ($comment->NeedsModeration) ? $page->Link() . '#Comments_holder' : $page->Link() . '#Comment_' . $comment->ID;
return Director::redirect($url);
return $this->controller->redirect($url);
}
}
return Director::redirectBack();
}
return $this->controller->redirectBack();
}
}
}

0
docs/en/Configuration.md Normal file
View File

0
docs/en/Upgrading.md Normal file
View File

View File

@ -1,12 +1,14 @@
<div id="PageComments_holder" class="typography">
<% if CommentsEnabled %>
<div id="PageComments_holder" class="typography">
<h4><% _t('POSTCOM','Post your comment') %></h4>
<% if PostCommentForm %>
<% if CanPostComment %>
$PostCommentForm
<% if AddCommentForm %>
<% if canPost %>
$AddCommentForm
<% else %>
<p><% _t('COMMENTLOGINERROR', 'You cannot post comments until you have logged in') %><% if PostingRequiresPermission %>,<% _t('COMMENTPERMISSIONERROR', 'and that you have an appropriate permission level') %><% end_if %>.
<a href="Security/login?BackURL={$Page.Link}" title="Login to post a comment"><% _t('COMMENTPOSTLOGIN', 'Login Here') %></a>.
<a href="Security/login?BackURL={$Page.Link}" title="<% _t('LOGINTOPOSTCOMMENT', 'Login to post a comment') %>"><% _t('COMMENTPOSTLOGIN', 'Login Here') %></a>.
</p>
<% end_if %>
<% else %>
@ -20,7 +22,7 @@
<ul id="PageComments">
<% control Comments %>
<li class="$EvenOdd<% if FirstLast %> $FirstLast <% end_if %> $SpamClass">
<% include PageCommentInterface_singlecomment %>
<% include CommentsInterface_singlecomment %>
</li>
<% end_control %>
</ul>
@ -52,14 +54,17 @@
<p id="NoComments"><% _t('NOCOMMENTSYET','No one has commented on this page yet.') %></p>
<% end_if %>
</div>
<% if DeleteAllLink %>
<p id="DeleteComments"><a href="$DeleteAllLink">
<% _t('PageCommentInterface.DELETEALLCOMMENTS','Delete all comments on this page') %>
</a></p>
<p id="DeleteComments">
<a href="$DeleteAllLink"><% _t('PageCommentInterface.DELETEALLCOMMENTS','Delete all comments on this page') %></a>
</p>
<% end_if %>
<p id="CommentsRSSFeed">
<a class="commentrss" href="$CommentRssLink"><% _t('RSSFEEDCOMMENTS', 'RSS feed for comments on this page') %></a> |
<a href="PageComment/rss" class="commentrss" title="<% _t('RSSVIEWALLCOMMENTS', 'View all Comments') %>"><% _t('RSSFEEDALLCOMMENTS', 'RSS feed for all comments') %></a>
</p>
</div>
</div>
<% end_if %>