Dotclear

source: plugins/antispam/inc/lib.dc.antispam.url.php @ 3730:5c45a5df9a59

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

Code formatting (PSR-2)

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Antispam, a plugin for 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 dcAntispamURL extends dcUrlHandlers
15{
16    public static function hamFeed($args)
17    {
18        self::genFeed('ham', $args);
19    }
20
21    public static function spamFeed($args)
22    {
23        self::genFeed('spam', $args);
24    }
25
26    private static function genFeed($type, $args)
27    {
28        global $core;
29        $user_id = dcAntispam::checkUserCode($core, $args);
30
31        if ($user_id === false) {
32            self::p404();
33            return;
34        }
35
36        $core->auth->checkUser($user_id, null, null);
37
38        header('Content-Type: application/xml; charset=UTF-8');
39
40        $title   = $core->blog->name . ' - ' . __('Spam moderation') . ' - ';
41        $params  = array();
42        $end_url = '';
43        if ($type == 'spam') {
44            $title .= __('Spam');
45            $params['comment_status'] = -2;
46            $end_url                  = '?status=-2';
47        } else {
48            $title .= __('Ham');
49            $params['sql'] = ' AND comment_status IN (1,-1) ';
50        }
51
52        echo
53        '<?xml version="1.0" encoding="utf-8"?>' . "\n" .
54        '<rss version="2.0"' . "\n" .
55        'xmlns:dc="http://purl.org/dc/elements/1.1/"' . "\n" .
56        'xmlns:content="http://purl.org/rss/1.0/modules/content/">' . "\n" .
57        '<channel>' . "\n" .
58        '<title>' . html::escapeHTML($title) . '</title>' . "\n" .
59            '<link>' . (DC_ADMIN_URL ? DC_ADMIN_URL . 'comments.php' . $end_url : 'about:blank') . '</link>' . "\n" .
60            '<description></description>' . "\n";
61
62        $rs       = $core->blog->getComments($params);
63        $maxitems = 20;
64        $nbitems  = 0;
65
66        while ($rs->fetch() && ($nbitems < $maxitems)) {
67            $nbitems++;
68            $uri    = DC_ADMIN_URL ? DC_ADMIN_URL . 'comment.php?id=' . $rs->comment_id : 'about:blank';
69            $author = $rs->comment_author;
70            $title  = $rs->post_title . ' - ' . $author;
71            if ($type == 'spam') {
72                $title .= '(' . $rs->comment_spam_filter . ')';
73            }
74            $id = $rs->getFeedID();
75
76            $content = '<p>IP: ' . $rs->comment_ip;
77
78            if (trim($rs->comment_site)) {
79                $content .= '<br />URL: <a href="' . $rs->comment_site . '">' . $rs->comment_site . '</a>';
80            }
81            $content .= "</p><hr />\n";
82            $content .= $rs->comment_content;
83
84            echo
85            '<item>' . "\n" .
86            '  <title>' . html::escapeHTML($title) . '</title>' . "\n" .
87            '  <link>' . $uri . '</link>' . "\n" .
88            '  <guid>' . $id . '</guid>' . "\n" .
89            '  <pubDate>' . $rs->getRFC822Date() . '</pubDate>' . "\n" .
90            '  <dc:creator>' . html::escapeHTML($author) . '</dc:creator>' . "\n" .
91            '  <description>' . html::escapeHTML($content) . '</description>' . "\n" .
92                '</item>';
93        }
94
95        echo "</channel>\n</rss>";
96    }
97}
Note: See TracBrowser for help on using the repository browser.

Sites map