From e182ba0c42a9d2b2afecb8da32d00f634999935e Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 7 Oct 2016 21:52:07 +0200 Subject: Add clone hints to 404 error pages When clicking on the linked Git clone URL of a package base, users are faced with a 404 error page since the URL is not supposed to be opened in a web browser. Add some notes to 404 error pages corresponding to Git clone URLs that explain how to use them instead. Fixes FS#51266. Signed-off-by: Lukas Fleischer --- web/html/404.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/web/html/404.php b/web/html/404.php index a47ae1e..757c485 100644 --- a/web/html/404.php +++ b/web/html/404.php @@ -2,12 +2,45 @@ set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); +$path = $_SERVER['PATH_INFO']; +$tokens = explode('/', $path); + +if (preg_match('/^([a-z0-9][a-z0-9.+_-]*?)(\.git)?$/', $tokens[1], $matches)) { + $gitpkg = $matches[1]; + if (pkg_from_name($gitpkg)) { + $gitcmd = 'git clone ' . sprintf(config_get('options', 'git_clone_uri_anon'), htmlspecialchars($gitpkg)); + $gitlink = get_pkgbase_uri($gitpkg); + } else { + unset($gitpkg); + } +} else { + unset($gitpkg); +} + html_header( __("Page Not Found") ); ?>

404 -

+ +
    +
  • + : + +
  • +
  • + ' . htmlspecialchars($gitpkg) . '', + '' . htmlspecialchars($gitcmd) . '') ?> +
  • +
  • + ', '', + '' . htmlspecialchars($gitpkg) . '') ?> +
  • +
+