Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2010-10-13 17:23:00

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,518
Website

[MOD] Move posts - 1.1

Mod for moving of posts from one topic in another (only for administrators and moderators).

v 1.0

1. OPEN FILE moderate.php.
2. FIND

            <p class="conr modbuttons"><input type="submit" name="split_posts" value="<?php echo $lang_misc['Split'] ?>"<?php echo $button_status ?> /> <input type="submit" name="delete_posts" value="<?php echo $lang_misc['Delete'] ?>"<?php echo $button_status ?> /></p>

REPLACE WITH

            <p class="conr modbuttons"><input type="submit" name="move_posts" value="<?php echo $lang_misc['Move'] ?>"<?php echo $button_status ?> /> <input type="submit" name="split_posts" value="<?php echo $lang_misc['Split'] ?>"<?php echo $button_status ?> /> <input type="submit" name="delete_posts" value="<?php echo $lang_misc['Delete'] ?>"<?php echo $button_status ?> /></p>

3. FIND

    // Delete one or more posts
    if (isset($_POST['delete_posts']) || isset($_POST['delete_posts_comply']))

REPLACE WITH

    // Перемещение одного и более сообщений в другую тему
    if (isset($_POST['move_posts']) || isset($_POST['move_posts_forum']) || isset($_POST['move_posts_topic']))
    {
        $posts = $_POST['posts'];
        if (empty($posts))
            message($lang_misc['No posts selected']);

        if (isset($_POST['move_posts_forum']) || isset($_POST['move_posts_topic']))
        {
            confirm_referrer('moderate.php');

            if (@preg_match('/[^0-9,]/', $posts))
                message($lang_common['Bad request']);

            $move_to_forum = isset($_POST['move_to_forum']) ? intval($_POST['move_to_forum']) : 0;
            if ($move_to_forum < 1)
                message($lang_common['Bad request']);

            $result = $db->query('SELECT f.id FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE f.id='.$move_to_forum.' AND (fp.read_forum IS NULL OR fp.read_forum=1) AND f.redirect_url IS NULL') or error('Unable to fetch forum', __FILE__, __LINE__, $db->error());
            if (!$db->num_rows($result))
                message($lang_common['Bad request']);

            if (isset($_POST['move_posts_topic']))
            {
                $move_to_topic = isset($_POST['move_to_topic']) ? intval($_POST['move_to_topic']) : 0;
                if ($move_to_topic < 1 || $move_to_topic == $tid)
                    message($lang_common['Bad request']);

                $result = $db->query('SELECT id FROM '.$db->prefix.'topics WHERE id='.$move_to_topic.' AND forum_id='.$move_to_forum) or error('Unable to fetch topic', __FILE__, __LINE__, $db->error());
                if (!$db->num_rows($result))
                    message($lang_common['Bad request']);

                // Verify that the post IDs are valid
                $result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE id IN('.$posts.') AND topic_id='.$tid) or error('Unable to check posts', __FILE__, __LINE__, $db->error());

                if ($db->num_rows($result) != substr_count($posts, ',') + 1)
                    message($lang_common['Bad request']);

                // перемещаем
                $add_text = '[color=#808080][i] '.$lang_misc['Post from topic'].' "'.$cur_topic['subject'].'"[/i]. '.$pun_user['username'].'[/color]'."\n\n";
                $db->query('UPDATE '.$db->prefix.'posts  SET topic_id='.$move_to_topic.', message=CONCAT(\''.$db->escape($add_text).'\', message) WHERE topic_id='.$tid.' AND id IN('.$posts.')') or error('Unable to update posts/topic', __FILE__, __LINE__, $db->error());

                // обновим темы
                $num_posts_deleted = substr_count($posts, ',') + 1;
                $result = $db->query('SELECT id, poster, posted FROM '.$db->prefix.'posts WHERE topic_id='.$tid.' ORDER BY id DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
                $last_post = $db->fetch_assoc($result);
                $db->query('UPDATE '.$db->prefix.'topics SET last_post='.$last_post['posted'].', last_post_id='.$last_post['id'].', last_poster=\''.$db->escape($last_post['poster']).'\', num_replies=num_replies-'.$num_posts_deleted.' WHERE id='.$tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
                $result = $db->query('SELECT id, poster, posted FROM '.$db->prefix.'posts WHERE topic_id='.$move_to_topic.' ORDER BY id DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
                $last_post = $db->fetch_assoc($result);
                $db->query('UPDATE '.$db->prefix.'topics SET last_post='.$last_post['posted'].', last_post_id='.$last_post['id'].', last_poster=\''.$db->escape($last_post['poster']).'\', num_replies=num_replies+'.$num_posts_deleted.' WHERE id='.$move_to_topic) or error('Unable to update topic', __FILE__, __LINE__, $db->error());

                // обновим форумы
                update_forum($fid);
                if ($fid != $move_to_forum)
                    update_forum($move_to_forum);

                redirect('viewtopic.php?id='.$tid, $lang_misc['Move posts redirect']);
            }

            $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_misc['Moderate']);
            define('PUN_ACTIVE_PAGE', 'index');
            require PUN_ROOT.'header.php';

            $result = $db->query('SELECT id, subject FROM '.$db->prefix.'topics WHERE forum_id='.$move_to_forum.' AND id<>'.$tid.' ORDER BY sticky DESC, last_post DESC') or error('Unable to fetch forum', __FILE__, __LINE__, $db->error());
            if (!$db->num_rows($result))
                message($lang_common['Bad request']);

?>
<div class="blockform">
    <h2><span><?php echo $lang_misc['Move posts'] ?></span></h2>
    <div class="box">
        <form method="post" action="moderate.php?fid=<?php echo $fid ?>&amp;tid=<?php echo $tid ?>">
            <div class="inform">
                <fieldset>
                    <legend><?php echo $lang_misc['Move legend'] ?></legend>
                    <div class="infldset">
                        <label><?php echo $lang_misc['Move to'].' '.$lang_common['Topic'] ?>
                            <select name="move_to_topic">
<?php
            while ($cur_topic = $db->fetch_assoc($result))
                echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</option>'."\n";
?>
                            </select>
                        </label>
                        <input type="hidden" name="posts" value="<?php echo $posts ?>" />
                        <input type="hidden" name="move_to_forum" value="<?php echo $move_to_forum ?>" />
                    </div>
                </fieldset>
            </div>
            <p class="buttons"><input type="submit" name="move_posts_topic" value="<?php echo $lang_misc['Move'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
        </form>
    </div>
</div>
<?php

            require PUN_ROOT.'footer.php';
        }

        $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_misc['Moderate']);
        define('PUN_ACTIVE_PAGE', 'index');
        require PUN_ROOT.'header.php';

?>
<div class="blockform">
    <h2><span><?php echo $lang_misc['Move posts'] ?></span></h2>
    <div class="box">
        <form method="post" action="moderate.php?fid=<?php echo $fid ?>&amp;tid=<?php echo $tid ?>">
            <div class="inform">
                <fieldset>
                    <legend><?php echo $lang_misc['Move legend'] ?></legend>
                    <div class="infldset">
                        <label><?php echo $lang_misc['Move to'].' '.$lang_common['Forum'] ?>
                        <select name="move_to_forum">
<?php

        $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.redirect_url IS NULL AND f.num_topics>0 ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());

        $cur_category = 0;
        while ($cur_forum = $db->fetch_assoc($result))
        {
            if ($cur_forum['cid'] != $cur_category)    // A new category since last iteration?
            {
                if ($cur_category)
                    echo "\t\t\t\t\t\t\t".'</optgroup>'."\n";

                echo "\t\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($cur_forum['cat_name']).'">'."\n";
                $cur_category = $cur_forum['cid'];
            }
            echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_forum['fid'].'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</option>'."\n";
        }

?>
                            </optgroup>
                        </select>
                        </label>
                        <input type="hidden" name="posts" value="<?php echo implode(',', array_keys($posts)) ?>" />
                    </div>
                </fieldset>
            </div>
            <p class="buttons"><input type="submit" name="move_posts_forum" value="<?php echo $lang_misc['Move'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
        </form>
    </div>
</div>
<?php

        require PUN_ROOT.'footer.php';
    // Перемещение одного и более сообщений в другую тему
    }
    // Delete one or more posts
    else if (isset($_POST['delete_posts']) || isset($_POST['delete_posts_comply']))

