This repository was archived by the owner on Nov 29, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple-foaf.php
94 lines (80 loc) · 2.66 KB
/
simple-foaf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* Plugin Name: SimpleFOAF
* Plugin URI: http://notizblog.org/
* Description: FOAF RDF/XML profile.
* Version: 1.0.1
* Author: Matthias Pfefferle
* Author URI: http://notizblog.org/
* License: GPL-2.0
* License URI: http://opensource.org/licenses/GPL-2.0
*/
// based on the great work of
// http://www.wasab.dk/morten/blog/archives/2004/07/05/wordpress-plugin-foaf-output?version=1.17
add_action( 'init', array( 'SimpleFoafPlugin', 'init' ) );
register_activation_hook( __FILE__, array( 'SimpleFoafPlugin', 'flush_rewrite_rules' ) );
register_deactivation_hook( __FILE__, array( 'SimpleFoafPlugin', 'flush_rewrite_rules' ) );
class SimpleFoafPlugin {
/**
* init function
*/
public static function init() {
add_action( 'wp_head', array( 'SimpleFoafPlugin', 'add_header' ) );
add_filter( 'host_meta', array( 'SimpleFoafPlugin', 'add_host_meta_links' ) );
add_filter( 'webfinger_user_data', array( 'SimpleFoafPlugin', 'add_webfinger_links' ), 10, 3 );
// add 'foaf' as feed
add_action( 'do_feed_foaf', array( 'SimpleFoafPlugin', 'do_feed_foaf' ) );
add_feed( 'foaf', array( 'SimpleFoafPlugin', 'do_feed_foaf' ) );
}
/**
* reset rewrite rules
*/
public static function flush_rewrite_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
/**
* add link headers
*/
public static function add_header() {
if ( is_home() ) {
?>
<link rel="meta" type="application/rdf+xml" title="FOAF" href="<?php echo get_feed_link( 'foaf' ); ?>" />
<?php
} elseif ( is_author() ) {
if ( get_query_var( 'author_name' ) ) {
$authordata = get_user_by( 'slug', get_query_var( 'author_name' ) );
} else {
$authordata = get_userdata( get_query_var( 'author' ) );
}
?>
<link rel="meta" type="application/rdf+xml" title="FOAF" href="<?php echo get_author_feed_link( $authordata->ID, 'foaf' ); ?>" />
<?php
}
}
/**
* handles new feed type
*/
public static function do_feed_foaf() {
header( 'Content-type: application/rdf+xml' );
if ( is_author() ) {
load_template( dirname( __FILE__ ) . '/feed-foaf-author.php' );
} else {
load_template( dirname( __FILE__ ) . '/feed-foaf.php' );
}
}
/**
* add the host meta information
*/
public static function add_host_meta_links( $host_meta ) {
$host_meta['links'][] = array( 'rel' => 'describedby', 'href' => get_feed_link( 'foaf' ), 'type' => 'application/rdf+xml' );
return $host_meta;
}
/**
* add the host meta information
*/
public static function add_webfinger_links( $webfinger, $resource, $user ) {
$webfinger['links'][] = array( 'rel' => 'describedby', 'href' => get_author_feed_link( $user->ID, 'foaf' ), 'type' => 'application/rdf+xml' );
return $webfinger;
}
}