Completed
Push — 1.10.x ( 9a71ab...f8e8ec )
by
unknown
50:16
created

xajaxResponse::loadXML()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 12
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
/**
3
 * xajaxResponse.inc.php :: xajax XML response class
4
 *
5
 * xajax version 0.2.4
6
 * copyright (c) 2005 by Jared White & J. Max Wilson
7
 * http://www.xajaxproject.org
8
 *
9
 * xajax is an open source PHP class library for easily creating powerful
10
 * PHP-driven, web-based Ajax Applications. Using xajax, you can asynchronously
11
 * call PHP functions and update the content of your your webpage without
12
 * reloading the page.
13
 *
14
 * xajax is released under the terms of the LGPL license
15
 * http://www.gnu.org/copyleft/lesser.html#SEC3
16
 *
17
 * This library is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU Lesser General Public
19
 * License as published by the Free Software Foundation; either
20
 * version 2.1 of the License, or (at your option) any later version.
21
 *
22
 * This library is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25
 * Lesser General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU Lesser General Public
28
 * License along with this library; if not, write to the Free Software
29
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
30
 *
31
 * @package chamilo.include.xajax
32
 * @version $Id: xajaxResponse.inc.php,v 1.1 2006/07/21 15:29:46 elixir_inter Exp $
33
 * @copyright Copyright (c) 2005-2006  by Jared White & J. Max Wilson
34
 * @license http://www.gnu.org/copyleft/lesser.html#SEC3 LGPL License
35
 */
36
37
/*
38
   ----------------------------------------------------------------------------
39
   | Online documentation for this class is available on the xajax wiki at:   |
40
   | http://wiki.xajaxproject.org/Documentation:xajaxResponse.inc.php         |
41
   ----------------------------------------------------------------------------
42
*/
43
44
/**
45
 * The xajaxResponse class is used to create responses to be sent back to your
46
 * Web page.  A response contains one or more command messages for updating
47
 * your page.
48
 * Currently xajax supports 21 kinds of command messages, including some common
49
 * ones such as:
50
 * <ul>
51
 * <li>Assign - sets the specified attribute of an element in your page</li>
52
 * <li>Append - appends data to the end of the specified attribute of an
53
 * element in your page</li>
54
 * <li>Prepend - prepends data to the beginning of the specified attribute of
55
 * an element in your page</li>
56
 * <li>Replace - searches for and replaces data in the specified attribute of
57
 * an element in your page</li>
58
 * <li>Script - runs the supplied JavaScript code</li>
59
 * <li>Alert - shows an alert box with the supplied message text</li>
60
 * </ul>
61
 *
62
 * <i>Note:</i> elements are identified by their HTML id, so if you don't see
63
 * your browser HTML display changing from the request, make sure you're using
64
 * the right id names in your response.
65
 *
66
 * @package chamilo.include.xajax
67
 */
