pax_global_header00006660000000000000000000000064120516067700014516gustar00rootroot0000000000000052 comment=a6f756e0dacef51ffdacbf6e6b21ae09d87c01f5 wordpress-xrds-simple-1.1/000077500000000000000000000000001205160677000156545ustar00rootroot00000000000000wordpress-xrds-simple-1.1/LICENSE000066400000000000000000000020471205160677000166640ustar00rootroot00000000000000Copyright (c) 2008 Stephen Paul Weber. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. wordpress-xrds-simple-1.1/readme.txt000066400000000000000000000030331205160677000176510ustar00rootroot00000000000000=== XRDS-Simple === Contributors: singpolyma, wnorris Tags: xrds, xrds-simple, discovery Requires at least: 2.1 Tested up to: 2.6.0 Stable tag: 1.1 Provides framework for other plugins to advertise services via XRDS. == Description == [XRDS-Simple][] is a profile of XRDS, a service discovery protocol which used in the [OpenID][] authentication specification as well as [OAuth][]. This plugin provides a generic framework to allow other plugins to contribute their own service endpoints to be included in the XRDS service document for the domain. [XRDS-Simple]: http://xrds-simple.net/ [OpenID]: http://openid.net/ [OAuth]: http://oauth.net/ == Installation == This plugin follows the [standard WordPress installation method][]: 1. Upload the `xrds-simple` folder to the `/wp-content/plugins/` directory 1. Activate the plugin through the 'Plugins' menu in WordPress [standard WordPress installation method]: http://codex.wordpress.org/Managing_Plugins#Installing_Plugins == Frequently Asked Questions == = How do I contribute services to the XRDS document = Implement the filter 'xrds_simple', and see the public functions at the top of the file. == Changelog == Project maintined on github at [diso/wordpress-xrds-simple](https://github.com/diso/wordpress-xrds-simple). = version 1.0 (Nov 16, 2012)= - fix various PHP and WordPress errors and warnings - add ability to fetch plain text XRDS document (mainly for debugging. see [example](http://willnorris.com/?xrds=1&format=text)) = version 1.0 (Oct 7, 2008) = - initial public release wordpress-xrds-simple-1.1/xrds-simple.php000066400000000000000000000206601205160677000206400ustar00rootroot00000000000000 $type, 'expires' => $expires, 'services' => array()); return $xrds; } /** * Convenience function for adding a new service endpoint to the XRDS structure. * * @param array $xrds current XRDS-Simple structure * @param string $id ID of the XRD to add the new service to. If no XRD exists with the specified ID, * a new one will be created. * @param string $name human readable name of the service * @param array $content content to be included in the service definition. Format: * * array( * 'NodeName (ie, Type)' => array( * array('attribute' => 'value', 'content' => 'content string'), * ... * ), * ... * ) * * @param int $priority service priorty * @return array updated XRDS-Simple structure * @since 1.0 */ function xrds_add_service($xrds, $xrd_id, $name, $content, $priority=10) { if (!array_key_exists($xrd_id, $xrds) || !is_array($xrds[$xrd_id])) { $xrds = xrds_add_xrd($xrds, $xrd_id); } $xrds[$xrd_id]['services'][$name] = array('priority' => $priority, 'content' => $content); return $xrds; } /** * Convenience function for adding a new service with minimal options. * Services will always be added to the 'main' XRD with the default priority. * No additional parameters such as httpMethod on URIs can be passed. If those * are necessary, use xrds_add_service(). * * @param array $xrds current XRDS-Simple structure * @param string $name human readable name of the service * @param mixed $type one type (string) or array of multiple types * @param mixed $uri one URI (string) or array of multiple URIs * @return array updated XRDS-Simple structure * @since 1.0 */ function xrds_add_simple_service($xrds, $name, $type, $uri) { if (!is_array($type)) $type = array($type); if (!is_array($uri)) $uri = array($uri); $service = array('Type' => array(), 'URI' => array()); foreach ($type as $t) { $service['Type'][] = array('content' => $t); } foreach ($uri as $u) { $service['URI'][] = array('content' => $u); } return xrds_add_service($xrds, 'main', $name, $service); } // Private Functions add_action('wp_head', 'xrds_meta'); add_action('parse_request', 'xrds_parse_request'); add_action('admin_menu', 'xrds_admin_menu'); add_filter('xrds_simple', 'xrds_atompub_service'); /** * Print HTML meta tags, advertising the location of the XRDS document. */ function xrds_meta() { echo ''."\n"; echo ''."\n"; } /** * Build the XRDS-Simple document. * * @return string XRDS-Simple document */ function xrds_write() { $xrds = array(); $xrds = apply_filters('xrds_simple', $xrds); //make sure main is last if($xrds['main']) { $o = $xrds['main']; unset($xrds['main']); $xrds['main'] = $o; } $xml = ''."\n"; $xml .= ''."\n"; foreach($xrds as $id => $xrd) { $xml .= ' ' . "\n"; $xml .= ' xri://$xrds*simple'."\n"; if(!array_key_exists('type', $xrd) || !$xrd['type']) $xrd['type'] = array(); if(!is_array($xrd['type'])) $xrd['type'] = array($xrd['type']); foreach($xrd['type'] as $type) $xml .= ' '.htmlspecialchars($type).''."\n"; if(array_key_exists('expires', $xrd) && $xrd['expires']) $xml .= ' '.htmlspecialchars($xrd['expires']).''."\n"; foreach($xrd['services'] as $name => $service) { $xml .= "\n".' '."\n"; $xml .= ' '."\n"; foreach($service['content'] as $node => $nodes) { if(!is_array($nodes)) $nodes = array($nodes);//sanity check foreach($nodes as $attr) { $xml .= ' <'.htmlspecialchars($node); if(!is_array($attr)) $attr = array('content' => $attr);//sanity check foreach($attr as $name => $v) { if($name == 'content') continue; $xml .= ' '.htmlspecialchars($name).'="'.htmlspecialchars($v).'"'; }//end foreach attr $xml .= '>'.htmlspecialchars($attr['content']).''."\n"; }//end foreach content }//end foreach $xml .= ' '."\n"; }//end foreach services $xml .= ' '."\n"; }//end foreach $xml .= ''."\n"; return $xml; } /** * Handle options page for XRDS-Simple. */ function xrds_options_page() { echo "
\n"; echo "

