Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit ba9eee4

Browse files
authored
Merge pull request #146 from dshanske/commentclass
Comment Class Improvements
2 parents 038a716 + 32fb349 commit ba9eee4

File tree

6 files changed

+55
-59
lines changed

6 files changed

+55
-59
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ The Webmention and Pingback logos are made by [Aaron Parecki](http://aaronpareck
6868

6969
Project actively developed on Github at [pfefferle/wordpress-semantic-linkbacks](https://github.com/pfefferle/wordpress-semantic-linkbacks). Please file support issues there.
7070

71+
### 3.7.3 ###
72+
* Remove `h-as` properties
73+
* Remove hard-coded microformats2 properties from facepile and move them to being generated from comment_class
74+
* Remove unused properties
75+
* Introduce type argument in list_linkbacks to generate unique ideas for each list of linkbacks without having to specify them using style and li-class
76+
7177
### 3.7.2 ###
7278

7379
* Bugfix: "Normal comments" hidden in comment-section (https://github.com/pfefferle/wordpress-semantic-linkbacks/issues/140)

includes/class-linkbacks-handler.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -559,33 +559,31 @@ public static function get_comment_author_url( $url, $id, $comment ) {
559559
public static function comment_class( $classes, $class, $comment_id, $post_id ) {
560560
// get comment
561561
$comment = get_comment( $comment_id );
562-
563562
// "comment type to class" mapper
564563
$class_mapping = array(
565-
'mention' => array( 'h-as-mention' ),
566-
567-
'reply' => array( 'h-as-reply' ),
568-
'repost' => array( 'h-as-repost', 'p-repost' ),
569-
'like' => array( 'h-as-like', 'p-like' ),
570-
'favorite' => array( 'h-as-favorite', 'p-favorite' ),
571-
'tag' => array( 'h-as-tag', 'p-tag' ),
572-
'bookmark' => array( 'h-as-bookmark', 'p-bookmark' ),
573-
'rsvp:yes' => array( 'h-as-rsvp' ),
574-
'rsvp:no' => array( 'h-as-rsvp' ),
575-
'rsvp:maybe' => array( 'h-as-rsvp' ),
576-
'rsvp:invited' => array( 'h-as-rsvp' ),
577-
'rsvp:tracking' => array( 'h-as-rsvp' ),
564+
'mention' => array( 'u-mention' ),
565+
566+
'reply' => array( 'u-comment' ),
567+
'repost' => array( 'u-repost' ),
568+
'like' => array( 'u-like' ),
569+
'favorite' => array( 'u-favorite' ),
570+
'tag' => array( 'u-tag' ),
571+
'bookmark' => array( 'u-bookmark' ),
572+
'rsvp:yes' => array( 'u-rsvp' ),
573+
'rsvp:no' => array( 'u-rsvp' ),
574+
'rsvp:maybe' => array( 'u-rsvp' ),
575+
'rsvp:invited' => array( 'u-rsvp' ),
576+
'rsvp:tracking' => array( 'u-rsvp' ),
578577
);
579578

580579
$semantic_linkbacks_type = self::get_type( $comment );
581580

582581
// check the comment type
583582
if ( $semantic_linkbacks_type && isset( $class_mapping[ $semantic_linkbacks_type ] ) ) {
584583
$classes = array_merge( $classes, $class_mapping[ $semantic_linkbacks_type ] );
585-
586584
$classes = array_unique( $classes );
587585
}
588-
586+
$classes[] = 'h-cite';
589587
return $classes;
590588
}
591589

includes/functions.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ function list_linkbacks( $args, $comments ) {
150150
'avatar_size' => 64,
151151
'style' => 'ul', // What HTML type to wrap it in. Accepts 'ul', 'ol'.
152152
'style-class' => 'mention-list', // What class to assign to the wrapper
153-
'li-class' => 'single-mention', // What class to assign to the list elements
153+
'li-class' => null, // What class to assign to the list elements
154154
'echo' => true, // Whether to echo the output or return
155+
'type' => 'mention', // Type is the semantic linkbacks type and is here only to automatically add to the classes if present
155156
);
156157

157158
$r = wp_parse_args( $args, $defaults );
@@ -170,21 +171,19 @@ function list_linkbacks( $args, $comments ) {
170171
} else {
171172
$classes = $r['li-class'];
172173
}
173-
// All of the list_linkbacks() calls right now are in linkbacks.php, and
174-
// they pass the mf2 class as the last li-class element, which is unique,
175-
// so use that.
176-
$id_class = $classes[ count( $classes ) - 1 ];
177-
$ellipsis_id = 'mention-ellipsis-' . $id_class;
178-
$fold_id = 'mentions-below-fold-' . $id_class;
179-
180-
$classes[] = 'h-cite';
181-
$classes = join( ' ', $classes );
182-
$return = sprintf( '<%1$s class="%2$s">', $r['style'], $r['style-class'] );
183-
$fold_at = get_option( 'semantic_linkbacks_facepiles_fold_limit', 8 );
174+
if ( is_string( $r['style-class'] ) ) {
175+
$r['style-class'] = explode( ' ', $r['style-class'] );
176+
}
177+
178+
$classes[] = 'linkback-' . $r['type'] . '-single';
179+
$r['style-class'][] = 'linkback-' . $r['type'];
180+
181+
$return = sprintf( '<%1$s class="%2$s">', $r['style'], join( ' ', $r['style-class'] ) );
182+
$fold_at = (int) get_option( 'semantic_linkbacks_facepiles_fold_limit', 8 );
184183

185184
foreach ( $comments as $i => $comment ) {
186185
if ( $fold_at && $i === $fold_at ) {
187-
$classes .= ' additional-facepile';
186+
$classes[] = 'additional-facepile';
188187
}
189188

190189
// If it's an emoji reaction, overlay the emoji.
@@ -201,6 +200,8 @@ function list_linkbacks( $args, $comments ) {
201200
preg_replace( '/^www\./', '', $url )
202201
);
203202
}
203+
$class = get_comment_class( $classes, $comment );
204+
$class = join( ' ', $class );
204205

205206
$return .= sprintf(
206207
'<li class="%1$s" id="%5$s">
@@ -210,7 +211,7 @@ function list_linkbacks( $args, $comments ) {
210211
</span>
211212
<a class="u-url" href="%7$s"></a>
212213
</li>',
213-
$classes,
214+
$class,
214215
get_avatar( $comment, $r['avatar_size'] ),
215216
get_comment_author_url( $comment ),
216217
get_comment_author( $comment ),

readme.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ The Webmention and Pingback logos are made by [Aaron Parecki](http://aaronpareck
6868

6969
Project actively developed on Github at [pfefferle/wordpress-semantic-linkbacks](https://github.com/pfefferle/wordpress-semantic-linkbacks). Please file support issues there.
7070

71+
= 3.7.3 =
72+
* Remove `h-as` properties
73+
* Remove hard-coded microformats2 properties from facepile and move them to being generated from comment_class
74+
* Remove unused properties
75+
* Introduce type argument in list_linkbacks to generate unique ideas for each list of linkbacks without having to specify them using style and li-class
76+
7177
= 3.7.2 =
7278

7379
* Bugfix: "Normal comments" hidden in comment-section (https://github.com/pfefferle/wordpress-semantic-linkbacks/issues/140)

templates/linkbacks.php

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<?php
55
list_linkbacks(
66
array(
7-
'li-class' => array( 'single-mention', 'p-reply', 'emoji-reaction' ),
7+
'type' => 'reacji',
88
),
99
Semantic_Linkbacks_Walker_Comment::$reactions
1010
);
@@ -18,7 +18,7 @@
1818
<?php
1919
list_linkbacks(
2020
array(
21-
'li-class' => array( 'single-mention', 'p-like' ),
21+
'type' => 'like',
2222
),
2323
get_linkbacks( 'like' )
2424
);
@@ -32,7 +32,7 @@
3232
<?php
3333
list_linkbacks(
3434
array(
35-
'li-class' => array( 'single-mention', 'p-favorite' ),
35+
'type' => 'favorite',
3636
),
3737
get_linkbacks( 'favorite' )
3838
);
@@ -46,7 +46,7 @@
4646
<?php
4747
list_linkbacks(
4848
array(
49-
'li-class' => array( 'single-mention', 'p-bookmark' ),
49+
'type' => 'bookmark',
5050
),
5151
get_linkbacks( 'bookmark' )
5252
);
@@ -60,7 +60,7 @@
6060
<?php
6161
list_linkbacks(
6262
array(
63-
'li-class' => array( 'single-mention', 'p-repost' ),
63+
'type' => 'repost',
6464
),
6565
get_linkbacks( 'repost' )
6666
);
@@ -74,7 +74,7 @@
7474
<?php
7575
list_linkbacks(
7676
array(
77-
'li-class' => array( 'single-mention', 'p-tag' ),
77+
'type' => 'tag',
7878
),
7979
get_linkbacks( 'tag' )
8080
);
@@ -91,10 +91,7 @@
9191
<?php
9292
list_linkbacks(
9393
array(
94-
'li-class' => array(
95-
'single-mention',
96-
'p-rsvp',
97-
)
94+
'type' => 'rsvp-yes',
9895
),
9996
get_linkbacks( 'rsvp:yes' )
10097
);
@@ -106,10 +103,7 @@
106103
<?php
107104
list_linkbacks(
108105
array(
109-
'li-class' => array(
110-
'single-mention',
111-
'p-rsvp',
112-
)
106+
'type' => 'invited',
113107
),
114108
get_linkbacks( 'rsvp:invited' )
115109
);
@@ -121,10 +115,7 @@
121115
<?php
122116
list_linkbacks(
123117
array(
124-
'li-class' => array(
125-
'single-mention',
126-
'p-rsvp',
127-
)
118+
'type' => 'rsvp-maybe',
128119
),
129120
get_linkbacks( 'rsvp:maybe' )
130121
);
@@ -136,10 +127,7 @@
136127
<?php
137128
list_linkbacks(
138129
array(
139-
'li-class' => array(
140-
'single-mention',
141-
'p-rsvp',
142-
)
130+
'type' => 'rsvp-no',
143131
),
144132
get_linkbacks( 'rsvp:no' )
145133
);
@@ -151,10 +139,7 @@
151139
<?php
152140
list_linkbacks(
153141
array(
154-
'li-class' => array(
155-
'single-mention',
156-
'p-rsvp',
157-
)
142+
'type' => 'rsvp-tracking',
158143
),
159144
get_linkbacks( 'rsvp:tracking' )
160145
);
@@ -169,7 +154,7 @@
169154
<?php
170155
list_linkbacks(
171156
array(
172-
'li-class' => array( 'single-mention', 'p-mention' ),
157+
'type' => 'mention',
173158
),
174159
get_linkbacks( 'mention' )
175160
);

tests/test-rendering.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function make_comments( $num, $semantic_linkbacks_type = 'like' ) {
3030
public function test_facepile_markup() {
3131
$comments = $this->make_comments( 1 );
3232
$this->assertStringMatchesFormat(
33-
'<ul class="mention-list"><li class="single-mention h-cite" id="comment-2">
33+
'<ul class="mention-list linkback-mention"><li class="webmention even thread-even depth-1 linkback-mention-single u-like h-cite" id="comment-2">
3434
<span class="p-author h-card">
3535
<a class="u-url" title="Person 0 liked this Article on example.com." href="http://example.com/person0"><img alt=\'\' src=\'http://example.com/photo\' srcset=\'http://example.com/photo 2x\' class=\'avatar avatar-64 photo avatar-default u-photo avatar-semantic-linkbacks\' height=\'64\' width=\'64\' /> </a>
3636
<span class="hide-name p-name">Person 0</span>
@@ -105,7 +105,7 @@ public function test_reactions() {
105105
$this->assertStringMatchesFormat(
106106
'<div class="reactions">
107107
<h3>Reacjis</h3>
108-
<ul class="mention-list"><li class="single-mention p-reply emoji-reaction h-cite" id="comment-%d">
108+
<ul class="mention-list linkback-reacji"><li class="comment even thread-even depth-1 linkback-reacji-single h-cite" id="comment-%d">
109109
<span class="p-author h-card">
110110
<a class="u-url" title="Person 😢 on example.com." href="http://example.com/person"><img alt=\'\' src=\'http://example.com/photo\' srcset=\'http://example.com/photo 2x\' class=\'avatar avatar-64 photo avatar-default u-photo avatar-semantic-linkbacks\' height=\'64\' width=\'64\' /> <span class="emoji-overlay">😢</span></a>
111111
<span class="hide-name p-name">Person</span>

0 commit comments

Comments
 (0)