portdb: reimplemented XML output format support

This commit is contained in:
Matt Housh 2024-03-22 16:20:49 -05:00
parent 70e3eab922
commit 84208a533c
Signed by: jaeger
GPG Key ID: F9DE89ED1BFADFD7
4 changed files with 205 additions and 60 deletions

View File

@ -20,6 +20,17 @@
EOD; EOD;
return $this->out; return $this->out;
} }
public function rowToXML() {
$this->out = <<<EOD
<duplicate>
<name>$this->name</name>
<count>$this->count</count>
</duplicate>\n
EOD;
return $this->out;
}
} }
?> ?>

View File

@ -56,6 +56,48 @@
EOD; EOD;
return $this->out; return $this->out;
} }
public function filesToXML() {
$xml = "";
if ($this->type == "httpup") {
$base_url = "{$this->url}";
} else {
$base_url = localrepo($this->repo);
}
if ($base_url != "") {
$base_url = chop($base_url, "/");
$xml .= "<pkgfile>{$base_url}/{$this->name}/Pkgfile</pkgfile>\n";
$xml .= " <footprint>{$base_url}/{$this->name}/.footprint</footprint>\n";
$xml .= " <signature>{$base_url}/{$this->name}/.signature</signature>";
}
return $xml;
}
public function rowToXML() {
$downloadcmd = $this->downloadCmd();
$this->out = <<<EOD
<port>
<name>$this->name</name>
<repo>$this->repo</repo>\n
EOD;
if ($this->type == "httpup") {
$files = $this->filesToXML();
$this->out .= <<<EOD
<files>
$files
</files>\n
EOD;
}
$this->out .= <<<EOD
<command>$downloadcmd</command>
</port>\n
EOD;
return $this->out;
}
} }
?> ?>

View File