XRDS-Simple

\n"; echo '

XRDS Document

'; echo '
';
	echo htmlentities(xrds_write());
	echo '
'; echo '

Registered Filters

'; global $wp_filter; if (array_key_exists('xrds_simple', $wp_filter) && !empty($wp_filter['xrds_simple'])) { echo ''; } else { echo '

No registered filters.

'; } echo '
'; }//end xrds_options_page function xrds_plugin_actions($links, $file) { static $this_plugin; if(!$this_plugin) $this_plugin = plugin_basename(__FILE__); if($file == $this_plugin) { $settings_link = 'Settings'; $links[] = $settings_link; }//end if this_plugin return $links; }//end xrds_plugin_actions /** * Setup admin menu for XRDS. */ function xrds_admin_menu() { add_options_page('XRDS-Simple', 'XRDS-Simple', 'manage_options', 'xrds-simple', 'xrds_options_page'); add_filter('plugin_action_links', 'xrds_plugin_actions', 10, 2); } /** * Parse the WordPress request. If the request is for the XRDS document, handle it accordingly. * * @param object $wp WP instance for the current request */ function xrds_parse_request($wp) { $accept = explode(',', $_SERVER['HTTP_ACCEPT']); if(isset($_GET['xrds']) || in_array('application/xrds+xml', $accept)) { if (isset($_REQUEST['format']) && $_REQUEST['format'] == 'text') { header('Content-type: text/plain'); } else { header('Content-type: application/xrds+xml'); } echo xrds_write(); exit; } else { @header('X-XRDS-Location: '.get_bloginfo('url').'/?xrds'); @header('X-Yadis-Location: '.get_bloginfo('url').'/?xrds'); } } /** * Contribute the AtomPub Service to XRDS-Simple. * * @param array $xrds current XRDS-Simple array * @return array updated XRDS-Simple array */ function xrds_atompub_service($xrds) { $xrds = xrds_add_service($xrds, 'main', 'AtomPub Service', array( 'Type' => array( array('content' => 'http://www.w3.org/2007/app') ), 'MediaType' => array( array('content' => 'application/atomsvc+xml') ), 'URI' => array( array('content' => get_bloginfo('wpurl').'/wp-app.php/service' ) ), ) ); return $xrds; } /** * Check if data is well-formed XML. * * @param string $data XML structure to test * @return mixed FALSE if data is well-formed XML, XML error code otherwise */ function xrds_checkXML($data) {//returns FALSE if $data is well-formed XML, errorcode otherwise $rtrn = 0; $theParser = xml_parser_create(); if(!xml_parse_into_struct($theParser,$data,$vals)) { $errorcode = xml_get_error_code($theParser); if($errorcode != XML_ERROR_NONE && $errorcode != 27) $rtrn = $errorcode; }//end if ! parse xml_parser_free($theParser); return $rtrn; } ?>