68
class xajaxResponse
69
{
70
	/**#@+
71
	 * @access protected
72
	 */
73
	/**
74
	 * @var string internal XML storage
75
	 */
76
	var $xml;
77
	/**
78
	 * @var string the encoding type to use
79
	 */
80
	var $sEncoding;
81
	/**
82
	 * @var boolean if special characters in the XML should be converted to
83
	 *              entities
84
	 */
85
	var $bOutputEntities;
86
87
	/**#@-*/
88
89
	/**
90
	 * The constructor's main job is to set the character encoding for the
91
	 * response.
92
	 *
93
	 * <i>Note:</i> to change the character encoding for all of the
94
	 * responses, set the XAJAX_DEFAULT_ENCODING constant before you
95
	 * instantiate xajax.
96
	 *
97
	 * @param string  contains the character encoding string to use
98
	 * @param boolean lets you set if you want special characters in the output
99
	 *                converted to HTML entities
100
	 *
101
	 */
102
	public function __construct($sEncoding=XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities=false)
103
	{
104
		$this->setCharEncoding($sEncoding);
105
		$this->bOutputEntities = $bOutputEntities;
106
	}
107
108
	/**
109
	 * Sets the character encoding for the response based on $sEncoding, which
110
	 * is a string containing the character encoding to use. You don't need to
111
	 * use this method normally, since the character encoding for the response
112
	 * gets set automatically based on the XAJAX_DEFAULT_CHAR_ENCODING
113
	 * constant.
114
	 *
115
	 * @param string
116
	 */
117
	function setCharEncoding($sEncoding)
118
	{
119
		$this->sEncoding = $sEncoding;
120
	}
121
122
	/**
123
	 * Tells the response object to convert special characters to HTML entities
124
	 * automatically (only works if the mb_string extension is available).
125
	 */
126
	function outputEntitiesOn()
127
	{
128
		$this->bOutputEntities = true;
129
	}
130
131
	/**
132
	 * Tells the response object to output special characters intact. (default
133
	 * behavior)
134
	 */
135
	function outputEntitiesOff()
136
	{
137
		$this->bOutputEntities = false;
138
	}
139
140
	/**
141
	 * Adds a confirm commands command message to the XML response.
142
	 *
143
	 * <i>Usage:</i> <kbd>$objResponse->addConfirmCommands(1, "Do you want to preview the new data?");</kbd>
144
	 *
145
	 * @param integer the number of commands to skip if the user presses
146
	 *                Cancel in the browsers's confirm dialog
147
	 * @param string  the message to show in the browser's confirm dialog
148
	 */
149
	function addConfirmCommands($iCmdNumber, $sMessage)
150
	{
151
		$this->xml .= $this->_cmdXML(array("n"=>"cc","t"=>$iCmdNumber),$sMessage);
152
	}
153
154
	/**
155
	 * Adds an assign command message to the XML response.
156
	 *
157
	 * <i>Usage:</i> <kbd>$objResponse->addAssign("contentDiv", "innerHTML", "Some Text");</kbd>
158
	 *
159
	 * @param string contains the id of an HTML element
160
	 * @param string the part of the element you wish to modify ("innerHTML",
161
	 *               "value", etc.)
162
	 * @param string the data you want to set the attribute to
163
	 */
164
	function addAssign($sTarget,$sAttribute,$sData)
165
	{
166
		$this->xml .= $this->_cmdXML(array("n"=>"as","t"=>$sTarget,"p"=>$sAttribute),$sData);
167
	}
168
169
	/**
170
	 * Adds an append command message to the XML response.
171
	 *
172
	 * <i>Usage:</i> <kbd>$objResponse->addAppend("contentDiv", "innerHTML", "Some New Text");</kbd>
173
	 *
174
	 * @param string contains the id of an HTML element
175
	 * @param string the part of the element you wish to modify ("innerHTML",
176
	 *               "value", etc.)
177
	 * @param string the data you want to append to the end of the attribute
178
	 */
179
	function addAppend($sTarget,$sAttribute,$sData)
180
	{
181
		$this->xml .= $this->_cmdXML(array("n"=>"ap","t"=>$sTarget,"p"=>$sAttribute),$sData);
182
	}
183
184
	/**
185
	 * Adds an prepend command message to the XML response.
186
	 *
187
	 * <i>Usage:</i> <kbd>$objResponse->addPrepend("contentDiv", "innerHTML", "Some Starting Text");</kbd>
188
	 *
189
	 * @param string contains the id of an HTML element
190
	 * @param string the part of the element you wish to modify ("innerHTML",
191
	 *               "value", etc.)
192
	 * @param string the data you want to prepend to the beginning of the
193
	 *               attribute
194
	 */
195
	function addPrepend($sTarget,$sAttribute,$sData)
196
	{
197
		$this->xml .= $this->_cmdXML(array("n"=>"pp","t"=>$sTarget,"p"=>$sAttribute),$sData);
198
	}
199
200
	/**
201
	 * Adds a replace command message to the XML response.
202
	 *
203
	 * <i>Usage:</i> <kbd>$objResponse->addReplace("contentDiv", "innerHTML", "text", "<b>text</b>");</kbd>
204
	 *
205
	 * @param string contains the id of an HTML element
206
	 * @param string the part of the element you wish to modify ("innerHTML",
207
	 *               "value", etc.)
208
	 * @param string the string to search for
209
	 * @param string the string to replace the search string when found in the
210
	 *               attribute
211
	 */
212
	function addReplace($sTarget,$sAttribute,$sSearch,$sData)
213
	{
214
		$sDta = "<s><![CDATA[$sSearch]]></s><r><![CDATA[$sData]]></r>";
215
		$this->xml .= $this->_cmdXML(array("n"=>"rp","t"=>$sTarget,"p"=>$sAttribute),$sDta);
216
	}
217
218
	/**
219
	 * Adds a clear command message to the XML response.
220
	 *
221
	 * <i>Usage:</i> <kbd>$objResponse->addClear("contentDiv", "innerHTML");</kbd>
222
	 *
223
	 * @param string contains the id of an HTML element
224
	 * @param string the part of the element you wish to clear ("innerHTML",
225
	 *               "value", etc.)
226
	 */
227
	function addClear($sTarget,$sAttribute)
228
	{
229
		$this->addAssign($sTarget,$sAttribute,'');
230
	}
231
232
	/**
233
	 * Adds an alert command message to the XML response.
234
	 *
235
	 * <i>Usage:</i> <kbd>$objResponse->addAlert("This is important information");</kbd>
236
	 *
237
	 * @param string the text to be displayed in the Javascript alert box
238
	 */
239
	function addAlert($sMsg)
240
	{
241
		$this->xml .= $this->_cmdXML(array("n"=>"al"),$sMsg);
242
	}
243
244
	/**
245
	 * Uses the addScript() method to add a Javascript redirect to another URL.
246
	 *
247
	 * <i>Usage:</i> <kbd>$objResponse->addRedirect("http://www.xajaxproject.org");</kbd>
248
	 *
249
	 * @param string the URL to redirect the client browser to
250
	 */
251
	function addRedirect($sURL)
252
	{
253
		//we need to parse the query part so that the values are rawurlencode()'ed
254
		//can't just use parse_url() cos we could be dealing with a relative URL which
255
		//  parse_url() can't deal with.
256
		$queryStart = strpos($sURL, '?', strrpos($sURL, '/'));
257
		if ($queryStart !== FALSE)
258
		{
259
			$queryStart++;
260
			$queryEnd = strpos($sURL, '#', $queryStart);
261
			if ($queryEnd === FALSE)
262
				$queryEnd = strlen($sURL);
263
			$queryPart = substr($sURL, $queryStart, $queryEnd-$queryStart);
264
            $queryParts = array();
265
			parse_str($queryPart, $queryParts);
266
			$newQueryPart = "";
267
			foreach($queryParts as $key => $value)
0 ignored issues
show
Bug introduced by
The expression $queryParts of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
268
			{
269
				$newQueryPart .= rawurlencode($key).'='.rawurlencode($value).ini_get('arg_separator.output');
270
			}
271
			$sURL = str_replace($queryPart, $newQueryPart, $sURL);
272
		}
273
		$this->addScript('window.location = "'.$sURL.'";');
274
	}
275
276
	/**
277
	 * Adds a Javascript command message to the XML response.
278
	 *
279
	 * <i>Usage:</i> <kbd>$objResponse->addScript("var x = prompt('get some text');");</kbd>
280
	 *
281
	 * @param string contains Javascript code to be executed
282
	 */
283
	function addScript($sJS)
284
	{
285
		$this->xml .= $this->_cmdXML(array("n"=>"js"),$sJS);
286
	}
287
288
	/**
289
	 * Adds a Javascript function call command message to the XML response.
290
	 *
291
	 * <i>Usage:</i> <kbd>$objResponse->addScriptCall("myJSFunction", "arg 1", "arg 2", 12345);</kbd>
292
	 *
293
	 * @param string $sFunc the name of a Javascript function
0 ignored issues
show
Bug introduced by
There is no parameter named $sFunc. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
294
	 * @param mixed $args,... optional arguments to pass to the Javascript function
0 ignored issues
show
Bug introduced by
There is no parameter named $args,.... Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
295
	 */
296
	function addScriptCall() {
297
		$arguments = func_get_args();
298
		$sFunc = array_shift($arguments);
299
		$sData = $this->_buildObjXml($arguments);
300
		$this->xml .= $this->_cmdXML(array("n"=>"jc","t"=>$sFunc),$sData);
301
	}
302
303
	/**
304
	 * Adds a remove element command message to the XML response.
305
	 *
306
	 * <i>Usage:</i> <kbd>$objResponse->addRemove("Div2");</kbd>
307
	 *
308
	 * @param string contains the id of an HTML element to be removed
309
	 */
310
	function addRemove($sTarget)
311
	{
312
		$this->xml .= $this->_cmdXML(array("n"=>"rm","t"=>$sTarget),'');
313
	}
314
315
	/**
316
	 * Adds a create element command message to the XML response.
317
	 *
318
	 * <i>Usage:</i> <kbd>$objResponse->addCreate("parentDiv", "h3", "myid");</kbd>
319
	 *
320
	 * @param string contains the id of an HTML element to to which the new
321
	 *               element will be appended.
322
	 * @param string the tag to be added
323
	 * @param string the id to be assigned to the new element
324
	 * @param string deprecated, use the addCreateInput() method instead
325
	 */
326
	function addCreate($sParent, $sTag, $sId, $sType="")
327
	{
328
		if ($sType)
329
		{
330
			trigger_error("The \$sType parameter of addCreate has been deprecated.  Use the addCreateInput() method instead.", E_USER_WARNING);
331
			return;
332
		}
333
		$this->xml .= $this->_cmdXML(array("n"=>"ce","t"=>$sParent,"p"=>$sId),$sTag);
334
	}
335
336
	/**
337
	 * Adds a insert element command message to the XML response.
338
	 *
339
	 * <i>Usage:</i> <kbd>$objResponse->addInsert("childDiv", "h3", "myid");</kbd>
340
	 *
341
	 * @param string contains the id of the child before which the new element
342
	 *               will be inserted
343
	 * @param string the tag to be added
344
	 * @param string the id to be assigned to the new element
345
	 */
346
	function addInsert($sBefore, $sTag, $sId)
347
	{
348
		$this->xml .= $this->_cmdXML(array("n"=>"ie","t"=>$sBefore,"p"=>$sId),$sTag);
349
	}
350
351
	/**
352
	 * Adds a insert element command message to the XML response.
353
	 *
354
	 * <i>Usage:</i> <kbd>$objResponse->addInsertAfter("childDiv", "h3", "myid");</kbd>
355
	 *
356
	 * @param string contains the id of the child after which the new element
357
	 *               will be inserted
358
	 * @param string the tag to be added
359
	 * @param string the id to be assigned to the new element
360
	 */
361
	function addInsertAfter($sAfter, $sTag, $sId)
362
	{
363
		$this->xml .= $this->_cmdXML(array("n"=>"ia","t"=>$sAfter,"p"=>$sId),$sTag);
364
	}
365
366
	/**
367
	 * Adds a create input command message to the XML response.
368
	 *
369
	 * <i>Usage:</i> <kbd>$objResponse->addCreateInput("form1", "text", "username", "input1");</kbd>
370
	 *
371
	 * @param string contains the id of an HTML element to which the new input
372
	 *               will be appended
373
	 * @param string the type of input to be created (text, radio, checkbox,
374
	 *               etc.)
375
	 * @param string the name to be assigned to the new input and the variable
376
	 *               name when it is submitted
377
	 * @param string the id to be assigned to the new input
378
	 */
379
	function addCreateInput($sParent, $sType, $sName, $sId)
380
	{
381
		$this->xml .= $this->_cmdXML(array("n"=>"ci","t"=>$sParent,"p"=>$sId,"c"=>$sType),$sName);
382
	}
383
384
	/**
385
	 * Adds an insert input command message to the XML response.
386
	 *
387
	 * <i>Usage:</i> <kbd>$objResponse->addInsertInput("input5", "text", "username", "input1");</kbd>
388
	 *
389
	 * @param string contains the id of the child before which the new element
390
	 *               will be inserted
391
	 * @param string the type of input to be created (text, radio, checkbox,
392
	 *               etc.)
393
	 * @param string the name to be assigned to the new input and the variable
394
	 *               name when it is submitted
395
	 * @param string the id to be assigned to the new input
396
	 */
397
	function addInsertInput($sBefore, $sType, $sName, $sId)
398
	{
399
		$this->xml .= $this->_cmdXML(array("n"=>"ii","t"=>$sBefore,"p"=>$sId,"c"=>$sType),$sName);
400
	}
401
402
	/**
403
	 * Adds an insert input command message to the XML response.
404
	 *
405
	 * <i>Usage:</i> <kbd>$objResponse->addInsertInputAfter("input7", "text", "email", "input2");</kbd>
406
	 *
407
	 * @param string contains the id of the child after which the new element
408
	 *               will be inserted
409
	 * @param string the type of input to be created (text, radio, checkbox,
410
	 *               etc.)
411
	 * @param string the name to be assigned to the new input and the variable
412
	 *               name when it is submitted
413
	 * @param string the id to be assigned to the new input
414
	 */
415
	function addInsertInputAfter($sAfter, $sType, $sName, $sId)
416
	{
417
		$this->xml .= $this->_cmdXML(array("n"=>"iia","t"=>$sAfter,"p"=>$sId,"c"=>$sType),$sName);
418
	}
419
420
	/**
421
	 * Adds an event command message to the XML response.
422
	 *
423
	 * <i>Usage:</i> <kbd>$objResponse->addEvent("contentDiv", "onclick", "alert(\'Hello World\');");</kbd>
424
	 *
425
	 * @param string contains the id of an HTML element
426
	 * @param string the event you wish to set ("onclick", "onmouseover", etc.)
427
	 * @param string the Javascript string you want the event to invoke
428
	 */
429
	function addEvent($sTarget,$sEvent,$sScript)
430
	{
431
		$this->xml .= $this->_cmdXML(array("n"=>"ev","t"=>$sTarget,"p"=>$sEvent),$sScript);
432
	}
433
434
	/**
435
	 * Adds a handler command message to the XML response.
436
	 *
437
	 * <i>Usage:</i> <kbd>$objResponse->addHandler("contentDiv", "onclick", "content_click");</kbd>
438
	 *
439
	 * @param string contains the id of an HTML element
440
	 * @param string the event you wish to set ("onclick", "onmouseover", etc.)
441
	 * @param string the name of a Javascript function that will handle the
442
	 *               event. Multiple handlers can be added for the same event
443
	 */
444
	function addHandler($sTarget,$sEvent,$sHandler)
445
	{
446
		$this->xml .= $this->_cmdXML(array("n"=>"ah","t"=>$sTarget,"p"=>$sEvent),$sHandler);
447
	}
448
449
	/**
450
	 * Adds a remove handler command message to the XML response.
451
	 *
452
	 * <i>Usage:</i> <kbd>$objResponse->addRemoveHandler("contentDiv", "onclick", "content_click");</kbd>
453
	 *
454
	 * @param string contains the id of an HTML element
455
	 * @param string the event you wish to remove ("onclick", "onmouseover",
456
	 *               etc.)
457
	 * @param string the name of a Javascript handler function that you want to
458
	 *               remove
459
	 */
460
	function addRemoveHandler($sTarget,$sEvent,$sHandler)
461
	{
462
		$this->xml .= $this->_cmdXML(array("n"=>"rh","t"=>$sTarget,"p"=>$sEvent),$sHandler);
463
	}
464
465
	/**
466
	 * Adds an include script command message to the XML response.
467
	 *
468
	 * <i>Usage:</i> <kbd>$objResponse->addIncludeScript("functions.js");</kbd>
469
	 *
470
	 * @param string URL of the Javascript file to include
471
	 */
472
	function addIncludeScript($sFileName)
473
	{
474
		$this->xml .= $this->_cmdXML(array("n"=>"in"),$sFileName);
475
	}
476
477
	/**
478
	 * Returns the XML to be returned from your function to the xajax processor
479
	 * on your page. Since xajax 0.2, you can also return an xajaxResponse
480
	 * object from your function directly, and xajax will automatically request
481
	 * the XML using this method call.
482
	 *
483
	 * <i>Usage:</i> <kbd>return $objResponse->getXML();</kbd>
484
	 *
485
	 * @return string response XML data
486
	 */
487
	function getXML()
488
	{
489
		$sXML = "<?xml version=\"1.0\"";
490 View Code Duplication
		if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0)
491
			$sXML .= " encoding=\"".$this->sEncoding."\"";
492
		$sXML .= " ?"."><xjx>" . $this->xml . "</xjx>";
493
494
		return $sXML;
495
	}
