-
Notifications
You must be signed in to change notification settings - Fork 1k
/
PicalaBridge.php
84 lines (73 loc) · 2.46 KB
/
PicalaBridge.php
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
class PicalaBridge extends BridgeAbstract
{
const TYPES = [
'Actualités' => 'actualites',
'Économie' => 'economie',
'Tests' => 'tests',
'Pratique' => 'pratique',
];
const NAME = 'Picala Bridge';
const URI = 'https://www.picala.fr';
const DESCRIPTION = 'Dernière nouvelles du média indépendant sur le vélo électrique';
const MAINTAINER = 'Chouchen';
const PARAMETERS = [
[
'type' => [
'name' => 'Type',
'type' => 'list',
'values' => self::TYPES,
],
],
];
public function getURI()
{
if (!is_null($this->getInput('type'))) {
return sprintf('%s/%s', static::URI, $this->getInput('type'));
}
return parent::getURI();
}
public function getIcon()
{
return 'https://picala-static.s3.amazonaws.com/static/img/favicon/favicon-32x32.png';
}
public function getDescription()
{
if (!is_null($this->getInput('type'))) {
return sprintf('%s - %s', static::DESCRIPTION, array_search($this->getInput('type'), self::TYPES));
}
return parent::getDescription();
}
public function getName()
{
if (!is_null($this->getInput('type'))) {
return sprintf('%s - %s', static::NAME, array_search($this->getInput('type'), self::TYPES));
}
return parent::getName();
}
public function collectData()
{
$fullhtml = getSimpleHTMLDOM($this->getURI());
foreach ($fullhtml->find('.list-container-category a') as $article) {
$firstImage = $article->find('img', 0);
$image = null;
if ($firstImage !== null) {
$srcsets = explode(',', $firstImage->getAttribute('srcset'));
$image = explode(' ', trim(array_shift($srcsets)))[0];
}
$item = [];
$item['uri'] = self::URI . $article->href;
$item['title'] = $article->find('h2', 0)->plaintext;
if ($image === null) {
$item['content'] = $article->find('.teaser__text', 0)->plaintext;
} else {
$item['content'] = sprintf(
'<img src="%s" /><br>%s',
$image,
$article->find('.teaser__text', 0)->plaintext
);
}
$this->items[] = $item;
}
}
}