|
| 1 | +# PHP Open-Graph |
| 2 | + |
| 3 | +[](https://packagist.org/packages/astrotomic/php-open-graph) |
| 4 | +[](https://github.com/Astrotomic/php-open-graph/blob/master/LICENSE) |
| 5 | +[](https://plant.treeware.earth/Astrotomic/php-open-graph) |
| 6 | + |
| 7 | +[](https://github.com/Astrotomic/php-open-graph/actions?query=workflow%3Arun-tests) |
| 8 | +[](https://styleci.io/repos/82821437) |
| 9 | +[](https://packagist.org/packages/astrotomic/php-open-graph) |
| 10 | + |
| 11 | +This package provides a fluent PHP OOP builder for [Open Graph protocol](https://ogp.me). |
| 12 | + |
1 | 13 | ## Installation |
2 | 14 |
|
3 | 15 | You can install the package via composer: |
4 | 16 |
|
5 | | -``` bash |
6 | | -composer require spatie/open-graph |
| 17 | +```bash |
| 18 | +composer require astrotomic/php-open-graph |
7 | 19 | ``` |
8 | 20 |
|
9 | | -## Getting started |
| 21 | +## Usage |
10 | 22 |
|
11 | | -### 1. Set HTML `prefix` attribute |
| 23 | +```php |
| 24 | +use Astrotomic\OpenGraph\OpenGraph; |
| 25 | +use Astrotomic\OpenGraph\StructuredProperties\Image; |
12 | 26 |
|
13 | | -Every Open Graph webpage needs to specify the following `prefix` attribute on the `<html>` tag: |
| 27 | +echo OpenGraph::website('Example') |
| 28 | + ->url('https://example.com') |
| 29 | + ->image('https://example.com/image1.jpg') |
| 30 | + ->image(Image::make('https://example.com/image1.jpg')->width(600)); |
| 31 | +``` |
14 | 32 |
|
15 | 33 | ```html |
16 | | -<html prefix="og: http://ogp.me/ns#"> |
| 34 | +<meta property="og:type" content="website"> |
| 35 | +<meta property="og:title" content="Example"> |
| 36 | +<meta property="og:url" content="https://example.com"> |
| 37 | +<meta property="og:image:url" content="https://example.com/image1.jpg"> |
| 38 | +<meta property="og:image:url" content="https://example.com/image1.jpg"> |
| 39 | +<meta property="og:image:width" content="600"> |
17 | 40 | ``` |
18 | 41 |
|
19 | | -### 2. Choose your Open Graph object type |
| 42 | +### Types |
20 | 43 |
|
21 | | -As specified in the [RDF schema](http://ogp.me/ns/ogp.me.ttl) every Open Graph object needs an `og:type` property. We've made it easy for you by providing classes for every Open Graph object you may want to generate. |
| 44 | +#### Global |
22 | 45 |
|
23 | | -| og:type | spatie/open-graph class | |
24 | | -|-----------------------|------------------------------| |
25 | | -| `website` | `OpenGraphWebsite` | |
26 | | -| `article` | `OpenGraphArticle` | |
27 | | -| `book` | `OpenGraphBook` | |
28 | | -| `profile` | `OpenGraphProfile` | |
29 | | -| `music.song` | `OpenGraphMusicSong` | |
30 | | -| `music.album` | `OpenGraphMusicAlbum` | |
31 | | -| `music.playlist` | `OpenGraphMusicPlaylist` | |
32 | | -| `music.radio_station` | `OpenGraphMusicRadioStation` | |
33 | | -| `video.movie` | `OpenGraphVideoMovie` | |
34 | | -| `video.episode` | `OpenGraphVideoEpisode` | |
35 | | -| `video.tv_show` | `OpenGraphVideoTvShow` | |
36 | | -| `video.other` | `OpenGraphVideoOther` | |
| 46 | +* `\Astrotomic\OpenGraph\Types\Website` |
| 47 | +* `\Astrotomic\OpenGraph\Types\Article` |
| 48 | +* `\Astrotomic\OpenGraph\Types\Profile` |
| 49 | +* `\Astrotomic\OpenGraph\Types\Book` |
37 | 50 |
|
38 | | -### 3. Generate Open Graph tags |
| 51 | +#### Music |
39 | 52 |
|
40 | | -Every OpenGraph class in this package has a `create` method that accepts a few required properties and a `getMetatags` method that returns a string of `<meta>` tags. |
| 53 | +* `\Astrotomic\OpenGraph\Types\Music\Album` |
| 54 | +* `\Astrotomic\OpenGraph\Types\Music\Playlist` |
| 55 | +* `\Astrotomic\OpenGraph\Types\Music\Song` |
| 56 | +* `\Astrotomic\OpenGraph\Types\Music\RadioStation` |
41 | 57 |
|
42 | | -For example your webpage might feature a book. We can generate the Open Graph tags as follows: |
| 58 | +#### Video |
43 | 59 |
|
44 | | -```php |
45 | | -$openGraphTags = OpenGraphBook::create('My Awesome Website', 'http://www.example.com', 'http://www.example.com/image.jpg') |
46 | | - ->getMetaTags(); |
| 60 | +* `\Astrotomic\OpenGraph\Types\Video\Movie` |
| 61 | +* `\Astrotomic\OpenGraph\Types\Video\TvShow` |
| 62 | +* `\Astrotomic\OpenGraph\Types\Video\Episode` |
| 63 | +* `\Astrotomic\OpenGraph\Types\Video\Other` |
| 64 | + |
| 65 | +### Structured Properties |
| 66 | + |
| 67 | +* `\Astrotomic\OpenGraph\StructuredProperties\Image` |
| 68 | +* `\Astrotomic\OpenGraph\StructuredProperties\Video` |
| 69 | +* `\Astrotomic\OpenGraph\StructuredProperties\Audio` |
| 70 | + |
| 71 | +## Testing |
| 72 | + |
| 73 | +``` bash |
| 74 | +composer test |
47 | 75 | ``` |
48 | 76 |
|
49 | | -## Open Graph types |
| 77 | +## Changelog |
| 78 | + |
| 79 | +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. |
| 80 | + |
| 81 | +## Contributing |
| 82 | + |
| 83 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
50 | 84 |
|
51 | | -### `OpenGraphWebsite` |
| 85 | +### Security |
52 | 86 |
|
53 | | -### `OpenGraphArticle` |
| 87 | +If you discover any security related issues, please email dev@astrotomic.info instead of using the issue tracker. |
54 | 88 |
|
55 | | -### `OpenGraphBook` |
| 89 | +## Credits |
56 | 90 |
|
57 | | -### `OpenGraphProfile` |
| 91 | +- [Tom Witkowski](https://github.com/Gummibeer) |
| 92 | +- [Alex Vanderbist](https://github.com/AlexVanderbist) |
| 93 | +- [All Contributors](../../contributors) |
58 | 94 |
|
59 | | -### `OpenGraphMusicSong` |
| 95 | +## License |
60 | 96 |
|
61 | | -### `OpenGraphMusicAlbum` |
| 97 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
62 | 98 |
|
63 | | -### `OpenGraphMusicPlaylist` |
| 99 | +## Treeware |
64 | 100 |
|
65 | | -### `OpenGraphMusicRadioStation` |
| 101 | +You're free to use this package, but if it makes it to your production environment I would highly appreciate you buying the world a tree. |
66 | 102 |
|
67 | | -### `OpenGraphVideoMovie` |
| 103 | +It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to [plant trees](https://www.bbc.co.uk/news/science-environment-48870920). If you contribute to my forest you’ll be creating employment for local families and restoring wildlife habitats. |
68 | 104 |
|
69 | | -### `OpenGraphVideoEpisode` |
| 105 | +You can buy trees at [offset.earth/treeware](https://plant.treeware.earth/Astrotomic/php-open-graph) |
70 | 106 |
|
71 | | -### `OpenGraphVideoTvShow` |
| 107 | +Read more about Treeware at https://treeware.earth |
72 | 108 |
|
73 | | -### `OpenGraphVideoOther` |
|
0 commit comments