aboutsummaryrefslogtreecommitdiff
path: root/bridges/HardwareInfoBridge.php
blob: ae79e0fddc557eb7728eec7f1b11a49a770eea31 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
class HardwareInfoBridge extends FeedExpander
{
	const NAME = 'Hardware Info Bridge';
	const URI = 'https://nl.hardware.info/';
	const DESCRIPTION = 'Tech news from hardware.info (Dutch)';
	const MAINTAINER = 't0stiman';

	public function collectData()
	{
		$this->collectExpandableDatas('https://nl.hardware.info/updates/all.rss', 20);
	}

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

		//get full article
		$articlePage = getSimpleHTMLDOMCached($feedItem->link);

		$article = $articlePage->find('div.article__content', 0);

		//everything under the social bar is not part of the article, remove it
		$reachedEndOfArticle = false;

		foreach($article->find('*') as $child) {

			if(!$reachedEndOfArticle && isset($child->attr['class'])
				&& $child->attr['class'] == 'article__content__social-bar') {
				$reachedEndOfArticle = true;
			}

			if($reachedEndOfArticle) {
				$child->outertext = '';
			}
		}

		//get rid of some more elements we don't need
		$to_remove_selectors = array(
		'script',
		'div.incontent',
		'div.article__content__social-bar',
		'div#revealNewsTip',
		'div.article__previous_next'
		);

		foreach($to_remove_selectors as $selector) {
			foreach($article->find($selector) as $found) {
				$found->outertext = '';
			}
		}

		// convert iframes to links. meant for embedded YouTube videos.
		foreach($article->find('iframe') as $found) {

			$iframeUrl = $found->getAttribute('src');

			if ($iframeUrl) {
				$found->outertext = '<a href="' . $iframeUrl . '">' . $iframeUrl . '</a>';
			}
		}

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