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

Commit 5008474

Browse files
authored
Merge pull request #148 from dshanske/swarm-coins
Add Swarm Coins property support
2 parents ba9eee4 + fc54219 commit 5008474

File tree

6 files changed

+68
-24
lines changed

6 files changed

+68
-24
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Project actively developed on Github at [pfefferle/wordpress-semantic-linkbacks]
7373
* Remove hard-coded microformats2 properties from facepile and move them to being generated from comment_class
7474
* Remove unused properties
7575
* 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+
* Whitelist property swarm-coins, used by [OwnYourSwarm](https://ownyourswarm.p3k.io/docs#coins) and display it if using built-in comment handler.
7677

7778
### 3.7.2 ###
7879

includes/class-linkbacks-handler.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,33 @@ public static function get_canonical_url( $comment ) {
327327
* @return string the type
328328
*/
329329
public static function get_type( $comment ) {
330-
if ( is_numeric( $comment ) ) {
331-
$comment = get_comment( $comment );
330+
if ( $comment instanceof WP_Comment ) {
331+
$comment = $comment->comment_ID;
332332
}
333333
// get type...
334-
return get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_type', true );
334+
return get_comment_meta( $comment, 'semantic_linkbacks_type', true );
335+
}
336+
337+
/**
338+
* Return property
339+
*
340+
* @param int|WP_Comment $comment Comment
341+
* @param string $key Key
342+
*
343+
* @return boolean|string|array Property or False if Property Does Not Exist
344+
*/
345+
public static function get_prop( $comment, $key ) {
346+
if ( $comment instanceof WP_Comment ) {
347+
$comment = $comment->comment_ID;
348+
}
349+
$prop = get_comment_meta( $comment, $key );
350+
if ( ! $prop || is_string( $prop ) ) {
351+
return $prop;
352+
}
353+
if ( 1 === count( $prop ) ) {
354+
return array_shift( $prop );
355+
}
356+
return $prop;
335357
}
336358

337359

@@ -343,11 +365,11 @@ public static function get_type( $comment ) {
343365
* @return string the URL
344366
*/
345367
public static function get_author_url( $comment ) {
346-
if ( is_numeric( $comment ) ) {
347-
$comment = get_comment( $comment );
368+
if ( $comment instanceof WP_Comment ) {
369+
$comment = $comment->comment_ID;
348370
}
349371
// get author URL...
350-
return get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_author_url', true );
372+
return get_comment_meta( $comment, 'semantic_linkbacks_author_url', true );
351373
}
352374

353375
/**

includes/class-linkbacks-mf2-handler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ public static function generate_commentdata( $commentdata ) {
257257
'audio',
258258
'photo',
259259
'featured',
260+
'swarm-coins' // https://ownyourswarm.p3k.io/docs#coins
260261
);
261262

262263
// Add in supported properties

includes/class-linkbacks-walker-comment.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ protected function html5_comment( $comment, $depth, $args ) {
7676
parent::html5_comment( $comment, $depth, $args );
7777
return;
7878
}
79-
$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
80-
$cite = apply_filters( 'semantic_linkbacks_cite', '<small>&nbsp;@&nbsp;<cite><a href="%1s">%2s</a></cite></small>' );
81-
$type = Linkbacks_Handler::get_type( $comment );
82-
$url = Linkbacks_Handler::get_url( $comment );
83-
$host = wp_parse_url( $url, PHP_URL_HOST );
79+
$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
80+
$cite = apply_filters( 'semantic_linkbacks_cite', '<small>&nbsp;@&nbsp;<cite><a href="%1s">%2s</a></cite></small>' );
81+
$type = Linkbacks_Handler::get_type( $comment );
82+
$url = Linkbacks_Handler::get_url( $comment );
83+
$coins = Linkbacks_Handler::get_prop( $comment, 'mf2_swarm-coins' );
84+
$host = wp_parse_url( $url, PHP_URL_HOST );
8485
// strip leading www, if any
8586
$host = preg_replace( '/^www\./', '', $host );
8687

@@ -103,10 +104,21 @@ protected function html5_comment( $comment, $depth, $args ) {
103104
if ( $type && ! empty( $cite ) ) {
104105
printf( $cite, $url, $host );
105106
}
107+
106108
?>
107109
</div><!-- .comment-author -->
108110

109111
<div class="comment-metadata">
112+
<?php
113+
if ( $coins ) {
114+
// translators: Number of Swarm Coins
115+
printf( _n( '+%d coin', '+%d coins', (int) $coins, 'semantic-linkbacks' ), $coins );
116+
echo ' / ';
117+
}
118+
?>
119+
120+
121+
110122
<a class="u-url" href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
111123
<time class="dt-published" datetime="<?php comment_time( DATE_W3C ); ?>">
112124
<?php

languages/semantic-linkbacks.pot

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
# This file is distributed under the MIT.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: Semantic-Linkbacks 3.7.1\n"
5+
"Project-Id-Version: Semantic-Linkbacks 3.7.2\n"
66
"Report-Msgid-Bugs-To: "
7-
"https://wordpress.org/support/plugin/semantic-linkbacks\n"
8-
"POT-Creation-Date: 2017-12-05 21:30:18+00:00\n"
7+
"http://wordpress.org/support/plugin/semantic-linkbacks\n"
8+
"POT-Creation-Date: 2017-12-29 09:07:37+00:00\n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=utf-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
1212
"PO-Revision-Date: 2017-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
15-
"X-Generator: grunt-wp-i18n 0.5.4\n"
15+
"X-Generator: grunt-wp-i18n 0.4.9\n"
1616

1717
#: includes/class-linkbacks-handler.php:204
1818
#. translators: Name verb on domain
@@ -150,21 +150,28 @@ msgstr ""
150150
msgid "this Audio"
151151
msgstr ""
152152

153-
#: includes/class-linkbacks-walker-comment.php:104
153+
#: includes/class-linkbacks-walker-comment.php:101
154154
#. translators: %s: comment author link
155155
msgid "%s <span class=\"says\">says:</span>"
156156
msgstr ""
157157

158-
#: includes/class-linkbacks-walker-comment.php:118
158+
#: includes/class-linkbacks-walker-comment.php:115
159+
#. translators: Number of Swarm Coins
160+
msgid "+%d coin"
161+
msgid_plural "+%d coins"
162+
msgstr[0] ""
163+
msgstr[1] ""
164+
165+
#: includes/class-linkbacks-walker-comment.php:126
159166
#. translators: 1: comment date, 2: comment time
160167
msgid "%1$s at %2$s"
161168
msgstr ""
162169

163-
#: includes/class-linkbacks-walker-comment.php:122
170+
#: includes/class-linkbacks-walker-comment.php:130
164171
msgid "Edit"
165172
msgstr ""
166173

167-
#: includes/class-linkbacks-walker-comment.php:126
174+
#: includes/class-linkbacks-walker-comment.php:134
168175
msgid "Your response is awaiting moderation."
169176
msgstr ""
170177

@@ -214,7 +221,7 @@ msgid ""
214221
"for:"
215222
msgstr ""
216223

217-
#: templates/discussion-settings.php:7 templates/linkbacks.php:168
224+
#: templates/discussion-settings.php:7 templates/linkbacks.php:153
218225
msgid "Mentions"
219226
msgstr ""
220227

@@ -262,19 +269,19 @@ msgstr ""
262269
msgid "Yes"
263270
msgstr ""
264271

265-
#: templates/linkbacks.php:105
272+
#: templates/linkbacks.php:102
266273
msgid "Invited"
267274
msgstr ""
268275

269-
#: templates/linkbacks.php:120
276+
#: templates/linkbacks.php:114
270277
msgid "Maybe"
271278
msgstr ""
272279

273-
#: templates/linkbacks.php:135
280+
#: templates/linkbacks.php:126
274281
msgid "No"
275282
msgstr ""
276283

277-
#: templates/linkbacks.php:150
284+
#: templates/linkbacks.php:138
278285
msgid "Tracking"
279286
msgstr ""
280287

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Project actively developed on Github at [pfefferle/wordpress-semantic-linkbacks]
7373
* Remove hard-coded microformats2 properties from facepile and move them to being generated from comment_class
7474
* Remove unused properties
7575
* 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+
* Whitelist property swarm-coins, used by [OwnYourSwarm](https://ownyourswarm.p3k.io/docs#coins) and display it if using built-in comment handler.
7677

7778
= 3.7.2 =
7879

0 commit comments

Comments
 (0)