Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions bridges/CdactionBridge.php
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
<?php

class CdactionBridge extends BridgeAbstract
{
class CdactionBridge extends BridgeAbstract {
const NAME = 'CD-ACTION bridge';
const URI = 'https://cdaction.pl';
const DESCRIPTION = 'Fetches the latest posts from given category.';
const MAINTAINER = 'tomaszkane';
const PARAMETERS = [ [
const PARAMETERS = [[
'category' => [
'name' => 'Kategoria',
'type' => 'list',
'values' => [
'Najnowsze (wszystkie)' => 'najnowsze',
'Najnowsze (wszystkie)' => 'feed',
'Newsy' => 'newsy',
'Recenzje' => 'recenzje',
'Teksty' => [
'Publicystyka' => 'publicystyka',
'Zapowiedzi' => 'zapowiedzi',
'Już graliśmy' => 'juz-gralismy',
'Poradniki' => 'poradniki',
],
'Teksty' => 'teksty',
'Kultura' => 'kultura',
'Wideo' => 'wideo',
'Czasopismo' => 'czasopismo',
'Technologie' => [
'Artykuły' => 'artykuly',
'Testy' => 'testy',
],
'Na luzie' => [
'Konkursy' => 'konkursy',
'Nadgodziny' => 'nadgodziny',
]
]
'Retro' => 'retro',
'Technologie' => 'technologie',
'Na luzie' => 'na-luzie',
],
]]
];

public function collectData()
{
$html = getSimpleHTMLDOM($this->getURI() . '/' . $this->getInput('category'));
public function collectData() {
$feedUrl = $this->getURI() . '/' . $this->getInput('category');

$newsJson = $html->find('script#__NEXT_DATA__', 0)->innertext;
if (!$newsJson = json_decode($newsJson)) {
if ($this->getInput('category') === 'feed') {
$xml = simplexml_load_file($feedUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to drop usage of this function? because it has security implications

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, you mean simplexml_load_file? I need to load https://cdaction.pl/feed/ it's XML with all needed data.
I can add some tweaks, like flags LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING and validate if file is really a xml. Any other suggesions?

$namespaces = $xml->getNamespaces(true);
foreach ($xml->channel->item as $child) {
$item = [];
$item['uri'] = (string) $child->link;
$item['title'] = (string) $child->title;
$item['timestamp'] = (string) $child->pubDate;
$item['content'] = (string) $child->description;
$item['author'] = (string) $child->children($namespaces['dc'])->creator;
foreach ($child->category as $cat) {
$item['categories'] = (string) $cat;
}
$this->items[] = $item;
}
return;
}

$queriesIndex = $this->getInput('category') === 'najnowsze' ? 0 : 1;
foreach ($newsJson->props->pageProps->dehydratedState->queries[$queriesIndex]->state->data->results as $news) {
$dom = getSimpleHTMLDOM($feedUrl);
/** @var simple_html_dom_node[] $nodes */
$nodes = $dom->find('a.article-link');
foreach ($nodes as $node) {
$item = [];
$item['uri'] = $this->getURI() . '/' . $news->category->slug . '/' . $news->slug;
$item['title'] = $news->title;
$item['timestamp'] = $news->publishedAt;
$item['author'] = $news->editor->fullName;
$item['content'] = $news->lead;
$item['enclosures'][] = $news->bannerUrl;
$item['categories'] = array_column($news->tags, 'name');
$item['uid'] = $news->id;

$item['uri'] = $node->attr['href'];
$item['title'] = trim($node->find('h3', 0)?->plaintext);
$item['timestamp'] = trim($node->find('.meta .date', 0)->plaintext) ? : null;
$item['author'] = trim($node->find('.author-name', 0)?->plaintext ?? '', " \n\r\t\v\0\"") ? : null;
$item['enclosures'][] = $node->find('.image img', 0)?->attr['src'] ?: null;
if ($category = trim($node->find('.category')?->plaintext)) {
$item['categories'][] = $category;
}
$this->items[] = $item;
}
}
Expand Down
Loading