Download the PHP package palex/phpstructureddata without Composer
On this page you can find all versions of the php package palex/phpstructureddata. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download palex/phpstructureddata
More information about palex/phpstructureddata
Files in palex/phpstructureddata
Package phpstructureddata
Short Description A set of PHP libraries that use the http://schema.org vocabulary to implement and output Microdata or RDFa Lite 1.1 semantics.
License MIT
Homepage https://github.com/PAlexcom/PHPStructuredData
Informations about the package phpstructureddata
PHPStructuredData 
A set of PHP libraries that use the http://schema.org vocabulary to implement and output Microdata or RDFa Lite 1.1 semantics.
This library is used in the Joomla CMS since version 3.2 (called JMicrodata).
Created during the Google Summer of Code 2013 and 2014.
Quick overview
The library was designed with this goals in mind:
- Having the possibility to switch between Microdata and RDFa Lite 1.1 semantics.
- Having the possibility to switch the Type dynamically, you just change the Type (there are more than 550+ different available Types).
- Display validated semantics, the library takes care of displaying data in the correct format (e.g. all the dates in the ISO standard).
- Enable/disable the library output.
- Fallbacks, you should never lose any meaningful semantic (e.g. if you change the Type and it does not have an author Property, it will fallback to the Person Type with the name Property).
Class diagram
Installation
-
Composer:
Add in your file: - From Source:
Run - Direct download:
Download the last version from here
Usage Example
Let's suppose that you already have an instance of the Microdata or RDFa library. And you need to add Microdata or RDFa semantics to the following HTML which is part of an article (e.g. ).
The library will render:
The library will render:
Instead, if you decide to change the current Type (e.g. ).
The library will render:
The library will render:
As you can see fallbacks to the Person Type, and there is no loss of information, even if the current Type doesn't have an author Property it will display important information for the machines, search engines know that there is a Person .
Instead, if you decide to not render Microdata or RDFa semantics, you just disable the library output (e.g. ).
Both and library will render:
Currently both and library doesn't support multiple fallbacks.
ParserPlugin
If you want to keep your views separated from the logic, is a PHP class for parsing the HTML markup and converting the HTML5 attributes into the correctly formatted Microdata or RDFa Lite 1.1 semantics.
The attributes are new in HTML5, they gives 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 the library will search for is , where sd stands for structured data, but you can register more than one custom suffix.
Markup Syntax
setType
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 in case of Microdata semantics or in case of RDFa Lite 1.1 semantics.
Example:
This will be output using semantics as:
Or using semantics as:
Specifying generic item properties
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 in case of Microdata semantics or 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:
This will be output using semantics as:
Or using semantics as:
Specifying schema—dependant item properties
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 in case of Microdata semantics or in case of RDFa Lite 1.1.
Example:
This will be output using semantics as:
Or using semantics as:
Using multiple properties
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:
This will be output using semantics as:
Or using semantics as:
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:
This will be output using semantics as:
Or using semantics as:
The Algorithm:
- 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.
- 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
- 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.
Usage Example
Let's suppose that you already have an instance of the library. And you need to add Microdata or RDFa semantics to the following HTML which is part of an article (e.g. ).
The output will be:
The output will be:
Instead, if you decide to change the current Type (e.g. ).
The output will be:
The output will be:
Documentation
libraries use the file to check and output validated semantics, that file contains all the available Types and Properties from the http://schema.org vocabulary, and it was generated automatically with the https://github.com/alexprut/Spider4Schema web crawler.
Todos
StructuredData
- Add support.
- Add multiple fallbacks support to .
- Add to the all the required properties specified by Google, Yandex, Baidu.
License
PHPStructuredData is licensed under the MIT License – see the LICENSE file for details.