From bd0e0cd8e5139c70311b669b18e795f656ba9643 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Sat, 12 Jun 2010 18:41:24 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=B0=20trunk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit +YUCHENG HU+ git-svn-id: https://svn.code.sf.net/p/hawebs/svn@155 a2543c7e-f6e9-4f8a-8bff-1ffc34733512 --- oss/joomla/trunk/xmlrpc/cache/index.html | 1 + oss/joomla/trunk/xmlrpc/client.php | 212 ++++++++++++++++++ .../trunk/xmlrpc/includes/application.php | 75 +++++++ oss/joomla/trunk/xmlrpc/includes/defines.php | 31 +++ .../trunk/xmlrpc/includes/framework.php | 67 ++++++ oss/joomla/trunk/xmlrpc/includes/index.html | 1 + oss/joomla/trunk/xmlrpc/index.php | 58 +++++ 7 files changed, 445 insertions(+) create mode 100644 oss/joomla/trunk/xmlrpc/cache/index.html create mode 100644 oss/joomla/trunk/xmlrpc/client.php create mode 100644 oss/joomla/trunk/xmlrpc/includes/application.php create mode 100644 oss/joomla/trunk/xmlrpc/includes/defines.php create mode 100644 oss/joomla/trunk/xmlrpc/includes/framework.php create mode 100644 oss/joomla/trunk/xmlrpc/includes/index.html create mode 100644 oss/joomla/trunk/xmlrpc/index.php diff --git a/oss/joomla/trunk/xmlrpc/cache/index.html b/oss/joomla/trunk/xmlrpc/cache/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/oss/joomla/trunk/xmlrpc/cache/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/oss/joomla/trunk/xmlrpc/client.php b/oss/joomla/trunk/xmlrpc/client.php new file mode 100644 index 00000000..20f40f48 --- /dev/null +++ b/oss/joomla/trunk/xmlrpc/client.php @@ -0,0 +1,212 @@ +getCfg('xmlrpc_server') && $mainframe->getCfg('debug'))) { + JError::raiseError(403, 'XML-RPC Client or Debugging not enabled.'); +} + +// Includes the required class file for the XML-RPC Client +jimport('phpxmlrpc.xmlrpc'); + +// Get default values for the XMLRPC server host and path +$uri = JURI::getInstance(); +$host = $uri->getHost(); +$path = $uri->getPath(); +$path = dirname($path).'/'; + +$host = JRequest::getString( 'host', $host, 'post' ); +$path = JRequest::getString( 'path', $path, 'post' ); +$debug = JRequest::getVar( 'debug', 0, 'post', 'int' ); +$task = JRequest::getVar( 'task', 0, 'post', 'cmd' ); + +$output = ''; +$array = array(); + +if ($task) +{ + if ($path) + { + $client = new xmlrpc_client($path, $host, 80); + } + else + { + $client = new xmlrpc_client('', $host); + } + $client->setDebug($debug); + + switch ($task) + { + case 'list_methods': + { + jimport( 'joomla.html.html' ); + $msg = new xmlrpcmsg('system.listMethods'); + $xmlrpcdoc = $client->send($msg); + + //echo var_dump($xmlrpcdoc); + //die; + + if ($xmlrpcdoc->faultCode() == 0) + { + $result = $xmlrpcdoc->value(); + $array = $result->scalarval(); + } + else + { + print $xmlrpcdoc->faultString(); + } + + $methods = array(); + for ($i=0; $i < sizeof($array); $i++) + { + $var = new xmlrpcval($array[$i]); + $array_method = $var->scalarval(); + + $methods[$i] = JHTML::_('select.option', $array_method->scalarval()); + } + + $output = 'Methods
'; + $output .= JHTML::_('select.genericlist', $methods, 'method', 'size="10"', 'value', 'text' ); + $output .= ' '; + $output .= ' '; + + } break; + + case 'exec': + { + $method = JRequest::getVar( 'method', '', '', 'cmd' ); + $args = JRequest::getVar( 'args' ); + + $message = new xmlrpcmsg($method, array(new xmlrpcval(0, "int"))); + + $xmlrpcdoc = $client->send($message); + + if ($xmlrpcdoc->faultCode()== 0) + { + $scalar_var = $xmlrpcdoc->value(); + $output = var_export($scalar_var->scalarval(), true); + } + else + { + print $xmlrpcdoc->faultString(); + } + + } break; + } + +} + +?> + + + + + + Joomla! XML-RPC Test Client + + + +
+
+
+
+
Joomla! XML-RPC Test Client
+
+
+ + + + + + + + + +
XML-RPC Host + + Eg: www.test.com or http://james:bond@www.test.com/xmlrpc +
Server File + + + Debug: + /> +
+ +
+
+
+ + diff --git a/oss/joomla/trunk/xmlrpc/includes/application.php b/oss/joomla/trunk/xmlrpc/includes/application.php new file mode 100644 index 00000000..2661e690 --- /dev/null +++ b/oss/joomla/trunk/xmlrpc/includes/application.php @@ -0,0 +1,75 @@ +_encoding = "UTF-8"; + + //Set the root in the URI based on the application name + JURI::root(null, str_replace('/'.$this->getName(), '', JURI::base(true))); + + } + + /** + * Get the charset encoding + * + * @return string the charset encoding + * @since 1.5 + */ + function getEncoding() { + return $this->_encoding; + } + + /** + * Set the charset encoding + * + * @var $encoding The encoding of the charset + */ + function setEncoding($encoding) { + $this->_encoding = $encoding; + } +} +?> \ No newline at end of file diff --git a/oss/joomla/trunk/xmlrpc/includes/defines.php b/oss/joomla/trunk/xmlrpc/includes/defines.php new file mode 100644 index 00000000..2216590e --- /dev/null +++ b/oss/joomla/trunk/xmlrpc/includes/defines.php @@ -0,0 +1,31 @@ + \ No newline at end of file diff --git a/oss/joomla/trunk/xmlrpc/includes/framework.php b/oss/joomla/trunk/xmlrpc/includes/framework.php new file mode 100644 index 00000000..c2cf4396 --- /dev/null +++ b/oss/joomla/trunk/xmlrpc/includes/framework.php @@ -0,0 +1,67 @@ +error_reporting === 0) { + error_reporting( 0 ); +} else if (@$CONFIG->error_reporting > 0) { + error_reporting( $CONFIG->error_reporting ); + ini_set( 'display_errors', 1 ); +} + +unset( $CONFIG ); + +/* + * Joomla! framework loading + */ + +// Include object abstract class +require_once(JPATH_SITE.DS.'libraries'.DS.'joomla'.DS.'utilities'.DS.'compat'.DS.'compat.php'); + +// Joomla! library imports +jimport( 'joomla.environment.uri' ); +jimport( 'joomla.user.user' ); +jimport( 'joomla.event.event'); +jimport( 'joomla.event.dispatcher'); +jimport( 'joomla.plugin.helper' ); +jimport( 'joomla.utilities.string' ); +?> \ No newline at end of file diff --git a/oss/joomla/trunk/xmlrpc/includes/index.html b/oss/joomla/trunk/xmlrpc/includes/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/oss/joomla/trunk/xmlrpc/includes/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/oss/joomla/trunk/xmlrpc/index.php b/oss/joomla/trunk/xmlrpc/index.php new file mode 100644 index 00000000..f7dc0d8c --- /dev/null +++ b/oss/joomla/trunk/xmlrpc/index.php @@ -0,0 +1,58 @@ +getCfg('xmlrpc_server')) { + JError::raiseError(403, 'XML-RPC Server not enabled.'); +} + +// Includes the required class file for the XML-RPC Server +jimport('phpxmlrpc.xmlrpc'); +jimport('phpxmlrpc.xmlrpcs'); + +// load all available remote calls +JPluginHelper::importPlugin( 'xmlrpc' ); +$allCalls = $mainframe->triggerEvent( 'onGetWebServices' ); +$methodsArray = array(); + +foreach ($allCalls as $calls) { + $methodsArray = array_merge($methodsArray, $calls); +} + +$xmlrpcServer = new xmlrpc_server($methodsArray, false); +// allow casting to be defined by that actual values passed +$xmlrpcServer->functions_parameters_type = 'phpvals'; +// define UTF-8 as the internal encoding for the XML-RPC server +$xmlrpcServer->xml_header($mainframe->getEncoding()); +$xmlrpc_internalencoding = $mainframe->getEncoding(); +// debug level +$xmlrpcServer->setDebug(0); +// start the service +$xmlrpcServer->service(); +?>