IXR_Value

IXR_Value.

Defined (1)

The class is defined in the following location(s).

/bp-forums/bbpress/bb-includes/backpress/class.ixr.php  
  1. class IXR_Value { 
  2. var $data; 
  3. var $type; 
  4.  
  5. function __construct($data, $type = false) 
  6. $this->data = $data; 
  7. if (!$type) { 
  8. $type = $this->calculateType(); 
  9. $this->type = $type; 
  10. if ($type == 'struct') { 
  11. // Turn all the values in the array in to new IXR_Value objects 
  12. foreach ($this->data as $key => $value) { 
  13. $this->data[$key] = new IXR_Value($value); 
  14. if ($type == 'array') { 
  15. for ($i = 0, $j = count($this->data); $i < $j; $i++) { 
  16. $this->data[$i] = new IXR_Value($this->data[$i]); 
  17.  
  18. function IXR_Value($data, $type = false) 
  19. $this->__construct($data, $type); 
  20.  
  21. function calculateType() 
  22. if ($this->data === true || $this->data === false) { 
  23. return 'boolean'; 
  24. if (is_integer($this->data)) { 
  25. return 'int'; 
  26. if (is_double($this->data)) { 
  27. return 'double'; 
  28.  
  29. // Deal with IXR object types base64 and date 
  30. if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { 
  31. return 'date'; 
  32. if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { 
  33. return 'base64'; 
  34.  
  35. // If it is a normal PHP object convert it in to a struct 
  36. if (is_object($this->data)) { 
  37. $this->data = get_object_vars($this->data); 
  38. return 'struct'; 
  39. if (!is_array($this->data)) { 
  40. return 'string'; 
  41.  
  42. // We have an array - is it an array or a struct? 
  43. if ($this->isStruct($this->data)) { 
  44. return 'struct'; 
  45. } else { 
  46. return 'array'; 
  47.  
  48. function getXml() 
  49. // Return XML for this value 
  50. switch ($this->type) { 
  51. case 'boolean': 
  52. return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; 
  53. break; 
  54. case 'int': 
  55. return '<int>'.$this->data.'</int>'; 
  56. break; 
  57. case 'double': 
  58. return '<double>'.$this->data.'</double>'; 
  59. break; 
  60. case 'string': 
  61. return '<string>'.htmlspecialchars($this->data).'</string>'; 
  62. break; 
  63. case 'array': 
  64. $return = '<array><data>'."\n"; 
  65. foreach ($this->data as $item) { 
  66. $return .= ' <value>'.$item->getXml()."</value>\n"; 
  67. $return .= '</data></array>'; 
  68. return $return; 
  69. break; 
  70. case 'struct': 
  71. $return = '<struct>'."\n"; 
  72. foreach ($this->data as $name => $value) { 
  73. $name = htmlspecialchars($name); 
  74. $return .= " <member><name>$name</name><value>"; 
  75. $return .= $value->getXml()."</value></member>\n"; 
  76. $return .= '</struct>'; 
  77. return $return; 
  78. break; 
  79. case 'date': 
  80. case 'base64': 
  81. return $this->data->getXml(); 
  82. break; 
  83. return false; 
  84.  
  85. /** 
  86. * Checks whether or not the supplied array is a struct or not 
  87. * @param unknown_type $array 
  88. * @return boolean 
  89. */ 
  90. function isStruct($array) 
  91. $expected = 0; 
  92. foreach ($array as $key => $value) { 
  93. if ((string)$key != (string)$expected) { 
  94. return true; 
  95. $expected++; 
  96. return false;