root/trunk/includes/smarty_plugins/modifier.linkurl.php

Revision 1, 2.6 KB (checked in by anonymous, 7 years ago)

initial import

Line 
1<?php
2/****************************************************** Open .node ***
3 * Description:   
4 * Status:        Stable.
5 * Author:        Alexandre Dath <alexandre@dotnode.com>
6 * $Id$
7 *
8 * Copyright (C) 2005 Alexandre Dath <alexandre@dotnode.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 ******************** http://opensource.ikse.net/projects/dotnode ***/
24
25/*
26 * Smarty plugin
27 * -------------------------------------------------------------
28 * File:     modifier.linkurl.php
29 * Purpose:  links URLs und shortens it to $length
30 *
31 * Author:   Christoph Erdmann <smarty@cerdmann.com>
32 * Internet: http://www.cerdmann.com
33 *
34 * Changelog:
35 * 2004-11-24 New parameter allows truncation without linking the URL
36 * 2004-11-20 In braces enclosed URLs are now better recognized
37 * -------------------------------------------------------------
38 */
39
40function smarty_modifier_linkurl($string, $length=35, $link=true)
41    {
42    if (!function_exists(kuerzen)) {
43    function kuerzen($string,$length)
44        {
45        $returner = $string;
46        if (strlen($returner) > $length)
47            {
48            $url = preg_match("=[^/]/[^/]=",$returner,$treffer,PREG_OFFSET_CAPTURE);
49            $cutpos = $treffer[0][1]+2;
50            $part[0] = substr($returner,0,$cutpos);
51            $part[1] = substr($returner,$cutpos);
52
53            $strlen1 = $cutpos;
54            if ($strlen1 > $length) return substr($returner,0,$length-3).'...';
55            $strlen2 = strlen($part[1]);
56            $cutpos = $strlen2-($length-3-$strlen1);
57            $returner = $part[0].'...'.substr($part[1],$cutpos);
58            }
59        return $returner;
60        }
61    }
62
63    if ($link == true)
64        {
65        $pattern = '#(^|[^\"=]{1})(http://|ftp://|mailto:|news:)([^\s<>\)]+)([\s\n<>\)]|$)#sme';
66        $string = preg_replace($pattern,"'$1<a href=\"$2$3\" title=\"$2$3\" target=\"_blank\">'.kuerzen('$2$3',$length).'</a>$4'",$string);
67        }
68    elseif ($link == false)
69        {
70        $pattern = '#(^|[^\"=]{1})(http://|ftp://|mailto:|news:)([^\s<>\)]+)([\s\n<>\)]|$)#sme';
71        $string = preg_replace($pattern,"kuerzen('$2$3',$length)",$string);
72        }
73
74    return $string;
75    }
76
77?>
Note: See TracBrowser for help on using the browser.