diff --git a/wire/core/MarkupQA.php b/wire/core/MarkupQA.php index 3fbf7ad6..f403c0ed 100644 --- a/wire/core/MarkupQA.php +++ b/wire/core/MarkupQA.php @@ -784,7 +784,7 @@ class MarkupQA extends Wire { if(file_exists($this->page->filesManager()->path() . basename($src))) { // file exists, but we just don't know what it is - leave it alone } else { - $this->error("Image file no longer exists: " . basename($src) . ")"); + $this->error("Image file no longer exists: $src"); if($this->page->of()) $value = str_replace($img, '', $value); $info['img_unresolved']++; } @@ -912,7 +912,7 @@ class MarkupQA extends Wire { * */ public function error($text, $flags = 0) { - $logText = "$text (page={$this->page->path}, field={$this->field->name})"; + $logText = "$text (field={$this->field->name}, id={$this->page->id}, path={$this->page->path})"; $this->wire('log')->save(self::errorLogName, $logText); /* if($this->wire('modules')->isInstalled('SystemNotifications')) { diff --git a/wire/modules/Fieldtype/FieldtypeComments/Comment.php b/wire/modules/Fieldtype/FieldtypeComments/Comment.php index c452173b..9db03e77 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/Comment.php +++ b/wire/modules/Fieldtype/FieldtypeComments/Comment.php @@ -11,6 +11,7 @@ * @property int $id * @property int $parent_id * @property string $text + * @property string|null $textFormatted Text value formatted for output (runtime use only, must be set manually) * @property int $sort * @property int $status * @property int|null $prevStatus @@ -140,6 +141,12 @@ class Comment extends WireData { */ protected $pageComments = null; + /** + * @var string|null + * + */ + protected $textFormatted = null; + /** * Construct a Comment and set defaults * @@ -197,6 +204,9 @@ class Comment extends WireData { } else if($key == 'prevStatus') { return $this->prevStatus; + + } else if($key == 'textFormatted') { + return $this->textFormatted; } return parent::get($key); @@ -216,6 +226,8 @@ class Comment extends WireData { $value = $this->get($key); if($key == 'text') { + if($this->textFormatted !== null) return $this->textFormatted; + $textformatters = null; // $textformatters = $this->field ? $this->field->textformatters : null; // @todo if(is_array($textformatters) && count($textformatters)) { @@ -230,8 +242,6 @@ class Comment extends WireData { $value = str_replace("\n\n", "

", $value); $value = str_replace("\n", "
", $value); } - - } else if(in_array($key, array('cite', 'email', 'user_agent', 'website'))) { $value = $this->wire('sanitizer')->entities(trim($value)); @@ -242,15 +252,28 @@ class Comment extends WireData { public function set($key, $value) { - if(in_array($key, array('id', 'parent_id', 'status', 'flags', 'pages_id', 'created', 'created_users_id'))) $value = (int) $value; - else if($key == 'text') $value = $this->cleanCommentString($value); - else if($key == 'cite') $value = str_replace(array("\r", "\n", "\t"), ' ', substr(strip_tags($value), 0, 128)); - else if($key == 'email') $value = $this->sanitizer->email($value); - else if($key == 'ip') $value = filter_var($value, FILTER_VALIDATE_IP); - else if($key == 'user_agent') $value = str_replace(array("\r", "\n", "\t"), ' ', substr(strip_tags($value), 0, 255)); - else if($key == 'website') $value = $this->wire('sanitizer')->url($value, array('allowRelative' => false, 'allowQuerystring' => false)); - else if($key == 'upvotes' || $key == 'downvotes') $value = (int) $value; - + if(in_array($key, array('id', 'parent_id', 'status', 'flags', 'pages_id', 'created', 'created_users_id'))) { + $value = (int) $value; + } else if($key === 'text') { + $value = $this->cleanCommentString($value); + $this->textFormatted = null; + } else if($key === 'cite') { + $value = str_replace(array("\r", "\n", "\t"), ' ', substr(strip_tags($value), 0, 128)); + } else if($key === 'email') { + $value = $this->sanitizer->email($value); + } else if($key === 'ip') { + $value = filter_var($value, FILTER_VALIDATE_IP); + } else if($key === 'user_agent') { + $value = str_replace(array("\r", "\n", "\t"), ' ', substr(strip_tags($value), 0, 255)); + } else if($key === 'website') { + $value = $this->wire('sanitizer')->url($value, array('allowRelative' => false, 'allowQuerystring' => false)); + } else if($key === 'upvotes' || $key === 'downvotes') { + $value = (int) $value; + } else if($key === 'textFormatted') { + $this->textFormatted = $value; + return $this; + } + // save the state so that modules can identify when a comment that was identified as spam // is then set to not-spam, or when a misidentified 'approved' comment is actually spam if($key == 'status' && $this->loaded) { diff --git a/wire/modules/Fieldtype/FieldtypeComments/CommentList.php b/wire/modules/Fieldtype/FieldtypeComments/CommentList.php index b68754b4..a7a3e7c0 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/CommentList.php +++ b/wire/modules/Fieldtype/FieldtypeComments/CommentList.php @@ -37,8 +37,17 @@ class CommentList extends Wire implements CommentListInterface { * */ protected $comments = null; - + + /** + * @var Page + * + */ protected $page; + + /** + * @var Field + * + */ protected $field; /** @@ -61,7 +70,7 @@ class CommentList extends Wire implements CommentListInterface { 'downvoteFormat' => '↓{cnt}', 'depth' => 0, 'replyLabel' => 'Reply', - ); + ); /** * Construct the CommentList @@ -94,6 +103,35 @@ class CommentList extends Wire implements CommentListInterface { $this->options = array_merge($this->options, $options); } + /** + * Get or set options + * + * @param string|null|array $key Use one of the following: + * - Omit to get array of all options + * - Specify option name to get (and omit $value argument) + * - Specify option name to set and provide a non-null $value argument + * - Specify array of one or more [ 'option' => 'value' ] to set and omit $value argument + * @param string|int|bool|null $value When setting an individual option, value should be specified here, otherwise omit + * @return array|string|int|bool|null When getting singe option, value is returned, otherwise array of all options is returned. + * @since 3.0.138 + * + */ + public function options($key = null, $value = null) { + if($key === null) { + return $this->options; + } else if(is_array($key)) { + $this->options = array_merge($this->options, $key); + return $this->options; + } else if($value !== null) { + $this->options[$key] = $value; + return $this->options; + } else if(isset($this->options[$key])) { + return $this->options[$key]; + } else { + return null; + } + } + /** * Get replies to the given comment ID, or 0 for root level comments * @@ -196,15 +234,15 @@ class CommentList extends Wire implements CommentListInterface { return $out; } - + /** * Render the comment * * This is the default rendering for development/testing/demonstration purposes * * It may be used for production, but only if it meets your needs already. Typically you'll want to render the comments - * using your own code in your templates. - * + * using your own code in your templates. + * * @param Comment $comment * @param int $depth Default=0 * @return string @@ -212,6 +250,25 @@ class CommentList extends Wire implements CommentListInterface { * */ public function renderItem(Comment $comment, $depth = 0) { + if($this->wire('hooks')->isHooked("CommentList::renderItem()")) { + return $this->__call('renderItem', array($comment, $depth)); + } else { + return $this->___renderItem($comment, $depth); + } + } + + /** + * Render the comment (hookable version) + * + * Hookable since 3.0.138 + * + * @param Comment $comment + * @param int $depth Default=0 + * @return string + * @see CommentArray::render() + * + */ + protected function ___renderItem(Comment $comment, $depth = 0) { $text = $comment->getFormatted('text'); $cite = $comment->getFormatted('cite');