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

Commit 1f87b1b

Browse files
authored
Merge pull request #108 from dshanske/templates
thanks!
2 parents 06b6f31 + 855a670 commit 1f87b1b

File tree

5 files changed

+351
-101
lines changed

5 files changed

+351
-101
lines changed

css/semantic-linkbacks.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.mention-list ul {
2+
border-style: solid;
3+
}
4+
5+
.mention-list li {
6+
display: inline-block;
7+
list-style: none;
8+
vertical-align: top;
9+
margin-left: 3px;
10+
}
11+
12+
.mention-list .hide-name {
13+
display: none;
14+
}
15+
16+
.mention-list li img {
17+
border-radius: 4px;
18+
height: 64px;
19+
width: 64px;
20+
display: block;
21+
object-fit: fill;
22+
}

includes/class-linkbacks-handler.php

Lines changed: 121 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,70 @@ public static function init() {
3333
add_filter( 'get_avatar_comment_types', array( 'Linkbacks_Handler', 'get_avatar_comment_types' ) );
3434
add_filter( 'comment_class', array( 'Linkbacks_Handler', 'comment_class' ), 10, 4 );
3535

36+
add_filter( 'wp_list_comments_args', array( 'Linkbacks_Handler', 'filter_comment_args' ) );
37+
add_action( 'comment_form_before', array( 'Linkbacks_Handler', 'show_mentions' ) );
38+
3639
// Register Meta Keys
3740
self::register_meta();
3841
}
3942

