root/trunk/gregarius/plugins/sanitizer.php

Revision 1181, 2.6 kB (checked in by mbonetti, 3 years ago)

Copyright (C) 2003 - 2006
(and s'more stuff thrown in)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2###############################################################################
3# Gregarius - A PHP based RSS aggregator.
4# Copyright (C) 2003 - 2006 Marco Bonetti
5#
6###############################################################################
7# This program is free software and open source software; you can redistribute
8# it and/or modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 2 of the License,
10# or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful, but WITHOUT
13# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15# more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  or visit
20# http://www.gnu.org/licenses/gpl.html
21#
22###############################################################################
23# E-mail:      mbonetti at gmail dot com
24# Web page:    http://gregarius.net/
25#
26###############################################################################
27
28
29/// Name: HTML filter
30/// Author: Marco Bonetti
31/// Description: This plugin fixes some common xhtml markup errors
32/// Version: 1.2
33
34function __endslash($in) {
35        $wrk = trim($in);
36        if (substr($wrk,-1) == '/') {
37                return $wrk;
38        } else {
39                return ($wrk ." /");
40        }
41}
42
43function __escape_ampersands($in) {
44        return str_replace('& ','&amp; ',$in);
45}
46
47function __sanitize($in) {
48       
49        $output= __escape_ampersands($in);
50        //<br />
51        $output = preg_replace('/<br\s?\/?>/i','<br />',$output);
52        //<img>
53        $output = preg_replace("/<img([^>]*)alt=([^>]*)>/im", "<img$1`alt=$2>", $output);
54        $output = preg_replace("/<img([^`|>]*)>/im", "<img alt=\"\"$1>", $output);
55        $output = preg_replace("/<img([^>]*)`alt=([^>]*)>/im", "<img$1alt=$2>", $output);
56        $output = preg_replace('/<img([^>]+)>/eim',"'<img '.__endslash('\\1').'>'",$output);
57
58        //lowercase tags
59        // Removed: Fix for #111.
60        //$output = preg_replace('/<([^\s]+)/eim',"'<'.strtolower('\\1')",$output);
61       
62        //blockquotes
63        $output = str_replace('<blockquote><p>','<blockquote>',$output);
64        $output = str_replace('</p></blockquote>','</blockquote>',$output);
65        $output = str_replace('<blockquote>','<blockquote><p>',$output);
66        $output = str_replace('</blockquote>','</p></blockquote>',$output);
67       
68        return stripslashes($output);
69}
70
71rss_set_hook('rss.plugins.import.description','__sanitize');
72
73//$in = "<img src=\"http://ok\" alt=\"alt\" /><BR><img src=\"http://nok\">";
74//echo __sanitize($in) . "\n";
75?>
Note: See TracBrowser for help on using the browser.