| 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 | |
|---|
| 30 | /// Name: Url filter |
|---|
| 31 | /// Author: Marco Bonetti |
|---|
| 32 | /// Description: This plugin will try to make ugly URL links look better |
|---|
| 33 | /// Version: 1.9 |
|---|
| 34 | |
|---|
| 35 | /** |
|---|
| 36 | * Replaces a link in the form <a href="http://www.test.com/a/b/c.html>http://www.test.com/a/b/c.html</a> |
|---|
| 37 | * with a nicer <a href="http://www.test.com/a/b/c.html">[test.com]</a> |
|---|
| 38 | */ |
|---|
| 39 | |
|---|
| 40 | function __urlfilter_filter($in) { |
|---|
| 41 | $match = '#<a[^>]+?href="(.*?)">\\1</a>#im'; |
|---|
| 42 | // matches non-linkified URLs |
|---|
| 43 | $match2 = '#[^>"\'/=\?](http[^\s<$]+)[\s$]?#im'; |
|---|
| 44 | $ret= preg_replace_callback($match, '__filter_callback', $in); |
|---|
| 45 | $ret2= preg_replace_callback($match2,'__filter_callback', $ret); |
|---|
| 46 | return $ret2; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | /** |
|---|
| 50 | * We need a callback because for some obscure reason the /ie modifier wouldnt work |
|---|
| 51 | * in preg_replace alone. This basically formats the output |
|---|
| 52 | */ |
|---|
| 53 | function __filter_callback($matches) { |
|---|
| 54 | $ret = preg_match("/^(http:\/\/)?([^\/<]+)/i", $matches[1], $outmatches); |
|---|
| 55 | if ($outmatches && isset ($outmatches[2])) { |
|---|
| 56 | return " <a href=\"". $matches[1]."\">[" . $outmatches[2] . "]</a> "; |
|---|
| 57 | } |
|---|
| 58 | return " <a href=\"". $matches[1]."\">[" . $matches[1] . "]</a> "; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | rss_set_hook('rss.plugins.import.description','__urlfilter_filter'); |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | ?> |
|---|