modxmlrpcresponse.class.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. require_once MODX_CORE_PATH . 'model/modx/xmlrpc/xmlrpc.inc';
  11. require_once MODX_CORE_PATH . 'model/modx/xmlrpc/xmlrpcs.inc';
  12. require_once MODX_CORE_PATH . 'model/modx/xmlrpc/xmlrpc_wrappers.inc';
  13. require_once MODX_CORE_PATH . 'model/modx/modresponse.class.php';
  14. /**
  15. * Handles any XML-RPC resources and their response
  16. *
  17. * @package modx
  18. * @subpackage xmlrpc
  19. */
  20. class modXMLRPCResponse extends modResponse {
  21. /**
  22. * The XML-RPC server attached to this response
  23. * @var xmlrpc_server
  24. * @access public
  25. */
  26. public $server= null;
  27. /**
  28. * A collection of services attached to this response
  29. * @var array
  30. * @access public
  31. */
  32. public $services= array ();
  33. /**
  34. * Output the content of the resource
  35. *
  36. * @param array $options An array of options for the output
  37. */
  38. public function outputContent(array $options= array()) {
  39. if (empty($options['rpc_type'])) $options['rpc_type']= 'XML';
  40. $resourceClass = 'mod' . $options['rpc_type'] . 'RPCResource';
  41. if (!($this->modx->resource instanceof $resourceClass)) {
  42. $this->modx->log(modX::LOG_LEVEL_FATAL, 'Could not load ' . $options['rpc_type'] . '-RPC Server class.');
  43. }
  44. $this->modx->resource->process();
  45. $this->modx->resource->_output= $this->modx->resource->_content;
  46. /* collect any uncached element tags in the content and process them */
  47. $this->modx->getParser();
  48. $maxIterations= intval($this->modx->getOption('parser_max_iterations',null,10));
  49. $this->modx->parser->processElementTags('', $this->modx->resource->_output, true, false, '[[', ']]', array(), $maxIterations);
  50. $this->modx->parser->processElementTags('', $this->modx->resource->_output, true, true, '[[', ']]', array(), $maxIterations);
  51. if (!$this->getServer()) {
  52. $this->modx->log(modX::LOG_LEVEL_FATAL, 'Could not load ' . $options['rpc_type'] . '-RPC Server.');
  53. }
  54. $this->server->service();
  55. ob_get_level() && @ob_end_flush();
  56. while (ob_get_level() && @ob_end_clean()) {}
  57. exit();
  58. }
  59. /**
  60. * Gets the XML-RPC server for this response
  61. *
  62. * @access public
  63. * @param boolean $execute Whether or not to execute the server as well as
  64. * load it
  65. * @return boolean True if the server initialized an instance correctly
  66. */
  67. public function getServer($execute= false) {
  68. if ($this->server === null || !($this->server instanceof xmlrpc_server)) {
  69. $this->server= new xmlrpc_server($this->services, $execute);
  70. }
  71. return $this->server instanceof xmlrpc_server;
  72. }
  73. /**
  74. * Registers a service to this response
  75. *
  76. * @access public
  77. * @param string $key The name of the service
  78. * @param string $signature The signature of the service
  79. */
  80. public function registerService($key, $signature) {
  81. $this->services[$key]= $signature;
  82. }
  83. /**
  84. * Unregisters a service from this response
  85. *
  86. * @access public
  87. * @param string $key The name of the service
  88. */
  89. public function unregisterService($key) {
  90. unset($this->services[$key]);
  91. }
  92. }