PHP 8.3 code fixes

This commit is contained in:
Silvan Calarco 2024-07-11 01:00:53 +02:00
parent e593a25368
commit ae6269ac58
4 changed files with 90 additions and 53 deletions

View File

@ -17,6 +17,9 @@ if ( !defined( 'ABSPATH' ) ) {
exit; exit;
} }
$api_url = "https://push.openmamba.org/openmamba/distroquery/api/v1/";
#$api_url = "https://openmamba.org/distroquery/api/v1/";
function human_filesize($bytes, $dec = 2): string { function human_filesize($bytes, $dec = 2): string {
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); $size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$factor = floor((strlen($bytes) - 1) / 3); $factor = floor((strlen($bytes) - 1) / 3);
@ -47,7 +50,12 @@ $url_prefix = home_url() . "/rpms/";
echo " > " . _r("Repositories"); echo " > " . _r("Repositories");
echo "<h1>" . _r("Available repositories") . ":</h1>"; echo "<h1>" . _r("Available repositories") . ":</h1>";
$request = wp_remote_get('https://push.openmamba.org/openmamba/distroquery/api/v1/repositories'); $request = wp_remote_get($api_url . "repositories");
if (is_wp_error($request)) {
echo "ERROR: " . $request->get_error_message();
goto finish;
}
$j = json_decode($request["body"], true); $j = json_decode($request["body"], true);
foreach ($j as $repository) { foreach ($j as $repository) {
$repository_url = $url_prefix . $repository["tag"]; $repository_url = $url_prefix . $repository["tag"];
@ -60,17 +68,22 @@ $url_prefix = home_url() . "/rpms/";
// //
echo " > <a href=\"" . $url_prefix . "\">Repositories</a>"; echo " > <a href=\"" . $url_prefix . "\">Repositories</a>";
$page = $_GET['page']; $page = isset($_GET['page'])?$_GET['page']:"";
$q = $_GET['q']; $q = isset($_GET['q'])?$_GET['q']:"";
$query_append = ""; $query_append = "";
if ($page != "") $query_append="&page=" . $page; if ($page != "") $query_append .="&page=" . $page;
if ($q != "") $query_append .= "&q=" . urlencode($q); if ($q != "") $query_append .= "&q=" . urlencode($q);
if ($query_append[0] == '&') $query_append[0] = "?"; if (strlen($query_append) > 0 && $query_append[0] == '&') $query_append[0] = "?";
$request = wp_remote_get($api_url . "repository/" . $repo . $query_append);
if (is_wp_error($request)) {
echo "ERROR: " . $request->get_error_message();
goto finish;
}
$request = wp_remote_get('https://push.openmamba.org/openmamba/distroquery/api/v1/repository/' . $repo . $query_append);
$j = json_decode($request["body"], true); $j = json_decode($request["body"], true);
if ($j["error"] != "") { if (isset($j["error"])) {
echo "<h5>ERROR: " . $j["error"] . "</h5>"; echo "<h5>ERROR: " . $j["error"] . "</h5>";
} else { } else {
@ -148,10 +161,15 @@ $url_prefix = home_url() . "/rpms/";
// //
echo " > <a href=\"" . $url_prefix . "\">" . _r("Repositories") . "</a>"; echo " > <a href=\"" . $url_prefix . "\">" . _r("Repositories") . "</a>";
$request = wp_remote_get('https://push.openmamba.org/openmamba/distroquery/api/v1/package/'. $repo . "/" . $package); $request = wp_remote_get($api_url . "package/" . $repo . "/" . $package);
if (is_wp_error($request)) {
echo "ERROR: " . $request->get_error_message();
goto finish;
}
$j = json_decode($request["body"], true); $j = json_decode($request["body"], true);
if ($j["error"] != "") { if (isset($j["error"])) {
echo "<h3>" . _r("ERROR") . ": " . $j["error"] . "</h3>"; echo "<h3>" . _r("ERROR") . ": " . $j["error"] . "</h3>";
} else { } else {
echo " > <a href=\"" . $url_prefix . "/" . $repo . "\">$repo</a> > " . $package; echo " > <a href=\"" . $url_prefix . "/" . $repo . "\">$repo</a> > " . $package;
@ -209,11 +227,13 @@ $url_prefix = home_url() . "/rpms/";
echo $buildrequire["name"]; echo $buildrequire["name"];
if ($buildrequire["flags"] != "") echo "[" . $buildrequire["flags"] . $buildrequire["version"] . "]"; if ($buildrequire["flags"] != "") echo "[" . $buildrequire["flags"] . $buildrequire["version"] . "]";
$cnt = 0; $cnt = 0;
if (isset($buildrequire["providers"]["archs"][$arch])) {
foreach ($buildrequire["providers"]["archs"][$arch] as $provider) { foreach ($buildrequire["providers"]["archs"][$arch] as $provider) {
$cnt++; $cnt++;
$provider_url = $url_prefix . $provider["repository"] . "/" . $provider["name"] . "/" . $arch; $provider_url = $url_prefix . $provider["repository"] . "/" . $provider["name"] . "/" . $arch;
echo " <a href=\"" . $provider_url . "\">[" . $cnt . "]</a>"; echo " <a href=\"" . $provider_url . "\">[" . $cnt . "]</a>";
} }
}
if ($cnt == 0) echo " (" . _r("unresolved") . ")"; if ($cnt == 0) echo " (" . _r("unresolved") . ")";
echo "<br/>"; echo "<br/>";
} }
@ -243,9 +263,14 @@ $url_prefix = home_url() . "/rpms/";
// //
echo " > <a href=\"" . $url_prefix . "\">" . _r("Repositories") . "</a>"; echo " > <a href=\"" . $url_prefix . "\">" . _r("Repositories") . "</a>";
$request = wp_remote_get('https://push.openmamba.org/openmamba/distroquery/api/v1/package/'. $repo . "/" . $package . "/" . $arch); $request = wp_remote_get($api_url . "package/" . $repo . "/" . $package . "/" . $arch);
if (is_wp_error($request)) {
echo "ERROR: " . $request->get_error_message();
goto finish;
}
$j = json_decode($request["body"],true); $j = json_decode($request["body"],true);
if ($j["error"] != "") { if (isset($j["error"])) {
echo "<h3>" . _r("ERROR") . ": " . $j["error"] . "</h3>"; echo "<h3>" . _r("ERROR") . ": " . $j["error"] . "</h3>";
} else { } else {
echo " > <a href=\"" . $url_prefix . "/" . $repo . "\">$repo</a> > " . $package . " (" . $arch . ")"; echo " > <a href=\"" . $url_prefix . "/" . $repo . "\">$repo</a> > " . $package . " (" . $arch . ")";
@ -287,42 +312,52 @@ $url_prefix = home_url() . "/rpms/";
_r("Brothers") . "</th><th>" . _r("Provides") . "</th><th>" . _r("Brothers") . "</th><th>" . _r("Provides") . "</th><th>" .
_r("Obsoletes") . "</th><th>" . _r("Requires") . "</th></tr>"; _r("Obsoletes") . "</th><th>" . _r("Requires") . "</th></tr>";
echo "<tr><td>"; echo "<tr><td>";
if (isset($j["brothers"])) {
foreach ($j["brothers"] as $brother) { foreach ($j["brothers"] as $brother) {
$brother_url = $url_prefix . $repo . "/" . $brother . "/" . $arch; $brother_url = $url_prefix . $repo . "/" . $brother . "/" . $arch;
echo "<a href=\"". $brother_url . "\">". $brother . "</a><br/>"; echo "<a href=\"". $brother_url . "\">". $brother . "</a><br/>";
} }
}
echo "</td><td>"; echo "</td><td>";
if (isset($j["provides"])) {
foreach ($j["provides"] as $provide) { foreach ($j["provides"] as $provide) {
echo $provide["name"]; echo $provide["name"];
if ($provide["flags"] != "") echo " " . $provide["flags"] . " " . $provide["version"]; if ($provide["flags"] != "") echo " " . $provide["flags"] . " " . $provide["version"];
echo "<br/>"; echo "<br/>";
} }
}
echo "</td><td>"; echo "</td><td>";
if (isset($j["obsoletes"])) {
foreach ($j["obsoletes"] as $obsolete) { foreach ($j["obsoletes"] as $obsolete) {
echo $obsolete["name"]; echo $obsolete["name"];
if ($obsolete["flags"] != "") echo " " . $obsolete["flags"] . " " . $obsolete["version"]; if ($obsolete["flags"] != "") echo " " . $obsolete["flags"] . " " . $obsolete["version"];
echo "<br/>"; echo "<br/>";
} }
}
echo "</td><td>"; echo "</td><td>";
if (isset($j["requires"])) {
foreach ($j["requires"] as $require) { foreach ($j["requires"] as $require) {
echo $require["name"]; echo $require["name"];
if ($require["flags"] != "") echo " " . $require["flags"] . " " . $require["version"]; if ($require["flags"] != "") echo " " . $require["flags"] . " " . $require["version"];
$cnt = 0; $cnt = 0;
if (isset($require["providers"])) {
foreach ($require["providers"] as $provider) { foreach ($require["providers"] as $provider) {
$cnt++; $cnt++;
$provider_url = $url_prefix . $provider["repository"] . "/" . $provider["name"] . "/" . $arch; $provider_url = $url_prefix . $provider["repository"] . "/" . $provider["name"] . "/" . $arch;
echo " <a href=\"" . $provider_url . "\">[" . $cnt . "]</a>"; echo " <a href=\"" . $provider_url . "\">[" . $cnt . "]</a>";
} }
}
if ($cnt == 0) echo " <font color=red>(" . _r("unresolved") . ")</font>"; if ($cnt == 0) echo " <font color=red>(" . _r("unresolved") . ")</font>";
echo "<br/>"; echo "<br/>";
} }
}
echo "</td></tr></table>"; echo "</td></tr></table>";
} }
} }
?> ?>
<?php finish: ?>
</span></div><!-- end of #content-full --> </span></div><!-- end of #content-full -->
<?php get_footer(); ?> <?php get_footer(); ?>

View File

@ -35,7 +35,7 @@ function add_custom_scripts() {
if($_SERVER['HTTPS']=='on') { if($_SERVER['HTTPS']=='on') {
$protocol='https:'; $protocol='https:';
} }
$output .= "<script type=\"text/javascript\" src=\"" . get_stylesheet_directory_uri() . "/scripts/jquery.cookiebar.js\"></script>\n"; //$output .= "<script type=\"text/javascript\" src=\"" . get_stylesheet_directory_uri() . "/scripts/jquery.cookiebar.js\"></script>\n";
wp_register_script('jquery', get_stylesheet_directory_uri() . "/scripts/jquery.min.js", false, '1.11.3'); wp_register_script('jquery', get_stylesheet_directory_uri() . "/scripts/jquery.min.js", false, '1.11.3');
wp_enqueue_script('jquery'); wp_enqueue_script('jquery');
$JQUERY_LOADED = true; $JQUERY_LOADED = true;
@ -69,21 +69,21 @@ function set_title($title) {
$urlargs = substr($_SERVER['REQUEST_URI'], $urlargspos + 1); $urlargs = substr($_SERVER['REQUEST_URI'], $urlargspos + 1);
parse_str($urlargs, $args); parse_str($urlargs, $args);
$newtitle = $title; $newtitle = $title;
if ($args['arch']) { if (array_key_exists('arch', $args)) {
if (preg_match('/^[a-zA-Z0-9._]*$/', $args['arch'])) { if (preg_match('/^[a-zA-Z0-9._]*$/', $args['arch'])) {
$newtitle = urlencode($args['arch']) . " - " . $newtitle; $newtitle = urlencode($args['arch']) . " - " . $newtitle;
} else { } else {
$newtitle = " Invalid request - " . $newtitle; $newtitle = " Invalid request - " . $newtitle;
} }
} }
if ($args['tag']) { if (array_key_exists('tag', $args)) {
if (preg_match('/^[a-zA-Z0-9._-]*$/', $args['tag'])) { if (preg_match('/^[a-zA-Z0-9._-]*$/', $args['tag'])) {
$newtitle = urlencode($args['tag']) . " - " . $newtitle; $newtitle = urlencode($args['tag']) . " - " . $newtitle;
} else { } else {
$newtitle = " Invalid request - " . $newtitle; $newtitle = " Invalid request - " . $newtitle;
} }
} }
if ($args['pkg']) { if (array_key_exists('pkg', $args)) {
if ($args['pkg'] == '_index') if ($args['pkg'] == '_index')
$newtitle = 'Index - ' . $newtitle; $newtitle = 'Index - ' . $newtitle;
else { else {
@ -149,7 +149,7 @@ function openmamba_infofile($mediaprefix, $milestone, $fallbackmilestone, $mediu
$script_file = "$mediaprefix/$fallbackmilestone/$medium/info/$filename.$outputlang.html.inc"; $script_file = "$mediaprefix/$fallbackmilestone/$medium/info/$filename.$outputlang.html.inc";
} }
$ret = ''; $ret = '';
if ($script_file) { if (isset($script_file)) {
$file = fopen($script_file, "r"); $file = fopen($script_file, "r");
while (!feof($file)) { while (!feof($file)) {
$b=fread($file,1024); $b=fread($file,1024);
@ -198,23 +198,23 @@ function openmamba_download_func( $atts ) {
$ret .= "<br><br>"; $ret .= "<br><br>";
if ($a['multilang']) { if ($a['multilang']) {
reset($archname); reset($archname);
while (list(, $currarch) = each($archname)) { foreach($archname as $ey => $currarch) {
if (strpos(";".$a['archs'].";",$currarch) == false) continue; if (strpos(";".$a['archs'].";",$currarch) == false) continue;
$ret .= openmamba_download_link($milestone,$medium,$currarch,$ext,$mlword,"en"); $ret .= openmamba_download_link($milestone,$medium,$currarch,$ext,$mlword,"en");
} }
} else { } else {
reset($archname); reset($archname);
$langs = array('it' => 'italiano','en' => 'english','es' => 'español'); $langs = array('it' => 'italiano','en' => 'english','es' => 'español');
while (list(, $currarch) = each($archname)) { foreach($archname as $ey => $currarch) {
if (strpos(";".$a['archs'].";",$currarch) == false) continue; if (strpos(";".$a['archs'].";",$currarch) == false) continue;
$ret .= openmamba_download_link($milestone,$medium,$currarch,$ext,$langs[$outputlang],$outputlang); $ret .= openmamba_download_link($milestone,$medium,$currarch,$ext,$langs[$outputlang],$outputlang);
} }
foreach ($langs as $l => $lang) { foreach ($langs as $l => $lang) {
if ($l == $outputlang) continue; if ($l == $outputlang) continue;
reset($archname); reset($archname);
while (list(, $currarch) = each($archname)) { foreach($archname as $ey => $currarch) {
if (strpos(";".$a['archs'].";",$currarch) == false) continue; if (strpos(";".$a['archs'].";",$currarch) == false) continue;
$out .= openmamba_download_link($milestone,$medium,$currarch,$ext,$lang,$l); $out = openmamba_download_link($milestone,$medium,$currarch,$ext,$lang,$l);
} }
} }
$ret .= do_shortcode("[expand title=\"". __("More languages...","responsive") . "\"]". $out ."[/expand]"); $ret .= do_shortcode("[expand title=\"". __("More languages...","responsive") . "\"]". $out ."[/expand]");

View File

@ -48,6 +48,8 @@ button, input, select, textarea {
.featured-title { .featured-title {
color: #59b237; color: #59b237;
margin-top:28px;
font-size:40px;
} }
.featured-subtitle { .featured-subtitle {

View File

@ -1,7 +1,7 @@
<?php <?php
if (!is_user_logged_in()) { if (!is_user_logged_in()) {
wp_redirect( wp_login_url( "http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI] )); wp_redirect( wp_login_url( "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"] ));
} }