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

Started by krumax on 2012-04-26 22:33 — 33 replies, 9498 views

#1
В принципе работает, но надо малёхо доработать...

$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);
}
}
#2
        $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);
            }
        }
было такое решение... у меня работает, но оно для свн
#3
менять нужно при инсёрте и апдейте
но никак не при селекте.
#4
Для чего этот мод, объясните пожалуйста?
#5
Boltik, знакомый код Порутчика 😉
#6
Для чего этот мод, объясните пожалуйста?
Например:
При вставке в сообщение ссылки вида http://krumax.org/viewtopic.php?t=6209 преобразует её в вид:
Призрак матери / Ghost Mother [ Тарасорн Сирипарнварапорн ] (2007,ужасы, мистика) DVDRip
#7
Например:
При вставке в сообщение ссылки вида http://krumax.org/viewtopic.php?t=6209 преобразует её в вид:
Призрак матери / Ghost Mother [ Тарасорн Сирипарнварапорн ] (2007,ужасы, мистика) DVDRip
О, интересная штука. Инструкцию по установке напишет кто?
#8
Locer, а что же здесь писать то ?)
posts.php
найти
$message = prepare_message($message);

// Flood control
перед этим добавь код с первого топика.
#9
адаптированная и проверенная версия от Boltik, добавить такую же в чатик =)
$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);
            }
        }
#10
Boltik, знакомый код Порутчика
а наверно... я не в курсе кто накатал эту фичу, но у меня работает.