3 /*********************************
4 * system.describeMethods Support *
5 *********************************/
7 /* public function. format method description.
8 * input = result from xmlrpc method "system.describeMethods" in a php array
9 * result = html string suitable for display.
11 function format_describe_methods_result($response) {
14 $method_hash = array();
15 $xi_type_hash = array();
17 $typeList = $response[typeList];
18 $methodList = $response[methodList];
20 usort($typeList, "name_cmp");
21 usort($methodList, "name_cmp");
24 $buf .= "<big>Methods\n<ul>";
25 foreach($methodList as $method) {
26 $name = $method[name];
27 $buf .= "<li><a href='#$name'>$name()</a>\n";
28 $method_hash[$name] = $method;
30 $buf .= "</ul></big>";
33 $buf .= "<big>Types\n<ul>";
34 foreach($typeList as $type) {
36 $buf .= "<li><a href='#$name'>$name</a>\n";
37 $xi_type_hash[$name] = $type;
39 $buf .= "</ul></big>";
42 $buf .= "<h2>Methods</h2><table bgcolor='#dddddd' align='center' border=1 width=100%>";
43 foreach($methodList as $method) {
44 $name = $method[name];
45 $author = $method[author] ? $method[author] : $unknown;
46 $version = $method[version] ? $method[version] : $unknown;
47 $desc = $method[purpose] ? $method[purpose] : $unknown;
48 $sigs = $method[signatures];
49 $buf .= "<tr bgcolor='#444444'><td align='center' class='title' colspan=3><font color='#EEEEEE'><a name='$name'><b><big>$name</big></b></a></font></td></tr>";
50 $buf .= "<tr>" . field("Signature(s)", get_sigs($method), 3) . "</tr>";
51 $buf .= "<tr>" . field("Author", $author, 2) . field("Version", $version) . "</tr>";
52 $buf .= "<tr>" . field("Purpose", $desc, 3) . "</tr>";
54 $exclude_list = array(
62 foreach($method as $key => $val) {
63 if (!in_array($key, $exclude_list)) {
65 $buf .= "<tr bgcolor='#aaaaaa'><td colspan=3>" . ucfirst($key) . "</td></tr>";
67 foreach($val as $key2 => $desc) {
68 if (gettype($desc) === "string") {
69 if (gettype($key2) !== "string") {
73 $buf .= "<tr>" . field(ucfirst($key2), $desc, 3) . "</tr>";
78 $buf .= "<tr>" . field(ucfirst($key), $val, 3) . "</tr>";
84 $bmultiple = count($sigs) > 1;
85 foreach($sigs as $sig) {
88 $buf .= "<tr bgcolor='#888888'><td colspan=3><font color='white'><b>Signature $count:</b> " . get_sig($name, $sig) . "</font></td></tr>";
92 $buf .= "<tr bgcolor='#aaaaaa'><td colspan=3>Parameters</td></tr>";
94 $buf .= "<tr><td colspan=3>";
95 $buf .= do_params($sig[params], false, false);
100 $buf .= "<tr bgcolor='#aaaaaa'><td colspan=3>Return Value(s)</td></tr>";
101 $buf .= "<tr><td colspan=3>";
102 $buf .= do_params($sig[returns], false, false);
103 $buf .= "</td></tr>";
109 $buf .= "<tr bgcolor='#aaaaaa'><td colspan=3>See Also</td></tr>";
111 foreach($method[see] as $name => $desc) {
112 if ($method_hash[$name]) {
113 $name = "<a href='#$name'>$name</a>";
116 $buf .= "<tr>" . field($name, $desc, 3) . "</tr>";
120 $buf .= "</table><H2>Types</H2><TABLE><table bgcolor='#dddddd' align='center' border=1 width=100%>";
121 $buf .= "<tr><td colspan=3>";
123 $buf .= do_params($typeList, true);
125 $buf .= "</td></tr>";
131 /*********************************************************************
132 * The following functions are non-public and may change at any time. *
133 *********************************************************************/
135 /* non public - format key/val pair in a <td></td> */
136 function field($title, $text, $columns=false, $width=false) {
138 $colspan = " colspan='$columns'";
141 $width = " width='$width' ";
143 $colon = $title && $text ? ":" : "";
144 return "<td$colspan$width><b>$title$colon</b> $text</td>";
147 function is_xmlrpc_type($type) {
148 static $types = array("array", "struct", "mixed", "string", "int", "i4", "datetime", "base64", "boolean");
149 return in_array($type, $types);
152 function user_type($type) {
153 global $xi_type_hash;
154 return $xi_type_hash[$type] ? true : false;
157 function do_param($param, $bNewType=false, $bLinkUserTypes=true, $depth=0) {
158 /* guard against serious craziness */
159 if (++ $depth >= 24) {
160 return "<dt><b>max depth reached. bailing out...</b></dt>";
162 $name = $param[name];
163 $type = $param[type];
164 $desc = $param[description];
165 $member = $param[member];
166 $opt = $param[optional];
167 $def = $param['default'];
168 $type_def = $param[type_def];
171 $type_def = "<a href='#$type_def'>$type_def</a> ";
180 $anchor = "<a name='$name'></a>";
183 if (user_type($type)) {
184 if ($bLinkUserTypes) {
185 $type = "<a href='#$type'>$type</a>";
188 /* hack to display user values inline. max depth check above. */
189 global $xi_type_hash;
190 $newtype = $xi_type_hash[$type];
192 $newtype[name] = $param[name];
193 $newtype[optional] = $param[optional];
194 if ($param[description]) {
195 $newtype[description] = $param[description];
197 $newtype[type_def] = $type;
198 $buf .= do_param($newtype, $bNewType, $bLinkUserTypes, $depth);
203 $buf .= "$type_def$type <i>$anchor$name</i>";
207 $buf .= "optional" . ($def ? ", " : "");
210 $buf .= "default=$def";
219 $buf .= do_params($member, $bNewType, $bLinkUserTypes, $depth);
226 /* non public - format params list recursively */
227 function do_params($params, $bNewType=false, $bLinkUserTypes=true, $depth=0) {
229 $br = $bNewType ? "<br>" : "";
231 foreach($params as $param) {
232 $buf .= do_param($param, $bNewType, $bLinkUserTypes, $depth);
234 $buf .= "</dl>$br\n";
239 function get_sig($method_name, $sig) {
241 if ($method_name && $sig) {
242 $return = $sig[returns][0][type];
248 $buf .= "$method_name( ";
252 foreach($sig[params] as $param) {
253 $type = $param[type];
254 $opt = $param[optional];
255 $def = $param["default"];
256 $name = $param["name"];
257 if (user_type($type)) {
258 $type = "<a href='#$type'>$type</a>";
262 $buf .= $first ? '[' : ' [';
287 /* non public. generate method signature from method description */
288 function get_sigs($method) {
289 $method_name = $method[name];
293 if ($method[signatures]) {
294 foreach($method[signatures] as $sig) {
295 $buf .= "<li>" . get_sig($method_name, $sig);
302 function name_cmp($a, $b) {
303 return strcmp($a[name], $b[name]);
306 /*************************************
307 * END system.describeMethods Support *
308 *************************************/