2016-09-14 14:32:34 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class GizmodoBridge extends FeedExpander
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2017-02-11 18:16:56 +03:00
|
|
|
const MAINTAINER = 'polopollo';
|
|
|
|
const NAME = 'Gizmodo';
|
2020-05-17 21:35:34 +03:00
|
|
|
const URI = 'https://gizmodo.com';
|
2016-09-25 18:04:28 +03:00
|
|
|
const CACHE_TIMEOUT = 1800; // 30min
|
2020-05-17 21:35:34 +03:00
|
|
|
const DESCRIPTION = 'Returns the newest posts from Gizmodo.';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
protected function parseItem($item)
|
|
|
|
{
|
2016-09-14 14:32:34 +03:00
|
|
|
$item = parent::parseItem($item);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOMCached($item['uri']);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
$html = defaultLinkTo($html, $this->getURI());
|
|
|
|
$this->stripTags($html);
|
|
|
|
$this->handleFigureTags($html);
|
|
|
|
$this->handleIframeTags($html);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
// Get header image
|
|
|
|
$image = $html->find('meta[property="og:image"]', 0)->content;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
$item['content'] = $html->find('div.js_post-content', 0)->innertext;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
// Get categories
|
|
|
|
$categories = explode(',', $html->find('meta[name="keywords"]', 0)->content);
|
|
|
|
$item['categories'] = array_map('trim', $categories);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
$item['enclosures'][] = $html->find('meta[property="og:image"]', 0)->content;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-14 14:32:34 +03:00
|
|
|
return $item;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$this->collectExpandableDatas(self::URI . '/rss', 20);
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
private function stripTags($html)
|
|
|
|
{
|
|
|
|
foreach ($html->find('aside') as $aside) {
|
|
|
|
$aside->outertext = '';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
foreach ($html->find('div.ad-unit') as $div) {
|
|
|
|
$div->outertext = '';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
foreach ($html->find('script') as $script) {
|
|
|
|
$script->outertext = '';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
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 = '';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
$imageUrl = 'https://i.kinja-img.com/gawker-media/image/upload/' . $id . '.' . $format;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
$figure->find('span', 0)->outertext = <<<EOD
|
|
|
|
<img src="{$imageUrl}">
|
|
|
|
EOD;
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-05-17 21:35:34 +03:00
|
|
|
private function handleIframeTags($html)
|
|
|
|
{
|
|
|
|
foreach ($html->find('iframe') as $iframe) {
|
|
|
|
$iframe->src = urljoin($this->getURI(), $iframe->src);
|
|
|
|
}
|
2016-09-14 14:32:34 +03:00
|
|
|
}
|
|
|
|
}
|