Skip to content

Commit

Permalink
fix(dribble) (RSS-Bridge#4044)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvikan authored Mar 31, 2024
1 parent 182567e commit d5d470c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions bridges/DribbbleBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public function collectData()
{
$html = getSimpleHTMLDOM(self::URI);

$json = $this->loadEmbeddedJsonData($html);
$data = $this->fetchData($html);

foreach ($html->find('li[id^="screenshot-"]') as $shot) {
$item = [];

$additional_data = $this->findJsonForShot($shot, $json);
$additional_data = $this->findJsonForShot($shot, $data);
if ($additional_data === null) {
$item['uri'] = self::URI . $shot->find('a', 0)->href;
$item['title'] = $shot->find('.shot-title', 0)->plaintext;
Expand All @@ -46,9 +46,8 @@ public function collectData()
}
}

private function loadEmbeddedJsonData($html)
private function fetchData($html)
{
$json = [];
$scripts = $html->find('script');

foreach ($scripts as $script) {
Expand All @@ -69,12 +68,17 @@ private function loadEmbeddedJsonData($html)
$end = strpos($script->innertext, '];') + 1;

// convert JSON to PHP array
$json = json_decode(substr($script->innertext, $start, $end - $start), true);
break;
$json = substr($script->innertext, $start, $end - $start);

try {
// TODO: fix broken json
return Json::decode($json);
} catch (\JsonException $e) {
return [];
}
}
}

return $json;
return [];
}

private function findJsonForShot($shot, $json)
Expand Down

0 comments on commit d5d470c

Please sign in to comment.