public
Created

AccountManager

  • Download Gist
account-manager.php
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 95 96 97 98
<?php
/*
Plugin Name: Account Manager
Plugin URI: http://notizblog.org/projects/apml-for-wordpress/
Description:
Version: 0.1
Author: Matthias Pfefferle
Author URI: http://notizblog.org/
*/
add_filter('query_vars', array('MozillaAccountManager', 'queryVars'));
add_action('parse_request', array('MozillaAccountManager', 'parseRequest'));
add_action('host_meta_xrd', array('MozillaAccountManager', 'hostMetaXrd'));
add_action('init', array('MozillaAccountManager', 'init'));
 
// Pre-2.6 compatibility
if ( ! defined( 'WP_CONTENT_URL' ) )
define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
if ( ! defined( 'WP_CONTENT_DIR' ) )
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
if ( ! defined( 'WP_PLUGIN_URL' ) )
define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
if ( ! defined( 'WP_PLUGIN_DIR' ) )
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
 
class MozillaAccountManager {
/**
*
*/
function init(){
global $current_user;
global $user_ID;
get_currentuserinfo();
header('X-Account-Management: '.get_option( 'siteurl' ).'/?account-manager=amcd');
if ('' == $user_ID) {
header('X-Account-Management-Status: passive;');
} else {
header('X-Account-Management-Status: active; name="'.$current_user->display_name.'"');
}
}
 
/**
* Add 'account-manager' as a valid query variables.
*
* @param array $vars
* @return array
*/
function queryVars($vars) {
$vars[] = 'account-manager';
 
return $vars;
}
/**
* Print APML document if 'apml' query variable is present
*/
function parseRequest() {
global $wp_query, $wp;
 
if( array_key_exists('account-manager', $wp->query_vars) ) {
if ($wp->query_vars['account-manager'] == 'amcd') {
MozillaAccountManager::printAmcd();
}
}
}
 
function printAmcd() {
$connect = array();
$connect = array('method' => 'POST',
'path' => get_option( 'siteurl' ).'/wp-login.php',
'params' => array('username' => 'log', 'password' => 'pwd')
);
$disconnect = array('method' => 'GET',
'path' => wp_logout_url()
);
$amcd = array();
$amcd['methods'] = array("username-password-form" => array('connect' => $connect,
'disconnect' => $disconnect,
'sessionstatus' => $sessionstatus)
);
header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);
echo json_encode($amcd);
exit;
}
/**
* Contribute the APML Service to Webfinger.
*/
function hostMetaXrd() {
echo "<Link rel='http://services.mozilla.com/amcd/0.1' href='".get_option( 'siteurl' )."/?account-manager=amcd' />";
}
}
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.