6
6
Description:
7
7
Author: Jean-Sébastien Mansart
8
8
Author URI: http://jihais.se
9
- Version: 0.2
9
+ Version: 0.3
10
10
License: GPL2++
11
- Contributors: Peter Molnar
11
+ Contributors: Peter Molnar, Ryan Barrett
12
12
*/
13
13
14
14
// function to add markup at the end of the post
@@ -23,9 +23,12 @@ function add_js_rel_syndication($content) {
23
23
elseif ( defined ( 'NextScripts_SNAP_Version ' ) ) {
24
24
$ see_on = getRelSyndicationFromSNAP ();
25
25
}
26
+ else {
27
+ $ see_on = getRelSyndicationFromBridgyPublish ();
28
+ }
26
29
27
30
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> " ;
29
32
}
30
33
// Returns the content.
31
34
return $ content ;
@@ -170,4 +173,34 @@ function getRelSyndicationFromSNAP() {
170
173
171
174
return $ see_on_social ;
172
175
}
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
+
173
206
?>
0 commit comments