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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
<?php
class ErowallBridge extends BridgeAbstract
{
const NAME = 'Erowall.com Bridge';
const URI = 'https://www.erowall.com/';
const DESCRIPTION = 'Latest wallpapers from erowall.com';
const MAINTAINER = 'kurz.junge';
const PARAMETERS = [
'global' => [
'count' => [
'type' => 'number',
'name' => 'Count',
'title' => 'How many wallpapers to fetch',
'defaultValue' => 16
]
],
'By tag' => [
'tag' => [
'type' => 'text',
'name' => 'tag',
'title' => 'Filter results by tag (e.g. playboy)',
'required' => true
]
],
'Latest' => [],
'Most viewed' => [],
'Most downloaded' => []
];
public function collectData()
{
$requestedCount = $this->getInput('count');
$count = 0;
while ($count < $requestedCount) {
# Indexing from 1
$videosURL = $this->getPagedURI($count / 16 + 1);
$website = getSimpleHTMLDOMCached($videosURL);
$nodes = $website->find('.wpmini');
foreach ($nodes as $wpmini) {
$n = $wpmini->find('a', 0);
# The href has format "/w/1234/" so we just remove all non-numeric
$uid = preg_replace('/[^0-9]/', '', $n->href);
$imageURL = self::URI . "/wallpapers/original/$uid.jpg";
$item = [
'title' => "Wallpaper $uid",
'uri' => self::URI . $n->href,
'uid' => "$uid",
'enclosures' => [ $imageURL ],
'content' => "<img src=\"$imageURL\"/>"
];
$tags = basename($n->title, ' wallpaper');
$item['categories'] = array_map(
'ucwords',
explode(',', $tags)
);
$this->items[] = $item;
$count++;
if ($count >= $requestedCount) {
break;
}
}
# In case that current page has less than 16 wallpapers, it is the
# last page and we don't iterate further
if (count($nodes) < 16) {
break;
}
}
}
private function getPagedURI($pgnum)
{
return $this->getURI() . "/page/$pgnum";
}
public function getURI()
{
$ret = self::URI;
switch ($this->queriedContext) {
case 'Most viewed':
$ret .= 'views/';
break;
case 'Most downloaded':
$ret .= 'down/';
break;
case 'Latest':
$ret .= 'dat/';
break;
default:
$tag = $this->getInput('tag') ?? '';
$ret .= 'teg/' . str_replace(' ', '+', $tag);
}
return $ret;
}
public function getName()
{
$count = $this->getInput('count');
$ret = 'Erowall ';
switch ($this->queriedContext) {
case 'Most viewed':
case 'Most downloaded':
case 'Latest':
$ret .= $count . ' ' . strtolower($this->queriedContext);
break;
case 'By tag':
$tag = $this->getInput('tag');
$ret .= "$count latest " . $tag;
break;
default:
}
return $ret . ' wallpapers';
}
}
|