Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ModelKarteiBridge] Add new bridge #975

Merged
merged 1 commit into from
Dec 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions bridges/ModelKarteiBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
class ModelKarteiBridge extends BridgeAbstract {
const NAME = 'model-kartei.de';
const URI = 'https://www.model-kartei.de/';
const DESCRIPTION = 'Get the public comp card gallery';
const MAINTAINER = 'fulmeek';
const PARAMETERS = array(array(
'model_id' => array(
'name' => 'Model ID',
'exampleValue' => '123456'
)
));

const LIMIT_ITEMS = 10;

private $feedName = '';


public function collectData() {
$model_id = preg_replace('/[^0-9]/', '', $this->getInput('model_id'));
if (empty($model_id))
returnServerError('Invalid model ID');

$html = getSimpleHTMLDOM(self::URI . 'sedcards/model/' . $model_id . '/')
or returnServerError('Model not found');

$objTitle = $html->find('.sTitle', 0);
if ($objTitle)
$this->feedName = $objTitle->plaintext;

$itemlist = $html->find('#photoList .photoPreview');
if (!$itemlist)
returnServerError('No gallery');

foreach($itemlist as $idx => $element) {
if ($idx >= self::LIMIT_ITEMS)
break;

$item = array();

$title = $element->title;
$date = $element->{'data-date'};
$author = $this->feedName;
$text = '';

$objImage = $element->find('a.photoLink img', 0);
$objLink = $element->find('a.photoLink', 0);

if ($objLink) {
$page = getSimpleHTMLDOMCached($objLink->href);

if (empty($title)) {
$objTitle = $page->find('.p-title', 0);
if ($objTitle)
$title = $objTitle->plaintext;
}
if (empty($date)) {
$objDate = $page->find('.cameraDetails .date', 0);
if ($objDate)
$date = strtotime($objDate->parent()->plaintext);
}
if (empty($author)) {
$objAuthor = $page->find('.p-publisher a', 0);
if ($objAuthor)
$author = $objAuthor->plaintext;
}

$objFullImage = $page->find('img#gofullscreen', 0);
if ($objFullImage)
$objImage = $objFullImage;

$objText = $page->find('.p-desc', 0);
if ($objText)
$text = $objText->plaintext;
}

$item['title'] = $title;
$item['timestamp'] = $date;
$item['author'] = $author;

if ($objImage)
$item['content'] = '<img src="' . $objImage->src . '"/>';
if ($objLink) {
$item['uri'] = $objLink->href;
if (!empty($item['content']))
$item['content'] = '<a href="' . $objLink->href . '" target="_blank">' . $item['content'] . '</a>';
} else {
$item['uri'] = 'urn:sha1:' . hash('sha1', $item['content']);
}
if (!empty($text))
$item['content'] = '<p>' . $text . '</p>' . $item['content'];

$this->items[] = $item;
}
}


public function getName(){
if(!empty($this->feedName)) {
return $this->feedName . ' - ' . self::NAME;
}
return parent::getName();
}
}