You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-38Lines changed: 36 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,51 +73,61 @@ $info->linkedData; //The linked-data info (http://json-ld.org/)
73
73
$info->feeds; //The RSS/Atom feeds
74
74
```
75
75
76
-
###The adapter
76
+
## The adapter
77
77
78
78
The adapter is the class that get all information of the page from the providers and choose the best result for each value. For example, a page can provide multiple titles from opengraph, twitter cards, oembed, the `<title>` html element, etc, so the adapter get all this titles and choose the best one.
79
79
80
80
Embed has an generic adapter called "Webpage" to use with any web but has also some specific adapters for sites like archive.org, facebook, google, github, spotify, etc, that provides information using their own apis, or need to fix any specific issue.
81
81
82
82
The available options for the adapters are:
83
83
84
-
* min_image_width (int): Minimal image width used to choose the main image
85
-
* min_image_height (int): Minimal image height used to choose the main image
86
-
* images_blacklist (array): Images that you don't want to be used. Could be plain text or [Url](https://github.com/oscarotero/Embed/blob/master/src/Url.php) match pattern.
87
-
* choose_bigger_image (bool): Choose the bigger image as the main image (instead the first found, that usually is the most relevant).
84
+
Name | Type | Description
85
+
-----|------|------------
86
+
`min_image_width` | `int` | Minimal image width used to choose the main image
87
+
`min_image_height` | `int` | Minimal image height used to choose the main image
88
+
`images_blacklist` | `string|array` | Images that you don't want to be used. Could be plain text or [Uri](https://github.com/oscarotero/Embed/blob/master/src/Uri.php) match pattern.
89
+
`choose_bigger_image` | `bool` | Choose the bigger image as the main image (instead the first found, that usually is the most relevant).
88
90
89
-
###The providers
91
+
## The providers
90
92
91
93
The providers get the data from different sources. Each source has it's own provider. For example, there is a provider for opengraph, other for twitter cards, for oembed, html, etc. Some providers can be configured and are the following:
92
94
93
-
####oembed
95
+
### oembed
94
96
95
97
Used to get data from oembed api if it's available:
96
98
97
-
* parameters (array): Extra query parameters to send with the oembed request
98
-
* embedly_key (string): If it's defined, use embed.ly api as fallback oembed provider.
99
-
* iframely_key (string): If it's defined, use iframe.ly api as fallback oembed provider.
99
+
Name | Type | Description
100
+
-----|------|------------
101
+
`parameters` | `array` | Extra query parameters to send with the oembed request
102
+
`embedly_key` | `string` | If it's defined, use embed.ly api as fallback oembed provider.
103
+
`iframely_key` | `string` | If it's defined, use iframe.ly api as fallback oembed provider.
100
104
101
-
####html
105
+
### html
102
106
103
107
Used to get data directly from the html code of the page:
104
108
105
-
* max_images (int): Max number of images fetched from the html code (searching for the `<img>` elements). By default is -1 (no limit). Use 0 to no get images.
106
-
* external_images (bool|array): By default is false, this means that images located in other domains are not allowed. You can set true (allow all) or provide an array of url patterns.
109
+
Name | Type | Description
110
+
-----|------|------------
111
+
`max_images` | `int` | Max number of images fetched from the html code (searching for the `<img>` elements). By default is -1 (no limit). Use 0 to no get images.
112
+
`external_images` | `bool|array` | By default is false, this means that images located in other domains are not allowed. You can set true (allow all) or provide an array of url patterns.
107
113
108
-
####google
114
+
### google
109
115
110
-
Used only for google maps to generate the embed code[using the embed api](https://developers.google.com/maps/documentation/embed/)
116
+
Used only for google maps to generate the embed code.
111
117
112
-
* key (string): the key used
118
+
Name | Type | Description
119
+
-----|------|------------
120
+
`key` | `string` | The key used [for the embed api](https://developers.google.com/maps/documentation/embed/)
113
121
114
-
####soundcloud
122
+
### soundcloud
115
123
116
124
Used only for soundcloud pages, to get information using its api.
117
125
118
-
* key (string): to get info from soundcloud API.
126
+
Name | Type | Description
127
+
-----|------|------------
128
+
`key` | `string` | The key used to get info from soundcloud API.
119
129
120
-
###Example with all options:
130
+
## Example with all options:
121
131
122
132
The options are passed as the second argument as you can see in the following example:
To dispatch the http request, Embed has the interface `Embed\Http\DispatcherInterface`. By default the curl library is used but you can create your own dispatcher to use any other library like [guzzle](https://github.com/guzzle/guzzle):
155
165
156
-
Create the dispatcher class:
157
-
158
166
```php
167
+
use Embed\Embed;
159
168
use Embed\Http\DispatcherInteface;
160
169
use Embed\Http\Uri;
161
170
use Embed\Http\Response;
@@ -185,24 +194,15 @@ class MyDispatcher implements DispatcherInterface
185
194
return $responses;
186
195
}
187
196
}
188
-
```
189
197
190
-
And to use it:
191
-
192
-
```php
193
-
use Embed\Embed;
194
-
use Embed\Http\Request;
195
-
196
-
$request = new Request('http://example.com', new MyDispatcher());
197
-
198
-
$info = Embed::create($request);
198
+
//Use the dispatcher passing as third argument
199
+
$info = Embed::create('http://example.com', [], new MyDispatcher());
199
200
```
200
201
201
202
The default curl dispatcher accepts the same options that the [curl_setopt PHP function](http://php.net/manual/en/function.curl-setopt.php). You can edit the default values:
202
203
203
204
```php
204
205
use Embed\Embed;
205
-
use Embed\Http\Request;
206
206
use Embed\Http\CurlDispatcher;
207
207
208
208
$dispatcher = new CurlDispatcher([
@@ -217,14 +217,12 @@ $dispatcher = new CurlDispatcher([
217
217
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
218
218
]);
219
219
220
-
$request = new Request('http://example.com', $dispatcher);
The adapter get the data from all providers and choose the best values. But you can get all available values accessing directly to each provider. There's also the possibility to inspect all http request executed for debug purposes:
225
+
The adapter get the data from all providers and choose the best values. But you can get all available values accessing directly to each provider. There's also the possibility to inspect all http requests executed for debug purposes:
0 commit comments