Commit 67c299d2 authored by catch's avatar catch

Issue #1077566 by scor, karschsp, jessebeach: Convert html.tpl.php to HTML5.

parent 5b38f202
......@@ -248,26 +248,10 @@ function drupal_get_breadcrumb() {
return $breadcrumb;
}
/**
* Returns a string containing RDF namespace declarations for use in XML and
* XHTML output.
*/
function drupal_get_rdf_namespaces() {
$xml_rdf_namespaces = array();
// Serializes the RDF namespaces in XML namespace syntax.
if (function_exists('rdf_get_namespaces')) {
foreach (rdf_get_namespaces() as $prefix => $uri) {
$xml_rdf_namespaces[] = 'xmlns:' . $prefix . '="' . $uri . '"';
}
}
return count($xml_rdf_namespaces) ? "\n " . implode("\n ", $xml_rdf_namespaces) : '';
}
/**
* Add output to the head tag of the HTML page.
*
* This function can be called as long the headers aren't sent. Pass no
* This function can be called as long as the headers aren't sent. Pass no
* arguments (or NULL for both) to retrieve the currently stored elements.
*
* @param $data
......
......@@ -2359,13 +2359,14 @@ function template_preprocess_html(&$variables) {
$variables['classes_array'][] = drupal_html_class('node-type-' . $node->type);
}
// RDFa allows annotation of XHTML pages with RDF data, while GRDDL provides
// mechanisms for extraction of this RDF content via XSLT transformation
// using an associated GRDDL profile.
$variables['rdf_namespaces'] = drupal_get_rdf_namespaces();
$variables['grddl_profile'] = 'http://www.w3.org/1999/xhtml/vocab';
$variables['language'] = $GLOBALS['language'];
$variables['language']->dir = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
// Initializes attributes which are specific to the html and body elements.
$variables['html_attributes_array'] = array();
$variables['body_attributes_array'] = array();
// HTML element attributes.
$variables['html_attributes_array']['xmlns'] = "http://www.w3.org/1999/xhtml";
$variables['html_attributes_array']['xml:lang'] = $GLOBALS['language']->language;
$variables['html_attributes_array']['dir'] = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
// Add favicon.
if (theme_get_setting('toggle_favicon')) {
......@@ -2494,6 +2495,10 @@ function template_process_page(&$variables) {
* @see html.tpl.php
*/
function template_process_html(&$variables) {
// Flatten out html_attributes and body_attributes.
$variables['html_attributes'] = drupal_attributes($variables['html_attributes_array']);
$variables['body_attributes'] = drupal_attributes($variables['body_attributes_array']);
// Render page_top and page_bottom into top level variables.
$variables['page_top'] = drupal_render($variables['page']['page_top']);
$variables['page_bottom'] = drupal_render($variables['page']['page_bottom']);
......
......@@ -188,7 +188,7 @@ function number_field_formatter_info() {
'label' => t('Default'),
'field types' => array('number_integer'),
'settings' => array(
'thousand_separator' => ' ',
'thousand_separator' => '',
// The 'decimal_separator' and 'scale' settings are not configurable
// through the UI, and will therefore keep their default values. They
// are only present so that the 'number_integer' and 'number_decimal'
......@@ -202,7 +202,7 @@ function number_field_formatter_info() {
'label' => t('Default'),
'field types' => array('number_decimal', 'number_float'),
'settings' => array(
'thousand_separator' => ' ',
'thousand_separator' => '',
'decimal_separator' => '.',
'scale' => 2,
'prefix_suffix' => TRUE,
......
......@@ -460,6 +460,18 @@ function rdf_process(&$variables, $hook) {
}
}
/**
* Implements MODULE_preprocess_HOOK()
*/
function rdf_preprocess_html(&$variables) {
// Adds RDF namespace prefix bindings in the form of an RDFa 1.1 prefix
// attribute inside the html element.
$prefixes = array();
foreach(rdf_get_namespaces() as $prefix => $uri) {
$variables['html_attributes_array']['prefix'][] = $prefix . ': ' . $uri . "\n";
}
}
/**
* Implements MODULE_preprocess_HOOK().
*/
......
......@@ -713,3 +713,48 @@ class RdfGetRdfNamespacesTestCase extends DrupalWebTestCase {
$this->assertTrue(!isset($ns['dc']), t('A prefix with conflicting namespaces is discarded.'));
}
}
/**
* Tests for RDF namespaces XML serialization.
*/
class DrupalGetRdfNamespacesTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'RDF namespaces serialization test',
'description' => 'Confirm that the serialization of RDF namespaces in present in the HTML markup.',
'group' => 'RDF',
);
}
function setUp() {
parent::setUp('rdf', 'rdf_test');
}
/**
* Test RDF namespaces.
*/
function testGetRdfNamespaces() {
// Fetches the front page and extracts RDFa 1.1 prefixes.
$this->drupalGet('');
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array(
':prefix_binding' => 'rdfs: http://www.w3.org/2000/01/rdf-schema#',
));
$this->assertTrue(!empty($element), t('A prefix declared once is displayed.'));
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array(
':prefix_binding' => 'foaf: http://xmlns.com/foaf/0.1/',
));
$this->assertTrue(!empty($element), t('The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.'));
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array(
':prefix_binding' => 'foaf1: http://xmlns.com/foaf/0.1/',
));
$this->assertTrue(!empty($element), t('Two prefixes can be assigned the same namespace.'));
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array(
':prefix_binding' => 'dc: ',
));
$this->assertTrue(empty($element), t('A prefix with conflicting namespaces is discarded.'));
}
}
......@@ -2387,38 +2387,6 @@ class DrupalJSONTest extends DrupalUnitTestCase {
}
}
/**
* Tests for RDF namespaces XML serialization.
*/
class DrupalGetRdfNamespacesTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'RDF namespaces XML serialization tests',
'description' => 'Confirm that the serialization of RDF namespaces via drupal_get_rdf_namespaces() is output and parsed correctly in the XHTML document.',
'group' => 'System',
);
}
function setUp() {
parent::setUp('rdf', 'rdf_test');
}
/**
* Test RDF namespaces.
*/
function testGetRdfNamespaces() {
// Fetches the front page and extracts XML namespaces.
$this->drupalGet('');
$xml = new SimpleXMLElement($this->content);
$ns = $xml->getDocNamespaces();
$this->assertEqual($ns['rdfs'], 'http://www.w3.org/2000/01/rdf-schema#', t('A prefix declared once is displayed.'));
$this->assertEqual($ns['foaf'], 'http://xmlns.com/foaf/0.1/', t('The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.'));
$this->assertEqual($ns['foaf1'], 'http://xmlns.com/foaf/0.1/', t('Two prefixes can be assigned the same namespace.'));
$this->assertTrue(!isset($ns['dc']), t('A prefix with conflicting namespaces is discarded.'));
}
}
/**
* Basic tests for drupal_add_feed().
*/
......
......@@ -460,3 +460,31 @@ class ThemeHtmlTag extends DrupalUnitTestCase {
$this->assertEqual('<title>title test</title>'."\n", theme_html_tag($tag), t('Test title tag generation.'));
}
}
/**
* Functional test for attributes of html.tpl.php.
*/
class ThemeHtmlTplPhpAttributesTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'html.tpl.php html and body attributes',
'description' => 'Tests attributes inserted in the html and body elements of html.tpl.php.',
'group' => 'Theme',
);
}
function setUp() {
parent::setUp('theme_test');
}
/**
* Tests that modules and themes can alter variables in html.tpl.php.
*/
function testThemeHtmlTplPhpAttributes() {
$this->drupalGet('');
$attributes = $this->xpath('/html[@theme_test_html_attribute="theme test html attribute value"]');
$this->assertTrue(count($attributes) == 1, t('Attribute set in the html element via hook_preprocess_html() found.'));
$attributes = $this->xpath('/html/body[@theme_test_body_attribute="theme test body attribute value"]');
$this->assertTrue(count($attributes) == 1, t('Attribute set in the body element via hook_preprocess_html() found.'));
}
}
......@@ -127,3 +127,11 @@ function _theme_test_suggestion() {
function theme_test_preprocess_breadcrumb(&$variables) {
$variables['theme_test_preprocess_breadcrumb'] = 1;
}
/**
* Implements hook_preprocess_html().
*/
function theme_test_preprocess_html(&$variables) {
$variables['html_attributes_array']['theme_test_html_attribute'] = 'theme test html attribute value';
$variables['body_attributes_array']['theme_test_body_attribute'] = 'theme test body attribute value';
}
......@@ -9,7 +9,8 @@
* - $css: An array of CSS files for the current page.
* - $language: (object) The language the site is being displayed in.
* $language->language contains its textual representation.
* $language->dir contains the language direction. It will either be 'ltr' or 'rtl'.
* $language->dir contains the language direction.
* It will either be 'ltr' or 'rtl'.
* - $rdf_namespaces: All the RDF namespace prefixes used in the HTML document.
* - $grddl_profile: A GRDDL profile allowing agents to extract the RDF data.
* - $head_title: A modified version of the page title, for use in the TITLE
......@@ -40,22 +41,20 @@
* @see template_preprocess_html()
* @see template_process()
*/
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>"<?php print $rdf_namespaces; ?>>
<head profile="<?php print $grddl_profile; ?>">
<?php print $head; ?>
<title><?php print $head_title; ?></title>
<?php print $styles; ?>
<?php print $scripts; ?>
</head>
<body class="<?php print $classes; ?>" <?php print $attributes;?>>
<div id="skip-link">
<a href="#main-content" class="element-invisible element-focusable"><?php print t('Skip to main content'); ?></a>
</div>
<?php print $page_top; ?>
<?php print $page; ?>
<?php print $page_bottom; ?>
</body>
?><!DOCTYPE html>
<html<?php print $html_attributes; ?>>
<head>
<?php print $head; ?>
<title><?php print $head_title; ?></title>
<?php print $styles; ?>
<?php print $scripts; ?>
</head>
<body class="<?php print $classes; ?>" <?php print $body_attributes;?>>
<div id="skip-link">
<a href="#main-content" class="element-invisible element-focusable"><?php print t('Skip to main content'); ?></a>
</div>
<?php print $page_top; ?>
<?php print $page; ?>
<?php print $page_bottom; ?>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment