Dotclear

source: plugins/fairTrackbacks/class.dc.filter.fairtrackbacks.php @ 3730:5c45a5df9a59

Revision 3730:5c45a5df9a59, 2.5 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Code formatting (PSR-2)

Line 
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 -----------------------------------------
12if (!defined('DC_RC_PATH')) {return;}
13
14class 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    public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status)
32    {
33        if ($type != 'trackback') {
34            return;
35        }
36
37        try
38        {
39            $default_parse = array('scheme' => '', 'host' => '', 'path' => '', 'query' => '');
40            $S             = array_merge($default_parse, parse_url($site));
41
42            if ($S['scheme'] != 'http' || !$S['host'] || !$S['path']) {
43                throw new Exception('Invalid URL');
44            }
45
46            # Check incomink link page
47            $post     = $this->core->blog->getPosts(array('post_id' => $post_id));
48            $post_url = $post->getURL();
49            $P        = array_merge($default_parse, parse_url($post_url));
50
51            if ($post_url == $site) {
52                throw new Exception('Same source and destination');
53            }
54
55            $o = netHttp::initClient($site, $path);
56            $o->setTimeout(3);
57            $o->get($path);
58
59            # Trackback source does not return 200 status code
60            if ($o->getStatus() != 200) {
61                throw new Exception('Invalid Status Code');
62            }
63
64            $tb_page = $o->getContent();
65
66            # Do we find a link to post in trackback source?
67            if ($S['host'] == $P['host']) {
68                $pattern = $P['path'] . ($P['query'] ? '?' . $P['query'] : '');
69            } else {
70                $pattern = $post_url;
71            }
72            $pattern = preg_quote($pattern, '/');
73
74            if (!preg_match('/' . $pattern . '/', $tb_page)) {
75                throw new Exception('Unfair');
76            }
77        } catch (Exception $e) {
78            throw new Exception('Trackback not allowed for this URL.');
79        }
80    }
81}
Note: See TracBrowser for help on using the repository browser.

Sites map