fetchCachedData($id);
}
/** @inheritdoc */
protected function fetchData($id)
{
$http = new DokuHTTPClient();
$url = $this->getFallbackURL($id);
$html = $http->get($url);
if (!$html) throw new \Exception('Could not fetch data from isdn.de. ' . $http->error);
$data = $this->defaultResult;
$data['id'] = $this->extract('/extract('/extract('/extract('/extractAll('/(.+?)<\/a>/', $html);
$data['publisher'] = $this->extract('/(.+?)<\/a>/', $html);
return $data;
}
/**
* Extract a value from a HTML string using a regex
*
* @param string $regex
* @param string $html
* @param int $group
* @return string
*/
protected function extract($regex, $html, $group = 1)
{
if (preg_match($regex, $html, $m)) {
return html_entity_decode($m[$group]);
}
return '';
}
/**
* Extract all matching values from a HTML string using a regex
*
* @param string $regex
* @param string $html
* @param int $group
* @return string
*/
protected function extractAll($regex, $html, $group = 1)
{
if (preg_match_all($regex, $html, $m)) {
$all = $m[$group];
$all = array_map('html_entity_decode', $all);
$all = array_unique($all);
return $all;
}
return [];
}
}