Skip to content

Commit 1aadc57

Browse files
committed
ensure the same provider that get the code, get also its width and height
1 parent debde83 commit 1aadc57

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

src/Adapters/Adapter.php

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,28 +217,50 @@ public function getCode()
217217
{
218218
$allCodes = Utils::getData($this->providers, 'code');
219219

220-
$default = null;
221-
222-
foreach ($allCodes as $codeInfo) {
223-
$code = $codeInfo['value'];
220+
$choosen = null;
224221

222+
foreach ($allCodes as $code) {
225223
// <object> and <embed> codes have less priority
226-
if (strpos($code, '</object>') !== false || strpos($code, '</embed>') !== false) {
227-
if (empty($default)) {
228-
$default = $code;
224+
if (strpos($code['value'], '</object>') !== false || strpos($code['value'], '</embed>') !== false) {
225+
if (empty($choosen)) {
226+
$choosen = $code;
229227
}
230228

231229
continue;
232230
}
233231

234-
if (strpos($code, '</iframe>') !== false) {
235-
return preg_replace('|^.*(<iframe.*</iframe>).*$|Us', '$1', $code);
232+
if (strpos($code['value'], '</iframe>') !== false) {
233+
$code['value'] = preg_replace('|^.*(<iframe.*</iframe>).*$|Us', '$1', $code['value']);
236234
}
237235

238-
return $code;
236+
$choosen = $code;
237+
break;
239238
}
240239

241-
return $default;
240+
$this->width = null;
241+
$this->height = null;
242+
243+
if ($choosen) {
244+
//get the width/height
245+
foreach ($choosen['providers'] as $provider) {
246+
$this->width = $this->providers[$provider]->getWidth();
247+
$this->height = $this->providers[$provider]->getHeight();
248+
249+
if (is_numeric($this->width)) {
250+
$this->width = (int) $this->width;
251+
}
252+
253+
if (is_numeric($this->height)) {
254+
$this->height = (int) $this->height;
255+
}
256+
257+
if (!empty($this->width) || !empty($this->height)) {
258+
break;
259+
}
260+
}
261+
262+
return $choosen['value'];
263+
}
242264
}
243265

244266
/**
@@ -412,19 +434,19 @@ public function getImageHeight()
412434
*/
413435
public function getWidth()
414436
{
415-
$val = Utils::getFirstValue(Utils::getData($this->providers, 'width'));
437+
$this->code;
416438

417-
return $val ? (is_numeric($val) ? (int) $val : $val) : null;
439+
return $this->width;
418440
}
419441

420442
/**
421443
* {@inheritdoc}
422444
*/
423445
public function getHeight()
424446
{
425-
$val = Utils::getFirstValue(Utils::getData($this->providers, 'height'));
447+
$this->code;
426448

427-
return $val ? (is_numeric($val) ? (int) $val : $val) : null;
449+
return $this->height;
428450
}
429451

430452
/**

0 commit comments

Comments
 (0)