krumax
Пользователь
В принципе работает, но надо малёхо доработать...
PHP:
$script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($bb_cfg['script_path']));
$script_name = ($script_name != '') ? $script_name . '/' : '';
$server_name = trim($bb_cfg['server_name']);
$server_protocol = ($bb_cfg['cookie_secure']) ? 'https://' : 'http://';
$server_port = ($bb_cfg['server_port'] <> 80) ? ':' . trim($bb_cfg['server_port']) . '/' : '/';
$board_path = $server_protocol . $server_name . $server_port . $script_name;
$viewtopic_url = preg_quote($board_path . 'viewtopic.php?', '/') . '('. POST_TOPIC_URL . '|'. POST_POST_URL . ')=';
preg_match_all('/(^|[\n\t (>.])(' . $viewtopic_url . ')([0-9]+)([\w\#$%&~\-;:=,?@\[\]+]*)/si', $message, $matches);
foreach ($matches[0] as $k => $str)
{
$topic_post_id = $matches[4][$k];
$topic_title = get_topic_title ($topic_post_id);
if (!empty($topic_title))
{
preg_match('/([,]*)$/', $str, $math);
$internal_url = preg_replace('/(&)sid=[0-9a-f]{32}/', '', substr($str, strlen($matches[1][$k])));
$internal_url = preg_replace('/([,]*)$/', '', $internal_url);
$message = str_replace($str, $matches[1][$k] . '[url=' . trim($internal_url) . ']' . addslashes($topic_title) . '[/url]' . ((isset($math[1])) ? $math[1] : ''), $message);
}
}