/** * Returns the classes for the comment div as an array * * @param string|array $class One or more classes to add to the class list * @param array|string $comment Comment array or comment id * * @return array Array of classes */ public function getClass($class = '', $comment = null) { $this->getComment($comment); $classes = []; $classes[] = 'comment'; // If the comment author has an id (registered), then print the log in name if ($this->comment['Comment']['user_id'] > 0 && ($user = ClassRegistry::init('User')->getUser($this->comment['Comment']['user_id']))) { // For all registered users, 'byuser' $classes[] = 'byuser'; $classes[] = 'comment-author-' . HuradSanitize::htmlClass(['comment-author-' . $user['UserMeta']['nickname'], 'comment-author-' . $this->comment['Comment']['user_id']]); // For comment authors who are the author of the post if ($post = ClassRegistry::init('Post')->getPost($this->comment['Comment']['post_id'])) { if ($this->comment['Comment']['user_id'] === $post['Post']['user_id']) { $classes[] = 'by-post-author'; } } } if (empty($this->commentAlt)) { $this->commentAlt = 0; } if (empty($commentDepth)) { $commentDepth = 1; } if (empty($commentThreadAlt)) { $commentThreadAlt = 0; } if ($this->commentAlt % 2) { $classes[] = 'odd'; $classes[] = 'alt'; } else { $classes[] = 'even'; } $this->commentAlt++; // Alt for top-level comments if (1 == $commentDepth) { if ($commentThreadAlt % 2) { $classes[] = 'thread-odd'; $classes[] = 'thread-alt'; } else { $classes[] = 'thread-even'; } $commentThreadAlt++; } $classes[] = "depth-{$commentDepth}"; if (!empty($class)) { if (!is_array($class)) { $class = preg_split('#\\s+#', $class); } $classes = Hash::merge($classes, $class); } $classes = array_map('HuradSanitize::htmlClass', $classes); $classesStr = implode(' ', $classes); return $this->Hook->applyFilters('Helper.Comment.getClass', $classesStr, $classes, $class); }