Замена внутренней ссылки на название поста

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('/(&amp;)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);
}
}
 
B

Boltik

Гость
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 ])(' . $viewtopic_url . ')([0-9]+)([\w\#$%&~\-;:=,?@\[\]+]*)/si', $message, $matches);
        foreach ($matches[0] as $k => $str)
        {
            $topic_post_id = $matches[4][$k];
            $topic_title = '';
            if ($matches[3][$k] == POST_TOPIC_URL)
            {
                $sql = ("SELECT topic_title
                    FROM " . TOPICS_TABLE . "
                    WHERE topic_id = " . (int) $topic_post_id);
            }
            else
            {
                $sql = ("SELECT t.topic_title
                    FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
                    WHERE p.topic_id = t.topic_id
                    AND p.post_id = " . (int) $topic_post_id);
            }
            if ($result = $db->sql_query($sql))
            {
                $row = $db->sql_fetchrow($result);
                $topic_title =  $row['topic_title'];
           
            }
            $db->sql_freeresult($result);
   
            if (!empty($topic_title))
            {
                $message = str_replace($str, $matches[1][$k] . '[url=' . trim($str) . ']' . $topic_title . '[/url]', $message);
            }
        }
было такое решение... у меня работает, но оно для свн
 

krumax

Пользователь
Locer, а что же здесь писать то ?)
posts.php
найти
PHP:
$message = prepare_message($message);

// Flood control
перед этим добавь код с первого топика.
 
B

Bustra

Гость
адаптированная и проверенная версия от Boltik, добавить такую же в чатик =)
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 ])(' . $viewtopic_url . ')([0-9]+)([\w\#$%&~\-;:=,?@\[\]+]*)/si', $message, $matches);
        foreach ($matches[0] as $k => $str)
        {
            $topic_post_id = $matches[4][$k];
            $topic_title = '';
            if ($matches[3][$k] == POST_TOPIC_URL)
            {
                $sql = ("SELECT topic_title
                    FROM " . BB_TOPICS . "
                    WHERE topic_id = " . (int) $topic_post_id);
            }
            else
            {
                $sql = ("SELECT t.topic_title
                    FROM " . BB_TOPICS . " t, " . BB_POSTS . " p
                    WHERE p.topic_id = t.topic_id
                    AND p.post_id = " . (int) $topic_post_id);
            }
            if ($result = DB()->sql_query($sql))
            {
                $row = DB()->sql_fetchrow($result);
                $topic_title =  $row['topic_title'];
     
            }
            DB()->sql_freeresult($result);
 
            if (!empty($topic_title))
            {
                $message = str_replace($str, $matches[1][$k] . '[url=' . trim($str) . ']' . $topic_title . '[/url]', $message);
            }
        }
 
Сверху