distroquery: suppport for pagination of repository packages list
This commit is contained in:
parent
6062c4ab7d
commit
7e451f7cbb
@ -53,7 +53,9 @@ $url_prefix = home_url() . "/rpms/";
|
||||
//
|
||||
echo " > <a href=\"" . $url_prefix . "\">Repositories</a>";
|
||||
|
||||
$request = wp_remote_get('https://push.openmamba.org/openmamba/distroquery/api/v1/repository/' . $repo);
|
||||
$page = $_GET['page'];
|
||||
if ($page != "") $query_string="?page=" . $page;
|
||||
$request = wp_remote_get('https://push.openmamba.org/openmamba/distroquery/api/v1/repository/' . $repo . $query_string);
|
||||
$j = json_decode($request["body"], true);
|
||||
|
||||
if ($j["error"] != "") {
|
||||
@ -63,7 +65,41 @@ $url_prefix = home_url() . "/rpms/";
|
||||
echo " > " . $repo;
|
||||
echo "<h1>" . _r("List of packages") . ":</h1>";
|
||||
|
||||
foreach ($j as $package) {
|
||||
// Pagination
|
||||
if ($j["query"]["pages"]) {
|
||||
$page = $j["query"]["page"];
|
||||
$pages = $j["query"]["pages"];
|
||||
$from_page = 1;
|
||||
if ($page > 10) $from_page = $page - 10;
|
||||
$to_page = $from_page + 20;
|
||||
if ($to_page > $pages) {
|
||||
$to_page = $pages;
|
||||
$from_page = $to_page - 20;
|
||||
if ($from_page < 1) $from_page = 1;
|
||||
}
|
||||
echo _r("Page") . " " . $page . " " . _r("of") . " " . $pages . " [ ";
|
||||
if ($from_page > 1) {
|
||||
$back_page = $from_page - 10;
|
||||
if ($back_page < 1) $back_page = 1;
|
||||
echo "<a href=\"" . $url_prefix . "/" . $repo . "?page=" . $back_page . "\"><</a> ";
|
||||
}
|
||||
for ($i = $from_page; $i <= $to_page; $i++) {
|
||||
if ($i != $j["query"]["page"]) {
|
||||
echo "<a href=\"" . $url_prefix . "/" . $repo . "?page=" . $i . "\">" . $i . "</a> ";
|
||||
} else {
|
||||
echo "<strong>" . $i . "</strong> ";
|
||||
}
|
||||
}
|
||||
if ($to_page < $pages) {
|
||||
$next_page = $to_page + 10;
|
||||
if ($next_page > $pages) $next_page = $pages;
|
||||
if ($next_page < 1) $next_page = 1;
|
||||
echo "<a href=\"" . $url_prefix . "/" . $repo . "?page=" . $next_page . "\">></a> ";
|
||||
}
|
||||
echo "]</br></br>";
|
||||
}
|
||||
|
||||
foreach ($j["packages"] as $package) {
|
||||
$package_url = $url_prefix . $repo . "/" . $package["name"];
|
||||
echo "<a href=\"" . $package_url . "\">". $package["name"] . "</a>: " . $package["summary"] . "</br>";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user