home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / Links.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  3.3 KB  |  86 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Stijn de Reede <sjr@gmx.co.uk>                               |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Links.php,v 1.5 2004/02/05 16:39:45 sjr Exp $
  20. //
  21.  
  22. /**
  23. * @package  HTML_BBCodeParser
  24. * @author   Stijn de Reede  <sjr@gmx.co.uk>
  25. */
  26.  
  27.  
  28. require_once('HTML/BBCodeParser.php');
  29.  
  30.  
  31.  
  32.  
  33. class HTML_BBCodeParser_Filter_Links extends HTML_BBCodeParser
  34. {
  35.  
  36.     /**
  37.     * An array of tags parsed by the engine
  38.     *
  39.     * @access   private
  40.     * @var      array
  41.     */
  42.     var $_definedTags = array(  'url' => array( 'htmlopen'  => 'a',
  43.                                                 'htmlclose' => 'a',
  44.                                                 'allowed'   => 'none^img',
  45.                                                 'attributes'=> array(   'url'   => 'href=%2$s%1$s%2$s',
  46.                                                                         't'     => 'target=%2$s%1$s%2$s')
  47.                                                )
  48.                               );
  49.  
  50.  
  51.     /**
  52.     * Executes statements before the actual array building starts
  53.     *
  54.     * This method should be overwritten in a filter if you want to do
  55.     * something before the parsing process starts. This can be useful to
  56.     * allow certain short alternative tags which then can be converted into
  57.     * proper tags with preg_replace() calls.
  58.     * The main class walks through all the filters and and calls this
  59.     * method if it exists. The filters should modify their private $_text
  60.     * variable.
  61.     *
  62.     * @return   none
  63.     * @access   private
  64.     * @see      $_text
  65.     * @author   Stijn de Reede  <sjr@gmx.co.uk>
  66.     */
  67.     function _preparse()
  68.     {
  69.         $options = PEAR::getStaticProperty('HTML_BBCodeParser','_options');
  70.         $o = $options['open'];
  71.         $c = $options['close'];
  72.         $oe = $options['open_esc'];
  73.         $ce = $options['close_esc'];
  74.         $pattern = array(   "!(^|\s|\()((((http(s?)|ftp)://)|www)[-a-z0-9.]+\.[a-z]{2,4}[^\s()]*)!i",
  75.                             "!".$oe."url(".$ce."|\s.*".$ce.")(.*)".$oe."/url".$ce."!iU");
  76.         $replace = array(   "\\1".$o."url".$c."\\2".$o."/url".$c,
  77.                             $o."url=\\2\\1\\2".$o."/url".$c);
  78.         $this->_preparsed = preg_replace($pattern, $replace, $this->_text);
  79.     }
  80.  
  81.  
  82. }
  83.  
  84.  
  85. ?>
  86.