1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AnimeDb package. |
5
|
|
|
* |
6
|
|
|
* @author Peter Gribanov <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2011, Peter Gribanov |
8
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace AnimeDb\Bundle\WorldArtBrowserBundle\Service; |
12
|
|
|
|
13
|
|
|
use AnimeDb\Bundle\WorldArtBrowserBundle\Exception\BannedException; |
14
|
|
|
use AnimeDb\Bundle\WorldArtBrowserBundle\Exception\NotFoundException; |
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
16
|
|
|
|
17
|
|
|
class ErrorDetector |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param ResponseInterface $response |
21
|
|
|
* @param string $path |
22
|
|
|
* @param array $options |
23
|
|
|
* |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
7 |
|
public function detect(ResponseInterface $response, $path, array $options = []) |
27
|
|
|
{ |
28
|
7 |
|
if ($response->getStatusCode() == 404) { |
29
|
1 |
|
throw NotFoundException::page(); |
30
|
|
|
} |
31
|
|
|
|
32
|
6 |
|
$content = $response->getBody()->getContents(); |
33
|
|
|
|
34
|
6 |
|
if ($this->isBanned($content)) { |
35
|
2 |
|
throw BannedException::banned(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// return anime Akira page if anime not found |
39
|
|
|
// example http://www.world-art.ru/animation/animation.php?id=10000000 |
40
|
4 |
|
if (strpos($path, '/animation/animation.php') !== false && |
41
|
|
|
( |
42
|
|
|
// check ID in options |
43
|
4 |
|
(isset($options['query']['id']) && $this->isNotAkira($id = $options['query']['id'], $content)) || |
44
|
|
|
// check ID in path |
45
|
4 |
|
(preg_match('/\?id=(\d+)/', $path, $match) && $this->isNotAkira($id = $match[1], $content)) |
46
|
|
|
) |
47
|
|
|
) { |
48
|
2 |
|
throw NotFoundException::anime($id); |
49
|
|
|
} |
50
|
|
|
|
51
|
2 |
|
return $content; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $content |
56
|
|
|
* |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
6 |
|
private function isBanned($content) |
60
|
|
|
{ |
61
|
|
|
return |
62
|
6 |
|
strpos($content, 'url=http://www.world-art.ru/not_connect.html') !== false || |
63
|
6 |
|
strpos($content, 'NETGEAR ProSecure') !== false |
64
|
|
|
; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Is not a Akira. |
69
|
|
|
* |
70
|
|
|
* @see http://www.world-art.ru/animation/animation.php?id=1 |
71
|
|
|
* |
72
|
|
|
* @param int $id |
73
|
|
|
* @param string $content |
74
|
|
|
* |
75
|
|
|
* @return bool |
76
|
|
|
*/ |
77
|
4 |
|
private function isNotAkira($id, $content) |
78
|
|
|
{ |
79
|
4 |
|
return $id != 1 && strpos($content, '/animation/img/1000/1/1.jpg') !== false; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|