new_tags['bold'][0] regex
* @example $this->new_tags['bold'][1] replace
*
* @var array/public
*/
var $new_tags = array();
/**
* zum verkleinern von bildern innerhalb von [img]-tags (width)
*
* @var int/public
*/
var $imageMaxWidth = 700;
/**
* zum verkleinern von bildern innerhalb von [img]-tags (height)
*
* @var int/public
*/
var $imageMaxHeight = 500;
/**
* array für smilies
*
* @example $this->smilies[':)'] image
*
* @var array/public
*/
var $smilies = array();
/**
* legt fest ob innherlab des strings nach geshi-tags gesucht werden soll
*
* @var bool/public
*/
var $geshi_callback = true;
/**
* legt jeweils einmalig den include-path für die geshi-klasse fest
*
* @var string/public
*/
var $geshi_temp_include_path = null;
/**
* legt den permanenten include-path von geshi fest
*
* @var string/public
*/
var $geshi_include_path = null;
/**
* legt als kontruk vordefinierte tags an
*
* @return null
*/
public function mc_XBBcodeParser() {
$this->new_tags['google'][0] = '\[google\](.*)\[\/google\]';
$this->new_tags['google'][1] = 'Google: $1';
$this->new_tags['wiki'][0] = '\[wiki\](.*)\[\/wiki\]';
$this->new_tags['wiki'][1] = 'Wiki: $1';
}
/**
* nimmt eigene bb-codes auf
*
* @param string $tagName (regex)
* @param string $replace
* @param mixed $attributes
* @return null
*/
public function assign($tagName, $replace, $attributes = '')
{
if(empty($attributes)) {
$this->new_tags[$tagName][0] = "\[$tagName\](.*)\[\/$tagName\]";
$this->new_tags[$tagName][1] = $replace;
}
else {
if(is_array($attributes)) {
$this->new_tags[$tagName][0] = "\[$tagName ";
foreach($attributes AS $attrName) {
$this->new_tags[$tagName][0] .= $attrName."=\'(.*)\' ";
}
$this->new_tags[$tagName][0] = substr_replace(
$this->new_tags[$tagName][0],
'',
-1
)."\](.*)\[\/$tagName\]";
$this->new_tags[$tagName][1] = $replace;
}
else {
$this->new_tags[$tagName][0] = "\[$tagName $attributes=\'(.*)\'\](.*)\[\/$tagName\]";
$this->new_tags[$tagName][1] = $replace;
}
}
}
/**
* sucht und ersetzt [img]-tags
*
* @param string $string
* @return string (parsed)
*/
public function parse_images($string) {
//die html-syntax [img='bild.png' /]
$pl1 = "\[img=\'(.*)\' \/\]";
//standard-syntax [img='bild.png'][/img]
$pl2 = "\[img=\'(.*)\'\]\[\/img\]";
//syntax1
$string = preg_replace_callback(
'!'.$pl1.'!isU',
create_function(
'$result',
'
$imgsrc = $result[1];
if(($size = getimagesize($imgsrc)) == false) return null; //kein bild!
else {
$sw = '.$this->imageMaxWidth.' / $size[0];
$sh = '.$this->imageMaxHeight.' / $size[1];
if($size[0] > '.$this->imageMaxHeight.' || $size[1] > '.$this->imageMaxWidth.') {
if($sw < $sh) {
$sizeW = '.$this->imageMaxWidth.';
$sizeH = round($size[1] * $sw);
}
else {
$sizeW = round($size[0] * $sh);
$sizeH = '.$this->imageMaxHeight.';
}
}
else {
$sizeW = $size[0];
$sizeH = $size[1];
}
return "";
}
'
),
$string
);
//syntax2
$string = preg_replace_callback(
'!'.$pl2.'!isU',
create_function(
'$result',
'
$imgsrc = $result[1];
if(($size = getimagesize($imgsrc)) == false) return null; //kein bild!
else {
$sw = '.$this->imageMaxWidth.' / $size[0];
$sh = '.$this->imageMaxHeight.' / $size[1];
if($size[0] > '.$this->imageMaxHeight.' || $size[1] > '.$this->imageMaxWidth.') {
if($sw < $sh) {
$sizeW = '.$this->imageMaxWidth.';
$sizeH = round($size[1] * $sw);
}
else {
$sizeW = round($size[0] * $sh);
$sizeH = '.$this->imageMaxHeight.';
}
}
else {
$sizeW = $size[0];
$sizeH = $size[1];
}
return "
";
}
'
),
$string
);
return $string;
}
/**
* sucht und ersetzt eigene bb-codes
*
* @param string $string
* @return string (parsed)
*/
public function parse_own($string) {
$plattern = array();
$replaces = array();
foreach($this->new_tags AS $pl) {
$plattern[] = '!'.$pl[0].'!sieU';
$replaces[] = "'{$pl[1]}'";
}
return preg_replace($plattern, $replaces, $string);
}
/**
* sucht und ersetzt einfache html-tags
*
* @param string $string
* @return string (parsed)
*/
public function parse_tags($string) {
$s = array(
'!\[b\](.*)\[\/b\]!sieU',
'!\[i\](.*)\[\/i\]!sieU',
'!\[u\](.*)\[\/u\]!sieU',
'!\[s\](.*)\[\/s\]!sieU',
'!\[color=\'(.*)\'\](.*)\[\/color\]!sieU',
'!\[size=\'(.*)\'\](.*)\[\/size\]!sieU'
);
$r = array(
'\'$1\'',
'\'$1\'',
'\'$1\'',
'\'$1\'',
'\'$2\'',
'\'$2\''
);
$string = preg_replace($s, $r, $string);
$string = preg_replace_callback(
'!\[list(.*)\](.*)\[\/list\]!isU',
create_function(
'$result',
'
$r = str_replace(array("\'", "=", "\""), \'\', $result[1]);
switch($r) {
case "1": $type = "decimal"; break;
case "*": $type = "square"; break;
case "disc": $type = "disc"; break;
case "none": $type = "none"; break;
case "latin": $type = "upper-latin"; break;
case "roman": $type = "upper-roman"; break;
default: $type = "disc";
}
$li = str_replace("[*]", "
'.((".(($phtml === true) ? "true" : "false").") ? htmlentities('\\1') : '\\1').'$str