00001 <?php
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00036
00037 class FF_Output_AJAX extends FF_Output {
00038
00039
00044 var $_xml = '';
00045
00050 var $_nodes = array();
00051
00052
00053
00054
00061 function display()
00062 {
00063 $this->_renderMessages();
00064 foreach ($this->_nodes as $s_key => $val) {
00065 if (is_array($val) && count($val) == 1) {
00066 $this->_xml .= $this->arrayToXML(current($val), $s_key, key($val));
00067 }
00068 else {
00069 $this->_xml .= $this->arrayToXML(array($s_key => $val));
00070 }
00071 }
00072
00073 header('Content-Type: text/xml');
00074 print '<?xml version="1.0" encoding="ISO-8859-1"?>';
00075 print '<ajax>';
00076 print $this->_xml;
00077 print '</ajax>';
00078 }
00079
00080
00081
00082
00094 function addNode($in_key, $in_value, $in_nodeName = null)
00095 {
00096 if (is_null($in_nodeName)) {
00097 $this->_nodes[$in_key] = $in_value;
00098 }
00099 else {
00100 $this->_nodes[$in_key] = array($in_nodeName => $in_value);
00101 }
00102 }
00103
00104
00105
00106
00116 function arrayToXML($in_array, $in_topNode = null, $in_nodeName = 'el', $in_level = 1)
00117 {
00118 $s_xml = '';
00119 if ($in_level == 1 && !is_null($in_topNode)) {
00120 $s_xml .= "<$in_topNode>";
00121 }
00122
00123 foreach ($in_array as $key => $value) {
00124 if (is_array($value)) {
00125
00126
00127 if (isset($value[0])) {
00128 $s_xml .= $this->arrayToXML($value, $in_topNode, $key, $in_level);
00129 }
00130 else {
00131 if (is_int($key)) {
00132 $key = $in_nodeName;
00133 }
00134
00135 $s_xml .= "<$key>";
00136 $s_xml .= $this->arrayToXML($value, $key, $in_nodeName, $in_level + 1);
00137 $s_xml .= "</$key>";
00138 }
00139 }
00140 else {
00141
00142 $value = preg_replace('/[[:cntrl:]]/', '', $value);
00143 if (trim($value) == '') {
00144 $s_xml .= "<$key />";
00145 }
00146 else if (htmlspecialchars($value) != $value) {
00147 $s_xml .= "<$key><![CDATA[$value]]></$key>";
00148 }
00149 else {
00150 $s_xml .= "<$key>$value</$key>";
00151 }
00152 }
00153 }
00154
00155 if ($in_level == 1 && !is_null($in_topNode)) {
00156 $s_xml .= "</$in_topNode>";
00157 }
00158
00159 return $s_xml;
00160 }
00161
00162
00163
00164
00177 function setMessage($in_message, $in_mode = FASTFRAME_NORMAL_MESSAGE, $in_top = false)
00178 {
00179 parent::setMessage($in_message, $in_mode, $in_top);
00180
00181 if ($in_mode == FASTFRAME_ERROR_MESSAGE) {
00182 header('HTTP/1.0 500 Unsuccessful Action');
00183 }
00184 }
00185
00186
00187
00188
00195 function _renderMessages()
00196 {
00197 $a_messages = array();
00198 foreach ($this->messages as $a_message) {
00199 $a_messages[] = array('txt' => $a_message[0], 'type' => $a_message[1]);
00200 }
00201
00202 $this->addNode('msgs', $a_messages, 'msg');
00203 }
00204
00205
00206 }
00207 ?>