Dotclear

source: plugins/fairTrackbacks/class.dc.filter.fairtrackbacks.php @ 3874:ab8368569446

Revision 3874:ab8368569446, 2.3 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

short notation for array (array() → [])

RevLine 
[0]1<?php
[3731]2/**
3 * @brief fairTrackbacks, an antispam filter plugin for Dotclear 2
4 *
5 * @package Dotclear
6 * @subpackage Plugins
7 *
8 * @copyright Olivier Meunier & Association Dotclear
9 * @copyright GPL-2.0-only
10 */
11
[3730]12if (!defined('DC_RC_PATH')) {return;}
[0]13
14class dcFilterFairTrackbacks extends dcSpamFilter
15{
[3730]16    public $name    = 'Fair Trackbacks';
17    public $has_gui = false;
18    public $active  = true;
19    public $order   = -10;
[2566]20
[3730]21    public function __construct($core)
22    {
23        parent::__construct($core);
24    }
[2566]25
[3730]26    protected function setInfo()
27    {
28        $this->description = __('Checks trackback source for a link to the post');
29    }
[2566]30
[3730]31    public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status)
32    {
33        if ($type != 'trackback') {
34            return;
35        }
[2566]36
[3730]37        try
38        {
[3874]39            $default_parse = ['scheme' => '', 'host' => '', 'path' => '', 'query' => ''];
[3730]40            $S             = array_merge($default_parse, parse_url($site));
[2566]41
[3730]42            if ($S['scheme'] != 'http' || !$S['host'] || !$S['path']) {
43                throw new Exception('Invalid URL');
44            }
[2566]45
[3730]46            # Check incomink link page
[3874]47            $post     = $this->core->blog->getPosts(['post_id' => $post_id]);
[3730]48            $post_url = $post->getURL();
49            $P        = array_merge($default_parse, parse_url($post_url));
[2566]50
[3730]51            if ($post_url == $site) {
52                throw new Exception('Same source and destination');
53            }
[2566]54
[3730]55            $o = netHttp::initClient($site, $path);
56            $o->setTimeout(3);
57            $o->get($path);
[2566]58
[3730]59            # Trackback source does not return 200 status code
60            if ($o->getStatus() != 200) {
61                throw new Exception('Invalid Status Code');
62            }
[2566]63
[3730]64            $tb_page = $o->getContent();
[2566]65
[3730]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, '/');
[2566]73
[3730]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    }
[0]81}
Note: See TracBrowser for help on using the repository browser.

Sites map