forked from science-ation/science-ation
46f292ba16
If a id exists, it is updated If no id exists, it is created edit now returns the full mentor view array
147 lines
3.4 KiB
PHP
147 lines
3.4 KiB
PHP
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>API Doc</title>
|
|
<link rel="stylesheet" href="apidoc.css" type="text/css" media="all" />
|
|
</head>
|
|
<body>
|
|
<?
|
|
$commands=array();
|
|
$nicommands=array();
|
|
//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();
|
|
//assume its implemented unless we say otherwise
|
|
$cmd['implemented']=true;
|
|
$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 && preg_match("/object\((.*)\)/",$line,$matches)) {
|
|
$objects=explode(":",$matches[1],2);
|
|
$cmd['object'][]=$objects;
|
|
}
|
|
if($incmd==true && $line=="notimplemented") {
|
|
$cmd['implemented']=false;
|
|
}
|
|
if($incmd==true && $line=="*/") {
|
|
$incmd=false;
|
|
if($cmd['implemented'])
|
|
$commands[$cmd['command']]=$cmd;
|
|
else
|
|
$nicommands[$cmd['command']]=$cmd;
|
|
unset($cmd);
|
|
}
|
|
}
|
|
|
|
echo "<h1>Status</h1>\n";
|
|
$numi=count($commands);
|
|
$numni=count($nicommands);
|
|
$total=$numi+$numni;
|
|
$percent=round($numi/$total*100);
|
|
echo "$numi of $total implemented ($percent%) <br />\n";
|
|
|
|
echo "<h1>Basics</h1>\n";
|
|
echo "All API commands return \"status\", which is either \"ok\" or \"error\" <br />\n";
|
|
echo "If status is \"error\", then the return also contains \"error\" which contains the error message <br />\n";
|
|
|
|
echo "<h1>Implemented API</h1>\n";
|
|
ksort($commands);
|
|
$cols=3;
|
|
$percol=ceil($numi/$cols);
|
|
echo "<table cellspacing=\"10\">";
|
|
echo "<tr><td>";
|
|
$x=0;
|
|
foreach($commands AS $c=>$com) {
|
|
if($x%$percol==0) echo "</td><td>";
|
|
echo "<a href=\"#$c\">$c</a><br />";
|
|
$x++;
|
|
}
|
|
echo "</tr></table>\n";
|
|
|
|
foreach($commands AS $c=>$com) {
|
|
echo "<a name=\"$c\"></a>";
|
|
echo "<h2>".htmlspecialchars($c)."</h2>";
|
|
echo "<div class=\"apidoc\">\n";
|
|
echo $com['description'];
|
|
echo "<br />";
|
|
if(count($com['post'])) {
|
|
echo "<h3>Post</h3>\n";
|
|
echo "<ul>";
|
|
foreach($com['post'] AS $p) {
|
|
echo "<li>$p</li>\n";
|
|
}
|
|
echo "</ul>";
|
|
}
|
|
if(count($com['return'])) {
|
|
echo "<h3>Return</h3>\n";
|
|
echo "<ul>";
|
|
foreach($com['return'] AS $p) {
|
|
echo "<li>$p</li>\n";
|
|
}
|
|
echo "</ul>";
|
|
}
|
|
if(count($com['object'])) {
|
|
echo "<h3>Objects Referenced</h3>\n";
|
|
echo "<ul>";
|
|
foreach($com['object'] AS $o) {
|
|
echo "<li><b>{$o[0]}</b>: {$o[1]}</li>\n";
|
|
}
|
|
echo "</ul>";
|
|
}
|
|
echo "<br />";
|
|
echo "</div>";
|
|
}
|
|
|
|
echo "<h1>Not Implemented API</h1>\n";
|
|
|
|
ksort($nicommands);
|
|
foreach($nicommands AS $c=>$com) {
|
|
echo "<h2>".htmlspecialchars($c)."</h2>";
|
|
echo "<div class=\"apidoc\">\n";
|
|
echo $com['description'];
|
|
echo "<br />";
|
|
if(count($com['post'])) {
|
|
echo "<h3>Post</h3>\n";
|
|
echo "<ul>";
|
|
foreach($com['post'] AS $p) {
|
|
echo "<li>$p</li>\n";
|
|
}
|
|
echo "</ul>";
|
|
}
|
|
if(count($com['return'])) {
|
|
echo "<h3>Return</h3>\n";
|
|
echo "<ul>";
|
|
foreach($com['return'] AS $p) {
|
|
echo "<li>$p</li>\n";
|
|
}
|
|
echo "</ul>";
|
|
}
|
|
echo "<br />";
|
|
echo "</div>";
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
</body>
|
|
</html>
|