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>";
43 $buf .= "<h2>Methods</h2><table bgcolor='#dddddd' align='center' border=1 width=100%>";
44 foreach($methodList as $method) {
45 $name = $method[name];
46 $author = $method[author] ? $method[author] : $unknown;
47 $version = $method[version] ? $method[version] : $unknown;
48 $desc = $method[purpose] ? $method[purpose] : $unknown;
49 $sigs = $method[signatures];
50 $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>";
51 $buf .= "<tr>" . field("Signature(s)", get_sigs($method), 3) . "</tr>";
52 $buf .= "<tr>" . field("Author", $author, 2) . field("Version", $version) . "</tr>";
53 $buf .= "<tr>" . field("Purpose", $desc, 3) . "</tr>";
55 $exclude_list = array(
63 foreach($method as $key => $val) {
64 if (!in_array($key, $exclude_list)) {
66 $buf .= "<tr bgcolor='#aaaaaa'><td colspan=3>" . ucfirst($key) . "</td></tr>";
68 foreach($val as $key2 => $desc) {
69 if (gettype($desc) === "string") {
70 if (gettype($key2) !== "string") {
74 $buf .= "<tr>" . field(ucfirst($key2), $desc, 3) . "</tr>";
79 $buf .= "<tr>" . field(ucfirst($key), $val, 3) . "</tr>";
86 $bmultiple = count($sigs) > 1;
87 foreach($sigs as $sig) {
90 $buf .= "<tr bgcolor='#888888'><td colspan=3><font color='white'><b>Signature $count:</b> " . get_sig($name, $sig) . "</font></td></tr>";
94 $buf .= "<tr bgcolor='#aaaaaa'><td colspan=3>Parameters</td></tr>";
96 $buf .= "<tr><td colspan=3>";
97 $buf .= do_params($sig[params], false, false);
102 $buf .= "<tr bgcolor='#aaaaaa'><td colspan=3>Return Value(s)</td></tr>";
103 $buf .= "<tr><td colspan=3>";
104 $buf .= do_params($sig[returns], false, false);
105 $buf .= "</td></tr>";
111 $buf .= "<tr bgcolor='#aaaaaa'><td colspan=3>See Also</td></tr>";
113 foreach($method[see] as $name => $desc) {
114 if ($method_hash[$name]) {
115 $name = "<a href='#$name'>$name</a>";
118 $buf .= "<tr>" . field($name, $desc, 3) . "</tr>";
122 $buf .= "</table><H2>Types</H2><TABLE><table bgcolor='#dddddd' align='center' border=1 width=100%>";
123 $buf .= "<tr><td colspan=3>";
125 $buf .= do_params($typeList, true);
127 $buf .= "</td></tr>";
133 /*********************************************************************
134 * The following functions are non-public and may change at any time. *
135 *********************************************************************/
137 /* non public - format key/val pair in a <td></td> */
138 function field($title, $text, $columns=false, $width=false) {
140 $colspan = " colspan='$columns'";
143 $width = " width='$width' ";
145 $colon = $title && $text ? ":" : "";
146 return "<td$colspan$width><b>$title$colon</b> $text</td>";
149 function is_xmlrpc_type($type) {
150 static $types = array("array", "struct", "mixed", "string", "int", "i4", "datetime", "base64", "boolean");
151 return in_array($type, $types);
154 function user_type($type) {
155 global $xi_type_hash;
156 return $xi_type_hash[$type] ? true : false;
160 function do_param($param, $bNewType=false, $bLinkUserTypes=true, $depth=0) {
161 /* guard against serious craziness */
162 if (++ $depth >= 24) {
163 return "<dt><b>max depth reached. bailing out...</b></dt>";
165 $name = $param[name];
166 $type = $param[type];
167 $desc = $param[description];
168 $member = $param[member];
169 $opt = $param[optional];
170 $def = $param['default'];
171 $type_def = $param[type_def];
174 $type_def = "<a href='#$type_def'>$type_def</a> ";
183 $anchor = "<a name='$name'></a>";
186 if (user_type($type)) {
187 if ($bLinkUserTypes) {
188 $type = "<a href='#$type'>$type</a>";
191 /* hack to display user values inline. max depth check above. */
192 global $xi_type_hash;
193 $newtype = $xi_type_hash[$type];
195 $newtype[name] = $param[name];
196 $newtype[optional] = $param[optional];
197 if ($param[description]) {
198 $newtype[description] = $param[description];
200 $newtype[type_def] = $type;
201 $buf .= do_param($newtype, $bNewType, $bLinkUserTypes, $depth);
206 $buf .= "$type_def$type <i>$anchor$name</i>";
210 $buf .= "optional" . ($def ? ", " : "");
213 $buf .= "default=$def";
222 $buf .= do_params($member, $bNewType, $bLinkUserTypes, $depth);
229 /* non public - format params list recursively */
230 function do_params($params, $bNewType=false, $bLinkUserTypes=true, $depth=0) {
232 $br = $bNewType ? "<br>" : "";
234 foreach($params as $param) {
235 $buf .= do_param($param, $bNewType, $bLinkUserTypes, $depth);
237 $buf .= "</dl>$br\n";
243 function get_sig($method_name, $sig) {
245 if ($method_name && $sig) {
246 $return = $sig[returns][0][type];
252 $buf .= "$method_name( ";
256 foreach($sig[params] as $param) {
257 $type = $param[type];
258 $opt = $param[optional];
259 $def = $param["default"];
260 $name = $param["name"];
261 if (user_type($type)) {
262 $type = "<a href='#$type'>$type</a>";
266 $buf .= $first ? '[' : ' [';
291 /* non public. generate method signature from method description */
292 function get_sigs($method) {
293 $method_name = $method[name];
297 if ($method[signatures]) {
298 foreach($method[signatures] as $sig) {
299 $buf .= "<li>" . get_sig($method_name, $sig);
306 function name_cmp($a, $b) {
307 return strcmp($a[name], $b[name]);
311 /*************************************
312 * END system.describeMethods Support *
313 *************************************/