misc.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /*
  3. * 4PSA DNSManager SOAP API Client for PHP v1.1
  4. *
  5. * Function for xml SOAP resquest/response format
  6. *
  7. * Copyright (c) 2011 Rack-Soft (www.4psa.com). All rights reserved.
  8. *
  9. */
  10. /**
  11. * Formats an XML string into an array of tags
  12. * @param <string> $xml - string with SOAP request/response
  13. * @return <array> $format_xml - array with tags
  14. */
  15. function format_xml($xml) {
  16. $format_xml = array();
  17. for ($i = 0; $i < strlen($xml); $i++) {
  18. $start_pos = stripos($xml, '<');
  19. $stop_pos = stripos($xml, '>');
  20. $tag = substr($xml, $start_pos+1, $stop_pos-$start_pos-1);
  21. $xml = substr($xml, $stop_pos+1);
  22. /* search for ending tag in $xml remained */
  23. $end_tag = strstr($xml, '/' . $tag);
  24. if (strlen($end_tag) > 0) {
  25. $end_tag_pos = strlen($xml) - strlen($end_tag);
  26. if ((stripos($xml, '<')+1) == $end_tag_pos) {
  27. $value = substr($xml, 0, $end_tag_pos);
  28. $tag_name = $tag;
  29. $tag = $tag_name . '>' .$value. '/' .$tag_name;
  30. $xml = substr($end_tag, strlen($tag_name)+2);
  31. }
  32. }
  33. $format_xml[] = $tag;
  34. }
  35. $tags_no = count($format_xml);
  36. if ($tags_no > 0) {
  37. $format_xml[0] = '<'.$format_xml[0];
  38. $format_xml[$tags_no-1] = $format_xml[$tags_no-1].'>';
  39. }
  40. if (!empty($format_xml[1])) {
  41. $envelope = explode(' ', $format_xml[1]);
  42. for ($i = 1; $i < count($envelope)-1; $i++) {
  43. $envelope[$i] = $envelope[$i]."\n";
  44. }
  45. $format_xml[1] = implode(' ', $envelope);
  46. return $format_xml;
  47. } else {
  48. return FALSE;
  49. }
  50. }
  51. /**
  52. * Formats a hash of languages in format 'code' => 'name'
  53. * @param <array> $languages - object with languages information
  54. * @return <array> $format_lang - array of languages
  55. */
  56. function format_languages($languages) {
  57. $format_lang = array();
  58. if (is_array($languages) && !empty($languages)) {
  59. foreach ($languages as $key => $val) {
  60. $lang = get_object_vars($val);
  61. $format_lang[$lang['code']] = $lang['name'];
  62. }
  63. }
  64. return $format_lang;
  65. }
  66. /**
  67. * Splits a faultstring to fit to a fix area
  68. * @param <array> $xml_array - array with xml tags
  69. * @param <type> $width - fix area size
  70. * @return <array> $xml_array - formated array with XML tags
  71. */
  72. function split_faultstring($xml_array, $width = '') {
  73. if (!empty($xml_array)) {
  74. foreach ($xml_array as $key => $val) {
  75. if (is_numeric(strpos($val, 'faultstring>')) || is_numeric(strpos($val, 'message>'))) {
  76. $length = 20;
  77. if (!empty($width)) {
  78. $length = $width/7;
  79. }
  80. $val = wordwrap($val, $length, "\n");
  81. $xml_array[$key] = $val;
  82. }
  83. }
  84. return $xml_array;
  85. }
  86. return FALSE;
  87. }
  88. /**
  89. * Gets the location of the local schemes, based on the location of a php script
  90. * @param string $script_location - the location of the script
  91. * @return string $location - the location of the local schemes
  92. */
  93. function get_local_schemes_location($script_location) {
  94. $lastslashpos = strrpos($script_location, "/");
  95. $location = substr($script_location, 0, $lastslashpos);
  96. $secondlastpos = strrpos($location, "/");
  97. $location = substr($location, 0, $secondlastpos + 1);
  98. return $location;
  99. }