Skip to content

Commit

Permalink
0.9.9
Browse files Browse the repository at this point in the history
pre Release
  • Loading branch information
Karel Wintersky committed Jun 28, 2024
1 parent cd8d74d commit 0a97ba5
Show file tree
Hide file tree
Showing 54 changed files with 2,473 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
* text=auto
* eol=lf

tests export-ignore
vendor export-ignore
docs export-ignore

.git export-ignore
.gitattributes export-ignore
.gitignore export-ignore

makefile export-ignore

phpunit.xml export-ignore
.php-cs-fixer.php export-ignore

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
composer.lock
.idea*
11 changes: 11 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The BSD 2-Clause License
Copyright (c) 2015-2020, Daniel Stainback <[email protected]>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
261 changes: 259 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,259 @@
# json-ld-generator
JSON-LD Generator
# JSON-LD Generator

Extremely simple JSON-LD generator.

AJUR Media fork, compatible with PHP7.4 & PHP 8.*

Original code:
- [JSON-LD Generator on Packagist](https://packagist.org/packages/torann/json-ld)
- [JSON-LD Generator on GitHub](https://github.com/Torann/json-ld)

## Installation

From the command line run

```
$ composer require ajur-media/json-ld-generator
```

## Methods

**/Context.php**

- `create($context, array $data = [])`
- `getProperties()`
- `generate($flags)`

## Context Types

- article
- audiobook
- beach
- blog_posting
- book
- breadcrumb_list
- contact_point
- corporation
- creative_work
- duration
- event
- geo_coordinates
- image_object
- invoice
- list_item
- local_business
- media_object
- music_album
- music_group
- music_playlist
- music_recording
- news_article
- offer
- order
- organization
- person
- place
- postal_address
- price_specification
- product
- rating
- recipe
- review
- sculpture
- search_box
- thing
- video_object
- web_page
- web_site

## Examples

### Quick Example

#### Business

```php
$context = \AJUR\Toolkit\JsonLd\Context::create('local_business', [
'name' => 'Consectetur Adipiscing',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor',
'telephone' => '555-555-5555',
'openingHours' => 'mon,tue,fri',
'address' => [
'streetAddress' => '112 Apple St.',
'addressLocality' => 'Hamden',
'addressRegion' => 'CT',
'postalCode' => '06514',
],
'geo' => [
'latitude' => '41.3958333',
'longitude' => '-72.8972222',
],
]);

echo $context; // Will output the script tag
```

### News Article

```php
$context = \JsonLd\Context::create('news_article', [
'headline' => 'Article headline',
'description' => 'A most wonderful article',
'mainEntityOfPage' => [
'url' => 'https://google.com/article',
],
'image' => [
'url' => 'https://google.com/thumbnail1.jpg',
'height' => 800,
'width' => 800,
],
'datePublished' => '2015-02-05T08:00:00+08:00',
'dateModified' => '2015-02-05T09:20:00+08:00',
'author' => [
'name' => 'John Doe',
],
'publisher' => [
'name' => 'Google',
'logo' => [
'url' => 'https://google.com/logo.jpg',
'width' => 600,
'height' => 60,
]
],
]);

echo $context; // Will output the script tag
```

## Custom Context Type

The first argument for the `create($context, array $data = [])` method also accepts class names. This is helpful for custom context types.

```php
<?php

namespace App\JsonLd;

use JsonLd\ContextTypes\AbstractContext;

class FooBar extends AbstractContext
{
/**
* Property structure
*
* @var array
*/
protected $structure = [
'name' => null,
'description' => null,
'image' => null,
'url' => null,
];
}
```

```php
$context = \JsonLd\Context::create(\App\JsonLd\FooBar::class, [
'name' => 'Foo Foo headline',
'description' => 'Bar bar article description',
'url' => 'http://google.com',
]);

echo $context; // Will output the script tag
```

## Breadcrumbs

Breadcrumb trails on a page indicate the page's position in the site hierarchy. A user can navigate all the way up in the site
hierarchy, one level at a time, by starting from the last breadcrumb in the breadcrumb trail.

### Example

```php
$context = \JsonLd\Context::create('breadcrumb_list', [
'itemListElement' => [
[
'url' => 'https://example.com/arts',
'name' => 'Arts',
],
[
'url' => 'https://example.com/arts/books',
'name' => 'Books',
],
[
'url' => 'https://example.com/arts/books/poetry',
'name' => 'Poetry',
],
]
]);
```

**Output**

```javascript
<script type="application/ld+json">
{
"@context": "http:\/\/schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"item": {
"@id": "https:\/\/example.com\/arts",
"name": "Arts"
}
},
{
"@type": "ListItem",
"position": 2,
"item": {
"@id": "https:\/\/example.com\/arts\/books",
"name": "Books"
}
},
{
"@type": "ListItem",
"position": 3,
"item": {
"@id": "https:\/\/example.com\/arts\/books\/poetry",
"name": "Poetry"
}
}
]
}
</script>
```

## Search Box

With Google Sitelinks search box, from search results. Search users sometimes use navigational queries, typing in the brand name or URL of a known site or app, only to do a more detailed search once they reach their destination. For example, users searching for pizza pins on Pinterest would type Pinterest or pinterest.com into Google Search--either from the Google App or from their web browser--then load the site or Android app, and finally search for pizza.

### Example

```php
$context = \JsonLd\Context::create('search_box', [
'url' => 'https://www.example.com/',
'potentialAction' => [
'target' => 'https://query.example.com/search?q={search_term_string}',
'query-input' => 'required name=search_term_string',
],
]);
```

**Output**

```javascript
<script type="application/ld+json">
{
"@context": "http:\/\/schema.org",
"@type": "WebSite",
"url": "https:\/\/www.example.com\/",
"potentialAction": {
"@type": "SearchAction",
"target": "https:\/\/query.example.com\/search?q={search_term_string}",
"query-input": "required name=search_term_string"
}
}
</script>
```
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "ajur-media/json-ld-generator",
"description": "Extremely simple JSON-LD markup generator (AJUR Media fork)",
"keywords": ["json-ld", "generator", "schema", "structured-data"],
"license": "BSD-2-Clause",
"authors": [
{
"name": "Daniel Stainback",
"email": "[email protected]"
},
{
"name": "Karel Wintersky",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.4 | 8.*",
"ext-json": "*",
"ext-mbstring": "*"
},
"autoload": {
"psr-4": {
"AJUR\\Toolkit\\JsonLd\\": "src/"
}
}
}
Loading

0 comments on commit 0a97ba5

Please sign in to comment.