IXR_Value

IXR_Value.

Defined (1)

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

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