OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / include / lib / patTemplate / patTemplate / OutputFilter / BBCode.php
1 <?PHP
2 /**
3  * patTemplate BBCode output filter
4  *
5  * $Id: BBCode.php 440 2008-03-30 09:00:16Z fishbone $
6  *
7  * Uses patBBCode.
8  *
9  * @package             patTemplate
10  * @subpackage  Filters
11  * @author              Stephan Schmidt <schst@php.net>
12  */
13
14 /**
15  * patTemplate BBCode output filter
16  *
17  * $Id: BBCode.php 440 2008-03-30 09:00:16Z fishbone $
18  *
19  * Uses patBBCode. Note that patBBCode's syntax is not
20  * entirely the same than the 'official' BBCode. See the
21  * patBBCode projet page for details.
22  *
23  * The following parameters are available:
24  *
25  * - skinDir (required)
26  *   The folder where BBCode templates are stored
27  *   
28  * - reader (required)
29  *   The type of reader to use
30  *
31  * - BBCode (optional)
32  *   A fully configured BBCode objet to use. The other
33  *   two options are not required if you set this.
34  *
35  * @package             patTemplate
36  * @subpackage  Filters
37  * @author              Stephan Schmidt <schst@php.net>
38  * @author              Sebastian Mordziol <argh@php-tools.net>
39  * @link                http://www.php-tools.net/site.php?file=patBBCode/Overview.xml
40  */
41 class patTemplate_OutputFilter_BBCode extends patTemplate_OutputFilter
42 {
43    /**
44     * filter name
45         *
46         * @access       protected
47         * @abstract
48         * @var  string
49         */
50         var     $_name  =       'BBCode';
51
52    /**
53         * BBCode parser
54         *
55         * @access       private
56         * @var          object patBBCode
57         */
58         var $BBCode = null;
59
60    /**
61         * remove all whitespace from the output
62         *
63         * @access       public
64         * @param        string          data
65         * @return       string          data without whitespace
66         */
67         function apply( $data )
68         {
69                 if( !$this->_prepare() )
70                         return $data;
71
72                 $data = $this->BBCode->parseString( $data );
73                         
74                 return $data;
75         }
76
77    /**
78         * prepare BBCode object
79         *
80         * @access       private
81         */
82         function _prepare()
83         {
84                 // there already is a BBCode object
85                 if( is_object( $this->BBCode ) ) {
86                         return true;
87                 }
88                 
89                 // maybe a fully configured BBCode object was provided?
90                 if( isset( $this->_params['BBCode'] ) ) {
91                         $this->BBCode =& $this->_params['BBCode'];
92                         return true;
93                 }
94                 
95                 // include the patBBCode class
96                 if( !class_exists( 'patBBCode' ) )
97                 {
98                         if( !@include_once 'pat/patBBCode.php' )
99                                 return false;
100                 }
101
102                 $this->BBCode = &new patBBCode();
103                 
104                 if( isset( $this->_params['skinDir'] ) )
105                         $this->BBCode->setSkinDir( $this->_params['skinDir'] );
106                 
107                 $reader =& $this->BBCode->createConfigReader( $this->_params['reader'] );
108                 
109                 // give patBBCode the reader we just created
110                 $this->BBCode->setConfigReader( $reader );
111
112                 return true;
113         }
114 }
115 ?>