<?php
header('Content-type: text/html; charset=UTF-8');
header('Content-type: application/json; charset=UTF-8');
$artist=stripslashes(strip_tags($_GET['artist']));
$url = 'http://wiki.rock63.ru/api.php?action=parse&prop=text|images&page='.str_replace(' ', '_', $artist).'&format=json&redirects';
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'rock63.ru Android App');
$c = curl_exec($ch);
$c = json_decode($c, true);
$text = $c['parse']['text']['*'];
if ($text =='') {
$text = 'Информация об исполнителе не найдена.<br />Вы можете сами <a href="http://wiki.rock63.ru/Special:Search/'.str_replace(' ', '_', $artist).'">добавить статью</a> о нем на wiki.rock63.ru.';
} else {
$text = str_replace('<h1>', '<p><strong>', $text);
$text = str_replace('</h1>', '</strong></p>', $text);
$text = str_replace('<h2>', '<p><strong>', $text);
$text = str_replace('</h2>', '</strong></p>', $text);
if (preg_match_all('#<img[^>]*src=(["\'])([^"\']*)\1[^>]*>#is', $text, $image)) {
foreach ($image[2] as $img) {
if (strpos($img, '250px') !== false) {
$output['img'][] = 'http://rock63.ru'.$img;
}
}
}
$text = preg_replace('/<table[^>]*>.*?<\/table>/s', '', $text);
$text = preg_replace('/<span class="editsection"[^>]*>.*?<\/span>/s', '', $text);
$text = preg_replace('/<div class="references-small"[^>]*>.*?<\/div>/s', '', $text);
$text = preg_replace('/<a href="#cite_note[^>]*"[^>]*>.*?<\/a>/s', '', $text);
$text = preg_replace('/<a href="[^>]*" class=\"image\"[^>]*>.*?<\/a>/s', '', $text);
$text = preg_replace('/<a href="[^>]*" class=\"internal\"[^>]*>.*?<\/a>/s', '', $text);
$text = strip_tags($text, '');
}
$output['text'] = $text;
echo json_encode($output, JSON_UNESCAPED_UNICODE);
?>