1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author     Andreas Gohr <gohr@cosmocode.de>
5 */
6if(!defined('DOKU_INC')) die();
7
8if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
9require_once(DOKU_PLUGIN.'action.php');
10
11/**
12 * All DokuWiki plugins to extend the parser/rendering mechanism
13 * need to inherit from this class
14 */
15class action_plugin_oiddelegate extends DokuWiki_Action_Plugin {
16
17    /**
18     * return some info
19     */
20    function getInfo() {
21        return confToHash(dirname(__FILE__).'/plugin.info.txt');
22    }
23
24    function register(Doku_Event_Handler $controller) {
25        $controller->register_hook('TPL_METAHEADER_OUTPUT','BEFORE', $this, 'handle_metaheader');
26    }
27
28    function handle_metaheader(&$event, $param) {
29        global $ACT;
30        global $ID;
31        if($ACT != 'show') return true;
32
33        // read delegate setups from config
34        $delegates = confToHash(DOKU_CONF.'openid-delegates.conf');
35        $delegate = $delegates[$ID];   // check delegate for current page
36        if(!$delegate) $delegate = $delegates['*']; // fall back to default if any
37        if(!$delegate) return true;
38
39        list($oid,$server,$provider,$xrds) = preg_split('/\s+/',$delegate,4);
40        $oid      = trim($oid);
41        $server   = trim($server);
42        $provider = trim($provider);
43        $xrds     = trim($xrds);
44
45        // openid 1 support
46        if($server){
47            $event->data['link'][] = array(
48                'rel'  => 'openid.server',
49                'href' => $server,
50            );
51            $event->data['link'][] = array(
52                'rel'  => 'openid.delegate',
53                'href' => $oid,
54            );
55        }
56        // openid 2 support
57        if($provider){
58            $event->data['link'][] = array(
59                'rel'  => 'openid2.provider',
60                'href' => $provider,
61            );
62            $event->data['link'][] = array(
63                'rel'  => 'openid2.local_id',
64                'href' => $oid,
65            );
66        }
67        // openid 2 + XRDS
68        if($xrds){
69            $event->data['meta'][] = array(
70                'http-equiv'  => 'X-XRDS-Location',
71                'href' => $xrds,
72            );
73        }
74
75        return true;
76    }
77}
78