4. SAVE FILE moderate.php.
5. OPEN FILE /lang/[language]/misc.php
6. ADD NEW ELEMENTS OF ARRAY
For Russian

'Move posts' => 'Переместить сообщения',
'Move posts redirect' => 'Сообщения перемещены. Переадресация &hellip;',
'Post from topic' => 'Это сообщение перенесено из темы',

For English

'Move posts' => 'Move posts',
'Move posts redirect' => 'Posts moved. Redirecting …',
'Post from topic' => 'This post is moved from topic',

7. SAVE FILE /lang/[language]/misc.php
---------------------------------------------
10961751.th.gif
10721624.th.gif

Last edited by Visman (2010-10-23 09:29:03)

Offline

#2 2010-10-20 18:44:13

theamazingcat
Member
Registered: 2010-07-10
Posts: 9

Re: [MOD] Move posts - 1.1

thanks this worked great for moving posts,  is it possible to Merge posts somehow?


Keeping it surreal! http://theamazingcat.com

Offline

#3 2010-10-21 07:28:29

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,518
Website

Re: [MOD] Move posts - 1.1

theamazingcat wrote:

is it possible to Merge posts somehow?

What is it?

Offline

#4 2010-10-21 08:55:04

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,737
Website

Re: [MOD] Move posts - 1.1

