folderaction.inc.php
9.68 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
/**
* $Id$
*
* KnowledgeTree Open Source Edition
* Document Management Made Simple
* Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
* Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
* must display the words "Powered by KnowledgeTree" and retain the original
* copyright notice.
* Contributor( s): ______________________________________
*
*/
require_once(KT_LIB_DIR . '/dispatcher.inc.php');
require_once(KT_LIB_DIR . '/actions/actionregistry.inc.php');
require_once(KT_LIB_DIR . '/browse/browseutil.inc.php');
require_once(KT_LIB_DIR . "/util/sanitize.inc");
class KTFolderAction extends KTStandardDispatcher {
var $sName;
var $sDescription;
var $_sShowPermission = 'ktcore.permissions.folder_details';
var $_sDisablePermission;
var $sHelpPage = 'ktcore/browse.html';
var $_bAdminAlwaysAvailable = false;
var $sSection = 'browse';
function KTFolderAction($oFolder = null, $oUser = null, $oPlugin = null) {
parent::KTStandardDispatcher();
$this->oFolder =& $oFolder;
$this->oUser =& $oUser;
$this->oPlugin =& $oPlugin;
$this->aBreadcrumbs = array(
array('action' => 'browse', 'name' => _kt('Browse')),
);
$this->persistParams(array('fFolderId'));
}
function setFolder(&$oFolder) {
$this->oFolder =& $oFolder;
}
function setUser(&$oUser) {
$this->oUser =& $oUser;
}
function _show() {
if (is_null($this->_sShowPermission)) {
return true;
}
$oPermission =& KTPermission::getByName($this->_sShowPermission);
if (PEAR::isError($oPermission)) {
return true;
}
if ($this->_bAdminAlwaysAvailable) {
if (KTBrowseUtil::inAdminMode($this->oUser, $this->oFolder)) {
return true;
}
}
return KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oFolder);
}
function getURL() {
$oKTConfig =& KTConfig::getSingleton();
$sExt = '.php';
if (KTUtil::arrayGet($_SERVER, 'kt_no_extensions')) {
$sExt = '';
}
if ($oKTConfig->get('KnowledgeTree/pathInfoSupport')) {
return sprintf('%s/action%s/%s?fFolderId=%d', $GLOBALS['KTRootUrl'], $sExt, $this->sName, $this->oFolder->getID());
} else {
return sprintf('%s/action%s?kt_path_info=%s&fFolderId=%d', $GLOBALS['KTRootUrl'], $sExt, $this->sName, $this->oFolder->getID());
}
}
function getInfo() {
if ($this->_show() === false) {
return null;
}
$aInfo = array(
'description' => $this->sDescription,
'name' => $this->getDisplayName(),
'ns' => $this->sName,
'url' => $this->getURL(),
);
return $this->customiseInfo($aInfo);
}
function getName() {
return sanitizeForSQLtoHTML($this->sName);
}
function getDisplayName() {
// This should be overridden by the i18nised display name
// This implementation is only here for backwards compatibility
return sanitizeForSQLtoHTML($this->sDisplayName);
}
function getDescription() {
return sanitizeForSQLtoHTML($this->sDescription);
}
function customiseInfo($aInfo) {
return $aInfo;
}
function check() {
$this->oFolder =& $this->oValidator->validateFolder($_REQUEST['fFolderId']);
if (!$this->_show()) { return false; }
$aOptions = array(
'final' => false,
'documentaction' => 'viewDocument',
'folderaction' => 'browse',
);
$this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs,
KTBrowseUtil::breadcrumbsForFolder($this->oFolder, $aOptions));
$portlet = new KTActionPortlet(sprintf(_kt('About this folder')));
$aActions = KTFolderActionUtil::getFolderInfoActionsForFolder($this->oFolder, $this->oUser);
$portlet->setActions($aActions,$this->sName);
$this->oPage->addPortlet($portlet);
$portlet = new KTActionPortlet(sprintf(_kt('Actions on this folder')));
$aActions = KTFolderActionUtil::getFolderActionsForFolder($this->oFolder, $this->oUser);
$portlet->setActions($aActions,$this->sName);
$this->oPage->addPortlet($portlet);
if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, 'ktcore.permissions.folder_details', $this->oFolder)) {
$this->oPage->setSecondaryTitle($this->oFolder->getName());
} else {
if (KTBrowseUtil::inAdminMode($this->oUser, $this->oFolder)) {
$this->oPage->setSecondaryTitle(sprintf('(%s)', $this->oFolder->getName()));
} else {
$this->oPage->setSecondaryTitle('...');
}
}
return true;
}
function do_main() {
return _kt('Dispatcher component of action not implemented.');
}
}
class JavascriptFolderAction extends KTFolderAction
{
/**
* This is an array of js files to be included for this action
*
* @var array
*/
var $js_paths = array();
/**
* This is custom javascript that should be included
*
* @var array
*/
var $js = array();
/**
* Indicates if a custom function should be provided, or if the function is part of an existing js file.
* If true
*
* @var boolean
*/
var $function_provided_by_action = true;
/**
* Set the function name if you have a custom name you want to provide.
*
* @var string
*/
var $function_name = null;
function JavascriptFolderAction($oFolder = null, $oUser = null, $oPlugin = null)
{
parent::KTFolderAction($oFolder, $oUser, $oPlugin);
$this->js_initialise();
}
function js_initialise()
{
// this will be overridden
}
function js_include($js)
{
$this->js[] = $js;
}
function js_include_file($path)
{
global $AjaxDocumentJSPaths;
if (!isset($AjaxDocumentJSPaths))
{
$AjaxDocumentJSPaths = array();
}
if (!in_array($AjaxDocumentJSPaths))
{
$AjaxDocumentJSPaths[] = $path;
$this->js_paths [] = $path;
}
}
function customiseInfo($aInfo)
{
$js = '';
foreach($this->js_paths as $path)
{
$js .= "<script language=\"javascript\" src=\"$path\"></script>\n";
}
$js .= '<script language="javascript">'. "\n";
foreach($this->js as $js2)
{
$js .= $js2 . "\n";
}
$js .= $this->getScript() . '</script>'. "\n";
$js .= '<div onclick="' . $this->getScriptActivation() . '"><a>' . $this->getDisplayName() . '</a></div>'. "\n";
$aInfo['js'] = $js;
return $aInfo;
}
function getScript()
{
if ($this->function_provided_by_action === false)
{
return '';
}
return "function " . $this->getScriptActivation() . '{'.$this->getFunctionScript().'}';
}
function getFunctionScript()
{
return 'alert(\''. $this->getDisplayName() .' not implemented!\');';
}
function getScriptActivation()
{
if (!is_null($this->function_name))
{
return $this->function_name;
}
global $AjaxDocumentActions;
$class = get_class($this);
return 'js' . $class. 'Dispatcher()';
}
}
class KTFolderActionUtil {
function getFolderActions() {
$oRegistry =& KTActionRegistry::getSingleton();
return $oRegistry->getActions('folderaction');
}
function getFolderInfoActions() {
$oRegistry =& KTActionRegistry::getSingleton();
return $oRegistry->getActions('folderinfo');
}
function &getFolderActionsForFolder($oFolder, $oUser) {
$aObjects = array();
foreach (KTFolderActionUtil::getFolderActions() as $aAction) {
list($sClassName, $sPath, $sPlugin) = $aAction;
$oRegistry =& KTPluginRegistry::getSingleton();
$oPlugin =& $oRegistry->getPlugin($sPlugin);
if (!empty($sPath)) {
require_once($sPath);
}
$aObjects[] =new $sClassName($oFolder, $oUser, $oPlugin);
}
return $aObjects;
}
function &getFolderInfoActionsForFolder($oFolder, $oUser) {
$aObjects = array();
foreach (KTFolderActionUtil::getFolderInfoActions() as $aAction) {
list($sClassName, $sPath, $sPlugin) = $aAction;
$oRegistry =& KTPluginRegistry::getSingleton();
$oPlugin =& $oRegistry->getPlugin($sPlugin);
if (!empty($sPath)) {
require_once($sPath);
}
$aObjects[] =new $sClassName($oFolder, $oUser, $oPlugin);
}
return $aObjects;
}
}
?>