xmlrpc_example.module

  1. examples
    1. 6 xmlrpc_example/xmlrpc_example.module
    2. 7 xmlrpc_example/xmlrpc_example.module
    3. 8 xmlrpc_example/xmlrpc_example.module
  2. drupal
    1. 4.7 developer/examples/xmlrpc_example.module
    2. 5 developer/examples/xmlrpc_example.module

This is an example of how to implement XML-RPC callbacks by implementing a validation suite.

Information on the test in this suite can be found at: http://www.xmlrpc.com/validator1Docs

Functions & methods

NameDescription
xmlrpc_example_arrayOfStructsTest
xmlrpc_example_countTheEntities
xmlrpc_example_easyStructTest
xmlrpc_example_echoStructTest
xmlrpc_example_manyTypesTest
xmlrpc_example_moderateSizeArrayCheck
xmlrpc_example_nestedStructTest
xmlrpc_example_simpleStructReturnTest
xmlrpc_example_xmlrpcImplementation of hook_xmlrpc().

File

developer/examples/xmlrpc_example.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * This is an example of how to implement XML-RPC callbacks by implementing a
  5. * validation suite.
  6. *
  7. * Information on the test in this suite can be found at:
  8. * http://www.xmlrpc.com/validator1Docs
  9. */
  10. /**
  11. * Implementation of hook_xmlrpc().
  12. *
  13. * This function provides Drupal with an array to map XML-RPC callbacks to the
  14. * functions implemented by this module.
  15. */
  16. function xmlrpc_example_xmlrpc() {
  17. return (array(
  18. 'validator1.arrayOfStructsTest' => 'xmlrpc_example_arrayOfStructsTest',
  19. 'validator1.countTheEntities' => 'xmlrpc_example_countTheEntities',
  20. 'validator1.easyStructTest' => 'xmlrpc_example_easyStructTest',
  21. 'validator1.echoStructTest' => 'xmlrpc_example_echoStructTest',
  22. 'validator1.manyTypesTest' => 'xmlrpc_example_manyTypesTest',
  23. 'validator1.moderateSizeArrayCheck' => 'xmlrpc_example_moderateSizeArrayCheck',
  24. 'validator1.nestedStructTest' => 'xmlrpc_example_nestedStructTest',
  25. 'validator1.simpleStructReturnTest' => 'xmlrpc_example_simpleStructReturnTest'
  26. ));
  27. }
  28. function xmlrpc_example_arrayOfStructsTest($array) {
  29. $sum = 0;
  30. foreach ($array as $struct) {
  31. $sum += $struct['curly'];
  32. }
  33. return $sum;
  34. }
  35. function xmlrpc_example_countTheEntities($string) {
  36. return array(
  37. 'ctLeftAngleBrackets' => substr_count($string, '<'),
  38. 'ctRightAngleBrackets' => substr_count($string, '>'),
  39. 'ctAmpersands' => substr_count($string, '&'),
  40. 'ctApostrophes' => substr_count($string, "'"),
  41. 'ctQuotes' => substr_count($string, '"'),
  42. );
  43. }
  44. function xmlrpc_example_easyStructTest($array) {
  45. return $array["curly"] + $array["moe"] + $array["larry"];
  46. }
  47. function xmlrpc_example_echoStructTest($array) {
  48. return $array;
  49. }
  50. function xmlrpc_example_manyTypesTest($args) {
  51. $timestamp = mktime($args[4]->hour, $args[4]->minute, $args[4]->second, $args[4]->month, $args[4]->day, $args[4]->year);
  52. return array($args[0], $args[1], $args[2], $args[3], xmlrpc_date($timestamp), xmlrpc_base64($args[5]));
  53. }
  54. function xmlrpc_example_moderateSizeArrayCheck($array) {
  55. return array_shift($array) . array_pop($array);
  56. }
  57. function xmlrpc_example_nestedStructTest($array) {
  58. return $array["2000"]["04"]["01"]["larry"] + $array["2000"]["04"]["01"]["moe"] + $array["2000"]["04"]["01"]["curly"];
  59. }
  60. function xmlrpc_example_simpleStructReturnTest($number) {
  61. return array("times10" => ($number*10), "times100" => ($number*100), "times1000" => ($number*1000));
  62. }
Login or register to post comments