2016-08-05 13:16:00 +02:00
|
|
|
<?php
|
|
|
|
class CastorusBridge extends BridgeAbstract {
|
|
|
|
public function loadMetadatas(){
|
|
|
|
$this->maintainer = "logmanoriginal";
|
|
|
|
$this->name = "Castorus Bridge";
|
2016-08-09 20:01:21 +02:00
|
|
|
$this->uri = 'http://www.castorus.com';
|
2016-08-05 13:16:00 +02:00
|
|
|
$this->description = "Returns the latest changes";
|
2016-08-05 14:59:26 +02:00
|
|
|
|
|
|
|
$this->parameters["Get latest changes"] = '[]';
|
2016-08-09 14:57:42 +02:00
|
|
|
$this->parameters["Get latest changes via ZIP code"] =
|
2016-08-05 14:59:26 +02:00
|
|
|
'[
|
|
|
|
{
|
|
|
|
"name": "ZIP code",
|
|
|
|
"identifier" : "zip",
|
|
|
|
"type" : "text",
|
2016-08-15 01:19:16 +02:00
|
|
|
"required" : true,
|
2016-08-05 14:59:26 +02:00
|
|
|
"exampleValue" : "74910, 74",
|
|
|
|
"title" : "Insert ZIP code (complete or partial)"
|
|
|
|
}
|
|
|
|
]';
|
2016-08-09 14:57:42 +02:00
|
|
|
$this->parameters["Get latest changes via city name"] =
|
2016-08-05 14:59:26 +02:00
|
|
|
'[
|
|
|
|
{
|
|
|
|
"name": "City name",
|
|
|
|
"identifier" : "city",
|
|
|
|
"type" : "text",
|
2016-08-15 01:19:16 +02:00
|
|
|
"required" : true,
|
2016-08-05 14:59:26 +02:00
|
|
|
"exampleValue" : "Seyssel, Seys",
|
|
|
|
"title" : "Insert city name (complete or partial)"
|
|
|
|
}
|
|
|
|
]';
|
2016-08-05 13:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extracts the tile from an actitiy
|
2016-08-06 16:00:56 +02:00
|
|
|
private function ExtractActivityTitle($activity){
|
2016-08-05 13:16:00 +02:00
|
|
|
$title = $activity->find('a', 0);
|
|
|
|
|
|
|
|
if(!$title)
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnServerError('Cannot find title!');
|
2016-08-09 14:57:42 +02:00
|
|
|
|
2016-08-05 13:16:00 +02:00
|
|
|
return htmlspecialchars(trim($title->plaintext));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extracts the url from an actitiy
|
2016-08-06 16:00:56 +02:00
|
|
|
private function ExtractActivityUrl($activity){
|
2016-08-05 13:16:00 +02:00
|
|
|
$url = $activity->find('a', 0);
|
|
|
|
|
|
|
|
if(!$url)
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnServerError('Cannot find url!');
|
2016-08-09 14:57:42 +02:00
|
|
|
|
2016-08-09 20:01:21 +02:00
|
|
|
return $this->uri . $url->href;
|
2016-08-05 13:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extracts the time from an activity
|
2016-08-06 16:00:56 +02:00
|
|
|
private function ExtractActivityTime($activity){
|
2016-08-09 14:57:42 +02:00
|
|
|
// Unfortunately the time is part of the parent node,
|
2016-08-05 13:16:00 +02:00
|
|
|
// so we have to clear all child nodes first
|
|
|
|
$nodes = $activity->find('*');
|
|
|
|
|
|
|
|
if(!$nodes)
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnServerError('Cannot find nodes!');
|
2016-08-09 14:57:42 +02:00
|
|
|
|
2016-08-05 13:16:00 +02:00
|
|
|
foreach($nodes as $node){
|
|
|
|
$node->outertext = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return strtotime($activity->innertext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extracts the price change
|
2016-08-06 16:00:56 +02:00
|
|
|
private function ExtractActivityPrice($activity){
|
2016-08-05 13:16:00 +02:00
|
|
|
$price = $activity->find('span', 1);
|
|
|
|
|
|
|
|
if(!$price)
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnServerError('Cannot find price!');
|
2016-08-09 14:57:42 +02:00
|
|
|
|
2016-08-05 13:16:00 +02:00
|
|
|
return $price->innertext;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function collectData(array $params){
|
2016-08-05 14:59:26 +02:00
|
|
|
if(isset($params['zip']))
|
|
|
|
$zip_filter = trim($params['zip']);
|
|
|
|
|
|
|
|
if(isset($params['city']))
|
|
|
|
$city_filter = trim($params['city']);
|
|
|
|
|
2016-08-09 14:57:42 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM($this->uri);
|
2016-08-05 13:16:00 +02:00
|
|
|
|
|
|
|
if(!$html)
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnServerError('Could not load data from ' . $this->uri . '!');
|
2016-08-09 14:57:42 +02:00
|
|
|
|
2016-08-05 13:16:00 +02:00
|
|
|
$activities = $html->find('div#activite/li');
|
|
|
|
|
|
|
|
if(!$activities)
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnServerError('Failed to find activities!');
|
2016-08-09 14:57:42 +02:00
|
|
|
|
2016-08-05 13:16:00 +02:00
|
|
|
foreach($activities as $activity){
|
|
|
|
$item = new \Item();
|
|
|
|
|
|
|
|
$item->title = $this->ExtractActivityTitle($activity);
|
|
|
|
$item->uri = $this->ExtractActivityUrl($activity);
|
|
|
|
$item->timestamp = $this->ExtractActivityTime($activity);
|
2016-08-09 14:57:42 +02:00
|
|
|
$item->content = '<a href="' . $item->uri . '">' . $item->title . '</a><br><p>'
|
2016-08-05 13:16:00 +02:00
|
|
|
. $this->ExtractActivityPrice($activity) . '</p>';
|
|
|
|
|
2016-08-05 14:59:26 +02:00
|
|
|
if(isset($zip_filter) && !(substr($item->title, 0, strlen($zip_filter)) === $zip_filter)){
|
|
|
|
continue; // Skip this item
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($city_filter) && !(substr($item->title, strpos($item->title, ' ') + 1, strlen($city_filter)) === $city_filter)){
|
|
|
|
continue; // Skip this item
|
|
|
|
}
|
|
|
|
|
2016-08-05 13:16:00 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
2016-08-05 13:19:36 +02:00
|
|
|
return 600; // 10 minutes
|
2016-08-05 13:16:00 +02:00
|
|
|
}
|
|
|
|
}
|