2021-03-13 19:57:30 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class YeggiBridge extends BridgeAbstract
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2021-03-13 19:57:30 +03:00
|
|
|
const NAME = 'Yeggi Search';
|
|
|
|
const URI = 'https://www.yeggi.com';
|
2022-03-30 00:48:28 +03:00
|
|
|
const DESCRIPTION = 'Returns 3D Models from Thingiverse, MyMiniFactory, Cults3D, and more';
|
2021-03-13 19:57:30 +03:00
|
|
|
const MAINTAINER = 'AntoineTurmel';
|
|
|
|
const PARAMETERS = [
|
2022-07-01 16:10:30 +03:00
|
|
|
[
|
2021-03-13 19:57:30 +03:00
|
|
|
'query' => [
|
|
|
|
'name' => 'Search query',
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
|
|
|
'title' => 'Insert your search term here',
|
2022-03-24 13:59:34 +03:00
|
|
|
'exampleValue' => 'vase'
|
2021-03-13 19:57:30 +03:00
|
|
|
],
|
|
|
|
'sortby' => [
|
|
|
|
'name' => 'Sort by',
|
|
|
|
'type' => 'list',
|
|
|
|
'required' => false,
|
|
|
|
'values' => [
|
|
|
|
'Best match' => '0',
|
|
|
|
'Popular' => '1',
|
|
|
|
'Latest' => '2',
|
|
|
|
],
|
|
|
|
'defaultValue' => 'newest'
|
|
|
|
],
|
|
|
|
'show' => [
|
|
|
|
'name' => 'Show',
|
|
|
|
'type' => 'list',
|
|
|
|
'required' => false,
|
|
|
|
'values' => [
|
|
|
|
'All' => '0',
|
|
|
|
'Free' => '1',
|
|
|
|
'For sale' => '2',
|
|
|
|
],
|
|
|
|
'defaultValue' => 'all'
|
|
|
|
],
|
|
|
|
'showimage' => [
|
|
|
|
'name' => 'Show image in content',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'required' => false,
|
|
|
|
'title' => 'Activate to show the image in the content',
|
|
|
|
'defaultValue' => 'checked'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2021-03-13 19:57:30 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
public function collectData()
|
|
|
|
{
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM($this->getURI());
|
2021-03-13 19:57:30 +03:00
|
|
|
|
|
|
|
$results = $html->find('div.item_1_A');
|
|
|
|
|
|
|
|
foreach ($results as $result) {
|
2022-07-01 16:10:30 +03:00
|
|
|
$item = [];
|
2021-03-13 19:57:30 +03:00
|
|
|
$title = $result->find('.item_3_B_2', 0)->plaintext;
|
|
|
|
$explodeTitle = explode(' ', $title);
|
|
|
|
if (count($explodeTitle) == 2) {
|
|
|
|
$item['title'] = $explodeTitle[1];
|
2022-07-01 16:10:30 +03:00
|
|
|
} else {
|
2021-03-13 19:57:30 +03:00
|
|
|
$item['title'] = $explodeTitle[0];
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2021-03-13 19:57:30 +03:00
|
|
|
$item['uri'] = self::URI . $result->find('a', 0)->href;
|
|
|
|
$item['author'] = 'Yeggi';
|
|
|
|
|
|
|
|
$text = $result->find('i');
|
|
|
|
$item['content'] = $text[0]->plaintext . ' on ' . $text[1]->plaintext;
|
|
|
|
$item['uid'] = hash('md5', $item['title']);
|
2022-03-30 01:57:25 +03:00
|
|
|
|
|
|
|
foreach ($result->find('.item_3_B_2 > a[href^=/q/]') as $tag) {
|
|
|
|
$item['tags'][] = $tag->plaintext;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2021-03-13 19:57:30 +03:00
|
|
|
|
2022-03-30 01:57:25 +03:00
|
|
|
$image = $result->find('img', 0)->src;
|
|
|
|
|
2021-03-13 19:57:30 +03:00
|
|
|
if ($this->getInput('showimage')) {
|
|
|
|
$item['content'] .= '<br><img src="' . $image . '">';
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2021-03-13 19:57:30 +03:00
|
|
|
|
2022-03-30 01:57:25 +03:00
|
|
|
$item['enclosures'] = [$image];
|
2021-03-13 19:57:30 +03:00
|
|
|
|
|
|
|
$this->items[] = $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2021-03-13 19:57:30 +03:00
|
|
|
|
|
|
|
public function getURI()
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2021-03-13 19:57:30 +03:00
|
|
|
if (!is_null($this->getInput('query'))) {
|
|
|
|
$uri = self::URI . '/q/' . urlencode($this->getInput('query')) . '/';
|
|
|
|
$uri .= '?o_f=' . $this->getInput('show');
|
|
|
|
$uri .= '&o_s=' . $this->getInput('sortby');
|
|
|
|
|
|
|
|
return $uri;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2021-03-13 19:57:30 +03:00
|
|
|
|
|
|
|
return parent::getURI();
|
|
|
|
}
|
|
|
|
}
|