2020-06-09 21:21:34 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class MarktplaatsBridge extends BridgeAbstract {
|
|
|
|
const NAME = 'Marktplaats';
|
|
|
|
const URI = 'https://marktplaats.nl';
|
|
|
|
const DESCRIPTION = 'Read search queries from marktplaats.nl';
|
|
|
|
const PARAMETERS = array(
|
|
|
|
'Search' => array(
|
|
|
|
'q' => array(
|
|
|
|
'name' => 'query',
|
|
|
|
'type' => 'text',
|
2022-03-24 13:59:34 +03:00
|
|
|
'exampleValue' => 'lamp',
|
2020-06-09 21:21:34 +03:00
|
|
|
'required' => true,
|
|
|
|
'title' => 'The search string for marktplaats',
|
|
|
|
),
|
|
|
|
'z' => array(
|
|
|
|
'name' => 'zipcode',
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => false,
|
2022-06-04 22:06:38 +03:00
|
|
|
'exampleValue' => '1013AA',
|
2020-06-09 21:21:34 +03:00
|
|
|
'title' => 'Zip code for location limited searches',
|
|
|
|
),
|
|
|
|
'd' => array(
|
|
|
|
'name' => 'distance',
|
|
|
|
'type' => 'number',
|
|
|
|
'required' => false,
|
2022-06-04 22:06:38 +03:00
|
|
|
'exampleValue' => '100000',
|
2020-06-09 21:21:34 +03:00
|
|
|
'title' => 'The distance in meters from the zipcode',
|
|
|
|
),
|
|
|
|
'f' => array(
|
|
|
|
'name' => 'priceFrom',
|
|
|
|
'type' => 'number',
|
|
|
|
'required' => false,
|
|
|
|
'title' => 'The minimal price in cents',
|
|
|
|
),
|
|
|
|
't' => array(
|
|
|
|
'name' => 'priceTo',
|
|
|
|
'type' => 'number',
|
|
|
|
'required' => false,
|
|
|
|
'title' => 'The maximal price in cents',
|
|
|
|
),
|
|
|
|
's' => array(
|
|
|
|
'name' => 'showGlobal',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'required' => false,
|
|
|
|
'title' => 'Include result with negative distance',
|
|
|
|
),
|
|
|
|
'i' => array(
|
|
|
|
'name' => 'includeImage',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'required' => false,
|
|
|
|
'title' => 'Include the image at the end of the content',
|
|
|
|
),
|
|
|
|
'r' => array(
|
|
|
|
'name' => 'includeRaw',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'required' => false,
|
|
|
|
'title' => 'Include the raw data behind the content',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const CACHE_TIMEOUT = 900;
|
|
|
|
|
|
|
|
public function collectData() {
|
|
|
|
$query = '';
|
|
|
|
$excludeGlobal = false;
|
|
|
|
if(!is_null($this->getInput('z')) && !is_null($this->getInput('d'))) {
|
|
|
|
$query = '&postcode=' . $this->getInput('z') . '&distanceMeters=' . $this->getInput('d');
|
|
|
|
}
|
|
|
|
if(!is_null($this->getInput('f'))) {
|
|
|
|
$query .= '&PriceCentsFrom=' . $this->getInput('f');
|
|
|
|
}
|
|
|
|
if(!is_null($this->getInput('t'))) {
|
|
|
|
$query .= '&PriceCentsTo=' . $this->getInput('t');
|
|
|
|
}
|
|
|
|
if(!is_null($this->getInput('s'))) {
|
|
|
|
if(!$this->getInput('s')) {
|
|
|
|
$excludeGlobal = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$url = 'https://www.marktplaats.nl/lrp/api/search?query=' . urlencode($this->getInput('q')) . $query;
|
2022-06-04 22:05:43 +03:00
|
|
|
$jsonString = getSimpleHTMLDOM($url);
|
2020-06-09 21:21:34 +03:00
|
|
|
$jsonObj = json_decode($jsonString);
|
|
|
|
foreach($jsonObj->listings as $listing) {
|
|
|
|
if(!$excludeGlobal || $listing->location->distanceMeters >= 0) {
|
|
|
|
$item = array();
|
|
|
|
$item['uri'] = 'https://marktplaats.nl' . $listing->vipUrl;
|
|
|
|
$item['title'] = $listing->title;
|
|
|
|
$item['timestamp'] = $listing->date;
|
|
|
|
$item['author'] = $listing->sellerInformation->sellerName;
|
|
|
|
$item['content'] = $listing->description;
|
|
|
|
$item['categories'] = $listing->verticals;
|
|
|
|
$item['uid'] = $listing->itemId;
|
|
|
|
if(!is_null($this->getInput('i')) && !empty($listing->imageUrls)) {
|
2020-09-03 08:44:32 +03:00
|
|
|
$item['enclosures'] = $listing->imageUrls;
|
|
|
|
if(is_array($listing->imageUrls)) {
|
|
|
|
foreach($listing->imageUrls as $imgurl) {
|
|
|
|
$item['content'] .= "<br />\n<img src='https:" . $imgurl . "' />";
|
2020-06-09 21:21:34 +03:00
|
|
|
}
|
2020-09-03 08:44:32 +03:00
|
|
|
} else {
|
|
|
|
$item['content'] .= "<br>\n<img src='https:" . $listing->imageUrls . "' />";
|
2020-06-09 21:21:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!is_null($this->getInput('r'))) {
|
|
|
|
if($this->getInput('r')) {
|
|
|
|
$item['content'] .= "<br />\n<br />\n<br />\n" . json_encode($listing);
|
|
|
|
}
|
|
|
|
}
|
2020-10-15 10:53:19 +03:00
|
|
|
$item['content'] .= "<br>\n<br>\nPrice: " . $listing->priceInfo->priceCents / 100;
|
|
|
|
$item['content'] .= ' (' . $listing->priceInfo->priceType . ')';
|
2020-09-03 08:44:32 +03:00
|
|
|
if(!empty($listing->location->cityName)) {
|
|
|
|
$item['content'] .= "<br><br>\n" . $listing->location->cityName;
|
|
|
|
}
|
|
|
|
if(!is_null($this->getInput('r'))) {
|
|
|
|
if($this->getInput('r')) {
|
|
|
|
$item['content'] .= "<br />\n<br />\n<br />\n" . json_encode($listing);
|
|
|
|
}
|
|
|
|
}
|
2020-06-09 21:21:34 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-15 10:53:19 +03:00
|
|
|
|
2020-09-03 08:44:32 +03:00
|
|
|
public function getName(){
|
2020-10-15 10:53:19 +03:00
|
|
|
if(!is_null($this->getInput('q'))) {
|
|
|
|
return $this->getInput('q') . ' - Marktplaats';
|
|
|
|
}
|
|
|
|
return parent::getName();
|
|
|
|
}
|
2020-06-09 21:21:34 +03:00
|
|
|
}
|