diff --git a/bridges/CdactionBridge.php b/bridges/CdactionBridge.php index a73a1b4f15f..70b4084db4f 100644 --- a/bridges/CdactionBridge.php +++ b/bridges/CdactionBridge.php @@ -1,61 +1,61 @@ [ '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); + $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; } }