diff --git a/wire/modules/Fieldtype/FieldtypeComments/Comment.php b/wire/modules/Fieldtype/FieldtypeComments/Comment.php index ef5daac6..6f98d308 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/Comment.php +++ b/wire/modules/Fieldtype/FieldtypeComments/Comment.php @@ -127,6 +127,12 @@ class Comment extends WireData { */ protected $quiet = false; + /** + * @var CommentArray|null + * + */ + protected $pageComments = null; + /** * Construct a Comment and set defaults * @@ -252,6 +258,9 @@ class Comment extends WireData { /** * Clean a comment string by issuing several filters + * + * @param string $str + * @return string * */ public function cleanCommentString($str) { @@ -364,11 +373,13 @@ class Comment extends WireData { * */ public function children() { - $field = $this->getField(); - $comments = $this->getPage()->get($field->name); + /** @var CommentArray $comments */ + $comments = $this->getPageComments(); $children = $comments->makeNew(); - $children->setPage($this->getPage()); - $children->setField($field); + $page = $this->getPage(); + $field = $this->getField(); + if($page) $children->setPage($this->getPage()); + if($field) $children->setField($this->getField()); $id = $this->id; foreach($comments as $comment) { if(!$comment->parent_id) continue; @@ -377,6 +388,35 @@ class Comment extends WireData { return $children; } + /** + * Get array that holds all the comments for the current Page/Field + * + * #pw-internal + * + * @param bool $autoDetect Autodetect from Page and Field if not already set? (default=true) + * @return CommentArray|null + * + */ + public function getPageComments($autoDetect = true) { + if($autoDetect && !$this->pageComments) { + $field = $this->getField(); + $this->pageComments = $this->getPage()->get($field->name); + } + return $this->pageComments; + } + + /** + * Set the CommentArray that holds all comments for the curent Page/Field + * + * #pw-internal + * + * @param CommentArray $pageComments + * + */ + public function setPageComments(CommentArray $pageComments) { + $this->pageComments = $pageComments; + } + /** * Render stars markup * diff --git a/wire/modules/Fieldtype/FieldtypeComments/CommentArray.php b/wire/modules/Fieldtype/FieldtypeComments/CommentArray.php index 10708122..834e02ed 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/CommentArray.php +++ b/wire/modules/Fieldtype/FieldtypeComments/CommentArray.php @@ -86,14 +86,6 @@ class CommentArray extends PaginatedArray implements WirePaginatable { * */ public function render(array $options = array()) { - $defaultOptions = array( - 'useGravatar' => ($this->field ? $this->field->get('useGravatar') : ''), - 'useVotes' => ($this->field ? $this->field->get('useVotes') : 0), - 'useStars' => ($this->field ? $this->field->get('useStars') : 0), - 'depth' => ($this->field ? (int) $this->field->get('depth') : 0), - 'dateFormat' => ($this->field ? $this->field->get('dateFormat') : 'relative'), - ); - $options = array_merge($defaultOptions, $options); $commentList = $this->getCommentList($options); return $commentList->render(); } @@ -148,6 +140,21 @@ class CommentArray extends PaginatedArray implements WirePaginatable { * */ public function getCommentList(array $options = array()) { + $field = $this->field; + if($field) { + $defaults = array( + 'useGravatar' => $field->get('useGravatar'), + 'useVotes' => $field->get('useVotes'), + 'useStars' => $field->get('useStars'), + 'depth' => $field->get('depth'), + 'dateFormat' => $field->get('dateFormat'), + ); + } else { + $defaults = array( + 'dateFormat' => 'relative' + ); + } + $options = array_merge($defaults, $options); return $this->wire(new CommentList($this, $options)); } @@ -274,6 +281,7 @@ class CommentArray extends PaginatedArray implements WirePaginatable { if($getCount) return array($stars, $count); return $stars; } + /** * Render combined star rating for all comments in this CommentsArray * @@ -304,6 +312,18 @@ class CommentArray extends PaginatedArray implements WirePaginatable { if($showCount) $out .= $commentStars->renderCount((int) $count, $stars, $options['schema']); return $out; } + + /** + * Track an item added + * + * @param Comment $item + * @param int|string $key + * + */ + protected function trackAdd($item, $key) { + parent::trackAdd($item, $key); + if(!$item->getPageComments(false)) $item->setPageComments($this); + } } diff --git a/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php b/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php index cc449c4f..91b8ebdb 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php +++ b/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php @@ -82,7 +82,9 @@ class CommentForm extends Wire implements CommentFormInterface { 'class' => '', 'rows' => 5, 'cols' => 50, + 'form' => '', // any extra attributes for form element ), + 'inputWrapTag' => 'p', // tag that wraps label/inputs 'labels' => array( 'cite' => '', // Your Name 'email' => '', // Your E-Mail @@ -91,7 +93,28 @@ class CommentForm extends Wire implements CommentFormInterface { 'text' => '', // Comments 'submit' => '', // Submit 'starsRequired' => '', // Please select a star rating - ), + ), + 'classes' => array( + 'form' => '', + 'label' => '', + 'labelSpan' => '', + 'cite' => 'CommentFormCite {id}_cite', + 'citeInput' => 'required', + 'email' => 'CommentFormEmail {id}_email', + 'emailInput' => 'required email', + 'text' => 'CommentFormText {id}_text', + 'textInput' => 'required', + 'website' => 'CommentFormWebsite {id}_website', + 'websiteInput' => 'website', + 'stars' => 'CommentFormStars {id}_stars', + 'starsRequired' => 'CommentFormStarsRequired', + 'honeypot' => 'CommentFormHP {id}_hp', + 'notify' => 'CommentFormNotify', + 'radioLabel' => '', + 'radioInput' => '', + 'submit' => 'CommentFormSubmit {id}_submit', + 'submitButton' => '', + ), // values that will be already set, perhaps pulled from a user profile for instance (null = ignore) // note that using presets is NOT cache safe: do not use for non-logged-in users if output caches are active @@ -100,7 +123,7 @@ class CommentForm extends Wire implements CommentFormInterface { 'email' => null, 'website' => null, 'text' => null, - ), + ), // whether or not eht preset values above will be changeable by the user // applies only for preset values that are not null. @@ -190,6 +213,14 @@ class CommentForm extends Wire implements CommentFormInterface { public function setLabel($label, $value) { $this->options['labels'][$label] = $value; } + + public function getOptions() { + return $this->options; + } + + public function setOptions(array $options) { + $this->options = array_merge($this->options, $options); + } /** * Replaces the output of the render() method when a Comment is posted @@ -402,48 +433,68 @@ class CommentForm extends Wire implements CommentFormInterface { protected function renderFormThread($id, $class, $attrs, $labels, $inputValues) { + $classes = $this->options['classes']; + $classes['form'] .= " $class CommentFormThread"; + + foreach($classes as $key => $value) { + $classes[$key] = trim(str_replace('{id}', $id, $value)); + } + + $labelClass = $classes['label']; + $labelClass = $labelClass ? " class='$labelClass'" : ""; + $labelSpanClass = $classes['labelSpan']; + $labelSpanClass = $labelSpanClass ? " class='$labelSpanClass'" : ""; + + $tag = $this->options['inputWrapTag']; + $formAttrs = trim( + "class='$classes[form]' " . + "action='$attrs[action]#$id' " . + "method='$attrs[method]' " . + $attrs['form'] + ); + $form = - "\n
" . - "\n\t

" . - "\n\t\t " . - "\n\t

" . - "\n\t

" . - "\n\t\t" . - "\n\t

"; + "\n\t"; if($this->commentsField && $this->commentsField->useWebsite && $this->commentsField->schemaVersion > 0) { $form .= - "\n\t

" . - "\n\t\t" . - "\n\t

"; + "\n\t"; } if($this->commentsField->useStars && $this->commentsField->schemaVersion > 5) { $commentStars = new CommentStars(); - $starsClass = 'CommentFormStars'; + $starsClass = $classes['stars']; if($this->commentsField->useStars > 1) { $starsNote = $labels['starsRequired']; - $starsClass .= ' CommentFormStarsRequired'; + $starsClass .= " $classes[starsRequired]"; } else { $starsNote = ''; } $form .= - "\n\t

" . - "\n\t\t" . - "\n\t

"; + "\n\t"; } // do we need to show the honeypot field? @@ -452,34 +503,36 @@ class CommentForm extends Wire implements CommentFormInterface { $honeypotLabel = isset($labels[$honeypot]) ? $labels[$honeypot] : ''; $honeypotValue = isset($inputValues[$honeypot]) ? $inputValues[$honeypot] : ''; $form .= - "\n\t

" . + "\n\t<$tag class='$classes[honeypot]'>" . "\n\t\t" . - "\n\t

"; + "\n\t"; } $form .= - "\n\t

" . - "\n\t\t" . - "\n\t

" . + "\n\t" . $this->renderNotifyOptions() . - "\n\t

" . - "\n\t\t" . + "\n\t<$tag class='$classes[submit]'>" . + "\n\t\t" . "\n\t\t" . "\n\t\t" . - "\n\t

" . + "\n\t" . "\n
"; return $form; } protected function renderNotifyOptions() { + if(!$this->commentsField->useNotify) return ''; $out = ''; + $tag = $this->options['inputWrapTag']; $options = array(); @@ -487,22 +540,33 @@ class CommentForm extends Wire implements CommentFormInterface { $options['2'] = $this->_('Replies'); } - if($this->commentsField->useNotify == Comment::flagNotifyAll) { $options['4'] = $this->_('All'); } + $classes = array( + 'notify' => $this->options['classes']['notify'], + 'label' => $this->options['classes']['label'], + 'labelSpan' => $this->options['classes']['labelSpan'], + 'radioLabel' => $this->options['classes']['radioLabel'], + 'radioInput' => $this->options['classes']['radioInput'], + ); + + foreach($classes as $key => $value) { + $classes[$key] = $value ? " class='" . trim($value) . "'" : ""; + } + if(count($options)) { $out = - "\n\t

" . - "\n\t\t " . - "\n\t\t "; + "\n\t<$tag$classes[notify]>" . + "\n\t\t" . $this->_('E-Mail Notifications:') . " " . + "\n\t\t " . $this->_('Off') . " "; foreach($options as $value => $label) { $label = str_replace(' ', ' ', $label); - $out .= "\n\t\t "; + $out .= "\n\t\t $label "; } - $out .= "\n\t

"; + $out .= "\n\t"; } return $out; diff --git a/wire/modules/Fieldtype/FieldtypeComments/CommentList.php b/wire/modules/Fieldtype/FieldtypeComments/CommentList.php index 5fba032e..4938d8fe 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/CommentList.php +++ b/wire/modules/Fieldtype/FieldtypeComments/CommentList.php @@ -315,11 +315,21 @@ class CommentList extends Wire implements CommentListInterface { * It also populates a session variable 'CommentApprovalMessage' with * a text message of what occurred. * + * @param array $options * @return string * */ - public function renderCheckActions() { - + public function renderCheckActions(array $options = array()) { + + $defaults = array( + 'messageIdAttr' => 'CommentApprovalMessage', + 'messageMarkup' => "

{message}

", + 'linkMarkup' => "{label}", + 'successClass' => 'success', + 'errorClass' => 'error', + ); + + $options = array_merge($defaults, $options); $action = $this->wire('input')->get('comment_success'); if(empty($action) || $action === "1") return ''; @@ -327,11 +337,22 @@ class CommentList extends Wire implements CommentListInterface { $message = $this->wire('session')->get('CommentApprovalMessage'); if($message) { $this->wire('session')->remove('CommentApprovalMessage'); - $class = $action === '2' ? 'success' : 'error'; + $class = $action === '2' ? $options['successClass'] : $options['errorClass']; $commentID = (int) $this->wire('input')->get('comment_id'); $message = $this->wire('sanitizer')->entities($message); - if($commentID) $message = str_replace($commentID, "$commentID", $message); - return "

$message

"; + if($commentID) { + $link = str_replace( + array('{href}', '{label}'), + array("#Comment$commentID", $commentID), + $options['linkMarkup'] + ); + $message = str_replace($commentID, $link, $message); + } + return str_replace( + array('{id}', '{class}', '{message}'), + array($options['messageIdAttr'], $class, $message), + $options['messageMarkup'] + ); } } @@ -345,7 +366,7 @@ class CommentList extends Wire implements CommentListInterface { if($info['commentID']) $url .= "comment_id=$info[commentID]&"; $url .= "comment_success=" . ($info['success'] ? '2' : '3'); $this->wire('session')->set('CommentApprovalMessage', $info['message']); - $this->wire('session')->redirect($url . '#CommentApprovalMessage'); + $this->wire('session')->redirect($url . '#' . $options['messageIdAttr']); } return ''; diff --git a/wire/modules/Inputfield/InputfieldSelect.module b/wire/modules/Inputfield/InputfieldSelect.module index 904c4bd4..68b98723 100644 --- a/wire/modules/Inputfield/InputfieldSelect.module +++ b/wire/modules/Inputfield/InputfieldSelect.module @@ -421,13 +421,16 @@ class InputfieldSelect extends Inputfield { /** * Render the given options * - * @param array $options - * @param bool $allowBlank + * Note: method was protected prior to 3.0.116 + * + * @param array|null $options Options array or omit (null) to use already specified options + * @param bool $allowBlank Allow first item to be blank when supported? (default=tru) * @return string * */ - protected function renderOptions($options, $allowBlank = true) { + public function renderOptions($options = null, $allowBlank = true) { + if($options === null) $options = $this->options; $out = ''; reset($options); $key = key($options); diff --git a/wire/modules/Process/ProcessPagesExportImport/ProcessPagesExportImport.module b/wire/modules/Process/ProcessPagesExportImport/ProcessPagesExportImport.module index 8fbb9871..0c7b3e30 100644 --- a/wire/modules/Process/ProcessPagesExportImport/ProcessPagesExportImport.module +++ b/wire/modules/Process/ProcessPagesExportImport/ProcessPagesExportImport.module @@ -77,10 +77,12 @@ class ProcessPagesExportImport extends Process { return $form->render(); } } else { + /* $this->warning( 'Please note this is a development version of pages export/import ' . 'and not yet recommended for production use.' ); + */ $form = $this->buildForm(); return $form->render(); } @@ -307,6 +309,8 @@ class ProcessPagesExportImport extends Process { 'changeStatus' => in_array('status', $fieldNames), 'changeSort' => in_array('sort', $fieldNames), 'filesPath' => $this->wire('session')->getFor($this, 'filesPath'), + 'originalHost' => isset($a['host']) ? $a['host'] : $this->wire('config')->httpHost, + 'originalRootUrl' => isset($a['url']) ? $a['url'] : $this->wire('config')->urls->root, ); foreach($a['pages'] as $key => $item) {