The Joomla! Community Magazine™

What about Microdata in Joomla?

Written by | Tuesday, 01 October 2013 00:00 | Published in 2013 October
A couple of months ago I wrote an article about my Google Summer of Code project, which aimed to add microdata semantics in the Joomla CMS. Now lets take a closer look at the status of this project to see what has been done.
Microdata Semantics in Joomla Microdata Semantics in Joomla Alexandru Pruteanu

Here you can find my previous article in the Joomla Magazine about my Google Summer of Code project: Improve Joomla! Frontend Semantics & Accessibility

If you are not familiar with microdata please see this quick one minute video: https://www.youtube.com/watch?v=A-kX0Aut-18

Project status

This type of project involved considerable research with web standards and continuous testing to maintain valid HTML. The microdata library also needs to be flexible, fast, light, and easy-intuitive to use for developers. So I must admit that the library changed more than once the design architecture, in order to maintain the previous listed properties.

So, after a month of research and testing the library was finally merged in the Joomla CMS master branch, which you will be able to use from the next Joomla 3.2 version. If you are a developer you can use that library to implement microdata semantics in your extensions.

If you want to take a closer look, here you can find the library: libraries/joomla/microdata

How to use the JMicrodata library?

To use the new microdata semantics library you need to make an instance of the library in your extensions.

EXAMPLE:

		$microdata = new JMicrodata('Article');
	

So let's suppose that we have the following string:

		Written by Alexandru Pruteanu
	

And we need to add an author property:

		echo 'Written by' . $microdata->content(“Alexandru Pruteanu”)->property('author')->fallback('Person', 'name')->display();
	

The library will display:

		Written by
		<span itemprop='author' itemscope itemtype='https://schema.org/Person'>
			<span itemprop='name'>
				Alexandru Pruteanu
			</span>
		</span>
	

What happens if the current scope is something other than 'Article', for example a 'Product' scope, and the current scope doesn't have an author property?
Well it will fall back in:

		<span itemscope itemtype='https://schema.org/Person'>
			<span itemprop='name'>
				Alexandru Pruteanu
			</span>
		</span>		
	

If we want to disable the microdata semantics output?
You can simply disable the microdata output:

		$microdata->enable(false);
	

The library will display the following:

		Written by Alexandru Pruteanu
	

For further documentation please take a look at this Gist: https://gist.github.com/PAlexcom/6339949
Or just simply contact me, I'll surely talk with you ;)

What about the implementation in the Joomla CMS?

This is just a proposal that needs to be accepted, nothing of what is showed below is implemented yet in the official Joomla CMS versions.

While I'm telling you this I'm also working on the implementation in the CMS, there is already a pull request, but as it involves a lot of changes in the CMS it needs more testing.

Below you can find a live site with microdata semantics implemented: Joomla Live Site with Microdata Semantics

Here is what the Google Rich snippets tool can extract:

Google Rich Snippets Test Tool

Click here to make a live test, (refresh or press 'PREVIEW' if it doesn't work)

But how it's implemented in the Joomla CMS administration area?

You can enable/disable the microdata semantics from the Global Configuration.

EXAMPLE: Administration → Global Configuration → Site (tab) → SEO Setting

Microdata settings in Joomla Administration Global Configuration
You can enable/disable the microdata semantics output from the Article editing options, and also select the scope.

Microdata settings in com_content

What are the current issues?

Well, the biggest issue for the moment is that you can't switch from Microdata to RFDa or Microformats, but you can't even change the vocabulary. So we need a way to figure out how to make that possible.
At the time of this writing there is an issue with the necessity of having a JMicrodata global instance, otherwise everything will crash.

Conclusion

For me working with the Joomla Team/Developers and being part of the Google Summer of Code program has been an awesome and interesting experience. I've learned a lot and especially how an Open Source project is maintained and how people from different parts of the world work together. But even if the GSoC program has finished I would like to keep working on that project and also add new features. For any problems you might have with the library usage, any innovative ideas or if you want to give me a hand just let me know, I'm Alexandru Pruteanu and I'll be certainly glad to talk with you ;)

 

Read 18583 times
Tagged under Google Summer of Code, English
Alexandru Pruteanu

Alexandru Pruteanu

A young Web Engineer born in Moldavia who loves the web. Now, he is living in Italy where he studies Web Technologies & Multimedia at the University of Udine. He wakes up every day with the desire to learn something new and always tries to widen his knowledge. He is a happy Linux user, and a Open Source advocate. Currently he is working on several projects putting together experience, passion and creativity. His home page is http://p-alex.com or you can find him on Twitter (@PAlexcom).

avatar
I haven't test it yet, but regarding SEO this is major move!

Thank you for the great article!!!
VOTES:1
avatar
Great news for Joomla SEO.
Waiting for this project done.
Thanks for sharing.
VOTES:1
avatar
Just tested with my component and it works well - thanks for your work on this!

I'll need to implement this within separate functions for each of all my output types - so it would help performance a LOT if you could add a getInstance method to the class so that the types don't have to loaded each time I create a new class.
VOTES:1
avatar
Alexandru Pruteanu Sunday, 20 October 2013
Thanks for the advice Geraint,
I'll take a look at that and see how to solve that issue.
VOTES:0
avatar
I prefer to use JReviews extension for all my content which provides much easier solution for managing microdata.
VOTES:0
avatar
on joomla 32.2 last version today i dont find any microdatas settings in
Administration → Global Configuration → Site (tab) → SEO Setting
or articles options

where or how do you get these buttons ?

thank you
VOTES:1
avatar
Alexandru Pruteanu Sunday, 20 October 2013
Hi Erick Boileau,
The user interface implementation in the CMS is just a proposal that needs to be accepted, nothing of what is showed below is implemented yet in the official Joomla CMS versions.
I hope that from version 3.5 of Joomla the JMicrodata library will be implemented in the CMS.
You can find in Joomla 3.2 only the JMicrodata library that you can use to develop your extensions github.com/joomla/joomla-cms/tree/master...ies/joomla/microdata.
VOTES:1
avatar
thank you
VOTES:0
avatar
Very poor implementation. As with the canonical links in Joomla! (which cause more issues than without them).

Now currently, if you want to implement schema.org, you can do that with the html overrides. However, with your patch the system limits you to only specified data sets. Even if we add "recipe", which appears to be available, there is absolutely no way to attach fields for ingredients and so on. And as the whole Microdata is HTML, I clearly don't understand what this PHP is doing?!? Adding HTML? No, thanks.

The better approach would be to create a custom library that actually assigns Microdata to elements based on their class or id. And this to be rendered while Joomla! renders the HTML. That would be much broad solution with cross-extension usage.
VOTES:-1
avatar
Alexandru Pruteanu Tuesday, 05 November 2013
Hi Voltron, I really appreciate your feedback :)
First of all I would like to remember that for the moment there is anything yet implemented in the Joomla CMS, for the moment there is just the JMicrodata library in the Joomla libraries and a proposal was made with the implementation in the CMS that MUST BE APPROVED.

