Skip to content

Commit e3c0071

Browse files
author
jihaisse
committed
Merge pull request #3 from snarfed/master
add bridgy publish support, fix u-syndication class
2 parents 28c5edd + 07ce405 commit e3c0071

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

readme.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ see http://indiewebcamp.com/rel-syndication
3737

3838
* partial ( Facebook, Twitter & Tumblr only ) support for Social Networks Auto Poster {SNAP}
3939

40-
= Supported plugins =
40+
= Supported POSSE plugins and implementations =
4141

4242
* Social plugin is fully supported (http://wordpress.org/plugins/social/)
4343
* partial ( Facebook, Twitter & Tumblr only ) support for Social Networks Auto Poster {SNAP}
44+
* Bridgy Publish (https://www.brid.gy/about#publish). Requires the
45+
wordpress-webmention plugin (https://wordpress.org/plugins/webmention/).

rel-syndication.php

+36-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
Description:
77
Author: Jean-Sébastien Mansart
88
Author URI: http://jihais.se
9-
Version: 0.2
9+
Version: 0.3
1010
License: GPL2++
11-
Contributors: Peter Molnar
11+
Contributors: Peter Molnar, Ryan Barrett
1212
*/
1313

1414
// function to add markup at the end of the post
@@ -23,9 +23,12 @@ function add_js_rel_syndication($content) {
2323
elseif ( defined ( 'NextScripts_SNAP_Version' ) ) {
2424
$see_on = getRelSyndicationFromSNAP();
2525
}
26+
else {
27+
$see_on = getRelSyndicationFromBridgyPublish();
28+
}
2629

2730
if ($see_on !== ""){
28-
$content = $content . '<div class="usyndication">' . __("Also on:", "rel-syndication") . $see_on . "</div>";
31+
$content = $content . '<div class="u-syndication">' . __("Also on:", "rel-syndication") . $see_on . "</div>";
2932
}
3033
// Returns the content.
3134
return $content;
@@ -170,4 +173,34 @@ function getRelSyndicationFromSNAP() {
170173

171174
return $see_on_social;
172175
}
176+
177+
function getRelSyndicationFromBridgyPublish() {
178+
$broadcasts = array();
179+
foreach (get_post_custom_values('bridgy_publish_syndication_urls', get_the_ID()) as $key => $link) {
180+
array_push($broadcasts, '<li>' . $link . '</li>');
181+
}
182+
if ($broadcasts) {
183+
return '<ul>' . implode("\n", $broadcasts) . '</ul>';
184+
} else {
185+
return '';
186+
}
187+
}
188+
189+
function store_bridgy_publish_link($response, $source, $target, $post_ID) {
190+
if (!$post_ID) {
191+
return;
192+
}
193+
194+
$json = json_decode(wp_remote_retrieve_body($response));
195+
if (!is_wp_error($response) && $json && $json->url &&
196+
preg_match('~https?://(?:www\.)?(brid.gy|localhost:8080)/publish/(.*)~', $target, $matches)) {
197+
$link = '<a href="' . $json->url . '">' . ucfirst($matches[2]) . '</a>';
198+
$existing = get_post_custom_values('bridgy_publish_syndication_urls', $post_ID);
199+
if (array_search($link, get_post_custom_values('bridgy_publish_syndication_urls', $post_ID)) == false) {
200+
add_post_meta($post_ID, 'bridgy_publish_syndication_urls', $link);
201+
}
202+
}
203+
}
204+
add_action('webmention_post_send', 'store_bridgy_publish_link', 10, 4);
205+
173206
?>

0 commit comments

Comments
 (0)