Skip to content

Commit 8d73f57

Browse files
committed
imagesBlacklist option
1 parent 2800038 commit 8d73f57

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Adapters/Adapter.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Embed\Adapters;
33

4+
use Embed\Url;
45
use Embed\Utils;
56
use Embed\Request;
67
use Embed\Providers\ProviderInterface;
@@ -43,6 +44,7 @@ abstract class Adapter
4344
protected $config = [
4445
'minImageWidth' => 16,
4546
'minImageHeight' => 16,
47+
'imagesBlacklist' => null,
4648
'getBiggerImage' => false,
4749
'getBiggerIcon' => false,
4850
'facebookKey' => null,
@@ -304,9 +306,23 @@ public function getImagesUrls()
304306
{
305307
$imagesUrls = Utils::getData($this->providers, 'imagesUrls', $this->request->url);
306308

307-
$imagesUrls = array_filter($imagesUrls, function($imageUrl) {
309+
$blacklist = $this->config['imagesBlacklist'];
310+
$hasBlacklist = is_array($blacklist) && count($blacklist) > 0;
311+
312+
$imagesUrls = array_filter($imagesUrls, function($imageUrl) use ($blacklist, $hasBlacklist) {
308313
// Clean empty urls
309-
return !empty($imageUrl['value']);
314+
if (empty($imageUrl['value'])) {
315+
return false;
316+
}
317+
318+
// Remove image url if on blacklist
319+
if ($hasBlacklist) {
320+
$url = new Url($imageUrl['value']);
321+
322+
return !$url->match($blacklist) && !in_array($imageUrl['value'], $blacklist, true);
323+
}
324+
325+
return true;
310326
});
311327

312328
// Use array_values to reset keys after filter

0 commit comments

Comments
 (0)