xajaxCall.inc.php
8.34 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<?php
/*
File: xajaxCall.inc.php
Contains the xajaxCall class
Title: xajaxCall class
Please see <copyright.inc.php> for a detailed description, copyright
and license information.
*/
/*
@package xajax
@version $Id: xajaxCall.inc.php 362 2007-05-29 15:32:24Z calltoconstruct $
@copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson
@copyright Copyright (c) 2008-2009 by Joseph Woolley, Steffen Konerow, Jared White & J. Max Wilson
@license http://www.xajaxproject.org/bsd_license.txt BSD License
*/
/*
Class: xajaxCall
Create a piece of javascript code that will invoke the <xajax.call>
function.
This class is deprecated and will be removed in future versions; please use
<xajaxRequest> instead.
*/
class xajaxCall {
/**#@+
* @access protected
*/
/*
String: sFunction
Required: The name of the xajax enabled function to call
*/
var $sFunction;
/*
String: sReturnValue
Required: The value to return once the <xajax.call> has
returned. (for asynchronous calls, this is immediate)
*/
var $sReturnValue;
/*
Array: aParameters
The associative array that will be used to store the parameters for this
call.
- key: The textual representation of the parameter.
- value: A boolean value indicating whether or not to use quotes around
this parameter.
*/
var $aParameters;
/*
String: sMode
The mode to use for the call
- 'synchronous'
- 'asynchronous'
*/
var $sMode;
/*
String: sRequestType
The request type that will be used for the call
- 'GET'
- 'POST'
*/
var $sRequestType;
/*
String: sResponseProcessor
The name of the javascript function that will be invoked
to handle the response.
*/
var $sResponseProcessor;
/*
String: sRequestURI
The URI for where this request will be sent.
*/
var $sRequestURI;
/*
String: sContentType
The content type to use for the request.
*/
var $sContentType;
/*
Constructor: xajaxCall
Initializes the xajaxCall object.
Parameters:
sFunction - (string): The name of the xajax enabled function
that will be invoked when this javascript code is executed
on the browser. This function name should match a PHP
function from your script.
*/
function xajaxCall($sFunction = '') {
$this->sFunction = $sFunction;
$this->aParameters = array();
$this->sMode = '';
$this->sRequestType = '';
$this->sResponseProcessor = '';
$this->sRequestURI = '';
$this->sContentType = '';
}
/*
Function: setFunction
Override the function name set in the constructor.
Parameters:
sFunction - (string): The name of the xajax enabled function
that will be invoked when this javascript code is executed
on the browser. This function name should match a PHP
function from your script.
Returns:
object : The <xajaxCall> object.
*/
function setFunction($sFunction) {
$this->sFunction = $sFunction;
return $this;
}
/*
Function: clearParameters
Clear the list of parameters being accumulated for this
call.
Returns:
object : The <xajaxCall> object.
*/
function clearParameters() {
$this->aParameters = array();
}
/*
Function: addParameter
Adds a parameter to the list that will be specified for the
request generated by this <xajaxCall> object.
Parameters:
sParameter - (string): The parameter value or name.
bUseQuotes - (boolean): Whether or not to put quotes around this value.
If you specify the name of a javascript variable, or provide a javascript
function call as a parameter, do not use quotes around the value.
Returns:
object : The <xajaxCall> object.
*/
function addParameter($sParameter, $bUseQuotes = true) {
$this->aParameters[] = array($sParameter, $bUseQuotes);
return $this;
}
/*
Function: addFormValuesParameter
Add a parameter value that is the result of calling <xajax.getFormValues>
for the specified form.
Parameters:
sFormID - (string): The id of the form for which you wish to return
the input values.
Returns:
object : The <xajaxCall> object.
*/
function addFormValuesParameter($sFormID) {
$this->aParameters[] = array('xajax.getFormValues("'.$sFormID.'")');
return $this;
}
/*
Function: setMode
Sets the mode that will be specified for this <xajax.call>
Parameters:
$sMode - (string): The mode to be set.
- 'synchronous'
- 'asynchronous'
Returns:
object : The <xajaxCall> object.
*/
function setMode($sMode) {
$this->sMode = $sMode;
return $this;
}
/*
Function: setRequestType
Sets the request type which will be specified for the
generated <xajax.call>.
Parameters:
- 'GET'
- 'POST'
Returns:
object : The <xajaxCall> object.
*/
function setRequestType($sRequestType) {
$this->sRequestType = $sRequestType;
return $this;
}
/*
Function: setResponseProcessor
Sets the name of the javascript function that will be used
to process this response. This is an advanced function, use
with caution.
Parameters:
Returns:
object : The <xajaxCall> object.
*/
function setResponseProcessor($sResponseProcessor) {
$this->sResponseProcessor = $sResponseProcessor;
return $this;
}
/*
Function: setRequestURI
Override the default URI with the specified one.
Parameters:
sRequestURI - (string): The URI that the generated request will be sent
to.
Returns:
object : The <xajaxCall> object.
*/
function setRequestURI($sRequestURI) {
$this->sRequestURI = $sRequestURI;
return $this;
}
/*
Function: setContentType
Sets the content type that will be used by the generated request.
Parameters:
Returns:
object : The <xajaxCall> object.
*/
function setContentType($sContentType) {
$this->sContentType = $sContentType;
}
/*
Function: setReturnValue
Sets the value that will be returned after the generated call.
Set to an empty string if no return value is desired.
Parameters:
Returns:
object : The <xajaxCall> object.
*/
function setReturnValue($sReturnValue) {
$this->sReturnValue = $sReturnValue;
}
/*
Function: generate
Construct a <xajax.call> statement in javascript that can be used
to make a xajax request with the parameters and settings previously
configured for this <xajaxCall> object.
The output from this function can be used as an event handler in your
javascript code.
Returns:
string - The javascript statement that will invoked the <xajax.call>
function on the browser, causing a xajax request to be sent to
the server.
*/
function generate() {
$saida = 'xajax.call("';
$saida .= $this->sFunction;
$saida .= '", {';
$separator = '';
if (0 < count($this->aParameters)) {
$saida .= 'parameters: [';
foreach ($this->aParameters as $aParameter) {
$saida .= $separator;
$bUseQuotes = $aParameter[1];
if ($bUseQuotes)
$saida .= '"';
$saida .= $aParameter[0];
if ($bUseQuotes)
$saida .= '"';
$separator = ',';
}
$saida .= ']';
}
if (0 < strlen($this->sMode)) {
$saida .= $separator;
$saida .= 'mode:"';
$saida .= $this->sMode;
$saida .= '"';
$separator = ',';
}
if (0 < strlen($this->sRequestType)) {
$saida .= $separator;
$saida .= 'requestType:"';
$saida .= $this->sRequestType;
$saida .= '"';
$separator = ',';
}
if (0 < strlen($this->sResponseProcessor)) {
$saida .= $separator;
$saida .= 'responseProcessor:';
$saida .= $this->sResponseProcessor;
$separator = ',';
}
if (0 < strlen($this->sRequestURI)) {
$saida .= $separator;
$saida .= 'requestURI:"';
$saida .= $this->sRequestURI;
$saida .= '"';
$separator = ',';
}
if (0 < strlen($this->sContentType)) {
$saida .= $separator;
$saida .= 'contentType:"';
$saida .= $this->sContentType;
$saida .= '"';
$separator = ',';
}
$saida .= '}); ';
if (0 < strlen($this->sReturnValue)) {
$saida .= 'return ';
$saida .= $this->sReturnValue;
} else {
$saida .= 'return false;';
}
return $saida;
}
}