Skip to content

Commit

Permalink
[TheDrive] New bridge (#4304)
Browse files Browse the repository at this point in the history
  • Loading branch information
t0stiman authored Oct 17, 2024
1 parent 56994b3 commit bd88bc2
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions bridges/TheDriveBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

class TheDriveBridge extends FeedExpander
{
const NAME = 'The Drive';
const URI = 'https://www.thedrive.com/';
const DESCRIPTION = 'Car news from thedrive.com';
const MAINTAINER = 't0stiman';
const DONATION_URI = 'https://ko-fi.com/tostiman';

public function collectData()
{
$this->collectExpandableDatas('https://www.thedrive.com/feed', 20);
}

protected function parseItem($feedItem)
{
$item = parent::parseItem($feedItem);

//remove warzone articles
if (str_contains($item['uri'], 'the-war-zone')) {
return null;
}

//the first image in the article is an attachment for some reason
foreach ($item['enclosures'] as $attachment) {
$item['content'] = '<img src="' . $attachment . '">' . $item['content'];
}
$item['enclosures'] = [];

//make youtube videos clickable
$html = str_get_html($item['content']);

foreach ($html->find('div.lazied-youtube-frame') as $youtubeVideoDiv) {
$videoID = $youtubeVideoDiv->getAttribute('data-video-id');

//place <a> around the <div>
$youtubeVideoDiv->outertext = '<a href="https://www.youtube.com/watch?v=' . $videoID . '">' . $youtubeVideoDiv->outertext . '</a>';
}

$item['content'] = $html;

return $item;
}
}

0 comments on commit bd88bc2

Please sign in to comment.