joomla/joomla-cms — pull request #2302 by haydenyoung (2013-10-21 12:48:43+00:00)
Title: Microdata library objects.

Submission of an alternative to the current JMicrodata library class.

This is a rewrite of the microdata functionality in Joomla 3.2 and addresses many of the shortcomings of the current implementation. Additionally, the classes better fit Joomla's separation of presentation and application functionality by providing JHTML functionality within the CMS and adding the core microdata classes to the Joomla lib.

The Schema class sets up a named schema from which sub-schemas and snippets can be created.

The Snippet class builds a snippet and addresses many of the shortcomings of the current JMicrodata class. Features such as multiple properties and the ability to add snippets to any HTML element tag are some of the improvements. The Snippet class also does away with the typed schema allowing for any type of microdata to be handled. The functions also simplify the construction of these snippets.

JHtmlMicrodata provides a quick method to build snippets and scopes using the existing JHtml::_() feature rather than the current HTML* methods which work against Joomla's architecture.

My preference would have been to include unit tests but I was unable to run unit tests using Joomla 3.2 and PHPUnit (various errors resulted in my abandoning unit tests for now).

Simple examples:

// use the Microdata lib.
$mdarticle = new JMicrodataSchema('http://schema.org/Article');
echo $mdarticle->getSnippet()->scope(true)->properties(array('name','headline'))->meta();
echo $mdarticle->getSnippet()->properties('author')->content('Hayden Young')->itemref('test')->html('h1');

// Use JHTML::_();
echo JHtml::_('microdata.snippet', 'div', 'author', 'Hayden Young', array('class'=>'pull-right'));
echo JHtml::_('microdata.scope', 'h2', 'http://schema.org/Person', 'author', 'Hayden Young');