1. Приветствуем Вас на неофициальном форуме технической поддержки XenForo на русском языке. XenForo - коммерческий форумный движок от бывших создателей vBulletin, написанный на PHP.

BB-code [media] Sites - перестроить сообщения

Тема в разделе "Основные вопросы по XenForo", создана пользователем SAS1024, 28.04.2015.

Загрузка
  1. SAS1024

    SAS1024 Местный

    Регистрация:
    23.04.15
    Сообщения:
    85
    Симпатии:
    87
    Версия XF:
    1.4.10
    Всем привет.

    Скажите пожалуйста, решал ли кто-нибудь проблему перестройки старых сообщений после добавления нового сайта в ббкод Media ?

    То есть например у меня есть старые-старые ссылки на видео в Вконтакте. Затем я добавил в ббкод media поддержку сайта Вконтакте.
    Как мне теперь перестроить старые сообщения для того, чтобы старые ссылки подцепились ббкодом media ?
     
  2. Exile

    Exile Местный

    Регистрация:
    27.06.11
    Сообщения:
    997
    Симпатии:
    545
    Версия XF:
    1.4.4
  3. SAS1024

    SAS1024 Местный

    Регистрация:
    23.04.15
    Сообщения:
    85
    Симпатии:
    87
    Версия XF:
    1.4.10
    Это конечно слегка не то, о чём я спрашивал, но с его помощью, безусловно, можно решить проблему.
    Правда на больших форумах стоит выставить таймауты по-больше. Либо есть смысл написать своё, которое можно запустить из командной строки.
     
  4. Exile

    Exile Местный

    Регистрация:
    27.06.11
    Сообщения:
    997
    Симпатии:
    545
    Версия XF:
    1.4.4
    Это именно то, чем решается проблема. Вернее основа. У себя при конвертации форума с vB именно своим аналогом на основе этого дополнения, который запускал из командной строки, все сообщения "обновлял". Просто ни один скрипт 4 миллиона сообщений не вытянет не из консоли. Заранее прошу прощения за гавнокод, но подобные инструменты обычно пишутся лишь бы задачу выполняли.
    PHP:
    <?php

    set_time_limit
    (0);

    $startTime microtime(true);
    $fileDir dirname(__FILE__);

    require(
    $fileDir '/library/XenForo/Autoloader.php');
    XenForo_Autoloader::getInstance()->setupAutoloader($fileDir '/library');

    XenForo_Application::initialize($fileDir '/library'$fileDir);
    XenForo_Application::set('page_start_time'$startTime);

    for (
    $i 0$i <= 4000$i++) {

        
    $input = array(
            
    'find1'    => 'http://img.forumimg.net/buttons/viewpost.gif',
            
    'regex1'   => '/<div style="margin:20px; margin-top:5px; "> <div class="smallfont" style="margin-bottom:2px">Цитата:<\/div> <table cellpadding="6" cellspacing="0" border="0" width="100%"> <tr> <td class="alt2" style="border:1px inset">  <div> Сообщение от <strong>(.*?)<\/strong> <a href="(.*?)" rel="nofollow"><img class="inlineimg" src="http:\/\/img\.forumimg\.net\/buttons\/viewpost\.gif" border="0" alt="Посмотреть сообщение" \/><\/a> <\/div> <div style="font-style:italic">(.*?)<\/div>  <\/td> <\/tr> <\/table> <\/div>/isu',
            
    'replace1' => '[QUOTE="$1"]$3[/QUOTE]',

            
    'find2'   => '<div style="margin:20px; margin-top:5px; "> <div class="smallfont" style="margin-bottom:2px">Цитата:</div> <table cellpadding="6" cellspacing="0" border="0" width="100%"> <tr> <td class="alt2" style="border:1px inset">  <div> Сообщение от <strong>',
            
    'regex2'   => '/<div style="margin:20px; margin-top:5px; "> <div class="smallfont" style="margin-bottom:2px">Цитата:<\/div> <table cellpadding="6" cellspacing="0" border="0" width="100%"> <tr> <td class="alt2" style="border:1px inset">  <div> Сообщение от <strong>(.*?)<\/strong>  <\/div> <div style="font-style:italic">(.*?)<\/div>  <\/td> <\/tr> <\/table> <\/div>/isu',
            
    'replace2' => '[QUOTE="$1"]$2[/QUOTE]',

            
    'find3'   => '<div style="margin:20px; margin-top:5px; "> <div class="smallfont" style="margin-bottom:2px">Цитата:</div> <table cellpadding="6" cellspacing="0" border="0" width="100%"> <tr> <td class="alt2" style="border:1px inset">',
            
    'regex3'   => '/<div style="margin:20px; margin-top:5px; "> <div class="smallfont" style="margin-bottom:2px">Цитата:<\/div> <table cellpadding="6" cellspacing="0" border="0" width="100%"> <tr> <td class="alt2" style="border:1px inset">(.*?)<\/td> <\/tr> <\/table> <\/div>/isu',
            
    'replace3' => '[QUOTE]$1[/QUOTE]',

            
    'find4'   => 'target="_blank"',
            
    'regex4'   => '/<a href="(.*?)" target="_blank">(.*?)<\/a>/isu',
            
    'replace4' => '[URL="$1"]$2[/URL]',

            
    'find5'   => ']Ответ:',
            
    'regex5'   => '/\[b\]Ответ:(.*?)\[\/b\]\n\n/isu',
            
    'replace5' => '',

            
    'find6'   => ']Re:',
            
    'regex6'   => '/\[b\]Re:(.*?)\[\/b\]\n\n/isu',
            
    'replace6' => '',

            
    'find7'   => '<font size',
            
    'regex7'   => '/<font size="(.*?)">(.*?)<\/font>/isu',
            
    'replace7' => '[SIZE=$1]$2[/SIZE]',

            
    'find8'   => '<font color',
            
    'regex8'   => '/<font color="(.*?)">(.*?)<\/font>/isu',
            
    'replace8' => '[COLOR=$1]$2[/COLOR]',

            
    'find9'   => '<img src=',
            
    'regex9'   => '/<img src="(.*?)" border="0" alt="" \/>/isu',
            
    'replace9' => '[IMG]$1[/IMG]',

            
    'find12'   => '>Код:',
            
    'regex12'   => '/<div style="margin:20px; margin-top:5px"> <div class="smallfont" style="margin-bottom:2px">Код:<\/div> <pre class="alt2" dir="ltr" style="(.*?)">(.*?)<\/pre> <\/div>/isu',
            
    'replace12' => '[CODE]$2[/CODE]',

            
    'find13'   => '>PHP код:',
            
    'regex13'   => '/<div style="margin:20px; margin-top:5px"> <div class="smallfont" style="margin-bottom:2px">PHP код:<\/div> <div class="alt2" dir="ltr" style="(.*?)"> <code style="white-space:nowrap"> <code>(.*?)<\/code> <\/code> <\/div> <\/div>/isu',
            
    'replace13' => '[PHP ]$2[/PHP ]',

            
    'find10'   => 'class="inlineimg"',
            
    'regex10'   => '/<img src="(.*?)" border="0" alt="" title="(.*?)" class="inlineimg" \/>/isu',
            
    'replace10' => ':-)',

            
    'find_'   => 'style="margin: 2px"',
            
    'regex_'   => '/<img src="(.*?)" style="margin: 2px" \/>/isu',
            
    'replace_' => '',

            
    'find'   => '<legend>Изображения',
            
    'regex'   => '/<\/div>    <div style="padding:6px">   <fieldset class="fieldset"> <legend>Изображения<\/legend> <div style="padding:3px"> <img class="attach" src="(.*?)<\/div> <\/fieldset>/isu',
            
    'replace' => '',
        );

        
    $db XenForo_Application::get('db');
        
    $sql "SELECT post.* FROM xf_post AS post WHERE post.message LIKE '%".$input['find']."%' ORDER BY post.post_id LIMIT 5000";
        
    $posts $db->fetchAll($sql);
        
    $gamma 0;
        foreach (
    $posts AS $postId => &$post)
        {
            echo 
    $post['post_id'].' + ';
            if (
    preg_match_all($input['regex'], $post['message'], $matches))
            {
                
    $gamma++;
                
    $post['found'] = $matches[0];
                
    $post['replaced'] = preg_replace($input['regex'], $input['replace'], $post['found']);

                
    $message preg_replace($input['regex'], $input['replace'], $post['message']);

                
    $dw XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_Post');

                
    $dw->setOption(XenForo_DataWriter_DiscussionMessage::OPTION_IS_AUTOMATEDtrue);
                
    $dw->setExistingData($posttrue);

                
    $dw->set('message'$message);

                
    $dw->save();
            }
            else
            {
                unset(
    $posts[$postId]);
            }
        }
        echo 
    ' SUMM: '.$i.'->'.$gamma.' | ';
    }

    echo 
    'done';
    Скриншоты в стиле до и после (сообщения разные) прилагаю:
    [​IMG] [​IMG]
     
    SAS1024 нравится это.

Поделиться этой страницей