2023-09-09 10:19:09 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class ArsTechnicaBridge extends FeedExpander
|
|
|
|
{
|
|
|
|
const MAINTAINER = 'phantop';
|
|
|
|
const NAME = 'Ars Technica';
|
|
|
|
const URI = 'https://arstechnica.com/';
|
|
|
|
const DESCRIPTION = 'Returns the latest articles from Ars Technica';
|
|
|
|
const PARAMETERS = [[
|
|
|
|
'section' => [
|
|
|
|
'name' => 'Site section',
|
|
|
|
'type' => 'list',
|
|
|
|
'defaultValue' => 'index',
|
|
|
|
'values' => [
|
|
|
|
'All' => 'index',
|
|
|
|
'Apple' => 'apple',
|
|
|
|
'Board Games' => 'cardboard',
|
|
|
|
'Cars' => 'cars',
|
|
|
|
'Features' => 'features',
|
|
|
|
'Gaming' => 'gaming',
|
|
|
|
'Information Technology' => 'technology-lab',
|
|
|
|
'Science' => 'science',
|
|
|
|
'Staff Blogs' => 'staff-blogs',
|
|
|
|
'Tech Policy' => 'tech-policy',
|
|
|
|
'Tech' => 'gadgets',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]];
|
|
|
|
|
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$url = 'https://feeds.arstechnica.com/arstechnica/' . $this->getInput('section');
|
2023-10-14 00:14:08 +03:00
|
|
|
$this->collectExpandableDatas($url, 10);
|
2023-09-09 10:19:09 +03:00
|
|
|
}
|
|
|
|
|
2023-10-13 02:59:05 +03:00
|
|
|
protected function parseItem(array $item)
|
2023-09-09 10:19:09 +03:00
|
|
|
{
|
2023-12-23 11:42:37 +03:00
|
|
|
$item_html = getSimpleHTMLDOMCached($item['uri']);
|
2023-09-09 10:19:09 +03:00
|
|
|
$item_html = defaultLinkTo($item_html, self::URI);
|
2024-10-16 19:59:36 +03:00
|
|
|
|
|
|
|
$content = '';
|
|
|
|
$header = $item_html->find('article header', 0);
|
|
|
|
$leading = $header->find('p[class*=leading]', 0);
|
|
|
|
if ($leading != null) {
|
|
|
|
$content .= '<p>' . $leading->innertext . '</p>';
|
|
|
|
}
|
|
|
|
$intro_image = $header->find('img.intro-image', 0);
|
|
|
|
if ($intro_image != null) {
|
|
|
|
$content .= '<figure>' . $intro_image;
|
|
|
|
|
|
|
|
$image_caption = $header->find('.caption .caption-content', 0);
|
|
|
|
if ($image_caption != null) {
|
|
|
|
$content .= '<figcaption>' . $image_caption->innertext . '</figcaption>';
|
|
|
|
}
|
|
|
|
$content .= '</figure>';
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($item_html->find('.post-content') as $content_tag) {
|
|
|
|
$content .= $content_tag->innertext;
|
|
|
|
}
|
|
|
|
|
|
|
|
$item['content'] = str_get_html($content);
|
2023-12-13 23:40:13 +03:00
|
|
|
|
2024-05-17 22:29:17 +03:00
|
|
|
$parsely = $item_html->find('[name="parsely-page"]', 0);
|
|
|
|
$parsely_json = json_decode(html_entity_decode($parsely->content), true);
|
|
|
|
$item['categories'] = $parsely_json['tags'];
|
|
|
|
|
2024-10-16 19:59:36 +03:00
|
|
|
// Some lightboxes are nested in figures. I'd guess that's a
|
|
|
|
// bug in the website
|
|
|
|
foreach ($item['content']->find('figure div div.ars-lightbox') as $weird_lightbox) {
|
|
|
|
$weird_lightbox->parent->parent->outertext = $weird_lightbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's easier to reconstruct the whole thing than remove
|
|
|
|
// duplicate reactive tags
|
|
|
|
foreach ($item['content']->find('.ars-lightbox') as $lightbox) {
|
|
|
|
$lightbox_content = '';
|
|
|
|
foreach ($lightbox->find('.ars-lightbox-item') as $lightbox_item) {
|
|
|
|
$img = $lightbox_item->find('img', 0);
|
|
|
|
if ($img != null) {
|
|
|
|
$lightbox_content .= '<figure>' . $img;
|
|
|
|
$caption = $lightbox_item->find('div.pswp-caption-content', 0);
|
|
|
|
if ($caption != null) {
|
|
|
|
$credit = $lightbox_item->find('div.ars-gallery-caption-credit', 0);
|
|
|
|
if ($credit != null) {
|
|
|
|
$credit->innertext = 'Credit: ' . $credit->innertext;
|
|
|
|
}
|
|
|
|
$lightbox_content .= '<figcaption>' . $caption->innertext . '</figcaption>';
|
|
|
|
}
|
|
|
|
$lightbox_content .= '</figure>';
|
|
|
|
}
|
2023-12-23 11:42:37 +03:00
|
|
|
}
|
2024-10-16 19:59:36 +03:00
|
|
|
$lightbox->innertext = $lightbox_content;
|
2023-12-13 23:40:13 +03:00
|
|
|
}
|
|
|
|
|
2023-09-09 10:19:09 +03:00
|
|
|
// remove various ars advertising
|
2024-10-16 19:59:36 +03:00
|
|
|
foreach ($item['content']->find('.ars-interlude-container') as $ad) {
|
2023-09-09 10:19:09 +03:00
|
|
|
$ad->remove();
|
|
|
|
}
|
2024-10-16 19:59:36 +03:00
|
|
|
foreach ($item['content']->find('.toc-container') as $toc) {
|
|
|
|
$toc->remove();
|
2023-09-09 10:19:09 +03:00
|
|
|
}
|
2024-10-16 19:59:36 +03:00
|
|
|
|
|
|
|
// Mostly YouTube videos
|
|
|
|
$iframes = $item['content']->find('iframe');
|
|
|
|
foreach ($iframes as $iframe) {
|
|
|
|
$iframe->outertext = '<a href="' . $iframe->src . '">' . $iframe->src . '</a>';
|
|
|
|
}
|
|
|
|
// This fixed padding around the former iframes and actual inline videos
|
|
|
|
foreach ($item['content']->find('div[style*=aspect-ratio]') as $styled) {
|
|
|
|
$styled->removeAttribute('style');
|
2023-09-09 10:19:09 +03:00
|
|
|
}
|
|
|
|
|
2023-12-23 11:42:37 +03:00
|
|
|
$item['content'] = backgroundToImg($item['content']);
|
2024-10-16 19:59:36 +03:00
|
|
|
$item['uid'] = strval($parsely_json['post_id']);
|
2023-09-09 10:19:09 +03:00
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
}
|