diff --git a/2019/template/header.php b/2019/template/header.php index 894ae87..9b26a22 100644 --- a/2019/template/header.php +++ b/2019/template/header.php @@ -1,150 +1,103 @@ . /* * This is the header of the website */ /* * Args that should be passed: * * $conference (object) Current conference * $intro (true|undefined) If true, you want that damn splash screen * $og (array) OG meta tags * $canonical (string) Canonical link tag */ // do not visit directly defined( 'ABSPATH' ) or exit; // canonical URL $canonical = isset( $canonical ) ? $canonical : null; // if the canonical is specified, and we have to force the permalink, force that damn permalink if( $canonical && FORCE_PERMALINK ) { force_permalink( $canonical ); } // as default declare empty OG Meta tags if( ! isset( $args['og'] ) ) { $args['og'] = []; } // set default OG Meta tags $args['og'] = array_replace( [ 'url' => $canonical, 'image' => CURRENT_CONFERENCE_URL . '/images/linux-day-2019.png', // It's better an absolute URL here 'type' => 'website', 'title' => $conference->getConferenceTitle(), ], $args['og'] ); - -// TODO: move the define somewhere else (per-year, not a global parameter for every site across all years) -define('DEFAULT_LANGUAGE_ISO', 'it'); - -// I assume that latest_language()->getISO() does not return different codes for the same language: -// e.g. it should return ONLY it_IT OR it, not "it_IT" some times and "it" some others -// this does not appear to be the case and it breaks everything completely. - -// l is either given in the request or implicit -$l = $_GET['l'] ?? latest_language()->getISO(); - -// From the manual: "This function may not give correct results for relative URLs." -// Then build a full URL! -$parsed = parse_url("https://${_SERVER['HTTP_HOST']}${_SERVER['REQUEST_URI']}"); -if(isset($parsed["query"])) { - parse_str($parsed["query"], $query); -} else { - $query = []; -} - -if($l === DEFAULT_LANGUAGE_ISO) { - // Remove the ugly l - if(isset($_GET['l'])) { - unset($query["l"]); - } - - // are there any remaining query parameters? - if(count($query) > 0) { - $query = '?' . http_build_query($query); - } else { - $query = ''; - } - - // l was there: redirect to page without l (or remove this "if" to get a canonical URL without l) - if(isset($_GET['l'])) { - // TODO: change to 301 when we're sure - header("Location: ${parsed['path']}$query", true, 302); - exit(0); - } -} else { - // Other languages need the l for the canonical URL - $query["l"] = $l; - $query = '?' . http_build_query($query); -} -$canonical = "https://${_SERVER['HTTP_HOST']}${parsed['path']}$query"; ?> <?= esc_html( $conference->getConferenceTitle() ) ?> "> - - $value ): ?> $conference, 'top_nav_collapse' => !isset( $intro ), ] ); if( isset( $intro ) ) { template( 'intro' ); }