rss-bridge/bridges/YeggiBridge.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

101 lines
3.1 KiB
PHP
Raw Normal View History

2021-03-13 19:57:30 +03:00
<?php
class YeggiBridge extends BridgeAbstract
{
2021-03-13 19:57:30 +03:00
const NAME = 'Yeggi Search';
const URI = 'https://www.yeggi.com';
const DESCRIPTION = 'Returns 3D Models from Thingiverse, MyMiniFactory, Cults3D, and more';
2021-03-13 19:57:30 +03:00
const MAINTAINER = 'AntoineTurmel';
const PARAMETERS = [
[
2021-03-13 19:57:30 +03:00
'query' => [
'name' => 'Search query',
'type' => 'text',
'required' => true,
'title' => 'Insert your search term here',
'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'
]
]
2021-03-13 19:57:30 +03:00
];
public function collectData()
{
$html = getSimpleHTMLDOM($this->getURI());
2021-03-13 19:57:30 +03:00
$results = $html->find('div.item_1_A');
foreach ($results as $result) {
$item = [];
2021-03-13 19:57:30 +03:00
$title = $result->find('.item_3_B_2', 0)->plaintext;
$explodeTitle = explode('&nbsp; ', $title);
if (count($explodeTitle) == 2) {
$item['title'] = $explodeTitle[1];
} else {
2021-03-13 19:57:30 +03:00
$item['title'] = $explodeTitle[0];
}
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']);
foreach ($result->find('.item_3_B_2 > a[href^=/q/]') as $tag) {
$item['tags'][] = $tag->plaintext;
}
2021-03-13 19:57:30 +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 . '">';
}
2021-03-13 19:57:30 +03:00
$item['enclosures'] = [$image];
2021-03-13 19:57:30 +03:00
$this->items[] = $item;
}
}
2021-03-13 19:57:30 +03:00
public function getURI()
{
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;
}
2021-03-13 19:57:30 +03:00
return parent::getURI();
}
}