wordpress-theme-openmamba/distroquery.php

101 lines
3.3 KiB
PHP

<?php
/**
* Distroquery API Template
*
*
* @file distroquery.php
* @package openmamba-theme
* @author Silvan Calarco
* @copyright 2024
* @license license.txt
* @version Release: 1.0
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) {
exit;
}
$url_prefix = home_url() . "/distroquery-api/";
?>
<?php get_header(); ?>
<div id="content-full" class="grid col-940">
<?php
echo "[<a href=\"" . $url_prefix . "\">repositories</a>]";
$repo=get_query_var('repo');
$package=get_query_var('package');
$arch=get_query_var('arch');
if ($repo == "") {
//
// Repositories
//
echo "<h3>Available repositories:</h3>";
$request = wp_remote_get('https://push.openmamba.org/openmamba/distroquery/api/v1/repositories');
$j = json_decode($request["body"],true);
foreach ($j as $repository) {
$repository_url = $url_prefix . $repository["tag"];
echo "<a href=\"" . $repository_url . "\">". $repository["tag"] . "</a>: " . $repository["description"] . "</br>";
}
} else if ($package == "") {
//
// Repository
//
echo "<h3>List of packages:</h3>";
$request = wp_remote_get('https://push.openmamba.org/openmamba/distroquery/api/v1/repository/' . $repo);
$j = json_decode($request["body"],true);
} else if ($package != "") {
//
// Package
//
$request = wp_remote_get('https://push.openmamba.org/openmamba/distroquery/api/v1/package/'. $repo . "/" . $package . "/" . $arch);
$j = json_decode($request["body"],true);
?>
<h2><img src="https://www.google.com/s2/favicons?domain=<?php echo $j["source"]["url"] ?>" width="24" height="24">
<?php echo $j["name"] ?>: <?php echo $j["summary"] ?></h2>
<table class="pkgpage" width="100%">
<tr><td width="15%">Name:</td><td><?php echo $j["name"] ?></td></tr>
<tr><td width="15%">Release:</td><td>
<?php if ($j["source"]["epoch"] != "0") echo $j["source"]["epoch"].":";
echo $j["source"]["version"]."-".$j["source"]["release"] ?></td></tr>
<tr><td width="15%">Architecture:</td><td><?php echo $j["arch"] ?></td></tr>
<tr><td width="15%">Group:</td><td><?php echo $j["group"] ?></td></tr>
<tr><td width="15%">Description:</td><td><?php echo $j["description"] ?></td></tr>
<tr><td width="15%">Size:</td><td><?php echo $j["size"] ?></td></tr>
<tr><td width="15%">URL:</td><td><a href="<?php echo $j["source"]["url"] ?>" target=_blank><?php echo $j["source"]["url"] ?></a></td></tr>
<tr><td width="15%">Download:</td><td><a href="<?php echo $j["download_url"] ?>" target=_blank><?php echo basename($j["download_url"]) ?></a></td></tr>
<tr><td width="15%">Sources:</td><td><a href="<?php echo $j["source"]["source_url"] ?>" target=_blank><?php echo $j["source"]["source_url"] ?></a></td></tr>
<tr><td width="15%">Brothers:</td><td><?php
foreach ($j["brothers"] as $brother) {
$brother_url = $url_prefix . $repo . "/" . $brother . "/" . $arch;
echo "<a href=\"". $brother_url . "\">". $brother . "</a> ";
} ?>
</td></tr>
<tr><td width="15%">Provides:</td><td><?php
foreach ($j["provides"] as $provide) {
echo $provide["name"];
if ($provide["flags"] != "") echo "[" . $provide["flags"] . $provide["version"] . "]";
echo " ";
} ?>
</td></tr>
</table>
<?php
}
?>
</div><!-- end of #content-full -->
<?php get_footer(); ?>