diff --git a/portdb/portdb/includes/duplicate.inc.php b/portdb/portdb/includes/duplicate.inc.php index 370280a..a380bd6 100644 --- a/portdb/portdb/includes/duplicate.inc.php +++ b/portdb/portdb/includes/duplicate.inc.php @@ -20,6 +20,17 @@ EOD; return $this->out; } + + public function rowToXML() { + $this->out = << + $this->name + $this->count + \n +EOD; + + return $this->out; + } } ?> diff --git a/portdb/portdb/includes/port.inc.php b/portdb/portdb/includes/port.inc.php index a78b168..d0344de 100644 --- a/portdb/portdb/includes/port.inc.php +++ b/portdb/portdb/includes/port.inc.php @@ -56,6 +56,48 @@ EOD; 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 .= "{$base_url}/{$this->name}/Pkgfile\n"; + $xml .= " {$base_url}/{$this->name}/.footprint\n"; + $xml .= " {$base_url}/{$this->name}/.signature"; + } + return $xml; + } + + public function rowToXML() { + $downloadcmd = $this->downloadCmd(); + + $this->out = << + $this->name + $this->repo\n +EOD; + + if ($this->type == "httpup") { + $files = $this->filesToXML(); + $this->out .= << + $files + \n +EOD; + } + + $this->out .= <<$downloadcmd + \n +EOD; + + return $this->out; + } } ?> diff --git a/portdb/portdb/includes/repo.inc.php b/portdb/portdb/includes/repo.inc.php index c8595d3..b2c9ee8 100644 --- a/portdb/portdb/includes/repo.inc.php +++ b/portdb/portdb/includes/repo.inc.php @@ -63,6 +63,21 @@ EOD; return $this->out; } + public function rowToXML() { + $maintainer = $this->obfuscate($this->maintainer); + $this->out = << + $this->name + $maintainer + $this->type + $this->url + $this->numports + $this->pubkey + \n +EOD; + return $this->out; + } + public function getSyncFile() { $maintainer = $this->obfuscate($this->maintainer); $content = ''; diff --git a/portdb/portdb/index.php b/portdb/portdb/index.php index d440579..c231a6f 100644 --- a/portdb/portdb/index.php +++ b/portdb/portdb/index.php @@ -20,6 +20,10 @@ print file_get_contents('footer.html'); } + function xmlDocType() { + print "\n"; + } + function localrepo($name) { global $cruxver; @@ -40,6 +44,10 @@ if (isset($_GET['f'])) { $format = sanitize($_GET['f']); } else $format = null; if (isset($_GET['s'])) { $strict = sanitize($_GET['s']); } else $strict = null; + if ($format == "xml") { + header('Content-Type: application/xml'); + } + switch ($action) { case "repo": # individual repo index @@ -63,11 +71,27 @@ array_push($ports, $port); } - # header - printHeader(); + if ($format == "xml") { + # doctype + xmlDocType(); - # construct content/table - $out = <<rowToXML(); + } + + # end + $out .= "\n"; + + print($out); + } else { + # header + printHeader(); + + # construct content/table + $out = <<Ports in repository $port->repo (get sync file) @@ -81,21 +105,23 @@ \n EOD; - # add ports - foreach ($ports as $port) { - $out .= $port->rowToHTML(); - } + # add ports + foreach ($ports as $port) { + $out .= $port->rowToHTML(); + } - # end table - $out .= <<
EOD; - print $out; + print $out; + + # footer + printFooter(); + } - # footer - printFooter(); break; case "search": @@ -125,12 +151,28 @@ EOD; } } - # header - printHeader(); + if ($format == "xml") { + # doctype + xmlDocType(); - # construct content - $script_name = getenv("SCRIPT_NAME"); - $out = <<rowToXML(); + } + + # end + $out .= "\n"; + + print($out); + } else { + # header + printHeader(); + + # construct content + $script_name = getenv("SCRIPT_NAME"); + $out = <<Simple port search

Search for ports by name

@@ -140,11 +182,11 @@ EOD;
EOD; - # create table if a search was performed - if ($query != '') { + # create table if a search was performed + if ($query != '') { - # construct table - $out .= << @@ -157,22 +199,24 @@ EOD; \n EOD; - # add ports - foreach ($ports as $port) { - $out .= $port->rowToHTML(); - } + # add ports + foreach ($ports as $port) { + $out .= $port->rowToHTML(); + } - # end table - $out .= << EOD; + } + + print $out; + + # footer + printFooter(); } - print $out; - - # footer - printFooter(); break; case "dups": @@ -190,11 +234,26 @@ EOD; array_push($dups, $dup); } - # header - printHeader(); + if ($format == "xml") { + # doctype + xmlDocType(); + $out = "\n"; - # construct content/table - $out = <<rowToXML(); + } + + # end + $out .= "\n"; + + print($out); + } else { + # header + printHeader(); + + # construct content/table + $out = <<List of duplicate ports @@ -206,21 +265,22 @@ EOD; \n EOD; - # add duplicates - foreach ($dups as $dup) { - $out .= $dup->rowToHTML(); - } + # add duplicates + foreach ($dups as $dup) { + $out .= $dup->rowToHTML(); + } - # end table - $out .= <<
EOD; - print $out; + print $out; - # footer - printFooter(); + # footer + printFooter(); + } break; @@ -271,11 +331,27 @@ EOD; $rows = $db->doQuery($sql); $uniquecount = $rows[0]['uniquecount']; - # header - printHeader(); + if ($format == "xml") { + # doctype + xmlDocType(); - # construct content/table - $out = <<rowToXML(); + } + + # end + $out .= "\n"; + + print($out); + } else { + # header + printHeader(); + + # construct content/table + $out = <<Overview of available repositories @@ -291,13 +367,13 @@ EOD; \n EOD; - # add repos - foreach ($repos as $repo) { - $out .= $repo->rowToHTML(); - } + # add repos + foreach ($repos as $repo) { + $out .= $repo->rowToHTML(); + } - # add unique count - $out .= << @@ -305,16 +381,17 @@ EOD; \n EOD; - # end table - $out .= <<
$uniquecount (unique)
EOD; - print $out; + print $out; - # footer - printFooter(); + # footer + printFooter(); + } } ?>