forked from oscarotero/Embed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
314 lines (292 loc) · 11.6 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
include('Embed/autoloader.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Embed tests</title>
<style type="text/css">
body {
font-family: sans-serif;
min-width: 650px;
}
input[type="url"] {
width: 400px;
width: calc(100% - 220px);
}
input[type="text"] {
width: 400px;
}
input[type="number"] {
width: 50px;
}
input[type="url"], input[type="number"], input[type="text"] {
border: none;
background: white;
padding: 4px;
border-radius: 2px;
}
fieldset.main {
font-weight: bold;
background: #BBB;
border-bottom: solid 1px #999;
border-radius: 2px 2px 0 0;
}
fieldset.options {
font-size: 0.9em;
border-bottom: solid 1px #CCC;
}
fieldset.options label:hover {
background: #DDD;
}
fieldset {
border: none;
background: #EEE;
}
fieldset h2 {
font-size: 1.2em;
margin-left: 6px;
}
fieldset label {
display: block;
margin-top: 5px;
padding: 3px 6px;
border-radius: 2px;
cursor: pointer;
}
fieldset label span {
display: inline-block;
width: 200px;
}
a {
color: #999;
font-size: 0.9em;
}
a:hover {
color: black;
text-decoration: none;
}
button[type="submit"] {
font-size: 1.6rem;
font-weight: bold;
font-family: Arial;
background: yellowgreen;
border: none;
border-radius: 2px;
padding: 0.2em 1em;
cursor: pointer;
margin-top: 5px;
}
button[type="submit"]:hover {
background: black;
color: white;
}
img {
border: solid 1px black;
}
table.embed {
width: 100%;
margin-top: 100px;
}
table.embed th,
table.embed td {
padding-top: 5px;
padding-bottom: 5px;
border-top: solid 1px #CCC;
vertical-align: top;
}
table.embed th {
text-align: right;
}
table.embed td {
padding-left: 20px;
}
</style>
</head>
<?php
function getOption($name, $default = null)
{
return isset($_GET['options'][$name]) ? $_GET['options'][$name] : $default;
}
function getResolverOption($name, $default = null)
{
return isset($_GET['resolver'][$name]) ? $_GET['resolver'][$name] : $default;
}
?>
<body>
<form action="test.php">
<fieldset class="main">
<label><span>Url to test:</span> <input type="url" name="url" autofocus placeholder="http://" value="<?php echo isset($_GET['url']) ? $_GET['url'] : ''; ?>"></label>
</fieldset>
<fieldset class="options">
<h2>Info options</h2>
<label><span>Min image width:</span> <input type="number" name="options[minImageWidth]" value="<?php echo getOption('minImageWidth', 0); ?>"></label>
<label><span>Min image height:</span> <input type="number" name="options[minImageHeight]" value="<?php echo getOption('minImageHeight', 0); ?>"></label>
<label><span>Get bigger image</span> <input type="checkbox" name="options[getBiggerImage]" value="1" <?php echo getOption('getBiggerImage') ? 'checked' : ''; ?>></label>
<label><span>Get bigger icon</span> <input type="checkbox" name="options[getBiggerIcon]" value="1" <?php echo getOption('getBiggerIcon') ? 'checked' : ''; ?>></label>
<label><span>Facebook access token:</span> <input type="text" name="options[facebookAccessToken]" value="<?php echo getOption('facebookAccessToken'); ?>"></label>
<label><span>Embedly key:</span> <input type="text" name="options[embedlyKey]" value="<?php echo getOption('embedlyKey'); ?>"></label>
<label><span>Soundcloud client id:</span> <input type="text" name="options[soundcloudClientId]" value="<?php echo getOption('soundcloudClientId', 'YOUR_CLIENT_ID'); ?>"></label>
</fieldset>
<fieldset class="options">
<h2>Request resolver options:</h2>
<label><span>User agent:</span> <input type="text" name="resolver[user_agent]" value="<?php echo getResolverOption('user_agent', 'Embed PHP Library'); ?>"></label>
<label><span>Max redirections:</span> <input type="number" name="resolver[max_redirections]" value="<?php echo getResolverOption('max_redirections', 20); ?>"></label>
<label><span>Connection timeout:</span> <input type="number" name="resolver[connection_timeout]" value="<?php echo getResolverOption('connection_timeout', 10); ?>"></label>
<label><span>Timeout:</span> <input type="number" name="resolver[timeout]" value="<?php echo getResolverOption('timeout', 10); ?>"></label>
</fieldset>
<fieldset class="action">
<button type="submit">Test</button>
<a href="https://github.com/oscarotero/Embed/">Get the source code from Github</a>
-
<a href="javascript:(function(){window.open('http://oscarotero.com/embed/test.php?url='+document.location)})();">or the bookmarklet</a>
</fieldset>
</form>
<?php if (!empty($_GET['url'])): ?>
<section>
<?php
$options = isset($_GET['options']) ? (array) $_GET['options'] : array();
$resolverOptions = isset($_GET['resolver']) ? (array) $_GET['resolver'] : array();
Embed\Request::setResolverConfig($resolverOptions);
$url = new Embed\Request($_GET['url']);
$info = Embed\Embed::create($url, $options);
?>
<?php if (empty($info)): ?>
<p>The url is not valid!</p>
<table class="embed">
<tr>
<th>Http request result</th>
<td>
<ul>
<?php
foreach ($url->getRequestInfo() as $name => $value) {
if (is_array($value)) {
$value = print_r($value, true);
}
echo "<li><strong>$name:</strong> $value</li>";
}
?>
</ul>
</td>
</tr>
</table>
<?php else: ?>
<table class="embed">
<tr>
<th>Title</th>
<td><?php echo $info->title; ?></td>
</tr>
<tr>
<th>Description</th>
<td><?php echo $info->description; ?></td>
</tr>
<tr>
<th>Image</th>
<td>
<?php if ($info->image): ?>
<img src="<?php echo $info->image; ?>"> <?php echo $info->image; ?>
<?php endif; ?>
</td>
</tr>
<tr>
<th>Image size</th>
<td><?php echo $info->imageWidth.' x '.$info->imageHeight; ?></td>
</tr>
<tr>
<th>All images</th>
<td><pre><?php print_r($info->images); ?></pre></td>
</tr>
<tr>
<th>Embed code</th>
<td><?php echo $info->code; ?></td>
</tr>
<tr>
<th>Url</th>
<td><?php echo $info->url; ?></td>
</tr>
<tr>
<th>Type</th>
<td><?php echo $info->type; ?></td>
</tr>
<tr>
<th>Source</th>
<td><?php
if ($info->source) {
echo $info->source;
echo ' / <a href="test-sources.php?url='.urlencode($info->source).'" target="_blank">Test</a>';
}
?>
</td>
</tr>
<tr>
<th>Author name</th>
<td><?php echo $info->authorName; ?></td>
</tr>
<tr>
<th>Author url</th>
<td><?php echo $info->authorUrl; ?></td>
</tr>
<tr>
<th>Provider icon</th>
<td><img src="<?php echo $info->providerIcon; ?>"> <?php echo $info->providerIcon; ?></td>
</tr>
<tr>
<th>All icons</th>
<td><pre><?php print_r($info->providerIcons); ?></pre></td>
</tr>
<tr>
<th>Provider name</th>
<td><?php echo $info->providerName; ?></td>
</tr>
<tr>
<th>Provider url</th>
<td><?php echo $info->providerUrl; ?></td>
</tr>
<tr>
<th>Width</th>
<td><?php echo $info->width; ?></td>
</tr>
<tr>
<th>Height</th>
<td><?php echo $info->height; ?></td>
</tr>
<tr>
<th>Aspect ratio</th>
<td><?php echo $info->aspectRatio; ?></td>
</tr>
<tr>
<th>Http request result</th>
<td>
<ul>
<?php
foreach ($url->getRequestInfo() as $name => $value) {
if (is_array($value)) {
$value = print_r($value, true);
}
echo "<li><strong>$name:</strong> $value</li>";
}
?>
</ul>
</td>
</tr>
<?php foreach ($info->providers as $name => $provider) {
$content = htmlspecialchars(print_r($provider, true), ENT_IGNORE);
echo '<tr><th>'.$name.'</th><td><pre>'.$content.'</pre></td></tr>';
}
?>
<tr>
<th>Content</th>
<td>
<pre><?php echo htmlspecialchars($url->getContent(), ENT_IGNORE); ?></pre>
</td>
</tr>
</table>
<?php endif; ?>
</section>
<?php endif; ?>
</body>
</html>