This repository has been archived by the owner on Dec 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OAuthConsumerExample.php
68 lines (55 loc) · 2.16 KB
/
OAuthConsumerExample.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
<?php
class OAuthConsumerExample extends StudIPPlugin implements SystemPlugin
{
public function __construct()
{
parent::__construct();
$navigation = new Navigation(_('OAuth Consumer'), PluginEngine::getLink($this, array(), 'client'));
$navigation->setImage('icons/lightblue/computer.svg');
Navigation::addItem('/oauth_consumer', $navigation);
}
public function perform ($unconsumed_path)
{
require_once 'bootstrap.php';
$this->addStylesheet('assets/form-settings.less');
PageLayout::addScript($this->getPluginURL() . '/assets/oauth.js');
$dispatcher = new Trails_Dispatcher(
$this->getPluginPath() . DIRECTORY_SEPARATOR . 'app',
rtrim(PluginEngine::getLink($this, array(), null, true), '/'),
'client'
);
$dispatcher->plugin = $this;
$dispatcher->container = $this->getContainer();
$dispatcher->dispatch($unconsumed_path);
}
protected function getContainer()
{
$container = new Pimple\Container();
# workaround to get an absolute URL
URLHelper::setBaseURL($GLOBALS['ABSOLUTE_URI_STUDIP']);
$container['CONSUMER_URL'] = PluginEngine::getURL($this, array(), 'client/', true);
if ($this->coreAPIEnabled()) {
$container['core'] = array(
'PROVIDER_URL' => URLHelper::getURL('dispatch.php/api/oauth/', null, true),
'API_URL' => URLHelper::getURL('api.php/', null, true),
'API_PROVIDER' => 'CoreAPIProvider',
);
}
if ($this->restIPEnabled()) {
$container['rest.ip'] = array(
'PROVIDER_URL' => PluginEngine::getURL('restipplugin', array(), 'oauth/', true),
'API_URL' => PluginEngine::getURL('restipplugin', array(), 'api/', true),
'API_PROVIDER' => 'RestIPProvider',
);
}
return $container;
}
public function coreAPIEnabled()
{
return Config::get()->API_ENABLED;
}
public function restIPEnabled()
{
return PluginEngine::getPlugin('RestipPlugin') !== null;
}
}