Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom image avatar, custom fields to automatically populate the Your Name field, and the ability to hide user fields when logged in. #954

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 38 additions & 37 deletions wire/modules/Fieldtype/FieldtypeComments/CommentArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*
* Maintains an array of multiple Comment instances.
* Serves as the value referenced when a FieldtypeComment field is reference from a Page.
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
*
* http://www.processwire.com
* http://www.ryancramer.com
*
Expand All @@ -18,10 +18,10 @@
class CommentArray extends PaginatedArray implements WirePaginatable {

/**
* Page that owns these comments, required to use the renderForm() or getCommentForm() methods.
* Page that owns these comments, required to use the renderForm() or getCommentForm() methods.
*
*/
protected $page = null;
protected $page = null;

/**
* Field object associated with this CommentArray
Expand All @@ -31,31 +31,31 @@ class CommentArray extends PaginatedArray implements WirePaginatable {

/**
* Total number of comments, including those here and others that aren't, but may be here in pagination.
*
*
* @var int
*
*
*/
protected $numTotal = 0;

/**
* If this CommentArray is a partial representation of a larger set, this will contain the max number
* If this CommentArray is a partial representation of a larger set, this will contain the max number
* of comments allowed to be present/loaded in the CommentArray at once.
*
* May vary from count() when on the last page of a result set.
* As a result, paging routines should refer to their own itemsPerPage rather than count().
* Applicable for paginated result sets. This number is not enforced for adding items to this CommentArray.
*
* @var int
*
*
*/
protected $numLimit = 0;

/**
* If this CommentArray is a partial representation of a larger set, this will contain the starting result
* If this CommentArray is a partial representation of a larger set, this will contain the starting result
* number if previous results preceded it.
*
* @var int
*
*
*/
protected $numStart = 0;

Expand All @@ -65,9 +65,9 @@ class CommentArray extends PaginatedArray implements WirePaginatable {
*/
public function isValidItem($item) {
if($item instanceof Comment) {
if($this->page) $item->setPage($this->page);
if($this->field) $item->setField($this->field);
return true;
if($this->page) $item->setPage($this->page);
if($this->field) $item->setField($this->field);
return true;
} else {
return false;
}
Expand All @@ -83,13 +83,14 @@ public function isValidItem($item) {
*/
public function render(array $options = array()) {
$defaultOptions = array(
'useImageField' => ($this->field ? $this->field->useImageField : ''),
'useGravatar' => ($this->field ? $this->field->useGravatar : ''),
'useVotes' => ($this->field ? $this->field->useVotes : 0),
'depth' => ($this->field ? (int) $this->field->depth : 0),
'dateFormat' => 'relative',
'useVotes' => ($this->field ? $this->field->useVotes : 0),
'depth' => ($this->field ? (int) $this->field->depth : 0),
'dateFormat' => 'relative',
);
$options = array_merge($defaultOptions, $options);
$commentList = $this->getCommentList($options);
$commentList = $this->getCommentList($options);
return $commentList->render();
}

Expand All @@ -105,28 +106,28 @@ public function renderForm(array $options = array()) {
$defaultOptions = array(
'depth' => ($this->field ? (int) $this->field->depth : 0)
);
$options = array_merge($defaultOptions, $options);
$form = $this->getCommentForm($options);
$options = array_merge($defaultOptions, $options);
$form = $this->getCommentForm($options);
return $form->render();
}

/**
* Render all comments and a comments form below it
*
*
* @param array $options
* @return string
*
*
*/
public function renderAll(array $options = array()) {
return $this->render($options) . $this->renderForm($options);
return $this->render($options) . $this->renderForm($options);
}

/**
* Return instance of CommentList object
*
*/
public function getCommentList(array $options = array()) {
return new CommentList($this, $options);
return new CommentList($this, $options);
}

/**
Expand All @@ -135,35 +136,35 @@ public function getCommentList(array $options = array()) {
* @param array $options
* @return CommentForm
* @throws WireException
*
*
*/
public function getCommentForm(array $options = array()) {
if(!$this->page) throw new WireException("You must set a page to this CommentArray before using it i.e. \$ca->setPage(\$page)");
return new CommentForm($this->page, $this, $options);
if(!$this->page) throw new WireException("You must set a page to this CommentArray before using it i.e. \$ca->setPage(\$page)");
return new CommentForm($this->page, $this, $options);
}

/**
* Set the page that these comments are on
* Set the page that these comments are on
*
*/
*/
public function setPage(Page $page) {
$this->page = $page;
$this->page = $page;
}

/**
* Set the Field that these comments are on
* Set the Field that these comments are on
*
*/
*/
public function setField(Field $field) {
$this->field = $field;
$this->field = $field;
}

/**
* Get the page that these comments are on
*
*/
public function getPage() {
return $this->page;
public function getPage() {
return $this->page;
}

/**
Expand Down
Loading