-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpnhandleradminapi.php
More file actions
219 lines (184 loc) · 6.69 KB
/
pnhandleradminapi.php
File metadata and controls
219 lines (184 loc) · 6.69 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
<?php
/**
* FEproc - Mail template backend module for FormExpress for
* Zikula Content Management System
*
* @copyrightt (C) 2002 by Jason Judge, 2011 Chris Candreva
* @Version $Id: tables.php 84 2011-05-27 18:19:28Z ccandreva $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package FEproc
*
*
* LICENSE
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License (GPL)
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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.
*
* To read the license please visit http://www.gnu.org/copyleft/gpl.html
* ----------------------------------------------------------------------
* Original Author of file: Jason Judge.
* Based on template by Jim MacDonald.
* Current Maintainer of file: Chris Candreva <chris@westnet.com>
* ----------------------------------------------------------------------
*
*/
/**
* create a new template item
* @param $args['name'] name of the template
* @param $args['description'] description of the template
* @param $args['template'] actual template
* @returns int
* @return template item ID on success, false on failure
*/
function feproc_handleradminapi_create($args)
{
// Early security check.
if (!SecurityUtil::checkPermission ('FEproc::', '::', ACCESS_ADD)) {
return LogUtil::registerPermissionError();
}
// Until all calls are refactored, '$args' is the object itself
$obj = &$args;
$obj['attributes'] = serialize($obj['attributes']);
DBUtil::insertObject($obj, 'feproc_handlers');
// Get the ID of the item that we inserted.
$hid = $obj['id'];
// Let any hooks know that we have created a new item.
// TODO: this is not a standard item
pnModCallHooks('item', 'create', $hid, 'hid');
// Return the id of the newly created item to the calling process
return $hid;
}
/**
* delete a feproc handler item
* @param $args['hid'] ID of the item
* @returns bool
* @return true on success, false on failure
* TODO: don't allow a delete if the handler is being used by any workflow set stages.
*/
function feproc_handleradminapi_delete($args)
{
// Early security check.
if (!SecurityUtil::checkPermission ('FEproc::', '::', ACCESS_DELETE)) {
return LogUtil::registerPermissionError();
}
// Get arguments from argument array.
extract($args);
if (!isset($hid)) {
return LogUtil::registerError( __('Missing handler ID'), 500);
}
deleteObjectByID ('feproc_handlers', $hid);
// Let any hooks know that we have deleted a handerl
pnModCallHooks('item', 'delete', $hid, 'hid');
// Let the calling process know that we have finished successfully
return true;
}
/**
* update a template item
* @param $args['hid'] the ID of the item
* @param $args['name'] the new name of the item
* @param $args['description'] the new description of the item
* @param $args['...'] the actual template
* TODO: complete parameter list
*/
function feproc_handleradminapi_update($args)
{
// Early security check.
if (!SecurityUtil::checkPermission ('FEproc::', '::', ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// Until all calls are refactored, '$args' is the object itself
$obj = &$args;
$obj['attributes'] = serialize($obj['attributes']);
$obj['id'] = $obj['hid'];
DBUtil::updateObject($obj, 'feproc_handlers');
// Let the calling process know that we have finished successfully
return true;
}
/**
* Get a list of APIs for a module.
* TODO: the module may not have any APIs - handle that.
*/
function feproc_handleradminapi_moduleapilist($args)
{
extract($args);
$moduleinfo = pnModGetInfo(pnModGetIDFromName($modulename));
$directory = $moduleinfo['directory'];
$osfile = "modules/$directory/pn*api.php";
$apilist = Array();
$dh = opendir("modules/$directory");
while ($file = readdir($dh))
{
// TODO: are there any rules on the characters in a name? Letter case?
if (ereg('^pn(.+)api.php$', $file, $regs))
{
$apilist[] = Array('modulename' => $modulename, 'apiname' => $regs[1]);
}
}
if (empty($apilist))
{
$apilist = false;
}
return $apilist;
}
/**
* Get a list of fetix handlers for a module.
* $modulename - name of module.
*/
function feproc_handleradminapi_modulehandlers($args)
{
extract($args);
// Get the list of APIs for the module.
// TODO: handle there being no APIs in the module.
$apilist = pnModAPIFunc('feproc', 'handleradmin', 'moduleapilist',
array('modulename' => $modulename));
if (!$apilist)
{
return false;
}
$handlerlist = Array();
// Loop for each API and hunt for handlers.
foreach($apilist as $api)
{
$apimodule = $api['modulename'];
$apiname = $api['apiname'];
if (pnModAPILoad($apimodule, $apiname))
{
// The API has loaded okay.
// Load a list of fetix handlers, if any.
if ($handlerindex = pnModAPIFunc($apimodule, $apiname, 'feprochandlerindex'))
{
// There is a feproc handler here. Grab the details.
// Store the info details in the result array.
// Now get the details for each handler in turn.
foreach($handlerindex as $handler)
{
$info = Array();
// Load the API handler function and get its info.
if ($info = pnModAPIFunc($apimodule, $apiname, $handler['apifunc'], Array('action' => 'info')))
{
// Add a few more fields.
$info['module'] = $apimodule;
$info['apiname'] = $apiname;
$info['apifunc'] = $handler['apifunc'];
$info['source'] = $info['type'] .':'. $apimodule .':'. $apiname .':'. $handler['apifunc'];
// Store the handler in the array.
$handlerlist[] = $info;
}
}
}
}
}
if (empty($handlerlist))
{
$handlerlist = false;
}
return $handlerlist;
}
?>