@ -63,6 +63,21 @@ EOD;
return $this->out; return $this->out;
} }
public function rowToXML() {
$maintainer = $this->obfuscate($this->maintainer);
$this->out = <<<EOD
<repo>
<name>$this->name</name>
<maintainer>$maintainer</maintainer>
<type>$this->type</type>
<url>$this->url</url>
<ports>$this->numports</ports>
<publickey>$this->pubkey</publickey>
</repo>\n
EOD;
return $this->out;
}
public function getSyncFile() { public function getSyncFile() {
$maintainer = $this->obfuscate($this->maintainer); $maintainer = $this->obfuscate($this->maintainer);
$content = ''; $content = '';

View File

@ -20,6 +20,10 @@
print file_get_contents('footer.html'); print file_get_contents('footer.html');
} }
function xmlDocType() {
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
}
function localrepo($name) { function localrepo($name) {
global $cruxver; global $cruxver;
@ -40,6 +44,10 @@
if (isset($_GET['f'])) { $format = sanitize($_GET['f']); } else $format = null; if (isset($_GET['f'])) { $format = sanitize($_GET['f']); } else $format = null;
if (isset($_GET['s'])) { $strict = sanitize($_GET['s']); } else $strict = null; if (isset($_GET['s'])) { $strict = sanitize($_GET['s']); } else $strict = null;
if ($format == "xml") {
header('Content-Type: application/xml');
}
switch ($action) { switch ($action) {
case "repo": case "repo":
# individual repo index # individual repo index
@ -63,11 +71,27 @@
array_push($ports, $port); array_push($ports, $port);
} }
# header if ($format == "xml") {
printHeader(); # doctype
xmlDocType();
# construct content/table $out = "<ports>\n";
$out = <<<EOD
# add ports
foreach ($ports as $port) {
$out .= $port->rowToXML();
}
# end
$out .= "</ports>\n";
print($out);
} else {
# header
printHeader();
# construct content/table
$out = <<<EOD
<h2>Ports in repository $port->repo <a href="?a=getup&q={$port->repo}">(get sync file)</a></h2> <h2>Ports in repository $port->repo <a href="?a=getup&q={$port->repo}">(get sync file)</a></h2>
<table class="listing"> <table class="listing">
<thead> <thead>
@ -81,21 +105,23 @@
<tbody>\n <tbody>\n
EOD; EOD;
# add ports # add ports
foreach ($ports as $port) { foreach ($ports as $port) {
$out .= $port->rowToHTML(); $out .= $port->rowToHTML();
} }
# end table # end table
$out .= <<<EOD $out .= <<<EOD
</tbody> </tbody>
</table> </table>
EOD; EOD;
print $out; print $out;
# footer
printFooter();
}
# footer
printFooter();
break; break;
case "search": case "search":
@ -125,12 +151,28 @@ EOD;
} }
} }
# header if ($format == "xml") {
printHeader(); # doctype
xmlDocType();
# construct content $out = "<ports>\n";
$script_name = getenv("SCRIPT_NAME");
$out = <<<EOD # add ports
foreach ($ports as $port) {
$out .= $port->rowToXML();
}
# end
$out .= "</ports>\n";
print($out);
} else {
# header
printHeader();
# construct content
$script_name = getenv("SCRIPT_NAME");
$out = <<<EOD
<h2>Simple port search</h2> <h2>Simple port search</h2>
<p>Search for ports by name</p> <p>Search for ports by name</p>
<form name="searchform" method="get" action="$script_name"> <form name="searchform" method="get" action="$script_name">
@ -140,11 +182,11 @@ EOD;
</form> </form>
EOD; EOD;
# create table if a search was performed # create table if a search was performed
if ($query != '') { if ($query != '') {
# construct table # construct table
$out .= <<<EOD $out .= <<<EOD
<table class="listing"> <table class="listing">
<thead> <thead>
<tr> <tr>
@ -157,22 +199,24 @@ EOD;
<tbody>\n <tbody>\n
EOD; EOD;
# add ports # add ports
foreach ($ports as $port) { foreach ($ports as $port) {
$out .= $port->rowToHTML(); $out .= $port->rowToHTML();
} }
# end table # end table
$out .= <<<EOD $out .= <<<EOD
</tbody> </tbody>
</table> </table>
EOD; EOD;
}
print $out;
# footer
printFooter();
} }
print $out;
# footer
printFooter();
break; break;
case "dups": case "dups":
@ -190,11 +234,26 @@ EOD;
array_push($dups, $dup); array_push($dups, $dup);
} }
# header if ($format == "xml") {
printHeader(); # doctype
xmlDocType();
$out = "<duplicates>\n";
# construct content/table # add duplicates
$out = <<<EOD foreach ($dups as $dup) {
$out .= $dup->rowToXML();
}
# end
$out .= "</duplicates>\n";
print($out);
} else {
# header
printHeader();
# construct content/table
$out = <<<EOD
<h2>List of duplicate ports</h2> <h2>List of duplicate ports</h2>
<table class="listing"> <table class="listing">
<thead> <thead>
@ -206,21 +265,22 @@ EOD;
<tbody>\n <tbody>\n
EOD; EOD;
# add duplicates # add duplicates
foreach ($dups as $dup) { foreach ($dups as $dup) {
$out .= $dup->rowToHTML(); $out .= $dup->rowToHTML();
} }
# end table # end table
$out .= <<<EOD $out .= <<<EOD
</tbody> </tbody>
</table> </table>
EOD; EOD;
print $out; print $out;
# footer # footer
printFooter(); printFooter();
}
break; break;
@ -271,11 +331,27 @@ EOD;
$rows = $db->doQuery($sql); $rows = $db->doQuery($sql);
$uniquecount = $rows[0]['uniquecount']; $uniquecount = $rows[0]['uniquecount'];
# header if ($format == "xml") {
printHeader(); # doctype
xmlDocType();
# construct content/table $out = "<repos>\n";
$out = <<<EOD
# add repos
foreach ($repos as $repo) {
$out .= $repo->rowToXML();
}
# end
$out .= "</repos>\n";
print($out);
} else {
# header
printHeader();
# construct content/table
$out = <<<EOD
<h2>Overview of available repositories</h2> <h2>Overview of available repositories</h2>
<table class="listing"> <table class="listing">
<thead> <thead>
@ -291,13 +367,13 @@ EOD;
<tbody>\n <tbody>\n
EOD; EOD;
# add repos # add repos
foreach ($repos as $repo) { foreach ($repos as $repo) {
$out .= $repo->rowToHTML(); $out .= $repo->rowToHTML();
} }
# add unique count # add unique count
$out .= <<<EOD $out .= <<<EOD
<tr> <tr>
<td></td> <td></td>
<td>$uniquecount (unique)</td> <td>$uniquecount (unique)</td>
@ -305,16 +381,17 @@ EOD;
</tr>\n </tr>\n
EOD; EOD;
# end table # end table
$out .= <<<EOD $out .= <<<EOD
</tbody> </tbody>
</table> </table>
EOD; EOD;
print $out; print $out;
# footer # footer
printFooter(); printFooter();
}
} }
?> ?>