This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pnuserapi.php
executable file
·254 lines (213 loc) · 7.19 KB
/
pnuserapi.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
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
<?php
/**
* locations
*
* @copyright (c) 2008,2010, Locations Development Team
* @link http://code.zikula.org/locations
* @author Steffen Voß
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package locations
*/
// preload common used classes
Loader::requireOnce('modules/locations/common.php');
/**
* This function retrieves locations for a dropdown list
*
* @author Steffen Voß
* @params TODO
* @return Array
*/
function locations_userapi_getLocationsForDropdown($args)
{
$dom = ZLanguage::getModuleDomain('locations');
// load the object array class corresponding to $objectType
if (!($class = Loader::loadArrayClassFromModule('locations', 'location'))) {
pn_exit(__f('Error! Unable to load class [%s].', 'location', $dom));
}
// instantiate the object-array
$objectArray = new $class();
$objectData = $objectArray->get('', 'name');
$return = array();
foreach ($objectData as $key => $object) {
$return[$key]['value'] = $object['locationid'];
$return[$key]['text'] = $object['name']. ', ' . $object['street']. ', ' . $object['zip']. ' ' . $object['city'];
}
return($return);
}
/**
* This function retrieves locations for a dropdown list
*
* @author Steffen Voß
* @params TODO
* @return Array
* @param locationid integer location ID
*/
function locations_userapi_getLocationByID($args)
{
if (!SecurityUtil::checkPermission('locations::', '::', ACCESS_READ)) {
return LogUtil::registerPermissionError();
}
$dom = ZLanguage::getModuleDomain('locations');
// load the object class corresponding to $objectType
if (!($class = Loader::loadClassFromModule('locations', 'location'))) {
pn_exit(__f('Error! Unable to load class [%s].', 'location', $dom));
}
// intantiate object model
$object = new $class();
$idField = $object->getIDField();
// retrieve the ID of the object we wish to view
if (isset($args[$idField]) && is_numeric($args[$idField])) {
$id = (int) $args[$idField];
} else {
pn_exit(__('Error! Invalid Id received.', $dom));
}
// assign object data
// this performs a new database select operation
// while the result will be saved within the object, we assign it to a local variable for convenience
$objectData = $object->get($id, $idField);
if (!is_array($objectData) || !isset($objectData[$idField]) || !is_numeric($objectData[$idField])) {
return LogUtil::registerError(__('Error! No such location found.', $dom));
}
return $objectData;
}
/**
* wrapper for getLocationByID
*
* @author Steffen Voß
* @params TODO
* @return Array
* @param locationid integer location ID
*/
function locations_userapi_get($args)
{
$objectData = pnModAPIFunc('locations', 'user', 'getLocationByID', $args);
$objectData['title'] = $objectData['name'];
return $objectData;
}
/**
* swap langitude and longitude
*
* @return string
*/
function locations_userapi_swapLatLng($args)
{
$temp = explode(',',$args['latlng']);
$return = $temp[1] . ',' . $temp[0];
return($return);
}
/**
* get meta data for the module
*
* @return array metadata
*/
function locations_userapi_getmodulemeta()
{
return array('viewfunc' => 'view',
'displayfunc' => 'display',
'newfunc' => 'new',
'createfunc' => 'create',
'modifyfunc' => 'edit',
'updatefunc' => 'edit',
'deletefunc' => 'delete',
'titlefield' => 'name',
'itemid' => 'locationid');
}
/**
* form custom url string
*
* @author Carsten Volmer
* @return string custom url string
*/
function locations_userapi_encodeurl($args)
{
// check if we have the required input
if (!isset($args['modname']) || !isset($args['func']) || !isset($args['args'])) {
return LogUtil::registerArgsError();
}
if (!isset($args['type'])) {
$args['type'] = 'user';
}
$customFuncs = array('display');
if (!in_array($args['func'], $customFuncs)) {
return '';
}
// create an empty string ready for population
$vars = '';
// display function
if ($args['func'] == 'display') {
// for the display function use either the title (if present) or the object's id
$objectType = (isset($args['args']['ot'])) ? $args['args']['ot'] : 'location';
$id = 0;
if (isset($args['args'][$objectType . 'id'])) {
$id = $args['args'][$objectType . 'id'];
}
if (isset($args['args']['objectid'])) {
$id = $args['args']['objectid'];
}
if ($id > 0) {
$item = DBUtil::selectObjectByID('locations_' . $objectType, $id, $objectType . 'id');
}
else {
$item = DBUtil::selectObjectByID('locations_' . $objectType, $args['name'], 'urltitle');
}
$permalinkformat = pnModGetVar('locations', 'permalinkformat');
$in = array('%urltitle%', '%street%', '%zip%', '%city%', '%country%', '%state%');
$out = array($item['urltitle'], $item['street'], $item['zip'], $item['city'], $item['country'], $item['state']);
$vars = $item['locationid'] . '/' . str_replace($in, $out, $permalinkformat);
}
// don't display the function name if either displaying an page or the normal overview
if ($args['func'] == 'main' || $args['func'] == 'view' || $args['func'] == 'display') {
$args['func'] = '';
}
// puzzle return string together
$returnString = $args['modname'] . '/';
if (!empty($args['func'])) {
$returnString .= $args['func'] . '/';
}
if (!empty($vars)) {
$returnString .= $vars;
}
return $returnString;
}
/**
* decode the custom url string
*
* @author Carsten Volmer
* @return bool true if successful, false otherwise
*/
function locations_userapi_decodeurl($args)
{
// check we actually have some vars to work with
if (!isset($args['vars'])) {
return LogUtil::registerArgsError();
}
// define the available user functions
$funcs = array('main', 'view', 'display', 'getLocationsWithinDistanceOfZIP');
// set the correct function name based on our input
if (empty($args['vars'][2])) {
// no func and no vars = main
pnQueryStringSetVar('func', 'main');
} elseif (!in_array($args['vars'][2], $funcs)) {
// no func, but vars -- this is true for display function
pnQueryStringSetVar('func', 'display');
$nextvar = 2;
} else {
pnQueryStringSetVar('func', $args['vars'][2]);
$nextvar = 3;
}
// get rid of unused vars
$args['vars'] = array_slice($args['vars'], $nextvar);
$nextvar = 0;
$currentFunc = FormUtil::getPassedValue('func', '');
// identify the correct parameter to identify the object
if ($currentFunc == 'display') {
$identifierValue = $args['vars'][$nextvar];
$objectType = 'location';
pnQueryStringSetVar('ot', $objectType);
pnQueryStringSetVar($objectType . 'id', $identifierValue);
}
else {
return false;
}
return true;
}