496
497
	/**
498
	 * Adds the commands of the provided response XML output to this response
499
	 * object
500
	 *
501
	 * <i>Usage:</i>
502
	 * <code>$r1 = $objResponse1->getXML();
503
	 * $objResponse2->loadXML($r1);
504
	 * return $objResponse2->getXML();</code>
505
	 *
506
	 * @param string the response XML (returned from a getXML() method) to add
507
	 *               to the end of this response object
508
	 */
509
	function loadXML($mXML)
510
	{
511
		if (is_a($mXML, "xajaxResponse")) {
512
			$mXML = $mXML->getXML();
513
		}
514
		$sNewXML = "";
515
		$iStartPos = strpos($mXML, "<xjx>") + 5;
516
		$sNewXML = substr($mXML, $iStartPos);
517
		$iEndPos = strpos($sNewXML, "</xjx>");
518
		$sNewXML = substr($sNewXML, 0, $iEndPos);
519
		$this->xml .= $sNewXML;
520
	}
521
522
	/**
523
	 * Generates XML from command data
524
	 *
525
	 * @access private
526
	 * @param array associative array of attributes
527
	 * @param string data
528
	 * @return string XML command
529
	 */
530
	function _cmdXML($aAttributes, $sData)
531
	{
532
		if ($this->bOutputEntities) {
533
			// An adaptation for the Dokeos LMS, 22-AUG-2009.
534
			if (function_exists('api_convert_encoding')) {
535
				$sData = call_user_func_array('api_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding));
536
			}
537
			//if (function_exists('mb_convert_encoding')) {
538
			elseif (function_exists('mb_convert_encoding')) {
539
			//
540
				$sData = call_user_func_array('mb_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding));
541
			}
542
			else {
543
				trigger_error("The xajax XML response output could not be converted to HTML entities because the mb_convert_encoding function is not available", E_USER_NOTICE);
544
			}
545
		}
546
		$xml = "<cmd";
547
		foreach($aAttributes as $sAttribute => $sValue)
548
			$xml .= " $sAttribute=\"$sValue\"";
549
		if ($sData !== null && !stristr($sData,'<![CDATA['))
550
			$xml .= "><![CDATA[$sData]]></cmd>";
551
		else if ($sData !== null)
552
			$xml .= ">$sData</cmd>";
553
		else
554
			$xml .= "></cmd>";
555
556
		return $xml;
557
	}
558
559
	/**
560
	 * Recursively serializes a data structure in XML so it can be sent to
561
	 * the client. It could be thought of as the opposite of
562
	 * {@link xajax::_parseObjXml()}.
563
	 *
564
	 * @access private
565
	 * @param mixed data structure to serialize to XML
566
	 * @return string serialized XML
567
	 */
568
	function _buildObjXml($var) {
569
		if (gettype($var) == "object") $var = get_object_vars($var);
570
		if (!is_array($var)) {
571
			return "<![CDATA[$var]]>";
572
		}
573
		else {
574
			$data = "<xjxobj>";
575
			foreach ($var as $key => $value) {
576
				$data .= "<e>";
577
				$data .= "<k>" . htmlspecialchars($key) . "</k>";
578
				$data .= "<v>" . $this->_buildObjXml($value) . "</v>";
579
				$data .= "</e>";
580
			}
581
			$data .= "</xjxobj>";
582
			return $data;
583
		}
584
	}
585
586
}// end class xajaxResponse
587
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
588