2001-04-19 13:18:57 +00:00
< ? php
2003-08-28 20:50:20 +00:00
// -------------------------------------------------------------
//
// $Id$
//
// FILENAME : bbcode.php
// STARTED : Sat Feb 13, 2001
// COPYRIGHT : <20> 2001, 2003 phpBB Group
// WWW : http://www.phpbb.com/
// LICENCE : GPL vs2.0 [ see /docs/COPYING ]
//
// -------------------------------------------------------------
2001-08-30 22:20:23 +00:00
2003-04-11 00:19:29 +00:00
class bbcode
2002-03-18 13:35:23 +00:00
{
2003-04-11 00:19:29 +00:00
var $bbcode_uid = '' ;
var $bbcode_bitfield = 0 ;
var $bbcode_cache = array ();
2003-06-24 16:46:30 +00:00
var $bbcode_template = array ();
2001-08-02 08:36:38 +00:00
2003-08-10 18:30:27 +00:00
var $template_bitfield = 0 ;
var $template_filename = '' ;
2003-04-16 22:44:38 +00:00
function bbcode ( $bitfield = 0 )
2001-04-19 13:18:57 +00:00
{
2003-04-16 22:44:38 +00:00
if ( $bitfield )
{
$this -> bbcode_bitfield = $bitfield ;
$this -> bbcode_cache_init ();
}
2001-04-19 13:18:57 +00:00
}
2001-08-02 08:36:38 +00:00
2003-07-02 22:23:45 +00:00
function bbcode_second_pass ( & $message , $bbcode_uid = '' , $bbcode_bitfield = FALSE )
2001-04-19 13:18:57 +00:00
{
2003-04-11 00:19:29 +00:00
if ( $bbcode_uid )
2001-10-24 22:52:24 +00:00
{
2003-04-11 00:19:29 +00:00
$this -> bbcode_uid = $bbcode_uid ;
}
2003-04-23 21:47:15 +00:00
2003-07-02 22:23:45 +00:00
if ( $bbcode_bitfield !== FALSE )
2003-04-11 00:19:29 +00:00
{
$this -> bbcode_bitfield = $bbcode_bitfield ;
2004-05-30 19:24:53 +00:00
// Init those added with a new bbcode_bitfield (already stored codes will not get parsed again)
$this -> bbcode_cache_init ();
2001-10-24 22:52:24 +00:00
}
2004-05-30 19:24:53 +00:00
2003-07-02 22:23:45 +00:00
if ( ! $this -> bbcode_bitfield )
2003-04-23 21:47:15 +00:00
{
2003-05-11 16:21:35 +00:00
return $message ;
2003-04-23 21:47:15 +00:00
}
2002-10-30 00:57:27 +00:00
2003-04-11 00:19:29 +00:00
$str = array ( 'search' => array (), 'replace' => array ());
$preg = array ( 'search' => array (), 'replace' => array ());
2001-04-19 13:18:57 +00:00
2003-04-16 22:44:38 +00:00
$bitlen = strlen ( decbin ( $this -> bbcode_bitfield ));
for ( $bbcode_id = 0 ; $bbcode_id < $bitlen ; ++ $bbcode_id )
2001-04-19 13:18:57 +00:00
{
2003-07-02 22:23:45 +00:00
if ( $this -> bbcode_bitfield & ( 1 << $bbcode_id ))
2001-04-19 13:18:57 +00:00
{
2003-08-28 20:50:20 +00:00
if ( ! empty ( $this -> bbcode_cache [ $bbcode_id ]))
2002-01-08 15:51:43 +00:00
{
2003-08-28 20:50:20 +00:00
foreach ( $this -> bbcode_cache [ $bbcode_id ] as $type => $array )
2001-10-24 22:52:24 +00:00
{
2003-08-28 20:50:20 +00:00
foreach ( $array as $search => $replace )
{
${$type} [ 'search' ][] = str_replace ( '$uid' , $this -> bbcode_uid , $search );
${$type} [ 'replace' ][] = $replace ;
}
2001-10-24 22:52:24 +00:00
}
2001-04-19 13:18:57 +00:00
}
}
2003-04-11 00:19:29 +00:00
}
2003-04-16 22:44:38 +00:00
if ( count ( $str [ 'search' ]))
{
$message = str_replace ( $str [ 'search' ], $str [ 'replace' ], $message );
}
if ( count ( $preg [ 'search' ]))
{
$message = preg_replace ( $preg [ 'search' ], $preg [ 'replace' ], $message );
}
2001-08-02 08:36:38 +00:00
2003-08-28 20:50:20 +00:00
// Remove the uid from tags that have not been transformed into HTML
$message = str_replace ( ':' . $this -> bbcode_uid , '' , $message );
2003-04-11 00:19:29 +00:00
}
//
// bbcode_cache_init()
//
// requires: $this->bbcode_bitfield
// sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield
//
function bbcode_cache_init ()
{
2003-08-28 20:50:20 +00:00
global $user , $phpbb_root_path ;
2003-08-10 18:30:27 +00:00
if ( empty ( $this -> template_filename ))
{
$style = 'primary' ;
if ( ! empty ( $user -> theme [ 'secondary' ]))
{
2003-08-28 20:50:20 +00:00
// If the primary style has custom templates for BBCodes then we'll make sure
// the bbcode.html file is present, otherwise we'll use the secondary style
2003-04-11 00:19:29 +00:00
2003-08-28 20:50:20 +00:00
if ( $this -> bbcode_bitfield & $user -> theme [ 'primary' ][ 'bbcode_bitfield' ])
2003-08-10 18:30:27 +00:00
{
$style = ( file_exists ( $phpbb_root_path . 'styles/templates/' . $user -> theme [ 'primary' ][ 'template_path' ] . '/bbcode.html' )) ? 'primary' : 'secondary' ;
}
}
$this -> template_bitfield = $user -> theme [ $style ][ 'bbcode_bitfield' ];
2003-08-11 10:41:03 +00:00
$this -> template_filename = $phpbb_root_path . 'styles/' . $user -> theme [ $style ][ 'template_path' ] . '/template/bbcode.html' ;
2003-08-10 18:30:27 +00:00
}
$sql = '' ;
2003-04-11 00:19:29 +00:00
$bbcode_ids = array ();
2003-04-16 22:44:38 +00:00
$bitlen = strlen ( decbin ( $this -> bbcode_bitfield ));
for ( $bbcode_id = 0 ; $bbcode_id < $bitlen ; ++ $bbcode_id )
2003-04-11 00:19:29 +00:00
{
2003-07-02 22:23:45 +00:00
if ( isset ( $this -> bbcode_cache [ $bbcode_id ]) || ! ( $this -> bbcode_bitfield & ( 1 << $bbcode_id )))
2003-04-16 22:44:38 +00:00
{
2003-06-05 19:19:48 +00:00
// do not try to re-cache it if it's already in
2003-04-16 22:44:38 +00:00
continue ;
}
2003-11-16 22:28:47 +00:00
$bbcode_ids [] = $bbcode_id ;
2003-04-11 00:19:29 +00:00
2004-02-08 18:02:17 +00:00
if ( $bbcode_id > NUM_CORE_BBCODES )
2001-04-19 13:18:57 +00:00
{
2003-08-28 20:50:20 +00:00
$sql .= (( $sql ) ? ',' : '' ) . $bbcode_id ;
2001-04-19 13:18:57 +00:00
}
2003-04-11 00:19:29 +00:00
}
2003-08-28 20:50:20 +00:00
2003-04-11 00:19:29 +00:00
if ( $sql )
{
global $db ;
$rowset = array ();
2001-08-02 08:36:38 +00:00
2003-08-28 20:50:20 +00:00
$sql = ' SELECT *
2003-05-22 01:26:36 +00:00
FROM ' . BBCODES_TABLE . "
2003-08-28 20:50:20 +00:00
WHERE bbcode_id IN ( $sql ) " ;
2001-08-02 08:36:38 +00:00
2003-04-11 00:19:29 +00:00
$result = $db -> sql_query ( $sql );
while ( $row = $db -> sql_fetchrow ( $result ))
{
$rowset [ $row [ 'bbcode_id' ]] = $row ;
}
2003-04-16 22:44:38 +00:00
$db -> sql_freeresult ( $result );
2003-04-11 00:19:29 +00:00
}
2003-05-22 01:26:36 +00:00
2003-04-11 00:19:29 +00:00
foreach ( $bbcode_ids as $bbcode_id )
{
switch ( $bbcode_id )
{
case 0 :
$this -> bbcode_cache [ $bbcode_id ] = array (
'str' => array (
2003-05-22 01:26:36 +00:00
'[quote:$uid]' => $this -> bbcode_tpl ( 'quote_open' , $bbcode_id ),
'[/quote:$uid]' => $this -> bbcode_tpl ( 'quote_close' , $bbcode_id )
2003-04-11 00:19:29 +00:00
),
'preg' => array (
2003-09-07 18:11:37 +00:00
'#\[quote="(.*?)":$uid\]#' => $this -> bbcode_tpl ( 'quote_username_open' , $bbcode_id )
2003-04-11 00:19:29 +00:00
)
);
break ;
case 1 :
2003-05-22 01:26:36 +00:00
$this -> bbcode_cache [ $bbcode_id ] = array ( 'str' => array (
'[b:$uid]' => $this -> bbcode_tpl ( 'b_open' , $bbcode_id ),
'[/b:$uid]' => $this -> bbcode_tpl ( 'b_close' , $bbcode_id )
));
2003-04-11 00:19:29 +00:00
break ;
case 2 :
2003-05-22 01:26:36 +00:00
$this -> bbcode_cache [ $bbcode_id ] = array ( 'str' => array (
'[i:$uid]' => $this -> bbcode_tpl ( 'i_open' , $bbcode_id ),
'[/i:$uid]' => $this -> bbcode_tpl ( 'i_close' , $bbcode_id )
));
2003-04-11 00:19:29 +00:00
break ;
case 3 :
2003-05-22 01:26:36 +00:00
$this -> bbcode_cache [ $bbcode_id ] = array ( 'preg' => array (
'#\[url:$uid\]((.*?))\[/url:$uid\]#s' => $this -> bbcode_tpl ( 'url' , $bbcode_id ),
'#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s' => $this -> bbcode_tpl ( 'url' , $bbcode_id )
));
2003-04-11 00:19:29 +00:00
break ;
case 4 :
2003-10-12 11:59:23 +00:00
if ( $user -> optionget ( 'viewimg' ))
2003-05-20 13:24:23 +00:00
{
2003-05-22 01:26:36 +00:00
$this -> bbcode_cache [ $bbcode_id ] = array ( 'preg' => array (
'#\[img:$uid\](.*?)\[/img:$uid\]#s' => $this -> bbcode_tpl ( 'img' , $bbcode_id )
));
2003-05-20 13:24:23 +00:00
}
else
{
2003-05-22 01:26:36 +00:00
$this -> bbcode_cache [ $bbcode_id ] = array ( 'preg' => array (
2003-08-28 20:50:20 +00:00
'#\[img:$uid\](.*?)\[/img:$uid\]#s' => str_replace ( '$2' , '[ img ]' , $this -> bbcode_tpl ( 'url' , $bbcode_id ))
2003-05-22 01:26:36 +00:00
));
2003-05-20 13:24:23 +00:00
}
2003-05-22 01:26:36 +00:00
break ;
2003-04-11 00:19:29 +00:00
case 5 :
2003-05-22 01:26:36 +00:00
$this -> bbcode_cache [ $bbcode_id ] = array ( 'preg' => array (
'#\[size=([\-\+]?[1-2]?[0-9]):$uid\](.*?)\[/size:$uid\]#s' => $this -> bbcode_tpl ( 'size' , $bbcode_id )
));
2003-04-11 00:19:29 +00:00
break ;
case 6 :
2003-05-22 01:26:36 +00:00
$this -> bbcode_cache [ $bbcode_id ] = array ( 'preg' => array (
'!\[color=(#[0-9A-F]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!s' => $this -> bbcode_tpl ( 'color' , $bbcode_id )
));
2003-04-11 00:19:29 +00:00
break ;
case 7 :
2003-05-22 01:26:36 +00:00
$this -> bbcode_cache [ $bbcode_id ] = array ( 'str' => array (
'[u:$uid]' => $this -> bbcode_tpl ( 'u_open' , $bbcode_id ),
'[/u:$uid]' => $this -> bbcode_tpl ( 'u_close' , $bbcode_id )
));
2003-04-11 00:19:29 +00:00
break ;
case 8 :
2003-05-22 01:26:36 +00:00
$this -> bbcode_cache [ $bbcode_id ] = array ( 'preg' => array (
2003-08-28 20:50:20 +00:00
'#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise' => " \$ this->bbcode_second_pass_code(' \$ 1', ' \$ 2') "
2003-05-22 01:26:36 +00:00
));
2003-04-11 00:19:29 +00:00
break ;
case 9 :
$this -> bbcode_cache [ $bbcode_id ] = array (
'str' => array (
2003-11-16 22:28:47 +00:00
'[list:$uid]' => $this -> bbcode_tpl ( 'ulist_open_default' , $bbcode_id ),
'[/list:u:$uid]' => $this -> bbcode_tpl ( 'ulist_close' , $bbcode_id ),
'[/list:o:$uid]' => $this -> bbcode_tpl ( 'olist_close' , $bbcode_id ),
'[*:$uid]' => $this -> bbcode_tpl ( 'listitem' , $bbcode_id ),
'[/*:$uid]' => $this -> bbcode_tpl ( 'listitem_close' , $bbcode_id ),
'[/*:m:$uid]' => $this -> bbcode_tpl ( 'listitem_close' , $bbcode_id )
2003-04-11 00:19:29 +00:00
),
'preg' => array (
2003-08-28 20:50:20 +00:00
'#\[list=([^\[]+):$uid\]#e' => " \$ this->bbcode_list(' \$ 1') " ,
2003-04-11 00:19:29 +00:00
)
);
break ;
case 10 :
2003-05-22 01:26:36 +00:00
$this -> bbcode_cache [ $bbcode_id ] = array ( 'preg' => array (
2003-08-28 20:50:20 +00:00
'#\[email:$uid\]((.*?))\[/email:$uid\]#is' => $this -> bbcode_tpl ( 'email' , $bbcode_id ),
2003-05-22 01:26:36 +00:00
'#\[email=([^\[]+):$uid\](.*?)\[/email:$uid\]#is' => $this -> bbcode_tpl ( 'email' , $bbcode_id )
));
2003-04-11 00:19:29 +00:00
break ;
2003-04-16 22:44:38 +00:00
case 11 :
2003-10-12 11:59:23 +00:00
if ( $user -> optionget ( 'viewflash' ))
2003-05-20 13:24:23 +00:00
{
2003-05-22 01:26:36 +00:00
$this -> bbcode_cache [ $bbcode_id ] = array ( 'preg' => array (
2003-05-25 19:19:31 +00:00
'#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => $this -> bbcode_tpl ( 'flash' , $bbcode_id )
2003-05-22 01:26:36 +00:00
));
2003-05-20 13:24:23 +00:00
}
else
{
2003-05-22 01:26:36 +00:00
$this -> bbcode_cache [ $bbcode_id ] = array ( 'preg' => array (
2003-08-28 20:50:20 +00:00
'#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => str_replace ( '$1' , '$3' , str_replace ( '$2' , '[ flash ]' , $this -> bbcode_tpl ( 'url' , $bbcode_id )))
2003-05-22 01:26:36 +00:00
));
2003-05-20 13:24:23 +00:00
}
2003-05-22 01:26:36 +00:00
break ;
2004-02-08 18:02:17 +00:00
case 12 :
$this -> bbcode_cache [ $bbcode_id ] = array ( 'preg' => array (
'#\[attachment=([0-9]+):$uid\]#' => $this -> bbcode_tpl ( 'inline_attachment_open' , $bbcode_id ),
'#\[\/attachment:$uid\]#' => $this -> bbcode_tpl ( 'inline_attachment_close' , $bbcode_id )
));
break ;
2003-04-11 00:19:29 +00:00
default :
if ( isset ( $rowset [ $bbcode_id ]))
{
2003-08-28 20:50:20 +00:00
if ( $this -> template_bitfield & ( 1 << $bbcode_id ))
{
// The bbcode requires a custom template to be loaded
if ( ! $bbcode_tpl = $this -> bbcode_tpl ( $rowset [ $bbcode_id ][ 'bbcode_tag' ], $bbcode_id ))
{
// For some reason, the required template seems not to be available,
// use the default template
$bbcode_tpl = ( ! empty ( $rowset [ $bbcode_id ][ 'second_pass_replace' ])) ? $rowset [ $bbcode_id ][ 'second_pass_replace' ] : $rowset [ $bbcode_id ][ 'bbcode_tpl' ];
}
else
{
// In order to use templates with custom bbcodes we need
// to replace all {VARS} to corresponding backreferences
// Note that backreferences are numbered from bbcode_match
if ( preg_match_all ( '/\{(URL|EMAIL|TEXT|COLOR|NUMBER)[0-9]*\}/' , $rowset [ $bbcode_id ][ 'bbcode_match' ], $m ))
{
foreach ( $m [ 0 ] as $i => $tok )
{
$bbcode_tpl = str_replace ( $tok , '$' . ( $i + 1 ), $bbcode_tpl );
}
}
}
}
else
{
// Default template
$bbcode_tpl = ( ! empty ( $rowset [ $bbcode_id ][ 'second_pass_replace' ])) ? $rowset [ $bbcode_id ][ 'second_pass_replace' ] : $rowset [ $bbcode_id ][ 'bbcode_tpl' ];
}
// Replace {L_*} lang strings
$bbcode_tpl = preg_replace ( '/{L_([A-Z_]+)}/e' , " (!empty( \$ user->lang[' \$ 1'])) ? \$ user->lang[' \$ 1'] : ucwords(strtolower(str_replace'_', ' ', ' \$ 1'))) " , $bbcode_tpl );
if ( ! empty ( $rowset [ $bbcode_id ][ 'second_pass_replace' ]))
{
// The custom BBCode requires second-pass pattern replacements
$this -> bbcode_cache [ $bbcode_id ] = array (
'preg' => array ( $rowset [ $bbcode_id ][ 'second_pass_match' ] => $bbcode_tpl )
);
}
else
{
$this -> bbcode_cache [ $bbcode_id ] = array (
'str' => array ( $rowset [ $bbcode_id ][ 'second_pass_match' ] => $bbcode_tpl )
);
}
2001-04-19 13:18:57 +00:00
}
else
{
2003-08-28 20:50:20 +00:00
$this -> bbcode_cache [ $bbcode_id ] = FALSE ;
2001-04-19 13:18:57 +00:00
}
}
}
2003-04-11 00:19:29 +00:00
}
2003-04-23 21:47:15 +00:00
2003-05-25 19:19:31 +00:00
function bbcode_tpl ( $tpl_name , $bbcode_id = - 1 )
2003-04-23 21:47:15 +00:00
{
2003-06-24 16:46:30 +00:00
if ( empty ( $bbcode_hardtpl ))
{
static $bbcode_hardtpl = array (
2003-11-16 22:28:47 +00:00
'b_open' => '<span style="font-weight: bold">' ,
'b_close' => '</span>' ,
'i_open' => '<span style="font-style: italic">' ,
'i_close' => '</span>' ,
'u_open' => '<span style="text-decoration: underline">' ,
'u_close' => '</span>' ,
'url' => '<a href="$1" target="_blank">$2</a>' ,
'img' => '<img src="$1" border="0" />' ,
'size' => '<span style="font-size: $1px; line-height: normal">$2</span>' ,
'color' => '<span style="color: $1">$2</span>' ,
'email' => '<a href="mailto:$1">$2</a>'
2003-06-24 16:46:30 +00:00
);
}
2003-08-10 18:30:27 +00:00
if ( $bbcode_id != - 1 && ! ( $this -> template_bitfield & ( 1 << $bbcode_id )))
2003-04-23 21:47:15 +00:00
{
2003-08-28 20:50:20 +00:00
return ( isset ( $bbcode_hardtpl [ $tpl_name ])) ? $bbcode_hardtpl [ $tpl_name ] : FALSE ;
2003-05-22 01:26:36 +00:00
}
2003-04-23 21:47:15 +00:00
2003-06-24 16:46:30 +00:00
if ( empty ( $this -> bbcode_template ))
2003-05-22 01:26:36 +00:00
{
2003-08-10 21:17:11 +00:00
if ( ! ( $fp = @ fopen ( $this -> template_filename , 'rb' )))
2003-04-23 21:47:15 +00:00
{
trigger_error ( 'Could not load bbcode template' );
}
2003-08-10 18:30:27 +00:00
$tpl = fread ( $fp , filesize ( $this -> template_filename ));
2003-04-23 21:47:15 +00:00
@ fclose ( $fp );
// replace \ with \\ and then ' with \'.
$tpl = str_replace ( '\\' , '\\\\' , $tpl );
$tpl = str_replace ( " ' " , " \ ' " , $tpl );
2003-05-22 01:26:36 +00:00
// strip newlines and indent
$tpl = preg_replace ( " / \n [ \n \r \ s \t ]*/ " , '' , $tpl );
2003-04-23 21:47:15 +00:00
// Turn template blocks into PHP assignment statements for the values of $bbcode_tpl..
2003-08-28 20:50:20 +00:00
$tpl = preg_replace ( '#<!-- BEGIN (.*?) -->(.*?)<!-- END (.*?) -->#' , " \n " . " \$ this->bbcode_template[' \$ 1'] = \$ this->bbcode_tpl_replace(' \$ 1',' \$ 2'); " , $tpl );
2003-04-23 21:47:15 +00:00
2003-06-24 16:46:30 +00:00
$this -> bbcode_template = array ();
2003-04-23 21:47:15 +00:00
eval ( $tpl );
2003-05-22 01:26:36 +00:00
}
2003-04-23 21:47:15 +00:00
2003-08-28 20:50:20 +00:00
return ( isset ( $this -> bbcode_template [ $tpl_name ])) ? $this -> bbcode_template [ $tpl_name ] : (( isset ( $bbcode_hardtpl [ $tpl_name ])) ? $bbcode_hardtpl [ $tpl_name ] : FALSE );
2003-05-22 01:26:36 +00:00
}
function bbcode_tpl_replace ( $tpl_name , $tpl )
{
static $replacements = array (
2003-08-28 20:50:20 +00:00
'quote_username_open' => array ( '{USERNAME}' => '$1' ),
2003-11-16 22:28:47 +00:00
'color' => array ( '{COLOR}' => '$1' , '{TEXT}' => '$2' ),
'size' => array ( '{SIZE}' => '$1' , '{TEXT}' => '$2' ),
'img' => array ( '{URL}' => '$1' ),
'flash' => array ( '{WIDTH}' => '$1' , '{HEIGHT}' => '$2' , '{URL}' => '$3' ),
'url' => array ( '{URL}' => '$1' , '{DESCRIPTION}' => '$2' ),
'email' => array ( '{EMAIL}' => '$1' , '{DESCRIPTION}' => '$2' )
2003-05-22 01:26:36 +00:00
);
2003-05-18 23:26:05 +00:00
2003-08-28 20:50:20 +00:00
$tpl = preg_replace ( '/{L_([A-Z_]+)}/e' , " (!empty( \$ user->lang[' \$ 1'])) ? \$ user->lang[' \$ 1'] : ucwords(strtolower(str_replace('_', ' ', ' \$ 1'))) " , $tpl );
2003-05-22 01:26:36 +00:00
if ( ! empty ( $replacements [ $tpl_name ]))
{
$tpl = strtr ( $tpl , $replacements [ $tpl_name ]);
2003-04-23 21:47:15 +00:00
}
2003-05-22 01:26:36 +00:00
return trim ( $tpl );
2003-04-23 21:47:15 +00:00
}
2003-04-11 00:19:29 +00:00
2003-06-05 19:19:48 +00:00
function bbcode_list ( $type )
2001-04-19 13:18:57 +00:00
{
2003-06-05 19:19:48 +00:00
if ( $type == '' )
2003-04-11 00:19:29 +00:00
{
2003-06-05 19:19:48 +00:00
$tpl = 'ulist_open_default' ;
$type = 'default' ;
$start = 0 ;
}
elseif ( $type == 'i' )
{
$tpl = 'olist_open' ;
2003-05-18 23:26:05 +00:00
$type = 'lower-roman' ;
$start = 1 ;
}
elseif ( $type == 'I' )
{
2003-06-05 19:19:48 +00:00
$tpl = 'olist_open' ;
2003-05-18 23:26:05 +00:00
$type = 'upper-roman' ;
$start = 1 ;
2003-04-11 00:19:29 +00:00
}
2003-05-18 23:26:05 +00:00
elseif ( preg_match ( '#^(disc|circle|square)$#i' , $type ))
2003-04-11 00:19:29 +00:00
{
2003-06-05 19:19:48 +00:00
$tpl = 'ulist_open' ;
2003-05-18 23:26:05 +00:00
$type = strtolower ( $type );
2003-04-11 00:19:29 +00:00
$start = 1 ;
}
2003-05-18 23:26:05 +00:00
elseif ( preg_match ( '#^[a-z]$#' , $type ))
{
2003-06-05 19:19:48 +00:00
$tpl = 'olist_open' ;
2003-05-18 23:26:05 +00:00
$type = 'lower-alpha' ;
$start = ord ( $type ) - 96 ;
}
elseif ( preg_match ( '#[A-Z]#' , $type ))
{
2003-06-05 19:19:48 +00:00
$tpl = 'olist_open' ;
2003-05-18 23:26:05 +00:00
$type = 'upper-alpha' ;
$start = ord ( $type ) - 64 ;
}
elseif ( is_numeric ( $type ))
{
2003-06-05 19:19:48 +00:00
$tpl = 'olist_open' ;
2003-05-18 23:26:05 +00:00
$type = 'arabic-numbers' ;
$start = intval ( $chr );
}
2003-04-11 00:19:29 +00:00
else
{
2003-06-05 19:19:48 +00:00
$tpl = 'olist_open' ;
2003-05-18 23:26:05 +00:00
$type = 'arabic-numbers' ;
$start = 1 ;
2003-04-11 00:19:29 +00:00
}
2003-06-05 19:19:48 +00:00
return str_replace ( '{LIST_TYPE}' , $type , $this -> bbcode_tpl ( $tpl ));
2001-04-19 13:18:57 +00:00
}
2001-08-02 08:36:38 +00:00
2003-04-16 22:44:38 +00:00
function bbcode_second_pass_code ( $type , $code )
2003-04-11 00:19:29 +00:00
{
2003-08-28 20:50:20 +00:00
// when using the /e modifier, preg_replace slashes double-quotes but does not
// seem to slash anything else
$code = str_replace ( '\"' , '"' , $code );
2003-04-16 22:44:38 +00:00
switch ( $type )
{
case 'php' :
default :
$code = str_replace ( " \t " , ' ' , $code );
$code = str_replace ( ' ' , ' ' , $code );
$code = str_replace ( ' ' , ' ' , $code );
2004-07-27 20:03:09 +00:00
$code = preg_replace ( '#<!\-\- s(.*?) \-\-><img src="\{SMILE_PATH\}\/.*? \/><!\-\- s\1 \-\->#' , '\1' , $code );
2003-04-16 22:44:38 +00:00
}
2003-04-23 21:47:15 +00:00
$code = $this -> bbcode_tpl ( 'code_open' ) . $code . $this -> bbcode_tpl ( 'code_close' );
2001-08-02 08:36:38 +00:00
2003-04-11 00:19:29 +00:00
return $code ;
}
2001-04-19 13:18:57 +00:00
}
2002-07-14 14:41:12 +00:00
?>