An open API service indexing awesome lists of open source software.

https://github.com/alexprut/plg_system_structureddata

Joomla System Plugin for parsing the HTML markup and convert the data-* HTML5 attributes in Microdata or RDFa Lite 1.1 semantics.
https://github.com/alexprut/plg_system_structureddata

html joomla microdata php structureddata

Last synced: about 1 month ago
JSON representation

Joomla System Plugin for parsing the HTML markup and convert the data-* HTML5 attributes in Microdata or RDFa Lite 1.1 semantics.

Awesome Lists containing this project

README

        

StructuredData
==============
A Joomla ```3.2+``` system plugin (in the ```./lib``` folder is present the new proposed version of the [JMicrodata](https://github.com/joomla/joomla-cms/tree/master/libraries/joomla/microdata "JMicrodata") library).
Created during the Google Summer of Code 2014.

If you want to keep your views separated from the logic, ```plg_system_structureddata``` is system plugin for parsing the HTML markup and converting the ```data-*``` HTML5 attributes into the correctly formatted Microdata or RDFa Lite 1.1 semantics.

The ```data-*``` attributes are new in HTML5, they give us the ability to embed custom data attributes on all HTML elements. So if you disable the library output, the HTML will still be validated. The default suffix that the library will search for is ```data-sd```, where sd stands for structured data, but you can register more than one custom suffix.

Installation
============
[Download the last version of the plugin](https://github.com/alexprut/plg_system_structureddata/archive/master.zip "Download plg_system_structureddata") and install it. __Don't forget to publish this plugin!__

Usage
=====
Since the system plugin runs immediately before the final content is sent to the client, you can use the plugin syntax everywhere, including native and third-party extensions that allow HTML editing.

### Markup Syntax
##### setType
![ParserPlugin Syntax](https://alexprut.github.io/PHPStructuredData/images/parser-plugin-syntax-v1.3.0-setType.png)
The _type_ defines which schema is being used for the following markup. The Type must always have the first character Uppercase to be correctly interpreted. If the type is a valid schema, the global scope for the page from this point onwards is updated to this schema. The plugin will replace the data tag with ```itemscope itemtype='https://schema.org/Type'``` in case of Microdata semantics or ```vocab='https://schema.org' typeof='Type'``` in case of RDFa Lite 1.1 semantics.

###### Example:
```html


This is my article



```

This will be output using ```Microdata``` semantics as:
```html


This is my article



```
Or using ```RDFa``` semantics as:
```html

This is my article



```

##### Specifying generic item properties
![ParserPlugin Syntax](https://alexprut.github.io/PHPStructuredData/images/parser-plugin-syntax-v1.3.0-global.png)
Once a schema has been declared, the next step is to declare individual properties – explaining the content and giving it semantic meaning.

The _property_ must always have the first character as lowercase to be correctly interpreted. If the property is found to be part of the current schema, the plugin will replace the data tag with ```itemprop='property'``` in case of Microdata semantics or ```property='property'``` in case of RDFa Lite 1.1 semantics. If the property is not found to be a valid property of the active schema, it will be ignored and the next available property will be parsed.

###### Example:
```html


This is my article



```

This will be output using ```Microdata``` semantics as:
```html


This is my article



```
Or using ```RDFa``` semantics as:
```html

This is my article



```

##### Specifying schema—dependant item properties
![ParserPlugin Syntax](https://alexprut.github.io/PHPStructuredData/images/parser-plugin-syntax-v1.3.0-specialized.png)
Sometimes you may want to explicitly state a property which should only be used when a specific schema is active – for example, if the property has a specific property in one schema, which is called something different in another schema.

It is possible to achieve this by using a schema–dependant property. This works by using a combination between both _Type_ and _property_, separated by a full stop. In short, if the current global scope is equal to Type and the property is part of that Type, the plugin will replace the data tag with ```itemprop='property'``` in case of Microdata semantics or ```property='property'``` in case of RDFa Lite 1.1.

###### Example:
```html


This is my article


4



```

This will be output using ```Microdata``` semantics as:
```html


This is my article


4



```
Or using ```RDFa``` semantics as:
```html

This is my article


4



```

### Using multiple properties
![ParserPlugin Syntax](https://alexprut.github.io/PHPStructuredData/images/parser-plugin-syntax-v1.3.0.png)
It is possible, using a combination of these, to specify multiple properties including some which are specific for a schema and others which are generic. The order of the building blocks isn't significant and a white space is used as a separator.

###### Example:
```html


This is my article


4


Amazing dessert recipes



```

This will be output using ```Microdata``` semantics as:
```html


This is my article


4


Amazing dessert recipes



```
Or using ```RDFa``` semantics as:
```html

This is my article


4


Amazing dessert recipes



```

##### Nesting schemas
Sometimes it is necessary to nest schemas – for example if you want to describe a person when you have the Article schema open. This is possible using nested schemas. To use this, simply append the schema preceeded by a full stop, __after__ the property. Once you have finished using the nested schema, close the containing tag, and re-set the original schema.

###### Example:
```html


This is my article


4



John Doe



Cake



```

This will be output using ```Microdata``` semantics as:
```html


This is my article


4



John Doe



Cake



```
Or using ```RDFa``` semantics as:
```html

This is my article


4



John Doe



Cake"



```

##### The Algorithm:
1. First the parser checks for __setTypes__. If one or more matches are found then the current global scope will be updated with the first match. At this point if there are no specific or generic properties the algorithm will finish and replace the data tag with the specified scope. Otherwise continue to point 2.
2. The parser checks for __specific item properties__. If one or more valid matches are found, then the algorithm will finish and replace the data tag with the first match property. Otherwise go to point 3
3. The parser checks for __generic properties__. If one or more valid matches are found, then the algorithm will replace the data tag with the first property that is matched, and complete the algorithm.

Semantically marking up 'on the fly' within HTML editors
========================================================
To apply markup within articles simply use the data tag and the method explained above.
See below for an example.
![plg_system_structureddata content editor usage](https://alexprut.github.io/plg_system_structureddata/images/plg_system_structureddata-editor.png)

Incorporating into your extensions and templates
================================================
Let's suppose that somewhere in your code you need to add Microdata or RDFa semantics to the following HTML which is part of an article (_e.g._ ```$scope='Article';```).
```html




How to Tie a Reef Knot



Written by

John Doe



1 January 2014


Lorem ipsum dolor sit amet...


```
The ```Microdata``` output will be:
```html



How to Tie a Reef Knot



Written by

John Doe



1 January 2014


Lorem ipsum dolor sit amet...


```
The ```RDFa``` output will be:
```html



How to Tie a Reef Knot



Written by

John Doe



1 January 2014


Lorem ipsum dolor sit amet...


```
Instead, if you decide to change the current Type (_e.g._ ```$scope="Review";```).
The ```Microdata``` output will be:
```html



How to Tie a Reef Knot



Written by

John Doe



1 January 2014


Lorem ipsum dolor sit amet...


```
The ```RDFa``` output will be:
```html



How to Tie a Reef Knot



Written by

John Doe



1 January 2014


Lorem ipsum dolor sit amet...


```

License
-------
plg_system_structureddata is licensed under the GNU GPL v2 License – see the LICENSE file for details.