Skip to content

Commit

Permalink
some changes for host-meta
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle committed May 21, 2011
1 parent 6dac493 commit faa1282
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 40 deletions.
33 changes: 5 additions & 28 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
Plugin Name: /.well-known/
Plugin URI: http://notizblog.org/
Description: This plugin enables "Well-Known URIs" support for WordPress (RFC 5785: http://tools.ietf.org/html/rfc5785).
Version: 0.2.1.1
Version: 0.4
Author: Matthias Pfefferle
Author URI: http://notizblog.org/
*/

//
add_action('admin_init', 'flush_rewrite_rules');
add_filter('query_vars', array('WellKnownPlugin', 'queryVars'));
add_action('parse_request', array('WellKnownPlugin', 'delegateRequest'));
add_action('generate_rewrite_rules', array('WellKnownPlugin', 'rewriteRules'));
register_activation_hook(__FILE__, array('WellKnownPlugin', 'activationHook'));

/**
* well-known class
Expand All @@ -28,18 +28,9 @@ class WellKnownPlugin {
*/
function queryVars($vars) {
$vars[] = 'well-known';

return $vars;
}

/**
* activation hook
*/
function activationHook() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}

/**
* Add rewrite rules for .well-known.
*
Expand All @@ -57,23 +48,9 @@ function rewriteRules($wp_rewrite) {
* delegates the request to the matching (registered) class
*/
function delegateRequest() {
global $wp_query, $wp;

$wellKnown = array();
$wellKnown = apply_filters('well-known', $wellKnown);

$queryVars = $wp->query_vars;

if( array_key_exists('well-known', $queryVars) ) {
if (array_key_exists($queryVars['well-known'], $wellKnown)) {
$remoteFunction = $wellKnown[$queryVars['well-known']];

call_user_func($remoteFunction);
} else {
header("HTTP/1.1 404 Not Found");
echo "there is no such uri: /.well-known/".$queryVars['well-known'];
}

global $wp;
if( isset($wp->query_vars['well-known']) ) {
do_action("well-known", $wp->query_vars);
exit;
}
}
Expand Down
26 changes: 14 additions & 12 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Contributors: Matthias Pfefferle
Donate link: http://www.14101978.de
Tags: OpenID, XRD, well-known, XML, Discovery
Requires at least: 2.7
Tested up to: 2.9.9
Stable tag: 0.2.1.1
Requires at least: 3.2
Tested up to: 3.2.9
Stable tag: 0.3

This plugin enables "Well-Known URIs" support for WordPress (RFC 5785: http://tools.ietf.org/html/rfc5785).

Expand Down Expand Up @@ -37,6 +37,10 @@ From the RFC:

== Changelog ==

= 0.4 =
* some improvements for host-meta (jrd)
= 0.3 =
* adding well-known uris a bit more wordpress-like
= 0.2.1.1 =
* Ooops, copy&paste bug
= 0.2.1 =
Expand All @@ -60,23 +64,21 @@ From the RFC:
Set a callback for an URI (/.well-known/robots.txt)


`add_filter('well-known', array('RobotsTxt', 'robotsUri'));
function robotsUri($wellKnown) {
return $wellKnown[] = array('robots.txt' => array('RobotsTxt', 'printHostMeta'));
}`
`add_action('well-known', 'robots_txt');`


Print robots.txt:


`function printHostMeta() {
header('Content-Type: text/plain; charset=' . get_option('blog_charset'), true);
echo "User-agent: *";
echo "Allow: /";
`function robots_txt($query) {
if ($query == "robots.txt") {
header('Content-Type: text/plain; charset=' . get_option('blog_charset'), true);
echo "User-agent: *";
echo "Allow: /";
}
}`

= Is there an implementation where I can write off? =


Yes, you can find an example plugin, which defines a well-known-uri,
here: http://wordpress.org/extend/plugins/host-meta/

0 comments on commit faa1282

Please sign in to comment.