science-ation/apidoc.php
2010-09-27 20:50:37 +00:00

66 lines
1.5 KiB
PHP

<html>
<head>
<title>API Doc</title>
<link rel="stylesheet" href="apidoc.css" type="text/css" media="all" />
</head>
<body>
<?
//lets get sneaky here, and have the file parse itself!
$lines=file("api.php");
foreach($lines AS $line) {
$line=trim($line);
$matches=array();
if(preg_match("/APIDOC/",$line)) {
list($b,$a)=explode(":",$line);
$cmd=array();
$cmd['command']=trim($a);
$cmd['description']=array();
$cmd['post']=array();
$cmd['return']=array();
$incmd=true;
}
if($incmd==true && preg_match("/description\((.*)\)/",$line,$matches)) {
$cmd['description']=$matches[1];
}
if($incmd==true && preg_match("/post\((.*)\)/",$line,$matches)) {
$posts=explode(",",$matches[1]);
$cmd['post']=$posts;
}
if($incmd==true && preg_match("/return\((.*)\)/",$line,$matches)) {
$returns=explode(",",$matches[1]);
$cmd['return']=$returns;
}
if($incmd==true && $line=="*/") {
$incmd=false;
$commands[$cmd['command']]=$cmd;
unset($cmd);
}
}
ksort($commands);
foreach($commands AS $c=>$com) {
echo "<h1>".htmlspecialchars($c)."</h1>";
echo "<div class=\"apidoc\">\n";
echo $com['description'];
echo "<br />";
if(count($com['post'])) {
echo "<h2>Post</h2>\n";
echo "<ul>";
foreach($com['post'] AS $p) {
echo "<li>$p</li>\n";
}
echo "</ul>";
}
if(count($com['return'])) {
echo "<h2>Return</h2>\n";
echo "<ul>";
foreach($com['return'] AS $p) {
echo "<li>$p</li>\n";
}
echo "</ul>";
}
echo "<br />";
echo "</div>";
}
?>