[CrewbayBridge] Update bridge according to new crewbay.com website (#930)

This commit is contained in:
Thibault Couraud 2018-11-18 08:16:24 +00:00 committed by LogMANOriginal
parent 254fe9212a
commit b29ba5b973

View file

@ -113,7 +113,33 @@ class CrewbayBridge extends BridgeAbstract {
foreach ($annonces as $annonce) { foreach ($annonces as $annonce) {
$detail = $annonce->find('.btn--profile', 0); $detail = $annonce->find('.btn--profile', 0);
$htmlDetail = getSimpleHTMLDOMCached($detail->getAttribute('data-modal-href')); $htmlDetail = getSimpleHTMLDOMCached($detail->href);
if (!empty($this->getInput('recreational_position')) || !empty($this->getInput('professional_position'))) {
if ($this->getInput('type') == 'boats') {
if ($this->getInput('status') == 'professional') {
$positions = array($annonce->find('.title .position', 0)->plaintext);
} else {
$positions = array(str_replace('Wanted:', '', $annonce->find('.content li', 0)->plaintext));
}
} else {
$list = $htmlDetail->find('.viewer-details .viewer-list');
$positions = explode("\r\n", end($list)->find('span.value', 0)->plaintext);
}
$found = false;
$keyword = $this->getInput('status') == 'professional' ? 'professional_position' : 'recreational_position';
foreach ($positions as $position) {
if (strpos(trim($position), $this->getInput($keyword)) !== false) {
$found = true;
break;
}
}
if (!$found) {
continue;
}
}
$item = array(); $item = array();
@ -134,22 +160,24 @@ class CrewbayBridge extends BridgeAbstract {
$images = $annonce->find('.avatar img'); $images = $annonce->find('.avatar img');
$item['enclosures'] = array(end($images)->getAttribute('src')); $item['enclosures'] = array(end($images)->getAttribute('src'));
if ($this->getInput('type') == 'boats') { $content = $htmlDetail->find('.viewer-intro--info', 0)->innertext;
$fields = array('job', 'boat', 'skipper');
} else {
$fields = array('profile', 'positions', 'info', 'qualifications' , 'skills', 'references');
}
$content = ''; $sections = $htmlDetail->find('.viewer-container .viewer-section');
foreach ($fields as $field) { foreach ($sections as $section) {
$info = $htmlDetail->find('.profile--modal-body .info-' . $field, 0); if ($section->find('.viewer-section-title', 0)) {
if ($info) { $class = str_replace('viewer-', '', explode(' ', $section->getAttribute('class'))[0]);
$content .= $htmlDetail->find('.profile--modal-body .info-' . $field, 0)->innertext; if (!in_array($class, array('apply', 'photos', 'reviews', 'contact', 'experience', 'qa'))) {
// Basic sections
$content .= $section->find('.viewer-section-title h3', 0)->outertext;
$content .= $section->find('.viewer-section-content', 0)->innertext;
}
} else {
// Info section
$content .= $section->find('.viewer-section-content h3', 0)->outertext;
$content .= $section->find('.viewer-section-content p', 0)->outertext;
} }
} }
$item['content'] = $content;
if (!empty($this->getInput('keyword'))) { if (!empty($this->getInput('keyword'))) {
$keyword = strtolower($this->getInput('keyword')); $keyword = strtolower($this->getInput('keyword'));
if (strpos(strtolower($item['title']), $keyword) === false) { if (strpos(strtolower($item['title']), $keyword) === false) {
@ -159,28 +187,16 @@ class CrewbayBridge extends BridgeAbstract {
} }
} }
if (!empty($this->getInput('recreational_position')) || !empty($this->getInput('professional_position'))) { $item['content'] = $content;
if ($this->getInput('type') == 'boats') {
if ($this->getInput('status') == 'professional') {
$positions = array($annonce->find('.title .position', 0)->plaintext);
} else {
$positions = array(str_replace('Wanted:', '', $annonce->find('.content li', 0)->plaintext));
}
} else {
$positions = explode("\r\n", trim($htmlDetail->find('.info-positions .value', 0)->plaintext));
}
$found = false; $tags = $htmlDetail->find('li.viewer-tags--tag');
$keyword = $this->getInput('status') == 'professional' ? 'professional_position' : 'recreational_position'; foreach ($tags as $tag) {
foreach ($positions as $position) { if (!isset($item['categories'])) {
if (strpos(trim($position), $this->getInput($keyword)) !== false) { $item['categories'] = array();
$found = true;
break;
}
} }
$text = trim($tag->plaintext);
if (!$found) { if (!in_array($text, $item['categories'])) {
continue; $item['categories'][] = $text;
} }
} }