Всем привет, возникла такая проблема, создал форум на phpbb3, но там оказалась проблема со смайликами, только один смайл парсится, остальные остаются в виде кода смайла, после перехода на новую строку смайлик снова парсится. Выяснил что ошибка где-то в этой функции, но т.к. я с регулярными выражениями умею работать только в текстовом редакторе, для поиска, то нужна ваша помощь:
/**
* Parse Smilies
*/
function smilies($max_smilies = 0)
{
global $db, $user;
static $match;
static $replace;
// See if the static arrays have already been filled on an earlier invocation
if (!is_array($match))
{
$match = $replace = array();
// NOTE: obtain_* function? chaching the table contents?
// For now setting the ttl to 10 minutes
switch ($db->sql_layer)
{
case 'mssql':
case 'mssql_odbc':
case 'mssqlnative':
$sql = 'SELECT *
FROM ' . SMILIES_TABLE . '
ORDER BY LEN(code) DESC';
break;
case 'firebird':
$sql = 'SELECT *
FROM ' . SMILIES_TABLE . '
ORDER BY CHAR_LENGTH(code) DESC';
break;
// LENGTH supported by MySQL, IBM DB2, Oracle and Access for sure...
default:
$sql = 'SELECT *
FROM ' . SMILIES_TABLE . '
ORDER BY LENGTH(code) DESC';
break;
}
$result = $db->sql_query($sql, 600);
while ($row = $db->sql_fetchrow($result))
{
if (empty($row['code']))
{
continue;
}
// (assertion)
$match[] = preg_quote($row['code'], '#');
$replace[] = '<!-- s' . $row['code'] . ' --><img src="{SMILIES_PATH}/' . $row['smiley_url'] . '" alt="' . $row['code'] . '" title="' . $row['emotion'] . '" /><!-- s' . $row['code'] . ' -->';
}
$db->sql_freeresult($result);
}
if (sizeof($match))
{
if ($max_smilies)
{
// 'u' modifier has been added to correctly parse smilies within unicode strings
// For details: http://tracker.phpbb.com/browse/PHPBB3-10117
$num_matches = preg_match_all('#(?<=^|[\n .])(?:' . implode('|', $match) . ')(?![^<>]*>)#u', $this->message, $matches);
unset($matches);
if ($num_matches !== false && $num_matches > $max_smilies)
{
$this->warn_msg[] = sprintf($user->lang['TOO_MANY_SMILIES'], $max_smilies);
return;
}
}
// Make sure the delimiter # is added in front and at the end of every element within $match
// 'u' modifier has been added to correctly parse smilies within unicode strings
// For details: http://tracker.phpbb.com/browse/PHPBB3-10117
$this->message = trim(preg_replace(explode(chr(0), '#(?<=^|[\n .])' . implode('(?![^<>]*>)#u' . chr(0) . '#(?<=^|[\n .])', $match) . '(?![^<>]*>)#u'), $replace, $this->message));
}
}