43+
/**
44+
* Filter the comments and ignore every comment other than 'comment'
45+
*
46+
* @param array $args an array of arguments for displaying comments
47+
*
48+
* @return array the filtered array
49+
*/
50+
public static function filter_comment_args( $args ) {
51+
$args['type'] = 'comment';
52+
53+
return $args;
54+
}
55+
56+
/**
57+
*
58+
*
59+
*/
60+
public static function show_mentions() {
61+
load_template( plugin_dir_path( dirname( __FILE__ ) ) . 'templates/linkbacks.php' );
62+
}
63+
4064
/**
4165
* This is more to lay out the data structure than anything else.
4266
*/
4367
public static function register_meta() {
4468
$args = array(
45-
'sanitize_callback' => 'esc_url_raw',
46-
'type' => 'string',
47-
'description' => 'Author URL',
48-
'single' => true,
49-
'show_in_rest' => true,
69+
'sanitize_callback' => 'esc_url_raw',
70+
'type' => 'string',
71+
'description' => 'Author URL',
72+
'single' => true,
73+
'show_in_rest' => true,
5074
);
5175
register_meta( 'comment', 'semantic_linkbacks_author_url', $args );
5276

5377
$args = array(
54-
'sanitize_callback' => 'esc_url_raw',
55-
'type' => 'string',
56-
'description' => 'Avatar URL',
57-
'single' => true,
58-
'show_in_rest' => true,
78+
'sanitize_callback' => 'esc_url_raw',
79+
'type' => 'string',
80+
'description' => 'Avatar URL',
81+
'single' => true,
82+
'show_in_rest' => true,
5983
);
6084
register_meta( 'comment', 'semantic_linkbacks_avatar', $args );
6185

6286
$args = array(
63-
'sanitize_callback' => 'esc_url_raw',
64-
'type' => 'string',
65-
'description' => 'Canonical URL',
66-
'single' => true,
67-
'show_in_rest' => true,
87+
'sanitize_callback' => 'esc_url_raw',
88+
'type' => 'string',
89+
'description' => 'Canonical URL',
90+
'single' => true,
91+
'show_in_rest' => true,
6892
);
6993
register_meta( 'comment', 'semantic_linkbacks_canonical', $args );
7094

7195
$args = array(
72-
'type' => 'string',
73-
'description' => 'Linkbacks Type',
74-
'single' => true,
75-
'show_in_rest' => true,
96+
'type' => 'string',
97+
'description' => 'Linkbacks Type',
98+
'single' => true,
99+
'show_in_rest' => true,
76100
);
77101
register_meta( 'comment', 'semantic_linkbacks_type', $args );
78102
}
@@ -131,10 +155,10 @@ public static function retrieve( $url ) {
131155
global $wp_version;
132156
$user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
133157
$args = array(
134-
'timeout' => 100,
135-
'limit_response_size' => 1048576,
136-
'redirection' => 20,
137-
'user-agent' => "$user_agent; verifying linkback",
158+
'timeout' => 100,
159+
'limit_response_size' => 1048576,
160+
'redirection' => 20,
161+
'user-agent' => "$user_agent; verifying linkback",
138162
);
139163
return wp_safe_remote_get( $url, $args );
140164
}
@@ -162,20 +186,20 @@ public static function update_meta( $comment_id, $commentdata ) {
162186
*/
163187
public static function get_comment_type_excerpts() {
164188
$strings = array(
165-
// special case. any value that evals to false will be considered standard
166-
'mention' => __( '%1$s mentioned %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
167-
168-
'reply' => __( '%1$s replied to %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
169-
'repost' => __( '%1$s reposted %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
170-
'like' => __( '%1$s liked %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
171-
'favorite' => __( '%1$s favorited %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
172-
'tag' => __( '%1$s tagged %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
173-
'bookmark' => __( '%1$s bookmarked %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
174-
'rsvp:yes' => __( '%1$s is <strong>attending</strong>.', 'semantic-linkbacks' ),
175-
'rsvp:no' => __( '%1$s is <strong>not attending</strong>.', 'semantic-linkbacks' ),
176-
'rsvp:maybe' => __( 'Maybe %1$s will be <strong>attending</strong>.', 'semantic-linkbacks' ),
177-
'rsvp:invited' => __( '%1$s is <strong>invited</strong>.', 'semantic-linkbacks' ),
178-
'rsvp:tracking' => __( '%1$s <strong>tracks</strong> this event.', 'semantic-linkbacks' ),
189+
// special case. any value that evals to false will be considered standard
190+
'mention' => __( '%1$s mentioned %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
191+
192+
'reply' => __( '%1$s replied to %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
193+
'repost' => __( '%1$s reposted %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
194+
'like' => __( '%1$s liked %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
195+
'favorite' => __( '%1$s favorited %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
196+
'tag' => __( '%1$s tagged %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
197+
'bookmark' => __( '%1$s bookmarked %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
198+
'rsvp:yes' => __( '%1$s is <strong>attending</strong>.', 'semantic-linkbacks' ),
199+
'rsvp:no' => __( '%1$s is <strong>not attending</strong>.', 'semantic-linkbacks' ),
200+
'rsvp:maybe' => __( 'Maybe %1$s will be <strong>attending</strong>.', 'semantic-linkbacks' ),
201+
'rsvp:invited' => __( '%1$s is <strong>invited</strong>.', 'semantic-linkbacks' ),
202+
'rsvp:tracking' => __( '%1$s <strong>tracks</strong> this event.', 'semantic-linkbacks' ),
179203
);
180204

181205
return $strings;
@@ -188,20 +212,20 @@ public static function get_comment_type_excerpts() {
188212
*/
189213
public static function get_comment_type_strings() {
190214
$strings = array(
191-
// Special case. any value that evals to false will be considered standard
192-
'mention' => __( 'Mention', 'semantic-linkbacks' ),
193-
194-
'reply' => __( 'Reply', 'semantic-linkbacks' ),
195-
'repost' => __( 'Repost', 'semantic-linkbacks' ),
196-
'like' => __( 'Like', 'semantic-linkbacks' ),
197-
'favorite' => __( 'Favorite', 'semantic-linkbacks' ),
198-
'tag' => __( 'Tag', 'semantic-linkbacks' ),
199-
'bookmark' => __( 'Bookmark', 'semantic-linkbacks' ),
200-
'rsvp:yes' => __( 'RSVP', 'semantic-linkbacks' ),
201-
'rsvp:no' => __( 'RSVP', 'semantic-linkbacks' ),
202-
'rsvp:invited' => __( 'RSVP', 'semantic-linkbacks' ),
203-
'rsvp:maybe' => __( 'RSVP', 'semantic-linkbacks' ),
204-
'rsvp:tracking' => __( 'RSVP', 'semantic-linkbacks' ),
215+
// Special case. any value that evals to false will be considered standard
216+
'mention' => __( 'Mention', 'semantic-linkbacks' ),
217+
218+
'reply' => __( 'Reply', 'semantic-linkbacks' ),
219+
'repost' => __( 'Repost', 'semantic-linkbacks' ),
220+
'like' => __( 'Like', 'semantic-linkbacks' ),
221+
'favorite' => __( 'Favorite', 'semantic-linkbacks' ),
222+
'tag' => __( 'Tag', 'semantic-linkbacks' ),
223+
'bookmark' => __( 'Bookmark', 'semantic-linkbacks' ),
224+
'rsvp:yes' => __( 'RSVP', 'semantic-linkbacks' ),
225+
'rsvp:no' => __( 'RSVP', 'semantic-linkbacks' ),
226+
'rsvp:invited' => __( 'RSVP', 'semantic-linkbacks' ),
227+
'rsvp:maybe' => __( 'RSVP', 'semantic-linkbacks' ),
228+
'rsvp:tracking' => __( 'RSVP', 'semantic-linkbacks' ),
205229
);
206230

207231
return $strings;
@@ -214,18 +238,18 @@ public static function get_comment_type_strings() {
214238
*/
215239
public static function get_post_format_strings() {
216240
$strings = array(
217-
// Special case. any value that evals to false will be considered standard
218-
'standard' => __( 'this Article', 'semantic-linkbacks' ),
219-
220-
'aside' => __( 'this Aside', 'semantic-linkbacks' ),
221-
'chat' => __( 'this Chat', 'semantic-linkbacks' ),
222-
'gallery' => __( 'this Gallery', 'semantic-linkbacks' ),
223-
'link' => __( 'this Link', 'semantic-linkbacks' ),
224-
'image' => __( 'this Image', 'semantic-linkbacks' ),
225-
'quote' => __( 'this Quote', 'semantic-linkbacks' ),
226-
'status' => __( 'this Status', 'semantic-linkbacks' ),
227-
'video' => __( 'this Video', 'semantic-linkbacks' ),
228-
'audio' => __( 'this Audio', 'semantic-linkbacks' ),
241+
// Special case. any value that evals to false will be considered standard
242+
'standard' => __( 'this Article', 'semantic-linkbacks' ),
243+
244+
'aside' => __( 'this Aside', 'semantic-linkbacks' ),
245+
'chat' => __( 'this Chat', 'semantic-linkbacks' ),
246+
'gallery' => __( 'this Gallery', 'semantic-linkbacks' ),
247+
'link' => __( 'this Link', 'semantic-linkbacks' ),
248+
'image' => __( 'this Image', 'semantic-linkbacks' ),
249+
'quote' => __( 'this Quote', 'semantic-linkbacks' ),
250+
'status' => __( 'this Status', 'semantic-linkbacks' ),
251+
'video' => __( 'this Video', 'semantic-linkbacks' ),
252+
'audio' => __( 'this Audio', 'semantic-linkbacks' ),
229253
);
230254

231255
return $strings;
@@ -322,8 +346,8 @@ public static function comment_text_add_cite( $text, $comment = null, $args = ar
322346

323347
// only change text for "real" comments (replys)
324348
if ( ! $semantic_linkbacks_type ||
325-
'' != $comment->comment_type ||
326-
'reply' != $semantic_linkbacks_type ) {
349+
'' != $comment->comment_type ||
350+
'reply' != $semantic_linkbacks_type ) {
327351
return $text;
328352
}
329353

@@ -362,8 +386,8 @@ public static function comment_text_excerpt( $text, $comment = null, $args = arr
362386

363387
// only change text for pingbacks/trackbacks/webmentions
364388
if ( '' == $comment->comment_type ||
365-
! $semantic_linkbacks_type ||
366-
'reply' == $semantic_linkbacks_type ) {
389+
! $semantic_linkbacks_type ||
390+
'reply' == $semantic_linkbacks_type ) {
367391
return $text;
368392
}
369393

@@ -382,28 +406,28 @@ public static function comment_text_excerpt( $text, $comment = null, $args = arr
382406
}
383407
}
384408

385-
// get post type
386-
$post_formatstrings = self::get_post_format_strings();
387-
$post_type = $post_formatstrings[ $post_format ];
409+
// get post type
410+
$post_formatstrings = self::get_post_format_strings();
411+
$post_type = $post_formatstrings[ $post_format ];
388412

389-
$post_type = apply_filters( 'semantic_linkbacks_post_type', $post_type, $comment->comment_post_ID );
413+
$post_type = apply_filters( 'semantic_linkbacks_post_type', $post_type, $comment->comment_post_ID );
390414

391-
// get all the excerpts
392-
$comment_type_excerpts = self::get_comment_type_excerpts();
415+
// get all the excerpts
416+
$comment_type_excerpts = self::get_comment_type_excerpts();
393417

394-
$url = self::get_url( $comment );
418+
$url = self::get_url( $comment );
395419

396-
// parse host
397-
$host = wp_parse_url( $url, PHP_URL_HOST );
398-
// strip leading www, if any
399-
$host = preg_replace( '/^www\./', '', $host );
420+
// parse host
421+
$host = wp_parse_url( $url, PHP_URL_HOST );
422+
// strip leading www, if any
423+
$host = preg_replace( '/^www\./', '', $host );
400424

401-
// generate output. use full content if it's small enough, otherwise use excerpt.
425+
// generate output. use full content if it's small enough, otherwise use excerpt.
402426
if ( ! ( 'mention' == $semantic_linkbacks_type && strlen( wp_strip_all_tags( $text ) ) <= MAX_INLINE_MENTION_LENGTH ) ) {
403427
$text = sprintf( $comment_type_excerpts[ $semantic_linkbacks_type ], get_comment_author_link( $comment->comment_ID ), $post_type, $url, $host );
404428
}
405429

406-
return apply_filters( 'semantic_linkbacks_excerpt', $text );
430+
return apply_filters( 'semantic_linkbacks_excerpt', $text );
407431
}
408432

409433
/**
@@ -431,17 +455,17 @@ public static function get_avatar_url( $comment ) {
431455
*/
432456
public static function pre_get_avatar_data( $args, $id_or_email ) {
433457
if ( ! $id_or_email instanceof WP_Comment ||
434-
! isset( $id_or_email->comment_type ) ||
435-
$id_or_email->user_id ) {
436-
return $args;
458+
! isset( $id_or_email->comment_type ) ||
459+
$id_or_email->user_id ) {
460+
return $args;
437461
}
438462

439463
// check if comment has an avatar
440464
$avatar = self::get_avatar_url( $id_or_email->comment_ID );
441465

442466
if ( $avatar ) {
443467
if ( ! isset( $args['class'] ) ) {
444-
$args['class'] = array( 'u-photo' );
468+
$args['class'] = array( 'u-photo' );
445469
} else {
446470
$args['class'][] = 'u-photo';
447471
$args['class'] = array_unique( $args['class'] );
@@ -501,19 +525,19 @@ public static function comment_class( $classes, $class, $comment_id, $post_id )
501525

502526
// "comment type to class" mapper
503527
$class_mapping = array(
504-
'mention' => array( 'h-as-mention' ),
505-
506-
'reply' => array( 'h-as-reply' ),
507-
'repost' => array( 'h-as-repost', 'p-repost' ),
508-
'like' => array( 'h-as-like', 'p-like' ),
509-
'favorite' => array( 'h-as-favorite', 'p-favorite' ),
510-
'tag' => array( 'h-as-tag', 'p-tag' ),
511-
'bookmark' => array( 'h-as-bookmark', 'p-bookmark' ),
512-
'rsvp:yes' => array( 'h-as-rsvp' ),
513-
'rsvp:no' => array( 'h-as-rsvp' ),
514-
'rsvp:maybe' => array( 'h-as-rsvp' ),
515-
'rsvp:invited' => array( 'h-as-rsvp' ),
516-
'rsvp:tracking' => array( 'h-as-rsvp' ),
528+
'mention' => array( 'h-as-mention' ),
529+
530+
'reply' => array( 'h-as-reply' ),
531+
'repost' => array( 'h-as-repost', 'p-repost' ),
532+
'like' => array( 'h-as-like', 'p-like' ),
533+
'favorite' => array( 'h-as-favorite', 'p-favorite' ),
534+
'tag' => array( 'h-as-tag', 'p-tag' ),
535+
'bookmark' => array( 'h-as-bookmark', 'p-bookmark' ),
536+
'rsvp:yes' => array( 'h-as-rsvp' ),
537+
'rsvp:no' => array( 'h-as-rsvp' ),
538+
'rsvp:maybe' => array( 'h-as-rsvp' ),
539+
'rsvp:invited' => array( 'h-as-rsvp' ),
540+
'rsvp:tracking' => array( 'h-as-rsvp' ),
517541
);
518542

519543
$semantic_linkbacks_type = self::get_type( $comment );

0 commit comments

Comments
 (0)