That would mean combining two posts into one.


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#5 2010-10-21 09:33:56

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,518
Website

Re: [MOD] Move posts - 1.1

Franz wrote:

That would mean combining two posts into one.

This?
222av.th.jpg

Offline

#6 2010-10-21 09:37:06

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,737
Website

Re: [MOD] Move posts - 1.1

No, if I would merge posts #3 and #4 in this topic, it would look like this:

-------------------------------------------------------

theamazingcat wrote:

is it possible to Merge posts somehow?

What is it?

That would mean combining two posts into one.


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#7 2010-10-21 09:42:49

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,518
Website

Re: [MOD] Move posts - 1.1

Idea interesting, but I yet didn't do it.

Offline

#8 2010-10-22 14:28:02

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,518
Website

Re: [MOD] Move posts - 1.1

UP 1.0 to 1.1

1. OPEN FILE moderate.php.
2. FIND

                $result = $db->query('SELECT id, poster, posted FROM '.$db->prefix.'posts WHERE topic_id='.$move_to_topic.' ORDER BY id DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
                $last_post = $db->fetch_assoc($result);
                $db->query('UPDATE '.$db->prefix.'topics SET last_post='.$last_post['posted'].', last_post_id='.$last_post['id'].', last_poster=\''.$db->escape($last_post['poster']).'\', num_replies=num_replies+'.$num_posts_deleted.' WHERE id='.$move_to_topic) or error('Unable to update topic', __FILE__, __LINE__, $db->error());

REPLACE WITH

                $result = $db->query('SELECT id, poster, posted FROM '.$db->prefix.'posts WHERE topic_id='.$move_to_topic.' ORDER BY id DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
                $last_post = $db->fetch_assoc($result);
                $result = $db->query('SELECT id, poster, posted FROM '.$db->prefix.'posts WHERE topic_id='.$move_to_topic.' ORDER BY id LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
                $first_post = $db->fetch_assoc($result);
                $db->query('UPDATE '.$db->prefix.'topics SET posted='.$first_post['posted'].', first_post_id='.$first_post['id'].', poster=\''.$db->escape($first_post['poster']).'\', last_post='.$last_post['posted'].', last_post_id='.$last_post['id'].', last_poster=\''.$db->escape($last_post['poster']).'\', num_replies=num_replies+'.$num_posts_deleted.' WHERE id='.$move_to_topic) or error('Unable to update topic', __FILE__, __LINE__, $db->error());

3. SAVE FILE moderate.php.

Offline

#9 2011-12-10 16:41:29

Donny Bahama
Member
Registered: 2011-05-15
Posts: 9

Re: [MOD] Move posts - 1.1

I installed this, but I'm not sure how to actually use it. I expected to see a "move" link at the lower right of every post (mixed in with "Report", "Edit", etc.) but there is none. Help?

Offline

#10 2011-12-10 16:51:21

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,518
Website

Re: [MOD] Move posts - 1.1

db792d672d98531a0121d4402e81a742.jpg

Offline

Board footer

Powered by FluxBB