improved search module
This commit is contained in:
@@ -32,9 +32,7 @@ class SearchController extends Controller
|
|||||||
$site = Helper::sanitize($this->request->getParam('select-value-search'));
|
$site = Helper::sanitize($this->request->getParam('select-value-search'));
|
||||||
$this->search->setSite($site);
|
$this->search->setSite($site);
|
||||||
$data = $this->search->go($keyword);
|
$data = $this->search->go($keyword);
|
||||||
$resp['title'] = ['title', 'seeders', 'info', 'actions'];
|
return new JSONResponse($data);
|
||||||
$resp['row'] = $data;
|
|
||||||
return new JSONResponse($resp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace OCA\NCDownloader\Search\Sites;
|
namespace OCA\NCDownloader\Search\Sites;
|
||||||
|
|
||||||
//The Piratebay
|
//The Piratebay
|
||||||
class TPB implements searchBase
|
class TPB extends searchBase implements searchInterface
|
||||||
{
|
{
|
||||||
//html content
|
//html content
|
||||||
private $content = null;
|
private $content = null;
|
||||||
@@ -14,11 +14,12 @@ class TPB implements searchBase
|
|||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
$this->crawler = $crawler;
|
$this->crawler = $crawler;
|
||||||
}
|
}
|
||||||
public function search($keyword)
|
public function search(string $keyword): array
|
||||||
{
|
{
|
||||||
$this->searchUrl = $this->baseUrl . trim($keyword);
|
$this->searchUrl = $this->baseUrl . trim($keyword);
|
||||||
$this->crawler->add($this->getContent());
|
$this->crawler->add($this->getContent());
|
||||||
return $this->parse();
|
$this->getItems()->addActionLinks(null);
|
||||||
|
return ['title' => $this->getTableTitles(), 'row' => $this->getRows()];
|
||||||
}
|
}
|
||||||
public function setContent($content)
|
public function setContent($content)
|
||||||
{
|
{
|
||||||
@@ -53,4 +54,9 @@ class TPB implements searchBase
|
|||||||
});
|
});
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
public function getItems()
|
||||||
|
{
|
||||||
|
$this->rows = $this->parse();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,25 +3,26 @@
|
|||||||
namespace OCA\NCDownloader\Search\Sites;
|
namespace OCA\NCDownloader\Search\Sites;
|
||||||
|
|
||||||
//bitsearch.to
|
//bitsearch.to
|
||||||
class bitSearch implements searchBase
|
class bitSearch extends searchBase implements searchInterface
|
||||||
{
|
{
|
||||||
//html content
|
//html content
|
||||||
private $content = null;
|
private $content = null;
|
||||||
public $baseUrl = "https://bitsearch.to/search";
|
public $baseUrl = "https://bitsearch.to/search";
|
||||||
private $query = null;
|
protected $query = null;
|
||||||
|
protected $tableTitles = [];
|
||||||
|
|
||||||
public function __construct($crawler, $client)
|
public function __construct($crawler, $client)
|
||||||
{
|
{
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
$this->crawler = $crawler;
|
$this->crawler = $crawler;
|
||||||
}
|
}
|
||||||
public function search($keyword)
|
public function search(string $keyword): array
|
||||||
{
|
{
|
||||||
$this->query = ['q' => trim($keyword), 'sort' => 'seeders'];
|
$this->query = ['q' => trim($keyword), 'sort' => 'seeders'];
|
||||||
$this->searchUrl = $this->baseUrl;
|
$this->searchUrl = $this->baseUrl;
|
||||||
//$this->setContent(file_get_contents(__DIR__ . "/BitSearch.html"));
|
|
||||||
$this->crawler->add($this->getContent());
|
$this->crawler->add($this->getContent());
|
||||||
return $this->parse();
|
$this->getItems()->addActionLinks(null);
|
||||||
|
return ['title' =>$this->getTableTitles(), 'row' => $this->getRows()];
|
||||||
}
|
}
|
||||||
public function setContent($content)
|
public function setContent($content)
|
||||||
{
|
{
|
||||||
@@ -35,6 +36,7 @@ class bitSearch implements searchBase
|
|||||||
$response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]);
|
$response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]);
|
||||||
return $response->getContent();
|
return $response->getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parse()
|
public function parse()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -62,4 +64,9 @@ class bitSearch implements searchBase
|
|||||||
});
|
});
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
public function getItems()
|
||||||
|
{
|
||||||
|
$this->rows = $this->parse();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,40 @@
|
|||||||
|
|
||||||
namespace OCA\NCDownloader\Search\Sites;
|
namespace OCA\NCDownloader\Search\Sites;
|
||||||
|
|
||||||
interface searchBase
|
abstract class searchBase
|
||||||
{
|
{
|
||||||
public function search($keyword);
|
protected $query = null;
|
||||||
public function parse();
|
protected $tableTitles = [];
|
||||||
|
protected $rows = [];
|
||||||
|
protected $actionLinks = [["name" => 'download', 'path' => '/index.php/apps/ncdownloader/new'], ['name' => 'clipboard']];
|
||||||
|
|
||||||
|
public function getTableTitles(): array
|
||||||
|
{
|
||||||
|
if (empty($this->tableTitles)) {
|
||||||
|
return ['title', 'seeders', 'info', 'actions'];
|
||||||
|
}
|
||||||
|
return $this->tableTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTableTitles(array $titles)
|
||||||
|
{
|
||||||
|
$this->tableTitles = $titles;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function addActionLinks(?array $links)
|
||||||
|
{
|
||||||
|
$links = $links ?? $this->actionLinks;
|
||||||
|
foreach ($this->rows as $key => &$value) {
|
||||||
|
if (!$value) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$value['actions'] = $links;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function getRows(): array
|
||||||
|
{
|
||||||
|
return $this->rows;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
10
lib/Search/Sites/searchInterface.php
Normal file
10
lib/Search/Sites/searchInterface.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\NCDownloader\Search\Sites;
|
||||||
|
|
||||||
|
interface searchInterface
|
||||||
|
{
|
||||||
|
public function search(string $keyword):array;
|
||||||
|
public function getRows():array;
|
||||||
|
public function getTableTitles():array;
|
||||||
|
}
|
||||||
@@ -27,7 +27,6 @@ class torrentSearch
|
|||||||
return ['message', $e->getMessage()];
|
return ['message', $e->getMessage()];
|
||||||
}
|
}
|
||||||
$data = $siteInst->search($keyword);
|
$data = $siteInst->search($keyword);
|
||||||
$this->addAction($data);
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,14 +39,4 @@ class torrentSearch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addAction(&$data)
|
|
||||||
{
|
|
||||||
foreach ($data as $key => &$value) {
|
|
||||||
if (!$value) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$value['actions'] = [["name" => 'download', 'path' => '/index.php/apps/ncdownloader/new'], ['name' => 'clipboard']];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user