ona  18.1.1
About: OpenNetAdmin provides a database managed inventory of your IP network (with Web and CLI interface).
  Fossies Dox: ona-18.1.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

xajaxResponse.inc.php
Go to the documentation of this file.
1 <?php
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 
69 {
76  var $xml;
86 
102  function xajaxResponse($sEncoding=XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities=false)
103  {
104  $this->setCharEncoding($sEncoding);
105  $this->bOutputEntities = $bOutputEntities;
106  }
107 
118  {
119  $this->sEncoding = $sEncoding;
120  }
121 
126  function outputEntitiesOn()
127  {
128  $this->bOutputEntities = true;
129  }
130 
135  function outputEntitiesOff()
136  {
137  $this->bOutputEntities = false;
138  }
139 
149  function addConfirmCommands($iCmdNumber, $sMessage)
150  {
151  $this->xml .= $this->_cmdXML(array("n"=>"cc","t"=>$iCmdNumber),$sMessage);
152  }
153 
164  function addAssign($sTarget,$sAttribute,$sData)
165  {
166  $this->xml .= $this->_cmdXML(array("n"=>"as","t"=>$sTarget,"p"=>$sAttribute),$sData);
167  }
168 
179  function addAppend($sTarget,$sAttribute,$sData)
180  {
181  $this->xml .= $this->_cmdXML(array("n"=>"ap","t"=>$sTarget,"p"=>$sAttribute),$sData);
182  }
183 
195  function addPrepend($sTarget,$sAttribute,$sData)
196  {
197  $this->xml .= $this->_cmdXML(array("n"=>"pp","t"=>$sTarget,"p"=>$sAttribute),$sData);
198  }
199 
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 
227  function addClear($sTarget,$sAttribute)
228  {
229  $this->addAssign($sTarget,$sAttribute,'');
230  }
231 
239  function addAlert($sMsg)
240  {
241  $this->xml .= $this->_cmdXML(array("n"=>"al"),$sMsg);
242  }
243 
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  parse_str($queryPart, $queryParts);
265  $newQueryPart = "";
266  foreach($queryParts as $key => $value)
267  {
268  $newQueryPart .= rawurlencode($key).'='.rawurlencode($value).ini_get('arg_separator.output');
269  }
270  $sURL = str_replace($queryPart, $newQueryPart, $sURL);
271  }
272  $this->addScript('window.location = "'.$sURL.'";');
273  }
274 
282  function addScript($sJS)
283  {
284  $this->xml .= $this->_cmdXML(array("n"=>"js"),$sJS);
285  }
286 
295  function addScriptCall() {
296  $arguments = func_get_args();
297  $sFunc = array_shift($arguments);
298  $sData = $this->_buildObjXml($arguments);
299  $this->xml .= $this->_cmdXML(array("n"=>"jc","t"=>$sFunc),$sData);
300  }
301 
309  function addRemove($sTarget)
310  {
311  $this->xml .= $this->_cmdXML(array("n"=>"rm","t"=>$sTarget),'');
312  }
313 
325  function addCreate($sParent, $sTag, $sId, $sType="")
326  {
327  if ($sType)
328  {
329  trigger_error("The \$sType parameter of addCreate has been deprecated. Use the addCreateInput() method instead.", E_USER_WARNING);
330  return;
331  }
332  $this->xml .= $this->_cmdXML(array("n"=>"ce","t"=>$sParent,"p"=>$sId),$sTag);
333  }
334 
345  function addInsert($sBefore, $sTag, $sId)
346  {
347  $this->xml .= $this->_cmdXML(array("n"=>"ie","t"=>$sBefore,"p"=>$sId),$sTag);
348  }
349 
360  function addInsertAfter($sAfter, $sTag, $sId)
361  {
362  $this->xml .= $this->_cmdXML(array("n"=>"ia","t"=>$sAfter,"p"=>$sId),$sTag);
363  }
364 
378  function addCreateInput($sParent, $sType, $sName, $sId)
379  {
380  $this->xml .= $this->_cmdXML(array("n"=>"ci","t"=>$sParent,"p"=>$sId,"c"=>$sType),$sName);
381  }
382 
396  function addInsertInput($sBefore, $sType, $sName, $sId)
397  {
398  $this->xml .= $this->_cmdXML(array("n"=>"ii","t"=>$sBefore,"p"=>$sId,"c"=>$sType),$sName);
399  }
400 
414  function addInsertInputAfter($sAfter, $sType, $sName, $sId)
415  {
416  $this->xml .= $this->_cmdXML(array("n"=>"iia","t"=>$sAfter,"p"=>$sId,"c"=>$sType),$sName);
417  }
418 
428  function addEvent($sTarget,$sEvent,$sScript)
429  {
430  $this->xml .= $this->_cmdXML(array("n"=>"ev","t"=>$sTarget,"p"=>$sEvent),$sScript);
431  }
432 
443  function addHandler($sTarget,$sEvent,$sHandler)
444  {
445  $this->xml .= $this->_cmdXML(array("n"=>"ah","t"=>$sTarget,"p"=>$sEvent),$sHandler);
446  }
447 
459  function addRemoveHandler($sTarget,$sEvent,$sHandler)
460  {
461  $this->xml .= $this->_cmdXML(array("n"=>"rh","t"=>$sTarget,"p"=>$sEvent),$sHandler);
462  }
463 
471  function addIncludeScript($sFileName)
472  {
473  $this->xml .= $this->_cmdXML(array("n"=>"in"),$sFileName);
474  }
475 
486  function getXML()
487  {
488  $sXML = "<?xml version=\"1.0\"";
489  if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0)
490  $sXML .= " encoding=\"".$this->sEncoding."\"";
491  $sXML .= " ?"."><xjx>" . $this->xml . "</xjx>";
492 
493  return $sXML;
494  }
495 
508  function loadXML($mXML)
509  {
510  if (is_a($mXML, "xajaxResponse")) {
511  $mXML = $mXML->getXML();
512  }
513  $sNewXML = "";
514  $iStartPos = strpos($mXML, "<xjx>") + 5;
515  $sNewXML = substr($mXML, $iStartPos);
516  $iEndPos = strpos($sNewXML, "</xjx>");
517  $sNewXML = substr($sNewXML, 0, $iEndPos);
518  $this->xml .= $sNewXML;
519  }
520 
529  function _cmdXML($aAttributes, $sData)
530  {
531  if ($this->bOutputEntities) {
532  if (function_exists('mb_convert_encoding')) {
533  $sData = call_user_func_array('mb_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding));
534  }
535  else {
536  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);
537  }
538  }
539  $xml = "<cmd";
540  foreach($aAttributes as $sAttribute => $sValue)
541  $xml .= " $sAttribute=\"$sValue\"";
542  if ($sData !== null && !stristr($sData,'<![CDATA['))
543  $xml .= "><![CDATA[$sData]]></cmd>";
544  else if ($sData !== null)
545  $xml .= ">$sData</cmd>";
546  else
547  $xml .= "></cmd>";
548 
549  return $xml;
550  }
551 
561  function _buildObjXml($var) {
562  if (gettype($var) == "object") $var = get_object_vars($var);
563  if (!is_array($var)) {
564  return "<![CDATA[$var]]>";
565  }
566  else {
567  $data = "<xjxobj>";
568  foreach ($var as $key => $value) {
569  $data .= "<e>";
570  $data .= "<k>" . htmlspecialchars($key) . "</k>";
571  $data .= "<v>" . $this->_buildObjXml($value) . "</v>";
572  $data .= "</e>";
573  }
574  $data .= "</xjxobj>";
575  return $data;
576  }
577  }
578 
579 }// end class xajaxResponse
580 ?>
xajaxResponse\loadXML
loadXML($mXML)
Definition: xajaxResponse.inc.php:508
xajaxResponse\$sEncoding
$sEncoding
Definition: xajaxResponse.inc.php:80
xajaxResponse\addRemoveHandler
addRemoveHandler($sTarget, $sEvent, $sHandler)
Definition: xajaxResponse.inc.php:459
xajaxResponse\addPrepend
addPrepend($sTarget, $sAttribute, $sData)
Definition: xajaxResponse.inc.php:195
xajaxResponse\addClear
addClear($sTarget, $sAttribute)
Definition: xajaxResponse.inc.php:227
xajaxResponse\addScript
addScript($sJS)
Definition: xajaxResponse.inc.php:282
xajaxResponse\_cmdXML
_cmdXML($aAttributes, $sData)
Definition: xajaxResponse.inc.php:529
xajaxResponse\$xml
$xml
Definition: xajaxResponse.inc.php:76
xajaxResponse\addReplace
addReplace($sTarget, $sAttribute, $sSearch, $sData)
Definition: xajaxResponse.inc.php:212
xajaxResponse\addHandler
addHandler($sTarget, $sEvent, $sHandler)
Definition: xajaxResponse.inc.php:443
xajaxResponse\addInsertInput
addInsertInput($sBefore, $sType, $sName, $sId)
Definition: xajaxResponse.inc.php:396
xajaxResponse\addRemove
addRemove($sTarget)
Definition: xajaxResponse.inc.php:309
xajaxResponse\addInsertAfter
addInsertAfter($sAfter, $sTag, $sId)
Definition: xajaxResponse.inc.php:360
xajaxResponse\$bOutputEntities
$bOutputEntities
Definition: xajaxResponse.inc.php:85
xajaxResponse\outputEntitiesOn
outputEntitiesOn()
Definition: xajaxResponse.inc.php:126
xajaxResponse\xajaxResponse
xajaxResponse($sEncoding=XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities=false)
Definition: xajaxResponse.inc.php:102
xajaxResponse\addAppend
addAppend($sTarget, $sAttribute, $sData)
Definition: xajaxResponse.inc.php:179
xajaxResponse\_buildObjXml
_buildObjXml($var)
Definition: xajaxResponse.inc.php:561
xajaxResponse\addInsertInputAfter
addInsertInputAfter($sAfter, $sType, $sName, $sId)
Definition: xajaxResponse.inc.php:414
xajaxResponse\addIncludeScript
addIncludeScript($sFileName)
Definition: xajaxResponse.inc.php:471
xajaxResponse\addCreateInput
addCreateInput($sParent, $sType, $sName, $sId)
Definition: xajaxResponse.inc.php:378
xajaxResponse\addConfirmCommands
addConfirmCommands($iCmdNumber, $sMessage)
Definition: xajaxResponse.inc.php:149
xajaxResponse\getXML
getXML()
Definition: xajaxResponse.inc.php:486
xajaxResponse
Definition: xajaxResponse.inc.php:68
xajaxResponse\addRedirect
addRedirect($sURL)
Definition: xajaxResponse.inc.php:251
xajaxResponse\addEvent
addEvent($sTarget, $sEvent, $sScript)
Definition: xajaxResponse.inc.php:428
xajaxResponse\addInsert
addInsert($sBefore, $sTag, $sId)
Definition: xajaxResponse.inc.php:345
xajaxResponse\setCharEncoding
setCharEncoding($sEncoding)
Definition: xajaxResponse.inc.php:117
xajaxResponse\addScriptCall
addScriptCall()
Definition: xajaxResponse.inc.php:295
xajaxResponse\outputEntitiesOff
outputEntitiesOff()
Definition: xajaxResponse.inc.php:135
xajaxResponse\addAlert
addAlert($sMsg)
Definition: xajaxResponse.inc.php:239
xajaxResponse\addAssign
addAssign($sTarget, $sAttribute, $sData)
Definition: xajaxResponse.inc.php:164
xajaxResponse\addCreate
addCreate($sParent, $sTag, $sId, $sType="")
Definition: xajaxResponse.inc.php:325