1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
12 | if (!defined('DC_RC_PATH')) { return; } |
---|
13 | |
---|
14 | class dcFilterFairTrackbacks extends dcSpamFilter |
---|
15 | { |
---|
16 | public $name = 'Fair Trackbacks'; |
---|
17 | public $has_gui = false; |
---|
18 | public $active = true; |
---|
19 | public $order = -10; |
---|
20 | |
---|
21 | public function __construct($core) |
---|
22 | { |
---|
23 | parent::__construct($core); |
---|
24 | } |
---|
25 | |
---|
26 | protected function setInfo() |
---|
27 | { |
---|
28 | $this->description = __('Checks trackback source for a link to the post'); |
---|
29 | } |
---|
30 | |
---|
31 | |
---|
32 | public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status) |
---|
33 | { |
---|
34 | if ($type != 'trackback') { |
---|
35 | return; |
---|
36 | } |
---|
37 | |
---|
38 | try |
---|
39 | { |
---|
40 | $default_parse = array('scheme'=>'','host'=>'','path'=>'','query'=>''); |
---|
41 | $S = array_merge($default_parse,parse_url($site)); |
---|
42 | |
---|
43 | if ($S['scheme'] != 'http' || !$S['host'] || !$S['path']) { |
---|
44 | throw new Exception('Invalid URL'); |
---|
45 | } |
---|
46 | |
---|
47 | # Check incomink link page |
---|
48 | $post = $this->core->blog->getPosts(array('post_id' => $post_id)); |
---|
49 | $post_url = $post->getURL(); |
---|
50 | $P = array_merge($default_parse,parse_url($post_url)); |
---|
51 | |
---|
52 | if ($post_url == $site) { |
---|
53 | throw new Exception('Same source and destination'); |
---|
54 | } |
---|
55 | |
---|
56 | $o = netHttp::initClient($site,$path); |
---|
57 | $o->setTimeout(3); |
---|
58 | $o->get($path); |
---|
59 | |
---|
60 | # Trackback source does not return 200 status code |
---|
61 | if ($o->getStatus() != 200) { |
---|
62 | throw new Exception('Invalid Status Code'); |
---|
63 | } |
---|
64 | |
---|
65 | $tb_page = $o->getContent(); |
---|
66 | |
---|
67 | # Do we find a link to post in trackback source? |
---|
68 | if ($S['host'] == $P['host']) { |
---|
69 | $pattern = $P['path'].($P['query'] ? '?'.$P['query'] : ''); |
---|
70 | } else { |
---|
71 | $pattern = $post_url; |
---|
72 | } |
---|
73 | $pattern = preg_quote($pattern,'/'); |
---|
74 | |
---|
75 | if (!preg_match('/'.$pattern.'/',$tb_page)) { |
---|
76 | throw new Exception('Unfair'); |
---|
77 | } |
---|
78 | } |
---|
79 | catch (Exception $e) |
---|
80 | { |
---|
81 | throw new Exception('Trackback not allowed for this URL.'); |
---|
82 | } |
---|
83 | } |
---|
84 | } |
---|
85 | ?> |
---|