<?php

function _list_pluck( $list, $field ) {
	foreach ( $list as $key => $value ) {
		if ( is_object( $value ) )
			$list[ $key ] = $value->$field;
		else
			$list[ $key ] = $value[ $field ];
	}

	return $list;
}

require 'tinymce-schemas.php';

$html4_attr = _list_pluck( (array) $html4, 'attributesOrder' );
$html5_attr = _list_pluck( (array) $html5, 'attributesOrder' );

$html4_children = _list_pluck( (array) $html4, 'children' );
$html5_children = _list_pluck( (array) $html5, 'children' );

foreach ( $html4_children as &$element ) {
	$element = array_keys( (array) $element );
}

foreach ( $html5_children as &$element ) {
	$element = array_keys( (array) $element );
}
unset( $element );

$html4_only = array_keys( array_diff_key( $html4_attr, $html5_attr ) );
$html5_only = array_keys( array_diff_key( $html5_attr, $html4_attr ) );

echo "THESE ELEMENTS WERE IN THE HTML4 SCHEMA AND ARE NOT IN HTML5\n\n";
echo implode( ", ", $html4_only );

echo "\n\n";

if ( false ) :

foreach ( $html4_attr as $element => $attributes ) {
	if ( in_array( $element, $html4_only ) )
		echo $element . '[' . implode( '|', $attributes ) . ']' . "\n";
}
foreach ( $html4_attr as $element => $attributes ) {
	if ( in_array( $element, array( 'table', 'tr', 'td', 'th', 'a', 'object', 'param', 'embed' ) ) )
		echo $element . '[' . implode( '|', $attributes ) . ']' . "\n";
}

endif;

echo "These elements are new to the HTML5 schema\n\n";
echo implode( ", ", $html5_only ) . "\n";

$shared_elements = array_keys( array_intersect_key( $html4_attr, $html5_attr ) );

$removed_in_html5 = array();
foreach ( $shared_elements as $element ) {
	if ( $removed = array_diff( $html4_attr[ $element ], $html5_attr[ $element ], array( 'xml:lang', 'lang' ) ) )
		$removed_in_html5[ $element ] = $removed;
}

echo "\n\nThese elements had attributes removed from html5:\n\n";

foreach ( $removed_in_html5 as $element => $attributes ) {
	echo "$element --- " . implode( ', ', $attributes ) . "\n";
}

$added_in_html5 = array();
foreach ( $shared_elements as $element ) {
	if ( $added = array_diff( $html5_attr[ $element ], $html4_attr[ $element ], array( 'accesskey', 'draggable', 'item', 'hidden', 'itemprop', 'role', 'spellcheck', 'subject' ) ) )
		$added_in_html5[ $element ] = $added;
}

echo "\n\nThese elements had attributes added in html5:\n\n";

foreach ( $added_in_html5 as $element => $attributes ) {
	echo "$element --- " . implode( ', ', $attributes ) . "\n";
}
