Skip to content

Commit 0c15d6d

Browse files
committed
more fixes
1 parent be8db5e commit 0c15d6d

File tree

6 files changed

+13
-43
lines changed

6 files changed

+13
-43
lines changed

demo/index.php

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ function getOption($name, $default = null)
123123
{
124124
return htmlspecialchars(isset($_GET['options'][$name]) ? $_GET['options'][$name] : $default, ENT_QUOTES, 'UTF-8');
125125
}
126-
function getResolverOption($name, $default = null)
127-
{
128-
return isset($_GET['resolver'][$name]) ? $_GET['resolver'][$name] : $default;
129-
}
130126
?>
131127

132128
<body>
@@ -147,14 +143,6 @@ function getResolverOption($name, $default = null)
147143
<label><span>facebookProvider</span> <input type="checkbox" name="options[facebookProvider]" value="1" <?php echo getOption('facebookProvider') ? 'checked' : ''; ?>></label>
148144
<label><span>oembedParameters (in json format):</span> <input type="text" name="options[oembedParameters]" value="<?php echo getOption('oembedParameters'); ?>"></label>
149145
</fieldset>
150-
<fieldset class="options">
151-
<h2>Request resolver options:</h2>
152-
153-
<label><span>userAgent:</span> <input type="text" name="resolver[userAgent]" value="<?php echo getResolverOption('userAgent', 'Embed PHP Library'); ?>"></label>
154-
<label><span>maxRedirections:</span> <input type="number" name="resolver[maxRedirections]" value="<?php echo getResolverOption('maxRedirections', 20); ?>"></label>
155-
<label><span>connectionTimeout:</span> <input type="number" name="resolver[connectionTimeout]" value="<?php echo getResolverOption('connectionTimeout', 10); ?>"></label>
156-
<label><span>timeout:</span> <input type="number" name="resolver[timeout]" value="<?php echo getResolverOption('timeout', 10); ?>"></label>
157-
</fieldset>
158146
<fieldset class="action">
159147
<button type="submit">Test</button>
160148
&nbsp;&nbsp;&nbsp;
@@ -173,32 +161,13 @@ function getResolverOption($name, $default = null)
173161
$options['oembedParameters'] = $options['oembedParameters'] ? json_decode($options['oembedParameters'], true) : array();
174162
}
175163

176-
$request = new Embed\Request(new Embed\Url($_GET['url']), null, isset($_GET['resolver']) ? (array) $_GET['resolver'] : null);
177-
$info = Embed\Embed::create($request, $options);
164+
$info = Embed\Embed::create($_GET['url'], $options);
178165
?>
179166

180167
<?php if (empty($info)): ?>
181168

182169
<p>The url is not valid!</p>
183170

184-
<table class="embed">
185-
<tr>
186-
<th>Http request result</th>
187-
<td>
188-
<ul>
189-
<?php
190-
foreach ($url->getRequestInfo() as $name => $value) {
191-
if (is_array($value)) {
192-
$value = print_r($value, true);
193-
}
194-
echo "<li><strong>$name:</strong> $value</li>";
195-
}
196-
?>
197-
</ul>
198-
</td>
199-
</tr>
200-
</table>
201-
202171
<?php else: ?>
203172

204173
<table class="embed">
@@ -297,7 +266,7 @@ function getResolverOption($name, $default = null)
297266
<td>
298267
<ul>
299268
<?php
300-
foreach ($request->getRequestInfo() as $name => $value) {
269+
foreach ($info->request->getRequestInfo() as $name => $value) {
301270
if (is_array($value)) {
302271
$value = print_r($value, true);
303272
}
@@ -315,7 +284,7 @@ function getResolverOption($name, $default = null)
315284
<tr>
316285
<th>Content</th>
317286
<td>
318-
<pre><?php echo htmlspecialchars($request->getContent(), ENT_IGNORE); ?></pre>
287+
<pre><?php echo htmlspecialchars($info->request->getContent(), ENT_IGNORE); ?></pre>
319288
</td>
320289
</tr>
321290
</table>

demo/sources.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@
5858
if (!empty($_GET['url'])): ?>
5959
<section>
6060
<?php
61-
$request = new Embed\Request($_GET['url']);
62-
$source = Embed\Embed::createSource($request);
61+
$source = Embed\Embed::createSource($_GET['url']);
6362
?>
6463

6564
<?php if (empty($source)): ?>
@@ -70,15 +69,15 @@
7069

7170
<h1><a href="<?php echo $source->providerUrl; ?>"><?php echo $source->providerUrl; ?></a></h1>
7271

73-
<a href="test.php?url=<?php echo $source->providerUrl; ?>" target="_blank">Test</a><br>
74-
<a href="<?php echo $source->sourceUrl; ?>" target="_blank">Source url</a>
72+
<a href="index.php?url=<?php echo $source->providerUrl; ?>">Test</a><br>
73+
<a href="<?php echo $source->sourceUrl; ?>">Source url</a>
7574

7675
<ul>
7776
<?php foreach ($source->items as $url): ?>
7877
<li>
79-
<a href="<?php echo $url['url']; ?>"><?php echo $url['url']; ?></a> | <a href="test.php?url=<?php echo urlencode($url['url']); ?>" target="_blank">Test</a><br>
78+
<a href="<?php echo $url['url']; ?>"><?php echo $url['url']; ?></a> | <a href="index.php?url=<?php echo urlencode($url['url']); ?>">Test</a><br>
8079
<?php if ($url['originUrl']): ?>
81-
<a href="<?php echo $url['originUrl']; ?>"><?php echo $url['originUrl']; ?></a> | <a href="test.php?url=<?php echo urlencode($url['originUrl']); ?>" target="_blank">Test origin Url</a><br>
80+
<a href="<?php echo $url['originUrl']; ?>"><?php echo $url['originUrl']; ?></a> | <a href="index.php?url=<?php echo urlencode($url['originUrl']); ?>">Test origin Url</a><br>
8281
<?php endif; ?>
8382
<time><?php echo $url['pubdate']; ?></time>
8483
</li>
@@ -92,7 +91,7 @@
9291
<tr>
9392
<th>Content</th>
9493
<td>
95-
<pre><?php echo htmlspecialchars($request->getContent(), ENT_IGNORE); ?></pre>
94+
<pre><?php echo htmlspecialchars($source->request->getContent(), ENT_IGNORE); ?></pre>
9695
</td>
9796
</tr>
9897
</table>

src/Adapters/Adapter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/**
88
* Base class extended by all adapters
99
*
10+
* @property Request $request
1011
* @property null|string $title
1112
* @property null|string $description
1213
* @property null|string $url

src/Embed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static function createSource($request, array $options = null)
6161
$resolverClass = isset($options['resolver']['class']) ? $options['resolver']['class'] : null;
6262
$resolverOptions = isset($options['resolver']['options']) ? $options['resolver']['options'] : null;
6363

64-
$request = new Request($request, $resolverClass, $resolverOptions);
64+
$request = new Request(new Url($request), $resolverClass, $resolverOptions);
6565
} elseif (!($request instanceof Request)) {
6666
throw new \InvalidArgumentException("Embed::createSource only accepts instances of Embed\\Request or strings");
6767
}

src/Sources/Feed.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
class Feed extends Source implements SourceInterface
1010
{
1111
protected $data;
12-
protected $request;
1312

1413
/**
1514
* {@inheritDoc}

src/Sources/Source.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
abstract class Source
1010
{
11+
public $request;
12+
1113
/**
1214
* Magic method to execute methods on get paramaters
1315
* For example, $source->sourceUrl executes $source->getSourceUrl()

0 commit comments

Comments
 (0)