Index: trunk/globals.php
===================================================================
diff -u -r651 -r693
--- trunk/globals.php (.../globals.php) (revision 651)
+++ trunk/globals.php (.../globals.php) (revision 693)
@@ -562,106 +562,126 @@
}
}
-function ReplaceSingleTag($tag,$text)
+// --- bbcode processing function: begin ----
+function PreformatBBCodes($text)
{
- $tag = strtolower($tag);
- $opentag = '['.$tag;
- $closetag = '[/'.$tag.']';
-
- if( stristr($text,$opentag) )
- {
- $pos = strpos( strtolower($text), $opentag.' '); // tag has parameters
- if($pos === false)
- {
- $pos = strpos( strtolower($text), $opentag.']');
- }
-
- $endopen = strpos($text,']',$pos);
- $closepos = strpos( strtolower($text),$closetag,$pos);
-
- if($closepos)
- {
- $taglength = ($closepos - $endopen) + strlen($closetag);
- $tagText = substr($text,$pos, $closepos + strlen($closetag) - $pos);
- $innerText = substr($text,$endopen+1,$closepos - $endopen-1);
- if($tag=="UL")
- {
- $innerText = str_replace("[*]","
",$innerText);
- }
- $tagText = substr($tagText,1,($endopen - $pos)-1);
- //echo "Matched $tagText
\n";
- $tagText = "<".$tagText.">";
- $replace_text = $tagText.$innerText."".$tag.">";
- $text = substr($text,0,$pos).$replace_text.substr($text,$closepos+strlen($closetag));
- return $text;
- }
- else
- return $text;
- }
- else
- return $text;
+ // convert phpbb url bbcode to valid in-bulletin's format
+ // 1. urls
+ $text = preg_replace('/\[url=(.*)\](.*)\[\/url\]/Ui','[url href="$1"]$2[/url]',$text);
+ $text = preg_replace('/\[url\](.*)\[\/url\]/Ui','[url href="$1"]$1[/url]',$text);
+ // 2. images
+ $text = preg_replace('/\[img\](.*)\[\/img\]/Ui','[img src="$1" border="0"][/img]',$text);
+ // 3. color
+ $text = preg_replace('/\[color=(.*)\](.*)\[\/color\]/Ui','[font color="$1"]$2[/font]',$text);
+ // 4. size
+ $text = preg_replace('/\[size=(.*)\](.*)\[\/size\]/Ui','[font size="$1"]$2[/font]',$text);
+ // 5. lists
+ $text = preg_replace('/\[list(.*)\](.*)\[\/list\]/Uis','[ul]$2[/ul]',$text);
+ // 6. email to link
+ $text = preg_replace('/\[email\](.*)\[\/email\]/Ui','[url href="mailto:$1"]$1[/url]',$text);
+ //7. b tag
+ $text = preg_replace('/\[(b|i|u):(.*)\](.*)\[\/(b|i|u):(.*)\]/Ui','[$1]$3[/$4]',$text);
+ //8. code tag
+ $text = preg_replace('/\[code:(.*)\](.*)\[\/code:(.*)\]/Uis','[code]$2[/code]',$text);
+ return $text;
}
-function ReplaceTag($tag,$text)
+/**
+ * @return string
+ * @param string $BBCode
+ * @param string $TagParams
+ * @param string $TextInside
+ * @param string $ParamsAllowed
+ * @desc Removes not allowed params from tag and returns result
+*/
+function CheckBBCodeAttribs($BBCode, $TagParams, $TextInside, $ParamsAllowed)
{
- $new_text = ReplaceSingleTag($tag,$text);
-
- while($new_text != $text)
- {
- $text = $new_text;
- $new_text = ReplaceSingleTag($tag,$text);
- }
- return $new_text;
-}
-
-function ReplaceURL($text)
-{
-
- // process url bbtags without href parameter
- $text = preg_replace('/\[url\]([^\]]*)\[\/url\]/U', '[url href="$1"]$1[/url]', $text);
+ // $BBCode - bbcode to check, $TagParams - params string entered by user
+ // $TextInside - text between opening and closing bbcode tag
+ // $ParamsAllowed - list of allowed parameter names ("|" separated)
- // change bbcode to href's
- while( stristr($text,'[url') )
+ preg_match_all('/(.+)="(.+)"/Uis',$TagParams,$params);
+ if( count($params[0]) > 0 )
{
- $urlpos = strpos( strtolower($text), '[url');
- $endopen = strpos($text,']',$urlpos);
- if($endopen)
+ array_shift($params);
+ $param_count = count($params[0]); // count passed parameter names
+ $ParamsAllowed = explode('|',$ParamsAllowed);
+
+ $i = 0;
+ $ret = Array();
+ while($i < $param_count)
{
- $url = ''.$TextInside.''.$BBCode.'>';
}
- $text = str_replace(Array('[/url]','[/URL]'),Array('',''),$text);
- return $text;
+ else
+ {
+ return '<'.$BBCode.'>'.$TextInside.''.$BBCode.'>'; // params allowed, but not entered
+ }
+ return false;
}
-
function ReplaceBBCode($text)
{
- global $objConfig;
+ global $objConfig, $objSmileys;
- // BBCode: [b], [i], [u], [ul], [font]
- $tags = explode(",",$objConfig->Get("BBTags"));
- for($i = 0; $i < count($tags); $i++)
+ // convert phpbb bbcodes to in-bulletin bbcodes
+ $text = PreformatBBCodes($text);
+
+// $tag_defs = 'b:;i:;u:;ul:type|align;font:color|face|size;url:href;img:src|border';
+
+ $tags_defs = explode(';',$objConfig->Get('BBTags'));
+ $i = 0; $tags_defs_count = count($tags_defs);
+ while($i < $tags_defs_count)
{
- $text = ReplaceTag(strtoupper($tags[$i]),$text);
+ $tag = explode(':',$tags_defs[$i]);
+ $tag_name = $tag[0];
+ $tag_params = $tag[1];
+ if( strlen($tag_params) > 0 )
+ {
+ $text = preg_replace('/\['.$tag_name.'(.*)\](.*)\[\/'.$tag_name.'\]/Uise','CheckBBCodeAttribs("'.$tag_name.'","$1","$2","'.$tag_params.'");', $text);
+ }
+ else
+ {
+ $text = preg_replace('/\['.$tag_name.'\](.*)\[\/'.$tag_name.'\]/Uis','<'.$tag_name.'>$1'.$tag_name.'>', $text);
+ }
+ $i++;
}
-
- // BBCode: [url href="xxx"]xxx[/url]
- $text = ReplaceURL($text);
- // BBCode: [code]xxx[/code]
- //$text = preg_replace('/\[code[^\]]*\](.*)\[\/code[^\]]*\]/Ues', 'highlight_string( _unhtmlentities(\'$1\') , true);', $text);
- $text = preg_replace('/\[code[^\]]*\](.*)\[\/code[^\]]*\]/Ues', 'highlight_string( _unhtmlentities( stripslashes("$1") ) , true);', $text);
+ // additional processing for [url], [*], [img] bbcode
+ $text = str_replace( Array('','[*]'),
+ Array('',''),
+ $text);
+
+ // bbcode [code]xxx[/code] processing
+ $text = preg_replace('/\[code](.*)\[\/code]/Ues', 'ReplaceCodeBBCode(highlight_string(\'UndoSmileys(_unhtmlentities( stripslashes(\'$1\') ) ).\' ?>\', true));', $text);
return $text;
}
+function ReplaceCodeBBCode($input_string)
+{
+ if( strlen($input_string) )
+ {
+ $input_string = str_replace(Array('<?php ','?>'),Array('',''),$input_string);
+ }
+
+ $input_string = str_replace("
","",$input_string);
+ return $input_string;
+}
+
+// --- bbcode processing function: end ----
+
function GetMinValue($Table,$Field, $Where=NULL)
{
$ret = 0;