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