Files
selima-perl/lib/php/monica/validate.inc.php
2026-03-10 21:31:43 +08:00

153 lines
5.4 KiB
PHP

<?php
// File name: validate.inc.php
// Description: PHP subroutines to display the HTML validator buttons
// Date: 2004-06-17
// Author: imacat <imacat@pristine.com.tw>
// Copyright: Copyright (C) 2004-2007 Pristine Communications
// Set the include path
if (!defined("INCPATH_SET")) {
require_once dirname(__FILE__) . "/incpath.inc.php";
}
// Referenced subroutines
require_once "monica/addget.inc.php";
require_once "monica/cgiemu.inc.php";
require_once "monica/gettext.inc.php";
require_once "monica/htmlchar.inc.php";
require_once "monica/https.inc.php";
require_once "monica/ipv4addr.inc.php";
require_once "monica/pagefunc.inc.php";
require_once "monica/requri.inc.php";
// html_validator: Print the HTML validator buttons
function html_validator($args = null)
{
// Obtain page parameters
$args = page_param($args);
// This is only for the preview and development website
if ( !(!is_null($args["preview"])
|| (defined("IS_PROD") && !IS_PROD))) {
return;
}
// Non-static or preview pages - use the validator in the client network
if (!$args["static"] || !is_null($args["preview"])) {
// The client is in the Pristine Network
if ( ipv4_in_network("172.16.168.0/24", $_SERVER["REMOTE_ADDR"])
|| ipv4_in_network("211.78.169.160/29", $_SERVER["REMOTE_ADDR"])) {
$html_validator = "html-validator.pristine.com.tw";
// The client is in imacat's Network
} elseif ( ipv4_in_network("10.0.0.0/24", $_SERVER["REMOTE_ADDR"])
|| ipv4_in_network("211.20.30.96/29", $_SERVER["REMOTE_ADDR"])) {
$html_validator = "html-validator.imacat.idv.tw";
// Elsewhere
} else {
$html_validator = "validator.w3.org";
}
// Static pages on the development site - use the validator in the server network
} elseif (defined("IS_PROD") && !IS_PROD) {
// The server is in the Pristine Network
if ( ipv4_in_network("172.16.168.0/24", $_SERVER["SERVER_ADDR"])
|| ipv4_in_network("211.78.169.160/29", $_SERVER["SERVER_ADDR"])) {
$html_validator = "html-validator.pristine.com.tw";
// The server is in imacat's Network
} elseif ( ipv4_in_network("10.0.0.0/24", $_SERVER["SERVER_ADDR"])
|| ipv4_in_network("211.20.30.96/29", $_SERVER["SERVER_ADDR"])) {
$html_validator = "html-validator.imacat.idv.tw";
// Elsewhere
} else {
$html_validator = "validator.w3.org";
}
}
// Set the picture host to our same host
$pic_host = REQUEST_SCHEME . "://" . REQUEST_HOST;
if (is_https()) {
if ($_SERVER["SERVER_PORT"] != 443) {
$pic_host .= ":" . $_SERVER["SERVER_PORT"];
}
} else {
if ($_SERVER["SERVER_PORT"] != 80) {
$pic_host .= ":" . $_SERVER["SERVER_PORT"];
}
}
// The HTML version
$htmlver = "XHTML 1.1";
if (defined("HTML_VERSION")) {
$htmlver = HTML_VERSION;
}
switch ($htmlver) {
// Default to XHTML 1.1
case "XHTML 1.1":
default:
$htmlbut = "http://$html_validator/images/vxhtml10";
$htmlver = "XHTML 1.1";
break;
case "XHTML 1.1":
$htmlbut = "http://$html_validator/images/vxhtml11";
break;
case "HTML 4.01":
$htmlbut = "http://$html_validator/images/vh401";
break;
case "HTML 4.0":
$htmlbut = "http://$html_validator/images/vh40";
break;
case "HTML 3.2":
$htmlbut = "http://$html_validator/images/vh32";
break;
case "HTML 3.0":
$htmlbut = "http://$html_validator/images/vh30";
break;
case "HTML 2.0":
$htmlbut = "http://$html_validator/images/vh20";
break;
}
if ($args["static"] && is_null($args["preview"])) {
$hvurl = "http://$html_validator/check/referer";
} else {
$url = REQUEST_FULLURI;
if (isset($_SESSION)) {
$url = add_get_arg($url, session_name(), session_id());
}
$hvurl = "http://$html_validator/check?uri=" . urlencode($url);
}
$areatitle = C_("HTML Validatior Logo Area");
$vhtmltitle = C_("HTML validation result of this page");
$vhtmlalt = sprintf(C_("Valid %s!"), $htmlver);
$vcsstitle = C_("CSS validation result of this page");
$vcssalt = C_("Valid CSS!");
$wcag1title = C_("Explanation of Level Triple-A Conformance");
$wcag1alt = C_("Level Triple-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0");
?><address class="validator" title="<?php echo h($areatitle); ?>">
<a href="<?php echo h($hvurl); ?>"
title="<?php echo h($vhtmltitle); ?>"<?php
if ($args["lang"] != "en") {
?> hreflang="en"<?php
} ?>><img
src="<?php echo h($htmlbut); ?>"
alt="<?php echo h($vhtmlalt); ?>" /></a>|<a
href="http://jigsaw.w3.org/css-validator/check/referer"
title="<?php echo h($vcsstitle); ?>"<?php
if ($args["lang"] != "en") {
?> hreflang="en"<?php
} ?>><img
src="<?php echo h($pic_host); ?>/images/w3c/vcss"
alt="<?php echo h($vcssalt); ?>" /></a>|<a
href="http://www.w3.org/WAI/WCAG1AAA-Conformance"
title="<?php echo h($wcag1title); ?>"<?php
if ($args["lang"] != "en") {
?> hreflang="en"<?php
} ?>><img
src="<?php echo h($pic_host); ?>/images/w3c/wcag1AAA"
alt="<?php echo h($wcag1alt); ?>" /></a>
</address>
<?php
return;
}
?>