functions.php,distroquery.php: initial implementation of distroquery API frontend
This commit is contained in:
parent
9b11a6c62f
commit
c2985c53f7
100
distroquery.php
Normal file
100
distroquery.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?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(); ?>
|
@ -482,3 +482,32 @@ function rew_unset_no_js($classes) {
|
||||
}
|
||||
return $classes ;
|
||||
}
|
||||
|
||||
// Distroquery API management
|
||||
add_filter( 'query_vars', function( $query_vars ) {
|
||||
$query_vars[] = 'distroquery';
|
||||
$query_vars[] = 'repo';
|
||||
$query_vars[] = 'package';
|
||||
$query_vars[] = 'arch';
|
||||
return $query_vars;
|
||||
} );
|
||||
|
||||
function distroquery_api_rewrite_rules ( ) {
|
||||
add_rewrite_rule ( '^distroquery-api/([^/]*)/([^/]*)/([^/]*)/?',
|
||||
'index.php?distroquery=1&repo=$matches[1]&package=$matches[2]&arch=$matches[3]','top' );
|
||||
add_rewrite_rule ( '^distroquery-api/([^/]*)/([^/]*)/?',
|
||||
'index.php?distroquery=1&repo=$matches[1]&package=$matches[2]','top' );
|
||||
add_rewrite_rule ( '^distroquery-api/([^/]*)/?',
|
||||
'index.php?distroquery=1&repo=$matches[1]','top' );
|
||||
add_rewrite_rule ( '^distroquery-api/?',
|
||||
'index.php?distroquery=1','top' );
|
||||
}
|
||||
add_action ( 'init', 'distroquery_api_rewrite_rules', 10, 0 ) ;
|
||||
|
||||
add_filter( 'template_include', function( $template ) {
|
||||
if ( get_query_var( 'distroquery' ) == false || get_query_var( 'distroquery' ) == '' ) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
return get_theme_file_path() . '/distroquery.php';
|
||||
} );
|
||||
|
Loading…
Reference in New Issue
Block a user