diff --git a/distroquery.php b/distroquery.php new file mode 100644 index 0000000..7d81b89 --- /dev/null +++ b/distroquery.php @@ -0,0 +1,100 @@ + + + +
+ +repositories]"; + + + $repo=get_query_var('repo'); + $package=get_query_var('package'); + $arch=get_query_var('arch'); + + if ($repo == "") { +// +// Repositories +// + echo "

Available repositories:

"; + $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 "". $repository["tag"] . ": " . $repository["description"] . "
"; + } + + } else if ($package == "") { +// +// Repository +// + echo "

List of packages:

"; + $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); +?> + +

" width="24" height="24"> +:

+ + + + + + + + + + + + + + +
Name:
Release: +
Architecture:
Group:
Description:
Size:
URL:" target=_blank>
Download:" target=_blank>
Sources:" target=_blank>
Brothers:". $brother . " "; + } ?> +
Provides: +
+ + + +
+ + diff --git a/functions.php b/functions.php index da35586..096b7de 100644 --- a/functions.php +++ b/functions.php @@ -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'; +} );