plugin.inc.php
7.99 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
class KTPlugin {
var $sNamespace;
var $sFilename = null;
var $bAlwaysInclude = false;
var $iVersion = 0;
var $_aPortlets = array();
var $_aTriggers = array();
var $_aActions = array();
var $_aPages = array();
var $_aAuthenticationProviders = array();
var $_aAdminCategories = array();
var $_aAdminPages = array();
var $_aDashlets = array();
var $_ai18n = array();
function KTPlugin($sFilename = null) {
$this->sFilename = $sFilename;
}
function setFilename($sFilename) {
$this->sFilename = $sFilename;
}
function registerPortlet($aLocation, $sPortletClassName, $sPortletNamespace, $sFilename = null) {
$sFilename = $this->_fixFilename($sFilename);
$this->_aPortlets[$sPortletNamespace] = array($aLocation, $sPortletClassName, $sPortletNamespace, $sFilename, $this->sNamespace);
}
function registerTrigger($sAction, $sStage, $sTriggerClassName, $sTriggerNamespace, $sFilename = null) {
$sFilename = $this->_fixFilename($sFilename);
$this->_aTriggers[$sTriggerNamespace] = array($sAction, $sStage, $sTriggerClassName, $sTriggerNamespace, $sFilename, $this->sNamespace);
}
function registerAction($sActionType, $sActionClassName, $sActionNamespace, $sFilename = null) {
$sFilename = $this->_fixFilename($sFilename);
$this->_aActions[$sActionNamespace] = array($sActionType, $sActionClassName, $sActionNamespace, $sFilename, $this->sNamespace);
}
function registerPage($sWebPath, $sPageClassName, $sFilename = null) {
$sFilename = $this->_fixFilename($sFilename);
$sWebPath = sprintf("%s/%s", $this->sNamespace, $sWebPath);
$this->_aPages[$sWebPath] = array($sWebPath, $sPageClassName, $sFilename, $this->sNamespace);
}
function getPagePath($sPath) {
$sExt = ".php";
if (KTUtil::arrayGet($_SERVER, 'kt_no_extensions')) {
$sExt = "";
}
$oKTConfig =& KTConfig::getSingleton();
if ($oKTConfig->get("KnowledgeTree/pathInfoSupport")) {
return sprintf('%s/plugin%s/%s/%s', $GLOBALS['KTRootUrl'], $sExt, $this->sNamespace, $sPath);
} else {
return sprintf('%s/plugin%s?kt_path_info=%s/%s', $GLOBALS['KTRootUrl'], $sExt, $this->sNamespace, $sPath);
}
}
function registerAuthenticationProvider($sName, $sClass, $sNamespace, $sFilename = null) {
$sFilename = $this->_fixFilename($sFilename);
$this->_aAuthenticationProviders[$sNamespace] = array($sName, $sClass, $sNamespace, $sFilename, $this->sNamespace);
}
//registerLocation($sName, $sClass, $sCategory, $sTitle, $sDescription, $sDispatcherFilePath = null, $sURL = null)
function registerAdminPage($sName, $sClass, $sCategory, $sTitle, $sDescription, $sFilename) {
$sFullname = $sCategory . '/' . $sName;
$sFilename = $this->_fixFilename($sFilename);
$this->_aAdminPages[$sFullname] = array($sName, $sClass, $sCategory, $sTitle, $sDescription, $sFilename, null, $this->sNamespace);
}
function registerAdminCategory($sPath, $sName, $sDescription) {
$this->_aAdminCategories[$sPath] = array($sPath, $sName, $sDescription);
}
function registerDashlet($sClassName, $sNamespace, $sFilename) {
$sFilename = $this->_fixFilename($sFilename);
$this->_aDashlets[$sNamespace] = array($sClassName, $sNamespace, $sFilename, $this->sNamespace);
}
function registeri18n($sDomain, $sPath) {
$sPath = $this->_fixFilename($sPath);
$this->_ai18n[$sDomain] = array($sDomain, $sPath);
}
function _fixFilename($sFilename) {
if (empty($sFilename)) {
$sFilename = $this->sFilename;
} else if (OS_WINDOWS && (substr($sFilename, 1, 2) == ':\\')) {
$sFilename = $this->sFilename;
} else if (OS_WINDOWS && (substr($sFilename, 1, 2) == ':/')) {
$sFilename = $this->sFilename;
} else if (substr($sFilename, 0, 1) != '/') {
if ($this->sFilename) {
$sDirPath = dirname($this->sFilename);
$sFilename = sprintf("%s/%s", $sDirPath, $sFilename);
}
}
return $sFilename;
}
function isRegistered() {
if ($this->bAlwaysInclude) {
return true;
}
require_once(KT_LIB_DIR . '/plugins/pluginentity.inc.php');
$oEntity = KTPluginEntity::getByNamespace($this->sNamespace);
if (PEAR::isError($oEntity)) {
if (is_a($oEntity, 'KTEntityNoObjects')) {
// plugin not registered in database
// XXX: nbm: Show an error on the page that a plugin
// isn't registered or something, perhaps.
return false;
}
return false;
}
if ($oEntity->getDisabled()) {
return false;
}
return true;
}
function load() {
if (!$this->isRegistered()) {
return;
}
$this->setup();
require_once(KT_LIB_DIR . '/actions/actionregistry.inc.php');
require_once(KT_LIB_DIR . '/actions/portletregistry.inc.php');
require_once(KT_LIB_DIR . '/triggers/triggerregistry.inc.php');
require_once(KT_LIB_DIR . '/plugins/pageregistry.inc.php');
require_once(KT_LIB_DIR . '/authentication/authenticationproviderregistry.inc.php');
require_once(KT_LIB_DIR . "/plugins/KTAdminNavigation.php");
require_once(KT_LIB_DIR . "/dashboard/dashletregistry.inc.php");
require_once(KT_LIB_DIR . "/i18n/i18nregistry.inc.php");
$oPRegistry =& KTPortletRegistry::getSingleton();
$oTRegistry =& KTTriggerRegistry::getSingleton();
$oARegistry =& KTActionRegistry::getSingleton();
$oPageRegistry =& KTPageRegistry::getSingleton();
$oAPRegistry =& KTAuthenticationProviderRegistry::getSingleton();
$oAdminRegistry =& KTAdminNavigationRegistry::getSingleton();
$oDashletRegistry =& KTDashletRegistry::getSingleton();
$oi18nRegistry =& KTi18nRegistry::getSingleton();
foreach ($this->_aPortlets as $k => $v) {
call_user_func_array(array(&$oPRegistry, 'registerPortlet'), $v);
}
foreach ($this->_aTriggers as $k => $v) {
call_user_func_array(array(&$oTRegistry, 'registerTrigger'), $v);
}
foreach ($this->_aActions as $k => $v) {
call_user_func_array(array(&$oARegistry, 'registerAction'), $v);
}
foreach ($this->_aPages as $k => $v) {
call_user_func_array(array(&$oPageRegistry, 'registerPage'), $v);
}
foreach ($this->_aAuthenticationProviders as $k => $v) {
call_user_func_array(array(&$oAPRegistry, 'registerAuthenticationProvider'), $v);
}
foreach ($this->_aAdminCategories as $k => $v) {
call_user_func_array(array(&$oAdminRegistry, 'registerCategory'), $v);
}
foreach ($this->_aAdminPages as $k => $v) {
call_user_func_array(array(&$oAdminRegistry, 'registerLocation'), $v);
}
foreach ($this->_aDashlets as $k => $v) {
call_user_func_array(array(&$oDashletRegistry, 'registerDashlet'), $v);
}
foreach ($this->_ai18n as $k => $v) {
call_user_func_array(array(&$oi18nRegistry, 'registeri18n'), $v);
}
}
function setup() {
return;
}
function register() {
$oEntity = KTPluginEntity::getByNamespace($this->sNamespace);
if (!PEAR::isError($oEntity)) {
$oEntity->updateFromArray(array(
'path' => $this->sFilename,
'version' => $this->iVersion,
));
return $oEntity;
}
$oEntity = KTPluginEntity::createFromArray(array(
'namespace' => $this->sNamespace,
'path' => $this->sFilename,
'version' => $this->iVersion,
'disabled' => 1,
));
if (PEAR::isError($oEntity)) {
return $oEntity;
}
return true;
}
}