From d5a75a2545a87f488f8d4a7c78363ac1b7b5c946 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 25 Jul 2020 05:58:42 +0200 Subject: [PATCH] [DribbbleBridge] regex fix and CSS selector update (#1657) * [DribbbleBridge] Fixed regular expressions for quote replacement in JSON (previously invalid JSON was created if a property value contained colons or single quotes). Also updated two CSS selectors as Dribbble's HTML has changed. * [DribbbleBridge] Added fix for relative dates in JSON * [DribbbleBridge] Removed redundant whitespaces --- bridges/DribbbleBridge.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bridges/DribbbleBridge.php b/bridges/DribbbleBridge.php index b1193c90..ae3a2819 100644 --- a/bridges/DribbbleBridge.php +++ b/bridges/DribbbleBridge.php @@ -24,14 +24,14 @@ favicon-63b2904a073c89b52b19aa08cebc16a154bcf83fee8ecc6439968b1e6db569c7.ico'; $additional_data = $this->findJsonForShot($shot, $json); if ($additional_data === null) { $item['uri'] = self::URI . $shot->find('a', 0)->href; - $item['title'] = $shot->find('.dribbble-over strong', 0)->plaintext; + $item['title'] = $shot->find('.shot-title', 0)->plaintext; } else { $item['timestamp'] = strtotime($additional_data['published_at']); $item['uri'] = self::URI . $additional_data['path']; $item['title'] = $additional_data['title']; } - $item['author'] = trim($shot->find('.attribution-user a', 0)->plaintext); + $item['author'] = trim($shot->find('.user-information .display-name', 0)->plaintext); $description = $shot->find('.comment', 0); $item['content'] = $description === null ? '' : $description->plaintext; @@ -51,10 +51,13 @@ favicon-63b2904a073c89b52b19aa08cebc16a154bcf83fee8ecc6439968b1e6db569c7.ico'; foreach($scripts as $script) { if(strpos($script->innertext, 'newestShots') !== false) { // fix single quotes - $script->innertext = str_replace('\'', '"', $script->innertext); + $script->innertext = preg_replace('/\'(.*)\'(,?)$/im', '"\1"\2', $script->innertext); // fix JavaScript JSON (why do they not adhere to the standard?) - $script->innertext = preg_replace('/(\w+):/i', '"\1":', $script->innertext); + $script->innertext = preg_replace('/^(\s*)(\w+):/im', '\1"\2":', $script->innertext); + + // fix relative dates, so they are recognized by strtotime + $script->innertext = preg_replace('/"about ([0-9]+ hours? ago)"(,?)$/im', '"\1"\2', $script->innertext); // find beginning of JSON array $start = strpos($script->innertext, '[');