1 | <?php |
---|
2 | /* |
---|
3 | File: xajaxResponse.inc.php |
---|
4 | |
---|
5 | Contains the response class. |
---|
6 | |
---|
7 | Title: xajax response class |
---|
8 | |
---|
9 | Please see <copyright.inc.php> for a detailed description, copyright |
---|
10 | and license information. |
---|
11 | */ |
---|
12 | |
---|
13 | /* |
---|
14 | @package xajax |
---|
15 | @version $Id: xajaxResponse.inc.php 361 2007-05-24 12:48:14Z calltoconstruct $ |
---|
16 | @copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson |
---|
17 | @license http://www.xajaxproject.org/bsd_license.txt BSD License |
---|
18 | */ |
---|
19 | |
---|
20 | /* |
---|
21 | Class: xajaxResponse |
---|
22 | |
---|
23 | Collect commands to be sent back to the browser in response to a xajax |
---|
24 | request. Commands are encoded and packaged in a format that is acceptable |
---|
25 | to the response handler from the javascript library running on the client |
---|
26 | side. |
---|
27 | |
---|
28 | Common commands include: |
---|
29 | - <xajaxResponse->assign>: Assign a value to an elements property. |
---|
30 | - <xajaxResponse->append>: Append a value on to an elements property. |
---|
31 | - <xajaxResponse->script>: Execute a portion of javascript code. |
---|
32 | - <xajaxResponse->call>: Execute an existing javascript function. |
---|
33 | - <xajaxResponse->alert>: Display an alert dialog to the user. |
---|
34 | |
---|
35 | Elements are identified by the value of the HTML id attribute. If you do |
---|
36 | not see your updates occuring on the browser side, ensure that you are |
---|
37 | using the correct id in your response. |
---|
38 | */ |
---|
39 | class xajaxResponse |
---|
40 | { |
---|
41 | /**#@+ |
---|
42 | * @access protected |
---|
43 | */ |
---|
44 | |
---|
45 | /* |
---|
46 | Array: aCommands |
---|
47 | |
---|
48 | Stores the commands that will be sent to the browser in the response. |
---|
49 | */ |
---|
50 | var $aCommands; |
---|
51 | |
---|
52 | /* |
---|
53 | String: sCharacterEncoding |
---|
54 | |
---|
55 | The name of the encoding method you wish to use when dealing with |
---|
56 | special characters. See <xajax->setEncoding> for more information. |
---|
57 | */ |
---|
58 | var $sCharacterEncoding; |
---|
59 | |
---|
60 | /* |
---|
61 | Boolean: bOutputEntities |
---|
62 | |
---|
63 | Convert special characters to the HTML equivellent. See also |
---|
64 | <xajax->bOutputEntities> and <xajax->setFlag>. |
---|
65 | */ |
---|
66 | var $bOutputEntities; |
---|
67 | |
---|
68 | /* |
---|
69 | Mixed: returnValue |
---|
70 | |
---|
71 | A string, array or integer value to be returned to the caller when |
---|
72 | using 'synchronous' mode requests. See <xajax->setMode> for details. |
---|
73 | */ |
---|
74 | var $returnValue; |
---|
75 | |
---|
76 | /* |
---|
77 | Object: objPluginManager |
---|
78 | |
---|
79 | A reference to the global plugin manager. |
---|
80 | */ |
---|
81 | var $objPluginManager; |
---|
82 | |
---|
83 | /**#@-*/ |
---|
84 | |
---|
85 | /* |
---|
86 | Constructor: xajaxResponse |
---|
87 | |
---|
88 | Create and initialize a xajaxResponse object. |
---|
89 | */ |
---|
90 | function xajaxResponse() |
---|
91 | { |
---|
92 | //SkipDebug |
---|
93 | if (0 < func_num_args()) { |
---|
94 | $objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
95 | trigger_error( |
---|
96 | $objLanguageManager->getText('XJXRSP:EDERR:01') |
---|
97 | , E_USER_ERROR |
---|
98 | ); |
---|
99 | } |
---|
100 | //EndSkipDebug |
---|
101 | |
---|
102 | $this->aCommands = array(); |
---|
103 | |
---|
104 | $objResponseManager =& xajaxResponseManager::getInstance(); |
---|
105 | |
---|
106 | $this->sCharacterEncoding = $objResponseManager->getCharacterEncoding(); |
---|
107 | $this->bOutputEntities = $objResponseManager->getOutputEntities(); |
---|
108 | |
---|
109 | $this->objPluginManager =& xajaxPluginManager::getInstance(); |
---|
110 | } |
---|
111 | |
---|
112 | /* |
---|
113 | Function: setCharacterEncoding |
---|
114 | |
---|
115 | Overrides the default character encoding (or the one specified in the |
---|
116 | constructor) to the specified character encoding. |
---|
117 | |
---|
118 | sCharacterEncoding - (string): The encoding method to use for this response. |
---|
119 | |
---|
120 | See also, <xajaxResponse->xajaxResponse>() |
---|
121 | |
---|
122 | Returns: |
---|
123 | |
---|
124 | object - The xajaxResponse object. |
---|
125 | */ |
---|
126 | function setCharacterEncoding($sCharacterEncoding) |
---|
127 | { |
---|
128 | $this->sCharacterEncoding = $sCharacterEncoding; |
---|
129 | return $this; |
---|
130 | } |
---|
131 | |
---|
132 | /* |
---|
133 | Function: setOutputEntities |
---|
134 | |
---|
135 | Convert special characters to their HTML equivellent automatically |
---|
136 | (only works if the mb_string extension is available). |
---|
137 | |
---|
138 | bOption - (boolean): Convert special characters |
---|
139 | |
---|
140 | Returns: |
---|
141 | |
---|
142 | object - The xajaxResponse object. |
---|
143 | */ |
---|
144 | function setOutputEntities($bOutputEntities) |
---|
145 | { |
---|
146 | $this->bOutputEntities = (boolean)$bOutputEntities; |
---|
147 | return $this; |
---|
148 | } |
---|
149 | |
---|
150 | /* |
---|
151 | Function: plugin |
---|
152 | |
---|
153 | Provides access to registered response plugins. If you are using PHP |
---|
154 | 4 or 5, pass the plugin name as the first argument, the plugin method |
---|
155 | name as the second argument and subsequent arguments (if any) to be |
---|
156 | passed along to the plugin. |
---|
157 | |
---|
158 | Optionally, if you use PHP 5, you can pass just the plugin name as the |
---|
159 | first argument and the plugin object will be returned. You can then |
---|
160 | access the methods of the plugin directly. |
---|
161 | |
---|
162 | sName - (string): Name of the plugin. |
---|
163 | sFunction - (string, optional): The name of the method to call. |
---|
164 | arg1...argn - (mixed, optional): Additional arguments to pass on to |
---|
165 | the plugin function. |
---|
166 | |
---|
167 | Returns: |
---|
168 | |
---|
169 | object - The plugin specified by sName. |
---|
170 | */ |
---|
171 | function &plugin() |
---|
172 | { |
---|
173 | $aArgs = func_get_args(); |
---|
174 | $nArgs = func_num_args(); |
---|
175 | |
---|
176 | //SkipDebug |
---|
177 | if (false == (0 < $nArgs)) { |
---|
178 | $objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
179 | trigger_error( |
---|
180 | $objLanguageManager->getText('XJXRSP:MPERR:01') |
---|
181 | , E_USER_ERROR |
---|
182 | ); |
---|
183 | } |
---|
184 | //EndSkipDebug |
---|
185 | |
---|
186 | $sName = array_shift($aArgs); |
---|
187 | |
---|
188 | $objPlugin =& $this->objPluginManager->getPlugin($sName); |
---|
189 | |
---|
190 | if (false === $objPlugin) |
---|
191 | { |
---|
192 | $bReturn = false; |
---|
193 | return $bReturn; |
---|
194 | } |
---|
195 | |
---|
196 | $objPlugin->setResponse($this); |
---|
197 | |
---|
198 | if (0 < count($aArgs)) |
---|
199 | { |
---|
200 | $sMethod = array_shift($aArgs); |
---|
201 | |
---|
202 | $aFunction = array(&$objPlugin, $sMethod); |
---|
203 | call_user_func_array($aFunction, $aArgs); |
---|
204 | } |
---|
205 | |
---|
206 | return $objPlugin; |
---|
207 | } |
---|
208 | |
---|
209 | /* |
---|
210 | Function: __get |
---|
211 | |
---|
212 | Magic function for PHP 5. Used to permit plugins to be called as if they |
---|
213 | where native members of the xajaxResponse instance. |
---|
214 | |
---|
215 | sPluginName - (string): The name of the plugin. |
---|
216 | |
---|
217 | Returns: |
---|
218 | |
---|
219 | object - The plugin specified by sPluginName. |
---|
220 | */ |
---|
221 | function &__get($sPluginName) |
---|
222 | { |
---|
223 | $objPlugin =& $this->plugin($sPluginName); |
---|
224 | return $objPlugin; |
---|
225 | } |
---|
226 | |
---|
227 | /* |
---|
228 | Function: confirmCommands |
---|
229 | |
---|
230 | Response command that prompts user with [ok] [cancel] style |
---|
231 | message box. If the user clicks cancel, the specified |
---|
232 | number of response commands following this one, will be |
---|
233 | skipped. |
---|
234 | |
---|
235 | iCmdNumber - (integer): The number of commands to skip upon cancel. |
---|
236 | sMessage - (string): The message to display to the user. |
---|
237 | |
---|
238 | Returns: |
---|
239 | |
---|
240 | object - The xajaxResponse object. |
---|
241 | */ |
---|
242 | function confirmCommands($iCmdNumber, $sMessage) |
---|
243 | { |
---|
244 | return $this->addCommand( |
---|
245 | array( |
---|
246 | 'n'=>'cc', |
---|
247 | 't'=>$iCmdNumber |
---|
248 | ), |
---|
249 | $sMessage |
---|
250 | ); |
---|
251 | } |
---|
252 | |
---|
253 | /* |
---|
254 | Function: assign |
---|
255 | |
---|
256 | Response command indicating that the specified value should be |
---|
257 | assigned to the given element's attribute. |
---|
258 | |
---|
259 | sTarget - (string): The id of the html element on the browser. |
---|
260 | sAttribute - (string): The property to be assigned. |
---|
261 | sData - (string): The value to be assigned to the property. |
---|
262 | |
---|
263 | Returns: |
---|
264 | |
---|
265 | object - The <xajaxResponse> object. |
---|
266 | |
---|
267 | Example: |
---|
268 | |
---|
269 | $objResponse->assign("contentDiv", "innerHTML", "Some Text"); |
---|
270 | */ |
---|
271 | function assign($sTarget,$sAttribute,$sData) |
---|
272 | { |
---|
273 | return $this->addCommand( |
---|
274 | array( |
---|
275 | 'n'=>'as', |
---|
276 | 't'=>$sTarget, |
---|
277 | 'p'=>$sAttribute |
---|
278 | ), |
---|
279 | $sData |
---|
280 | ); |
---|
281 | } |
---|
282 | |
---|
283 | /* |
---|
284 | Function: append |
---|
285 | |
---|
286 | Response command that indicates the specified data should be appended |
---|
287 | to the given element's property. |
---|
288 | |
---|
289 | sTarget - (string): The id of the element to be updated. |
---|
290 | sAttribute - (string): The name of the property to be appended to. |
---|
291 | sData - (string): The data to be appended to the property. |
---|
292 | |
---|
293 | Returns: |
---|
294 | |
---|
295 | object - The <xajaxResponse> object. |
---|
296 | */ |
---|
297 | function append($sTarget,$sAttribute,$sData) |
---|
298 | { |
---|
299 | return $this->addCommand( |
---|
300 | array( |
---|
301 | 'n'=>'ap', |
---|
302 | 't'=>$sTarget, |
---|
303 | 'p'=>$sAttribute |
---|
304 | ), |
---|
305 | $sData |
---|
306 | ); |
---|
307 | } |
---|
308 | |
---|
309 | /* |
---|
310 | Function: prepend |
---|
311 | |
---|
312 | Response command to prepend the specified value onto the given |
---|
313 | element's property. |
---|
314 | |
---|
315 | sTarget - (string): The id of the element to be updated. |
---|
316 | sAttribute - (string): The property to be updated. |
---|
317 | sData - (string): The value to be prepended. |
---|
318 | |
---|
319 | Returns: |
---|
320 | |
---|
321 | object - The <xajaxResponse> object. |
---|
322 | */ |
---|
323 | function prepend($sTarget,$sAttribute,$sData) |
---|
324 | { |
---|
325 | return $this->addCommand( |
---|
326 | array( |
---|
327 | 'n'=>'pp', |
---|
328 | 't'=>$sTarget, |
---|
329 | 'p'=>$sAttribute |
---|
330 | ), |
---|
331 | $sData |
---|
332 | ); |
---|
333 | } |
---|
334 | |
---|
335 | /* |
---|
336 | Function: replace |
---|
337 | |
---|
338 | Replace a specified value with another value within the given |
---|
339 | element's property. |
---|
340 | |
---|
341 | sTarget - (string): The id of the element to update. |
---|
342 | sAttribute - (string): The property to be updated. |
---|
343 | sSearch - (string): The needle to search for. |
---|
344 | sData - (string): The data to use in place of the needle. |
---|
345 | */ |
---|
346 | function replace($sTarget,$sAttribute,$sSearch,$sData) |
---|
347 | { |
---|
348 | return $this->addCommand( |
---|
349 | array( |
---|
350 | 'n'=>'rp', |
---|
351 | 't'=>$sTarget, |
---|
352 | 'p'=>$sAttribute |
---|
353 | ), |
---|
354 | array( |
---|
355 | 's' => $sSearch, |
---|
356 | 'r' => $sData |
---|
357 | ) |
---|
358 | ); |
---|
359 | } |
---|
360 | |
---|
361 | /* |
---|
362 | Function: clear |
---|
363 | |
---|
364 | Response command used to clear the specified property of the |
---|
365 | given element. |
---|
366 | |
---|
367 | sTarget - (string): The id of the element to be updated. |
---|
368 | sAttribute - (string): The property to be clared. |
---|
369 | |
---|
370 | Returns: |
---|
371 | |
---|
372 | object - The <xajaxResponse> object. |
---|
373 | */ |
---|
374 | function clear($sTarget,$sAttribute) |
---|
375 | { |
---|
376 | return $this->assign( |
---|
377 | $sTarget, |
---|
378 | $sAttribute, |
---|
379 | '' |
---|
380 | ); |
---|
381 | } |
---|
382 | |
---|
383 | /* |
---|
384 | Function: contextAssign |
---|
385 | |
---|
386 | Response command used to assign a value to a member of a |
---|
387 | javascript object (or element) that is specified by the context |
---|
388 | member of the request. The object is referenced using the 'this' keyword |
---|
389 | in the sAttribute parameter. |
---|
390 | |
---|
391 | sAttribute - (string): The property to be updated. |
---|
392 | sData - (string): The value to assign. |
---|
393 | |
---|
394 | Returns: |
---|
395 | |
---|
396 | object - The <xajaxResponse> object. |
---|
397 | */ |
---|
398 | function contextAssign($sAttribute, $sData) |
---|
399 | { |
---|
400 | return $this->addCommand( |
---|
401 | array( |
---|
402 | 'n'=>'c:as', |
---|
403 | 'p'=>$sAttribute |
---|
404 | ), |
---|
405 | $sData |
---|
406 | ); |
---|
407 | } |
---|
408 | |
---|
409 | /* |
---|
410 | Function: contextAppend |
---|
411 | |
---|
412 | Response command used to append a value onto the specified member |
---|
413 | of the javascript context object (or element) specified by the context |
---|
414 | member of the request. The object is referenced using the 'this' keyword |
---|
415 | in the sAttribute parameter. |
---|
416 | |
---|
417 | sAttribute - (string): The member to be appended to. |
---|
418 | sData - (string): The value to append. |
---|
419 | |
---|
420 | Returns: |
---|
421 | |
---|
422 | object - The <xajaxResponse> object. |
---|
423 | */ |
---|
424 | function contextAppend($sAttribute, $sData) |
---|
425 | { |
---|
426 | return $this->addCommand( |
---|
427 | array( |
---|
428 | 'n'=>'c:ap', |
---|
429 | 'p'=>$sAttribute |
---|
430 | ), |
---|
431 | $sData |
---|
432 | ); |
---|
433 | } |
---|
434 | |
---|
435 | /* |
---|
436 | Function: contextPrepend |
---|
437 | |
---|
438 | Response command used to prepend the speicified data to the given |
---|
439 | member of the current javascript object specified by context in the |
---|
440 | current request. The object is access via the 'this' keyword in the |
---|
441 | sAttribute parameter. |
---|
442 | |
---|
443 | sAttribute - (string): The member to be updated. |
---|
444 | sData - (string): The value to be prepended. |
---|
445 | |
---|
446 | Returns: |
---|
447 | |
---|
448 | object - The <xajaxResponse> object. |
---|
449 | */ |
---|
450 | function contextPrepend($sAttribute, $sData) |
---|
451 | { |
---|
452 | return $this->addCommand( |
---|
453 | array( |
---|
454 | 'n'=>'c:pp', |
---|
455 | 'p'=>$sAttribute |
---|
456 | ), |
---|
457 | $sData |
---|
458 | ); |
---|
459 | } |
---|
460 | |
---|
461 | /* |
---|
462 | Function: contextClear |
---|
463 | |
---|
464 | Response command used to clear the value of the property specified |
---|
465 | in the sAttribute parameter. The member is access via the 'this' |
---|
466 | keyword and can be used to update a javascript object specified |
---|
467 | by context in the request parameters. |
---|
468 | |
---|
469 | sAttribute - (string): The member to be cleared. |
---|
470 | |
---|
471 | Returns: |
---|
472 | |
---|
473 | object - The <xajaxResponse> object. |
---|
474 | */ |
---|
475 | function contextClear($sAttribute) |
---|
476 | { |
---|
477 | return $this->contextAssign( |
---|
478 | $sAttribute, |
---|
479 | '' |
---|
480 | ); |
---|
481 | } |
---|
482 | |
---|
483 | /* |
---|
484 | Function: alert |
---|
485 | |
---|
486 | Response command that is used to display an alert message to the user. |
---|
487 | |
---|
488 | sMsg - (string): The message to be displayed. |
---|
489 | |
---|
490 | Returns: |
---|
491 | |
---|
492 | object - The <xajaxResponse> object. |
---|
493 | */ |
---|
494 | function alert($sMsg) |
---|
495 | { |
---|
496 | return $this->addCommand( |
---|
497 | array( |
---|
498 | 'n'=>'al' |
---|
499 | ), |
---|
500 | $sMsg |
---|
501 | ); |
---|
502 | } |
---|
503 | |
---|
504 | function debug($sMessage) |
---|
505 | { |
---|
506 | return $this->addCommand( |
---|
507 | array( |
---|
508 | 'n'=>'dbg' |
---|
509 | ), |
---|
510 | $sMessage |
---|
511 | ); |
---|
512 | } |
---|
513 | |
---|
514 | /* |
---|
515 | Function: redirect |
---|
516 | |
---|
517 | Response command that causes the browser to navigate to the specified |
---|
518 | URL. |
---|
519 | |
---|
520 | sURL - (string): The relative or fully qualified URL. |
---|
521 | iDelay - (integer, optional): Number of seconds to delay before |
---|
522 | the redirect occurs. |
---|
523 | |
---|
524 | Returns: |
---|
525 | |
---|
526 | object - The <xajaxResponse> object. |
---|
527 | */ |
---|
528 | function redirect($sURL, $iDelay=0) |
---|
529 | { |
---|
530 | //we need to parse the query part so that the values are rawurlencode()'ed |
---|
531 | //can't just use parse_url() cos we could be dealing with a relative URL which |
---|
532 | // parse_url() can't deal with. |
---|
533 | $queryStart = strpos($sURL, '?', strrpos($sURL, '/')); |
---|
534 | if ($queryStart !== FALSE) |
---|
535 | { |
---|
536 | $queryStart++; |
---|
537 | $queryEnd = strpos($sURL, '#', $queryStart); |
---|
538 | if ($queryEnd === FALSE) |
---|
539 | $queryEnd = strlen($sURL); |
---|
540 | $queryPart = substr($sURL, $queryStart, $queryEnd-$queryStart); |
---|
541 | parse_str($queryPart, $queryParts); |
---|
542 | $newQueryPart = ""; |
---|
543 | if ($queryParts) |
---|
544 | { |
---|
545 | $first = true; |
---|
546 | foreach($queryParts as $key => $value) |
---|
547 | { |
---|
548 | if ($first) |
---|
549 | $first = false; |
---|
550 | else |
---|
551 | $newQueryPart .= ini_get('arg_separator.output'); |
---|
552 | $newQueryPart .= rawurlencode($key).'='.rawurlencode($value); |
---|
553 | } |
---|
554 | } else if ($_SERVER['QUERY_STRING']) { |
---|
555 | //couldn't break up the query, but there's one there |
---|
556 | //possibly "http://url/page.html?query1234" type of query? |
---|
557 | //just encode it and hope it works |
---|
558 | $newQueryPart = rawurlencode($_SERVER['QUERY_STRING']); |
---|
559 | } |
---|
560 | $sURL = str_replace($queryPart, $newQueryPart, $sURL); |
---|
561 | } |
---|
562 | if ($iDelay) |
---|
563 | $this->script( |
---|
564 | 'window.setTimeout("window.location = \'' |
---|
565 | . $sURL |
---|
566 | . '\';",' |
---|
567 | . ($iDelay*1000) |
---|
568 | . ');' |
---|
569 | ); |
---|
570 | else |
---|
571 | $this->script( |
---|
572 | 'window.location = "' |
---|
573 | . $sURL |
---|
574 | . '";' |
---|
575 | ); |
---|
576 | return $this; |
---|
577 | } |
---|
578 | |
---|
579 | /* |
---|
580 | Function: script |
---|
581 | |
---|
582 | Response command that is used to execute a portion of javascript on |
---|
583 | the browser. The script runs in it's own context, so variables declared |
---|
584 | locally, using the 'var' keyword, will no longer be available after the |
---|
585 | call. To construct a variable that will be accessable globally, even |
---|
586 | after the script has executed, leave off the 'var' keyword. |
---|
587 | |
---|
588 | sJS - (string): The script to execute. |
---|
589 | |
---|
590 | Returns: |
---|
591 | |
---|
592 | object - The <xajaxResponse> object. |
---|
593 | */ |
---|
594 | function script($sJS) |
---|
595 | { |
---|
596 | return $this->addCommand( |
---|
597 | array( |
---|
598 | 'n'=>'js' |
---|
599 | ), |
---|
600 | $sJS |
---|
601 | ); |
---|
602 | } |
---|
603 | |
---|
604 | /* |
---|
605 | Function: call |
---|
606 | |
---|
607 | Response command that indicates that the specified javascript |
---|
608 | function should be called with the given (optional) parameters. |
---|
609 | |
---|
610 | arg1 - (string): The name of the function to call. |
---|
611 | arg2 .. argn - arguments to be passed to the function. |
---|
612 | |
---|
613 | Returns: |
---|
614 | |
---|
615 | object - The <xajaxResponse> object. |
---|
616 | */ |
---|
617 | function call() { |
---|
618 | $aArgs = func_get_args(); |
---|
619 | $sFunc = array_shift($aArgs); |
---|
620 | return $this->addCommand( |
---|
621 | array( |
---|
622 | 'n'=>'jc', |
---|
623 | 'f'=>$sFunc |
---|
624 | ), |
---|
625 | $aArgs |
---|
626 | ); |
---|
627 | } |
---|
628 | |
---|
629 | /* |
---|
630 | Function: remove |
---|
631 | |
---|
632 | Response command used to remove an element from the document. |
---|
633 | |
---|
634 | sTarget - (string): The id of the element to be removed. |
---|
635 | |
---|
636 | Returns: |
---|
637 | |
---|
638 | object - The <xajaxResponse> object. |
---|
639 | */ |
---|
640 | function remove($sTarget) |
---|
641 | { |
---|
642 | return $this->addCommand( |
---|
643 | array( |
---|
644 | 'n'=>'rm', |
---|
645 | 't'=>$sTarget), |
---|
646 | '' |
---|
647 | ); |
---|
648 | } |
---|
649 | |
---|
650 | /* |
---|
651 | Function: create |
---|
652 | |
---|
653 | Response command used to create a new element on the browser. |
---|
654 | |
---|
655 | sParent - (string): The id of the parent element. |
---|
656 | sTag - (string): The tag name to be used for the new element. |
---|
657 | sId - (string): The id to assign to the new element. |
---|
658 | sType - (string, optional): The type of tag, deprecated, use |
---|
659 | <xajaxResponse->createInput> instead. |
---|
660 | |
---|
661 | Returns: |
---|
662 | |
---|
663 | object - The <xajaxResponse> object. |
---|
664 | */ |
---|
665 | function create($sParent, $sTag, $sId, $sType=null) |
---|
666 | { |
---|
667 | //SkipDebug |
---|
668 | if (false === (null === $sType)) { |
---|
669 | $objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
670 | trigger_error( |
---|
671 | $objLanguageManager->getText('XJXRSP:CPERR:01') |
---|
672 | , E_USER_WARNING |
---|
673 | ); |
---|
674 | } |
---|
675 | //EndSkipDebug |
---|
676 | |
---|
677 | return $this->addCommand( |
---|
678 | array( |
---|
679 | 'n'=>'ce', |
---|
680 | 't'=>$sParent, |
---|
681 | 'p'=>$sId |
---|
682 | ), |
---|
683 | $sTag |
---|
684 | ); |
---|
685 | } |
---|
686 | |
---|
687 | /* |
---|
688 | Function: insert |
---|
689 | |
---|
690 | Response command used to insert a new element just prior to the specified |
---|
691 | element. |
---|
692 | |
---|
693 | sBefore - (string): The element used as a reference point for the |
---|
694 | insertion. |
---|
695 | sTag - (string): The tag to be used for the new element. |
---|
696 | sId - (string): The id to be used for the new element. |
---|
697 | |
---|
698 | Returns: |
---|
699 | |
---|
700 | object - The <xajaxResponse> object. |
---|
701 | */ |
---|
702 | function insert($sBefore, $sTag, $sId) |
---|
703 | { |
---|
704 | return $this->addCommand( |
---|
705 | array( |
---|
706 | 'n'=>'ie', |
---|
707 | 't'=>$sBefore, |
---|
708 | 'p'=>$sId |
---|
709 | ), |
---|
710 | $sTag |
---|
711 | ); |
---|
712 | } |
---|
713 | |
---|
714 | /* |
---|
715 | Function: insertAfter |
---|
716 | |
---|
717 | Response command used to insert a new element after the specified |
---|
718 | one. |
---|
719 | |
---|
720 | sAfter - (string): The id of the element that will be used as a reference |
---|
721 | for the insertion. |
---|
722 | sTag - (string): The tag name to be used for the new element. |
---|
723 | sId - (string): The id to be used for the new element. |
---|
724 | |
---|
725 | Returns: |
---|
726 | |
---|
727 | object - The <xajaxResponse> object. |
---|
728 | */ |
---|
729 | function insertAfter($sAfter, $sTag, $sId) |
---|
730 | { |
---|
731 | return $this->addCommand( |
---|
732 | array( |
---|
733 | 'n'=>'ia', |
---|
734 | 't'=>$sAfter, |
---|
735 | 'p'=>$sId |
---|
736 | ), |
---|
737 | $sTag |
---|
738 | ); |
---|
739 | } |
---|
740 | |
---|
741 | /* |
---|
742 | Function: createInput |
---|
743 | |
---|
744 | Response command used to create an input element on the browser. |
---|
745 | |
---|
746 | sParent - (string): The id of the parent element. |
---|
747 | sType - (string): The type of the new input element. |
---|
748 | sName - (string): The name of the new input element. |
---|
749 | sId - (string): The id of the new element. |
---|
750 | |
---|
751 | Returns: |
---|
752 | |
---|
753 | object - The <xajaxResponse> object. |
---|
754 | */ |
---|
755 | function createInput($sParent, $sType, $sName, $sId) |
---|
756 | { |
---|
757 | return $this->addCommand( |
---|
758 | array( |
---|
759 | 'n'=>'ci', |
---|
760 | 't'=>$sParent, |
---|
761 | 'p'=>$sId, |
---|
762 | 'c'=>$sType |
---|
763 | ), |
---|
764 | $sName |
---|
765 | ); |
---|
766 | } |
---|
767 | |
---|
768 | /* |
---|
769 | Function: insertInput |
---|
770 | |
---|
771 | Response command used to insert a new input element preceeding the |
---|
772 | specified element. |
---|
773 | |
---|
774 | sBefore - (string): The id of the element to be used as the reference |
---|
775 | point for the insertion. |
---|
776 | sType - (string): The type of the new input element. |
---|
777 | sName - (string): The name of the new input element. |
---|
778 | sId - (string): The id of the new input element. |
---|
779 | |
---|
780 | Returns: |
---|
781 | |
---|
782 | object - The <xajaxResponse> object. |
---|
783 | */ |
---|
784 | function insertInput($sBefore, $sType, $sName, $sId) |
---|
785 | { |
---|
786 | return $this->addCommand( |
---|
787 | array( |
---|
788 | 'n'=>'ii', |
---|
789 | 't'=>$sBefore, |
---|
790 | 'p'=>$sId, |
---|
791 | 'c'=>$sType |
---|
792 | ), |
---|
793 | $sName |
---|
794 | ); |
---|
795 | } |
---|
796 | |
---|
797 | /* |
---|
798 | Function: insertInputAfter |
---|
799 | |
---|
800 | Response command used to insert a new input element after the |
---|
801 | specified element. |
---|
802 | |
---|
803 | sAfter - (string): The id of the element that is to be used |
---|
804 | as the insertion point for the new element. |
---|
805 | sType - (string): The type of the new input element. |
---|
806 | sName - (string): The name of the new input element. |
---|
807 | sId - (string): The id of the new input element. |
---|
808 | |
---|
809 | Returns: |
---|
810 | |
---|
811 | object - The <xajaxResponse> object. |
---|
812 | */ |
---|
813 | function insertInputAfter($sAfter, $sType, $sName, $sId) |
---|
814 | { |
---|
815 | return $this->addCommand( |
---|
816 | array( |
---|
817 | 'n'=>'iia', |
---|
818 | 't'=>$sAfter, |
---|
819 | 'p'=>$sId, |
---|
820 | 'c'=>$sType |
---|
821 | ), |
---|
822 | $sName |
---|
823 | ); |
---|
824 | } |
---|
825 | |
---|
826 | /* |
---|
827 | Function: setEvent |
---|
828 | |
---|
829 | Response command used to set an event handler on the browser. |
---|
830 | |
---|
831 | sTarget - (string): The id of the element that contains the event. |
---|
832 | sEvent - (string): The name of the event. |
---|
833 | sScript - (string): The javascript to execute when the event is fired. |
---|
834 | |
---|
835 | Returns: |
---|
836 | |
---|
837 | object - The <xajaxResponse> object. |
---|
838 | */ |
---|
839 | function setEvent($sTarget,$sEvent,$sScript) |
---|
840 | { |
---|
841 | return $this->addCommand( |
---|
842 | array( |
---|
843 | 'n'=>'ev', |
---|
844 | 't'=>$sTarget, |
---|
845 | 'p'=>$sEvent |
---|
846 | ), |
---|
847 | $sScript |
---|
848 | ); |
---|
849 | } |
---|
850 | |
---|
851 | function addEvent($sTarget,$sEvent,$sScript) |
---|
852 | { |
---|
853 | return $this->setEvent( |
---|
854 | $sTarget, |
---|
855 | $sEvent, |
---|
856 | $sScript |
---|
857 | ); |
---|
858 | } |
---|
859 | |
---|
860 | /* |
---|
861 | Function: addHandler |
---|
862 | |
---|
863 | Response command used to install an event handler on the specified element. |
---|
864 | |
---|
865 | sTarget - (string): The id of the element. |
---|
866 | sEvent - (string): The name of the event to add the handler to. |
---|
867 | sHandler - (string): The javascript function to call when the event is fired. |
---|
868 | |
---|
869 | You can add more than one event handler to an element's event using this method. |
---|
870 | |
---|
871 | Returns: |
---|
872 | |
---|
873 | object - The <xajaxResponse> object. |
---|
874 | */ |
---|
875 | function addHandler($sTarget,$sEvent,$sHandler) |
---|
876 | { |
---|
877 | return $this->addCommand( |
---|
878 | array( |
---|
879 | 'n'=>'ah', |
---|
880 | 't'=>$sTarget, |
---|
881 | 'p'=>$sEvent |
---|
882 | ), |
---|
883 | $sHandler |
---|
884 | ); |
---|
885 | } |
---|
886 | |
---|
887 | /* |
---|
888 | Function: removeHandler |
---|
889 | |
---|
890 | Response command used to remove an event handler from an element. |
---|
891 | |
---|
892 | sTarget - (string): The id of the element. |
---|
893 | sEvent - (string): The name of the event. |
---|
894 | sHandler - (string): The javascript function that is called when the |
---|
895 | event is fired. |
---|
896 | |
---|
897 | Returns: |
---|
898 | |
---|
899 | object - The <xajaxResponse> object. |
---|
900 | */ |
---|
901 | function removeHandler($sTarget,$sEvent,$sHandler) |
---|
902 | { |
---|
903 | return $this->addCommand( |
---|
904 | array( |
---|
905 | 'n'=>'rh', |
---|
906 | 't'=>$sTarget, |
---|
907 | 'p'=>$sEvent |
---|
908 | ), |
---|
909 | $sHandler); |
---|
910 | } |
---|
911 | |
---|
912 | /* |
---|
913 | Function: setFunction |
---|
914 | |
---|
915 | Response command used to construct a javascript function on the browser. |
---|
916 | |
---|
917 | sFunction - (string): The name of the function to construct. |
---|
918 | sArgs - (string): Comma separated list of parameter names. |
---|
919 | sScript - (string): The javascript code that will become the body of the |
---|
920 | function. |
---|
921 | |
---|
922 | Returns: |
---|
923 | |
---|
924 | object - The <xajaxResponse> object. |
---|
925 | */ |
---|
926 | function setFunction($sFunction, $sArgs, $sScript) |
---|
927 | { |
---|
928 | return $this->addCommand( |
---|
929 | array( |
---|
930 | 'n'=>'sf', |
---|
931 | 'f'=>$sFunction, |
---|
932 | 'p'=>$sArgs |
---|
933 | ), |
---|
934 | $sScript |
---|
935 | ); |
---|
936 | } |
---|
937 | |
---|
938 | /* |
---|
939 | Function: wrapFunction |
---|
940 | |
---|
941 | Response command used to construct a wrapper function around |
---|
942 | and existing javascript function on the browser. |
---|
943 | |
---|
944 | sFunction - (string): The name of the existing function to wrap. |
---|
945 | sArgs - (string): The comma separated list of parameters for the function. |
---|
946 | aScripts - (array): An array of javascript code snippets that will |
---|
947 | be used to build the body of the function. The first piece of code |
---|
948 | specified in the array will occur before the call to the original |
---|
949 | function, the second will occur after the original function is called. |
---|
950 | sReturnValueVariable - (string): The name of the variable that will |
---|
951 | retain the return value from the call to the original function. |
---|
952 | |
---|
953 | Returns: |
---|
954 | |
---|
955 | object - The <xajaxResponse> object. |
---|
956 | */ |
---|
957 | function wrapFunction($sFunction, $sArgs, $aScripts, $sReturnValueVariable) |
---|
958 | { |
---|
959 | return $this->addCommand( |
---|
960 | array( |
---|
961 | 'n'=>'wpf', |
---|
962 | 'f'=>$sFunction, |
---|
963 | 'p'=>$sArgs, |
---|
964 | 'c'=>$sReturnValueVariable |
---|
965 | ), |
---|
966 | $aScripts |
---|
967 | ); |
---|
968 | } |
---|
969 | |
---|
970 | /* |
---|
971 | Function: includeScript |
---|
972 | |
---|
973 | Response command used to load a javascript file on the browser. |
---|
974 | |
---|
975 | sFileName - (string): The relative or fully qualified URI of the |
---|
976 | javascript file. |
---|
977 | |
---|
978 | Returns: |
---|
979 | |
---|
980 | object - The <xajaxResponse> object. |
---|
981 | */ |
---|
982 | function includeScript($sFileName) |
---|
983 | { |
---|
984 | return $this->addCommand( |
---|
985 | array( |
---|
986 | 'n'=>'in' |
---|
987 | ), |
---|
988 | $sFileName |
---|
989 | ); |
---|
990 | } |
---|
991 | |
---|
992 | /* |
---|
993 | Function: includeScriptOnce |
---|
994 | |
---|
995 | Response command used to include a javascript file on the browser |
---|
996 | if it has not already been loaded. |
---|
997 | |
---|
998 | sFileName - (string): The relative for fully qualified URI of the |
---|
999 | javascript file. |
---|
1000 | |
---|
1001 | Returns: |
---|
1002 | |
---|
1003 | object - The <xajaxResponse> object. |
---|
1004 | */ |
---|
1005 | function includeScriptOnce($sFileName) |
---|
1006 | { |
---|
1007 | return $this->addCommand( |
---|
1008 | array( |
---|
1009 | 'n'=>'ino' |
---|
1010 | ), |
---|
1011 | $sFileName |
---|
1012 | ); |
---|
1013 | } |
---|
1014 | |
---|
1015 | /* |
---|
1016 | Function: removeScript |
---|
1017 | |
---|
1018 | Response command used to remove a SCRIPT reference to a javascript |
---|
1019 | file on the browser. Optionally, you can call a javascript function |
---|
1020 | just prior to the file being unloaded (for cleanup). |
---|
1021 | |
---|
1022 | sFileName - (string): The relative or fully qualified URI of the |
---|
1023 | javascript file. |
---|
1024 | sUnload - (string): Name of a javascript function to call prior |
---|
1025 | to unlaoding the file. |
---|
1026 | |
---|
1027 | Returns: |
---|
1028 | |
---|
1029 | object - The <xajaxResponse> object. |
---|
1030 | */ |
---|
1031 | function removeScript($sFileName, $sUnload = '') { |
---|
1032 | $this->addCommand( |
---|
1033 | array( |
---|
1034 | 'n'=>'rjs' |
---|
1035 | ), |
---|
1036 | ('' != $sUnload) |
---|
1037 | ? array($sFileName, $sUnload) |
---|
1038 | : $sFileName |
---|
1039 | ); |
---|
1040 | return $this; |
---|
1041 | } |
---|
1042 | |
---|
1043 | /* |
---|
1044 | Function: includeCSS |
---|
1045 | |
---|
1046 | Response command used to include a LINK reference to |
---|
1047 | the specified CSS file on the browser. This will cause the |
---|
1048 | browser to load and apply the style sheet. |
---|
1049 | |
---|
1050 | sFileName - (string): The relative or fully qualified URI of |
---|
1051 | the css file. |
---|
1052 | |
---|
1053 | Returns: |
---|
1054 | |
---|
1055 | object - The <xajaxResponse> object. |
---|
1056 | */ |
---|
1057 | function includeCSS($sFileName) |
---|
1058 | { |
---|
1059 | return $this->addCommand( |
---|
1060 | array( |
---|
1061 | 'n'=>'css' |
---|
1062 | ), |
---|
1063 | $sFileName |
---|
1064 | ); |
---|
1065 | } |
---|
1066 | |
---|
1067 | /* |
---|
1068 | Function: removeCSS |
---|
1069 | |
---|
1070 | Response command used to remove a LINK reference to |
---|
1071 | a CSS file on the browser. This causes the browser to |
---|
1072 | unload the style sheet, effectively removing the style |
---|
1073 | changes it caused. |
---|
1074 | |
---|
1075 | sFileName - (string): The relative or fully qualified URI |
---|
1076 | of the css file. |
---|
1077 | |
---|
1078 | Returns: |
---|
1079 | |
---|
1080 | object - The <xajaxResponse> object. |
---|
1081 | */ |
---|
1082 | function removeCSS($sFileName) |
---|
1083 | { |
---|
1084 | return $this->addCommand( |
---|
1085 | array( |
---|
1086 | 'n'=>'rcss' |
---|
1087 | ), |
---|
1088 | $sFileName |
---|
1089 | ); |
---|
1090 | } |
---|
1091 | |
---|
1092 | /* |
---|
1093 | Function: waitForCSS |
---|
1094 | |
---|
1095 | Response command instructing xajax to pause while the CSS |
---|
1096 | files are loaded. The browser is not typically a multi-threading |
---|
1097 | application, with regards to javascript code. Therefore, the |
---|
1098 | CSS files included or removed with <xajaxResponse->includeCSS> and |
---|
1099 | <xajaxResponse->removeCSS> respectively, will not be loaded or |
---|
1100 | removed until the browser regains control from the script. This |
---|
1101 | command returns control back to the browser and pauses the execution |
---|
1102 | of the response until the CSS files, included previously, are |
---|
1103 | loaded. |
---|
1104 | |
---|
1105 | iTimeout - (integer): The number of 1/10ths of a second to pause |
---|
1106 | before timing out and continuing with the execution of the |
---|
1107 | response commands. |
---|
1108 | |
---|
1109 | Returns: |
---|
1110 | |
---|
1111 | object - The <xajaxResponse> object. |
---|
1112 | */ |
---|
1113 | function waitForCSS($iTimeout = 600) { |
---|
1114 | $sData = ""; |
---|
1115 | $this->addCommand( |
---|
1116 | array( |
---|
1117 | 'n'=>'wcss', |
---|
1118 | 'p'=>$iTimeout |
---|
1119 | ), |
---|
1120 | $sData |
---|
1121 | ); |
---|
1122 | return $this; |
---|
1123 | } |
---|
1124 | |
---|
1125 | /* |
---|
1126 | Function: waitFor |
---|
1127 | |
---|
1128 | Response command instructing xajax to delay execution of the response |
---|
1129 | commands until a specified condition is met. Note, this returns control |
---|
1130 | to the browser, so that other script operations can execute. xajax |
---|
1131 | will continue to monitor the specified condition and, when it evaulates |
---|
1132 | to true, will continue processing response commands. |
---|
1133 | |
---|
1134 | script - (string): A piece of javascript code that evaulates to true |
---|
1135 | or false. |
---|
1136 | tenths - (integer): The number of 1/10ths of a second to wait before |
---|
1137 | timing out and continuing with the execution of the response |
---|
1138 | commands. |
---|
1139 | |
---|
1140 | Returns: |
---|
1141 | |
---|
1142 | object - The <xajaxResponse> object. |
---|
1143 | */ |
---|
1144 | function waitFor($script, $tenths) { |
---|
1145 | return $this->addCommand( |
---|
1146 | array( |
---|
1147 | 'n'=>'wf', |
---|
1148 | 'p'=>$tenths |
---|
1149 | ), |
---|
1150 | $script |
---|
1151 | ); |
---|
1152 | } |
---|
1153 | |
---|
1154 | /* |
---|
1155 | Function: sleep |
---|
1156 | |
---|
1157 | Response command which instructs xajax to pause execution |
---|
1158 | of the response commands, returning control to the browser |
---|
1159 | so it can perform other commands asynchronously. After |
---|
1160 | the specified delay, xajax will continue execution of the |
---|
1161 | response commands. |
---|
1162 | |
---|
1163 | tenths - (integer): The number of 1/10ths of a second to |
---|
1164 | sleep. |
---|
1165 | |
---|
1166 | Returns: |
---|
1167 | |
---|
1168 | object - The <xajaxResponse> object. |
---|
1169 | */ |
---|
1170 | function sleep($tenths) { |
---|
1171 | $this->addCommand( |
---|
1172 | array( |
---|
1173 | 'n'=>'s', |
---|
1174 | 'p'=>$tenths |
---|
1175 | ), |
---|
1176 | '' |
---|
1177 | ); |
---|
1178 | return $this; |
---|
1179 | } |
---|
1180 | |
---|
1181 | /* |
---|
1182 | Function: setReturnValue |
---|
1183 | |
---|
1184 | Stores a value that will be passed back as part of the response. |
---|
1185 | When making synchronous requests, the calling javascript can |
---|
1186 | obtain this value immediately as the return value of the |
---|
1187 | <xajax.call> function. |
---|
1188 | |
---|
1189 | value - (mixed): Any value. |
---|
1190 | |
---|
1191 | Returns: |
---|
1192 | |
---|
1193 | object - The <xajaxResponse> object. |
---|
1194 | */ |
---|
1195 | function setReturnValue($value) { |
---|
1196 | $this->returnValue = $this->_encodeArray($value); |
---|
1197 | return $this; |
---|
1198 | } |
---|
1199 | |
---|
1200 | /* |
---|
1201 | Function: getContentType |
---|
1202 | |
---|
1203 | Returns the current content type that will be used for the |
---|
1204 | response packet. (typically: "text/xml") |
---|
1205 | |
---|
1206 | Returns: |
---|
1207 | |
---|
1208 | string - The content type. |
---|
1209 | */ |
---|
1210 | function getContentType() |
---|
1211 | { |
---|
1212 | return 'text/xml'; |
---|
1213 | } |
---|
1214 | |
---|
1215 | /* |
---|
1216 | Function: getOutput |
---|
1217 | */ |
---|
1218 | function getOutput() |
---|
1219 | { |
---|
1220 | ob_start(); |
---|
1221 | $this->_printHeader_XML(); |
---|
1222 | $this->_printResponse_XML(); |
---|
1223 | return ob_get_clean(); |
---|
1224 | } |
---|
1225 | |
---|
1226 | /* |
---|
1227 | Function: printOutput |
---|
1228 | |
---|
1229 | Prints the output, generated from the commands added to the response, |
---|
1230 | that will be sent to the browser. |
---|
1231 | |
---|
1232 | Returns: |
---|
1233 | |
---|
1234 | string - The textual representation of the response commands. |
---|
1235 | */ |
---|
1236 | function printOutput() |
---|
1237 | { |
---|
1238 | $this->_sendHeaders(); |
---|
1239 | $this->_printHeader_XML(); |
---|
1240 | $this->_printResponse_XML(); |
---|
1241 | } |
---|
1242 | |
---|
1243 | /* |
---|
1244 | Function: _sendHeaders |
---|
1245 | |
---|
1246 | Used internally to generate the response headers. |
---|
1247 | */ |
---|
1248 | function _sendHeaders() |
---|
1249 | { |
---|
1250 | $objArgumentManager =& xajaxArgumentManager::getInstance(); |
---|
1251 | if (XAJAX_METHOD_GET == $objArgumentManager->getRequestMethod()) |
---|
1252 | { |
---|
1253 | header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); |
---|
1254 | header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
---|
1255 | header ("Cache-Control: no-cache, must-revalidate"); |
---|
1256 | header ("Pragma: no-cache"); |
---|
1257 | } |
---|
1258 | |
---|
1259 | $sCharacterSet = ''; |
---|
1260 | if ($this->sCharacterEncoding && 0 < strlen(trim($this->sCharacterEncoding))) { |
---|
1261 | $sCharacterSet = '; charset="' . trim($this->sCharacterEncoding) . '"'; |
---|
1262 | } |
---|
1263 | |
---|
1264 | $sContentType = $this->getContentType(); |
---|
1265 | |
---|
1266 | header('content-type: ' . $sContentType . ' ' . $sCharacterSet); |
---|
1267 | } |
---|
1268 | |
---|
1269 | /* |
---|
1270 | Function: getCommandCount |
---|
1271 | |
---|
1272 | Returns: |
---|
1273 | |
---|
1274 | integer - The number of commands in the response. |
---|
1275 | */ |
---|
1276 | function getCommandCount() |
---|
1277 | { |
---|
1278 | return count($this->aCommands); |
---|
1279 | } |
---|
1280 | |
---|
1281 | /* |
---|
1282 | Function: loadCommands |
---|
1283 | |
---|
1284 | Merges the response commands from the specified <xajaxResponse> |
---|
1285 | object with the response commands in this <xajaxResponse> object. |
---|
1286 | |
---|
1287 | mCommands - (object): <xajaxResponse> object. |
---|
1288 | bBefore - (boolean): Add the new commands to the beginning |
---|
1289 | of the list. |
---|
1290 | |
---|
1291 | */ |
---|
1292 | function loadCommands($mCommands, $bBefore=false) |
---|
1293 | { |
---|
1294 | if (is_a($mCommands, 'xajaxResponse')) { |
---|
1295 | $this->returnValue = $mCommands->returnValue; |
---|
1296 | |
---|
1297 | if ($bBefore) { |
---|
1298 | $this->aCommands = array_merge($mCommands->aCommands, $this->aCommands); |
---|
1299 | } |
---|
1300 | else { |
---|
1301 | $this->aCommands = array_merge($this->aCommands, $mCommands->aCommands); |
---|
1302 | } |
---|
1303 | } |
---|
1304 | else if (is_array($mCommands)) { |
---|
1305 | if ($bBefore) { |
---|
1306 | $this->aCommands = array_merge($mCommands, $this->aCommands); |
---|
1307 | } |
---|
1308 | else { |
---|
1309 | $this->aCommands = array_merge($this->aCommands, $mCommands); |
---|
1310 | } |
---|
1311 | } |
---|
1312 | else { |
---|
1313 | //SkipDebug |
---|
1314 | if (!empty($mCommands)) { |
---|
1315 | $objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
1316 | trigger_error( |
---|
1317 | $objLanguageManager->getText('XJXRSP:LCERR:01') |
---|
1318 | , E_USER_ERROR |
---|
1319 | ); |
---|
1320 | } |
---|
1321 | //EndSkipDebug |
---|
1322 | } |
---|
1323 | } |
---|
1324 | |
---|
1325 | function absorb($objResponse) |
---|
1326 | { |
---|
1327 | $this->loadCommands($objResponse); |
---|
1328 | } |
---|
1329 | |
---|
1330 | /* |
---|
1331 | Function: addPluginCommand |
---|
1332 | |
---|
1333 | Adds a response command that is generated by a plugin. |
---|
1334 | |
---|
1335 | objPlugin - (object): A reference to a plugin object. |
---|
1336 | aAttributes - (array): Array containing the attributes for this |
---|
1337 | response command. |
---|
1338 | mData - (mixed): The data to be sent with this command. |
---|
1339 | |
---|
1340 | Returns: |
---|
1341 | |
---|
1342 | object - The <xajaxResponse> object. |
---|
1343 | */ |
---|
1344 | function addPluginCommand($objPlugin, $aAttributes, $mData) |
---|
1345 | { |
---|
1346 | $aAttributes['plg'] = $objPlugin->getName(); |
---|
1347 | return $this->addCommand($aAttributes, $mData); |
---|
1348 | } |
---|
1349 | |
---|
1350 | /* |
---|
1351 | Function: addCommand |
---|
1352 | |
---|
1353 | Add a response command to the array of commands that will |
---|
1354 | be sent to the browser. |
---|
1355 | |
---|
1356 | aAttributes - (array): Associative array of attributes that |
---|
1357 | will describe the command. |
---|
1358 | mData - (mixed): The data to be associated with this command. |
---|
1359 | |
---|
1360 | Returns: |
---|
1361 | |
---|
1362 | object - The <xajaxResponse> command. |
---|
1363 | */ |
---|
1364 | function addCommand($aAttributes, $mData) |
---|
1365 | { |
---|
1366 | $aAttributes['data'] = $this->_encodeArray($mData); |
---|
1367 | $this->aCommands[] = $aAttributes; |
---|
1368 | return $this; |
---|
1369 | } |
---|
1370 | |
---|
1371 | /* |
---|
1372 | Function: _printHeader_XML |
---|
1373 | |
---|
1374 | Used internally to print XML start tag. |
---|
1375 | */ |
---|
1376 | function _printHeader_XML() |
---|
1377 | { |
---|
1378 | print '<'; |
---|
1379 | print '?'; |
---|
1380 | print 'xml version="1.0"'; |
---|
1381 | |
---|
1382 | $sEncoding = trim($this->sCharacterEncoding); |
---|
1383 | if ($this->sCharacterEncoding && 0 < strlen($sEncoding)) { |
---|
1384 | print ' encoding="'; |
---|
1385 | print $sEncoding; |
---|
1386 | print '"'; |
---|
1387 | } |
---|
1388 | |
---|
1389 | print ' ?'; |
---|
1390 | print '>'; |
---|
1391 | } |
---|
1392 | |
---|
1393 | /* |
---|
1394 | Function: _printResponse_XML |
---|
1395 | |
---|
1396 | Used internally to generate the command output. |
---|
1397 | */ |
---|
1398 | function _printResponse_XML() |
---|
1399 | { |
---|
1400 | print '<'; |
---|
1401 | print 'xjx>'; |
---|
1402 | |
---|
1403 | if (null !== $this->returnValue) |
---|
1404 | { |
---|
1405 | print '<'; |
---|
1406 | print 'xjxrv>'; |
---|
1407 | |
---|
1408 | $this->_printArray_XML($this->returnValue); |
---|
1409 | |
---|
1410 | print '<'; |
---|
1411 | print '/xjxrv>'; |
---|
1412 | } |
---|
1413 | |
---|
1414 | foreach(array_keys($this->aCommands) as $sKey) |
---|
1415 | $this->_printCommand_XML($this->aCommands[$sKey]); |
---|
1416 | |
---|
1417 | print '<'; |
---|
1418 | print '/xjx>'; |
---|
1419 | } |
---|
1420 | |
---|
1421 | /* |
---|
1422 | Function: _printCommand_XML |
---|
1423 | |
---|
1424 | Prints an XML representation of the command. |
---|
1425 | |
---|
1426 | aAttributes - (array): Associative array of attributes for this |
---|
1427 | command. |
---|
1428 | */ |
---|
1429 | function _printCommand_XML(&$aAttributes) |
---|
1430 | { |
---|
1431 | print '<'; |
---|
1432 | print 'cmd'; |
---|
1433 | |
---|
1434 | $mData = ''; |
---|
1435 | |
---|
1436 | foreach (array_keys($aAttributes) as $sKey) { |
---|
1437 | if ($sKey) { |
---|
1438 | if ('data' != $sKey) { |
---|
1439 | print ' '; |
---|
1440 | print $sKey; |
---|
1441 | print '="'; |
---|
1442 | print $aAttributes[$sKey]; |
---|
1443 | print '"'; |
---|
1444 | } else |
---|
1445 | $mData =& $aAttributes[$sKey]; |
---|
1446 | } |
---|
1447 | } |
---|
1448 | |
---|
1449 | print '>'; |
---|
1450 | |
---|
1451 | $this->_printArray_XML($mData); |
---|
1452 | |
---|
1453 | print '<'; |
---|
1454 | print '/cmd>'; |
---|
1455 | } |
---|
1456 | |
---|
1457 | /* |
---|
1458 | Function: _printArray_XML |
---|
1459 | |
---|
1460 | Prints an XML representation of a php array suitable |
---|
1461 | for inclusion in the response to the browser. Arrays |
---|
1462 | sent via this method will be converted into a javascript |
---|
1463 | array on the browser. |
---|
1464 | |
---|
1465 | mArray - (array): Array to be converted. |
---|
1466 | */ |
---|
1467 | function _printArray_XML(&$mArray) { |
---|
1468 | if ('object' == gettype($mArray)) |
---|
1469 | $mArray = get_object_vars($mArray); |
---|
1470 | |
---|
1471 | if (false == is_array($mArray)) { |
---|
1472 | $this->_printEscapedString_XML($mArray); |
---|
1473 | return; |
---|
1474 | } |
---|
1475 | |
---|
1476 | print '<'; |
---|
1477 | print 'xjxobj>'; |
---|
1478 | |
---|
1479 | foreach (array_keys($mArray) as $sKey) { |
---|
1480 | if (is_array($mArray[$sKey])) { |
---|
1481 | print '<'; |
---|
1482 | print 'e>'; |
---|
1483 | |
---|
1484 | foreach (array_keys($mArray[$sKey]) as $sInnerKey) { |
---|
1485 | //SkipDebug |
---|
1486 | if (htmlspecialchars($sInnerKey, ENT_COMPAT, 'UTF-8') != $sInnerKey) { |
---|
1487 | $objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
1488 | trigger_error( |
---|
1489 | $objLanguageManager->getText('XJXRSP:AKERR:01') |
---|
1490 | , E_USER_ERROR |
---|
1491 | ); |
---|
1492 | } |
---|
1493 | //EndSkipDebug |
---|
1494 | |
---|
1495 | if ('k' == $sInnerKey || 'v' == $sInnerKey) { |
---|
1496 | print '<'; |
---|
1497 | print $sInnerKey; |
---|
1498 | print '>'; |
---|
1499 | $this->_printArray_XML($mArray[$sKey][$sInnerKey]); |
---|
1500 | print '<'; |
---|
1501 | print '/'; |
---|
1502 | print $sInnerKey; |
---|
1503 | print '>'; |
---|
1504 | } else { |
---|
1505 | //SkipDebug |
---|
1506 | $objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
1507 | trigger_error( |
---|
1508 | $objLanguageManager->getText('XJXRSP:IEAERR:01') |
---|
1509 | , E_USER_ERROR |
---|
1510 | ); |
---|
1511 | //EndSkipDebug |
---|
1512 | } |
---|
1513 | } |
---|
1514 | |
---|
1515 | print '<'; |
---|
1516 | print '/e>'; |
---|
1517 | } else { |
---|
1518 | //SkipDebug |
---|
1519 | $objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
1520 | trigger_error( |
---|
1521 | $objLanguageManager->getText('XJXRSP:NEAERR:01') |
---|
1522 | , E_USER_ERROR |
---|
1523 | ); |
---|
1524 | //EndSkipDebug |
---|
1525 | } |
---|
1526 | } |
---|
1527 | |
---|
1528 | print '<'; |
---|
1529 | print '/xjxobj>'; |
---|
1530 | } |
---|
1531 | |
---|
1532 | /* |
---|
1533 | Function: _printEscapedString_XML |
---|
1534 | |
---|
1535 | Escape the specified data if necessary, so special characters in the |
---|
1536 | command data does not interfere with the structure of the response. |
---|
1537 | |
---|
1538 | This could be overridden to allow for transport encodings other than |
---|
1539 | XML. |
---|
1540 | |
---|
1541 | sData - (string): The data to be escaped. |
---|
1542 | |
---|
1543 | Returns: |
---|
1544 | |
---|
1545 | string - The escaped data. |
---|
1546 | */ |
---|
1547 | function _printEscapedString_XML(&$sData) |
---|
1548 | { |
---|
1549 | if (null === $sData) { |
---|
1550 | print ''; |
---|
1551 | return; |
---|
1552 | } |
---|
1553 | |
---|
1554 | if ($this->bOutputEntities) { |
---|
1555 | //SkipDebug |
---|
1556 | if (false === function_exists('mb_convert_encoding')) { |
---|
1557 | $objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
1558 | trigger_error( |
---|
1559 | $objLanguageManager->getText('XJXRSP:MBEERR:01') |
---|
1560 | , E_USER_NOTICE |
---|
1561 | ); |
---|
1562 | } |
---|
1563 | //EndSkipDebug |
---|
1564 | |
---|
1565 | print call_user_func_array('mb_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sCharacterEncoding)); |
---|
1566 | return; |
---|
1567 | } |
---|
1568 | |
---|
1569 | $nCDATA = 0; |
---|
1570 | |
---|
1571 | $bNoOpenCDATA = (false === strpos($sData, '<'.'![CDATA[')); |
---|
1572 | if ($bNoOpenCDATA) { |
---|
1573 | $bNoCloseCDATA = (false === strpos($sData, ']]>')); |
---|
1574 | if ($bNoCloseCDATA) { |
---|
1575 | $bSpecialChars = (htmlspecialchars($sData, ENT_COMPAT, 'UTF-8') != $sData); |
---|
1576 | if ($bSpecialChars) |
---|
1577 | $nCDATA = 1; |
---|
1578 | } else |
---|
1579 | $nCDATA = 2; |
---|
1580 | } else |
---|
1581 | $nCDATA = 2; |
---|
1582 | |
---|
1583 | if (0 < $nCDATA) { |
---|
1584 | print '<'; |
---|
1585 | print '![CDATA['; |
---|
1586 | |
---|
1587 | if (1 < $nCDATA) { |
---|
1588 | $aSegments = explode('<'.'![CDATA[', $sData); |
---|
1589 | $aOutput = array(); |
---|
1590 | $nOutput = 0; |
---|
1591 | foreach (array_keys($aSegments) as $keySegment) { |
---|
1592 | $aFragments = explode(']]>', $aSegments[$keySegment]); |
---|
1593 | $aStack = array(); |
---|
1594 | $nStack = 0; |
---|
1595 | foreach (array_keys($aFragments) as $keyFragment) { |
---|
1596 | if (0 < $nStack) |
---|
1597 | array_push($aStack, ']]]]><', '![CDATA[>', $aFragments[$keyFragment]); |
---|
1598 | else |
---|
1599 | $aStack[] = $aFragments[$keyFragment]; |
---|
1600 | ++$nStack; |
---|
1601 | } |
---|
1602 | if (0 < $nOutput) |
---|
1603 | array_push($aOutput, '<', '![]]><', '![CDATA[CDATA[', implode('', $aStack)); |
---|
1604 | else |
---|
1605 | $aOutput[] = implode('', $aStack); |
---|
1606 | ++$nOutput; |
---|
1607 | } |
---|
1608 | print implode('', $aOutput); |
---|
1609 | } else |
---|
1610 | print $sData; |
---|
1611 | |
---|
1612 | print ']]>'; |
---|
1613 | } else |
---|
1614 | print $sData; |
---|
1615 | } |
---|
1616 | |
---|
1617 | /* |
---|
1618 | Function: _encodeArray |
---|
1619 | |
---|
1620 | Recursively serializes a data structure in an array so that it can |
---|
1621 | be sent to the browser. This can be thought of as the opposite of |
---|
1622 | <xajaxRequestProcessorPlugin->_parseObjXml>. |
---|
1623 | |
---|
1624 | mData - (mixed): The data to be evaluated. |
---|
1625 | |
---|
1626 | Returns: |
---|
1627 | |
---|
1628 | mixed - The object constructed from the data. |
---|
1629 | */ |
---|
1630 | function _encodeArray(&$mData) { |
---|
1631 | if ('object' === gettype($mData)) |
---|
1632 | $mData = get_object_vars($mData); |
---|
1633 | |
---|
1634 | if (false === is_array($mData)) |
---|
1635 | return $mData; |
---|
1636 | |
---|
1637 | $aData = array(); |
---|
1638 | foreach (array_keys($mData) as $sKey) |
---|
1639 | $aData[] = array( |
---|
1640 | // key does not need to be encoded |
---|
1641 | 'k'=>$sKey, |
---|
1642 | 'v'=>$this->_encodeArray($mData[$sKey]) |
---|
1643 | ); |
---|
1644 | return $aData; |
---|
1645 | } |
---|
1646 | |
---|
1647 | }// end class xajaxResponse |
---|
1648 | |
---|
1649 | class xajaxCustomResponse |
---|
1650 | { |
---|
1651 | var $sOutput; |
---|
1652 | var $sContentType; |
---|
1653 | |
---|
1654 | var $sCharacterEncoding; |
---|
1655 | var $bOutputEntities; |
---|
1656 | |
---|
1657 | function xajaxCustomResponse($sContentType) |
---|
1658 | { |
---|
1659 | $this->sOutput = ''; |
---|
1660 | $this->sContentType = $sContentType; |
---|
1661 | |
---|
1662 | $objResponseManager =& xajaxResponseManager::getInstance(); |
---|
1663 | |
---|
1664 | $this->sCharacterEncoding = $objResponseManager->getCharacterEncoding(); |
---|
1665 | $this->bOutputEntities = $objResponseManager->getOutputEntities(); |
---|
1666 | } |
---|
1667 | |
---|
1668 | function setCharacterEncoding($sCharacterEncoding) |
---|
1669 | { |
---|
1670 | $this->sCharacterEncoding = $sCharacterEncoding; |
---|
1671 | } |
---|
1672 | |
---|
1673 | function setOutputEntities($bOutputEntities) |
---|
1674 | { |
---|
1675 | $this->bOutputEntities = $bOutputEntities; |
---|
1676 | } |
---|
1677 | |
---|
1678 | function clear() |
---|
1679 | { |
---|
1680 | $this->sOutput = ''; |
---|
1681 | } |
---|
1682 | |
---|
1683 | function append($sOutput) |
---|
1684 | { |
---|
1685 | $this->sOutput .= $sOutput; |
---|
1686 | } |
---|
1687 | |
---|
1688 | function absorb($objResponse) |
---|
1689 | { |
---|
1690 | //SkipDebug |
---|
1691 | if (false == is_a($objResponse, 'xajaxCustomResponse')) { |
---|
1692 | $objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
1693 | trigger_error( |
---|
1694 | $objLanguageManager->getText('XJXRSP:MXRTERR') |
---|
1695 | , E_USER_ERROR |
---|
1696 | ); |
---|
1697 | } |
---|
1698 | |
---|
1699 | if ($objResponse->getContentType() != $this->getContentType()) { |
---|
1700 | $objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
1701 | trigger_error( |
---|
1702 | $objLanguageManager->getText('XJXRSP:MXCTERR') |
---|
1703 | , E_USER_ERROR |
---|
1704 | ); |
---|
1705 | } |
---|
1706 | |
---|
1707 | if ($objResponse->getCharacterEncoding() != $this->getCharacterEncoding()) { |
---|
1708 | $objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
1709 | trigger_error( |
---|
1710 | $objLanguageManager->getText('XJXRSP:MXCEERR') |
---|
1711 | , E_USER_ERROR |
---|
1712 | ); |
---|
1713 | } |
---|
1714 | |
---|
1715 | if ($objResponse->getOutputEntities() != $this->getOutputEntities()) { |
---|
1716 | $objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
1717 | trigger_error( |
---|
1718 | $objLanguageManager->getText('XJXRSP:MXOEERR') |
---|
1719 | , E_USER_ERROR |
---|
1720 | ); |
---|
1721 | } |
---|
1722 | //EndSkipDebug |
---|
1723 | |
---|
1724 | $this->sOutput .= $objResponse->getOutput(); |
---|
1725 | } |
---|
1726 | |
---|
1727 | function getContentType() |
---|
1728 | { |
---|
1729 | return $this->sContentType; |
---|
1730 | } |
---|
1731 | |
---|
1732 | function getCharacterEncoding() |
---|
1733 | { |
---|
1734 | return $this->sCharacterEncoding; |
---|
1735 | } |
---|
1736 | |
---|
1737 | function getOutputEntities() |
---|
1738 | { |
---|
1739 | return $this->bOutputEntities; |
---|
1740 | } |
---|
1741 | |
---|
1742 | function getOutput() |
---|
1743 | { |
---|
1744 | return $this->sOutput; |
---|
1745 | } |
---|
1746 | |
---|
1747 | function printOutput() |
---|
1748 | { |
---|
1749 | $sContentType = $this->sContentType; |
---|
1750 | $sCharacterSet = $this->sCharacterEncoding; |
---|
1751 | |
---|
1752 | header("content-type: {$sContentType}; charset={$sCharacterSet}"); |
---|
1753 | |
---|
1754 | print $this->sOutput; |
---|
1755 | } |
---|
1756 | } |
---|