Найдено решение:
Заменяем "function parsesmileys($message) {" ... "}" на
$smiley = array(
"#\:\)#si" => "<img src='".IMAGES."smiley/smile.gif' alt='smiley'>",
"#\;\)#si" => "<img src='".IMAGES."smiley/wink.gif' alt='smiley'>",
"#\:\(#si" => "<img src='".IMAGES."smiley/sad.gif' alt='smiley'>",
"#\:\|#si" => "<img src='".IMAGES."smiley/frown.gif' alt='smiley'>",
"#\:o#si" => "<img src='".IMAGES."smiley/shock.gif' alt='smiley'>",
"#\:p#si" => "<img src='".IMAGES."smiley/pfft.gif' alt='smiley'>",
"#b\)#si" => "<img src='".IMAGES."smiley/cool.gif' alt='smiley'>",
"#\:d#si" => "<img src='".IMAGES."smiley/grin.gif' alt='smiley'>",
"#\:@#si" => "<img src='".IMAGES."smiley/angry.gif' alt='smiley'>",
"#f_emo_01#si" => "<img src='".IMAGES."smiley/emo/f_emo_01.gif' alt='smiley'>",
"#f_emo_02#si" => "<img src='".IMAGES."smiley/emo/f_emo_02.gif' alt='smiley'>",
"#f_emo_03#si" => "<img src='".IMAGES."smiley/emo/f_emo_03.gif' alt='smiley'>",
"#f_emo_04#si" => "<img src='".IMAGES."smiley/emo/f_emo_04.gif' alt='smiley'>",
"#f_emo_05#si" => "<img src='".IMAGES."smiley/emo/f_emo_05.gif' alt='smiley'>",
"#f_emo_06#si" => "<img src='".IMAGES."smiley/emo/f_emo_06.gif' alt='smiley'>",
"#f_emo_07#si" => "<img src='".IMAGES."smiley/emo/f_emo_07.gif' alt='smiley'>",
"#f_emo_08#si" => "<img src='".IMAGES."smiley/emo/f_emo_08.gif' alt='smiley'>",
"#f_emo_09#si" => "<img src='".IMAGES."smiley/emo/f_emo_09.gif' alt='smiley'>",
"#f_emo_10#si" => "<img src='".IMAGES."smiley/emo/f_emo_10.gif' alt='smiley'>",
"#f_emo_11#si" => "<img src='".IMAGES."smiley/emo/f_emo_11.gif' alt='smiley'>",
"#f_emo_12#si" => "<img src='".IMAGES."smiley/emo/f_emo_12.gif' alt='smiley'>",
"#f_emo_13#si" => "<img src='".IMAGES."smiley/emo/f_emo_13.gif' alt='smiley'>",
"#f_emo_14#si" => "<img src='".IMAGES."smiley/emo/f_emo_14.gif' alt='smiley'>",
"#f_emo_15#si" => "<img src='".IMAGES."smiley/emo/f_emo_15.gif' alt='smiley'>",
"#f_emo_16#si" => "<img src='".IMAGES."smiley/emo/f_emo_16.gif' alt='smiley'>",
"#f_emo_17#si" => "<img src='".IMAGES."smiley/emo/f_emo_17.gif' alt='smiley'>",
"#f_emo_18#si" => "<img src='".IMAGES."smiley/emo/f_emo_18.gif' alt='smiley'>",
"#f_emo_19#si" => "<img src='".IMAGES."smiley/emo/f_emo_19.gif' alt='smiley'>",
"#f_emo_20#si" => "<img src='".IMAGES."smiley/emo/f_emo_20.gif' alt='smiley'>",
"#f_emo_21#si" => "<img src='".IMAGES."smiley/emo/f_emo_21.gif' alt='smiley'>",
"#f_emo_22#si" => "<img src='".IMAGES."smiley/emo/f_emo_22.gif' alt='smiley'>",
"#f_emo_23#si" => "<img src='".IMAGES."smiley/emo/f_emo_23.gif' alt='smiley'>",
"#f_emo_24#si" => "<img src='".IMAGES."smiley/emo/f_emo_24.gif' alt='smiley'>",
"#f_emo_25#si" => "<img src='".IMAGES."smiley/emo/f_emo_25.gif' alt='smiley'>",
"#f_emo_26#si" => "<img src='".IMAGES."smiley/emo/f_emo_26.gif' alt='smiley'>",
"#f_emo_27#si" => "<img src='".IMAGES."smiley/emo/f_emo_27.gif' alt='smiley'>",
"#f_emo_28#si" => "<img src='".IMAGES."smiley/emo/f_emo_28.gif' alt='smiley'>",
"#f_emo_29#si" => "<img src='".IMAGES."smiley/emo/f_emo_29.gif' alt='smiley'>",
"#f_emo_30#si" => "<img src='".IMAGES."smiley/emo/f_emo_30.gif' alt='smiley'>",
"#f_emo_31#si" => "<img src='".IMAGES."smiley/emo/f_emo_31.gif' alt='smiley'>",
"#f_emo_32#si" => "<img src='".IMAGES."smiley/emo/f_emo_32.gif' alt='smiley'>",
"#f_emo_33#si" => "<img src='".IMAGES."smiley/emo/f_emo_33.gif' alt='smiley'>",
"#f_emo_34#si" => "<img src='".IMAGES."smiley/emo/f_emo_34.gif' alt='smiley'>",
"#f_emo_35#si" => "<img src='".IMAGES."smiley/emo/f_emo_35.gif' alt='smiley'>",
"#f_emo_36#si" => "<img src='".IMAGES."smiley/emo/f_emo_36.gif' alt='smiley'>",
"#f_emo_37#si" => "<img src='".IMAGES."smiley/emo/f_emo_37.gif' alt='smiley'>",
"#f_emo_38#si" => "<img src='".IMAGES."smiley/emo/f_emo_38.gif' alt='smiley'>",
"#f_emo_39#si" => "<img src='".IMAGES."smiley/emo/f_emo_39.gif' alt='smiley'>",
"#f_emo_40#si" => "<img src='".IMAGES."smiley/emo/f_emo_40.gif' alt='smiley'>",
"#f_emo_41#si" => "<img src='".IMAGES."smiley/emo/f_emo_41.gif' alt='smiley'>",
"#f_emo_42#si" => "<img src='".IMAGES."smiley/emo/f_emo_42.gif' alt='smiley'>",
"#f_emo_43#si" => "<img src='".IMAGES."smiley/emo/f_emo_43.gif' alt='smiley'>",
"#f_emo_44#si" => "<img src='".IMAGES."smiley/emo/f_emo_44.gif' alt='smiley'>",
"#f_emo_45#si" => "<img src='".IMAGES."smiley/emo/f_emo_45.gif' alt='smiley'>",
"#f_emo_46#si" => "<img src='".IMAGES."smiley/emo/f_emo_46.gif' alt='smiley'>",
"#f_emo_47#si" => "<img src='".IMAGES."smiley/emo/f_emo_47.gif' alt='smiley'>",
"#f_emo_48#si" => "<img src='".IMAGES."smiley/emo/f_emo_48.gif' alt='smiley'>",
"#f_emo_49#si" => "<img src='".IMAGES."smiley/emo/f_emo_49.gif' alt='smiley'>",
"#f_emo_50#si" => "<img src='".IMAGES."smiley/emo/f_emo_50.gif' alt='smiley'>",
"#f_emo_51#si" => "<img src='".IMAGES."smiley/emo/f_emo_51.gif' alt='smiley'>",
"#f_emo_52#si" => "<img src='".IMAGES."smiley/emo/f_emo_52.gif' alt='smiley'>",
"#f_emo_53#si" => "<img src='".IMAGES."smiley/emo/f_emo_53.gif' alt='smiley'>",
"#f_emo_54#si" => "<img src='".IMAGES."smiley/emo/f_emo_54.gif' alt='smiley'>",
"#f_emo_55#si" => "<img src='".IMAGES."smiley/emo/f_emo_55.gif' alt='smiley'>",
"#f_emo_56#si" => "<img src='".IMAGES."smiley/emo/f_emo_56.gif' alt='smiley'>",
"#f_emo_57#si" => "<img src='".IMAGES."smiley/emo/f_emo_57.gif' alt='smiley'>",
"#f_emo_58#si" => "<img src='".IMAGES."smiley/emo/f_emo_58.gif' alt='smiley'>",
"#f_emo_59#si" => "<img src='".IMAGES."smiley/emo/f_emo_59.gif' alt='smiley'>",
"#f_emo_60#si" => "<img src='".IMAGES."smiley/emo/f_emo_60.gif' alt='smiley'>",
"#f_emo_61#si" => "<img src='".IMAGES."smiley/emo/f_emo_61.gif' alt='smiley'>",
"#f_emo_62#si" => "<img src='".IMAGES."smiley/emo/f_emo_62.gif' alt='smiley'>",
"#f_emo_63#si" => "<img src='".IMAGES."smiley/emo/f_emo_63.gif' alt='smiley'>",
"#f_emo_64#si" => "<img src='".IMAGES."smiley/emo/f_emo_64.gif' alt='smiley'>",
"#f_emo_65#si" => "<img src='".IMAGES."smiley/emo/f_emo_65.gif' alt='smiley'>",
"#f_emo_66#si" => "<img src='".IMAGES."smiley/emo/f_emo_66.gif' alt='smiley'>",
"#f_emo_67#si" => "<img src='".IMAGES."smiley/emo/f_emo_67.gif' alt='smiley'>",
"#f_emo_68#si" => "<img src='".IMAGES."smiley/emo/f_emo_68.gif' alt='smiley'>",
"#f_emo_69#si" => "<img src='".IMAGES."smiley/emo/f_emo_69.gif' alt='smiley'>",
"#f_emo_70#si" => "<img src='".IMAGES."smiley/emo/f_emo_70.gif' alt='smiley'>",
"#f_emo_71#si" => "<img src='".IMAGES."smiley/emo/f_emo_71.gif' alt='smiley'>",
"#f_emo_72#si" => "<img src='".IMAGES."smiley/emo/f_emo_72.gif' alt='smiley'>",
"#f_emo_73#si" => "<img src='".IMAGES."smiley/emo/f_emo_73.gif' alt='smiley'>",
"#f_emo_74#si" => "<img src='".IMAGES."smiley/emo/f_emo_74.gif' alt='smiley'>",
"#f_emo_75#si" => "<img src='".IMAGES."smiley/emo/f_emo_75.gif' alt='smiley'>",
"#f_emo_76#si" => "<img src='".IMAGES."smiley/emo/f_emo_76.gif' alt='smiley'>",
"#f_emo_77#si" => "<img src='".IMAGES."smiley/emo/f_emo_77.gif' alt='smiley'>",
"#f_emo_78#si" => "<img src='".IMAGES."smiley/emo/f_emo_78.gif' alt='smiley'>",
"#f_emo_79#si" => "<img src='".IMAGES."smiley/emo/f_emo_79.gif' alt='smiley'>",
"#f_emo_80#si" => "<img src='".IMAGES."smiley/emo/f_emo_80.gif' alt='smiley'>",
"#f_emo_81#si" => "<img src='".IMAGES."smiley/emo/f_emo_81.gif' alt='smiley'>",
"#f_emo_82#si" => "<img src='".IMAGES."smiley/emo/f_emo_82.gif' alt='smiley'>",
"#f_emo_83#si" => "<img src='".IMAGES."smiley/emo/f_emo_83.gif' alt='smiley'>",
"#f_emo_84#si" => "<img src='".IMAGES."smiley/emo/f_emo_84.gif' alt='smiley'>",
"#f_emo_85#si" => "<img src='".IMAGES."smiley/emo/f_emo_85.gif' alt='smiley'>",
);
function doParseSmileys($string) {
global $smiley;
foreach($smiley as $key=>$smiley_img) $string = preg_replace($key, $smiley_img, $string);
//echo "[[[".$string."]]]";
return $string;
}
function processString2ParseSmileys($level, $str, $found, $tag) {
$delta = strlen($tag);
if ($level == 0) {
return doParseSmileys(substr($str,0,$found)).substr($str,$found,$delta);
} else {
return substr($str,0,$found+$delta);
}
}
function explodeNextTag($str, $level, $opening_tag, $closing_tag) {
//echo $level.$opening_tag." + ";
$found = strpos($str, $opening_tag);
if ($found != false) {
$result = processString2ParseSmileys($level, $str, $found, $opening_tag);
$level++;
$found += 6;
} else {
$found = strpos($str, $closing_tag);
if ($found != false) {
$result = processString2ParseSmileys($level, $str, $found, $closing_tag);
$level--;
$found += 7;
}
}
if ($found != false) {
$result .= explodeNextTag(substr($str,$found), $level, $opening_tag, $closing_tag);
} else {
$result = doParseSmileys($str);
}
return $result;
}
// Parse smiley bbcode into HTML images
function parsesmileys($message) {
$message = explodeNextTag($message, 0, "[ =) code]", "[ =) /code]");
return $message;
}
Вроде шустро работает.
Фишка моего кода в том, что смайлы можно отключать любым тегом. Достаточно вместо
$message = explodeNextTag($message, 0, "[ =) code]", "[ =) /code]");
написать, например,
$message = explodeNextTag($message, 0, "[nosmileys]", "[/nosmileys]");
Смайлы отключаются внутри тегов любого уровня вложенности. Единственное, чем я могу вас огорчить - нельзя использовать пока более 1 тега для отключения смайлов. Но это поправимо.
P.S. Естественно, [ =) code] надо читать без смайла. Это обход BBcode.
P.P.S. У меня на сайте вообще нет смайлов - сайт академический. Просто я здесь с проблемой столкнулся. |
|