/**
* make_url_clickable_callback
*/
function make_url_clickable_callback ($m)
{
global $bb_cfg;
$max_len = 70;
$href = $m[1];
$name = empty($m[2]) ? $href : $m[2];
if (mb_strlen($name, 'UTF-8') > $max_len)
{
$name = mb_substr($name, 0, $max_len - 19) .'...'. mb_substr($name, -16);
}
/* if (!preg_match("#{$bb_cfg['server_name']}#", $href))
{
require_once(INC_DIR . 'class.idna.php');
$IDN = new idna_convert();
return '<a href="'. make_url('/redirect.php?url=') . base64_encode($IDN->encode($href)) .'" class="postLink" target="_blank">'. $name .'</a>';
} */
if (preg_match($bb_cfg['autoreplace_category'], $href, $matches, PREG_OFFSET_CAPTURE))
{
$sql = "SELECT cat_title FROM " . BB_CATEGORIES . " WHERE cat_id = " . (int) $matches[3][0] . " LIMIT 1";
if ($result = DB()->sql_query($sql))
{
if ($row = DB()->sql_fetchrow($result))
{
$name = $row['cat_title'] . ' (категория)';
}
}
}
elseif (preg_match($bb_cfg['autoreplace_forum'], $href, $matches, PREG_OFFSET_CAPTURE))
{
$sql = "SELECT forum_name FROM " . BB_FORUMS . " WHERE forum_id = " . (int) $matches[3][0] . " LIMIT 1";
if ($result = DB()->sql_query($sql))
{
if ($row = DB()->sql_fetchrow($result))
{
$name = $row['forum_name'] . ' (форум)';
}
}
}
elseif (preg_match($bb_cfg['autoreplace_topic'], $href, $matches, PREG_OFFSET_CAPTURE))
{
$sql = "SELECT topic_title FROM " . BB_TOPICS . " WHERE topic_id=" . (int) $matches[3][0] . " LIMIT 1";
if ($result = DB()->sql_query($sql))
{
if ($row = DB()->sql_fetchrow($result))
{
$name = $row['topic_title'];
}
}
}
elseif (preg_match($bb_cfg['autoreplace_post'], $href, $matches, PREG_OFFSET_CAPTURE))
{
$sql = "SELECT t.topic_title, u.username, p.poster_id, p.post_time, p.post_username
FROM " . BB_POSTS . " p
LEFT JOIN " . BB_TOPICS . " t ON p.topic_id = t.topic_id
LEFT JOIN " . BB_USERS . " u ON u.user_id = p.poster_id
WHERE p.post_id = " . (int) $matches[3][0] . "
LIMIT 1";
if ($result = DB()->sql_query($sql))
{
if ($row = DB()->sql_fetchrow($result))
{
$post_username = ($row['poster_id'] > 0) ? $row['username'] : $row['post_username'];
$post_datetime = create_date($bb_cfg['last_post_date_format'], $row['post_time'], 4);
$name = $row['topic_title'] . ' (сообщение ' . $post_username . ' от ' . $post_datetime . ')';
}
}
}
elseif (preg_match($bb_cfg['autoreplace_user'], $href, $matches, PREG_OFFSET_CAPTURE))
{
$sql = "SELECT username, user_level FROM " . BB_USERS . " WHERE user_id = " . (int) $matches[3][0] . " LIMIT 1";
if ($result = DB()->sql_query($sql))
{
if ($row = DB()->sql_fetchrow($result))
{
if ( !empty($row['user_level']))
{
switch ($row['user_level'])
{
case 1:
$level = "администратор";
break;
case 2:
$level = "модератор";
break;
case 20:
$level = "участник групп";
break;
default:
$level = "пользователь";
}
}
else
{
$level = "пользователь";
}
$name = $row['username'] . ' ('.$level.')';
}
}
}
return "<a href=\"$href\" class=\"postLink\">$name</a>";
}