2
0
mirror of https://github.com/boostorg/website.git synced 2026-01-27 19:32:16 +00:00
Files
website/common/code/boost.php
Daniel James 48f05b1a47 Use html_encode that handles invalid UTF-8 everywhere
Trying to view documentation with an invalid path would cause an error when it
encoded the path in the 404 error page, so rather than fix that case, just use
a safer function everywhere. Although maybe should be a bit more cautious about
displaying user supplied text?
2018-02-09 17:21:53 +00:00

42 lines
1.2 KiB
PHP

<?php
/*
Copyright 2007 Redshift Software, Inc.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
*/
require_once(dirname(__FILE__) . '/boost_config.php');
class BoostWebsite {
static function array_get($array, $key, $default = null) {
return array_key_exists($key, $array) ? $array[$key] : $default;
}
}
if (defined('ENT_SUBSTITUTE')) {
function html_encode($text) {
return htmlentities($text, ENT_SUBSTITUTE, 'UTF-8');
}
} else {
function html_encode($text) {
if (!preg_match('//u', $text)) {
$text = preg_replace('/[\x80-\xFF]/', "\xef\xbf\xbd", $text);
}
return htmlentities($text, ENT_COMPAT, 'UTF-8');
}
}
class BoostException extends RuntimeException {}
spl_autoload_register(function($name) {
if (!preg_match('@^[A-Za-z0-9\\\\_]*$@', $name)) {
throw new BoostException("Invalid autoload name: {$name}");
}
$path = preg_replace('@([a-z])([A-Z])@', '$1_$2', $name);
$path = str_replace('\\', '/', $path);
$path = strtolower($path);
$file_path = __DIR__.'/'.$path.'.php';
if (is_file($file_path)) { require_once($file_path); }
});