1<?php
2/**
3 * Federated Login for DokuWiki - helper class
4 *
5 * Enables your DokuWiki to provide users with
6 * Hybrid OAuth + OpenId federated login.
7 *
8 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 * @link       http://www.dokuwiki.org/plugin:fedauth
10 * @author     Aoi Karasu <aoikarasu@gmail.com>
11 */
12
13// must be run within Dokuwiki
14if (!defined('DOKU_INC')) die();
15
16if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
17if (!defined('FEDAUTH_PLUGIN')) define('FEDAUTH_PLUGIN', DOKU_PLUGIN . 'fedauth/');
18if (!defined('CONFIG_PATH')) define('CONFIG_PATH', DOKU_CONF . 'fedauth/');
19if (!defined('CONFIG_INC')) define('CONFIG_INC', CONFIG_PATH . 'providers.php');
20if (!defined('DEFIMG_INC')) define('DEFIMG_INC', FEDAUTH_PLUGIN . 'images/');
21
22require_once(FEDAUTH_PLUGIN . "classes/fa_provider.class.php");
23require_once(FEDAUTH_PLUGIN . "classes/fa_providerlist.class.php");
24
25class helper_plugin_fedauth extends DokuWiki_Plugin {
26
27    /**
28     * Authorization providers collecion.
29     */
30    var $providers = null;
31
32    /**
33     * Returns the plugin meta information.
34     */
35    function getInfo() {
36        return array(
37            'author' => 'Aoi Karasu',
38            'email'  => 'aoikarasu@gmail.com',
39            'date'   => '2012-06-09',
40            'name'   => 'Federated Login Plugin',
41            'desc'   => 'Functions to handle hybrid oauth + openid login',
42            'url'    => 'http://www.dokuwiki.org/plugin:fedauth',
43        );
44    }
45
46    /**
47     * Returns the metadata of methods provided by this plugin.
48     */
49    function getMethods() {
50        $result = array();
51        $result[] = array(
52                'name'   => 'getProviders',
53                'desc'   => 'returns the authorization provider collection',
54                'return' => array('authorization provider collection' => 'object'),
55                );
56        return $result;
57    }
58
59    function getProviders() {
60        // try to return loaded providers
61        if ($this->providers) {
62            return $this->providers;
63        }
64        // try to load providers from local config
65        $provs = fa_providerlist::create(CONFIG_INC);
66        if ($provs->count() == 0) {
67            // load default providers, setup details and save as local
68            $provs = fa_providerlist::create(FEDAUTH_PLUGIN . 'providers.php');
69            foreach ($provs->getAll() as $key => $prov) {
70                $prov->setupDetails(DEFIMG_INC);
71            }
72            $provs->setConfigFile(CONFIG_INC);
73            io_makeFileDir(CONFIG_INC);
74            $provs->save($_SERVER['REMOTE_USER']);
75        }
76        $this->providers = $provs;
77        return $this->providers;
78    }
79
80    function htmlLoginFedAuth($return=false) {
81        global $ID, $conf, $auth;
82
83        // enable direct access to language strings
84        $this->setupLocale();
85
86        $user = $_SERVER['REMOTE_USER'];
87
88        if (empty($user)) {
89            $cmd = 'login';
90        }
91        else {
92            $cmd = 'addlogin';
93        }
94
95        $out = '<div id="fa__authform" class="sprovs"><form action="'.wl($ID).'" method="post">'
96             . '  <fieldset class="hidden">'
97             . '    <input type="hidden" name="do" value="fedauth" />'
98             . formSecurityToken(false)
99             . '  </fieldset>'
100             . '  <div id="axwrap__large">'
101//             . $this->html_providers_list($this->manager->providers->{'get'.ucfirst($listtype)}(), $large)
102             . '  </div>'
103             . '  <fieldset class="buttons">'
104             . '    <input type="submit" class="button" name="fa[toggle]" value="' . $this->lang['btn_toggle'] . '" />'
105             . '  </fieldset>'
106             . '</form></div>';
107
108        if ($return) return $out;
109        echo $out;
110        return true;
111    }
112
113    function htmlLoginFedAuthCompact($return=false) {
114    }
115
116} /* helper_plugin_federate */
117
118/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
119