Why using php, and why not just adding simple html overrides?
Well, the problem with html overrides is that you can't change the scope of a page with just one click, you must make another override and also you can't disable the Microdata output with one toggle button.
So let's make an example that you create an article, and you decide that it should have a Review scope, but after one day you decide to change it in Movie scope, well you just change the scope from the article options and everything will work and the microdata semantic will be displayed properly.

Another reason is the fallback, let suppose you have that line of code:
$microdata->content(“Alexandru Pruteanu”)->property('author')->fallback('Person', 'name')->display();
If the current scope does't have the author property the Person semantic will not be lost, it will render:
Alexandru Pruteanu

If you have any other questions or feedback just post here or let me know.
I'm p-alex.com on skype, I'll surely be glad to talk with you :)
VOTES:0
avatar
Well, here is the case with our implementation.
In order to assign a property, I will still need to make an override. And I don't get what is the benefit?!? I don't see any. Honestly.

However, if the Microdata is loaded with your library when parsing the HTML and a developer can assign properties based on classes or ids.

So imagine that the library provides the hooks (well and probably some basic implementation in the core), but a third party developer can make a plugin that hooks to your library and makes much more.

My proposal is to change the logic to:
$microdata->content(".author")->property('author')->fallback('Person', 'name')->display();
Which will make:
Written by Alexandru Pruteanu
into:
Written by
 
 
Alexandru Pruteanu
 
 

I fairly think this is the better approach. Now imagine that you provide a plugin hook, where with 10 lines of code, anyone can define which class/id is what. This allows much more flexibility.
VOTES:0
avatar
Alexandru Pruteanu Friday, 15 November 2013
Sorry for the bad example, I've made an error.

So if you have:
$microdata->content(“Alexandru Pruteanu”)->property('author')->fallback('Person', 'name')->display();

If the current scope have the author property, it will render
Alexandru Pruteanu

If the current scope does't have the author property the Person semantic will not be lost, it will render
Alexandru Pruteanu

For more real examples you can take a look here to understand what PHP does: github.com/joomla/joomla-cms/blob/master...a/JMicrodataTest.php

I understand your proposal, but what happens if the HTML has more than one ".author" class? It will render both? And if the ".author" class has inside other nested HTML?
VOTES:0
avatar
Alexandru Pruteanu Saturday, 16 November 2013
A bad example again, don't know how to remove it, sorry (it's the code filter) -.-

So if you have:
$microdata->content(“Alexandru Pruteanu”)->property('author')->fallback('Person', 'name')->display();
If the current scope have the author property, it will render
Alexandru Pruteanu

If the current scope does't have the author property the Person semantic will not be lost, it will render
Alexandru Pruteanu
VOTES:0
avatar
Any idea why I can't enable microdata in SEO settings on Joomla 3.2 release? I've already cleared the cache.
VOTES:0
avatar
The article was informative. Thanks for sharing!
VOTES:0
avatar
I can see that microdata has the potential to radically evolve searching. I'm wondering if the scope of the category 'microdata type' is likely to increase to define more specific categories of page content?

And if the scope does increase are we likely to be reliant on native joomla functionality or is there a route for plugins to assist?
VOTES:0
avatar
Thanks for the update, I look forward to keeping up with this development. It will certainly be a major step forward in administering Joomla websites. Especially if we need to 'train' customers in updating and maintenance. Really appreciate the work you put in to this.
VOTES:0