Skip to content

Commit

Permalink
[GizmodoBridge] Fix bridge (#1538)
Browse files Browse the repository at this point in the history
* [GizmodoBridge] Update bridge
  • Loading branch information
VerifiedJoseph authored May 17, 2020
1 parent 8233497 commit fa74d37
Showing 1 changed file with 64 additions and 20 deletions.
84 changes: 64 additions & 20 deletions bridges/GizmodoBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,78 @@ class GizmodoBridge extends FeedExpander {

const MAINTAINER = 'polopollo';
const NAME = 'Gizmodo';
const URI = 'http://gizmodo.com/';
const URI = 'https://gizmodo.com';
const CACHE_TIMEOUT = 1800; // 30min
const DESCRIPTION = 'Returns the newest posts from Gizmodo (full text).';
const DESCRIPTION = 'Returns the newest posts from Gizmodo.';

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

$articleHTMLContent = getSimpleHTMLDOMCached($item['uri']);
if(!$articleHTMLContent) {
$text = 'Could not load ' . $item['uri'];
} else {
$text = $articleHTMLContent->find('div.entry-content', 0)->innertext;
foreach($articleHTMLContent->find('pagespeed_iframe') as $element) {
$text .= '<p>link to a iframe (could be a video): <a href="'
. $element->src
. '">'
. $element->src
. '</a></p><br>';
}
$html = getSimpleHTMLDOMCached($item['uri'])
or returnServerError('Could not request: ' . $item['uri']);

$text = strip_tags($text, '<p><b><a><blockquote><img><em>');
}
$html = defaultLinkTo($html, $this->getURI());
$this->stripTags($html);
$this->handleFigureTags($html);
$this->handleIframeTags($html);

// Get header image
$image = $html->find('meta[property="og:image"]', 0)->content;

$item['content'] = $html->find('div.js_post-content', 0)->innertext;

// Get categories
$categories = explode(',', $html->find('meta[name="keywords"]', 0)->content);
$item['categories'] = array_map('trim', $categories);

$item['enclosures'][] = $html->find('meta[property="og:image"]', 0)->content;

$item['content'] = $text;
return $item;
}

public function collectData(){
$this->collectExpandableDatas('http://feeds.gawker.com/gizmodo/full');
public function collectData() {
$this->collectExpandableDatas(self::URI . '/rss', 20);
}

private function stripTags($html) {
foreach ($html->find('aside') as $aside) {
$aside->outertext = '';
}

foreach ($html->find('div.ad-unit') as $div) {
$div->outertext = '';
}

foreach ($html->find('script') as $script) {
$script->outertext = '';
}
}

private function handleFigureTags($html) {
foreach ($html->find('figure') as $index => $figure) {

if (isset($figure->attr['data-id'])) {
$id = $figure->attr['data-id'];
$format = $figure->attr['data-format'];

} else {
$img = $figure->find('img', 0);
$id = $img->attr['data-chomp-id'];
$format = $img->attr['data-format'];
$figure->find('div.img-permalink-sub-wrapper', 0)->style = '';
}

$imageUrl = 'https://i.kinja-img.com/gawker-media/image/upload/' . $id . '.' . $format;

$figure->find('span', 0)->outertext = <<<EOD
<img src="{$imageUrl}">
EOD;
}
}

private function handleIframeTags($html) {
foreach($html->find('iframe') as $iframe) {
$iframe->src = urljoin($this->getURI(), $iframe->src);
}
}
}

0 comments on commit fa74d37

Please sign in to comment.